Subversion Repositories wimsdev

Rev

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

Rev 15440 Rev 15442
Line 83... Line 83...
83
    int imod;
83
    int imod;
84
} revmod[MAX_MODULES];
84
} revmod[MAX_MODULES];
85
int modcnt;
85
int modcnt;
86
 
86
 
87
char *mlist;
87
char *mlist;
-
 
88
char *sheetindex[]={
-
 
89
  "title", "description",
-
 
90
  "duration", "severity",
-
 
91
  "level", "domain",
-
 
92
  "keywords", "reserved1", "reserved2", "information"
-
 
93
};
-
 
94
/* correspond to the order of sheetindex */
-
 
95
char *glindex[]={
-
 
96
  "gl_title", "gl_description",
-
 
97
  "", "",
-
 
98
  "gl_level", "gl_domain",
-
 
99
  "gl_keywords","","",""};
-
 
100
 
-
 
101
#define SHEETINDEX_NO (sizeof(sheetindex)/sizeof(sheetindex[0]))
-
 
102
char gsindbuf[SHEETINDEX_NO+1][MAX_LINELEN+1];
-
 
103
 
-
 
104
/* do not modify the order, correspond to the order in the sheet file */
-
 
105
enum{s_title, s_description,
-
 
106
      s_duration, s_severity,
-
 
107
      s_level, s_domain,
-
 
108
      s_keywords, s_reserved1, s_reserved2,
-
 
109
      s_information
-
 
110
};
-
 
111
 
-
 
112
char *modindex[]={
-
 
113
  "title", "description",
-
 
114
  "author", "address", "copyright",
-
 
115
  "version", "wims_version", "language",
-
 
116
  "category", "level", "domain", "keywords",
-
 
117
  "keywords_ca", "keywords_en", "keywords_fr", "keywords_it", "keywords_nl",
-
 
118
  "title_ca", "title_en", "title_fr", "title_it", "title_nl",
-
 
119
  "require"
-
 
120
};
-
 
121
#define MODINDEX_NO (sizeof(modindex)/sizeof(modindex[0]))
-
 
122
char indbuf[MODINDEX_NO][MAX_LINELEN+1];
-
 
123
enum{i_title, i_description,
-
 
124
  i_author,i_address,i_copyright,
-
 
125
  i_version,i_wims_version,i_language,
-
 
126
  i_category,i_level,i_domain,i_keywords,
-
 
127
  i_keywords_ca,i_keywords_en,i_keywords_fr,i_keywords_it,i_keywords_nl,
-
 
128
  i_title_ca,i_title_en,i_title_fr,i_title_it,i_title_nl,
-
 
129
  i_require
-
 
130
};
-
 
131
 
-
 
132
char *module_special_file[]={
-
 
133
  "intro","help","about"
-
 
134
};
-
 
135
#define MODSPEC_NO (sizeof(module_special_file)/sizeof(module_special_file[0]))
-
 
136
char module_language[4];
-
 
137
 
-
 
138
char *mdicbuf, *gdicbuf, *ddicbuf, *gentry, *mentry, *dentry;
-
 
139
 
-
 
140
int gentrycount, mentrycount, dentrycount;
-
 
141
 
88
 
142
 
89
/*  fold known accented letters to unaccented, other strange characters to space
143
/*  fold known accented letters to unaccented, other strange characters to space
90
 *  apostrophe is among the exceptions to be kept (important for multi-word expressions)
144
 *  apostrophe is among the exceptions to be kept (important for multi-word expressions)
91
 */
145
 */
