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