Back to index

wims  3.65+svn20090927
doc.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018  /* Document processing primitives. */
00019 
00020 char primbuf[MAX_LINELEN+1];
00021 char *primitive[256];
00022 int  primcnt;
00023 
00024 char *prim_if(char *p)
00025 {
00026     char *p1, *p2, *p3, *p4, *p5, *p6;
00027     char buf[MAX_LINELEN+1];
00028     p1=find_word_start(p); if(*p1!='{') return p;
00029     p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
00030     p3=find_word_start(p2+1); if(*p3!='{') return p;
00031     p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
00032     *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); subst(buf);
00033 /*    for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
00034        if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
00035     }
00036 */    prepcnt=0; parmprep(buf,pt_text);
00037     fprintf(outf," \n!if %s \n",buf);
00038     p5=find_word_start(p4+1);
00039     if(*p5=='{' && (p6=find_matching(p5+1,'}'))!=NULL) {
00040        *p4=elsechar; *p5=' '; *p6=endifchar;
00041     }
00042     else *p4=endifchar;
00043     return p3+1;
00044 }
00045 
00046 char *prim_while(char *p)
00047 {
00048     char *p1, *p2, *p3, *p4;
00049     char buf[MAX_LINELEN+1];
00050     p1=find_word_start(p); if(*p1!='{') return p;
00051     p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
00052     p3=find_word_start(p2+1); if(*p3!='{') return p;
00053     p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
00054     *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); subst(buf);
00055 /*    for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
00056        if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
00057     }
00058 */    prepcnt=0; parmprep(buf,pt_text);
00059     fprintf(outf," \n!while %s \n",buf);
00060     *p4=whilechar;
00061     return p3+1;
00062 }
00063 
00064 char *prim_for(char *p)
00065 {
00066     char *p1, *p2, *p3, *p4;
00067     char buf[MAX_LINELEN+1];
00068     p1=find_word_start(p); if(*p1!='{') return p;
00069     p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
00070     p3=find_word_start(p2+1); if(*p3!='{') return p;
00071     p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
00072     *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); subst(buf);
00073 /*    for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
00074        if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
00075     }
00076 */    fprintf(outf," \n!for m_%s \n",find_word_start(buf));
00077     *p4=nextchar;
00078     return p3+1;    
00079 }
00080 
00081        /* check whether the name is a document primitive. */
00082 char *doccheck(char *p)
00083 {
00084     char *pe, *pl, *pv, *pp, namebuf[128], parbuf[8192];
00085     int i, k, t;
00086     
00087     for(pe=p, i=0; isalnum(*pe) && i<sizeof(namebuf)-1; pe++, i++) 
00088       namebuf[i]=*pe;
00089     namebuf[i]=0; pe=find_word_start(pe);
00090     k=search_list(primitive,primcnt,sizeof(primitive[0]),namebuf);
00091     if(k<0) return p;
00092     if(strcmp(namebuf,"def")==0 || strcmp(namebuf,"define")==0) {
00093        char parmbuf[MAX_LINELEN+1];
00094        pl=find_word_start(pe);
00095        if(*pl=='{') pl=find_word_start(++pl); else return pe;
00096        pv=find_matching(pl,'}'); if(pv==NULL) return pe;
00097        if(pv-pl>=sizeof(parmbuf)-1) return pe;
00098        memmove(parmbuf,pl,pv-pl); parmbuf[pv-pl]=0;
00099        def(parmbuf);
00100        pe=pv+1; return pe;
00101     }
00102     if(strcmp(namebuf,"if")==0) return prim_if(pe);
00103     if(strcmp(namebuf,"for")==0) return prim_for(pe);
00104     if(strcmp(namebuf,"while")==0) return prim_while(pe);
00105     fprintf(outf,"\n!read primitives.phtml %d, %s",primserial++,namebuf);
00106     for(t=0;t<16;t++) {
00107        pl=find_word_start(pe);
00108        if(*pl=='{') pl=find_word_start(++pl); else break;
00109        pv=find_matching(pl,'}'); if(pv==NULL) break;
00110        if(pv-pl>=sizeof(parbuf)-1) break;
00111        memmove(parbuf,pl,pv-pl); parbuf[pv-pl]=0;
00112        for(pp=parbuf; *pp; pp++) {
00113            if(*pp==' ' || *pp=='$') *pp=' ';
00114            if(*pp=='\n') *pp='     ';
00115        }
00116        fprintf(outf,", %s",parbuf);
00117        pe=pv+1;
00118     }
00119     fprintf(outf," \n");
00120     return pe;
00121 }
00122