Go to most recent revision | Details | 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. */ |
||
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,'\\')) { |
||
5821 | bpr | 34 | if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_"); |
10 | reyssat | 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) { |
||
5821 | bpr | 40 | *p4=elsechar; *p5=' '; *p6=endifchar; |
10 | reyssat | 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,'\\')) { |
||
5821 | bpr | 56 | if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_"); |
10 | reyssat | 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,'\\')) { |
||
5821 | bpr | 74 | if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_"); |
10 | reyssat | 75 | } |
76 | */ fprintf(outf," \n!for m_%s \n",find_word_start(buf)); |
||
77 | *p4=nextchar; |
||
78 | return p3+1; |
||
79 | } |
||
80 | |||
5821 | bpr | 81 | /* check whether the name is a document primitive. */ |
82 | /* for the moment, only \def \define if for while or as in "msg2wims_primitives" |
||
83 | description of primitive must be in primitive_dir="docu/primitives"*/ |
||
10 | reyssat | 84 | char *doccheck(char *p) |
85 | { |
||
86 | char *pe, *pl, *pv, *pp, namebuf[128], parbuf[8192]; |
||
87 | int i, k, t; |
||
88 | |||
89 | for(pe=p, i=0; isalnum(*pe) && i<sizeof(namebuf)-1; pe++, i++) |
||
90 | namebuf[i]=*pe; |
||
91 | namebuf[i]=0; pe=find_word_start(pe); |
||
92 | k=search_list(primitive,primcnt,sizeof(primitive[0]),namebuf); |
||
93 | if(k<0) return p; |
||
94 | if(strcmp(namebuf,"def")==0 || strcmp(namebuf,"define")==0) { |
||
5821 | bpr | 95 | char parmbuf[MAX_LINELEN+1]; |
96 | pl=find_word_start(pe); |
||
97 | if(*pl=='{') pl=find_word_start(++pl); else return pe; |
||
98 | pv=find_matching(pl,'}'); if(pv==NULL) return pe; |
||
99 | if(pv-pl>=sizeof(parmbuf)-1) return pe; |
||
100 | memmove(parmbuf,pl,pv-pl); parmbuf[pv-pl]=0; |
||
101 | def(parmbuf); |
||
102 | pe=pv+1; return pe; |
||
10 | reyssat | 103 | } |
104 | if(strcmp(namebuf,"if")==0) return prim_if(pe); |
||
105 | if(strcmp(namebuf,"for")==0) return prim_for(pe); |
||
106 | if(strcmp(namebuf,"while")==0) return prim_while(pe); |
||
107 | fprintf(outf,"\n!read primitives.phtml %d, %s",primserial++,namebuf); |
||
108 | for(t=0;t<16;t++) { |
||
5821 | bpr | 109 | pl=find_word_start(pe); |
110 | if(*pl=='{') pl=find_word_start(++pl); else break; |
||
111 | pv=find_matching(pl,'}'); if(pv==NULL) break; |
||
112 | if(pv-pl>=sizeof(parbuf)-1) break; |
||
113 | memmove(parbuf,pl,pv-pl); parbuf[pv-pl]=0; |
||
114 | for(pp=parbuf; *pp; pp++) { |
||
115 | if(*pp==' ' || *pp=='$') *pp=' '; |
||
116 | if(*pp=='\n') *pp=' '; |
||
117 | } |
||
118 | fprintf(outf,", %s",parbuf); |
||
119 | pe=pv+1; |
||
10 | reyssat | 120 | } |
121 | fprintf(outf," \n"); |
||
122 | return pe; |
||
123 | } |
||
124 |