unit usys;

interface
uses umain;
  procedure fexec(name : tstring);
  procedure spawn;
  procedure ttype(typecopy:integer);
  procedure tdelete;
  procedure tpurge;

implementation
uses usp;

		(****************************************)
		(*	appels systemes			*)
		(*		execute,spawn		*)
		(*		type,delete,purge	*)
		(*		dir			*)
		(*		setdir			*)
		(*	msys.pas	-	prolog	*)
		(****************************************)


procedure fexec(name : tstring);
var	doserr	: integer;
begin
(* pdbzro doserr:=execdos(name,true,nil);
if doserr <> 0
then	begin
	backtrack:=true;
	case doserr of
		-1,-4	:writeln(output,'plus de place');
		-2,-3	:writeln(output,'erreur exec');
		else
		writeln(output,'erreur ',doserror);
		end;
	end;       *)
end;

procedure spawn;
var	cmd	: tstring;
begin
cmd:='';
write(output,'>');
read(input,cmd); readln(input);
while cmd <> 'exit' do
	begin
	if cmd <> ''
	then	fexec(cmd);
	write(output,'>');
	read(input,cmd); readln(input);
	end;
end;

procedure ttype(typecopy:integer); (* type (nom_de_fichier) *)
				(* copy (fichiersource,fichierdestinataire) *)
var	nom_fichier	:ttstring;
	fsource,fdest	:text;
	cho		:tstring;
	nb		:integer;
begin
lire_symbole(fils1_code);
nom_fichier:=symbole_lu;
mcreset(fsource,nom_fichier);
if ioresu <> 0	then	ok:=false;
if not ok
then	begin
	eros;
	writeln(output,'le fichier ',nom_fichier,' n''existe pas');
	backtrack:=true;
	end
else	begin
	ok := true;
	if typecopy >= 1
	then	begin
		if typecopy = 2
		then	nom_fichier := 'prn'
		else	begin
			lire_symbole(noeud^[fils2].code);
			nom_fichier:=symbole_lu;
			end;
		mrewrite(fdest,nom_fichier);
		if ioresu <> 0	then	ok:=false;
		end;
	if ok
	then	begin
		nb:=0;
		while nb<>-1 do
			begin
			if (nb=lig_bas) and (ttyout=0) and (typecopy=0)
			then	begin
				nb:=0;
				highvideo;
				write(output,'   frapper return ou fin > ');
				lowvideo;
				remet_couleur;

				read(input,cho);
				readln(input);
				if cho<>''
				then	nb:=-1;
				end;
			if nb <> -1
			then	begin
				nb:=nb+1;
				read(fsource,cho);
				if typecopy=0
				then	begin
					affiche(cho);
					(* writeln(output,cho);*)
					end
				else	writeln(fdest,cho);
				readln(fsource);
				end;
			if eof(fsource)
			then	nb:=-1;
			end;
		close(fsource);
		if typecopy >= 1
		then	close(fdest);
		end;
	end;
end;


procedure tdelete;
begin
end;

procedure tpurge;
begin
end;

