Subversion Repositories wimsdev

Rev

Rev 8947 | Rev 16838 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8947 Rev 12247
Line 22... Line 22...
22
char *getvar(char *p) {return NULL;}
22
char *getvar(char *p) {return NULL;}
23
void setvar(char *p, char *v) {return;}
23
void setvar(char *p, char *v) {return;}
24
*/
24
*/
25
char *_exec_if(char *p, int type)
25
char *_exec_if(char *p, int type)
26
{
26
{
27
    char *p1, *p2, *p3, *p4, *p5, *p6, *pp;
27
  char *p1, *p2, *p3, *p4, *p5, *p6, *pp;
28
    char buf[MAX_LINELEN+1];
28
  char buf[MAX_LINELEN+1];
29
    p1=find_word_start(p); if(*p1!='{') return p;
29
  p1=find_word_start(p); if(*p1!='{') return p;
30
    p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
30
  p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
31
    p3=find_word_start(p2+1); if(*p3!='{') return p;
31
  p3=find_word_start(p2+1); if(*p3!='{') return p;
32
    p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
32
  p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
33
    *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1);
33
  *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1);
34
    for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
34
  for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
35
      if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
35
    if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
36
    }
36
  }
37
    switch(type) {
37
  switch(type) {
38
          case 0: fprintf(outf,"\n!if %s \n$()",buf); break;
38
    case 0: fprintf(outf,"\n!if %s \n$()",buf); break;
39
          case 1: fprintf(outf,"\n!ifval %s \n$()",buf);
39
    case 1: fprintf(outf,"\n!ifval %s \n$()",buf);
40
    }
40
  }
41
    p5=find_word_start(p4+1);
41
  p5=find_word_start(p4+1);
42
    if(*p5=='{' && (p6=find_matching(p5+1,'}'))!=NULL) {
42
  if(*p5=='{' && (p6=find_matching(p5+1,'}'))!=NULL) {
43
      *p4=elsechar; *p5=' '; *p6=endifchar;
43
    *p4=elsechar; *p5=' '; *p6=endifchar;
44
    }
44
  }
45
    else *p4=endifchar;
45
  else *p4=endifchar;
46
    return p3+1;
46
  return p3+1;
47
}
47
}
48
char *exec_if(char *p) {return _exec_if(p,0);}
48
char *exec_if(char *p) {return _exec_if(p,0);}
49
char *exec_ifval(char *p) {return _exec_if(p,1);}
49
char *exec_ifval(char *p) {return _exec_if(p,1);}
50
 
50
 
51
char *exec_for(char *p)
51
char *exec_for(char *p)
52
{
52
{
53
    char *p1, *p2, *p3, *p4, *pp;
53
  char *p1, *p2, *p3, *p4, *pp;
54
    char buf[MAX_LINELEN+1];
54
  char buf[MAX_LINELEN+1];
55
    p1=find_word_start(p); if(*p1!='{') return p;
55
  p1=find_word_start(p); if(*p1!='{') return p;
56
    p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
56
  p2=find_matching(p1+1,'}'); if(p2==NULL) return p;
57
    p3=find_word_start(p2+1); if(*p3!='{') return p;
57
  p3=find_word_start(p2+1); if(*p3!='{') return p;
58
    p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
58
  p4=find_matching(p3+1,'}'); if(p4==NULL) return p;
59
    *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1);
59
  *p2=0; snprintf(buf,sizeof(buf),"%s",p1+1);
60
    for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
60
  for(pp=strchr(buf,'\\'); pp!=NULL; pp=strchr(pp+1,'\\')) {
61
      if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
61
    if(isalnum(*(pp+1))) string_modify(buf,pp,pp+1,"$m_");
62
    }
62
  }
63
    fprintf(outf," \n!for m_%s \n$()",find_word_start(buf));
63
  fprintf(outf," \n!for m_%s \n$()",find_word_start(buf));
64
    *p4=nextchar;
64
  *p4=nextchar;
65
    return p3+1;
65
  return p3+1;
