local struct = require "struct"
if #arg == 0 then
print "Usage: fileio dsname"
os.exit(8)
end
local file, msg = io.open(arg[1], "rb, type=record, noseek")
if not file then error(msg) end
local smftype = {}
setmetatable(smftype, {__index = function () return 0 end})
while true do
local rec = file:read()
if not rec then break end
local flag, type = struct.unpack("BB",rec)
smftype[type] = smftype[type] + 1
end
local types = {}
for type, count in pairs(smftype) do
table.insert(types, {type, count})
end
table.sort(types, function (a,b) return a[1] < b[1] end)
for _, v in pairs(types) do
print("type("..v[1]..") = "..v[2])
end