From 471334c3d07f398e4b0859c43276341a28b91504 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 2 Jul 2004 23:47:52 +0000 Subject: [PATCH] Fixed stupid bugs. --- etc/lp.lua | 4 +++- samples/lpr.lua | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/etc/lp.lua b/etc/lp.lua index e112ab4..3c36b11 100644 --- a/etc/lp.lua +++ b/etc/lp.lua @@ -26,10 +26,11 @@ local function connect(localhost, option) if option.localbind then -- bind to a local port (if we can) local localport = 721 + local done, err repeat skt = test(socket.tcp()) try(skt:settimeout(30)) - local done, err = skt:bind(localhost, localport) + done, err = skt:bind(localhost, localport) if not done then localport = localport + 1 skt:close() @@ -38,6 +39,7 @@ local function connect(localhost, option) until localport > 731 test(skt, err) else skt = test(socket.tcp()) end +print("'" .. host .. "'") try(skt:connect(host, port)) return { skt = skt, try = try } end diff --git a/samples/lpr.lua b/samples/lpr.lua index c23ebee..d743026 100644 --- a/samples/lpr.lua +++ b/samples/lpr.lua @@ -27,16 +27,14 @@ if not arg or not arg[1] then end do - local s="opt = {" - for i = 2 , table.getn(arg), 1 do - s = s .. string.gsub(arg[i],"[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)","%1%=\"%2\",\n") + local opt = {} + local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)" + for i = 2, table.getn(arg), 1 do + string.gsub(arg[i], pat, function(name, value) opt[name] = value end) end - s = s .. "};\n" - assert(loadstring(s))(); if not arg[2] then return usage() end - if arg[1] ~= "query" then r,e=lp.send(arg[1],opt) io.stdout:write(tostring(r or e),'\n')