Subversion Repositories wimsdev

Rev

Rev 3718 | Rev 8086 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3718 Rev 8084
Line 13... Line 13...
13
 *  You should have received a copy of the GNU General Public License
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
16
 */
17
 
17
 
18
        /* This program makes comparison between two text strings,
18
/* This program makes comparison between two text strings,
19
         * according to the symtext syntax. */
19
 * according to the symtext syntax. */
20
 
20
 
21
/* Input data: via environment variables.
21
/* Input data: via environment variables.
22
 * wims_exec_parm: line 1 = command (comp,expand,wordlist,random,1,2,3,...)
22
 * wims_exec_parm: line 1 = command (comp,expand,wordlist,random,1,2,3,...)
23
 * line 2 = text to examine (for comp).
23
 * line 2 = text to examine (for comp).
24
 * line 3 and up = symtext syntax.
24
 * line 3 and up = symtext syntax.
25
 * w_symtext: dictionary style.
25
 * w_symtext: dictionary style.
26
 * w_symtext_option: option words.
26
 * w_symtext_option: option words.
27
 *
27
 *
28
 * Output: two lines.
28
 * Output: two lines.
29
 * Line 1: ERROR or OK
29
 * Line 1: ERROR or OK
30
 * Line 2: result depending on command.
30
 * Line 2: result depending on command.
31
 */
31
 */
32
 
32
 
Line 44... Line 44...
44
 
44
 
45
struct poolstruct poolbuf[MAX_POOLS];
45
struct poolstruct poolbuf[MAX_POOLS];
46
int nextpool;
46
int nextpool;
47
 
47
 
48
int options;
48
int options;
49
#define op_nocase       (1<<0)
49
#define op_nocase    (1<<0)
50
#define op_deaccent     (1<<1)
50
#define op_deaccent  (1<<1)
51
#define op_reaccent     (1<<2)
51
#define op_reaccent  (1<<2)
52
#define op_nopunct      (1<<3)
52
#define op_nopunct   (1<<3)
53
#define op_nomath       (1<<4)
53
#define op_nomath    (1<<4)
54
#define op_noparenth    (1<<5)
54
#define op_noparenth (1<<5)
55
#define op_nocs         (1<<6)
55
#define op_nocs      (1<<6)
56
#define op_noquote      (1<<7)
56
#define op_noquote   (1<<7)
57
#define op_matchall     (1<<8)
57
#define op_matchall  (1<<8)
58
#define op_alphaonly    (1<<9)
58
#define op_alphaonly (1<<9)
59
#define op_alnumonly    (1<<10)
59
#define op_alnumonly (1<<10)
60
 
60
 
61
char cmdbuf[256], stbuf[MAX_LINELEN+1], textbuf[MAX_LINELEN+1];
61
char cmdbuf[256], stbuf[MAX_LINELEN+1], textbuf[MAX_LINELEN+1];
62
char wbuf[MAX_LINELEN+1];
62
char wbuf[MAX_LINELEN+1];
63
char cmdparm[1024];
63
char cmdparm[1024];
64
char defbuf[MAX_LINELEN+1];
64
char defbuf[MAX_LINELEN+1];
Line 73... Line 73...
73
    cmd_none, cmd_comp, cmd_debug, cmd_random, cmd_1, cmd_wordlist
73
    cmd_none, cmd_comp, cmd_debug, cmd_random, cmd_1, cmd_wordlist
74
};
74
};
75
struct {
75
struct {
76
    char *name; int value;
76
    char *name; int value;
77
} cmdlist[]={
77
} cmdlist[]={
78
    {"1",       cmd_1},
78
    {"1",       cmd_1},
79
    {"comp",    cmd_comp},
79
    {"comp",    cmd_comp},
80
    {"compare", cmd_comp},
80
    {"compare", cmd_comp},
81
    {"debug",   cmd_debug},
81
    {"debug",   cmd_debug},
82
    {"match",   cmd_comp},
82
    {"match",   cmd_comp},
83
    {"rand",    cmd_random},
83
    {"rand",    cmd_random},
84
    {"random",  cmd_random},
84
    {"random",  cmd_random},
85
    {"wordlist",cmd_wordlist},
85
    {"wordlist",cmd_wordlist},
86
    {"words",   cmd_wordlist}
86
    {"words",   cmd_wordlist}
87
};
87
};
88
#define cmdcnt (sizeof(cmdlist)/sizeof(cmdlist[0]))
88
#define cmdcnt (sizeof(cmdlist)/sizeof(cmdlist[0]))
89
int cmd;
89
int cmd;
90
 
