home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / FPALN.ZIP / FPALN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-07-14  |  4.3 KB  |  76 lines

  1. PROGRAM CountPagesAndLines;         {What the program does.                }
  2. CONST
  3.      ProgData = 'FPALN- Free DOS utility: text file page & line counter.';
  4.      ProgDat2 = 'V1.00: July 14, 1993. (c) 1993 by David Daniel Anderson - Reign Ware.';
  5.  
  6.      Usage  = 'Usage: FPALN text_file [/t (file Totals only)]';
  7.  
  8. VAR
  9.      PagedFile    : Text;           {The actual file to dissect (examine). }
  10.      PS1          : String[80];     {The name of the file.                 }
  11.      ALine        : String;         {A line in the file.                   }
  12.      FFCount,                       {Count of FormFeeds ( ), ASCII 12      }
  13.      TotalLines,                    {Total lines in the file.              }
  14.      LineCount    : Word;           {Total lines on each page.             }
  15.      JustTotals   : Boolean;        {Indicator of how much info to write.  }
  16.  
  17.  
  18. PROCEDURE WritePageStats;     {Called at end of every page to show subtotals.}
  19. BEGIN                         {Do nothing if instructed to only show totals. }
  20.      IF (NOT JustTotals) THEN             {Otherwise, go ahead.}
  21.         WriteLn('Page: ',FFCount:7,' has: ',LineCount:5,' lines.');
  22. END;
  23.  
  24. BEGIN
  25.      Writeln(ProgData);
  26.      Writeln(ProgDat2);
  27.      Writeln;
  28.      FFCount := 0;
  29.      TotalLines := 0;                              {Initialize all counts.}
  30.      LineCount := 0;
  31.      JustTotals := (ParamStr(2) = '/t');           {Just show totals if   }
  32.                                                    {  2nd parameter is /t.}
  33.      PS1 := ParamStr(1);                           {PS1 gets command line.}
  34.  
  35.      WHILE PS1 = '' DO BEGIN
  36.         Writeln('Text file to dissect:');          {   Recursive query.   }
  37.         ReadLn(PS1);
  38.      END;
  39.  
  40.      Assign(PagedFile,PS1);                        {  Assign properly.    }
  41. {$I-} Reset(PagedFile); {$I+}                      { Check if file exists.}
  42.      IF IOResult <> 0 THEN                         { If it                }
  43.      BEGIN                                         {    doesn't, then     }
  44.          Writeln('I cannot open "', PS1, '".');    {  quit with message.  }
  45.          Writeln(Usage);
  46.          Halt;
  47.      END;
  48.      WHILE NOT Eof(PagedFile) DO                   {Will read             }
  49.      BEGIN                                         {     the entire file. }
  50.           ReadLn(PagedFile,ALine);                 {Read a line.          }
  51.           TotalLines := Succ(TotalLines);          {Increment counter.    }
  52.           IF Pos(' ',ALine) <> 0 THEN              {If page break on line,}
  53.           BEGIN                                    {increment page counter.}
  54.              FFCount := Succ(FFCount);             {If page break in the  }
  55.              IF Pos(' ',ALine) > 1 THEN            {   middle of line,    }
  56.              BEGIN                                 {     the line would   }
  57.                 TotalLines := Succ(TotalLines);    {       print over two }
  58.                 LineCount := Succ(LineCount);      { lines, so increment  }
  59.              END;                                  { line counters again. }
  60.              WritePageStats; {A procedure, above.} {Write totals so far.  }
  61.              LineCount := 0;                       {Reset counter for     }
  62.           END;                                     {    next page.        }
  63.           LineCount := Succ(LineCount);            {The line in buffer    }
  64.      END;                                          { automatically counts.}
  65.      IF (TotalLines <> 0) THEN                     {If no lines,          }
  66.         FFCount := Succ(FFCount);                  {        then no pages!}
  67.      WritePageStats;                               {Write totals so far.  }
  68.      WriteLn;                           {These next lines write grand totals.}
  69.      Write('Text file ■',PS1:13,' ■ has: ',TotalLines:7,' lines on: ',FFCount:5);
  70.      IF FFCount <> 1 THEN                    {If zero pages, OR multiple    }
  71.         WriteLn(' pages.')                   {        pages, write "pages." }
  72.      ELSE                                    {otherwise,                    }
  73.         WriteLn(' page.');                   {        simply write "page."  }
  74.      Close (PagedFile);                      {Close our file for neatness.  }
  75. END.                                         {          Done!!!             }
  76.