Subversion Repositories wimsdev

Rev

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