From 17c4d1c30544f0ed638879835f179ada96249868 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 29 Dec 2000 22:15:09 +0000 Subject: Initial revision --- etc/dict.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 etc/dict.lua (limited to 'etc') diff --git a/etc/dict.lua b/etc/dict.lua new file mode 100644 index 0000000..683cb45 --- /dev/null +++ b/etc/dict.lua @@ -0,0 +1,39 @@ +-- 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") + send(s,w,"\r\n") + else + verbose(">>> looking up `",w,"'\n") + send(s,"DEFINE wn ",w,"\r\n") + end + while 1 do + local l=receive(s) + 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 + +send(s,"QUIT\r\n") +verbose("<<< ",receive(s),"\n") +close(s) -- cgit v1.2.3-55-g6feb