beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luasocket / samples / lpr.lua
blob3d5e2f8d1be2556687f8772bfead57de76423e5b
1 local lp = require("socket.lp")
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'
22 return nil
23 end
25 if not arg or not arg[1] then
26 return usage()
27 end
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
48 -- trivial tests
49 --lua lp.lua lp.lua queue=default host=localhost
50 --lua lp.lua lp.lua queue=default host=localhost format=binary localbind=1
51 --lua lp.lua query queue=default host=localhost