diff --git a/dictd/Makefile.in b/dictd/Makefile.in index ea1cb3f..f288dd3 100644 --- a/dictd/Makefile.in +++ b/dictd/Makefile.in @@ -70,7 +70,7 @@ LEXLIB= @LEXLIB@ CFLAGS= @CPPFLAGS@ @DEFS@ @CFLAGS@ -DDICT_PLUGIN_PATH=\"$(PLUGIN_DIR)/\" -DDICT_DICTIONARY_PATH=\"$(DICT_DIR)/\" -DDICT_VERSION=\"$(DICT_VERSION)\" -DDICT_CONFIG_PATH=\"$(CONF_DIR)/\" -I. -I$(srcdir) LIBMAA= @LIBMAA@ -LIBS= @LIBS@ ${LIBMAA} +LIBS= @LIBS@ ${LIBMAA} @NATSPEC_LIBS@ LDFLAGS= @LDFLAGS@ LIBOBJS= @LIBOBJS@ EXES= dict dictd dictzip dictfmt diff --git a/dictd/configure.in b/dictd/configure.in index 857d85d..2f10ca9 100644 --- a/dictd/configure.in +++ b/dictd/configure.in @@ -144,6 +144,9 @@ if test "x${withval}" != xno; then fi ]) +# Checks for libnatspec +AM_PATH_NATSPEC + AC_CHECK_LIB(socket,main) AC_CHECK_LIB(c,inet_ntoa, [true], diff --git a/dictd/dict.c b/dictd/dict.c index 2b831ec..d04ba59 100644 --- a/dictd/dict.c +++ b/dictd/dict.c @@ -22,6 +22,10 @@ #include "parse.h" #include "md5.h" #include +#include +#ifdef HAVE_NATSPEC +#include +#endif extern int yy_flex_debug; lst_List dict_Servers; @@ -103,6 +107,8 @@ static void set_ex_status (int status) #define EXST_INVALID_STRATEGY 40 #define EXST_CONNECTION_FAILED 41 +char *localcharset = ""; + struct def { lst_List data; const char *word; @@ -253,6 +259,8 @@ static lst_List client_read_text( int s ) lst_List l = lst_create(); char line[BUFFERSIZE]; int len; + char *source; + while ((len = net_read(s, line, BUFFERSIZE - 1)) >= 0) { line [len] = 0; @@ -260,10 +268,10 @@ static lst_List client_read_text( int s ) client_bytes += len; PRINTF(DBG_RAW,("* Text: %s\n",line)); if (line[0] == '.' && line[1] == '\0') break; + source = line; if (len >= 2 && line[0] == '.' && line[1] == '.') - lst_append( l, xstrdup(line + 1) ); - else - lst_append( l, xstrdup(line) ); + source++; + lst_append( l, natspec_convert(source, localcharset, "UTF-8", 3)); } if (len < 0) { client_close_pager(); @@ -769,12 +777,15 @@ end: /* Ready to send buffer, but are we cmd_reply.key = c->key; } if ((len = strlen(buffer))) { - char *pt; + char *pt, *decodedline; PRINTF(DBG_PIPE,("* Sending %d commands (%d bytes)\n",count,len)); PRINTF(DBG_RAW,("* Send/%d: %s",c->command,buffer)); - pt = alloca(2*len); - client_crlf(pt,buffer); + + decodedline = natspec_convert(buffer, "UTF-8", localcharset, 3); + pt = alloca(2*strlen(decodedline)); + client_crlf(pt, decodedline); + free(decodedline); net_write( cmd_reply.s, pt, strlen(pt) ); } else { PRINTF(DBG_PIPE,("* Sending nothing\n")); @@ -1289,6 +1300,7 @@ static void help( FILE *out_stream ) "-s --strategy strategy for matching or defining", "-c --config specify configuration file", "-C --nocorrect disable attempted spelling correction", + "-n --notranslate disable UTF-8 -> client encoding translation", "-D --dbs show available databases", "-S --strats show available search strategies", "-H --serverhelp show server help", @@ -1347,6 +1359,7 @@ int main( int argc, char **argv ) { "match", 0, 0, 'm' }, { "strategy", 1, 0, 's' }, { "nocorrect", 0, 0, 'C' }, + { "notranslate",0, 0, 'n' }, { "config", 1, 0, 'c' }, { "dbs", 0, 0, 'D' }, { "strats", 0, 0, 'S' }, @@ -1369,6 +1382,8 @@ int main( int argc, char **argv ) { 0, 0, 0, 0 } }; + setlocale(LC_CTYPE, ""); + dict_output = stdout; dict_error = stderr; @@ -1384,7 +1399,7 @@ int main( int argc, char **argv ) dbg_register( DBG_URL, "url" ); while ((c = getopt_long( argc, argv, - "h:p:d:i:Ims:DSHau:c:Ck:VLvrP:MfF", + "h:p:d:i:Imns:DSHau:c:Ck:VLvrP:MfF", longopts, NULL )) != EOF) { switch (c) { @@ -1394,6 +1409,7 @@ int main( int argc, char **argv ) case 'i': database = optarg; function |= INFO; break; case 'I': function |= SERVER; break; case 'm': function &= ~DEFINE; function |= MATCH; break; + case 'n': localcharset = "UTF-8"; break; case 's': strategy = optarg; break; case 'D': function |= DBS; break; case 'S': function |= STRATS; break; diff --git a/dictd/dictl.in b/dictd/dictl.in index 913c7ef..4727fbf 100755 --- a/dictd/dictl.in +++ b/dictd/dictl.in @@ -64,7 +64,7 @@ shquote (){ printf "%s\n" "'$__cmd'" } -cmd='dict' +cmd='dict -n' while test $# -ne 0; do cmd="$cmd "`shquote "$1"` shift