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