2004-10-11 08:18:57 +02:00
|
|
|
local lp = require("socket.lp")
|
2004-07-01 05:32:09 +02:00
|
|
|
|
|
|
|
local function usage()
|
2005-11-20 09:56:19 +01:00
|
|
|
print('\nUsage: lua lpr.lua [filename] [keyword=val...]\n')
|
2004-07-01 05:32:09 +02:00
|
|
|
print('Valid keywords are :')
|
|
|
|
print(
|
|
|
|
' host=remote host or IP address (default "localhost")\n' ..
|
|
|
|
' queue=remote queue or printer name (default "printer")\n' ..
|
|
|
|
' port=remote port number (default 515)\n' ..
|
|
|
|
' user=sending user name\n' ..
|
|
|
|
' format=["binary" | "text" | "ps" | "pr" | "fortran"] (default "binary")\n' ..
|
|
|
|
' banner=true|false\n' ..
|
|
|
|
' indent=number of columns to indent\n' ..
|
|
|
|
' mail=email of address to notify when print is complete\n' ..
|
|
|
|
' title=title to use for "pr" format\n' ..
|
|
|
|
' width=width for "text" or "pr" formats\n' ..
|
|
|
|
' class=\n' ..
|
|
|
|
' job=\n' ..
|
|
|
|
' name=\n' ..
|
|
|
|
' localbind=true|false\n'
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if not arg or not arg[1] then
|
|
|
|
return usage()
|
|
|
|
end
|
|
|
|
|
|
|
|
do
|
2004-07-03 01:47:52 +02:00
|
|
|
local opt = {}
|
|
|
|
local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)"
|
2013-02-25 23:28:28 +01:00
|
|
|
for i = 2, #arg, 1 do
|
2004-07-03 01:47:52 +02:00
|
|
|
string.gsub(arg[i], pat, function(name, value) opt[name] = value end)
|
2004-07-01 05:32:09 +02:00
|
|
|
end
|
|
|
|
if not arg[2] then
|
|
|
|
return usage()
|
|
|
|
end
|
|
|
|
if arg[1] ~= "query" then
|
2005-11-22 09:33:29 +01:00
|
|
|
opt.file = arg[1]
|
|
|
|
r,e=lp.send(opt)
|
2004-07-01 05:47:22 +02:00
|
|
|
io.stdout:write(tostring(r or e),'\n')
|
2004-07-01 05:32:09 +02:00
|
|
|
else
|
|
|
|
r,e=lp.query(opt)
|
2004-07-01 05:47:22 +02:00
|
|
|
io.stdout:write(tostring(r or e), '\n')
|
2004-07-01 05:32:09 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- trivial tests
|
|
|
|
--lua lp.lua lp.lua queue=default host=localhost
|
|
|
|
--lua lp.lua lp.lua queue=default host=localhost format=binary localbind=1
|
|
|
|
--lua lp.lua query queue=default host=localhost
|