lines.pp 1.9 KB

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