home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
RBBS in a Box Volume 1 #2
/
RBBS_vol1_no2.iso
/
050z
/
wc.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1984-12-03
|
2KB
|
65 lines
program wc;
{$I arglist.pin}
const
blank = ' ';
tab = ^I;
newline = ^J;
cr = ^M;
teof = ^Z;
var
infile : file;
filename : string[20];
inbuf : array[1..512] of char;
words,lines,chars : integer;
iptr : integer;
ch : char;
inword : boolean;
begin
words := 0;
lines := 0;
chars := 0;
inword := false;
if argc <> 1 then begin
write('input - ');
readln(filename);
assign(infile,filename);
end
else assign(infile,argv(1));
reset(infile);
repeat
{$I-}
blockread(infile,inbuf,4);
{$I+}
if ioresult <> 0 then begin
gotoxy(1,4);
writeln(chars,' C ',words,' W ',lines,' L ');
halt;
end;
iptr := 1;
while iptr <= 512 do begin
ch := inbuf[iptr];
chars := chars+1;
iptr := iptr+1;
if ch=teof then begin
gotoxy(1,4);
writeln(chars,' C ',words,' W ',lines,' L ');
halt;
end;
if (ch=cr) or (ch=tab) or (ch=blank) then inword :=
false
else if (ch=newline) then begin
inword := false;
lines := lines+1;
end
else if not inword then begin
inword := true;
words := words+1;
end;
end;
until eof(infile);
end.