| 1 |
local lp = require("socket.lp") |
| 2 |
|
| 3 |
local function usage() |
| 4 |
print('\nUsage: lua lpr.lua [filename] [keyword=val...]\n') |
| 5 |
print('Valid keywords are :') |
| 6 |
print( |
| 7 |
' host=remote host or IP address (default "localhost")\n' .. |
| 8 |
' queue=remote queue or printer name (default "printer")\n' .. |
| 9 |
' port=remote port number (default 515)\n' .. |
| 10 |
' user=sending user name\n' .. |
| 11 |
' format=["binary" | "text" | "ps" | "pr" | "fortran"] (default "binary")\n' .. |
| 12 |
' banner=true|false\n' .. |
| 13 |
' indent=number of columns to indent\n' .. |
| 14 |
' mail=email of address to notify when print is complete\n' .. |
| 15 |
' title=title to use for "pr" format\n' .. |
| 16 |
' width=width for "text" or "pr" formats\n' .. |
| 17 |
' class=\n' .. |
| 18 |
' job=\n' .. |
| 19 |
' name=\n' .. |
| 20 |
' localbind=true|false\n' |
| 21 |
) |
| 22 |
return nil |
| 23 |
end |
| 24 |
|
| 25 |
if not arg or not arg[1] then |
| 26 |
return usage() |
| 27 |
end |
| 28 |
|
| 29 |
do |
| 30 |
local opt = {} |
| 31 |
local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]?.?)" |
| 32 |
for i = 2, #arg, 1 do |
| 33 |
string.gsub(arg[i], pat, function(name, value) opt[name] = value end) |
| 34 |
end |
| 35 |
if not arg[2] then |
| 36 |
return usage() |
| 37 |
end |
| 38 |
if arg[1] ~= "query" then |
| 39 |
opt.file = arg[1] |
| 40 |
r,e=lp.send(opt) |
| 41 |
io.stdout:write(tostring(r or e),'\n') |
| 42 |
else |
| 43 |
r,e=lp.query(opt) |
| 44 |
io.stdout:write(tostring(r or e), '\n') |
| 45 |
end |
| 46 |
end |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|