mcbot/cmds/dict.lua
changeset 42 99477d3c2dda
parent 16 064a50911e05
child 66 d9c00a9fe9d5
equal deleted inserted replaced
41:5c0a2db896f5 42:99477d3c2dda
     9 
     9 
    10     local cmd = "/usr/bin/dict "..word.." 2> /dev/null"
    10     local cmd = "/usr/bin/dict "..word.." 2> /dev/null"
    11     local fh = io.popen(cmd)
    11     local fh = io.popen(cmd)
    12     result = fh:read("*a")  -- read dict output
    12     result = fh:read("*a")  -- read dict output
    13     fh:close()
    13     fh:close()
    14     if result:match("^$") then return nil, "dict: No output" end
    14     if not result or result:match("^$") then return nil, "dict: No output" end
    15 
    15 
    16     -- Sometimes dict outpur is ugly... Let's filter out whitespace.
    16     -- Sometimes dict outpur is ugly... Let's filter out whitespace.
    17     result = result:gsub("[ \t]+\n", "\n"):gsub("\n\n\n+", "\n\n")
    17     result = result:gsub("[ \t]+\n", "\n"):gsub("\n\n\n+", "\n\n")
    18     -- Trim trailing newlines
    18     -- Trim trailing newlines
    19     result = result:gsub("\n+$", "")
    19     result = result:gsub("\n+$", "")