diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-21 07:04:44 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-21 07:04:44 +0000 |
| commit | a2b780bf7a78c66d54a248fa99b5fc862c12a127 (patch) | |
| tree | a9377a265f47439952c9100c594ed789117d9063 /etc | |
| parent | 71f483496de874f1200526816528b7b2a4e9e4a6 (diff) | |
| download | luasocket-a2b780bf7a78c66d54a248fa99b5fc862c12a127.tar.gz luasocket-a2b780bf7a78c66d54a248fa99b5fc862c12a127.tar.bz2 luasocket-a2b780bf7a78c66d54a248fa99b5fc862c12a127.zip | |
Spell checking on the manuals.
David's changes to lp.lua.
Diffstat (limited to 'etc')
| -rw-r--r-- | etc/lp.lua | 24 |
1 files changed, 14 insertions, 10 deletions
| @@ -11,6 +11,8 @@ | |||
| 11 | -- make sure LuaSocket is loaded | 11 | -- make sure LuaSocket is loaded |
| 12 | local io = require("io") | 12 | local io = require("io") |
| 13 | local base = _G | 13 | local base = _G |
| 14 | local os = require("os") | ||
| 15 | local math = require("math") | ||
| 14 | local string = require("string") | 16 | local string = require("string") |
| 15 | local socket = require("socket") | 17 | local socket = require("socket") |
| 16 | local ltn12 = require("ltn12") | 18 | local ltn12 = require("ltn12") |
| @@ -192,6 +194,7 @@ local function send_data(con,fh,size) | |||
| 192 | con.try(size == 0, "file size mismatch") | 194 | con.try(size == 0, "file size mismatch") |
| 193 | end | 195 | end |
| 194 | end | 196 | end |
| 197 | recv_ack(con) -- note the double acknowledgement | ||
| 195 | send_ack(con) | 198 | send_ack(con) |
| 196 | recv_ack(con) | 199 | recv_ack(con) |
| 197 | return size | 200 | return size |
| @@ -224,7 +227,7 @@ local control_dflt = { | |||
| 224 | local seq = 0 | 227 | local seq = 0 |
| 225 | local function newjob(connection) | 228 | local function newjob(connection) |
| 226 | seq = seq + 1 | 229 | seq = seq + 1 |
| 227 | return math.floor(socket.gettime() * 1000 + seq) | 230 | return math.floor(socket.gettime() * 1000 + seq)%1000 |
| 228 | end | 231 | end |
| 229 | 232 | ||
| 230 | 233 | ||
| @@ -241,22 +244,24 @@ local format_codes = { | |||
| 241 | f = 'f' | 244 | f = 'f' |
| 242 | } | 245 | } |
| 243 | 246 | ||
| 244 | -- lp.send | 247 | -- lp.send{option} |
| 248 | -- requires option.file | ||
| 245 | 249 | ||
| 246 | send = socket.protect(function(file, option) | 250 | send = socket.protect(function(option) |
| 247 | socket.try(file, "invalid file name") | ||
| 248 | socket.try(option and base.type(option) == "table", "invalid options") | 251 | socket.try(option and base.type(option) == "table", "invalid options") |
| 252 | local file = option.file | ||
| 253 | socket.try(file, "invalid file name") | ||
| 249 | local fh = socket.try(io.open(file,"rb")) | 254 | local fh = socket.try(io.open(file,"rb")) |
| 250 | local datafile_size = fh:seek("end") -- get total size | 255 | local datafile_size = fh:seek("end") -- get total size |
| 251 | fh:seek("set") -- go back to start of file | 256 | fh:seek("set") -- go back to start of file |
| 252 | local localhost = socket.dns.gethostname() or os.getenv("COMPUTERNAME") | 257 | local localhost = socket.dns.gethostname() or os.getenv("COMPUTERNAME") |
| 253 | or "localhost" | 258 | or "localhost" |
| 254 | local con = connect(localhost, option) | 259 | local con = connect(localhost, option) |
| 255 | -- format the control file | 260 | -- format the control file |
| 256 | local jobno = newjob() | 261 | local jobno = newjob() |
| 257 | local localip = socket.dns.toip(localhost) | 262 | local localip = socket.dns.toip(localhost) |
| 258 | localhost = string.sub(localhost,1,31) | 263 | localhost = string.sub(localhost,1,31) |
| 259 | local user = string.sub(option.user or os.getenv("LPRUSER") or | 264 | local user = string.sub(option.user or os.getenv("LPRUSER") or |
| 260 | os.getenv("USERNAME") or os.getenv("USER") or "anonymous", 1,31) | 265 | os.getenv("USERNAME") or os.getenv("USER") or "anonymous", 1,31) |
| 261 | local lpfile = string.format("dfA%3.3d%-s", jobno, localhost); | 266 | local lpfile = string.format("dfA%3.3d%-s", jobno, localhost); |
| 262 | local fmt = format_codes[option.format] or 'l' | 267 | local fmt = format_codes[option.format] or 'l' |
| @@ -306,15 +311,14 @@ end) | |||
| 306 | -- | 311 | -- |
| 307 | query = socket.protect(function(p) | 312 | query = socket.protect(function(p) |
| 308 | p = p or {} | 313 | p = p or {} |
| 309 | local localhost = socket.dns.gethostname() or os.getenv("COMPUTERNAME") | 314 | local localhost = socket.dns.gethostname() or os.getenv("COMPUTERNAME") |
| 310 | or "localhost" | 315 | or "localhost" |
| 311 | local con = connect(localhost,p) | 316 | local con = connect(localhost,p) |
| 312 | local fmt | 317 | local fmt |
| 313 | if string.sub(p.format or 's',1,1) == 's' then fmt = 3 else fmt = 4 end | 318 | if string.sub(p.format or 's',1,1) == 's' then fmt = 3 else fmt = 4 end |
| 314 | con.try(con.skt:send(string.format("%c%s %s\n", fmt, p.queue or "*", | 319 | con.try(con.skt:send(string.format("%c%s %s\n", fmt, p.queue or "*", |
| 315 | p.list or ""))) | 320 | p.list or ""))) |
| 316 | local data = con.try(con.skt:receive("*a")) | 321 | local data = con.try(con.skt:receive("*a")) |
| 317 | con.skt:close() | 322 | con.skt:close() |
| 318 | return data | 323 | return data |
| 319 | end) | 324 | end) |
| 320 | |||
