home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1994 / 6 / 01 / mini-compiler / mini.ampk / Mini-Compiler / Demo / Wc.m < prev   
Encoding:
Text File  |  1995-06-01  |  1.8 KB  |  85 lines

  1. Program WordCount;
  2.  
  3. { Die Kommentarklammern liegen rechts neben 'ß' ! }
  4. { Diese Demo stellt ein einfaches Unix "wc" Kommando dar }
  5.  
  6.  
  7. Var fil               : Text;
  8.     Buff,name         : String;
  9.     Line,Size,ok : Boolean;
  10.     AnzL,AnzS    : Integer;
  11.  
  12. Procedure ParseParams;
  13. var Pa,s  : String;
  14.     hi,i  : Integer;
  15. Begin
  16.  s:=ParamStr;
  17.  ok:=True;
  18.  if s=''
  19.     then Begin
  20.           Ok:=False;
  21.           Writeln('wc [-lc] File')
  22.          End
  23.     else Begin
  24.           I:=Pos('-',s);
  25.           If i=0
  26.              then Begin
  27.                    Line:=True;
  28.                    Size:=True;
  29.                    Name:=s;
  30.                    While (Length(s)>0) and (Copy(s,1,1)=' ') Do
  31.                        s:=Copy(S,2,Length(s)-1);
  32.                    i:=Pos(' ',s);
  33.                    If i>0
  34.                       then s:=Copy(s,1,i-1);
  35.                    Name:=s
  36.                   End
  37.              else Begin
  38.                    hI:=Pos(' ',s);
  39.                    If hi=0
  40.                       then ok:=False
  41.                       else Begin
  42.                             pa:=Copy(s,i,hi-i);
  43.                             Line:=(Pos('l',pa)>0);
  44.                             Size:=(Pos('c',pa)>0);
  45.                             Name:=Copy(s,hi+1,Length(s)-hi)
  46.                            End
  47.  
  48.                   End
  49.          End
  50. End;
  51.  
  52. Function GetSize: Integer;
  53. Begin
  54.  Return(FileSize(fil))
  55. End;
  56.  
  57. Procedure Work;
  58.  
  59. Begin
  60.  Reset(fil,Name);
  61.  If IoResult=0
  62.     then Begin
  63.           AnzL:=0;
  64.           If Size
  65.              then AnzS:=GetSIze;
  66.           While Not(eof(Fil)) Do
  67.            Begin
  68.             Readln(Fil,Buff);
  69.             AnzL:=AnzL+1
  70.            End;
  71.           If Size
  72.              then Write('Size :',AnzS,' ');
  73.           If Line
  74.              then Write('Lines : ',AnzL);
  75.           Writeln;
  76.           Close(Fil)
  77.          End
  78. End;
  79.  
  80. Begin
  81.  ParseParams;
  82.  If Ok
  83.     then Work
  84. End.
  85.