-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChars.dpr
83 lines (69 loc) · 1.4 KB
/
Chars.dpr
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
program Chars;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
BUF_SIZE = $8000;
var
Filename: string;
FI: file of Char;
Count: array[0..255] of LongInt;
Buffer: array[0..BUF_SIZE - 1] of Char;
NumRead: Integer;
const
W = 8;
H = 32;
var
i, j, n: Integer;
ch: Char;
max: Integer;
wd: Integer;
s: string;
begin
if (ParamCount < 1) then
begin
WriteLn ('syntax: chars filename');
Halt (0);
end;
for i := 0 to 255 do
Count[i] := 0;
Filename := ParamStr (1);
if (not FileExists (Filename)) then
begin
WriteLn ('file not found: ' + Filename);
Halt (1);
end;
AssignFile (FI, Filename);
Reset (FI);
NumRead := BUF_SIZE;
while NumRead = BUF_SIZE do
begin
BlockRead (FI, Buffer, BUF_SIZE, NumRead);
for i := 0 to NumRead - 1 do
Inc (Count[ord (Buffer[i])]);
end;
CloseFile (FI);
max := 0;
for i := 0 to 255 do
if (Count[i] > max) then
max := Count[i];
wd := Length (IntToStr (max));
for j := 0 to H - 1 do
begin
for i := 0 to W - 1 do
begin
n := j + i * H;
Ch := Chr (n);
if (Ch in [#8, #9, #10, #13, #7]) then
Ch := ' ';
if (n <= 255) then
begin
s := ' ' + IntToStr (Count[n]);
while Length (s) < wd + 1 do
s := '.' + s;
Write (n: 3, ' ', Ch, ' .', s, ' ');
end;
end;
WriteLn;
end;
end.