Subversion Repositories wimsdev

Rev

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

Rev 8863 Rev 9090
Line 27... Line 27...
27
#define MAX_MODULES    65536
27
#define MAX_MODULES    65536
28
char *moduledir=    "public_html/modules";
28
char *moduledir=    "public_html/modules";
29
char *sheetdir=     "public_html/bases/sheet";
29
char *sheetdir=     "public_html/bases/sheet";
30
char *dicdir=       "public_html/bases";
30
char *dicdir=       "public_html/bases";
31
char *outdir=       "public_html/bases/site2";
31
char *outdir=       "public_html/bases/site2";
-
 
32
char *sheetoutdir=  "public_html/bases/sheet/index";
32
char *maindic=      "sys/words";
33
char *maindic=      "sys/words";
33
char *groupdic=     "sys/wgrp/wgrp";
34
char *groupdic=     "sys/wgrp/wgrp";
34
char *suffixdic=    "sys/suffix";
35
char *suffixdic=    "sys/suffix";
35
char *domaindic=    "sys/domaindic";
36
char *domaindic=    "sys/domaindic";
36
char *ignoredic=    "sys/indignore";
37
char *ignoredic=    "sys/indignore";
Line 211... Line 212...
211
    int i,l,thislang,t;
212
    int i,l,thislang,t;
212
    FILE *f;
213
    FILE *f;
213
 
214
 
214
    s=getenv("modind_outdir"); if(s!=NULL && *s!=0) outdir=s;
215
    s=getenv("modind_outdir"); if(s!=NULL && *s!=0) outdir=s;
215
    s=getenv("modind_sheetdir"); if(s!=NULL && *s!=0) sheetdir=s;
216
    s=getenv("modind_sheetdir"); if(s!=NULL && *s!=0) sheetdir=s;
-
 
217
    s=getenv("modind_sheetoutdir"); if(s!=NULL && *s!=0) sheetoutdir=s;
216
    snprintf(buf,sizeof(buf),"%s/addr",outdir);
218
    snprintf(buf,sizeof(buf),"%s/addr",outdir);
217
    addrf=fopen(buf,"w");
219
    addrf=fopen(buf,"w");
-
 
220
    if(!addrf) { fprintf(stderr,"modind: error creating output files addr.\n"); exit(1);}
218
    snprintf(buf,sizeof(buf),"%s/serial",outdir);
221
    snprintf(buf,sizeof(buf),"%s/serial",outdir);
219
    serialf=fopen(buf,"w");
222
    serialf=fopen(buf,"w");
-
 
223
    if(!serialf) { fprintf(stderr,"modind: error creating output files serial.\n"); exit(1);}
220
    modcnt=langcnt=0;
224
    modcnt=langcnt=0;
221
/* take the langs declared in conffile */
225
/* take the langs declared in conffile */
222
    getdef(conffile,"site_languages",buf);
226
    getdef(conffile,"site_languages",buf);
223
    for(p1=buf;*p1;p1++) if(!isalnum(*p1)) *p1=' ';
227
    for(p1=buf;*p1;p1++) if(!isalnum(*p1)) *p1=' ';
224
    for(p1=find_word_start(buf); *p1 && langcnt<MAX_LANGS; p1=find_word_start(p2)) {
228
    for(p1=find_word_start(buf); *p1 && langcnt<MAX_LANGS; p1=find_word_start(p2)) {
Line 231... Line 235...
231
    }
235
    }
232
    s=getenv("mlist"); if(s==NULL) exit(1);
236
    s=getenv("mlist"); if(s==NULL) exit(1);
233
    l=strlen(s); if(l<0 || l>100*MAX_LINELEN) exit(1);
237
    l=strlen(s); if(l<0 || l>100*MAX_LINELEN) exit(1);
234
    mlist=xmalloc(l+16); ovlstrcpy(mlist,s); old="";
238
    mlist=xmalloc(l+16); ovlstrcpy(mlist,s); old="";