66
}
66
}
67
/* process math formula inside \( ) or \( \) */
67
/* process math formula inside \( ) or \( \) */
68
void process_formula(char *p)
68
void process_formula(char *p)
69
{
69
{
70
    char *p3, bf[MAX_LINELEN+1];
70
  char *p3, bf[MAX_LINELEN+1];
71
 
71
 
72
    if(strlen(p)>=MAX_LINELEN) oef_error("formula too long");
72
  if(strlen(p)>=MAX_LINELEN) oef_error("formula too long");
73
    while((p3=strstr(p,"&lt;"))!=NULL) memmove(p3," <  ",4);
73
  while((p3=strstr(p,"&lt;"))!=NULL) memmove(p3," <  ",4);
74
    while((p3=strstr(p,"&gt;"))!=NULL) memmove(p3," >  ",4);
74
  while((p3=strstr(p,"&gt;"))!=NULL) memmove(p3," >  ",4);
75
    for(p3=strchr(p,'\n'); p3!=NULL; p3=strchr(p3,'\n')) *p3=' ';
75
  for(p3=strchr(p,'\n'); p3!=NULL; p3=strchr(p3,'\n')) *p3=' ';
76
    snprintf(bf,sizeof(bf),"%s",p);
76
  snprintf(bf,sizeof(bf),"%s",p);
77
    if(strchr(bf,'\\')==NULL && strchr(bf,'}')==NULL && strlen(bf)>2) {
77
  if(strchr(bf,'\\')==NULL && strchr(bf,'}')==NULL && strlen(bf)>2) {
78
      for(p3=strstr(bf,".."); p3!=NULL; p3=strstr(p3,"..")) {
78
    for(p3=strstr(bf,".."); p3!=NULL; p3=strstr(p3,"..")) {
79
          if(*(p3+2)=='.' || *(p3+2)==',') {
79
        if(*(p3+2)=='.' || *(p3+2)==',') {
80
            do p3++; while(*p3=='.'); continue;
80
          do p3++; while(*p3=='.'); continue;
81
          }
81
        }
82
          *p3=','; *(p3+1)=' ';
82
        *p3=','; *(p3+1)=' ';
83
      }
-
 
84
    }
83
    }
-
 
84
  }
85
    fprintf(outf,"\n!insmath %s\n$()",bf);
85
  fprintf(outf,"\n!insmath %s\n$()",bf);
86
}
86
}
87
 
87
 
