Subversion Repositories wimsdev

Rev

Rev 8367 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 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. */
8135 bpr 19
#include "../Lib/libwims.h"
20
#include "msg2wims.h"
10 reyssat 21
 
22
char primbuf[MAX_LINELEN+1];
23
char *primitive[256];
8135 bpr 24
int primcnt, prepcnt;
10 reyssat 25
 
8367 bpr 26
char *_prim_if(char *p, int type)
10 reyssat 27
{
28
    char *p1, *p2, *p3, *p4, *p5, *p6;
29
    char buf[MAX_LINELEN+1];
30
    p1=find_word_start(p); if(*p1!='{') return p;
31
    p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
32
    p3=find_word_start(p2+1); if(*p3!='{') return p;
33
    p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
8871 bpr 34
    *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); substdoc(buf);
8353 bpr 35
    prepcnt=0; parmprep(buf,pt_text);
8367 bpr 36
    switch(type) {
37
          case 0: fprintf(outf," \n!if %s \n",buf); break;
38
          case 1: fprintf(outf," \n!ifval %s \n",buf);
39
    }
10 reyssat 40
    p5=find_word_start(p4+1);
41
    if(*p5=='{' && (p6=find_matching(p5+1,'}'))!=NULL) {
5821 bpr 42
      *p4=elsechar; *p5=' '; *p6=endifchar;
10 reyssat 43
    }
44
    else *p4=endifchar;
45
    return p3+1;
46
}
47
 
8367 bpr 48
char *prim_if(char *p){ return _prim_if(p, 0); }
49
char *prim_ifval(char *p){ return _prim_if(p, 1);}
50
 
10 reyssat 51
char *prim_while(char *p)
52
{
53
    char *p1, *p2, *p3, *p4;
54
    char buf[MAX_LINELEN+1];
55
    p1=find_word_start(p); if(*p1!='{') return p;
56
    p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
57
    p3=find_word_start(p2+1); if(*p3!='{') return p;
58
    p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
8871 bpr 59
    *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); substdoc(buf);
8353 bpr 60
    prepcnt=0; parmprep(buf,pt_text);
10 reyssat 61
    fprintf(outf," \n!while %s \n",buf);
62
    *p4=whilechar;
63
    return p3+1;
64
}
65
 
66
char *prim_for(char *p)
67
{
68
    char *p1, *p2, *p3, *p4;
69
    char buf[MAX_LINELEN+1];
70
    p1=find_word_start(p); if(*p1!='{') return p;
71
    p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
72
    p3=find_word_start(p2+1); if(*p3!='{') return p;
73
    p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
8871 bpr 74
    *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1); substdoc(buf);
8353 bpr 75
    fprintf(outf," \n!for m_%s \n",find_word_start(buf));
10 reyssat 76
    *p4=nextchar;
8135 bpr 77
    return p3+1;
10 reyssat 78
}
79
 
8135 bpr 80
/* check whether the name is a document primitive. */
8367 bpr 81
/* for the moment, only def define if ifval for while or as in "msg2wims_primitives"
8353 bpr 82
 * description of primitive must be in primitive_dir="docu/primitives"
83
 * msg2wims_primitives is defined in two places:
84
 * public_html/modules/adm/doc/var.proc and public_html/scripts/docu/mkindex
85
 * should be elsewhere at least for primitives defined here
8367 bpr 86
 * that is "def define if ifval for while"
8353 bpr 87
 */
88
 
10 reyssat 89
char *doccheck(char *p)
90
{
91
    char *pe, *pl, *pv, *pp, namebuf[128], parbuf[8192];
92
    int i, k, t;
8135 bpr 93
 
94
    for(pe=p, i=0; isalnum(*pe) && i<sizeof(namebuf)-1; pe++, i++)
10 reyssat 95
      namebuf[i]=*pe;
96
    namebuf[i]=0; pe=find_word_start(pe);
97
    k=search_list(primitive,primcnt,sizeof(primitive[0]),namebuf);
98
    if(k<0) return p;
99
    if(strcmp(namebuf,"def")==0 || strcmp(namebuf,"define")==0) {
5821 bpr 100
      char parmbuf[MAX_LINELEN+1];
101
      pl=find_word_start(pe);
102
      if(*pl=='{') pl=find_word_start(++pl); else return pe;
103
      pv=find_matching(pl,'}'); if(pv==NULL) return pe;
104
      if(pv-pl>=sizeof(parmbuf)-1) return pe;
105
      memmove(parmbuf,pl,pv-pl); parmbuf[pv-pl]=0;
106
      def(parmbuf);
107
      pe=pv+1; return pe;
10 reyssat 108
    }
109
    if(strcmp(namebuf,"if")==0) return prim_if(pe);
8367 bpr 110
    if(strcmp(namebuf,"ifval")==0) return prim_ifval(pe);
10 reyssat 111
    if(strcmp(namebuf,"for")==0) return prim_for(pe);
112
    if(strcmp(namebuf,"while")==0) return prim_while(pe);
113
    fprintf(outf,"\n!read primitives.phtml %d, %s",primserial++,namebuf);
114
    for(t=0;t<16;t++) {
5821 bpr 115
      pl=find_word_start(pe);
116
      if(*pl=='{') pl=find_word_start(++pl); else break;
117
      pv=find_matching(pl,'}'); if(pv==NULL) break;
118
      if(pv-pl>=sizeof(parbuf)-1) break;
119
      memmove(parbuf,pl,pv-pl); parbuf[pv-pl]=0;
120
      for(pp=parbuf; *pp; pp++) {
121
          if(*pp=='     ' || *pp=='$') *pp=' ';
122
          if(*pp=='\n') *pp='   ';
123
      }
124
      fprintf(outf,", %s",parbuf);
125
      pe=pv+1;
10 reyssat 126
    }
127
    fprintf(outf," \n");
128
    return pe;
129
}
130