235
    for(i=0;i<langcnt;i++) {
239
    for(i=0;i<langcnt;i++) {
236
    snprintf(buf,sizeof(buf),"%s/%s.%s",dicdir,ignoredic,lang[i]);
240
      snprintf(buf,sizeof(buf),"%s/%s.%s",dicdir,ignoredic,lang[i]);
237
    f=fopen(buf,"r"); if(f==NULL) continue;
241
      f=fopen(buf,"r"); if(f==NULL) continue;
238
    l=fread(ignore[i],1,MAX_LINELEN,f);fclose(f);
242
      l=fread(ignore[i],1,MAX_LINELEN,f);fclose(f);
239
    if(l<0 || l>=MAX_LINELEN) l=0;
243
      if(l<0 || l>=MAX_LINELEN) l=0;
240
    ignore[i][l]=0;
244
      ignore[i][l]=0;
241
    }
245
    }
242
    for(t=0, p1=find_word_start(mlist);
246
    for(t=0, p1=find_word_start(mlist); *p1 && modcnt<MAX_MODULES;
243
    *p1 && modcnt<MAX_MODULES;
-
 
244
    p1=find_word_start(p2), t++) {
247
        p1=find_word_start(p2), t++) {
245
    p2=find_word_end(p1);
248
      p2=find_word_end(p1);
246
    l=p2-p1; if(*p2) *p2++=0;
249
      l=p2-p1; if(*p2) *p2++=0;
247
    fprintf(addrf,"%d:%s\n",t,p1);
250
      fprintf(addrf,"%d:%s\n",t,p1);
248
    fprintf(serialf,"%s:%d\n",p1,t);
251
      fprintf(serialf,"%s:%d\n",p1,t);
249
    thislang=-1;
252
      thislang=-1;
250
/* language is taken from the address */
253
/* language is taken from the address */
251
    if(l>3 && p1[l-3]=='.') {
254
      if(l>3 && p1[l-3]=='.') {
252
        for(i=0;i<langcnt;i++) if(strcasecmp(lang[i],p1+l-2)==0) break;
255
        for(i=0;i<langcnt;i++) if(strcasecmp(lang[i],p1+l-2)==0) break;
253
        if(i<langcnt) {p1[l-3]=0; thislang=i;}
256
        if(i<langcnt) {p1[l-3]=0; thislang=i;}
254
        else {/*  unknown language, not referenced */
257
        else {/*  unknown language, not referenced */
255
        continue;
258
        continue;
256
        }
259
        }
257
    }
260
      }
258
    if(modcnt>0 && strcmp(old,p1)==0 && thislang>=0) {
261
      if(modcnt>0 && strcmp(old,p1)==0 && thislang>=0) {
259
        if(mod[modcnt-1].langcnt<langcnt) {
262
        if(mod[modcnt-1].langcnt<langcnt) {
260
        mod[modcnt-1].langs[mod[modcnt-1].langcnt]=thislang;
263
        mod[modcnt-1].langs[mod[modcnt-1].langcnt]=thislang;
261
        mod[modcnt-1].counts[mod[modcnt-1].langcnt]=t;
264
        mod[modcnt-1].counts[mod[modcnt-1].langcnt]=t;
262
        (mod[modcnt-1].langcnt)++;
265
        (mod[modcnt-1].langcnt)++;
263
        }
266
        }
264
    }
267
     }
265
    else {
268
     else {
266
        mod[modcnt].name=old=p1;
269
        mod[modcnt].name=old=p1;
267
        if(thislang>=0) {
270
        if(thislang>=0) {
268
        mod[modcnt].langs[0]=thislang;
271
          mod[modcnt].langs[0]=thislang;
269
        mod[modcnt].langcnt=1;
272
          mod[modcnt].langcnt=1;
270
        }
273
        }
271
        else mod[modcnt].langcnt=0;
274
        else mod[modcnt].langcnt=0;
272
        mod[modcnt].counts[0]=t;
275
        mod[modcnt].counts[0]=t;
273
        modcnt++;
276
        modcnt++;
274
    }
277
    }
Line 284... Line 287...
284
    snprintf(buf,sizeof(buf),"%s/version",outdir);
287
    snprintf(buf,sizeof(buf),"%s/version",outdir);
285
    versionf=fopen(buf,"w");
288
    versionf=fopen(buf,"w");
286
    snprintf(buf,sizeof(buf),"%s/lists/robot.phtml",outdir);
289
    snprintf(buf,sizeof(buf),"%s/lists/robot.phtml",outdir);
287
    robotf=fopen(buf,"w");
290
    robotf=fopen(buf,"w");
288
    fclose(addrf); fclose(serialf);
291
    fclose(addrf); fclose(serialf);
289
    if(!robotf || !versionf || !authorf || !descf || !titf || !descf) {
292
    if(!robotf || !versionf || !authorf || !descf || !titf || !langf) {
290
    fprintf(stderr,"modind: error creating output files.\n");
293
      fprintf(stderr,"modind: error creating output files.\n");
291
    exit(1);
294
      exit(1);
292
    }
295
    }
293
}
296
}
294
 
