Rev 15394 | Rev 15442 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 1 | /* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
2 | * |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
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 |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
17 | |||
6884 | bpr | 18 | /* This is an internal program, |
7915 | bpr | 19 | * used to index modules for search engine. |
6884 | bpr | 20 | */ |
10 | reyssat | 21 | |
8100 | bpr | 22 | #include "../Lib/libwims.h" |
8123 | bpr | 23 | #include "translator_.h" |
24 | #include "suffix.h" |
||
10 | reyssat | 25 | |
6884 | bpr | 26 | #define MAX_LANGS MAX_LANGUAGES |
27 | #define MAX_MODULES 65536 |
||
28 | char *moduledir= "public_html/modules"; |
||
29 | char *sheetdir= "public_html/bases/sheet"; |
||
15375 | bpr | 30 | char *glossarydir= "public_html/scripts/data/glossary"; |
6884 | bpr | 31 | char *dicdir= "public_html/bases"; |
32 | char *outdir= "public_html/bases/site2"; |
||
9090 | bpr | 33 | char *sheetoutdir= "public_html/bases/sheet/index"; |
15375 | bpr | 34 | char *glossaryoutdir= "public_html/scripts/data/glossary/index"; |
6884 | bpr | 35 | char *maindic= "sys/words"; |
36 | char *groupdic= "sys/wgrp/wgrp"; |
||
37 | char *suffixdic= "sys/suffix"; |
||
38 | char *domaindic= "sys/domaindic"; |
||
39 | char *ignoredic= "sys/indignore"; |
||
40 | char *conffile= "log/wims.conf"; |
||
9092 | bpr | 41 | char *mlistbase= "lists"; |
10 | reyssat | 42 | |
43 | char lang[MAX_LANGS][4]={ |
||
1792 | bpr | 44 | "en","fr","cn","es","it","nl","si","ca","pt" |
10 | reyssat | 45 | }; |
6884 | bpr | 46 | #define DEFAULT_LANGCNT 6 |
10 | reyssat | 47 | char allang[MAX_LANGS][4]={ |
6564 | bpr | 48 | "en","fr","cn","es","it","nl","de","si","ca","pt" |
10 | reyssat | 49 | }; |
50 | #define allangcnt 8 |
||
51 | char ignore[MAX_LANGS][MAX_LINELEN+1]; |
||
52 | char mlistfile[MAX_LANGS][256]; |
||
53 | int langcnt; |
||
8650 | bpr | 54 | FILE *langf, *titf, *descf, *weightf, *robotf, *indf, *listf, *addrf, *serialf, *authorf, *versionf, *remf, *titlef; |
10 | reyssat | 55 | |
56 | struct cat { |
||
57 | char *name; |
||
58 | char typ; |
||
59 | } cat[]={ |
||
6884 | bpr | 60 | {"all_types", 'A'}, |
61 | {"exercise", 'X'}, |
||
62 | {"oef", 'O'}, |
||
63 | {"tool", 'T'}, |
||
64 | {"recreation",'R'}, |
||
65 | {"reference", 'Y'}, |
||
66 | {"document", 'D'}, |
||
67 | {"popup", 'P'}, |
||
68 | {"datamodule",'M'} |
||
10 | reyssat | 69 | }; |
70 | #define catno (sizeof(cat)/sizeof(cat[0])) |
||
71 | |||
72 | struct mod { |
||
73 | char *name; |
||
74 | unsigned char langs[MAX_LANGS]; |
||
75 | int counts[MAX_LANGS]; |
||
15440 | bpr | 76 | int langcnt; |
10 | reyssat | 77 | } mod[MAX_MODULES]; |
15440 | bpr | 78 | |
79 | // serial-> the name of the module indexed by serial, lang and its classe |
||
80 | struct revmod { |
||
81 | char name[MAX_MODULELEN+1]; |
||
82 | int lang; |
||
83 | int imod; |
||
84 | } revmod[MAX_MODULES]; |
||
10 | reyssat | 85 | int modcnt; |
86 | |||
87 | char *mlist; |
||
88 | |||
6884 | bpr | 89 | /* fold known accented letters to unaccented, other strange characters to space |
7915 | bpr | 90 | * apostrophe is among the exceptions to be kept (important for multi-word expressions) |
6884 | bpr | 91 | */ |
8100 | bpr | 92 | void deaccent2(char *p) |
10 | reyssat | 93 | { |
12248 | bpr | 94 | char *sp; |
95 | char *v; |
||
96 | for(sp=p;*sp;sp++) { |
||
97 | if(*sp<0 && (v=strchr(acctab,*sp))!=NULL) |
||
98 | *sp=*(deatab+(v-acctab)); |
||
99 | if(!isalnum(*sp) && strchr(",.&$+*",*sp)==0) *sp=' '; |
||
100 | else *sp=tolower(*sp); |
||
101 | } |
||
10 | reyssat | 102 | } |
103 | |||
6884 | bpr | 104 | /* translate everything non-alphanumeric into space */ |
10 | reyssat | 105 | void towords(char *p) |
106 | { |
||
12248 | bpr | 107 | char *pp; |
108 | for(pp=p;*pp;pp++) if(!isalnum(*pp) && strchr("&$+*",*pp)==0) *pp=' '; |
||
10 | reyssat | 109 | } |
110 | |||
6884 | bpr | 111 | /* Find first occurrence of word */ |
8100 | bpr | 112 | char *wordchr2(char *p, char *w) |
10 | reyssat | 113 | { |
12248 | bpr | 114 | char *r; |
10 | reyssat | 115 | |
12248 | bpr | 116 | for(r=strstr(p,w);r!=NULL && |
6884 | bpr | 117 | ( (r>p && !isspace(*(r-1))) || (!isspace(*(r+strlen(w))) && *(r+strlen(w))!=0) ); |
12248 | bpr | 118 | r=strstr(r+1,w)); |
119 | return r; |
||
10 | reyssat | 120 | } |
121 | |||
122 | char *find_tag_end(char *p) |
||
123 | { |
||
12248 | bpr | 124 | char *pp; |
125 | pp=p; if(*pp=='<') pp++; |
||
126 | for(; *pp && *pp!='>'; pp++) { |
||
6884 | bpr | 127 | if(*pp=='<') { |
12248 | bpr | 128 | pp=find_tag_end(pp)-1; continue; |
10 | reyssat | 129 | } |
6884 | bpr | 130 | if(*pp=='"') { |
12248 | bpr | 131 | pp=strchr(pp+1,'"'); |
132 | if(pp==NULL) return p+strlen(p); else continue; |
||
6884 | bpr | 133 | } |
134 | if(*pp=='\'') { |
||
12248 | bpr | 135 | pp=strchr(pp+1,'\''); |
136 | if(pp==NULL) return p+strlen(p); else continue; |
||
6884 | bpr | 137 | } |
12248 | bpr | 138 | } |
139 | if(*pp=='>') pp++; |
||
140 | return pp; |
||
10 | reyssat | 141 | } |
142 | |||
143 | char *find_tag(char *p, char *tag) |
||
144 | { |
||
12248 | bpr | 145 | char *pp; |
146 | int len; |
||
147 | len=strlen(tag); |
||
148 | for(pp=strchr(p,'<'); pp!=NULL && *pp; pp=strchr(pp+1,'<')) { |
||
6884 | bpr | 149 | if(strncasecmp(pp+1,tag,len)==0 && !isalnum(*(pp+1+len))) return pp; |
12248 | bpr | 150 | } |
151 | return p+strlen(p); |
||
10 | reyssat | 152 | } |
153 | |||
6884 | bpr | 154 | /* remove all html tags */ |
10 | reyssat | 155 | void detag(char *p) |
156 | { |
||
12248 | bpr | 157 | char *pp, *p2; |
158 | for(pp=strchr(p,'<'); pp!=NULL; pp=strchr(pp,'<')) { |
||
6884 | bpr | 159 | p2=find_tag_end(pp); |
160 | if(*p2==0) {*pp=0; return; } |
||
161 | ovlstrcpy(pp,p2); |
||
12248 | bpr | 162 | } |
10 | reyssat | 163 | } |
164 | |||
6819 | reyssat | 165 | /* add a space after comma to see end of words */ |
166 | |||
167 | void comma(char *p) |
||
168 | { |
||
12248 | bpr | 169 | char *pp; |
170 | for(pp=strchr(p,','); pp; pp=strchr(pp+1,',')) |
||
171 | string_modify3(p,pp,pp+1,", "); |
||
6819 | reyssat | 172 | } |
173 | |||
15375 | bpr | 174 | /* _getdef from lines.c except the error msg*/ |
10 | reyssat | 175 | void _getdef(char buf[], char *name, char value[]) |
176 | { |
||
15375 | bpr | 177 | char *p1, *p2, *p3, *p4; |
10 | reyssat | 178 | |
15375 | bpr | 179 | if(*name==0) goto nothing; /* this would create segfault. */ |
12248 | bpr | 180 | for(p1=strstr(buf,name); p1!=NULL; p1=strstr(p1+1,name)) { |
6884 | bpr | 181 | p2=find_word_start(p1+strlen(name)); |
182 | if((p1>buf && !isspace(*(p1-1))) || *p2!='=') continue; |
||
15375 | bpr | 183 | p3=p1; while(p3>buf && *(p3-1)!='\n') p3--; |
184 | p3=find_word_start(p3); |
||
185 | if(p3<p1 && *p3!='!') continue; |
||
186 | if(p3<p1) { |
||
187 | p3++; p4=find_word_end(p3); |
||
188 | if(find_word_start(p4)!=p1) continue; |
||
189 | if(p4-p3!=3 || (strncmp(p3,"set",3)!=0 && |
||
190 | strncmp(p3,"let",3)!=0 && |
||
191 | strncmp(p3,"def",3)!=0)) { |
||
192 | if(p4-p3!=6 || strncmp(p3,"define",6)!=0) continue; |
||
193 | } |
||
194 | } |
||
195 | p2++;p3=strchr(p2,'\n'); if(p3==NULL) p3=p2+strlen(p2); |
||
196 | p2=find_word_start(p2); |
||
197 | if(p2>p3) goto nothing; |
||
198 | /*if(p3-p2>=MAX_LINELEN) user_error("cmd_output_too_long");*/ |
||
199 | memmove(value,p2,p3-p2); value[p3-p2]=0; |
||
200 | strip_trailing_spaces(value); return; |
||
12248 | bpr | 201 | } |
15375 | bpr | 202 | nothing: |
15394 | bpr | 203 | value[0]=0; |
10 | reyssat | 204 | } |
205 | |||
6884 | bpr | 206 | /* Get variable definition from a file. |
207 | * Result stored in buffer value of length MAX_LINELEN. |
||
208 | */ |
||
10 | reyssat | 209 | void getdef(char *fname, char *name, char value[]) |
210 | { |
||
12248 | bpr | 211 | FILE *f; |
212 | char *buf; |
||
213 | int l; |
||
6881 | bpr | 214 | |
12248 | bpr | 215 | value[0]=0; |
216 | f=fopen(fname,"r"); if(f==NULL) return; |
||
217 | fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET); |
||
218 | buf=xmalloc(l+256); l=fread(buf,1,l,f); |
||
219 | fclose(f); |
||
220 | if(l<=0) return; else buf[l]=0; |
||
221 | _getdef(buf,name,value); |
||
222 | free(buf); |
||
10 | reyssat | 223 | } |
224 | |||
8123 | bpr | 225 | char *mdicbuf, *gdicbuf, *ddicbuf, *gentry, *mentry, *dentry; |
10 | reyssat | 226 | |
6881 | bpr | 227 | int gentrycount, mentrycount, dentrycount; |
10 | reyssat | 228 | |
6884 | bpr | 229 | /* Preparation of data */ |
10 | reyssat | 230 | void prep(void) |
231 | { |
||
12248 | bpr | 232 | char buf[MAX_LINELEN+1]; |
233 | char *p1,*p2,*s,*old; |
||
234 | int i,l,thislang,t; |
||
235 | FILE *f; |
||
6881 | bpr | 236 | |
12248 | bpr | 237 | s=getenv("modind_outdir"); if(s!=NULL && *s!=0) outdir=s; |
238 | s=getenv("modind_sheetdir"); if(s!=NULL && *s!=0) sheetdir=s; |
||
239 | s=getenv("modind_sheetoutdir"); if(s!=NULL && *s!=0) sheetoutdir=s; |
||
240 | snprintf(buf,sizeof(buf),"%s/addr",outdir); |
||
241 | addrf=fopen(buf,"w"); |
||
242 | if(!addrf) { fprintf(stderr,"modind: error creating output files addr.\n"); exit(1);} |
||
243 | snprintf(buf,sizeof(buf),"%s/serial",outdir); |
||
244 | serialf=fopen(buf,"w"); |
||
245 | if(!serialf) { fprintf(stderr,"modind: error creating output files serial.\n"); exit(1);} |
||
246 | modcnt=langcnt=0; |
||
6884 | bpr | 247 | /* take the langs declared in conffile */ |
12248 | bpr | 248 | getdef(conffile,"site_languages",buf); |
249 | for(p1=buf;*p1;p1++) if(!isalnum(*p1)) *p1=' '; |
||
250 | for(p1=find_word_start(buf); *p1 && langcnt<MAX_LANGS; p1=find_word_start(p2)) { |
||
6884 | bpr | 251 | p2=find_word_end(p1); |
252 | if(p2!=p1+2 || !isalpha(*p1) || !isalpha(*(p1+1))) continue; |
||
253 | memmove(lang[langcnt],p1,2); lang[langcnt++][2]=0; |
||
12248 | bpr | 254 | } |
255 | if(langcnt==0) {/* default languages */ |
||
6884 | bpr | 256 | langcnt=DEFAULT_LANGCNT; |
12248 | bpr | 257 | } |
258 | s=getenv("mlist"); if(s==NULL) exit(1); |
||
259 | l=strlen(s); if(l<0 || l>100*MAX_LINELEN) exit(1); |
||
260 | mlist=xmalloc(l+16); ovlstrcpy(mlist,s); old=""; |
||
261 | for(i=0;i<langcnt;i++) { |
||
262 | snprintf(buf,sizeof(buf),"%s/%s.%s",dicdir,ignoredic,lang[i]); |
||
263 | f=fopen(buf,"r"); if(f==NULL) continue; |
||
264 | l=fread(ignore[i],1,MAX_LINELEN,f);fclose(f); |
||
265 | if(l<0 || l>=MAX_LINELEN) l=0; |
||
266 | ignore[i][l]=0; |
||
267 | } |
||
268 | for(t=0, p1=find_word_start(mlist); *p1 && modcnt<MAX_MODULES; |
||
9090 | bpr | 269 | p1=find_word_start(p2), t++) { |
12248 | bpr | 270 | p2=find_word_end(p1); |
271 | l=p2-p1; if(*p2) *p2++=0; |
||
272 | fprintf(addrf,"%d:%s\n",t,p1); |
||
273 | fprintf(serialf,"%s:%d\n",p1,t); |
||
274 | thislang=-1; |
||
6564 | bpr | 275 | /* language is taken from the address */ |
12248 | bpr | 276 | if(l>3 && p1[l-3]=='.') { |
277 | for(i=0;i<langcnt;i++) if(strcasecmp(lang[i],p1+l-2)==0) break; |
||
278 | if(i<langcnt) {p1[l-3]=0; thislang=i;} |
||
279 | else {/* unknown language, not referenced */ |
||
6884 | bpr | 280 | continue; |
9090 | bpr | 281 | } |
12248 | bpr | 282 | } |
283 | if(modcnt>0 && strcmp(old,p1)==0 && thislang>=0) { |
||
284 | if(mod[modcnt-1].langcnt<langcnt) { |
||
6884 | bpr | 285 | mod[modcnt-1].langs[mod[modcnt-1].langcnt]=thislang; |
286 | mod[modcnt-1].counts[mod[modcnt-1].langcnt]=t; |
||
287 | (mod[modcnt-1].langcnt)++; |
||
12248 | bpr | 288 | } |
6884 | bpr | 289 | } |
12248 | bpr | 290 | else { |
291 | mod[modcnt].name=old=p1; |
||
292 | if(thislang>=0) { |
||
293 | mod[modcnt].langs[0]=thislang; |
||
294 | mod[modcnt].langcnt=1; |
||
295 | } |
||
296 | else mod[modcnt].langcnt=0; |
||
297 | mod[modcnt].counts[0]=t; |
||
298 | modcnt++; |
||
6884 | bpr | 299 | } |
12248 | bpr | 300 | } |
301 | snprintf(buf,sizeof(buf),"%s/language",outdir); |
||
302 | langf=fopen(buf,"w"); |
||
303 | snprintf(buf,sizeof(buf),"%s/title",outdir); |
||
304 | titf=fopen(buf,"w"); |
||
305 | snprintf(buf,sizeof(buf),"%s/description",outdir); |
||
306 | descf=fopen(buf,"w"); |
||
307 | snprintf(buf,sizeof(buf),"%s/author",outdir); |
||
308 | authorf=fopen(buf,"w"); |
||
309 | snprintf(buf,sizeof(buf),"%s/version",outdir); |
||
310 | versionf=fopen(buf,"w"); |
||
311 | snprintf(buf,sizeof(buf),"%s/%s/robot.phtml",outdir,mlistbase); |
||
312 | robotf=fopen(buf,"w"); |
||
313 | fclose(addrf); fclose(serialf); |
||
314 | if(!robotf || !versionf || !authorf || !descf || !titf || !langf) { |
||
315 | fprintf(stderr,"modind: error creating output files.\n"); |
||
316 | exit(1); |
||
317 | } |
||
10 | reyssat | 318 | } |
319 | |||
320 | void sprep(void) |
||
321 | { |
||
15440 | bpr | 322 | char buf[MAX_LINELEN+1]; |
12248 | bpr | 323 | char *p1,*p2,*s; |
15440 | bpr | 324 | int i,l,t,thislang; |
6881 | bpr | 325 | |
12248 | bpr | 326 | modcnt=0; |
15440 | bpr | 327 | snprintf(buf,sizeof(buf),"%s/addr",sheetoutdir); |
328 | addrf=fopen(buf,"w"); |
||
329 | if(!addrf) { fprintf(stderr,"modind: error creating output files addr.\n"); exit(1);} |
||
330 | snprintf(buf,sizeof(buf),"%s/serial",sheetoutdir); |
||
331 | serialf=fopen(buf,"w"); |
||
12248 | bpr | 332 | s=getenv("slist"); if(s==NULL) return; |
333 | l=strlen(s); if(l<0 || l>100*MAX_LINELEN) return; |
||
334 | mlist=xmalloc(l+16); ovlstrcpy(mlist,s); |
||
15440 | bpr | 335 | for(t=0,p1=find_word_start(mlist); *p1 && modcnt<MAX_MODULES; p1=find_word_start(p2),t++) { |
6884 | bpr | 336 | p2=find_word_end(p1); |
337 | l=p2-p1; if(*p2) *p2++=0; |
||
338 | for(i=0;i<langcnt;i++) if(strncasecmp(lang[i],p1,2)==0) break; |
||
339 | if(i<langcnt) thislang=i; else continue; |
||
15440 | bpr | 340 | ovlstrcpy(revmod[t].name,p1); |
341 | revmod[t].lang=thislang; |
||
6884 | bpr | 342 | mod[modcnt].name=p1; |
343 | mod[modcnt].langs[0]=thislang; |
||
344 | mod[modcnt].langcnt=1; |
||
15440 | bpr | 345 | revmod[t].imod=modcnt; |
6884 | bpr | 346 | modcnt++; |
15440 | bpr | 347 | fprintf(addrf,"%d:%s\n",modcnt,p1); |
348 | fprintf(serialf,"%s:%d\n",p1,modcnt); |
||
12248 | bpr | 349 | } |
15440 | bpr | 350 | fclose(addrf); fclose(serialf); |
10 | reyssat | 351 | } |
352 | |||
15375 | bpr | 353 | void gprep(void) |
354 | { |
||
15440 | bpr | 355 | char buf[MAX_LINELEN+1]; |
356 | char *p1,*p2,*s,*old; |
||
357 | int l,i,t,thislang; |
||
15375 | bpr | 358 | modcnt=0; |
15440 | bpr | 359 | snprintf(buf,sizeof(buf),"%s/addr",glossaryoutdir); |
360 | addrf=fopen(buf,"w"); |
||
361 | if(!addrf) { fprintf(stderr,"modind: error creating output files addr.\n"); exit(1);} |
||
362 | snprintf(buf,sizeof(buf),"%s/serial",glossaryoutdir); |
||
363 | serialf=fopen(buf,"w"); |
||
15375 | bpr | 364 | s=getenv("glist"); if(s==NULL) return; |
365 | l=strlen(s); if(l<0 || l>100*MAX_LINELEN) return; |
||
366 | mlist=xmalloc(l+16); ovlstrcpy(mlist,s); |
||
15440 | bpr | 367 | for(t=0,p1=find_word_start(mlist); *p1 && modcnt<MAX_MODULES; p1=find_word_start(p2),t++) { |
15375 | bpr | 368 | p2=find_word_end(p1); |
369 | if(*p2) *p2++=0; |
||
15440 | bpr | 370 | fprintf(addrf,"%d:%s\n",t,p1); |
371 | fprintf(serialf,"%s:%d\n",p1,t); |
||
372 | ovlstrcpy(revmod[t].name,p1); |
||
15375 | bpr | 373 | s=strchr(p1,'/'); |
374 | if(s != NULL) s=strchr(s+1,'/'); |
||
375 | if(s==NULL) { |
||
376 | fprintf(stderr,"modind: no language %s\n",p1); exit(1); |
||
377 | } |
||
378 | s++; |
||
379 | for(i=0;i<langcnt;i++) if(strncasecmp(lang[i],s,2)==0) break; |
||
15440 | bpr | 380 | thislang = i<langcnt ? i : -1; |
381 | revmod[t].lang=i; |
||
382 | s[0]=s[1]='x'; |
||
383 | if(modcnt>0 && strcmp(old,p1)==0 && thislang >= 0) { |
||
384 | if(mod[modcnt-1].langcnt<langcnt) { |
||
385 | mod[modcnt-1].langs[mod[modcnt-1].langcnt]=thislang; |
||
386 | mod[modcnt-1].counts[mod[modcnt-1].langcnt]=t; |
||
387 | (mod[modcnt-1].langcnt)++; |
||
388 | } |
||
389 | revmod[t].imod=modcnt-1; |
||
390 | } |
||
391 | else { |
||
392 | mod[modcnt].name=old=p1; |
||
393 | if(thislang>=0) { |
||
394 | mod[modcnt].langs[0]=thislang; |
||
395 | mod[modcnt].langcnt=1; |
||
396 | } |
||
397 | else mod[modcnt].langcnt=0; |
||
398 | mod[modcnt].counts[0]=t; |
||
399 | revmod[t].imod=modcnt; |
||
400 | modcnt++; |
||
401 | } |
||
15375 | bpr | 402 | } |
15440 | bpr | 403 | fclose(addrf); fclose(serialf); |
15375 | bpr | 404 | } |
405 | |||
10 | reyssat | 406 | char *sheetindex[]={ |
12248 | bpr | 407 | "title", "description", |
408 | "duration", "severity", |
||
409 | "level", "domain", |
||
410 | "keywords", "reserved1", "reserved2", "information" |
||
10 | reyssat | 411 | }; |
15375 | bpr | 412 | /* correspond to the order of sheetindex */ |
413 | char *glindex[]={ |
||
414 | "gl_title", "gl_description", |
||
415 | "", "", |
||
416 | "gl_level", "gl_domain", |
||
417 | "gl_keywords","","",""}; |
||
418 | |||
10 | reyssat | 419 | #define SHEETINDEX_NO (sizeof(sheetindex)/sizeof(sheetindex[0])) |
15440 | bpr | 420 | char gsindbuf[SHEETINDEX_NO+1][MAX_LINELEN+1]; |
15375 | bpr | 421 | |
422 | /* do not modify the order, correspond to the order in the sheet file */ |
||
10 | reyssat | 423 | enum{s_title, s_description, |
424 | s_duration, s_severity, |
||
425 | s_level, s_domain, |
||
426 | s_keywords, s_reserved1, s_reserved2, |
||
6967 | bpr | 427 | s_information |
10 | reyssat | 428 | }; |
429 | |||
430 | char *modindex[]={ |
||
12248 | bpr | 431 | "title", "description", |
432 | "author", "address", "copyright", |
||
433 | "version", "wims_version", "language", |
||
434 | "category", "level", "domain", "keywords", |
||
435 | "keywords_ca", "keywords_en", "keywords_fr", "keywords_it", "keywords_nl", |
||
436 | "title_ca", "title_en", "title_fr", "title_it", "title_nl", |
||
437 | "require" |
||
10 | reyssat | 438 | }; |
439 | #define MODINDEX_NO (sizeof(modindex)/sizeof(modindex[0])) |
||
440 | char indbuf[MODINDEX_NO][MAX_LINELEN+1]; |
||
441 | enum{i_title, i_description, |
||
12248 | bpr | 442 | i_author,i_address,i_copyright, |
443 | i_version,i_wims_version,i_language, |
||
444 | i_category,i_level,i_domain,i_keywords, |
||
445 | i_keywords_ca,i_keywords_en,i_keywords_fr,i_keywords_it,i_keywords_nl, |
||
446 | i_title_ca,i_title_en,i_title_fr,i_title_it,i_title_nl, |
||
447 | i_require |
||
10 | reyssat | 448 | }; |
449 | |||
450 | char *module_special_file[]={ |
||
12248 | bpr | 451 | "intro","help","about" |
10 | reyssat | 452 | }; |
453 | #define MODSPEC_NO (sizeof(module_special_file)/sizeof(module_special_file[0])) |
||
454 | char module_language[4]; |
||
455 | |||
6884 | bpr | 456 | /* read and treat module's INDEX file */ |
10 | reyssat | 457 | int module_index(const char *name) |
458 | { |
||
12248 | bpr | 459 | char *p, fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1]; |
460 | FILE *indf; |
||
461 | int i,l; |
||
10 | reyssat | 462 | |
12248 | bpr | 463 | snprintf(fbuf,sizeof(fbuf),"%s/%s/INDEX",moduledir,name); |
464 | indf=fopen(fbuf,"r"); |
||
465 | if(indf==NULL) { |
||
466 | fprintf(stderr,"modind: INDEX of %s not found\n",fbuf); return -1; |
||
467 | } |
||
468 | l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf); |
||
469 | if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1; |
||
6884 | bpr | 470 | /* treate all fields in *modindex */ |
12248 | bpr | 471 | for(i=0;i<MODINDEX_NO;i++) { |
472 | _getdef(ibuf,modindex[i],indbuf[i]); |
||
6884 | bpr | 473 | /* compatibility precaution */ |
12248 | bpr | 474 | if(indbuf[i][0]==':') indbuf[i][0]='.'; |
475 | } |
||
476 | p=find_word_start(indbuf[i_language]); |
||
477 | if(isalpha(*p) && isalpha(*(p+1))) { |
||
478 | memmove(module_language,p,2); module_language[2]=0; |
||
479 | } |
||
480 | else ovlstrcpy(module_language,"en"); |
||
481 | return 0; |
||
10 | reyssat | 482 | } |
483 | |||
484 | int sheet_index(int serial) |
||
485 | { |
||
12248 | bpr | 486 | char *p1, *p2, fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1]; |
487 | FILE *indf; |
||
488 | int i,l; |
||
10 | reyssat | 489 | |
12248 | bpr | 490 | snprintf(fbuf,sizeof(fbuf),"%s/%s.def",sheetdir,mod[serial].name); |
491 | indf=fopen(fbuf,"r"); if(indf==NULL) return -1; |
||
492 | l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf); |
||
493 | if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1; |
||
15375 | bpr | 494 | for(i=0;i<SHEETINDEX_NO;i++) gsindbuf[i][0]=0; |
12248 | bpr | 495 | for(i=0,p1=find_word_start(ibuf); |
9090 | bpr | 496 | i<SHEETINDEX_NO-1 && *p1!=':' && *p1!=0; |
497 | i++,p1=p2) { |
||
12248 | bpr | 498 | p2=strchr(p1,'\n'); |
499 | if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1); |
||
8100 | bpr | 500 | p1=find_word_start(p1); strip_trailing_spaces2(p1); |
15375 | bpr | 501 | snprintf(gsindbuf[i],MAX_LINELEN,"%s",p1); |
12248 | bpr | 502 | } |
503 | p2=strstr(p1,"\n:"); if(p2==NULL) p2=p1+strlen(p1); |
||
504 | else *p2=0; |
||
505 | p1=find_word_start(p1); strip_trailing_spaces2(p1); |
||
506 | for(p2=p1;*p2;p2++) if(*p2=='\n') *p2=' '; |
||
15375 | bpr | 507 | ovlstrcpy(gsindbuf[s_information],p1); |
15440 | bpr | 508 | ovlstrcpy(gsindbuf[SHEETINDEX_NO],revmod[serial].name); |
12248 | bpr | 509 | return 0; |
10 | reyssat | 510 | } |
511 | |||
15375 | bpr | 512 | int glossary_index(int serial) |
513 | { |
||
15440 | bpr | 514 | char nbuf[MAX_LINELEN+1],fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1],*p,*s; |
15375 | bpr | 515 | FILE *indf; |
516 | int i,l; |
||
15440 | bpr | 517 | s=lang[revmod[serial].lang]; |
518 | p=strchr(nbuf,'/'); |
||
519 | if(p != NULL) p=strchr(p+1,'/'); |
||
520 | if(p != NULL) {p[1]=s[0];p[2]=s[1];} |
||
521 | snprintf(fbuf,sizeof(fbuf),"%s/%s",glossarydir,revmod[serial].name); |
||
15375 | bpr | 522 | indf=fopen(fbuf,"r"); |
523 | l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf); |
||
524 | if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1; |
||
525 | for(i=0;i<SHEETINDEX_NO;i++) { |
||
526 | _getdef(ibuf,glindex[i],gsindbuf[i]); |
||
527 | } |
||
15440 | bpr | 528 | ovlstrcpy(gsindbuf[SHEETINDEX_NO],nbuf); |
15375 | bpr | 529 | return 0; |
530 | } |
||
531 | |||
10 | reyssat | 532 | unsigned char categories[16]; |
533 | char taken[MAX_LINELEN+1]; |
||
534 | int catcnt, takenlen, tweight; |
||
535 | |||
15394 | bpr | 536 | /* file management for appenditem */ |
537 | #define MAX_FILES (MAX_LANGS*catno) |
||
538 | |||
539 | char *fnames[MAX_FILES]; |
||
540 | FILE *files[MAX_FILES]; |
||
541 | int open_files; |
||
542 | |||
543 | FILE * file_from_list(char *name){ |
||
544 | int i, l = 0, r = open_files; |
||
545 | while (r>l){ |
||
546 | int m = (l+r)/2; |
||
547 | int cmp = strcmp(name,fnames[m]); |
||
548 | if (!cmp) return files[m]; |
||
549 | if (cmp < 0) r = m; else l = m+1; |
||
550 | } |
||
551 | for (i=open_files; i > l; i--) {files[i]=files[i-1]; fnames[i]=fnames[i-1];} |
||
552 | fnames[l] = xmalloc(MAX_FNAME); |
||
553 | ovlstrcpy(fnames[l],name); |
||
554 | open_files++; |
||
555 | return files[l]=fopen(name,"a"); |
||
556 | } |
||
557 | |||
10 | reyssat | 558 | void appenditem(char *word, int lind, int serial, int weight, char *l) |
559 | { |
||
12248 | bpr | 560 | char nbuf[MAX_LINELEN+1], buf[MAX_LINELEN+1]; |
561 | int i, ll; |
||
562 | char *p; |
||
563 | FILE *f; |
||
6881 | bpr | 564 | |
12248 | bpr | 565 | if(!isalnum(*word) || (ll=strlen(word))<2 || |
566 | wordchr2(taken,word)!=NULL || |
||
567 | wordchr2(ignore[lind],word)!=NULL || |
||
568 | takenlen>=MAX_LINELEN-ll-16) |
||
569 | return; |
||
570 | if(ll==2 && (!isdigit(word[0]) || !isalpha(word[1]))) return; |
||
571 | for(p=word;*p;p++) if(!isalnum(*p) && *p!=' ') return; |
||
572 | taken[takenlen++]=' '; taken[takenlen++]=' '; |
||
573 | ovlstrcpy(taken+takenlen,word); |
||
574 | takenlen+=ll; tweight+=weight; |
||
575 | snprintf(buf,sizeof(buf),"%s:%d?%d\n",word,serial,weight); |
||
576 | for(i=0;i<catcnt;i++) { |
||
6884 | bpr | 577 | snprintf(nbuf,sizeof(nbuf),"%s/%c.%s", |
12248 | bpr | 578 | outdir,categories[i],lang[lind]); |
15394 | bpr | 579 | f = file_from_list(nbuf); |
580 | if(f!=NULL) {fputs(buf,f);} |
||
12248 | bpr | 581 | } |
10 | reyssat | 582 | } |
583 | |||
6881 | bpr | 584 | void appenditem1 (char *buf, int lind, int serial, int weight, char *l ) |
585 | { |
||
586 | char *p1, *p2 ; |
||
587 | for(p1=find_word_start(buf); *p1; |
||
6884 | bpr | 588 | p1=find_word_start(p2)) { |
589 | p2=strchr(p1,','); |
||
590 | if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1); |
||
591 | if(strlen(p1)<=0) continue; |
||
592 | appenditem(p1,lind,serial,weight,module_language); |
||
6881 | bpr | 593 | } |
594 | } |
||
595 | void appenditem2 (char *buf, int lind, int serial, int weight, char *l ) |
||
596 | { |
||
597 | char *p1, *p2 ; |
||
598 | for(p1=find_word_start(buf);*p1; |
||
12248 | bpr | 599 | p1=find_word_start(p2)) { |
6884 | bpr | 600 | p2=find_word_end(p1); if(*p2) *p2++=0; |
601 | appenditem(p1,lind,serial,weight,module_language); |
||
6881 | bpr | 602 | } |
603 | } |
||
10 | reyssat | 604 | void onemodule(const char *name, int serial, int lind) |
605 | { |
||
12248 | bpr | 606 | int i; |
607 | unsigned char trlist[]={ |
||
608 | i_title,i_description,i_category,i_domain,i_keywords, |
||
609 | i_require,i_author, |
||
610 | i_keywords_ca,i_keywords_en,i_keywords_fr,i_keywords_it,i_keywords_nl, |
||
611 | i_title_ca,i_title_en,i_title_fr,i_title_it,i_title_nl |
||
612 | }; |
||
15375 | bpr | 613 | int trcnt=sizeof(trlist)/sizeof(trlist[0]); |
12248 | bpr | 614 | char *p1, *p2, *pp, *q, buf[MAX_LINELEN+1], lbuf[16]; |
615 | FILE *f; |
||
6881 | bpr | 616 | |
12248 | bpr | 617 | if(module_index(name)) return; |
618 | towords(indbuf[i_category]); |
||
7915 | bpr | 619 | /* list the categories (among A=all,X=eXercise,O,D,...) corresponding |
6884 | bpr | 620 | * to this module |
621 | */ |
||
12248 | bpr | 622 | for(i=catcnt=0;i<catno && catcnt<16;i++) { |
15380 | bpr | 623 | if(wordchr2(indbuf[i_category],cat[i].name)!=NULL) |
624 | categories[catcnt++]=cat[i].typ; |
||
12248 | bpr | 625 | } |
626 | if(catcnt==0) return; |
||
627 | if(categories[0]!=cat[0].typ) |
||
628 | categories[catcnt++]=cat[0].typ; |
||
6884 | bpr | 629 | /* write module's name in the category.language files, for instance lists/X.fr |
630 | * for french exercises |
||
631 | */ |
||
12248 | bpr | 632 | for(i=0;i<catcnt;i++) { |
633 | snprintf(buf,sizeof(buf),"%s/%s/%c.%s", |
||
634 | outdir,mlistbase,categories[i],lang[lind]); |
||
635 | f=fopen(buf,"a"); |
||
636 | if(f!=NULL) {fprintf(f,"%s\n",name); fclose(f);} |
||
637 | } |
||
6884 | bpr | 638 | /* add serial number and language (resp.title, ...) to corresponding file */ |
12248 | bpr | 639 | fprintf(langf,"%d:%s\n",serial,module_language); |
640 | fprintf(titf,"%d:%s\n",serial,indbuf[i_title]); |
||
641 | fprintf(descf,"%d:%s\n",serial,indbuf[i_description]); |
||
642 | fprintf(authorf,"%d:%s\n",serial,indbuf[i_author]); |
||
643 | fprintf(versionf,"%d:%s\n",serial,indbuf[i_version]); |
||
6881 | bpr | 644 | |
6884 | bpr | 645 | /* add module's information in html page for robots */ |
12248 | bpr | 646 | snprintf(buf,sizeof(buf),"%s",indbuf[i_description]); |
647 | for(pp=strchr(buf,','); pp; pp=strchr(pp,',')) |
||
648 | string_modify3(buf,pp,pp+1,","); |
||
649 | if(strcmp(module_language,lang[lind])==0) |
||
650 | fprintf(robotf,"%s ,%s,%s,%s,%s\n",name,module_language,name, |
||
651 | indbuf[i_title], buf); |
||
6819 | reyssat | 652 | |
6884 | bpr | 653 | /* Normalize the information of trlist, using dictionary |
7915 | bpr | 654 | * -- bases/sys/domain.xx without suffix translation (--> english version) |
6884 | bpr | 655 | */ |
15380 | bpr | 656 | entrycount=dentrycount; dicbuf=ddicbuf; |
657 | memmove(entry,dentry,dentrycount*sizeof(entry[0])); |
||
658 | unknown_type=unk_leave; |
||
659 | for(i=0;i<trcnt;i++) { |
||
660 | detag(indbuf[trlist[i]]); |
||
661 | deaccent2(indbuf[trlist[i]]); |
||
662 | comma(indbuf[trlist[i]]); |
||
663 | singlespace2(indbuf[trlist[i]]); |
||
664 | translate(indbuf[trlist[i]]); |
||
665 | } |
||
6884 | bpr | 666 | /* Normalize the information, using dictionary |
7915 | bpr | 667 | * bases/sys/words.xx with suffix translation |
6884 | bpr | 668 | */ |
15380 | bpr | 669 | entrycount=mentrycount; dicbuf=mdicbuf; |
670 | memmove(entry,mentry,mentrycount*sizeof(entry[0])); |
||
671 | unknown_type=unk_leave;/* used in translator_.c */ |
||
672 | for(i=0;i<trcnt;i++) { |
||
673 | suffix_translate(indbuf[trlist[i]]); |
||
674 | translate(indbuf[trlist[i]]); |
||
675 | } |
||
6881 | bpr | 676 | |
677 | /* taken contains all words already seen in the module index */ |
||
15380 | bpr | 678 | taken[0]=0; takenlen=tweight=0; |
6881 | bpr | 679 | /* append words of title */ |
15380 | bpr | 680 | ovlstrcpy(buf,indbuf[i_title]); towords(buf); |
681 | appenditem2(buf,lind,serial,4,module_language); |
||
6881 | bpr | 682 | |
6884 | bpr | 683 | /* extract words of every other information except level */ |
15380 | bpr | 684 | snprintf(buf,sizeof(buf),"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", |
685 | indbuf[i_description],indbuf[i_keywords], |
||
686 | indbuf[i_keywords_ca],indbuf[i_keywords_en],indbuf[i_keywords_fr], |
||
687 | indbuf[i_keywords_it],indbuf[i_keywords_nl], |
||
688 | indbuf[i_title_ca],indbuf[i_title_en],indbuf[i_title_fr], |
||
689 | indbuf[i_title_it],indbuf[i_title_nl], |
||
690 | indbuf[i_domain],indbuf[i_require],indbuf[i_author]); |
||
691 | towords(buf); |
||
692 | appenditem2(buf,lind,serial,2,module_language); |
||
6881 | bpr | 693 | |
6884 | bpr | 694 | /* this time the dictionary is the group dictionary sys/wgrp/wgrp |
695 | * with a g (groupdic), not an m (maindic) . see below main, suffix, group. |
||
7915 | bpr | 696 | * and delete unknown ?? and translate |
6884 | bpr | 697 | */ |
12248 | bpr | 698 | entrycount=gentrycount; dicbuf=gdicbuf; |
699 | memmove(entry,gentry,gentrycount*sizeof(entry[0])); |
||
6881 | bpr | 700 | |
15380 | bpr | 701 | /* append words of every title information */ |
12248 | bpr | 702 | ovlstrcpy(buf,indbuf[i_title]); |
703 | unknown_type=unk_delete; |
||
704 | translate(buf); |
||
705 | appenditem1(buf,lind,serial,2,module_language); |
||
6881 | bpr | 706 | |
15380 | bpr | 707 | /* append words of information of description except level */ |
12248 | bpr | 708 | snprintf(buf,sizeof(buf),"%s", indbuf[i_description]); |
709 | unknown_type=unk_delete; |
||
710 | translate(buf); |
||
711 | appenditem1(buf,lind,serial,4,module_language); |
||
6881 | bpr | 712 | |
15380 | bpr | 713 | /* append words (or group of words) of keywords and domain */ |
12248 | bpr | 714 | snprintf(buf,sizeof(buf),"%s, %s, %s, %s, %s, %s, %s", |
15380 | bpr | 715 | indbuf[i_domain],indbuf[i_keywords], |
716 | indbuf[i_keywords_ca], indbuf[i_keywords_en],indbuf[i_keywords_fr], |
||
717 | indbuf[i_keywords_it], indbuf[i_keywords_nl]); |
||
12248 | bpr | 718 | unknown_type=unk_leave; |
719 | translate(buf); |
||
720 | appenditem1(buf,lind,serial,2,module_language); |
||
6881 | bpr | 721 | |
15380 | bpr | 722 | /* append level information, with weight 2 */ |
12248 | bpr | 723 | snprintf(buf,sizeof(buf),"%s",indbuf[i_level]); |
724 | ovlstrcpy(lbuf,"level"); |
||
725 | for(p1=buf; *p1; p1++) if(!isalnum(*p1)) *p1=' '; |
||
726 | q=buf+strlen(buf); |
||
15380 | bpr | 727 | for(p1=find_word_start(buf); (*p1) && (p1 < q) ; p1=find_word_start(p2)) { |
12248 | bpr | 728 | p2=find_word_end(p1); |
729 | if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1); |
||
730 | if(strncmp(p1, "Lang" , p2-p1) && |
||
731 | (!isalpha(*p1) || |
||
732 | (!isdigit(*(p1+1)) && *(p1+1)!=0) || |
||
733 | (*(p1+1)!=0 && *(p1+2)!=0))) |
||
734 | continue; |
||
735 | *p1=tolower(*p1); |
||
736 | ovlstrcpy(lbuf+strlen("level"),p1); |
||
737 | appenditem(lbuf,lind,serial,2,module_language); |
||
738 | } |
||
6884 | bpr | 739 | /* append total weight of module to weight file site2/weight.xx */ |
12248 | bpr | 740 | fprintf(weightf,"%d:%d\n",serial,tweight); |
10 | reyssat | 741 | } |
742 | |||
743 | void modules(void) |
||
744 | { |
||
12248 | bpr | 745 | int i,j,k,d; |
746 | char namebuf[MAX_LINELEN+1]; |
||
747 | char mdic[MAX_LINELEN+1], sdic[MAX_LINELEN+1], gdic[MAX_LINELEN+1], ddic[MAX_LINELEN+1]; |
||
10 | reyssat | 748 | |
12248 | bpr | 749 | for(j=0;j<langcnt;j++) { |
6884 | bpr | 750 | snprintf(namebuf,sizeof(namebuf),"%s/weight.%s",outdir,lang[j]); |
751 | weightf=fopen(namebuf,"w"); |
||
752 | snprintf(mdic,sizeof(mdic),"%s/%s.%s",dicdir,maindic,lang[j]); |
||
753 | snprintf(sdic,sizeof(sdic),"%s/%s.%s",dicdir,suffixdic,lang[j]); |
||
754 | snprintf(gdic,sizeof(gdic),"%s/%s.%s",dicdir,groupdic,lang[j]); |
||
755 | snprintf(ddic,sizeof(ddic),"%s/%s.%s",dicdir,domaindic,lang[j]); |
||
756 | suffix_dic(sdic); prepare_dic(gdic); |
||
757 | gdicbuf=dicbuf; gentrycount=entrycount; |
||
758 | memmove(gentry,entry,gentrycount*sizeof(entry[0])); |
||
759 | prepare_dic(mdic); |
||
760 | mdicbuf=dicbuf; mentrycount=entrycount; |
||
761 | memmove(mentry,entry,mentrycount*sizeof(entry[0])); |
||
762 | prepare_dic(ddic); |
||
763 | ddicbuf=dicbuf; dentrycount=entrycount; |
||
764 | memmove(dentry,entry,dentrycount*sizeof(entry[0])); |
||
765 | unknown_type=unk_leave; translate(ignore[j]); |
||
766 | for(i=0;i<modcnt;i++) { |
||
12248 | bpr | 767 | if(mod[i].langcnt>0) { |
15336 | bpr | 768 | /* look for another language */ |
6884 | bpr | 769 | for(d=k=0;k<mod[i].langcnt;k++) |
15336 | bpr | 770 | if(mod[i].langs[k]<mod[i].langs[d]) d=k; |
6884 | bpr | 771 | for(k=0;k<mod[i].langcnt && mod[i].langs[k]!=j;k++); |
772 | if(k>=mod[i].langcnt) k=d; |
||
773 | snprintf(namebuf,MAX_LINELEN,"%s.%s",mod[i].name, |
||
12248 | bpr | 774 | lang[mod[i].langs[k]]); |
6884 | bpr | 775 | onemodule(namebuf,mod[i].counts[k],j); |
12248 | bpr | 776 | } |
777 | else { |
||
6884 | bpr | 778 | onemodule(mod[i].name,mod[i].counts[0],j); |
12248 | bpr | 779 | } |
10 | reyssat | 780 | } |
6884 | bpr | 781 | if(mentrycount>0) free(mdicbuf); |
782 | if(gentrycount>0) free(gdicbuf); |
||
783 | if(suffixcnt>0) free(sufbuf); |
||
784 | if(dentrycount>0) free(ddicbuf); |
||
785 | if(weightf) fclose(weightf); |
||
12248 | bpr | 786 | } |
10 | reyssat | 787 | } |
15394 | bpr | 788 | void clean(void) |
789 | { |
||
790 | int i; |
||
791 | for (i = 0; i < open_files; i++) fclose(files[i]); |
||
792 | fclose(langf); fclose(titf); fclose(descf); fclose(robotf); |
||
793 | fclose(authorf); fclose(versionf); |
||
794 | } |
||
10 | reyssat | 795 | |
6881 | bpr | 796 | /* FIXME ? differences with appenditem - use fprintf instead of snprintf */ |
10 | reyssat | 797 | void sappenditem(char *word, int lind, int serial, int weight) |
798 | { |
||
12248 | bpr | 799 | int ll; |
800 | char *p; |
||
6881 | bpr | 801 | |
12248 | bpr | 802 | if(!isalnum(*word) || (ll=strlen(word))<2 || |
803 | wordchr2(taken,word)!=NULL || |
||
804 | wordchr2(ignore[lind],word)!=NULL || |
||
805 | takenlen>=MAX_LINELEN-ll-16) |
||
806 | return; |
||
807 | if(ll==2 && (!isdigit(word[0]) || !isalpha(word[1]))) return; |
||
808 | for(p=word;*p;p++) if(!isalnum(*p) && *p!=' ') return; |
||
809 | taken[takenlen++]=' ';taken[takenlen++]=' '; |
||
810 | ovlstrcpy(taken+takenlen,word); |
||
811 | takenlen+=ll; tweight+=weight; |
||
812 | fprintf(indf,"%s:%d?%d\n",word,serial,weight); |
||
10 | reyssat | 813 | } |
15380 | bpr | 814 | /* onesg / onemodule are similar */ |
15375 | bpr | 815 | void onesg(int serial, int lind, int index(int)) |
10 | reyssat | 816 | { |
12248 | bpr | 817 | int i; |
818 | unsigned char trlist[]={ |
||
15375 | bpr | 819 | s_title,s_description,s_domain,s_keywords,s_information |
12248 | bpr | 820 | }; |
15380 | bpr | 821 | int trcnt=sizeof(trlist)/sizeof(trlist[0]); |
822 | char *p1, *p2, *q, buf[MAX_LINELEN+1], lbuf[16]; |
||
6881 | bpr | 823 | |
15375 | bpr | 824 | if(index(serial)) return; |
15440 | bpr | 825 | fprintf(listf,"%d:%s\n",serial,gsindbuf[SHEETINDEX_NO]); |
15375 | bpr | 826 | fprintf(titf,"%d:%s\n",serial,gsindbuf[s_title]); |
827 | fprintf(descf,"%d:%s\n",serial,gsindbuf[s_description]); |
||
828 | fprintf(remf,"%d:%s\n",serial,gsindbuf[s_information]); |
||
7915 | bpr | 829 | |
15380 | bpr | 830 | /* Normalize the information of trlist, using dictionary |
831 | * -- bases/sys/domain.xx without suffix translation (--> english version) |
||
832 | */ |
||
12248 | bpr | 833 | entrycount=dentrycount; dicbuf=ddicbuf; |
834 | memmove(entry,dentry,dentrycount*sizeof(entry[0])); |
||
835 | unknown_type=unk_leave; |
||
15380 | bpr | 836 | for(i=0;i<trcnt;i++) { |
15375 | bpr | 837 | detag(gsindbuf[trlist[i]]); |
838 | deaccent2(gsindbuf[trlist[i]]); |
||
839 | comma(gsindbuf[trlist[i]]); |
||
840 | singlespace2(gsindbuf[trlist[i]]); |
||
841 | translate(gsindbuf[trlist[i]]); |
||
12248 | bpr | 842 | } |
15380 | bpr | 843 | /* Normalize the information, using dictionary |
844 | * bases/sys/words.xx with suffix translation |
||
845 | */ |
||
12248 | bpr | 846 | entrycount=mentrycount; dicbuf=mdicbuf; |
847 | memmove(entry,mentry,mentrycount*sizeof(entry[0])); |
||
15380 | bpr | 848 | unknown_type=unk_leave;/* used in translator_.c */ |
849 | for(i=0;i<trcnt;i++) { |
||
15375 | bpr | 850 | suffix_translate(gsindbuf[trlist[i]]); |
851 | translate(gsindbuf[trlist[i]]); |
||
12248 | bpr | 852 | } |
15380 | bpr | 853 | |
854 | /* taken contains all words already seen in the module index */ |
||
12248 | bpr | 855 | taken[0]=0; takenlen=tweight=0; |
15380 | bpr | 856 | /* append words of title */ |
15375 | bpr | 857 | ovlstrcpy(buf,gsindbuf[s_title]); towords(buf); |
12248 | bpr | 858 | for(p1=find_word_start(buf);*p1; |
859 | p1=find_word_start(p2)) { |
||
6884 | bpr | 860 | p2=find_word_end(p1); if(*p2) *p2++=0; |
861 | sappenditem(p1,lind,serial,4); |
||
12248 | bpr | 862 | } |
15380 | bpr | 863 | |
864 | /* extract words of every other information except level */ |
||
12248 | bpr | 865 | snprintf(buf,sizeof(buf),"%s %s %s %s", |
15375 | bpr | 866 | gsindbuf[s_description],gsindbuf[s_keywords], |
867 | gsindbuf[s_domain],gsindbuf[s_information]); |
||
12248 | bpr | 868 | towords(buf); |
15375 | bpr | 869 | for(p1=find_word_start(buf);*p1;p1=find_word_start(p2)) { |
870 | p2=find_word_end(p1); if(*p2) *p2++=0; |
||
871 | sappenditem(p1,lind,serial,2); |
||
12248 | bpr | 872 | } |
15380 | bpr | 873 | /* this time the dictionary is the group dictionary sys/wgrp/wgrp |
874 | * with a g (groupdic), not an m (maindic) . see below main, suffix, group. |
||
875 | * and delete unknown ?? and translate |
||
876 | */ |
||
12248 | bpr | 877 | entrycount=gentrycount; dicbuf=gdicbuf; |
878 | memmove(entry,gentry,gentrycount*sizeof(entry[0])); |
||
15380 | bpr | 879 | |
880 | /* append words of every title information */ |
||
881 | ovlstrcpy(buf,gsindbuf[s_title]); |
||
12248 | bpr | 882 | unknown_type=unk_delete; |
15380 | bpr | 883 | translate(buf); |
15375 | bpr | 884 | for(p1=find_word_start(buf); *p1; p1=find_word_start(p2)) { |
885 | p2=strchr(p1,','); |
||
886 | if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1); |
||
887 | if(strlen(p1)<=0) continue; |
||
888 | sappenditem(p1,lind,serial,4); |
||
12248 | bpr | 889 | } |
15380 | bpr | 890 | |
891 | /* append words (or group of words) of keywords and domain */ |
||
12248 | bpr | 892 | snprintf(buf,sizeof(buf),"%s, %s", |
15375 | bpr | 893 | gsindbuf[s_keywords], |
894 | gsindbuf[s_domain]); |
||
15380 | bpr | 895 | unknown_type=unk_leave; |
12248 | bpr | 896 | translate(buf); |
15380 | bpr | 897 | for(p1=find_word_start(buf); *p1; p1=find_word_start(p2)) { |
6884 | bpr | 898 | p2=strchr(p1,','); |
899 | if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1); |
||
900 | if(strlen(p1)<=0) continue; |
||
901 | sappenditem(p1,lind,serial,2); |
||
12248 | bpr | 902 | } |
15380 | bpr | 903 | |
904 | /* append level information, with weight 2 */ |
||
905 | snprintf(buf,sizeof(buf),"%s",gsindbuf[s_level]); |
||
906 | ovlstrcpy(lbuf,"level"); |
||
907 | for(p1=buf; *p1; p1++) if(!isalnum(*p1)) *p1=' '; |
||
908 | q=buf+strlen(buf); |
||
909 | for(p1=find_word_start(buf); (*p1) && (p1 < q) ; |
||
910 | p1=find_word_start(p2)) { |
||
911 | p2=find_word_end(p1); |
||
912 | if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1); |
||
913 | if(strncmp(p1, "Lang" , p2-p1) && |
||
914 | (!isalpha(*p1) || (!isdigit(*(p1+1))) || |
||
915 | (*(p1+1)!=0 && *(p1+2)!=0))) |
||
916 | continue; |
||
917 | *p1=tolower(*p1); |
||
918 | ovlstrcpy(lbuf+strlen("level"),p1); |
||
919 | sappenditem(lbuf,lind,serial,2); |
||
920 | } |
||
921 | /* append total weight of module to weight file site2/weight.xx */ |
||
12248 | bpr | 922 | fprintf(weightf,"%d:%d\n",serial,tweight); |
10 | reyssat | 923 | } |
924 | |||
15375 | bpr | 925 | void sgs(char *outdir, int index(int)) |
10 | reyssat | 926 | { |
15440 | bpr | 927 | int i,j,k,d; |
12248 | bpr | 928 | char mdic[MAX_LINELEN+1], sdic[MAX_LINELEN+1], gdic[MAX_LINELEN+1], ddic[MAX_LINELEN+1]; |
929 | char buf[MAX_LINELEN+1]; |
||
7915 | bpr | 930 | |
15440 | bpr | 931 | snprintf(buf,sizeof(buf),"%s/list",outdir); |
932 | listf=fopen(buf,"w"); |
||
933 | snprintf(buf,sizeof(buf),"%s/title",outdir); |
||
934 | titf=fopen(buf,"w"); |
||
935 | snprintf(buf,sizeof(buf),"%s/description",outdir); |
||
936 | descf=fopen(buf,"w"); |
||
937 | snprintf(buf,sizeof(buf),"%s/information",outdir); |
||
938 | remf=fopen(buf,"w"); |
||
939 | if(!remf || !listf || !descf || !titf ) { |
||
940 | fprintf(stderr,"modind: error creating output files for %s.\n",outdir); exit(1); |
||
941 | } |
||
12248 | bpr | 942 | for(j=0;j<langcnt;j++) { |
15375 | bpr | 943 | snprintf(buf,sizeof(buf),"%s/%s",outdir,lang[j]); |
12248 | bpr | 944 | indf=fopen(buf,"w"); |
15375 | bpr | 945 | snprintf(buf,sizeof(buf),"%s/weight.%s",outdir,lang[j]); |
12248 | bpr | 946 | weightf=fopen(buf,"w"); |
15440 | bpr | 947 | if(!weightf || !indf ) { |
948 | fprintf(stderr,"modind: error creating output files for %s.\n",outdir); exit(1); |
||
9090 | bpr | 949 | } |
6884 | bpr | 950 | snprintf(mdic,sizeof(mdic),"%s/%s.%s",dicdir,maindic,lang[j]); |
951 | snprintf(sdic,sizeof(sdic),"%s/%s.%s",dicdir,suffixdic,lang[j]); |
||
952 | snprintf(gdic,sizeof(gdic),"%s/%s.%s",dicdir,groupdic,lang[j]); |
||
6961 | bpr | 953 | snprintf(ddic,sizeof(ddic),"%s/%s.%s",dicdir,domaindic,lang[j]); |
6884 | bpr | 954 | suffix_dic(sdic); prepare_dic(gdic); |
955 | gdicbuf=dicbuf; gentrycount=entrycount; |
||
956 | memmove(gentry,entry,gentrycount*sizeof(entry[0])); |
||
957 | prepare_dic(mdic); |
||
958 | mdicbuf=dicbuf; mentrycount=entrycount; |
||
959 | memmove(mentry,entry,mentrycount*sizeof(entry[0])); |
||
6973 | bpr | 960 | prepare_dic(ddic); |
961 | ddicbuf=dicbuf; dentrycount=entrycount; |
||
962 | memmove(dentry,entry,dentrycount*sizeof(entry[0])); |
||
6884 | bpr | 963 | unknown_type=unk_leave; translate(ignore[j]); |
15440 | bpr | 964 | for(i=0;i<modcnt;i++) |
965 | if(mod[i].langcnt>0) { |
||
966 | /* look for another language */ |
||
967 | for(d=k=0;k<mod[i].langcnt;k++) |
||
968 | if(mod[i].langs[k]<mod[i].langs[d]) d=k; |
||
969 | for(k=0;k<mod[i].langcnt && mod[i].langs[k]!=j;k++); |
||
970 | if(k>=mod[i].langcnt) k=d; |
||
971 | onesg(mod[i].counts[k],mod[i].langs[k],index); |
||
972 | } |
||
6884 | bpr | 973 | if(mentrycount>0) free(mdicbuf); |
974 | if(gentrycount>0) free(gdicbuf); |
||
975 | if(suffixcnt>0) free(sufbuf); |
||
6961 | bpr | 976 | if(dentrycount>0) free(ddicbuf); |
15440 | bpr | 977 | fclose(indf); fclose(weightf); |
12248 | bpr | 978 | } |
15440 | bpr | 979 | fclose(titf); fclose(descf); fclose(listf); fclose(titlef); fclose(remf); |
10 | reyssat | 980 | } |
981 | |||
982 | int main() |
||
983 | { |
||
12248 | bpr | 984 | gentry=xmalloc(entry_size); |
985 | dentry=xmalloc(entry_size); |
||
986 | mentry=xmalloc(entry_size); |
||
987 | prep(); |
||
988 | if(modcnt>0) modules(); |
||
989 | clean(); |
||
990 | sprep(); |
||
15375 | bpr | 991 | if(modcnt>0) sgs(sheetoutdir,sheet_index); |
992 | gprep(); |
||
993 | if(modcnt>0) sgs(glossaryoutdir,glossary_index); |
||
12248 | bpr | 994 | return 0; |
10 | reyssat | 995 | } |