{ procedure tdir;
type	str64 = string[64];
	str10 = string[10];

var	tree_dir	: boolean;	(* /t *)
	court	: boolean;	(* /w *)
	chemin1	: str64;
	chemin2	: str64;
	che2	: str64;
	longueur: str10;
	total	: real;
	nbtot	: integer;
	nbfich	: integer;
	nfichln	: integer;
	sousdir	: boolean;
	mega	: real;
	tail	: real;
	nbmega	: real;
	arbre	: boolean;
	q	: integer;

procedure direc(chemin1:str64;chemin2:str64;imb:integer);
var	searchr	: searchrec;
	atr	: byte;
	name	: str10;
	date	: datetime;
	erwt	: str10;
	chem	: str64;
	ii,ij	: integer;
	nomdir	: array[0..112] of str10;
	nbdir	: integer;
	ecrit	: boolean;

procedure spak(n:integer);
var	i :integer;
begin
if n>0
then	for i:=1 to n do
		write(output,' ');
end;

type stri = string[12];
procedure make_name(nom : stri ; var name : str10 ; var erwt : str10);
var	i	: integer;
begin
i := pos('.' , nom);
if i = 0
then	begin
	name := nom;
	erwt := '';
	end
else	begin
	name := copy(nom , 1, i-1);
	erwt := copy(nom , i+1 , 20);
	end;
end;

begin	(* code de direc *)
if chemin2 <> ''
then	direc(chemin1+chemin2,'',imb);
if (chemin1 = '')
or (chemin1[length(chemin1)] = '\')
or (chemin1[length(chemin1)] = ':')
then	chem := chemin1 + '*.*'
else	chem := chemin1;

nbdir := 0;
ecrit:=false;

findfirst(chem,anyfile,searchr);
while doserror = 0
do	begin
	if searchr.name[1] <> '.'
	then	begin
		make_name(searchr.name,name,erwt);
		atr := searchr.attr;
		if atr = 16
		then	begin
			if not arbre
			then	begin
				write(output,name);
				spak(8-length(name));
				write(output,' <DIR> ');
				if not court
				then	writeln(output);
				sousdir:=true;
				if court
				then	begin
					nfichln:=nfichln+1;
					if nfichln = 5
					then	begin
						nfichln:=0;
						writeln(output);
						end;
					end;
				end
			else	begin
				nbdir:=nbdir+1;
				nomdir[nbdir]:=name;
				end;
			end
		else	begin
			if (chemin2 = '') and not tree_dir
			then	begin
				if arbre and (not ecrit) and (che2<>'')
				then	begin
					for ii:=1 to imb-1 do
						write(output,'    ');
					ecrit:= true;
		writeln(output,copy(chemin1,1,length(chemin1)-length(che2)));
					end;
				if not court
				then	begin
					for ii:=1 to imb do
						write(output,'    ');
					end;
				tail := searchr.size;
				total := total+tail;
				nbtot := trunc((tail+511)/512) + nbtot;
				nbfich:=nbfich+1;
				write(output,name);
				spak(8-length(name));
				write(output,' ');
				write(output,erwt);
				spak(6-length(erwt));
				if not court
				then	begin
					write(output,searchr.size:8);
					unpacktime(searchr.time,date);
					spak(4);
					with date do
						begin
				write(output,day:2,'-',month:2,'-',year,' ');
				write(output,hour:2,':',min:2);
						end;
					writeln(output);
					end
				else	begin
					nfichln:=nfichln+1;
					if nfichln = 5
					then	begin
						nfichln:=0;
						writeln(output);
						end;
					end;
				end;
			end;
		end;
	findnext(searchr);
	end;
for ij := 1 to nbdir do
	begin
	for ii:=1 to imb do
		write(output,'    ');
	if che2 = ''
	then	begin
		if nfichln<>0
		then	writeln(output);
		if court
		then	write(output,'    - ');
		write(output,nomdir[ij]);
		spak(8-length(nomdir[ij]));
		write(output,' <DIR> ');
		if court
		then	write(output,'-');
		writeln(output);
		sousdir:=true;
		end;
	if chemin1[length(chemin1)]='\'
	then	direc(chemin1+nomdir[ij]+'\',chemin2,imb+1)
	else	direc(chemin1+'\'+nomdir[ij]+'\',chemin2,imb+1);
	end;
end;

begin	(* code de tdir *)
arbre:=false;
tree_dir:= false;
court := false;
if fils1 = 0
then	chemin1 := '*.*'
else	begin
	lire_symbole(fils1_code);
	chemin1 := symbole_lu;
	if chemin1[1]='/'
	then	begin
		if chemin1[2]='w'
		then	court := true
		else	begin
			if chemin1[2] = 't'
			then	arbre:=true;
			tree_dir := true;
			end;
		chemin1 := copy(chemin1,4,length(chemin1)-3);
		end;
	end;
chemin2 := '';
q := pos('*\',chemin1);
if q <> 0
then	begin
	chemin2:=copy(chemin1,q+2,20);
	chemin1:=copy(chemin1,1,q-1);
	arbre:=true;
	end;
che2:=chemin2;
total:=0;
nbtot:=0;
nbfich:=0;
nfichln:=0;
sousdir:=false;
direc(chemin1,chemin2,0);
nbmega:=nbtot/2000;
writeln;
if not tree_dir
then	begin
	if nbfich = 0
	then	begin
		if not sousdir
		then	writeln('   pas de fichier de ce nom');
		end
	else	begin
		if nbfich <> 1
		then	write('  ',nbfich,' fichiers ');
		write('   ',total:10:0,' octets   ',
			nbtot,' secteurs  ',nbmega:8:2,' megas');
		writeln;
		end;
	end;
end;

procedure tsetdir;
begin
lire_symbole(fils1_code);
chdir(symbole_lu);
end;          }
end.
