diff options
Diffstat (limited to 'samples')
-rw-r--r-- | samples/lpr.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/samples/lpr.lua b/samples/lpr.lua new file mode 100644 index 0000000..77c354f --- /dev/null +++ b/samples/lpr.lua | |||
@@ -0,0 +1,51 @@ | |||
1 | local lp = require("lp") | ||
2 | |||
3 | local function usage() | ||
4 | print('\nUsage: lp 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 s="opt = {" | ||
31 | for i = 2 , table.getn(arg), 1 do | ||
32 | s = s .. string.gsub(arg[i],"[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)","%1%=\"%2\",\n") | ||
33 | end | ||
34 | s = s .. "};\n" | ||
35 | assert(loadstring(s))(); | ||
36 | if not arg[2] then | ||
37 | return usage() | ||
38 | end | ||
39 | if arg[1] ~= "query" then | ||
40 | r,e=lp.send(arg[1],opt) | ||
41 | io.stderr:write(tostring(r or e),'\n') | ||
42 | else | ||
43 | r,e=lp.query(opt) | ||
44 | io.stderr: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 | ||