Subversion Repositories wimsdev

Rev

Rev 8123 | Rev 8650 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.  
  18. /*  This is an internal program,
  19.  * used to index modules for search engine.
  20.  */
  21.  
  22. #include "../wims.h"
  23. #include "../Lib/libwims.h"
  24. #include "translator_.h"
  25. #include "suffix.h"
  26.  
  27. #define MAX_LANGS    MAX_LANGUAGES
  28. #define MAX_MODULES    65536
  29. char *moduledir=    "public_html/modules";
  30. char *sheetdir=     "public_html/bases/sheet";
  31. char *dicdir=       "public_html/bases";
  32. char *outdir=       "public_html/bases/site2";
  33. char *maindic=      "sys/words";
  34. char *groupdic=     "sys/wgrp/wgrp";
  35. char *suffixdic=    "sys/suffix";
  36. char *domaindic=    "sys/domaindic";
  37. char *ignoredic=    "sys/indignore";
  38. char *conffile=     "log/wims.conf";
  39. char *mlistbase=    "list";
  40.  
  41. char lang[MAX_LANGS][4]={
  42.     "en","fr","cn","es","it","nl","si","ca","pt"
  43. };
  44. #define DEFAULT_LANGCNT    6
  45. char allang[MAX_LANGS][4]={
  46.     "en","fr","cn","es","it","nl","de","si","ca","pt"
  47. };
  48. #define allangcnt 8
  49. char ignore[MAX_LANGS][MAX_LINELEN+1];
  50. char mlistfile[MAX_LANGS][256];
  51. int langcnt;
  52. FILE *langf, *titf, *descf, *weightf, *robotf, *indf, *listf, *addrf, *serialf, *authorf, *versionf, *remf;
  53.  
  54. struct cat {
  55.     char *name;
  56.     char typ;
  57. } cat[]={
  58.     {"all_types", 'A'},
  59.     {"exercise",  'X'},
  60.     {"oef",       'O'},
  61.     {"tool",      'T'},
  62.     {"recreation",'R'},
  63.     {"reference", 'Y'},
  64.     {"document",  'D'},
  65.     {"popup",     'P'},
  66.     {"datamodule",'M'}
  67. };
  68. #define catno (sizeof(cat)/sizeof(cat[0]))
  69.  
  70. struct mod {
  71.     char *name;
  72.     unsigned char langs[MAX_LANGS];
  73.     int counts[MAX_LANGS];
  74.     int  langcnt;
  75. } mod[MAX_MODULES];
  76. int modcnt;
  77.  
  78. char *mlist;
  79.  
  80. /*  fold known accented letters to unaccented, other strange characters to space
  81.  *  apostrophe is among the exceptions to be kept (important for multi-word expressions)
  82.  */
  83. void deaccent2(char *p)
  84. {
  85.     char *sp;
  86.     char *v;
  87.     for(sp=p;*sp;sp++) {
  88.     if(*sp<0 && (v=strchr(acctab,*sp))!=NULL)
  89.       *sp=*(deatab+(v-acctab));
  90.     if(!isalnum(*sp) && strchr(",.&$+*",*sp)==0) *sp=' ';
  91.     else *sp=tolower(*sp);
  92.     }
  93. }
  94.  
  95. /*  translate everything non-alphanumeric into space */
  96. void towords(char *p)
  97. {
  98.     char *pp;
  99.     for(pp=p;*pp;pp++) if(!isalnum(*pp) && strchr("&$+*",*pp)==0) *pp=' ';
  100. }
  101.  
  102. /*  Find first occurrence of word */
  103. char *wordchr2(char *p, char *w)
  104. {
  105.     char *r;
  106.  
  107.     for(r=strstr(p,w);r!=NULL &&
  108.     ( (r>p && !isspace(*(r-1))) || (!isspace(*(r+strlen(w))) && *(r+strlen(w))!=0) );
  109.     r=strstr(r+1,w));
  110.     return r;
  111. }
  112.  
  113. /*  strip trailing spaces; return string end. */
  114. char *strip_trailing_spaces2(char *p)
  115. {
  116.     char *pp;
  117.     if(*p==0) return p;
  118.     for(pp=p+strlen(p)-1; pp>=p && isspace(*pp); *(pp--)=0);
  119.     return pp;
  120. }
  121.  
  122. char *find_tag_end(char *p)
  123. {
  124.     char *pp;
  125.     pp=p; if(*pp=='<') pp++;
  126.     for(; *pp && *pp!='>'; pp++) {
  127.     if(*pp=='<') {
  128.         pp=find_tag_end(pp)-1; continue;
  129.     }
  130.     if(*pp=='"') {
  131.         pp=strchr(pp+1,'"');
  132.         if(pp==NULL) return p+strlen(p); else continue;
  133.     }
  134.     if(*pp=='\'') {
  135.         pp=strchr(pp+1,'\'');
  136.         if(pp==NULL) return p+strlen(p); else continue;
  137.     }
  138.     }
  139.     if(*pp=='>') pp++; return pp;
  140. }
  141.  
  142. char *find_tag(char *p, char *tag)
  143. {
  144.     char *pp;
  145.     int len;
  146.     len=strlen(tag);
  147.     for(pp=strchr(p,'<'); pp!=NULL && *pp; pp=strchr(pp+1,'<')) {
  148.     if(strncasecmp(pp+1,tag,len)==0 && !isalnum(*(pp+1+len))) return pp;
  149.     }
  150.     return p+strlen(p);
  151. }
  152.  
  153. /*  remove all html tags */
  154. void detag(char *p)
  155. {
  156.     char *pp, *p2;
  157.     for(pp=strchr(p,'<'); pp!=NULL; pp=strchr(pp,'<')) {
  158.     p2=find_tag_end(pp);
  159.     if(*p2==0) {*pp=0; return; }
  160.     ovlstrcpy(pp,p2);
  161.     }
  162. }
  163.  
  164. /*  modify a string. Bufferlen must be at least MAX_LINELEN */
  165. void string_modify3(char *start, char *bad_beg, char *bad_end, char *good,...)
  166. {
  167.     char buf[MAX_LINELEN+1];
  168.     va_list vp;
  169.  
  170.     va_start(vp,good);
  171.     vsnprintf(buf,sizeof(buf),good,vp); va_end(vp);
  172.     if(strlen(start)-(bad_end-bad_beg)+strlen(buf)>=MAX_LINELEN)
  173.       return; /* this is an error situation. */
  174.     strcat(buf,bad_end);
  175.     ovlstrcpy(bad_beg,buf);
  176. }
  177.  
  178. /* add a space after comma to see end of words */
  179.  
  180. void comma(char *p)
  181. {
  182.     char *pp;
  183.     for(pp=strchr(p,','); pp; pp=strchr(pp+1,','))
  184.       string_modify3(p,pp,pp+1,", ");
  185. }
  186.  
  187. void _getdef(char buf[], char *name, char value[])
  188. {
  189.     char *p1, *p2, *p3;
  190.  
  191.     value[0]=0;
  192.     for(p1=strstr(buf,name); p1!=NULL; p1=strstr(p1+1,name)) {
  193.     p2=find_word_start(p1+strlen(name));
  194.     if((p1>buf && !isspace(*(p1-1))) || *p2!='=') continue;
  195.     p3=p1; while(p3>buf && isspace(*(p3-1)) && *(p3-1)!='\n') p3--;
  196.     if(p3>buf && *(p3-1)!='\n') continue;
  197.     p3=strchr(p2,'\n');
  198.     p2=find_word_start(p2+1);
  199.     if(p3 <= p2) continue;
  200.     snprintf(value,MAX_LINELEN,"%s",p2);
  201.     if(p3!=NULL && p3-p2<MAX_LINELEN) value[p3-p2]=0;
  202.     strip_trailing_spaces2(value);
  203.     break;
  204.     }
  205. }
  206.  
  207. /*  Get variable definition from a file.
  208.  * Result stored in buffer value of length MAX_LINELEN.
  209.  */
  210. void getdef(char *fname, char *name, char value[])
  211. {
  212.     FILE *f;
  213.     char *buf;
  214.     int l;
  215.  
  216.     value[0]=0;
  217.     f=fopen(fname,"r"); if(f==NULL) return;
  218.     fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
  219.     buf=xmalloc(l+256); l=fread(buf,1,l,f);
  220.     fclose(f);
  221.     if(l<=0) return; else buf[l]=0;
  222.     _getdef(buf,name,value);
  223.     free(buf);
  224. }
  225.  
  226. char *mdicbuf, *gdicbuf, *ddicbuf, *gentry, *mentry, *dentry;
  227.  
  228. int gentrycount, mentrycount, dentrycount;
  229.  
  230. /*  Preparation of data */
  231. void prep(void)
  232. {
  233.     char buf[MAX_LINELEN+1];
  234.     char *p1,*p2,*s,*old;
  235.     int i,l,thislang,t;
  236.     FILE *f;
  237.  
  238.     s=getenv("modind_outdir"); if(s!=NULL && *s!=0) outdir=s;
  239.     s=getenv("modind_sheetdir"); if(s!=NULL && *s!=0) sheetdir=s;
  240.     snprintf(buf,sizeof(buf),"%s/addr",outdir);
  241.     addrf=fopen(buf,"w");
  242.     snprintf(buf,sizeof(buf),"%s/serial",outdir);
  243.     serialf=fopen(buf,"w");
  244.     modcnt=langcnt=0;
  245. /* take the langs declared in conffile */
  246.     getdef(conffile,"site_languages",buf);
  247.     for(p1=buf;*p1;p1++) if(!isalnum(*p1)) *p1=' ';
  248.     for(p1=find_word_start(buf); *p1 && langcnt<MAX_LANGS; p1=find_word_start(p2)) {
  249.     p2=find_word_end(p1);
  250.     if(p2!=p1+2 || !isalpha(*p1) || !isalpha(*(p1+1))) continue;
  251.     memmove(lang[langcnt],p1,2); lang[langcnt++][2]=0;
  252.     }
  253.     if(langcnt==0) {/*  default languages */
  254.     langcnt=DEFAULT_LANGCNT;
  255.     }
  256.     s=getenv("mlist"); if(s==NULL) exit(1);
  257.     l=strlen(s); if(l<0 || l>100*MAX_LINELEN) exit(1);
  258.     mlist=xmalloc(l+16); ovlstrcpy(mlist,s); old="";
  259.     for(i=0;i<langcnt;i++) {
  260.     snprintf(buf,sizeof(buf),"%s/%s.%s",dicdir,ignoredic,lang[i]);
  261.     f=fopen(buf,"r"); if(f==NULL) continue;
  262.     l=fread(ignore[i],1,MAX_LINELEN,f);fclose(f);
  263.     if(l<0 || l>=MAX_LINELEN) l=0;
  264.     ignore[i][l]=0;
  265.     }
  266.     for(t=0, p1=find_word_start(mlist);
  267.     *p1 && modcnt<MAX_MODULES;
  268.     p1=find_word_start(p2), t++) {
  269.     p2=find_word_end(p1);
  270.     l=p2-p1; if(*p2) *p2++=0;
  271.     fprintf(addrf,"%d:%s\n",t,p1);
  272.     fprintf(serialf,"%s:%d\n",p1,t);
  273.     thislang=-1;
  274. /* language is taken from the address */
  275.     if(l>3 && p1[l-3]=='.') {
  276.         for(i=0;i<langcnt;i++) if(strcasecmp(lang[i],p1+l-2)==0) break;
  277.         if(i<langcnt) {p1[l-3]=0; thislang=i;}
  278.         else {/*  unknown language, not referenced */
  279.         continue;
  280.         }
  281.     }
  282.     if(modcnt>0 && strcmp(old,p1)==0 && thislang>=0) {
  283.         if(mod[modcnt-1].langcnt<langcnt) {
  284.         mod[modcnt-1].langs[mod[modcnt-1].langcnt]=thislang;
  285.         mod[modcnt-1].counts[mod[modcnt-1].langcnt]=t;
  286.         (mod[modcnt-1].langcnt)++;
  287.         }
  288.     }
  289.     else {
  290.         mod[modcnt].name=old=p1;
  291.         if(thislang>=0) {
  292.         mod[modcnt].langs[0]=thislang;
  293.         mod[modcnt].langcnt=1;
  294.         }
  295.         else mod[modcnt].langcnt=0;
  296.         mod[modcnt].counts[0]=t;
  297.         modcnt++;
  298.     }
  299.     }
  300.     snprintf(buf,sizeof(buf),"%s/language",outdir);
  301.     langf=fopen(buf,"w");
  302.     snprintf(buf,sizeof(buf),"%s/title",outdir);
  303.     titf=fopen(buf,"w");
  304.     snprintf(buf,sizeof(buf),"%s/description",outdir);
  305.     descf=fopen(buf,"w");
  306.     snprintf(buf,sizeof(buf),"%s/author",outdir);
  307.     authorf=fopen(buf,"w");
  308.     snprintf(buf,sizeof(buf),"%s/version",outdir);
  309.     versionf=fopen(buf,"w");
  310.     snprintf(buf,sizeof(buf),"%s/lists/robot.phtml",outdir);
  311.     robotf=fopen(buf,"w");
  312.     fclose(addrf); fclose(serialf);
  313.     if(!robotf || !versionf || !authorf || !descf || !titf || !descf) {
  314.     fprintf(stderr,"modind: error creating output files.\n");
  315.     exit(1);
  316.     }
  317. }
  318.  
  319. void sprep(void)
  320. {
  321.     char *p1,*p2,*s;
  322.     int i,l,thislang;
  323.  
  324.     modcnt=0;
  325.     s=getenv("slist"); if(s==NULL) return;
  326.     l=strlen(s); if(l<0 || l>100*MAX_LINELEN) return;
  327.     mlist=xmalloc(l+16); ovlstrcpy(mlist,s);
  328.     for(p1=find_word_start(mlist); *p1 && modcnt<MAX_MODULES; p1=find_word_start(p2)) {
  329.     p2=find_word_end(p1);
  330.     l=p2-p1; if(*p2) *p2++=0;
  331.     for(i=0;i<langcnt;i++) if(strncasecmp(lang[i],p1,2)==0) break;
  332.     if(i<langcnt) thislang=i; else continue;
  333.     mod[modcnt].name=p1;
  334.     mod[modcnt].langs[0]=thislang;
  335.     mod[modcnt].langcnt=1;
  336.     modcnt++;
  337.     }
  338. }
  339.  
  340. void clean(void)
  341. {
  342.     fclose(langf); fclose(titf); fclose(descf); fclose(robotf);
  343.     fclose(authorf); fclose(versionf);
  344. }
  345.  
  346. char *sheetindex[]={
  347.       "title", "description",
  348.       "duration", "severity",
  349.       "level", "domain",
  350.       "keywords", "reserved1", "reserved2", "information"
  351. };
  352. #define SHEETINDEX_NO (sizeof(sheetindex)/sizeof(sheetindex[0]))
  353. char sindbuf[SHEETINDEX_NO][MAX_LINELEN+1];
  354. enum{s_title, s_description,
  355.       s_duration, s_severity,
  356.       s_level, s_domain,
  357.       s_keywords, s_reserved1, s_reserved2,
  358.       s_information
  359. };
  360.  
  361. char *modindex[]={
  362.       "title", "description",
  363.       "author", "address", "copyright",
  364.       "version", "wims_version", "language",
  365.       "category", "level", "domain", "keywords",
  366.       "keywords_ca", "keywords_en", "keywords_fr", "keywords_it", "keywords_nl",
  367.       "title_ca", "title_en", "title_fr", "title_it", "title_nl",
  368.       "require"
  369. };
  370. #define MODINDEX_NO (sizeof(modindex)/sizeof(modindex[0]))
  371. char indbuf[MODINDEX_NO][MAX_LINELEN+1];
  372. enum{i_title, i_description,
  373.       i_author,i_address,i_copyright,
  374.       i_version,i_wims_version,i_language,
  375.       i_category,i_level,i_domain,i_keywords,
  376.       i_keywords_ca,i_keywords_en,i_keywords_fr,i_keywords_it,i_keywords_nl,
  377.       i_title_ca,i_title_en,i_title_fr,i_title_it,i_title_nl,
  378.       i_require
  379. };
  380.  
  381. char *module_special_file[]={
  382.     "intro","help","about"
  383. };
  384. #define MODSPEC_NO (sizeof(module_special_file)/sizeof(module_special_file[0]))
  385. char module_language[4];
  386.  
  387. /*  read and treat module's INDEX file */
  388. int module_index(const char *name)
  389. {
  390.     char *p, fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1];
  391.     FILE *indf;
  392.     int i,l;
  393.  
  394.     snprintf(fbuf,sizeof(fbuf),"%s/%s/INDEX",moduledir,name);
  395.     indf=fopen(fbuf,"r"); if(indf==NULL) return -1;
  396.     l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf);
  397.     if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1;
  398. /* treate all fields in *modindex */
  399.     for(i=0;i<MODINDEX_NO;i++) {
  400.     _getdef(ibuf,modindex[i],indbuf[i]);
  401. /*  compatibility precaution */
  402.     if(indbuf[i][0]==':') indbuf[i][0]='.';
  403.     }
  404.     p=find_word_start(indbuf[i_language]);
  405.     if(isalpha(*p) && isalpha(*(p+1))) {
  406.     memmove(module_language,p,2); module_language[2]=0;
  407.     }
  408.     else ovlstrcpy(module_language,"en");
  409.     return 0;
  410. }
  411.  
  412. int sheet_index(int serial)
  413. {
  414.     char *p1, *p2, fbuf[MAX_LINELEN+1], ibuf[MAX_LINELEN+1];
  415.     FILE *indf;
  416.     int i,l;
  417.  
  418.     snprintf(fbuf,sizeof(fbuf),"%s/%s.def",sheetdir,mod[serial].name);
  419.     indf=fopen(fbuf,"r"); if(indf==NULL) return -1;
  420.     l=fread(ibuf,1,MAX_LINELEN,indf); fclose(indf);
  421.     if(l>0 && l<MAX_LINELEN) ibuf[l]=0; else return -1;
  422.     for(i=0;i<SHEETINDEX_NO;i++) sindbuf[i][0]=0;
  423.     for(i=0,p1=find_word_start(ibuf);
  424.     i<SHEETINDEX_NO-1 && *p1!=':' && *p1!=0;
  425.     i++,p1=p2) {
  426.     p2=strchr(p1,'\n');
  427.     if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
  428.     p1=find_word_start(p1); strip_trailing_spaces2(p1);
  429.     snprintf(sindbuf[i],MAX_LINELEN,"%s",p1);
  430.     }
  431.     p2=strstr(p1,"\n:"); if(p2==NULL) p2=p1+strlen(p1);
  432.     else *p2=0;
  433.     p1=find_word_start(p1); strip_trailing_spaces2(p1);
  434.     for(p2=p1;*p2;p2++) if(*p2=='\n') *p2=' ';
  435.     ovlstrcpy(sindbuf[s_information],p1);
  436.     return 0;
  437. }
  438.  
  439. unsigned char categories[16];
  440. char taken[MAX_LINELEN+1];
  441. int catcnt, takenlen, tweight;
  442.  
  443. void appenditem(char *word, int lind, int serial, int weight, char *l)
  444. {
  445.     char nbuf[MAX_LINELEN+1], buf[MAX_LINELEN+1];
  446.     int i, ll;
  447.     char *p;
  448.     FILE *f;
  449.  
  450.     if(!isalnum(*word) || (ll=strlen(word))<2 ||
  451.        wordchr2(taken,word)!=NULL ||
  452.        wordchr2(ignore[lind],word)!=NULL ||
  453.        takenlen>=MAX_LINELEN-ll-16)
  454.       return;
  455.     if(ll==2 && (!isdigit(word[0]) || !isalpha(word[1]))) return;
  456.     for(p=word;*p;p++) if(!isalnum(*p) && *p!=' ') return;
  457.     taken[takenlen++]=' '; taken[takenlen++]=' ';
  458.     ovlstrcpy(taken+takenlen,word);
  459.     takenlen+=ll; tweight+=weight;
  460.     snprintf(buf,sizeof(buf),"%s:%d?%d\n",word,serial,weight);
  461.     for(i=0;i<catcnt;i++) {
  462.     snprintf(nbuf,sizeof(nbuf),"%s/%c.%s",
  463.          outdir,categories[i],lang[lind]);
  464.     f=fopen(nbuf,"a");
  465.     if(f!=NULL) {fputs(buf,f); fclose(f);}
  466.     }
  467. }
  468.  
  469. void appenditem1 (char *buf, int lind, int serial, int weight, char *l )
  470. {
  471.   char *p1, *p2 ;
  472.   for(p1=find_word_start(buf); *p1;
  473.     p1=find_word_start(p2)) {
  474.     p2=strchr(p1,',');
  475.     if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
  476.     if(strlen(p1)<=0) continue;
  477.     appenditem(p1,lind,serial,weight,module_language);
  478.   }
  479. }
  480. void appenditem2 (char *buf, int lind, int serial, int weight, char *l )
  481. {
  482.   char *p1, *p2 ;
  483.   for(p1=find_word_start(buf);*p1;
  484.     p1=find_word_start(p2)) {
  485.     p2=find_word_end(p1); if(*p2) *p2++=0;
  486.     appenditem(p1,lind,serial,weight,module_language);
  487.   }
  488. }
  489. void onemodule(const char *name, int serial, int lind)
  490. {
  491.     int i;
  492.     unsigned char trlist[]={
  493.     i_title,i_description,i_category,i_domain,i_keywords,
  494.       i_require,i_author,
  495.       i_keywords_ca,i_keywords_en,i_keywords_fr,i_keywords_it,i_keywords_nl,
  496.       i_title_ca,i_title_en,i_title_fr,i_title_it,i_title_nl
  497.     };
  498.     #define trcnt (sizeof(trlist)/sizeof(trlist[0]))
  499.     char *p1, *p2, *pp, *q, buf[MAX_LINELEN+1], lbuf[16];
  500.     FILE *f;
  501.  
  502.     if(module_index(name)) return;
  503.     towords(indbuf[i_category]);
  504. /*   list the categories (among A=all,X=eXercise,O,D,...) corresponding
  505.  *   to this module
  506.  */
  507.     for(i=catcnt=0;i<catno && catcnt<16;i++) {
  508.     if(wordchr2(indbuf[i_category],cat[i].name)!=NULL)
  509.       categories[catcnt++]=cat[i].typ;
  510.     }
  511.     if(catcnt==0) return;
  512.     if(categories[0]!=cat[0].typ)
  513.       categories[catcnt++]=cat[0].typ;
  514. /*  write module's name in the category.language files, for instance lists/X.fr
  515.  * for french exercises
  516.  */
  517.     for(i=0;i<catcnt;i++) {
  518.     snprintf(buf,sizeof(buf),"%s/lists/%c.%s",
  519.          outdir,categories[i],lang[lind]);
  520.     f=fopen(buf,"a");
  521.     if(f!=NULL) {fprintf(f,"%s\n",name); fclose(f);}
  522.     }
  523. /*   add serial number and language (resp.title, ...) to corresponding file  */
  524.     fprintf(langf,"%d:%s\n",serial,module_language);
  525.     fprintf(titf,"%d:%s\n",serial,indbuf[i_title]);
  526.     fprintf(descf,"%d:%s\n",serial,indbuf[i_description]);
  527.     fprintf(authorf,"%d:%s\n",serial,indbuf[i_author]);
  528.     fprintf(versionf,"%d:%s\n",serial,indbuf[i_version]);
  529.  
  530. /*   add module's information in html page for robots  */
  531.     snprintf(buf,sizeof(buf),"%s",indbuf[i_description]);
  532.     for(pp=strchr(buf,','); pp; pp=strchr(pp,','))
  533.       string_modify3(buf,pp,pp+1,"&#44;");
  534.     if(strcmp(module_language,lang[lind])==0)
  535.       fprintf(robotf,"%s ,%s,%s,%s,%s\n",name,module_language,name,
  536.           indbuf[i_title], buf);
  537.  
  538. /*   Normalize the information of trlist, using dictionary
  539.  *  -- bases/sys/domain.xx without suffix translation (--> english version)
  540.  */
  541.     entrycount=dentrycount; dicbuf=ddicbuf;
  542.     memmove(entry,dentry,dentrycount*sizeof(entry[0]));
  543.     unknown_type=unk_leave;
  544.     for(i=0;i<trcnt;i++) {
  545.     detag(indbuf[trlist[i]]);
  546.     deaccent2(indbuf[trlist[i]]);
  547.     comma(indbuf[trlist[i]]);
  548.     singlespace2(indbuf[trlist[i]]);
  549.     translate(indbuf[trlist[i]]);
  550.     }
  551. /*   Normalize the information, using dictionary
  552.  *   bases/sys/words.xx with suffix translation
  553.  */
  554.     entrycount=mentrycount; dicbuf=mdicbuf;
  555.     memmove(entry,mentry,mentrycount*sizeof(entry[0]));
  556.     unknown_type=unk_leave;/*  used in translator_.c */
  557.     for(i=0;i<trcnt;i++) {
  558.     suffix_translate(indbuf[trlist[i]]);
  559.     translate(indbuf[trlist[i]]);
  560.     }
  561.  
  562. /* taken contains all words already seen in the module index */
  563.     taken[0]=0; takenlen=tweight=0;
  564. /*  append words of title  */
  565.     ovlstrcpy(buf,indbuf[i_title]); towords(buf);
  566.     appenditem2(buf,lind,serial,4,module_language);
  567.  
  568. /*  extract words of every other information except level */
  569.     snprintf(buf,sizeof(buf),"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
  570.          indbuf[i_description],indbuf[i_keywords],
  571.          indbuf[i_keywords_ca],indbuf[i_keywords_en],indbuf[i_keywords_fr],
  572.          indbuf[i_keywords_it],indbuf[i_keywords_nl],
  573.          indbuf[i_title_ca],indbuf[i_title_en],indbuf[i_title_fr],
  574.          indbuf[i_title_it],indbuf[i_title_nl],
  575.          indbuf[i_domain],indbuf[i_require],indbuf[i_author]);
  576.     towords(buf);
  577.     appenditem2(buf,lind,serial,2,module_language);
  578.  
  579. /*   this time the dictionary is the group dictionary  sys/wgrp/wgrp
  580.  *   with a g (groupdic), not an m (maindic) . see below main, suffix, group.
  581.  *   and delete unknown ?? and translate
  582.  */
  583.     entrycount=gentrycount; dicbuf=gdicbuf;
  584.     memmove(entry,gentry,gentrycount*sizeof(entry[0]));
  585.  
  586. /*  append words of every title information  */
  587.     ovlstrcpy(buf,indbuf[i_title]);
  588.     unknown_type=unk_delete;
  589.     translate(buf);
  590.     appenditem1(buf,lind,serial,2,module_language);
  591.  
  592. /*  append words of information of description except level  */
  593.     snprintf(buf,sizeof(buf),"%s", indbuf[i_description]);
  594.     unknown_type=unk_delete;
  595.     translate(buf);
  596.     appenditem1(buf,lind,serial,4,module_language);
  597.  
  598. /*  append words (or group of words) of keywords and domain  */
  599.     snprintf(buf,sizeof(buf),"%s, %s, %s, %s, %s, %s, %s",
  600.          indbuf[i_domain],indbuf[i_keywords],
  601.          indbuf[i_keywords_ca], indbuf[i_keywords_en],indbuf[i_keywords_fr],
  602.          indbuf[i_keywords_it], indbuf[i_keywords_nl]);
  603.     unknown_type=unk_leave;
  604.     translate(buf);
  605.     appenditem1(buf,lind,serial,2,module_language);
  606.  
  607. /*   append level information, with weight 2 */
  608.     snprintf(buf,sizeof(buf),"%s",indbuf[i_level]);
  609.     ovlstrcpy(lbuf,"level");
  610.     for(p1=buf; *p1; p1++) if(!isalnum(*p1)) *p1=' ';
  611.     q=buf+strlen(buf);
  612.     for(p1=find_word_start(buf); (*p1) && (p1 < q) ;
  613.     p1=find_word_start(p2)) {
  614.     p2=find_word_end(p1);
  615.     if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
  616.     if(!isalpha(*p1) ||
  617.        (!isdigit(*(p1+1)) && *(p1+1)!=0) ||
  618.        (*(p1+1)!=0 && *(p1+2)!=0))
  619.       continue;
  620.     *p1=tolower(*p1);
  621.     ovlstrcpy(lbuf+strlen("level"),p1);
  622.     appenditem(lbuf,lind,serial,2,module_language);
  623.     }
  624. /*   append total weight of module to weight file site2/weight.xx  */
  625.     fprintf(weightf,"%d:%d\n",serial,tweight);
  626. }
  627.  
  628. void modules(void)
  629. {
  630.     int i,j,k,d;
  631.     char namebuf[MAX_LINELEN+1];
  632.     char mdic[MAX_LINELEN+1], sdic[MAX_LINELEN+1], gdic[MAX_LINELEN+1], ddic[MAX_LINELEN+1];
  633.  
  634.     for(j=0;j<langcnt;j++) {
  635.     snprintf(namebuf,sizeof(namebuf),"%s/weight.%s",outdir,lang[j]);
  636.     weightf=fopen(namebuf,"w");
  637.     snprintf(mdic,sizeof(mdic),"%s/%s.%s",dicdir,maindic,lang[j]);
  638.     snprintf(sdic,sizeof(sdic),"%s/%s.%s",dicdir,suffixdic,lang[j]);
  639.     snprintf(gdic,sizeof(gdic),"%s/%s.%s",dicdir,groupdic,lang[j]);
  640.     snprintf(ddic,sizeof(ddic),"%s/%s.%s",dicdir,domaindic,lang[j]);
  641.     suffix_dic(sdic); prepare_dic(gdic);
  642.     gdicbuf=dicbuf; gentrycount=entrycount;
  643.     memmove(gentry,entry,gentrycount*sizeof(entry[0]));
  644.     prepare_dic(mdic);
  645.     mdicbuf=dicbuf; mentrycount=entrycount;
  646.     memmove(mentry,entry,mentrycount*sizeof(entry[0]));
  647.     prepare_dic(ddic);
  648.     ddicbuf=dicbuf; dentrycount=entrycount;
  649.     memmove(dentry,entry,dentrycount*sizeof(entry[0]));
  650.     unknown_type=unk_leave; translate(ignore[j]);
  651.     for(i=0;i<modcnt;i++) {
  652.         if(mod[i].langcnt>0) {
  653.         for(d=k=0;k<mod[i].langcnt;k++)
  654.           if(mod[i].langs[k]<mod[i].langs[d]) d=k;
  655.         for(k=0;k<mod[i].langcnt && mod[i].langs[k]!=j;k++);
  656.         if(k>=mod[i].langcnt) k=d;
  657.         snprintf(namebuf,MAX_LINELEN,"%s.%s",mod[i].name,
  658.              lang[mod[i].langs[k]]);
  659.         onemodule(namebuf,mod[i].counts[k],j);
  660.         }
  661.         else {
  662.         onemodule(mod[i].name,mod[i].counts[0],j);
  663.         }
  664.     }
  665.     if(mentrycount>0) free(mdicbuf);
  666.     if(gentrycount>0) free(gdicbuf);
  667.     if(suffixcnt>0) free(sufbuf);
  668.     if(dentrycount>0) free(ddicbuf);
  669.     if(weightf) fclose(weightf);
  670.     }
  671. }
  672.  
  673. /* FIXME ? differences with appenditem - use fprintf instead of  snprintf */
  674. void sappenditem(char *word, int lind, int serial, int weight)
  675. {
  676.     int ll;
  677.     char *p;
  678.  
  679.     if(!isalnum(*word) || (ll=strlen(word))<2 ||
  680.        wordchr2(taken,word)!=NULL ||
  681.        wordchr2(ignore[lind],word)!=NULL ||
  682.        takenlen>=MAX_LINELEN-ll-16)
  683.       return;
  684.     if(ll==2 && (!isdigit(word[0]) || !isalpha(word[1]))) return;
  685.     for(p=word;*p;p++) if(!isalnum(*p) && *p!=' ') return;
  686.     taken[takenlen++]=' ';taken[takenlen++]=' ';
  687.     ovlstrcpy(taken+takenlen,word);
  688.     takenlen+=ll; tweight+=weight;
  689.     fprintf(indf,"%s:%d?%d\n",word,serial,weight);
  690. }
  691.  
  692. void onesheet(int serial, int lind)
  693. {
  694.     int i;
  695.     unsigned char trlist[]={
  696.     s_title,s_description,s_domain,s_keywords,s_information
  697.     };
  698.     #define trcnt (sizeof(trlist)/sizeof(trlist[0]))
  699.     char *p1, *p2, buf[MAX_LINELEN+1];
  700.  
  701.     if(sheet_index(serial)) return;
  702.     fprintf(listf,"%s\n",mod[serial].name+3);
  703.     fprintf(titf,"%d:%s\n",serial,sindbuf[s_title]);
  704.     fprintf(descf,"%d:%s\n",serial,sindbuf[s_description]);
  705.     fprintf(remf,"%d:%s\n",serial,sindbuf[s_information]);
  706.  
  707.     entrycount=dentrycount; dicbuf=ddicbuf;
  708.     memmove(entry,dentry,dentrycount*sizeof(entry[0]));
  709.     unknown_type=unk_leave;
  710.     for(i=0;i<trcnt;i++) {
  711.     detag(sindbuf[trlist[i]]);
  712.     deaccent2(sindbuf[trlist[i]]);
  713.     comma(sindbuf[trlist[i]]);
  714.     singlespace2(sindbuf[trlist[i]]);
  715.     translate(sindbuf[trlist[i]]);
  716.     }
  717.  
  718.     entrycount=mentrycount; dicbuf=mdicbuf;
  719.     memmove(entry,mentry,mentrycount*sizeof(entry[0]));
  720.     unknown_type=unk_leave;
  721.     for(i=0;i<trcnt;i++) {
  722.     suffix_translate(sindbuf[trlist[i]]);
  723.     translate(sindbuf[trlist[i]]);
  724.     }
  725.     taken[0]=0; takenlen=tweight=0;
  726.     ovlstrcpy(buf,sindbuf[s_title]); towords(buf);
  727.     for(p1=find_word_start(buf);*p1;
  728.     p1=find_word_start(p2)) {
  729.     p2=find_word_end(p1); if(*p2) *p2++=0;
  730.     sappenditem(p1,lind,serial,4);
  731.     }
  732.     snprintf(buf,sizeof(buf),"%s %s %s %s",
  733.          sindbuf[s_description],sindbuf[s_keywords],
  734.          sindbuf[s_domain],sindbuf[s_information]);
  735.     towords(buf);
  736.     for(p1=find_word_start(buf);*p1;
  737.     p1=find_word_start(p2)) {
  738.     p2=find_word_end(p1); if(*p2) *p2++=0;
  739.     sappenditem(p1,lind,serial,2);
  740.     }
  741.     entrycount=gentrycount; dicbuf=gdicbuf;
  742.     memmove(entry,gentry,gentrycount*sizeof(entry[0]));
  743.     unknown_type=unk_delete;
  744.     ovlstrcpy(buf,sindbuf[s_title]); translate(buf);
  745.     for(p1=find_word_start(buf); *p1;
  746.     p1=find_word_start(p2)) {
  747.     p2=strchr(p1,',');
  748.     if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
  749.     if(strlen(p1)<=0) continue;
  750.     sappenditem(p1,lind,serial,4);
  751.     }
  752.     snprintf(buf,sizeof(buf),"%s, %s, %s, %s",
  753.          sindbuf[s_description],sindbuf[s_keywords],
  754.          sindbuf[s_domain],sindbuf[s_information]);
  755.     translate(buf);
  756.     for(p1=find_word_start(buf); *p1;
  757.     p1=find_word_start(p2)) {
  758.     p2=strchr(p1,',');
  759.     if(p2!=NULL) *p2++=0; else p2=p1+strlen(p1);
  760.     if(strlen(p1)<=0) continue;
  761.     sappenditem(p1,lind,serial,2);
  762.     }
  763.     fprintf(weightf,"%d:%d\n",serial,tweight);
  764. }
  765.  
  766. void sheets(void)
  767. {
  768.     int i,j;
  769.     char mdic[MAX_LINELEN+1], sdic[MAX_LINELEN+1], gdic[MAX_LINELEN+1], ddic[MAX_LINELEN+1];
  770.     char buf[MAX_LINELEN+1];
  771.  
  772.     for(j=0;j<langcnt;j++) {
  773.     snprintf(buf,sizeof(buf),"%s/index/title.%s",sheetdir,lang[j]);
  774.     titf=fopen(buf,"w");
  775.     snprintf(buf,sizeof(buf),"%s/index/description.%s",sheetdir,lang[j]);
  776.     descf=fopen(buf,"w");
  777.     snprintf(buf,sizeof(buf),"%s/index/%s",sheetdir,lang[j]);
  778.     indf=fopen(buf,"w");
  779.     snprintf(buf,sizeof(buf),"%s/index/list.%s",sheetdir,lang[j]);
  780.     listf=fopen(buf,"w");
  781.     snprintf(buf,sizeof(buf),"%s/index/weight.%s",sheetdir,lang[j]);
  782.     weightf=fopen(buf,"w");
  783.     snprintf(buf,sizeof(buf),"%s/index/addr.%s",sheetdir,lang[j]);
  784.     addrf=fopen(buf,"w");
  785.     snprintf(buf,sizeof(buf),"%s/index/information.%s",sheetdir,lang[j]);
  786.     remf=fopen(buf,"w");
  787.     snprintf(buf,sizeof(buf),"%s/index/serial.%s",sheetdir,lang[j]);
  788.     serialf=fopen(buf,"w");
  789.     snprintf(mdic,sizeof(mdic),"%s/%s.%s",dicdir,maindic,lang[j]);
  790.     snprintf(sdic,sizeof(sdic),"%s/%s.%s",dicdir,suffixdic,lang[j]);
  791.     snprintf(gdic,sizeof(gdic),"%s/%s.%s",dicdir,groupdic,lang[j]);
  792.     snprintf(ddic,sizeof(ddic),"%s/%s.%s",dicdir,domaindic,lang[j]);
  793.     suffix_dic(sdic); prepare_dic(gdic);
  794.     gdicbuf=dicbuf; gentrycount=entrycount;
  795.     memmove(gentry,entry,gentrycount*sizeof(entry[0]));
  796.     prepare_dic(mdic);
  797.     mdicbuf=dicbuf; mentrycount=entrycount;
  798.     memmove(mentry,entry,mentrycount*sizeof(entry[0]));
  799.     prepare_dic(ddic);
  800.     ddicbuf=dicbuf; dentrycount=entrycount;
  801.     memmove(dentry,entry,dentrycount*sizeof(entry[0]));
  802.     unknown_type=unk_leave; translate(ignore[j]);
  803.     for(i=0;i<modcnt;i++) {
  804.         if(mod[i].langs[0]!=j) continue;
  805.         fprintf(addrf,"%d:%s\n",i,mod[i].name+3);
  806.         fprintf(serialf,"%s:%d\n",mod[i].name+3,i);
  807.         onesheet(i,j);
  808.     }
  809.     if(mentrycount>0) free(mdicbuf);
  810.     if(gentrycount>0) free(gdicbuf);
  811.     if(suffixcnt>0) free(sufbuf);
  812.     if(dentrycount>0) free(ddicbuf);
  813.     fclose(titf); fclose(descf); fclose(indf); fclose(listf);
  814.     fclose(weightf); fclose(addrf); fclose(serialf);
  815.     }
  816. }
  817.  
  818. int main()
  819. {
  820.     gentry=xmalloc(entry_size);
  821.     dentry=xmalloc(entry_size);
  822.     mentry=xmalloc(entry_size);
  823.     prep();
  824.     if(modcnt>0) modules();
  825.     clean();
  826.     sprep();
  827.     if(modcnt>0) sheets();
  828.     return 0;
  829. }
  830.  
  831.