home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Zipped / CALMIR21.ZIP / SOURCE.ZIP / SRC / COUNTTIP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-20  |  1.0 KB  |  47 lines

  1. program CountTip;
  2.  
  3. { This is a Turbo Pascal program to run from a DOS box.  Redirect
  4.   standard input to this program, and it will count the number of
  5.   tips in a file.  It ignores the first line (which should contain
  6.   a number), blank lines, and lines beginning with a semi-colon.
  7.  
  8.   It also checks that there is a full stop or exclamation mark
  9.   at the end of each string, to try and catch out those which are
  10.   longer than 255 characters.  }
  11.  
  12.  
  13. function CheckString(const s: string): Boolean;
  14. var
  15.   i: Integer;
  16. begin
  17.   i := Length(s);
  18.   while (i > 0) and (s[i] = ' ') and (s[i] <> '.') do
  19.     Dec(i);
  20.   CheckString := (s[i] = '.') or (s[i] = '!');
  21. end;
  22.  
  23.  
  24. var
  25.   Count, Lines : Integer;
  26.   s : string;
  27. begin
  28.   Readln;
  29.  
  30.   Count := 0;
  31.   Lines := 1;
  32.  
  33.   while not Eof do begin
  34.     Readln(s);
  35.     Inc(Lines);
  36.  
  37.     if (s > '') and (s[1] <> ';') then begin
  38.       Inc(Count);
  39.       if not CheckString(s) then
  40.         Writeln('Unterminated string at line ', Lines);
  41.     end;
  42.   end;
  43.  
  44.   Writeln('I''ve found ', Count, ' tips.');
  45. end.
  46.  
  47.