88
/* deux accolades obligatoires */
88
/* deux accolades obligatoires */
89
int _matchit3(char **p, char **ps, char *name, int type)
89
int _matchit3(char **p, char **ps, char *name, int type)
90
{
90
{
91
  char *pp = find_word_start(*p+strlen(name)+1);
91
  char *pp = find_word_start(*p+strlen(name)+1);
92
  if(strncmp(*p+1,name,strlen(name))==0 && *pp=='{') {
92
  if(strncmp(*p+1,name,strlen(name))==0 && *pp=='{') {
93
    char *pp2, *pe2, *pt;
93
    char *pp2, *pe2, *pt;
94
    char *pe=find_matching(pp+1,'}');
94
    char *pe=find_matching(pp+1,'}');
95
    if(pe) pp2=find_word_start(pe+1); else return 1;
95
    if(pe) pp2=find_word_start(pe+1); else return 1;
96
    if(pp2 && *pp2=='{') pe2=find_matching(pp2+1,'}'); else return 1;
96
    if(pp2 && *pp2=='{') pe2=find_matching(pp2+1,'}'); else return 1;
97
    if(pe2) {
97
    if(pe2) {
98
      pp++; pp2++; **p=*pe=*pe2=0;
98
      pp++; pp2++; **p=*pe=*pe2=0;
99
      switch(type) {
99
      switch(type) {
100
     /* $val1 is $imagedir supprime s'il se trouve dans le code de draw */
100
     /* $val1 is $imagedir supprime s'il se trouve dans le code de draw */
101
          case 0: while((pt=strstr(pp2,"$val1/"))!=NULL) ovlstrcpy(pt,pt+strlen("$val1/")); break;
101
          case 0: while((pt=strstr(pp2,"$val1/"))!=NULL) ovlstrcpy(pt,pt+strlen("$val1/")); break;
102
      }
102
      }
103
      fprintf(outf,"%s \n\
103
    fprintf(outf,"%s \n\
104
!read oef/%s.phtml %s \\\n%s \n$()", *ps,name,pp,pp2);
104
!read oef/%s.phtml %s \\\n%s \n$()", *ps,name,pp,pp2);
105
     *ps=*p=pe2; (*ps)++; return 1;
105
    *ps=*p=pe2; (*ps)++; return 1;
106
     }
106
    }
107
  }
107
  }
108
  return 0;
108
  return 0;
109
}
109
}
110
 
110
 
111
/* deux accolades la deuxième non obligatoire */
111
/* deux accolades la deuxième non obligatoire */
112
int _matchit2(char **p, char **ps, char *name)
112
int _matchit2(char **p, char **ps, char *name)
113
{
113
{
114
  char *pp = find_word_start(*p+strlen(name)+1);
114
  char *pp = find_word_start(*p+strlen(name)+1);
115
  if(strncmp(*p+1,name,strlen(name))==0 && *pp=='{') {
115
  if(strncmp(*p+1,name,strlen(name))==0 && *pp=='{') {
116
    char *pp2, *pe2;
116
    char *pp2, *pe2;
117
    char *pe=find_matching(pp+1,'}');
117
    char *pe=find_matching(pp+1,'}');
118
    if(pe) pp2=find_word_start(pe+1); else return 1;
118
    if(pe) pp2=find_word_start(pe+1); else return 1;
119
    pe2=pe;
119
    pe2=pe;
120
    if(*pp2=='{') {
120
    if(*pp2=='{') {
121
      pe2=find_matching(++pp2,'}');
121
      pe2=find_matching(++pp2,'}');
122
      if(pe2) *pe2=0;
122
      if(pe2) *pe2=0;
Line 124... Line 124...
124
    else pp2="";
124
    else pp2="";
125
    pp++; **p=*pe=0;
125
    pp++; **p=*pe=0;
126
    fprintf(outf,"%s \n\
126
    fprintf(outf,"%s \n\
127
!read oef/%s.phtml %s %s \n$()", *ps,name,pp,pp2);
127
!read oef/%s.phtml %s %s \n$()", *ps,name,pp,pp2);
128
    *ps=*p=pe2; (*ps)++; return 1;
128
    *ps=*p=pe2; (*ps)++; return 1;
129
  }
129
  }
130
  return 0;
130
  return 0;
131
}
131
}
132
 
132
 
133
/* une seule accolade */
133
/* une seule accolade */
134
int _matchit1(char **p, char **ps, char *name)
134
int _matchit1(char **p, char **ps, char *name)
Line 146... Line 146...
146
  return 0;
146
  return 0;
147
}
147
}
148
 
148
 
149
void out_exec(char *s1, char *s2)
149
void out_exec(char *s1, char *s2)
150
{
150
{
151
    char *ps, *p, c, *p2, *p3;
151
  char *ps, *p, c, *p2, *p3;
152
    if(s2) fprintf(outf,"\n!exit\n\n:%s\n$()",s2);
152
  if(s2) fprintf(outf,"\n!exit\n\n:%s\n$()",s2);
153
    ps=s1;
153
  ps=s1;
154
    for(p=ps;*p;p++) {
154
  for(p=ps;*p;p++) {
155
      if(*p==nextchar) {
155
    if(*p==nextchar) {
156
          *p=0;
156
      *p=0;
157
          fprintf(outf,"%s \n!next\n$()",ps); ps=p+1; continue;
157
      fprintf(outf,"%s \n!next\n$()",ps); ps=p+1; continue;
158
      }
158
    }
159
      if(*p==elsechar) {
159
    if(*p==elsechar) {
160
          *p=0;
160
      *p=0;
161
          fprintf(outf,"%s \n!else\n$()",ps); ps=p+1; continue;
161
      fprintf(outf,"%s \n!else\n$()",ps); ps=p+1; continue;
162
      }
162
    }
163
      if(*p==endifchar) {
163
    if(*p==endifchar) {
164
          *p=0;
164
      *p=0;
165
          fprintf(outf,"%s \n!endif\n$()",ps); ps=p+1; continue;
165
      fprintf(outf,"%s \n!endif\n$()",ps); ps=p+1; continue;
166
      }
166
    }
167
      if(*p!='\\') continue;
167
    if(*p!='\\') continue;
168
      c=*(p+1);
168
    c=*(p+1);
169
      if(isalnum(c)) {
169
    if(isalnum(c)) {
170
/* exit */
170
/* exit */
171
          if(strncmp(p+1,"exit",strlen("exit"))==0 && !isalnum(*(p+strlen("exit")+1))) {
171
      if(strncmp(p+1,"exit",strlen("exit"))==0 && !isalnum(*(p+strlen("exit")+1))) {
172
            *p=0; fprintf(outf,"%s\n!exit\n",ps); p+=strlen("exit")+1; ps=p;
172
        *p=0; fprintf(outf,"%s\n!exit\n",ps); p+=strlen("exit")+1; ps=p;
173
            continue;
173
        continue;
174
          }
174
      }
175
/* for */
175
/* for */
176
          if(strncmp(p+1,"for",strlen("for"))==0 && *find_word_start(p+strlen("for")+1)=='{') {
176
      if(strncmp(p+1,"for",strlen("for"))==0 && *find_word_start(p+strlen("for")+1)=='{') {
177
            char *pt;
177
        char *pt;
178
            *p=0; fprintf(outf,"%s",ps); p++; ps=p;
178
        *p=0; fprintf(outf,"%s",ps); p++; ps=p;
179
            pt=exec_for(p+strlen("for")); if(pt>p+strlen("for")) {p=pt-1;ps=pt;}
179
        pt=exec_for(p+strlen("for")); if(pt>p+strlen("for")) {p=pt-1;ps=pt;}
180
            continue;
180
        continue;
181
          }
181
      }
182
/* if */
182
/* if */
183
          if(strncmp(p+1,"if",strlen("if"))==0 && *find_word_start(p+strlen("if")+1)=='{') {
183
      if(strncmp(p+1,"if",strlen("if"))==0 && *find_word_start(p+strlen("if")+1)=='{') {
184
            char *pt;
184
        char *pt;
185
            *p=0; fprintf(outf,"%s",ps); p++; ps=p;
185
        *p=0; fprintf(outf,"%s",ps); p++; ps=p;
186
            pt=exec_if(p+2); if(pt>p+strlen("if")) {p=pt-1;ps=pt;}
186
        pt=exec_if(p+2); if(pt>p+strlen("if")) {p=pt-1;ps=pt;}
187
            continue;
-
 
188
          }
-
 
189
/* ifval */
-
 
190
          if(strncmp(p+1,"ifval",strlen("ifval"))==0 && *find_word_start(p+strlen("ifval")+1)=='{') {
-
 
191
            char *pt;
-
 
192
            *p=0; fprintf(outf,"%s",ps); p++; ps=p;
-
 
193
            pt=exec_if(p+strlen("ifval")); if(pt>p+strlen("ifval")) {p=pt-1;ps=pt;}
-
 
194
            continue;
-
 
195
          }
-
 
196
          if (_matchit2(&p, &ps, "img")) continue;
-
 
197
          if (_matchit2(&p, &ps, "audio")) continue;
-
 
198
          if (_matchit1(&p, &ps, "embed")) continue;
-
 
199
          if (_matchit1(&p, &ps, "special")) continue;
-
 
200
          if (_matchit3(&p, &ps, "draw",1)) continue;
-
 
201
          if (_matchit3(&p, &ps, "canvasdraw",0)) continue;
-
 
202
          *p++=0; fprintf(outf,"%s$m_",ps); ps=p; continue;
-
 
203
      }
-
 
204
      if(c=='\\') {
-
 
205
          ovlstrcpy(p,p+1); continue;
-
 
206
      }
-
 
207
      if(c=='(') {
-
 
208
          p2=find_matching(p+2,')'); p3=strstr(p,"\\)");
-
 
209
          if((p2==NULL && p3!=NULL) ||
-
 
210
             (p2!=NULL && p3!=NULL && p3<p2)) p2=p3+1;
-
 
211
          if(p2==NULL) continue;
-
 
212
          *p++=0; fprintf(outf,"%s",ps);
-
 
213
          *p2=0; if(*(p2-1)=='\\') *(p2-1)=0;
-
 
214
          process_formula(p+1);
-
 
215
          formulaend: p=p2; ps=p+1;
-
 
216
          continue;
187
        continue;
217
      }
188
      }
218
      if(c=='{') {
189
/* ifval */
219
          p2=find_matching(p+2,'}'); p3=strstr(p,"\\}");
190
      if(strncmp(p+1,"ifval",strlen("ifval"))==0 && *find_word_start(p+strlen("ifval")+1)=='{') {
220
          if((p2==NULL && p3!=NULL) ||
-
 
221
             (p2!=NULL && p3!=NULL && p3<p2)) p2=p3+1;
-
 
222
          if(p2==NULL) continue;
191
        char *pt;
223
          *p++=0; fprintf(outf,"%s",ps);
192
         *p=0; fprintf(outf,"%s",ps); p++; ps=p;
224
          *p2=0; process_formula(p+1);
193
        pt=exec_if(p+strlen("ifval")); if(pt>p+strlen("ifval")) {p=pt-1;ps=pt;}
225
          goto formulaend;
194
        continue;
226
      }
195
      }
-
 
196
      if (_matchit2(&p, &ps, "img")) continue;
-
 
197
      if (_matchit2(&p, &ps, "audio")) continue;
-
 
198
      if (_matchit1(&p, &ps, "embed")) continue;
-
 
199
      if (_matchit1(&p, &ps, "special")) continue;
-
 
200
      if (_matchit3(&p, &ps, "draw",1)) continue;
-
 
201
      if (_matchit3(&p, &ps, "canvasdraw",0)) continue;
-
 
202
      *p++=0; fprintf(outf,"%s$m_",ps); ps=p; continue;
-
 
203
    }
-
 
204
    if(c=='\\') {
-
 
205
      ovlstrcpy(p,p+1); continue;
-
 
206
    }
-
 
207
    if(c=='(') {
-
 
208
      p2=find_matching(p+2,')'); p3=strstr(p,"\\)");
-
 
209
      if((p2==NULL && p3!=NULL) ||
-
 
210
         (p2!=NULL && p3!=NULL && p3<p2)) p2=p3+1;
-
 
211
      if(p2==NULL) continue;
-
 
212
      *p++=0; fprintf(outf,"%s",ps);
-
 
213
        *p2=0; if(*(p2-1)=='\\') *(p2-1)=0;
-
 
214
        process_formula(p+1);
-
 
215
        formulaend: p=p2; ps=p+1;
-
 
216
        continue;
-
 
217
    }
-
 
218
    if(c=='{') {
-
 
219
      p2=find_matching(p+2,'}'); p3=strstr(p,"\\}");
-
 
220
      if((p2==NULL && p3!=NULL) ||
-
 
221
         (p2!=NULL && p3!=NULL && p3<p2)) p2=p3+1;
-
 
222
      if(p2==NULL) continue;
-
 
223
      *p++=0; fprintf(outf,"%s",ps);
-
 
224
      *p2=0; process_formula(p+1);
-
 
225
      goto formulaend;
227
    }
226
    }
-
 
227
  }
228
    fprintf(outf,"%s\n$()",ps);
228
  fprintf(outf,"%s\n$()",ps);
229
}
229
}
230
 
-