This repository was archived by the owner on Oct 11, 2022. It is now read-only.
forked from nickelsworth/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0041.pas
More file actions
45 lines (39 loc) · 1.37 KB
/
Copy path0041.pas
File metadata and controls
45 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{
>The subroutine opened a text file (in this case the Telix.USE file) in
>binary mode, and then searched through the file for the CR/LF pair and
>then incremented a counter. At the end I knew the number of lines in
>the text file. I suppose in Pascal I could open the file do a while
>loop and count the lines -- but that would require me to read every
>single line where the basic subroutine did all the searching without
>having to read the file line by line.
>I guess what I'm asking is how is a fast way to determine the number of
>lines in a text file using Pascal.
FWIW, This routine takes a little over 6 seconds on a 330K TELIX.USE on a
386/33
}
program countlines;
var
usefile : file;
buffer : array[0..8191] of byte;
counter, numw, numr : word;
size, numlines : longint;
begin
numlines := 0;
counter := 0;
fillchar(buffer, sizeof(buffer), #0);
assign(usefile,'TELIX.USE');
reset(usefile,1);
size := filesize(usefile);
repeat
blockread(usefile,buffer,sizeof(buffer),numr);
for counter := 0 to 8191 do
if buffer[counter] = ord(13)
then begin
inc(numlines);
write(round((filepos(usefile)/size)*100),'%',chr(13));
end;
until numr = 0;
close(usefile);
writeln('Your TELIX.USE has ',numlines,' lines.');
end.