UNIX Free Pascal



         

. - 3


fdclose(in1); (* : , - *)

fdclose(out2);

write(' : '); (* *)

readln(filename);

fdwrite(out1,filename,80); (* *)

{}writeln(': ');

fdread(in2,filesize,sizeof(filesize)); (* *)

{}writeln(': - ',filesize);

if in2=-1 then (* *)

writeln(' ',filename,' ')

else

begin

(* *)

{}writeln(': , ');

for i:=length(filename) downto 1 do

if filename[i]='/' then

begin

delete(filename,1,i);

break;

end;

fd:=fdopen(filename,Open_WRONLY or Open_CREAT or Open_TRUNC, octal(644));

if fd=-1 then

begin

writeln(' ',filename);

kill(pid,9);

halt(1);

end;

for i:=1 to filesize do(* *)

begin

fdread(in2,buf,1);

if i mod BLOCKSIZE=0 then

{}writeln(': ',i div BLOCKSIZE,' Kb');

fdwrite(fd,buf,1);(* *)

end;

fdclose(fd);(* *)

{}writeln(': ');

end;

waitpid(pid,nil,0); (* *)

{}writeln(': , ');

end;

end.

13.60. popen, who more.

uses linux;

var

f1,f2:text;

s:string;

begin

popen(f1,'who','r');

if linuxerror <> 0 then

begin

writeln(' who ');

exit;

end;

popen(f2,'more','w');

if linuxerror <> 0 then

begin

writeln(' more ');

exit;

end;

while not eof(f1) do

begin

readln(f1,s);

writeln(f2,s);

end;

pclose(f1);

pclose(f2);

end.