lp0 = manager:machine().luaprinters[1]
filenamebase=lp0:getprintername()
filenamecount=0
idlewaitperiod=30*60
idlecount=0
function feedchars(ch)
local idleflag=0
repeat
nextchar = lp0:getnextchar()
if nextchar >= 0 then
idleflag=1
if f == nil then
filenamecount = filenamecount+1
currentfilename = filenamebase..string.format("%04d",filenamecount)..".ps"
f=io.open(currentfilename,"w")
idlecount=0
end
f:write(string.char(nextchar))
end
until nextchar < 0
if idleflag==0 then
if f~=nil then
idlecount=idlecount+1
if idlecount%(60*5)==0 then print ("idle: "..idlecount/60) end
end
else
idlecount=0 -- reset idlecount
end
if idlecount > idlewaitperiod then
idlecount=-1
f:close()
f=nil
os.execute('gv "'..currentfilename..'" &')
print('gv '..currentfilename)
end
end
function framedispatch() for i,j in pairs(dispatchlist) do j() end end
emu.register_frame(framedispatch)
dispatchlist={feedchars}