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
|
/* This file is part of GNU Dico.
Copyright (C) 1998-2018 Sergey Poznyakoff
GNU Dico is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Dico is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */
#include "dico-priv.h"
struct dico_url dico_url;
struct auth_cred default_cred;
char *client = DICO_CLIENT_ID;
enum dico_client_mode mode = mode_define;
int transcript;
char *source_addr;
int noauth_option;
unsigned levenshtein_threshold;
char *autologin_file;
int quiet_option;
int debug_level;
int debug_source_info;
dico_stream_t debug_stream;
void
fixup_url(void)
{
xdico_assign_string(&dico_url.proto, "dict");
if (!dico_url.host)
xdico_assign_string(&dico_url.host, DEFAULT_DICT_SERVER);
if (!dico_url.port)
xdico_assign_string(&dico_url.port, DICO_DICT_PORT_STR);
if (!dico_url.req.database)
xdico_assign_string(&dico_url.req.database, "!");
if (!dico_url.req.strategy)
xdico_assign_string(&dico_url.req.strategy, ".");
if (mode == mode_match)
dico_url.req.type = DICO_REQUEST_MATCH;
}
int
main(int argc, char **argv)
{
int index, rc = 0;
appi18n_init();
dico_set_program_name(argv[0]);
debug_stream = dico_dbg_stream_create();
parse_init_scripts();
get_options(argc, argv, &index);
fixup_url();
set_quoting_style(NULL, escape_quoting_style);
signal(SIGPIPE, SIG_IGN);
argc -= index;
argv += index;
switch (mode) {
case mode_define:
case mode_match:
if (!argc) {
dico_shell();
exit(0);
}
break;
default:
if (argc)
dico_log(L_WARN, 0,
_("extra command line arguments ignored"));
}
switch (mode) {
case mode_define:
case mode_match:
if (!argc)
dico_die(1, L_ERR, 0,
_("you should give a word to look for or an URL"));
while (argc--)
rc |= dict_word((*argv)++) != 0;
break;
case mode_dbs:
rc = dict_single_command("SHOW DATABASES", NULL, "110");
break;
case mode_strats:
rc = dict_single_command("SHOW STRATEGIES", NULL, "111");
break;
case mode_help:
rc = dict_single_command("HELP", NULL, "113");
break;
case mode_info:
if (!dico_url.req.database)
dico_die(1, L_ERR, 0, _("Database name not specified"));
rc = dict_single_command("SHOW INFO", dico_url.req.database, "112");
break;
case mode_server:
rc = dict_single_command("SHOW SERVER", NULL, "114");
break;
}
return rc;
}
|