lines.pp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993-98 by Florian Klaempfl
  5. Line Counter Example
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. program count_lines;
  13. {
  14. Program that counts number of Lines in a file
  15. }
  16. uses
  17. dos,crt;
  18. type
  19. td = array[1..10000] of byte;
  20. var
  21. lines : longint;
  22. s : searchrec;
  23. f : file;
  24. d : ^td;
  25. {$ifdef tp}
  26. count : word;
  27. i,z : integer;
  28. {$else}
  29. count,i,z : longint;
  30. {$endif}
  31. begin
  32. lines:=0;
  33. new(d);
  34. if paramcount<1 then
  35. begin
  36. writeln('Usage: ',paramstr(0),' filename.ext [filename.ext] ...');
  37. writeln(' Multiple File Names and Wild Cards Allowed:');
  38. writeln(' Example: lines *.cpp stdio.h *.asm');
  39. halt(1);
  40. end;
  41. for i:=1 to paramcount do
  42. begin
  43. findfirst(paramstr(i),archive,s);
  44. while (doserror=0) do
  45. begin
  46. gotoxy(1,wherey);
  47. write(' ');
  48. gotoxy(1,wherey);
  49. write('Scanning: ',s.name);
  50. assign(f,s.name);
  51. reset(f,1);
  52. while not(eof(f)) do
  53. begin
  54. blockread(f,d^,10000,count);
  55. for z:=1 to count do
  56. if d^[z]=10 then inc(lines);
  57. end;
  58. close(f);
  59. findnext(s);
  60. end;
  61. end;
  62. dispose(d);
  63. gotoxy(1,wherey);
  64. write(' ');
  65. gotoxy(1,wherey);
  66. if lines=1 then writeln('1 Line') else writeln(lines,' Lines');
  67. end.
  68. {
  69. $Log$
  70. Revision 1.2 2002-09-07 15:06:35 peter
  71. * old logs removed and tabs fixed
  72. }