3 local p = require "posix"
6 local short = "hp:arltq"
9 {"port", "required", 'p'},
11 {"remove", "none", 'r'},
12 {"list", "none", 'l'},
13 {"test", "none", 't'},
27 for opt, optarg, optind, longind in p.getopt(arg, short, long) do
29 print("Unrecognized option")
31 elseif opt == 'h' then
32 print("Usage: rulc [-h|-p PORT|-a|-r|-l|-t|-q] DATA ...")
34 elseif opt == 'p' then
48 msg = string.format("%s {class=%q, instance=%q, title=%q, type=%q, state=%q}", msg, arg[data_idx], arg[data_idx+1], arg[data_idx+2], arg[data_idx+3], arg[data_idx+4])
49 elseif cmd == "add" then
50 msg = string.format("%s {%q, %q, %s}", msg, arg[data_idx], arg[data_idx+1], arg[data_idx+2] and string.format("{%s}", arg[data_idx+2]) or "")
51 elseif cmd == "remove" then
52 msg = string.format("%s %s", msg, arg[data_idx])
55 local fd = p.socket(p.AF_INET, p.SOCK_STREAM, 0)
56 local s = p.connect(fd, {family=p.AF_INET, addr="127.0.0.1", port=port})
62 rsp = p.recv(fd, p.BUFSIZ)
64 if rsp and #rsp > 0 then