92
void deaccent2(char *p)
146
void deaccent2(char *p)
93
{
147
{
94
  char *sp;
148
  char *sp;
95
  char *v;
149
  char *v;
96
  for(sp=p;*sp;sp++) {
150
  for(sp=p;*sp;sp++) {
97
  if(*sp<0 && (v=strchr(acctab,*sp))!=NULL)
151
  if(*sp<0 && (v=strchr(acctab,*sp))!=NULL)
98
    *sp=*(deatab+(v-acctab));
152
    *sp=*(deatab+(v-acctab));
Line 104... Line 158...
104
/*  translate everything non-alphanumeric into space */
158
/*  translate everything non-alphanumeric into space */
105
void towords(char *p)
159
void towords(char *p)
106
{
160
{
107
  char *pp;
161
  char *pp;
108
  for(pp=p;*pp;pp++) if(!isalnum(*pp) && strchr("&$+*",*pp)==0) *pp=' ';
162
  for(pp=p;*pp;pp++) if(!isalnum(*pp) && strchr("&$+*",*pp)==0) *pp=' ';
109
}
163
}
110
 
164
 
111
/*  Find first occurrence of word */
165
/*  Find first occurrence of word */
112
char *wordchr2(char *p, char *w)
166
char *wordchr2(char *p, char *w)
113
{
167
{
114
  char *r;
168
  char *r;
115
 
169
 
Line 127... Line 181...
127
    if(*pp=='<') {
181
    if(*pp=='<') {
128
      pp=find_tag_end(pp)-1; continue;
182
      pp=find_tag_end(pp)-1; continue;
129
    }
183
    }
130
    if(*pp=='"') {
184
    if(*pp=='"') {
131
      pp=strchr(pp+1,'"');
185
      pp=strchr(pp+1,'"');
132
      if(pp==NULL) return p+strlen(p); else continue;
186
      if(pp==NULL) return p+strlen(p); else continue;
133
    }
187
    }
134
    if(*pp=='\'') {
188
    if(*pp=='\'') {
135
      pp=strchr(pp+1,'\'');
189
      pp=strchr(pp+1,'\'');
136
      if(pp==NULL) return p+strlen(p); else continue;
190
      if(pp==NULL) return p+strlen(p); else continue;
137
    }
191
    }
138
  }
192
  }
Line 218... Line 272...
218
  buf=xmalloc(l+256); l=fread(buf,1,l,f);
272
  buf=xmalloc(l+256); l=fread(buf,1,l,f);
219
  fclose(f);
273
  fclose(f);
220
  if(l<=0) return; else buf[l]=0;
274
  if(l<=0) return; else buf[l]=0;
221
  _getdef(buf,name,value);
275
  _getdef(buf,name,value);
222
  free(buf);
276
  free(buf);
223
}
277
}
224
 
-
 
225
char *mdicbuf, *gdicbuf, *ddicbuf, *gentry, *mentry, *dentry;
-
 
226
 
-
 
227
int gentrycount, mentrycount, dentrycount;
-
 
228
 
278
 
229
/*  Preparation of data */
-
 
230
void prep(void)
279
void init(void)
231
{
280
{
232
  char buf[MAX_LINELEN+1];
281
  char buf[MAX_LINELEN+1];
233
  char *p1,*p2,*s,*old;
282
  char *p1,*p2,*s;
234
  int i,l,thislang,t;
283
  int i,l;
235
  FILE *f;
284
  FILE *f;
236
 
285
 
237
  s=getenv("modind_outdir"); if(s!=NULL && *s!=0) outdir=s;
286
  s=getenv("modind_outdir"); if(s!=NULL && *s!=0) outdir=s;
238
  s=getenv("modind_sheetdir"); if(s!=NULL && *s!=0) sheetdir=s;
287
  s=getenv("modind_sheetdir"); if(s!=NULL && *s!=0) sheetdir=s;
239
  s=getenv("modind_sheetoutdir"); if(s!=NULL && *s!=0) sheetoutdir=s;
288
  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);}
289
  s=getenv("modind_glossaryoutdir"); if(s!=NULL && *s!=0) glossaryoutdir=s;
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;
-
 
247
/* take the langs declared in conffile */
290
/* take the langs declared in conffile */
248
  getdef(conffile,"site_languages",buf);
291
  getdef(conffile,"site_languages",buf);
-
 
292
  langcnt=0;
249
  for(p1=buf;*p1;p1++) if(!isalnum(*p1)) *p1=' ';
293
  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)) {
294
  for(p1=find_word_start(buf); *p1 && langcnt<MAX_LANGS; p1=find_word_start(p2)) {
251
    p2=find_word_end(p1);
295
    p2=find_word_end(p1);
252
    if(p2!=p1+2 || !isalpha(*p1) || !isalpha(*(p1+1))) continue;
296
    if(p2!=p1+2 || !isalpha(*p1) || !isalpha(*(p1+1))) continue;
253
    memmove(lang[langcnt],p1,2); lang[langcnt++][2]=0;
297
    memmove(lang[langcnt],p1,2); lang[langcnt++][2]=0;
254
  }
298
  }