297
 
295
void sprep(void)
298
void sprep(void)
296
{
299
{
Line 366... Line 369...
366
    char *p, fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1];
369
    char *p, fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1];
367
    FILE *indf;
370
    FILE *indf;
368
    int i,l;
371
    int i,l;
369
 
372
 
370
    snprintf(fbuf,sizeof(fbuf),"%s/%s/INDEX",moduledir,name);
373
    snprintf(fbuf,sizeof(fbuf),"%s/%s/INDEX",moduledir,name);
371
    indf=fopen(fbuf,"r"); if(indf==NULL) return -1;
374
    indf=fopen(fbuf,"r");
-
 
375
    if(indf==NULL) {
-
 
376
      fprintf(stderr,"modind: INDEX of %s not found\n",fbuf); return -1
-
 
377
    }
372
    l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf);
378
    l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf);
373
    if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1;
379
    if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1;
374
/* treate all fields in *modindex */
380
/* treate all fields in *modindex */
375
    for(i=0;i<MODINDEX_NO;i++) {
381
    for(i=0;i<MODINDEX_NO;i++) {
376
    _getdef(ibuf,modindex[i],indbuf[i]);
382
      _getdef(ibuf,modindex[i],indbuf[i]);
377
/*  compatibility precaution */
383
/*  compatibility precaution */
378
    if(indbuf[i][0]==':') indbuf[i][0]='.';
384
      if(indbuf[i][0]==':') indbuf[i][0]='.';
379
    }
385
    }
380
    p=find_word_start(indbuf[i_language]);
386
    p=find_word_start(indbuf[i_language]);
381
    if(isalpha(*p) && isalpha(*(p+1))) {
387
    if(isalpha(*p) && isalpha(*(p+1))) {
382
    memmove(module_language,p,2); module_language[2]=0;
388
      memmove(module_language,p,2); module_language[2]=0;
383
    }
389
    }
384
    else ovlstrcpy(module_language,"en");
390
    else ovlstrcpy(module_language,"en");
385
    return 0;
391
    return 0;
386
}
392
}
387
 
393
 
Line 395... Line 401...
395
    indf=fopen(fbuf,"r"); if(indf==NULL) return -1;
401
    indf=fopen(fbuf,"r"); if(indf==NULL) return -1;
396
    l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf);
402
    l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf);
397
    if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1;
403
    if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1;
398
    for(i=0;i<SHEETINDEX_NO;i++) sindbuf[i][0]=0;
404
    for(i=0;i<SHEETINDEX_NO;i++) sindbuf[i][0]=0;
399
    for(i=0,p1=find_word_start(ibuf);
405
    for(i=0,p1=find_word_start(ibuf);
400
    i<SHEETINDEX_NO-1 && *p1!=':' && *p1!=0;
406
      i<SHEETINDEX_NO-1 && *p1!=':' && *p1!=0;
401
    i++,p1=p2) {
407
      i++,p1=p2) {
402
    p2=strchr(p1,'\n');
408
       p2=strchr(p1,'\n');
403
    if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
409
       if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
404
    p1=find_word_start(p1); strip_trailing_spaces2(p1);
410
       p1=find_word_start(p1); strip_trailing_spaces2(p1);
405
    snprintf(sindbuf[i],MAX_LINELEN,"%s",p1);
411
       snprintf(sindbuf[i],MAX_LINELEN,"%s",p1);
406
    }
412
    }
