comparison samples/lpr.lua @ 0:4b915342e2a8

LuaSocket 2.0.2 + CMake build description.
author Eric Wing <ewing . public |-at-| gmail . com>
date Tue, 26 Aug 2008 18:40:01 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4b915342e2a8
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, table.getn(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 -- 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