2
* Copyright (c) 1999 Hideki Sakurada
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
31
#define COMBUFSIZE 1024
32
char combuf[COMBUFSIZE];
34
#define CLIENT_END '0'
35
#define CLIENT_REQUEST '1'
36
#define CLIENT_VERSION '2'
37
#define CLIENT_HOST '3'
39
#define SERVER_ERROR '0'
40
#define SERVER_FOUND '1'
41
#define SERVER_NOT_FOUND '4'
42
#define SERVER_FULL '9'
44
char *version_string = "0.0";
46
/* declared in err.c */
48
extern int use_syslog;
53
struct dic *diclist[MAXDICNUM];
56
#define MAXENTNUM 1024
57
char *entlist[MAXENTNUM];
63
main(int argc, char *argv[]) {
74
/* process arguments */
75
while ((c = getopt(argc, argv, "l:f:sic:t")) != EOF) {
78
loglevel = atoi(optarg);
97
"usage: %s [-l digit] [-f logfile] [-s] [-c config] [dictinary1 ...] \n",
102
/* open logfile or syslog */
104
err(LOG_INFO, "%s started\n", argv[0]);
106
/* open dictionaries */
107
if ((dicnum = argc - optind) > MAXDICNUM) {
108
err(LOG_ERR, "too many %d dicts\n", argc - optind);
111
for (i = 0; i < dicnum; i++) {
112
err(LOG_DEBUG, "openning dictionary %s", argv[optind + i]);
113
diclist[i] = dic_open(argv[optind + i]);
119
fp = fopen(conf, "r");
121
err(LOG_ERR, "cannot open config file `%s'\n", conf);
124
while ((p = fgets(line, sizeof(line), fp)) != NULL) {
125
if (p[0] == '#' || p[0] == '\n')
127
p[strlen(p)-1] = '\0'; /* chop */
128
if (i >= MAXDICNUM) {
129
err(LOG_ERR, "too many dicts in config file\n");
132
err(LOG_DEBUG, "openning dictionary %s", p);
134
diclist[i++] = dic_open(p);
139
err(LOG_ERR, "no dict specified\n");
144
#ifdef DEBUG_FROM_TERMINAL
145
while (fgets(combuf, COMBUFSIZE, stdin) != NULL) {
147
while ((s = read(STDIN, combuf, COMBUFSIZE - 1)) > 0) {
157
write(STDOUT, version_string, strlen(version_string));
159
case CLIENT_HOST: /* not yet XXX */
160
write(STDOUT, "localhost:", strlen("localhost:"));
166
/* close dictionaries */
167
for (i = 0; i < dicnum; i++) {
168
diclist[i]->close(diclist[i]);
171
/* closing logfile or syslog */
172
err(LOG_DEBUG, "closing log\n");
191
if ((p = strchr(key, ' ')) == NULL) {
197
for (i = 0; i < dicnum; i++) {
198
if ((p = diclist[i]->search(diclist[i], key, keylen)) != NULL) {
199
if ((p = strtok(p, "/")) == NULL) {
200
err(LOG_ERR, "searchdicts: invalid entry %*s\n", keylen, key);
205
entlist[entnum++] = p;
206
if (entnum == MAXENTNUM) goto output;
208
} while ((p = strtok(NULL, "/\n")) != NULL);
215
combuf[0] = SERVER_NOT_FOUND;
216
fputs(combuf, stdout);
218
putchar(SERVER_FOUND);
219
for (i = 0; i < entnum; i++) {
221
fputs(entlist[i], stdout);
223
fputs("/\n", stdout);
229
int inentry(char *entry) {
231
for (i = 0; i < entnum; i++) {
232
if (strcmp(entry, entlist[i]) == 0) {