2000-12-29 23:15:09 +01:00
|
|
|
-- dict.lua
|
|
|
|
-- simple client for DICT protocol (see http://www.dict.org/)
|
|
|
|
-- shows definitions for each word from stdin. uses only "wn" dictionary.
|
|
|
|
-- if a word is "=", then the rest of the line is sent verbatim as a protocol
|
|
|
|
-- command to the server.
|
|
|
|
|
|
|
|
if verbose then verbose=write else verbose=function()end end
|
|
|
|
|
|
|
|
verbose(">>> connecting to server\n")
|
|
|
|
local s,e=connect("dict.org",2628)
|
|
|
|
assert(s,e)
|
|
|
|
verbose(">>> connected\n")
|
|
|
|
|
|
|
|
while 1 do
|
|
|
|
local w=read"*w"
|
|
|
|
if w==nil then break end
|
|
|
|
if w=="=" then
|
|
|
|
w=read"*l"
|
|
|
|
verbose(">>>",w,"\n")
|
2001-03-06 20:46:42 +01:00
|
|
|
s:send(w,"\r\n")
|
2000-12-29 23:15:09 +01:00
|
|
|
else
|
|
|
|
verbose(">>> looking up `",w,"'\n")
|
2001-03-06 20:46:42 +01:00
|
|
|
s:send("DEFINE wn ",w,"\r\n")
|
2000-12-29 23:15:09 +01:00
|
|
|
end
|
|
|
|
while 1 do
|
2001-03-06 20:46:42 +01:00
|
|
|
local l=s:receive()
|
2000-12-29 23:15:09 +01:00
|
|
|
if l==nil then break end
|
|
|
|
if strfind(l,"^[0-9]") then
|
|
|
|
write("<<< ",l,"\n")
|
|
|
|
else
|
|
|
|
write(l,"\n")
|
|
|
|
end
|
|
|
|
if strfind(l,"^250") or strfind(l,"^[45]") then break end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2001-03-06 20:46:42 +01:00
|
|
|
s:send("QUIT\r\n")
|
|
|
|
verbose("<<< ",s:receive(),"\n")
|
|
|
|
s:close()
|