Subversion Repositories wimsdev

Rev

Rev 5821 | 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.  /* Document processing primitives. */
  19.  
  20. char primbuf[MAX_LINELEN+1];
  21. char *primitive[256];
  22. int  primcnt;
  23.  
  24. char *prim_if(char *p)
  25. {
  26.     char *p1, *p2, *p3, *p4, *p5, *p6;
  27.     char buf[MAX_LINELEN+1];
  28.     p1=find_word_start(p); if(*p1!='{') return p;
  29.     p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
  30.     p3=find_word_start(p2+1); if(*p3!='{') return p;
  31.     p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
  32.     *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); subst(buf);
  33. /*    for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
  34.         if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
  35.     }
  36. */    prepcnt=0; parmprep(buf,pt_text);
  37.     fprintf(outf," \n!if %s \n",buf);
  38.     p5=find_word_start(p4+1);
  39.     if(*p5=='{' && (p6=find_matching(p5+1,'}'))!=NULL) {
  40.         *p4=elsechar; *p5=' '; *p6=endifchar;
  41.     }
  42.     else *p4=endifchar;
  43.     return p3+1;
  44. }
  45.  
  46. char *prim_while(char *p)
  47. {
  48.     char *p1, *p2, *p3, *p4;
  49.     char buf[MAX_LINELEN+1];
  50.     p1=find_word_start(p); if(*p1!='{') return p;
  51.     p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
  52.     p3=find_word_start(p2+1); if(*p3!='{') return p;
  53.     p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
  54.     *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); subst(buf);
  55. /*    for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
  56.         if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
  57.     }
  58. */    prepcnt=0; parmprep(buf,pt_text);
  59.     fprintf(outf," \n!while %s \n",buf);
  60.     *p4=whilechar;
  61.     return p3+1;
  62. }
  63.  
  64. char *prim_for(char *p)
  65. {
  66.     char *p1, *p2, *p3, *p4;
  67.     char buf[MAX_LINELEN+1];
  68.     p1=find_word_start(p); if(*p1!='{') return p;
  69.     p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
  70.     p3=find_word_start(p2+1); if(*p3!='{') return p;
  71.     p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
  72.     *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); subst(buf);
  73. /*    for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
  74.         if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
  75.     }
  76. */    fprintf(outf," \n!for m_%s \n",find_word_start(buf));
  77.     *p4=nextchar;
  78.     return p3+1;    
  79. }
  80.  
  81.         /* check whether the name is a document primitive. */
  82. char *doccheck(char *p)
  83. {
  84.     char *pe, *pl, *pv, *pp, namebuf[128], parbuf[8192];
  85.     int i, k, t;
  86.    
  87.     for(pe=p, i=0; isalnum(*pe) && i<sizeof(namebuf)-1; pe++, i++)
  88.       namebuf[i]=*pe;
  89.     namebuf[i]=0; pe=find_word_start(pe);
  90.     k=search_list(primitive,primcnt,sizeof(primitive[0]),namebuf);
  91.     if(k<0) return p;
  92.     if(strcmp(namebuf,"def")==0 || strcmp(namebuf,"define")==0) {
  93.         char parmbuf[MAX_LINELEN+1];
  94.         pl=find_word_start(pe);
  95.         if(*pl=='{') pl=find_word_start(++pl); else return pe;
  96.         pv=find_matching(pl,'}'); if(pv==NULL) return pe;
  97.         if(pv-pl>=sizeof(parmbuf)-1) return pe;
  98.         memmove(parmbuf,pl,pv-pl); parmbuf[pv-pl]=0;
  99.         def(parmbuf);
  100.         pe=pv+1; return pe;
  101.     }
  102.     if(strcmp(namebuf,"if")==0) return prim_if(pe);
  103.     if(strcmp(namebuf,"for")==0) return prim_for(pe);
  104.     if(strcmp(namebuf,"while")==0) return prim_while(pe);
  105.     fprintf(outf,"\n!read primitives.phtml %d, %s",primserial++,namebuf);
  106.     for(t=0;t<16;t++) {
  107.         pl=find_word_start(pe);
  108.         if(*pl=='{') pl=find_word_start(++pl); else break;
  109.         pv=find_matching(pl,'}'); if(pv==NULL) break;
  110.         if(pv-pl>=sizeof(parbuf)-1) break;
  111.         memmove(parbuf,pl,pv-pl); parbuf[pv-pl]=0;
  112.         for(pp=parbuf; *pp; pp++) {
  113.             if(*pp=='   ' || *pp=='$') *pp=' ';
  114.             if(*pp=='\n') *pp=' ';
  115.         }
  116.         fprintf(outf,", %s",parbuf);
  117.         pe=pv+1;
  118.     }
  119.     fprintf(outf," \n");
  120.     return pe;
  121. }
  122.  
  123.