90
 
91
void error(char *msg,...)
91
void error(char *msg,...)
Line 103... Line 103...
103
void _error(char *msg)
103
void _error(char *msg)
104
{
104
{
105
    error(msg);
105
    error(msg);
106
}
106
}
107
 
107
 
108
        /* read-in a file into buffer. Use open() and read().
108
/* read-in a file into buffer. Use open() and read().
109
         * Return buffer address which will be malloc'ed if buf=NULL. */
109
 * Return buffer address which will be malloc'ed if buf=NULL.
-
 
110
 */
110
char *readfile(char *fname, char buf[], long int buflen)
111
char *readfile(char *fname, char buf[], long int buflen)
111
{
112
{
112
    int fd, t;
113
    int fd, t;
113
    struct stat st;
114
    struct stat st;
114
    long int l, lc;
115
    long int l, lc;
115
    char *bf;
116
    char *bf;
116
    t=0; if(buf) buf[0]=0;
117
    t=0; if(buf) buf[0]=0;
117
    if(stat(fname,&st)) return NULL;
118
    if(stat(fname,&st)) return NULL;
118
    l=st.st_size; if(l<0) return NULL;
119
    l=st.st_size; if(l<0) return NULL;
119
    if(l>=buflen) {
120
    if(l>=buflen) {
120
        if(buflen<MAX_LINELEN) l=buflen-1;
121
     if(buflen<MAX_LINELEN) l=buflen-1;
121
        else error("file_too_long %s",fname);
122
     else error("file_too_long %s",fname);
122
    }
123
    }
123
    fd=open(fname,O_RDONLY); if(fd==-1) return NULL;
124
    fd=open(fname,O_RDONLY); if(fd==-1) return NULL;
124
    if(buf==NULL) bf=xmalloc(l+8); else {bf=buf;if(l==0) {t=1; l=buflen-1;}}
125
    if(buf==NULL) bf=xmalloc(l+8); else {bf=buf;if(l==0) {t=1; l=buflen-1;}}
125
    lc=read(fd,bf,l); close(fd);
126
    lc=read(fd,bf,l); close(fd);
126
    if(lc<0 || lc>l || (lc!=l && t==0))
127
    if(lc<0 || lc>l || (lc!=l && t==0))
127
        {if(buf==NULL) free(bf); else buf[0]=0; return NULL;}
128
      {if(buf==NULL) free(bf); else buf[0]=0; return NULL;}
128
    bf[lc]=0; _tolinux(bf); return bf;
129
    bf[lc]=0; _tolinux(bf); return bf;
129
}
130
}
130
 
131
 
131
        /* get option word in a string */
