1 /*
2 * Compound Text word statistics and search report
3 *
4 * extend.c : command line & definition parameter extention
5 *
6 * Copyright(c) isao yasuda, 1998
7 */
8 static char *rcs_id = "$Id: extend.c,v 1.3 2008/05/04 13:08:03 isao Exp $";
9
10 #include <stdio.h>
11 #include <string.h>
12 #include "staslova.h"
13 #include "table.h"
14
15 int
16 extender(int argc, char **argv)
17 {
18 int c;
19 int rtn = 0;
20 char *fn;
21 char *un;
22 char *pn = *argv;
23 unsigned char line[MAXLINE+1];
24 FILE *fp = NULL;
25
26 /* command line option parse */
27 while (--argc > 0 && (*++argv)[0] == '-')
28 while (c = *++argv[0])
29 switch (c) {
30 case 's': /* statistics report only */
31 task = STAT;
32 break;
33 case 'm': /* matching test only */
34 task = MTCT;
35 break;
36 case 'a': /* both statistics & matching test */
37 task = STAT | MTCT;
38 break;
39 case 'd': /* definition file */
40 if ((fn = (char *)strchr(++(*argv), '\n')) != NULL)
41 sprintf(fn, "\0");
42 fn = (char *)*argv;
43 if ((fp = fopen(fn, "r")) == NULL) {
44 perror("fopen");
45 return 2;
46 }
47 while (*(++argv[0]+1));
48 break;
49 case 'p': /* max pos count */
50 if ((un = (char *)strchr(++(*argv), '\n')) != NULL)
51 sprintf(un, "\0");
52 un = (char *)*argv;
53 if ((usrwdptc = atoi(un)) > MAXWDPTC) {
54 fprintf(stderr, "%s: max print size of word position list %d over: %d\n", pn, MAXWDPTC, usrwdptc);
55 return 1;
56 }
57 while (*(++argv[0]+1));
58 break;
59 case 'c': /* case, lower convert test or not*/
60 switch (c = *++argv[0]) {
61 case '0': /* lower convert mode */
62 case '1': /* as is without lower conversion */
63 casemode = c;
64 break;
65 default : /* unsuported, error */
66 fprintf(stderr, "%s: illegal option %c\n", pn, c);
67 return 1;
68 }
69 break;
70 case 'o': /* output level */
71 switch (c = *++argv[0]) {
72 case '0': /* statistics value only */
73 case '1': /* sta. value, match words & address */
74 case '2': /* sta. value, match words, address and text fragment */
75 outmode = c;
76 break;
77 default : /* unsuported, error */
78 fprintf(stderr, "%s: illegal option %c\n", pn, c);
79 return 1;
80 }
81 break;
82 case 'l': /* language preference */
83 switch (c = *++argv[0]) {
84 case '0': /* JIS > Cyrillic > Latin */
85 lprf[0] = JIS; langname[0] = langjis;
86 lprf[1] = CYRIL; langname[1] = langcyr;
87 lprf[2] = (ASCII | LATIN1 | LATIN2 | OTHER);
88 langname[2] = langlat;
89 break;
90 case '1': /* JIS > Latin > Cyrillic */
91 lprf[0] = JIS; langname[0] = langjis;
92 lprf[2] = CYRIL; langname[2] = langcyr;
93 lprf[1] = (ASCII | LATIN1 | LATIN2 | OTHER);
94 langname[1] = langlat;
95 break;
96 case '2': /* Cyrillic > JIS > Latin */
97 lprf[1] = JIS; langname[1] = langjis;
98 lprf[0] = CYRIL; langname[0] = langcyr;
99 lprf[2] = (ASCII | LATIN1 | LATIN2 | OTHER);
100 langname[2] = langlat;
101 break;
102 case '3': /* Cyrillic > Latin > JIS */
103 lprf[2] = JIS; langname[2] = langjis;
104 lprf[0] = CYRIL; langname[0] = langcyr;
105 lprf[1] = (ASCII | LATIN1 | LATIN2 | OTHER);
106 langname[1] = langlat;
107 break;
108 case '4': /* Latin > JIS > Cyrillic */
109 lprf[1] = JIS; langname[1] = langjis;
110 lprf[2] = CYRIL; langname[2] = langcyr;
111 lprf[0] = (ASCII | LATIN1 | LATIN2 | OTHER);
112 langname[0] = langlat;
113 break;
114 case '5': /* Latin > Cyrillic > JIS */
115 lprf[2] = JIS; langname[2] = langjis;
116 lprf[1] = CYRIL; langname[1] = langcyr;
117 lprf[0] = (ASCII | LATIN1 | LATIN2 | OTHER);
118 langname[0] = langlat;
119 break;
120 default : /* unsuported, error */
121 fprintf(stderr, "%s: illegal option %c\n", pn, c);
122 return 1;
123 }
124 break;
125 case 'h': /* help */
126 return 3;
127 default: /* error */
128 fprintf(stderr, "%s: illegal option %c\n", pn, c);
129 return 1;
130 }
131 if (argc != 0) {
132 fprintf(stderr, "%s: illegal option %c\n", pn, (*argv)[0]);
133 return 1;
134 }
135
136 /* definition file read & command parameter extension */
137 if (fp != NULL) {
138 while (fgets(line, sizeof(line), fp) != NULL)
139 if (*line != '#' && *line != ' ' && *line != '\n')
140 if (task == STAT) {
141 if (*line == 'k' || *line == 'j')
142 rtn |= sepextend(line);
143 } else {
144 if (*line == 'k' || *line == 'j')
145 rtn |= sepextend(line);
146 else if (*line == 's')
147 rtn |= condextend(line + 3);
148 else {
149 fprintf(stderr, "Unexpected command %s", line);
150 rtn |= 1;
151 }
152 }
153 fclose(fp);
154 }
155 return rtn;
156 }
157
158
159