home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / edit / line / line.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1991-07-30  |  3.6 KB  |  104 lines

  1. Program Line(Input,Output);
  2. Uses Crt, Dos;
  3. Const
  4.      VERSION = 3.05;
  5. Var
  6.    Infile      : Text;                           { input file }
  7.    Buffer      : String;                         { buffer for input file }
  8.    Count       : Longint;                        { current line count }
  9.    FileName    : String;                         { file name of input file }
  10.    s255        : String;                         { buffer for 80+ line }
  11.    LongCount   : Longint;                        { total lines with 80+ }
  12.    Maxlength   : Integer;                        { maximum line length }
  13.    PageCount   : Integer;                        { total page count }
  14.    LineCount   : Longint;                        { total line count }
  15.    LinePerPage : Integer;                        { line per page }
  16.  
  17.  
  18. Procedure ReadParam; (* Read all command line paramaters *)
  19. var i,j,k : Integer;
  20.     s   : String;
  21. begin
  22.      LinePerPage := 60;
  23.      FOR i := 1 to ParamCount DO
  24.      BEGIN
  25.           s := ParamStr(i);
  26.           CASE s[1] OF
  27.                '?' : BEGIN
  28.                           Writeln('LINE <Filename.ext> [/Px]');
  29.                           Write  ('      /Px - Define the number of lines ');
  30.                           Writeln('per game.');
  31.                           Halt(0);
  32.                      END;
  33.                '/' : BEGIN
  34.                           CASE s[2] OF
  35.                                'p','P' : BEGIN
  36.                                               Val(Copy(s,3,80),j,k);
  37.                                               LinePerPage := j;
  38.                                           END;
  39.                           END;
  40.                      END;
  41.                ELSE Filename := s;
  42.           END;
  43.      END;
  44. END;
  45.  
  46. BEGIN
  47.      Writeln;
  48.      Writeln('LINE - Line Counting utility.');
  49.      Writeln('v',VERSION:4:2,' Written by Seng On, 06-14-1991');
  50.      Writeln;
  51.  
  52.      IF ParamCount = 0 THEN
  53.         Writeln('File name required!')
  54.      ELSE
  55.      BEGIN
  56.           ReadParam;
  57. {$I-}     Assign(Infile,FileName);
  58.           Reset(Infile);
  59. {$I+}
  60.           IF IOResult = 0 THEN
  61.           BEGIN
  62.                TextColor(Blink+7);
  63.                Write('Counting ...');
  64.                TextColor(7);
  65.                Count := 0; LongCount := 0; MaxLength := 0; PageCount := 0;
  66.                LineCount := 0;
  67.  
  68.                WHILE NOT EOF(Infile) DO
  69.                BEGIN
  70.                     Readln(Infile,s255);
  71.                     Buffer := Copy(s255,1,80);
  72.                     Inc(Count); Inc(LineCount);
  73.  
  74.                     WHILE ((Pos(Chr(12),Buffer) > 0) AND (Length(Buffer) > 0)) DO
  75.                     BEGIN
  76.                          Inc(PageCount); Count := 1;
  77.                          Buffer := Copy(Buffer,Pos(Chr(12),Buffer)+1,80);
  78.                     END;
  79.  
  80.                     IF (Count >= LinePerPage) THEN
  81.                     BEGIN
  82.                          Inc(PageCount);
  83.                          Count := Count - LinePerPage;
  84.                     END;
  85.  
  86.                     IF Length(s255)>80 THEN Inc(LongCount);
  87.  
  88.                     IF Length(s255)>MaxLength THEN Maxlength := Length(s255);
  89.                END;
  90.  
  91.                Close(Infile);
  92.  
  93.                IF Count <> 0 THEN Inc(PageCount);
  94.  
  95.                Gotoxy(1,Wherey);
  96.                Write('LINE reports ',LineCount,' lines in ',FileName);
  97.                Writeln(' (MPRINT = ',PageCount,' pages[',LinePerPage,'])');
  98.                Write('Number of line(s) with 80+ characters = ',LongCount);
  99.                Writeln(' (Longest line = ',MaxLength,' characters)');
  100.           END ELSE Writeln('Unable to open ',FileName);
  101.  
  102.      END;
  103. END.
  104.