255
  if(langcnt==0) {/*  default languages */
299
  if(langcnt==0) {/*  default languages */
256
    langcnt=DEFAULT_LANGCNT;
300
    langcnt=DEFAULT_LANGCNT;
257
  }
301
  }
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++) {
302
  for(i=0;i<langcnt;i++) {
262
    snprintf(buf,sizeof(buf),"%s/%s.%s",dicdir,ignoredic,lang[i]);
303
    snprintf(buf,sizeof(buf),"%s/%s.%s",dicdir,ignoredic,lang[i]);
263
    f=fopen(buf,"r"); if(f==NULL) continue;
304
    f=fopen(buf,"r"); if(f==NULL) continue;
264
    l=fread(ignore[i],1,MAX_LINELEN,f);fclose(f);
305
    l=fread(ignore[i],1,MAX_LINELEN,f);fclose(f);
265
    if(l<0 || l>=MAX_LINELEN) l=0;
306
    if(l<0 || l>=MAX_LINELEN) l=0;
266
    ignore[i][l]=0;
307
    ignore[i][l]=0;
267
  }
308
  }
-
 
309
}
-
 
310
/*  Preparation of data */
-
 
311
void prep(void)
-
 
312
{
-
 
313
  char buf[MAX_LINELEN+1];
-
 
314
  char *p1,*p2,*s,*old;
-
 
315
  int i,l,thislang,t;
-
 
316
  modcnt=0;
-
 
317
  snprintf(buf,sizeof(buf),"%s/addr",outdir);
-
 
318
  addrf=fopen(buf,"w");
-
 
319
  if(!addrf) { fprintf(stderr,"modind: error creating output files addr.\n"); exit(1);}
-
 
320
  snprintf(buf,sizeof(buf),"%s/serial",outdir);
-
 
321
  serialf=fopen(buf,"w");
-
 
322
  if(!serialf) { fprintf(stderr,"modind: error creating output files serial.\n"); exit(1);}
-
 
323
 
-
 
324
  s=getenv("mlist"); if(s==NULL) exit(1);
-
 
325
  l=strlen(s); if(l<0 || l>100*MAX_LINELEN) exit(1);
-
 
326
  mlist=xmalloc(l+16); ovlstrcpy(mlist,s); old="";
-
 
327
 
268
  for(t=0, p1=find_word_start(mlist); *p1 && modcnt<MAX_MODULES;
328
  for(t=0, p1=find_word_start(mlist); *p1 && modcnt<MAX_MODULES;
269
        p1=find_word_start(p2), t++) {
329
        p1=find_word_start(p2), t++) {
270
    p2=find_word_end(p1);
330
    p2=find_word_end(p1);
271
    l=p2-p1; if(*p2) *p2++=0;
331
    l=p2-p1; if(*p2) *p2++=0;
272
    fprintf(addrf,"%d:%s\n",t,p1);
332
    fprintf(addrf,"%d:%s\n",t,p1);
273
    fprintf(serialf,"%s:%d\n",p1,t);
333
    fprintf(serialf,"%s:%d\n",p1,t);
274
    thislang=-1;
334
    thislang=-1;
275
/* language is taken from the address */
335
/* language is taken from the address */
276
    if(l>3 && p1[l-3]=='.') {
336
    if(l>3 && p1[l-3]=='.') {
Line 283... Line 343...
283
    if(modcnt>0 && strcmp(old,p1)==0 && thislang>=0) {
343
    if(modcnt>0 && strcmp(old,p1)==0 && thislang>=0) {
284
      if(mod[modcnt-1].langcnt<langcnt) {
344
      if(mod[modcnt-1].langcnt<langcnt) {
285
        mod[modcnt-1].langs[mod[modcnt-1].langcnt]=thislang;
345
        mod[modcnt-1].langs[mod[modcnt-1].langcnt]=thislang;
286
        mod[modcnt-1].counts[mod[modcnt-1].langcnt]=t;
346
        mod[modcnt-1].counts[mod[modcnt-1].langcnt]=t;
287
        (mod[modcnt-1].langcnt)++;
347
        (mod[modcnt-1].langcnt)++;
288
      }
348
      }
289
    }
349
    }
290
    else {
350
    else {
291
      mod[modcnt].name=old=p1;
351
      mod[modcnt].name=old=p1;
292
      if(thislang>=0) {
352
      if(thislang>=0) {
293
        mod[modcnt].langs[0]=thislang;
353
        mod[modcnt].langs[0]=thislang;
294
        mod[modcnt].langcnt=1;
354
        mod[modcnt].langcnt=1;
Line 312... Line 372...
312
  robotf=fopen(buf,"w");
372
  robotf=fopen(buf,"w");
313
  fclose(addrf); fclose(serialf);
373
  fclose(addrf); fclose(serialf);
314
  if(!robotf || !versionf || !authorf || !descf || !titf || !langf) {
374
  if(!robotf || !versionf || !authorf || !descf || !titf || !langf) {
315
    fprintf(stderr,"modind: error creating output files.\n");
375
    fprintf(stderr,"modind: error creating output files.\n");
316
    exit(1);
376
    exit(1);
317
  }
377
  }
318
}
378
}
319
 
379
 
320
void sprep(void)
380
void sprep(void)
321
{
381
{
322
  char buf[MAX_LINELEN+1];
382
  char buf[MAX_LINELEN+1];
Line 400... Line 460...
400
      modcnt++;
460
      modcnt++;
401
    }
461
    }
402
  }
462
  }
403
  fclose(addrf); fclose(serialf);
463
  fclose(addrf); fclose(serialf);
404
}
464
}
405
 
-
 
406
char *sheetindex[]={
-
 
407
  "title", "description",
-
 
408
  "duration", "severity",
-
 
409
  "level", "domain",
-
 
410
  "keywords", "reserved1", "reserved2", "information"
-
 
411
};
-
 
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
 
-
 
419
#define SHEETINDEX_NO (sizeof(sheetindex)/sizeof(sheetindex[0]))
-
 
420
char gsindbuf[SHEETINDEX_NO+1][MAX_LINELEN+1];
-
 
421
 
-
 
422
/* do not modify the order, correspond to the order in the sheet file */
-
 
423
enum{s_title, s_description,
-
 
424
      s_duration, s_severity,
-
 
425
      s_level, s_domain,
-
 
426
      s_keywords, s_reserved1, s_reserved2,
-
 
427
      s_information
-
 
428
};
-
 
429
 
-
 
430
char *modindex[]={
-
 
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"
-
 
438
};
-
 
439
#define MODINDEX_NO (sizeof(modindex)/sizeof(modindex[0]))
-
 
440
char indbuf[MODINDEX_NO][MAX_LINELEN+1];
-
 
441
enum{i_title, i_description,
-
 
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
-
 
448
};
-
 
449
 
-
 
450
char *module_special_file[]={
-
 
451
  "intro","help","about"
-
 
452
};
-
 
453
#define MODSPEC_NO (sizeof(module_special_file)/sizeof(module_special_file[0]))
-
 
454
char module_language[4];
-
 
455
 
465
 
456
/*  read and treat module's INDEX file */
466
/*  read and treat module's INDEX file */
457
int module_index(const char *name)
467
int module_index(const char *name)
458
{
468
{
459
  char *p, fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1];
469
  char *p, fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1];
Line 820... Line 830...
820
  };
830
  };
821
  int trcnt=sizeof(trlist)/sizeof(trlist[0]);
831
  int trcnt=sizeof(trlist)/sizeof(trlist[0]);
822
  char *p1, *p2, *q, buf[MAX_LINELEN+1], lbuf[16];
832
  char *p1, *p2, *q, buf[MAX_LINELEN+1], lbuf[16];
823
 
833
 
824
  if(index(serial)) return;
834
  if(index(serial)) return;
825
  fprintf(listf,"%d:%s\n",serial,gsindbuf[SHEETINDEX_NO]);
-
 
826
  fprintf(titf,"%d:%s\n",serial,gsindbuf[s_title]);
835
  fprintf(titf,"%d:%s\n",serial,gsindbuf[s_title]);
827
  fprintf(descf,"%d:%s\n",serial,gsindbuf[s_description]);
836
  fprintf(descf,"%d:%s\n",serial,gsindbuf[s_description]);
828
  fprintf(remf,"%d:%s\n",serial,gsindbuf[s_information]);
837
  fprintf(remf,"%d:%s\n",serial,gsindbuf[s_information]);
829
 
838
 
830
/*   Normalize the information of trlist, using dictionary
839
/*   Normalize the information of trlist, using dictionary
Line 926... Line 935...
926
{
935
{
927
  int i,j,k,d;
936
  int i,j,k,d;
928
  char mdic[MAX_LINELEN+1], sdic[MAX_LINELEN+1], gdic[MAX_LINELEN+1], ddic[MAX_LINELEN+1];
937
  char mdic[MAX_LINELEN+1], sdic[MAX_LINELEN+1], gdic[MAX_LINELEN+1], ddic[MAX_LINELEN+1];
929
  char buf[MAX_LINELEN+1];
938
  char buf[MAX_LINELEN+1];
930
 
939
 
931
  snprintf(buf,sizeof(buf),"%s/list",outdir);
940
  //snprintf(buf,sizeof(buf),"%s/list",outdir);
932
  listf=fopen(buf,"w");
941
  //listf=fopen(buf,"w");
933
  snprintf(buf,sizeof(buf),"%s/title",outdir);
942
  snprintf(buf,sizeof(buf),"%s/title",outdir);
934
  titf=fopen(buf,"w");
943
  titf=fopen(buf,"w");
935
  snprintf(buf,sizeof(buf),"%s/description",outdir);
944
  snprintf(buf,sizeof(buf),"%s/description",outdir);
936
  descf=fopen(buf,"w");
945
  descf=fopen(buf,"w");
937
  snprintf(buf,sizeof(buf),"%s/information",outdir);
946
  snprintf(buf,sizeof(buf),"%s/information",outdir);
938
  remf=fopen(buf,"w");
947
  remf=fopen(buf,"w");
939
  if(!remf || !listf || !descf || !titf ) {
948
  if(!remf || !descf || !titf ) {
940
    fprintf(stderr,"modind: error creating output files for %s.\n",outdir); exit(1);
949
    fprintf(stderr,"modind: error creating output files for %s.\n",outdir); exit(1);
941
  }
950
  }
942
  for(j=0;j<langcnt;j++) {
951
  for(j=0;j<langcnt;j++) {
943
    snprintf(buf,sizeof(buf),"%s/%s",outdir,lang[j]);
952
    snprintf(buf,sizeof(buf),"%s/%s",outdir,lang[j]);
944
    indf=fopen(buf,"w");
953
    indf=fopen(buf,"w");
Line 974... Line 983...
974
    if(gentrycount>0) free(gdicbuf);
983
    if(gentrycount>0) free(gdicbuf);
975
    if(suffixcnt>0) free(sufbuf);
984
    if(suffixcnt>0) free(sufbuf);
976
    if(dentrycount>0) free(ddicbuf);
985
    if(dentrycount>0) free(ddicbuf);
977
    fclose(indf); fclose(weightf);
986
    fclose(indf); fclose(weightf);
978
  }
987
  }
979
  fclose(titf); fclose(descf); fclose(listf); fclose(titlef); fclose(remf);
988
  fclose(titf); fclose(descf); fclose(titlef); fclose(remf);
980
}
989
}
981
 
990
 
982
int main()
991
int main()
983
{
992
{
984
  gentry=xmalloc(entry_size);
993
  gentry=xmalloc(entry_size);
985
  dentry=xmalloc(entry_size);
994
  dentry=xmalloc(entry_size);
986
  mentry=xmalloc(entry_size);
995
  mentry=xmalloc(entry_size);
-
 
996
  init();
987
  prep();
997
  prep();
988
  if(modcnt>0) modules();
998
  if(modcnt>0) modules();
989
  clean();
999
  clean();
990
  sprep();
1000
  sprep();
991
  if(modcnt>0) sgs(sheetoutdir,sheet_index);
1001
  if(modcnt>0) sgs(sheetoutdir,sheet_index);