summaryrefslogtreecommitdiff
path: root/ThirdParty/luasocket/samples/lpr.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-20 13:40:34 +0800
committerchai <chaifix@163.com>2021-10-20 13:40:34 +0800
commitff0f488c97fe8b554b909a0057cebc4c860eac8f (patch)
tree4e47262b52ffce7e9cfeaaeeab46371243bcaa78 /ThirdParty/luasocket/samples/lpr.lua
parentdde719dd575090b36aaa3ad85bb3cabf33f36c5a (diff)
+luasocket src
Diffstat (limited to 'ThirdParty/luasocket/samples/lpr.lua')
-rw-r--r--ThirdParty/luasocket/samples/lpr.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/ThirdParty/luasocket/samples/lpr.lua b/ThirdParty/luasocket/samples/lpr.lua
new file mode 100644
index 0000000..49a1dfa
--- /dev/null
+++ b/ThirdParty/luasocket/samples/lpr.lua
@@ -0,0 +1,51 @@
+local lp = require("socket.lp")
+
+local function usage()
+ print('\nUsage: lua lpr.lua [filename] [keyword=val...]\n')
+ 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
+ local opt = {}
+ local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]?.?)"
+ for i = 2, #arg, 1 do
+ string.gsub(arg[i], pat, function(name, value) opt[name] = value end)
+ end
+ if not arg[2] then
+ return usage()
+ end
+ if arg[1] ~= "query" then
+ opt.file = arg[1]
+ r,e=lp.send(opt)
+ io.stdout:write(tostring(r or e),'\n')
+ else
+ r,e=lp.query(opt)
+ io.stdout:write(tostring(r or e), '\n')
+ 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