132
/* get option word in a string */
132
void _getopt(char *name, char *p)
133
void _getopt(char *name, char *p)
133
{
134
{
134
    char *p1, *p2, *p3, *p4;
135
    char *p1, *p2, *p3, *p4;
135
    char buf[MAX_LINELEN+1];
136
    char buf[MAX_LINELEN+1];
136
   
137
 
137
    snprintf(buf,sizeof(buf),"%s",p);
138
    snprintf(buf,sizeof(buf),"%s",p);
138
    p1=find_word_start(name);
139
    p1=find_word_start(name);
139
    for(p2=buf;*p2;p2++) {
140
    for(p2=buf;*p2;p2++) {
140
        if(myisspace(*p2)) *p2=' ';
141
      if(myisspace(*p2)) *p2=' ';
141
        if(*p2=='=') *p2='      ';
142
      if(*p2=='=') *p2='        ';
142
    }
143
    }
143
    *p=0;
144
    *p=0;
144
    p2=wordchr(buf,p1); if(p2==NULL) return;
145
    p2=wordchr(buf,p1); if(p2==NULL) return;
145
    for(p3=find_word_end(p2);myisspace(*p3);p3++) {
146
    for(p3=find_word_end(p2);myisspace(*p3);p3++) {
146
        if(*p3=='       ') {
147
      if(*p3==' ') {
147
            p3=find_word_start(p3);
148
         p3=find_word_start(p3);
148
            switch(*p3) {
149
         switch(*p3) {
149
                case '"': {
150
            case '"': {
150
                    p4=strchr(p3+1,'"');
151
              p4=strchr(p3+1,'"');
151
                    goto tested;
152
              goto tested;
152
                }
153
            }
153
                case '(': {
154
            case '(': {
154
                    p4=find_matching(p3+1,')');
155
              p4=find_matching(p3+1,')');
155
                    goto tested;
156
              goto tested;
156
                }
157
            }
157
                case '[': {
158
            case '[': {
158
                    p4=find_matching(p3+1,']');
159
              p4=find_matching(p3+1,']');
159
                    goto tested;
160
              goto tested;
160
                }
161
            }
161
                case '{': {
162
            case '{': {
162
                    p4=find_matching(p3+1,'}');
163
              p4=find_matching(p3+1,'}');
163
                    tested:
164
              tested:
164
                    if(p4) {
165
              if(p4) {
165
                        p3++; *p4=0; break;
166
                p3++; *p4=0; break;
166
                    }
167
              }
167
                    else goto nomatch;
168
              else goto nomatch;
168
                }
169
          }
169
                default: {
170
          default: {
170
                    nomatch:
171
              nomatch:
171
                    *find_word_end(p3)=0;
172
              *find_word_end(p3)=0;
172
                }
173
          }
173
            }
174
         }
174
            mystrncpy(p,p3,MAX_LINELEN);
175
         mystrncpy(p,p3,MAX_LINELEN);
175
            return;
176
         return;
176
        }
177
       }
177
    }
178
    }
178
    *find_word_end(p2)=0;
179
    *find_word_end(p2)=0;
179
    memmove(p,p2,strlen(p2)+1);
180
    memmove(p,p2,strlen(p2)+1);
180
}
181
}
181
 
182
 
182
void _getdef(char buf[], char *name, char value[])
183
void _getdef(char buf[], char *name, char value[])
183
{
184
{
184
    char *p1, *p2, *p3, *p4;
185
    char *p1, *p2, *p3, *p4;
185
 
186
 
186
    if(*name==0) goto nothing;  /* this would create segfault. */
187
    if(*name==0) goto nothing;     /* this would create segfault. */
187
    for(p1=strstr(buf,name); p1!=NULL; p1=strstr(p1+1,name)) {
188
    for(p1=strstr(buf,name); p1!=NULL; p1=strstr(p1+1,name)) {
188
        p2=find_word_start(p1+strlen(name));
189
     p2=find_word_start(p1+strlen(name));
189
        if((p1>buf && !isspace(*(p1-1))) || *p2!='=') continue;
190
     if((p1>buf && !isspace(*(p1-1))) || *p2!='=') continue;
190
        p3=p1; while(p3>buf && *(p3-1)!='\n') p3--;
191
     p3=p1; while(p3>buf && *(p3-1)!='\n') p3--;
191
        p3=find_word_start(p3);
192
     p3=find_word_start(p3);
192
        if(p3<p1 && *p3!='!') continue;
193
     if(p3<p1 && *p3!='!') continue;
193
        if(p3<p1) {
194
     if(p3<p1) {
194
            p3++; p4=find_word_end(p3);
195
         p3++; p4=find_word_end(p3);
195
            if(find_word_start(p4)!=p1) continue;
196
         if(find_word_start(p4)!=p1) continue;
196
            if(p4-p3!=3 || (strncmp(p3,"set",3)!=0 &&
197
         if(p4-p3!=3 || (strncmp(p3,"set",3)!=0 &&
197
               strncmp(p3,"let",3)!=0 &&
198
            strncmp(p3,"let",3)!=0 &&
198
               strncmp(p3,"def",3)!=0)) {
199
            strncmp(p3,"def",3)!=0)) {
199
                if(p4-p3!=6 || strncmp(p3,"define",6)!=0) continue;
200
           if(p4-p3!=6 || strncmp(p3,"define",6)!=0) continue;
200
            }
201
         }
201
        }
202
     }
202
        p2++;p3=strchr(p2,'\n'); if(p3==NULL) p3=p2+strlen(p2);
203
     p2++;p3=strchr(p2,'\n'); if(p3==NULL) p3=p2+strlen(p2);
203
        p2=find_word_start(p2);
204
     p2=find_word_start(p2);
204
        if(p2>p3) goto nothing;
205
     if(p2>p3) goto nothing;
205
        if(p3-p2>=MAX_LINELEN) error("string_too_long def %s",name);
206
     if(p3-p2>=MAX_LINELEN) error("string_too_long def %s",name);
206
        memmove(value,p2,p3-p2); value[p3-p2]=0;
207
     memmove(value,p2,p3-p2); value[p3-p2]=0;
207
        strip_trailing_spaces(value); return;
208
     strip_trailing_spaces(value); return;
208
    }
209
    }
209
nothing:
210
nothing:
210
    value[0]=0; return;
211
    value[0]=0; return;
211
}
212
}
212
 
