/usr/share/jed/jed-extra/dict-cli.sl is in jed-extra 2.5.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | % dict-cli.sl: dict backend using the command line interface `dict`
%
% Copyright © 2005 Günter Milde (milde users.sf.net)
% Released under the terms of the GNU General Public License (ver. 2 or later)
%
% Versions:
% 0.1 2006-03-13 first public version
% 0.1.1 2006-09-25 use do_shell_cmd() for error redirection
provide("dict-backend");
provide("dict-cli");
% Requirements
% ------------
% * `dict` command line dict-client (see Dict_Cmd)
%!%+
%\variable{Dict_Cmd}
%\synopsis{Command line program for dict lookup}
%\usage{variable Dict_Cmd = "dict"}
%\description
% The command line program for dict lookup (on most systems this will be
% "dict"). An alternative is "dictl", a wrapper for conversion of|from UTF8
% into the users locale)
%\example
% To use the "dictl" wrapper if the current locale is not utf8 aware put in
% ~/.jed/jed.rc (or ~/.jedrc)
%#v+
% if (_slang_utf8_ok)
% variable Dict_Cmd = "dict";
% else
% variable Dict_Cmd = "dictl";
%#v-
%\seealso{dict, dict_mode, Dict_Server, Dict_DB}
%!%-
custom_variable("Dict_Cmd", "dict");
% cache for dict_show results
static variable show_cache = Assoc_Type[String_Type];
static variable last_host = "";
% transform host argument to command line option(s)
% "host" --> "--host <host>"
% "host:port" --> "--host <host> --port <port>"
private define parse_host(host)
{
host = strtok(host, ":");
return "--host " + strjoin(host, " --port ");
}
define dict_define(word, database, host)
{
variable db, cmd;
foreach db (strtok(database, ","))
{
cmd = sprintf("%s --database '%s' %s '%s'",
Dict_Cmd, db, parse_host(host), word);
set_prefix_argument(1);
do_shell_cmd(cmd);
}
}
% insert the result of the MATCH command into the current buffer
define dict_match(word, strategy, database, host)
{
variable db, cmd;
foreach db (strtok(database, ","))
{
cmd = sprintf("%s --database '%s' %s --match --strategy %s '%s'",
Dict_Cmd, db, parse_host(host), strategy, word);
set_prefix_argument(1);
do_shell_cmd(cmd);
}
}
% insert the result of the SHOW command into the current buffer
define dict_show(what, host)
{
if (host != last_host)
{
show_cache = Assoc_Type[String_Type]; % reset cache
last_host = host;
}
% if the result is cashed, insert and return
if (assoc_key_exists(show_cache, what))
return insert(show_cache[what]);
% what --> option
switch (what)
{ case "db": what = "--dbs"; }
{ case "strat": what = "--strats"; }
{ case "server": what = "--serverinfo"; }
{ is_substr(what, "info"): % convert "info:<db>" to "-- info <db>"
what = strtok(what, ":");
what = "--info " + strjoin(what, " ");
}
{ error("argument must be one of 'db', 'strat', 'server', info:<db>"); }
set_prefix_argument(1);
do_shell_cmd(sprintf("%s %s %s", Dict_Cmd, parse_host(host), what));
% cache result
mark_buffer();
show_cache[what] = bufsubstr();
}
#iffalse
% Build a dict:// URL for the query defined by the arguments in the form
% dict://host:port/d:word:database
% dict://host:port/m:word:database:strategy
% (see `man dict` or section 5. "URL Specification" of RFC2229)
variable db, urls, url;
if (is_substr(word, "dict://") == 1)
urls = [word];
else if (strategy == NULL) % definition lookup
urls = array_map(String_Type, &sprintf, "dict://%s/d:%s:%s",
Dict_Server, word, strtok(database, ","));
else
urls = array_map(String_Type, &sprintf, "dict://%s/m:%s:%s:%s",
Dict_Server, word, strtok(database, ","), strategy);
#endif
|