43 lines
1 KiB
Text
43 lines
1 KiB
Text
constant iBUFSIZE 500
|
|
|
|
function main(string filename)
|
|
fsfileinputstream fpi
|
|
integer e, i, aval, zval, cval
|
|
string s, buf, c
|
|
array chars
|
|
|
|
e = 0
|
|
fpi =@ fsfileinputstream.new(filename, error=e)
|
|
if fpi =@= .nul
|
|
s = "Error, file """ + filename + """ not found{d}{a}"
|
|
else
|
|
chars =@ array.new()
|
|
aval = .charval("a")
|
|
zval = .charval("z")
|
|
i = 1
|
|
while i <= 26
|
|
chars[i] = 0
|
|
i = i + 1
|
|
end while
|
|
buf = .lcase(fpi.getstring(iBUFSIZE, 1))
|
|
while not fpi.endofdata and buf > ""
|
|
i = 1
|
|
while i <= .len(buf)
|
|
c = .substr(buf, i, 1)
|
|
cval = .charval(c)
|
|
if cval >= aval and cval <= zval
|
|
chars[cval - aval + 1] = chars[cval - aval + 1] + 1
|
|
end if
|
|
i = i + 1
|
|
end while
|
|
buf = .lcase(fpi.getstring(iBUFSIZE, 1))
|
|
end while
|
|
|
|
s = "Character counts for """ + filename + """{d}{a}"
|
|
i = 1
|
|
while i <= chars.count()
|
|
s = s + .char(aval + i - 1) + ": " + .tostr(chars[i], 10) + "{d}{a}"
|
|
i = i + 1
|
|
end while
|
|
end if
|
|
end function s
|