213
 
213
char fnbuf[MAX_FNAME+1];
214
char fnbuf[MAX_FNAME+1];
214
 
215
 
215
        /* make a filename and check length */
216
/* make a filename and check length */
216
char *mkfname(char buf[], char *s,...)
217
char *mkfname(char buf[], char *s,...)
217
{
218
{
218
    va_list vp;
219
    va_list vp;
219
    char *p;
220
    char *p;
220
 
221
 
Line 235... Line 236...
235
{
236
{
236
    char *p, *p2, *p3, lbuf[8];
237
    char *p, *p2, *p3, lbuf[8];
237
    char buf[MAX_LINELEN+1], pbuf[MAX_LINELEN+1];
238
    char buf[MAX_LINELEN+1], pbuf[MAX_LINELEN+1];
238
    struct stat st;
239
    struct stat st;
239
    int i;
240
    int i;
240
   
241
 
241
    cmd=0;
242
    cmd=0;
242
    p=getenv("wims_exec_parm");
243
    p=getenv("wims_exec_parm");
243
    if(p==NULL) return;
244
    if(p==NULL) return;
244
    snprintf(pbuf,sizeof(pbuf),"%s",p);
245
    snprintf(pbuf,sizeof(pbuf),"%s",p);
245
    rows2lines(pbuf);
246
    rows2lines(pbuf);
246
    p2=strchr(pbuf,'\n'); if(p2==NULL) return; else *p2++=0;
247
    p2=strchr(pbuf,'\n'); if(p2==NULL) return; else *p2++=0;
247
    p=find_word_start(pbuf);
248
    p=find_word_start(pbuf);
248
    p3=find_word_end(p); if(p3-p>=sizeof(cmdbuf)) return;
249
    p3=find_word_end(p); if(p3-p>=sizeof(cmdbuf)) return;
249
    if(*p==0) return; else *p3++=0;
250
    if(*p==0) return; else *p3++=0;
250
    memmove(cmdbuf,p,p3-p); cmdbuf[p3-p]=0;
251
    memmove(cmdbuf,p,p3-p); cmdbuf[p3-p]=0;
251
    p=p2; p2=strchr(p,'\n'); if(p2==NULL) p2=p+strlen(p); else *p2++=0;
252
    p=p2; p2=strchr(p,'\n'); if(p2==NULL) p2=p+strlen(p); else *p2++=0;
252
    if(p2<=find_word_start(p)) return;
253
    if(p2<=find_word_start(p)) return;
253
    if(p2-p<sizeof(textbuf)) {
254
    if(p2-p<sizeof(textbuf)) {
254
        memmove(textbuf,p,p2-p); textbuf[p2-p]=0;
255
       memmove(textbuf,p,p2-p); textbuf[p2-p]=0;
255
    }
256
    }
256
    p=p2; p2=p+strlen(p);
257
    p=p2; p2=p+strlen(p);
257
    if(p2>p && p2-p<sizeof(stbuf)) {
258
    if(p2>p && p2-p<sizeof(stbuf)) {
258
        memmove(stbuf,p,p2-p); stbuf[p2-p]=0;
259
     memmove(stbuf,p,p2-p); stbuf[p2-p]=0;
259
    }
260
    }
260
    i=search_list(cmdlist,cmdcnt,sizeof(cmdlist[0]),cmdbuf);
261
    i=search_list(cmdlist,cmdcnt,sizeof(cmdlist[0]),cmdbuf);
261
    if(i>=0) cmd=cmdlist[i].value;
262
    if(i>=0) cmd=cmdlist[i].value;
262
    else error("bad_command %.20s",cmdbuf);
263
    else error("bad_command %.20s",cmdbuf);
263
    snprintf(cmdparm,sizeof(cmdparm),"%s",p2);
264
    snprintf(cmdparm,sizeof(cmdparm),"%s",p2);
264
   
265
 
265
    options=0;
266
    options=0;
266
    p=getenv("w_module_language"); if(p==NULL) p="";
267
    p=getenv("w_module_language"); if(p==NULL) p="";
267
    snprintf(lbuf,sizeof(lbuf),"%2s",p);
268
    snprintf(lbuf,sizeof(lbuf),"%2s",p);
268
    if(*p3) {
269
    if(*p3) {
269
        snprintf(buf,sizeof(buf),"%s",p3);
270
      snprintf(buf,sizeof(buf),"%s",p3);
270
        _getopt("style",buf);
271
      _getopt("style",buf);
271
        snprintf(style,sizeof(style),"%s",find_word_start(buf));
272
      snprintf(style,sizeof(style),"%s",find_word_start(buf));
272
        *find_word_end(style)=0;
273
      *find_word_end(style)=0;
273
        snprintf(buf,sizeof(buf),"%s",p3);
274
      snprintf(buf,sizeof(buf),"%s",p3);
274
        _getopt("language",buf);
275
      _getopt("language",buf);
275
        if(buf[0]) snprintf(lbuf,sizeof(lbuf),"%2s",buf);
276
      if(buf[0]) snprintf(lbuf,sizeof(lbuf),"%2s",buf);
276
    }
277
    }
277
    lbuf[2]=0;
278
    lbuf[2]=0;
278
    if(!myisalpha(lbuf[0]) || !myisalpha(lbuf[1])) ovlstrcpy(lbuf,"en");
279
    if(!myisalpha(lbuf[0]) || !myisalpha(lbuf[1])) ovlstrcpy(lbuf,"en");
279
    styledir[0]=defbuf[0]=optionbuf[0]=buf[0]=0;
280
    styledir[0]=defbuf[0]=optionbuf[0]=buf[0]=0;
280
    if(*style) {
281
    if(*style) {
281
        p=getenv("module_dir");
282
      p=getenv("module_dir");
282
        if(p==NULL) {                   /* non-wims operation */
283
      if(p==NULL) {               /* non-wims operation */
283
            snprintf(styledir,sizeof(styledir),"%s",style);
284
          snprintf(styledir,sizeof(styledir),"%s",style);
284
        }
285
      }
285
        else {
286
      else {
286
            for(i=0;i<MAX_NAMELEN && myisalnum(style[i]);i++);
287
          for(i=0;i<MAX_NAMELEN && myisalnum(style[i]);i++);
287
            style[i]=0;
288
          style[i]=0;
288
            if(style[0]) {              /* style defined */
289
          if(style[0]) {            /* style defined */
289
                if(*p!='/' && strstr(p,"..")==NULL) {   /* check module dir */
290
             if(*p!='/' && strstr(p,"..")==NULL) {      /* check module dir */
290
                    snprintf(styledir,sizeof(styledir),"%s/symtext/%s/%s/def",p,lbuf,style);
291
                snprintf(styledir,sizeof(styledir),"%s/symtext/%s/%s/def",p,lbuf,style);
291
                    if(stat(styledir,&st)) styledir[0]=0;
292
                if(stat(styledir,&st)) styledir[0]=0;
292
                }
293
             }
293
                if(styledir[0]==0) {    /* check default */
294
             if(styledir[0]==0) {      /* check default */
294
                    snprintf(styledir,sizeof(styledir),"%s/symtext/%s/%s/def",defaultdir,lbuf,style);
295
                snprintf(styledir,sizeof(styledir),"%s/symtext/%s/%s/def",defaultdir,lbuf,style);
295
                    if(stat(styledir,&st)) error("style_not_found %s",style);
296
                if(stat(styledir,&st)) error("style_not_found %s",style);
296
                }
297
             }
297
            }
298
          }
298
        }
299
      }
299
        if(styledir[0]) {               /* get def */
300
      if(styledir[0]) {            /* get def */
300
            readfile(styledir,defbuf,sizeof(defbuf));
301
          readfile(styledir,defbuf,sizeof(defbuf));
301
            styledir[strlen(styledir)-4]=0;
302
          styledir[strlen(styledir)-4]=0;
302
            suffix_dic(mkfname(NULL,"%s/suffix",styledir));
303
          suffix_dic(mkfname(NULL,"%s/suffix",styledir));
303
            transdic=diccnt;
304
          transdic=diccnt;
304
            if(prepare_dic("trans")==NULL) transdic=-1;
305
          if(prepare_dic("trans")==NULL) transdic=-1;
305
            dic[transdic].unknown_type=unk_leave;
306
          dic[transdic].unknown_type=unk_leave;
306
            macrodic=diccnt;
307
          macrodic=diccnt;
307
            if(prepare_dic("macros")==NULL) macrodic=-1;
308
          if(prepare_dic("macros")==NULL) macrodic=-1;
308
            dic[macrodic].unknown_type=unk_delete;
309
          dic[macrodic].unknown_type=unk_delete;
309
        }
310
      }
310
    }
311
    }
311
    _getdef(defbuf,"option",buf);
312
    _getdef(defbuf,"option",buf);
312
    snprintf(optionbuf,sizeof(optionbuf),"%s %s",p3,buf);
313
    snprintf(optionbuf,sizeof(optionbuf),"%s %s",p3,buf);
313
    if(wordchr(optionbuf,"nocase")!=NULL) options|=op_nocase;
314
    if(wordchr(optionbuf,"nocase")!=NULL) options|=op_nocase;
314
    if(wordchr(optionbuf,"deaccent")!=NULL) options|=op_deaccent;
315
    if(wordchr(optionbuf,"deaccent")!=NULL) options|=op_deaccent;
Line 322... Line 323...
322
    if(wordchr(optionbuf,"matchall")!=NULL) options|=op_matchall;
323
    if(wordchr(optionbuf,"matchall")!=NULL) options|=op_matchall;
323
    if(wordchr(optionbuf,"abconly")!=NULL) options|=op_alphaonly;
324
    if(wordchr(optionbuf,"abconly")!=NULL) options|=op_alphaonly;
324
    if(wordchr(optionbuf,"onlyabc")!=NULL) options|=op_alphaonly;
325
    if(wordchr(optionbuf,"onlyabc")!=NULL) options|=op_alphaonly;
325
    if(wordchr(optionbuf,"alnumonly")!=NULL) options|=op_alnumonly;
326
    if(wordchr(optionbuf,"alnumonly")!=NULL) options|=op_alnumonly;
326
    if(wordchr(optionbuf,"onlyalnum")!=NULL) options|=op_alnumonly;
327
    if(wordchr(optionbuf,"onlyalnum")!=NULL) options|=op_alnumonly;
327
   
328
 
328
    if(cmd==cmd_comp || cmd==cmd_debug) {
329
    if(cmd==cmd_comp || cmd==cmd_debug) {
329
        _getopt("debug",optionbuf);
330
      _getopt("debug",optionbuf);
330
        if(optionbuf[0]) {
331
      if(optionbuf[0]) {
331
            i=atoi(optionbuf);
332
          i=atoi(optionbuf);
332
            if(i>0 || strcmp(optionbuf,"0")==0) debug=i; else debug=1;
333
          if(i>0 || strcmp(optionbuf,"0")==0) debug=i; else debug=1;
333
            if(debug>0) cmd=cmd_debug;
334
          if(debug>0) cmd=cmd_debug;
334
        }
335
      }
335
    }
336
    }
336
    strip_enclosing_par(textbuf);
337
    strip_enclosing_par(textbuf);
337
    strfold(textbuf);
338
    strfold(textbuf);
338
}
339
}
339
 
340
 
340
int verify_tables(void)
341
int verify_tables(void)
341
{
342
{
342
    if(verify_order(builtin,builtincnt,sizeof(builtin[0]))) return -1;
343
    if(verify_order(builtin,builtincnt,sizeof(builtin[0]))) return -1;
343
    if(verify_order(cmdlist,cmdcnt,sizeof(cmdlist[0]))) return -1;
344
    if(verify_order(cmdlist,cmdcnt,sizeof(cmdlist[0]))) return -1;
344
   
345
 
345
    return 0;
346
    return 0;
346
}
347
}
347
 
348
 
348
int main(int argc, char *argv[])
349
int main(int argc, char *argv[])
349
{
350
{
350
    int i, n, mat;
351
    int i, n, mat;
351
    char *p1, *p2;
352
    char *p1, *p2;
352
    char lbuf[MAX_LINELEN+1];
353
    char lbuf[MAX_LINELEN+1];
353
 
354
 
354
    if(argc>1 && strcmp(argv[1],"-t")==0) {
355
    if(argc>1 && strcmp(argv[1],"-t")==0) {
355
        if(verify_tables()==0) {
356
      if(verify_tables()==0) {
356
            printf("Table orders OK.\n");
357
         printf("Table orders OK.\n");
357
            return 0;
358
         return 0;
358
        }
359
      }
359
        else return 1;
360
      else return 1;
360
    }
361
    }
361
    error1=error2=_error; debug=0;
362
    error1=error2=_error; debug=0;
362
    wptr=wbuf; wbuf[0]=0;
363
    wptr=wbuf; wbuf[0]=0;
363
    getparms();
364
    getparms();
364
    Mnext=Mbuf; Mcnt=0;
365
    Mnext=Mbuf; Mcnt=0;
365
    switch(cmd) {
366
    switch(cmd) {
366
        case cmd_comp: {
367
      case cmd_comp: {
367
            comp:
368
         comp:
368
            n=linenum(stbuf);
369
         n=linenum(stbuf);
369
            for(mat=0,i=1,p1=stbuf;i<=n;i++,p1=p2) {
370
         for(mat=0,i=1,p1=stbuf;i<=n;i++,p1=p2) {
370
                p2=find_line_end(p1); if(*p2) *p2++=0;
371
            p2=find_line_end(p1); if(*p2) *p2++=0;
371
                p1=find_word_start(p1);
372
            p1=find_word_start(p1);
372
                if(*p1==0) continue;
373
            if(*p1==0) continue;
373
                snprintf(lbuf,sizeof(lbuf),"%s",p1);
374
            snprintf(lbuf,sizeof(lbuf),"%s",p1);
374
                compile(lbuf);
375
            compile(lbuf);
375
                mat=match(textbuf);
376
            mat=match(textbuf);
376
                if(mat) {
377
            if(mat) {
377
                    printf("MATCH %d %s\n",i,outbuf);
378
                printf("MATCH %d %s\n",i,outbuf);
378
                    if((options&op_matchall)==0) break;
379
                if((options&op_matchall)==0) break;
379
                }
380
            }
380
            }
381
          }
381
            if(debug) fprintf(stderr,"word list: %s\n",wbuf);
382
          if(debug) fprintf(stderr,"word list: %s\n",wbuf);
382
            break;
383
          break;
383
        }
384
      }
384
        case cmd_debug: {
385
      case cmd_debug: {
385
            if(debug==0) debug=1;
386
          if(debug==0) debug=1;
386
            fprintf(stderr,"debug=%d.\n",debug);
387
          fprintf(stderr,"debug=%d.\n",debug);
387
            for(i=0;i<diccnt;i++)
388
          for(i=0;i<diccnt;i++)
388
              fprintf(stderr,"Dictionary %d: %s, %d entries.\n",
389
            fprintf(stderr,"Dictionary %d: %s, %d entries.\n",
389
                      i+1,dic[i].name,dic[i].len);
390
                  i+1,dic[i].name,dic[i].len);
390
            goto comp;
391
          goto comp;
391
        }
392
      }
392
        case cmd_random: {
393
      case cmd_random: {
393
           
394
 
394
            break;
395
          break;
395
        }
396
      }
396
        case cmd_wordlist: {
397
      case cmd_wordlist: {
397
           
398
 
398
            break;
399
          break;
399
        }
400
      }
400
        case cmd_1: {
401
      case cmd_1: {
401
           
402
 
402
            break;
403
          break;
403
        }
404
      }
404
         
405
 
405
        case cmd_none:
406
      case cmd_none:
406
        default: return 1;
407
      default: return 1;
407
    }
408
    }
408
    return 0;
409
    return 0;
409
}
410
}
410
 
411