home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / FPALN102.ZIP / FPALN.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-24  |  6KB  |  117 lines

  1. PROGRAM CountPagesAndLines;         {What the program does.                }
  2. {------------------------------------------------------------------------------
  3.  
  4.                                 REVISION HISTORY
  5.  
  6. v1.00  : 1993/07/14.  First public release.  DDA
  7. v1.01  : 1993/12/26.  Now recognizes DOS wildcards.  DDA
  8. v1.02  : 1994/01/24.  Now can handle files longer than 65535 lines.  DDA
  9.  
  10. ------------------------------------------------------------------------------}
  11.  
  12. uses dos ;
  13. VAR
  14.      PagedFile    : Text;           {The actual file to dissect (examine). }
  15.      ALine        : String;         {A line in the file.                   }
  16.      FFCount,                       {Count of FormFeeds ( ), ASCII 12      }
  17.      TotalLines,                    {Total lines in the file.              }
  18.      LineCount    : LongInt;        {Total lines on each page.             }
  19.      JustTotals   : Boolean;        {Indicator of how much info to write.  }
  20.  
  21.  
  22. procedure showhelp ( errornum : byte );
  23. const
  24.      ProgData = 'FPALN- Free DOS utility: text file page & line counter.';
  25.      ProgDat2 = 'v1.02: January 24, 1994. (c) 1994 by David Daniel Anderson - Reign Ware.';
  26.  
  27.      Usage  = 'Usage: FPALN text_file [/t (file Totals only)]';
  28. var
  29.     message : string [80];
  30. begin
  31.     writeln ( progdata );
  32.     writeln ( progdat2 );
  33.     writeln ;
  34.     writeln ( usage );
  35.     writeln ;
  36.  
  37.     case errornum of
  38.       1 : message := 'you must specify -exactly- one filespec (wildcards are OK).';
  39.       2 : message := 'too many parameters.';
  40.       3 : message := 'non-numeric found in a date or time string!';
  41.       4 : message := 'unable to open specified file.';
  42.     end;
  43.     writeln ( 'ERROR: (#',errornum,') - ', message );
  44.     halt ( errornum );
  45. end;
  46.  
  47. PROCEDURE WritePageStats;     {Called at end of every page to show subtotals.}
  48. BEGIN                         {Do nothing if instructed to only show totals. }
  49.      IF (NOT JustTotals) THEN             {Otherwise, go ahead.}
  50.         WriteLn('Page: ',FFCount:7,' has: ',LineCount:5,' lines.');
  51. END;
  52.  
  53. var
  54.    dirinfo : searchrec ;
  55.    ps1     : pathstr ;
  56.    pdir    : dirstr ;
  57.    pname   : namestr ;
  58.    pext    : extstr ;
  59.  
  60. BEGIN
  61.      JustTotals := (ParamStr(2) = '/t');           {Just show totals if   }
  62.                                                    {  2nd parameter is /t.}
  63.  
  64.      PS1 := ParamStr(1);                           {PS1 gets command line.}
  65.      WHILE PS1 = '' DO BEGIN
  66.         Writeln('Text file to dissect:');          {   Recursive query.   }
  67.         ReadLn(PS1);
  68.      END;
  69.  
  70.      ps1 := ( fexpand ( PS1 ));
  71.  
  72.      fsplit ( ps1,pdir,pname,pext );
  73.      findfirst ( ps1, ReadOnly+Hidden+Archive, dirinfo );
  74.      if ( doserror <> 0) then
  75.           showhelp(1);
  76.  
  77.      while doserror = 0 do begin
  78.  
  79.        Assign(PagedFile,pdir+dirinfo.name);          {  Assign properly.    }
  80.  {$I-} Reset(PagedFile); {$I+}                       { Check if file exists.}
  81.        IF IOResult <> 0 THEN                         { If it                }
  82.           showhelp (4);
  83.        Writeln('Reading text file ■',dirinfo.name:13,' ...');
  84.        FFCount := 0;
  85.        TotalLines := 0;                              {Initialize all counts.}
  86.        LineCount := 0;
  87.        WHILE NOT Eof(PagedFile) DO                   {Will read             }
  88.        BEGIN                                         {     the entire file. }
  89.             ReadLn(PagedFile,ALine);                 {Read a line.          }
  90.             Inc(TotalLines);                         {Increment counter.    }
  91.             IF Pos(' ',ALine) <> 0 THEN              {If page break on line,}
  92.             BEGIN                                    {increment page counter.}
  93.                Inc(FFCount);                         {If page break in the  }
  94.                IF Pos(' ',ALine) > 1 THEN            {   middle of line,    }
  95.                BEGIN                                 {     the line would   }
  96.                   Inc(TotalLines);                   {       print over two }
  97.                   Inc(LineCount);                    { lines, so increment  }
  98.                END;                                  { line counters again. }
  99.                WritePageStats; {A procedure, above.} {Write totals so far.  }
  100.                LineCount := 0;                       {Reset counter for     }
  101.             END;                                     {    next page.        }
  102.             Inc(LineCount);                          {The line in buffer    }
  103.        END;                                          { automatically counts.}
  104.        IF (TotalLines <> 0) THEN                     {If no lines,          }
  105.           Inc(FFCount);                              {        then no pages!}
  106.        WritePageStats;                               {Write totals so far.  }
  107.        Write('Text file ■',dirinfo.name:13,' ■ has: ',TotalLines:7,' lines on: ',FFCount:5);
  108.        IF FFCount <> 1 THEN                    {If zero pages, OR multiple    }
  109.           WriteLn(' pages.')                   {        pages, write "pages." }
  110.        ELSE                                    {otherwise,                    }
  111.           WriteLn(' page.');                   {        simply write "page."  }
  112.        WriteLn;                          {These next lines write grand totals.}
  113.        Close (PagedFile);                      {Close our file for neatness.  }
  114.            findnext ( dirinfo );
  115.      end; {while}
  116. END.                                         {          Done!!!             }
  117.