#!/usr/bin/lua

local function egyfile(fnev)
buf = nil
sp  = false	-- jott-e mar helykozzel kezdodo sor
db  = 0		-- osszes lekerdezesszam
hib = 0		-- hibas lekerdezesek szama
hibflg = false	-- volt-e hiba a puffereles ota
for sor in io.lines(fnev) do
	elso = string.sub(sor,1,1)
	--print(sp,elso,db,hib,string.sub(sor,1,50))
	if buf and (elso ~= '-' or elso == '-' and not sp )
	then	if not buf then buf = sor
		else	buf = buf..'\n'..sor
		end
		if elso == '-'
		then	hib = hib+1
			hibflg = true
			db  = db + 1
		elseif	elso == ' '
		then	sp = true
		end
	else	if elso == '-'
		then	if buf and hibflg then print(buf) end
			buf = sor
			sp  = false
			hibflg = false
			db  = db + 1
		end
	end
end
if buf and not sp	-- az utolso lekerdezes
then	print(buf)
	hib = hib+1
end
print(fnev,db,'lekérdezés, ebből',hib,'hibás')
end	-- fuggvenyveg

if not arg[1] then print('Hivás:',arg[0]..' fájlnév') return 1 end
for i,fnev in ipairs(arg)
do	egyfile(fnev)
end