407
    p2=strstr(p1,"\n:"); if(p2==NULL) p2=p1+strlen(p1);
413
    p2=strstr(p1,"\n:"); if(p2==NULL) p2=p1+strlen(p1);
408
    else *p2=0;
414
    else *p2=0;
409
    p1=find_word_start(p1); strip_trailing_spaces2(p1);
415
    p1=find_word_start(p1); strip_trailing_spaces2(p1);
410
    for(p2=p1;*p2;p2++) if(*p2=='\n') *p2=' ';
416
    for(p2=p1;*p2;p2++) if(*p2=='\n') *p2=' ';
Line 441... Line 447...
441
    if(f!=NULL) {fputs(buf,f); fclose(f);}
447
    if(f!=NULL) {fputs(buf,f); fclose(f);}
442
    }
448
    }
443
}
449
}
444
 
450
 
445
void appenditem1 (char *buf, int lind, int serial, int weight, char *l )
451
void appenditem1 (char *buf, int lind, int serial, int weight, char *l )
446
{
452
{
447
  char *p1, *p2 ;
453
  char *p1, *p2 ;
448
  for(p1=find_word_start(buf); *p1;
454
  for(p1=find_word_start(buf); *p1;
449
    p1=find_word_start(p2)) {
455
    p1=find_word_start(p2)) {
450
    p2=strchr(p1,',');
456
    p2=strchr(p1,',');
451
    if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
457
    if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
Line 489... Line 495...
489
      categories[catcnt++]=cat[0].typ;
495
      categories[catcnt++]=cat[0].typ;
490
/*  write module's name in the category.language files, for instance lists/X.fr
496
/*  write module's name in the category.language files, for instance lists/X.fr
491
 * for french exercises
497
 * for french exercises
492
 */
498
 */
493
    for(i=0;i<catcnt;i++) {
499
    for(i=0;i<catcnt;i++) {
494
    snprintf(buf,sizeof(buf),"%s/lists/%c.%s",
500
      snprintf(buf,sizeof(buf),"%s/lists/%c.%s",
495
         outdir,categories[i],lang[lind]);
501
         outdir,categories[i],lang[lind]);
496
    f=fopen(buf,"a");
502
      f=fopen(buf,"a");
497
    if(f!=NULL) {fprintf(f,"%s\n",name); fclose(f);}
503
      if(f!=NULL) {fprintf(f,"%s\n",name); fclose(f);}
498
    }
504
    }
499
/*   add serial number and language (resp.title, ...) to corresponding file  */
505
/*   add serial number and language (resp.title, ...) to corresponding file  */
500
    fprintf(langf,"%d:%s\n",serial,module_language);
506
    fprintf(langf,"%d:%s\n",serial,module_language);
501
    fprintf(titf,"%d:%s\n",serial,indbuf[i_title]);
507
    fprintf(titf,"%d:%s\n",serial,indbuf[i_title]);
502
    fprintf(descf,"%d:%s\n",serial,indbuf[i_description]);
508
    fprintf(descf,"%d:%s\n",serial,indbuf[i_description]);
Line 559... Line 565...
559
    entrycount=gentrycount; dicbuf=gdicbuf;
565
    entrycount=gentrycount; dicbuf=gdicbuf;
560
    memmove(entry,gentry,gentrycount*sizeof(entry[0]));
566
    memmove(entry,gentry,gentrycount*sizeof(entry[0]));
561
 
567
 
562
/*  append words of every title information  */
568
/*  append words of every title information  */
563
    ovlstrcpy(buf,indbuf[i_title]);
569
    ovlstrcpy(buf,indbuf[i_title]);
564
    unknown_type=unk_delete;
570
    unknown_type=unk_delete;
565
    translate(buf);
571
    translate(buf);
566
    appenditem1(buf,lind,serial,2,module_language);
572
    appenditem1(buf,lind,serial,2,module_language);
567
 
573
 
568
/*  append words of information of description except level  */
574
/*  append words of information of description except level  */
569
    snprintf(buf,sizeof(buf),"%s", indbuf[i_description]);
575
    snprintf(buf,sizeof(buf),"%s", indbuf[i_description]);
570
    unknown_type=unk_delete;
576
    unknown_type=unk_delete;
571
    translate(buf);
577
    translate(buf);
572
    appenditem1(buf,lind,serial,4,module_language);
578
    appenditem1(buf,lind,serial,4,module_language);
573
 
579
 
574
/*  append words (or group of words) of keywords and domain  */
580
/*  append words (or group of words) of keywords and domain  */
575
    snprintf(buf,sizeof(buf),"%s, %s, %s, %s, %s, %s, %s",
581
    snprintf(buf,sizeof(buf),"%s, %s, %s, %s, %s, %s, %s",
576
         indbuf[i_domain],indbuf[i_keywords],
582
         indbuf[i_domain],indbuf[i_keywords],
577
         indbuf[i_keywords_ca], indbuf[i_keywords_en],indbuf[i_keywords_fr],
583
         indbuf[i_keywords_ca], indbuf[i_keywords_en],indbuf[i_keywords_fr],
578
         indbuf[i_keywords_it], indbuf[i_keywords_nl]);
584
         indbuf[i_keywords_it], indbuf[i_keywords_nl]);
Line 585... Line 591...
585
    ovlstrcpy(lbuf,"level");
591
    ovlstrcpy(lbuf,"level");
586
    for(p1=buf; *p1; p1++) if(!isalnum(*p1)) *p1=' ';
592
    for(p1=buf; *p1; p1++) if(!isalnum(*p1)) *p1=' ';
587
    q=buf+strlen(buf);
593
    q=buf+strlen(buf);
588
    for(p1=find_word_start(buf); (*p1) && (p1 < q) ;
594
    for(p1=find_word_start(buf); (*p1) && (p1 < q) ;
589
    p1=find_word_start(p2)) {
595
    p1=find_word_start(p2)) {
590
    p2=find_word_end(p1);
596
      p2=find_word_end(p1);
591
    if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
597
      if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
592
    if(!isalpha(*p1) ||
598
      if(!isalpha(*p1) ||
593
       (!isdigit(*(p1+1)) && *(p1+1)!=0) ||
599
       (!isdigit(*(p1+1)) && *(p1+1)!=0) ||
594
       (*(p1+1)!=0 && *(p1+2)!=0))
600
       (*(p1+1)!=0 && *(p1+2)!=0))
595
      continue;
601
      continue;
596
    *p1=tolower(*p1);
602
      *p1=tolower(*p1);
597
    ovlstrcpy(lbuf+strlen("level"),p1);
603
      ovlstrcpy(lbuf+strlen("level"),p1);
598
    appenditem(lbuf,lind,serial,2,module_language);
604
      appenditem(lbuf,lind,serial,2,module_language);
599
    }
605
    }
600
/*   append total weight of module to weight file site2/weight.xx  */
606
/*   append total weight of module to weight file site2/weight.xx  */
601
    fprintf(weightf,"%d:%d\n",serial,tweight);
607
    fprintf(weightf,"%d:%d\n",serial,tweight);
602
}
608
}
603
 
609
 
Line 745... Line 751...
745
    int i,j;
751
    int i,j;
746
    char mdic[MAX_LINELEN+1], sdic[MAX_LINELEN+1], gdic[MAX_LINELEN+1], ddic[MAX_LINELEN+1];
752
    char mdic[MAX_LINELEN+1], sdic[MAX_LINELEN+1], gdic[MAX_LINELEN+1], ddic[MAX_LINELEN+1];
747
    char buf[MAX_LINELEN+1];
753
    char buf[MAX_LINELEN+1];
748
 
754
 
749
    for(j=0;j<langcnt;j++) {
755
    for(j=0;j<langcnt;j++) {
750
    snprintf(buf,sizeof(buf),"%s/index/title.%s",sheetdir,lang[j]);
756
      snprintf(buf,sizeof(buf),"%s/title.%s",sheetoutdir,lang[j]);
751
    titf=fopen(buf,"w");
757
      titf=fopen(buf,"w");
752
    snprintf(buf,sizeof(buf),"%s/index/description.%s",sheetdir,lang[j]);
758
      snprintf(buf,sizeof(buf),"%s/description.%s",sheetoutdir,lang[j]);
753
    descf=fopen(buf,"w");
759
      descf=fopen(buf,"w");
754
    snprintf(buf,sizeof(buf),"%s/index/%s",sheetdir,lang[j]);
760
      snprintf(buf,sizeof(buf),"%s/%s",sheetoutdir,lang[j]);
755
    indf=fopen(buf,"w");
761
      indf=fopen(buf,"w");
756
    snprintf(buf,sizeof(buf),"%s/index/list.%s",sheetdir,lang[j]);
762
      snprintf(buf,sizeof(buf),"%s/list.%s",sheetoutdir,lang[j]);
757
    listf=fopen(buf,"w");
763
      listf=fopen(buf,"w");
758
    snprintf(buf,sizeof(buf),"%s/index/weight.%s",sheetdir,lang[j]);
764
      snprintf(buf,sizeof(buf),"%s/weight.%s",sheetoutdir,lang[j]);
759
    weightf=fopen(buf,"w");
765
      weightf=fopen(buf,"w");
760
    snprintf(buf,sizeof(buf),"%s/index/addr.%s",sheetdir,lang[j]);
766
      snprintf(buf,sizeof(buf),"%s/addr.%s",sheetoutdir,lang[j]);
761
    addrf=fopen(buf,"w");
767
      addrf=fopen(buf,"w");
762
    snprintf(buf,sizeof(buf),"%s/index/information.%s",sheetdir,lang[j]);
768
      snprintf(buf,sizeof(buf),"%s/information.%s",sheetoutdir,lang[j]);
763
    remf=fopen(buf,"w");
769
      remf=fopen(buf,"w");
764
    snprintf(buf,sizeof(buf),"%s/index/serial.%s",sheetdir,lang[j]);
770
      snprintf(buf,sizeof(buf),"%s/serial.%s",sheetoutdir,lang[j]);
765
    serialf=fopen(buf,"w");
771
      serialf=fopen(buf,"w");
766
    snprintf(buf,sizeof(buf),"%s/index/tit.%s",sheetdir,lang[j]);
772
      snprintf(buf,sizeof(buf),"%s/tit.%s",sheetoutdir,lang[j]);
767
    titlef=fopen(buf,"w");
773
      titlef=fopen(buf,"w");
-
 
774
      if(!titlef || !serialf || !remf || !addrf || !weightf || !listf
-
 
775
        || !indf || !descf || !titf ) {
-
 
776
      fprintf(stderr,"modind: error creating output files for sheet %s.\n",sheetoutdir); exit(1);
-
 
777
    }
768
    snprintf(mdic,sizeof(mdic),"%s/%s.%s",dicdir,maindic,lang[j]);
778
    snprintf(mdic,sizeof(mdic),"%s/%s.%s",dicdir,maindic,lang[j]);
769
    snprintf(sdic,sizeof(sdic),"%s/%s.%s",dicdir,suffixdic,lang[j]);
779
    snprintf(sdic,sizeof(sdic),"%s/%s.%s",dicdir,suffixdic,lang[j]);
770
    snprintf(gdic,sizeof(gdic),"%s/%s.%s",dicdir,groupdic,lang[j]);
780
    snprintf(gdic,sizeof(gdic),"%s/%s.%s",dicdir,groupdic,lang[j]);
771
    snprintf(ddic,sizeof(ddic),"%s/%s.%s",dicdir,domaindic,lang[j]);
781
    snprintf(ddic,sizeof(ddic),"%s/%s.%s",dicdir,domaindic,lang[j]);
772
    suffix_dic(sdic); prepare_dic(gdic);
782
    suffix_dic(sdic); prepare_dic(gdic);