Rev 9095 | Rev 9229 | 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 | */ |
||
8135 | bpr | 17 | #include "../Lib/libwims.h" |
18 | #include "oef2wims.h" |
||
10 | reyssat | 19 | int prepcnt; |
2656 | bpr | 20 | int ex_statement=0, ex_hint=0, ex_help=0, ex_solution=0, ex_latex=0; |
8135 | bpr | 21 | |
22 | const size_t MAX_KEY_LEN=128; |
||
10 | reyssat | 23 | char vbuf_statement[MAX_LINELEN+1]; |
24 | char vbuf_hint[MAX_LINELEN+1]; |
||
25 | char vbuf_help[MAX_LINELEN+1]; |
||
26 | char vbuf_solution[MAX_LINELEN+1]; |
||
9093 | bpr | 27 | char vbuf_latex[MAX_LINELEN+1]; |
10 | reyssat | 28 | |
7677 | bpr | 29 | /* empty processor, template. */ |
10 | reyssat | 30 | void empty(char *p[MAX_PARM]) {} |
31 | |||
9095 | bpr | 32 | void p_header(char *p[MAX_PARM]) |
3288 | bpr | 33 | { |
34 | p[0]=find_word_start(p[0]); |
||
35 | if(strlen(p[0])>MAX_KEY_LEN) p[0][MAX_KEY_LEN]=0; |
||
9095 | bpr | 36 | fprintf(outf,"%s=%s\n", p[1], p[0]); |
3288 | bpr | 37 | } |
38 | |||
10 | reyssat | 39 | void p_computeanswer(char *p[MAX_PARM]) |
7677 | bpr | 40 | { |
10 | reyssat | 41 | p[0]=find_word_start(p[0]); |
42 | *find_word_end(p[0])=0; |
||
43 | if(strcasecmp(p[0],"yes")) |
||
44 | fprintf(outf,"computeanswer=no\n"); |
||
45 | else fprintf(outf,"computeanswer=%s\n",p[0]); |
||
46 | } |
||
47 | |||
48 | void p_precision(char *p[MAX_PARM]) |
||
49 | { |
||
50 | int pr; |
||
51 | pr=atoi(p[0]); |
||
52 | if(pr<0 || pr>100000000) return; |
||
53 | fprintf(outf,"precision=%d\n",pr); |
||
54 | } |
||
9227 | bpr | 55 | void p_gen2(char *name_gen, char *p[MAX_PARM]) |
7677 | bpr | 56 | { |
9227 | bpr | 57 | char vbuf_gen[MAX_LINELEN+1]; |
1105 | bpr | 58 | if(p==NULL) return; |
9227 | bpr | 59 | snprintf(vbuf_gen,sizeof(vbuf_gen),"%s",p[0]); subst(vbuf_gen); |
60 | singlespace(vbuf_gen); |
||
61 | fprintf(outf,"%s=%s\n\n", name_gen, vbuf_gen); |
||
1105 | bpr | 62 | } |
9227 | bpr | 63 | void p_css(char *p[MAX_PARM]) {p_gen2("oefcss", p);} |
64 | void p_credits(char *p[MAX_PARM]){p_gen2("credits", p);} |
||
4810 | bpr | 65 | |
10 | reyssat | 66 | void p_wims(char *p[MAX_PARM]) |
67 | { |
||
68 | char vbuf[MAX_LINELEN+1]; |
||
69 | snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf); |
||
7677 | bpr | 70 | /* the second condition could be removed? |
71 | * To be very careful! */ |
||
10 | reyssat | 72 | if(strchr(vbuf,'=')==NULL || strchr(vbuf,'!')!=NULL) return; |
7677 | bpr | 73 | fprintf(outf,"%s\n",vbuf); |
10 | reyssat | 74 | } |
75 | |||
76 | void p_mdef(char *p[MAX_PARM]) |
||
77 | { |
||
78 | char vbuf[MAX_LINELEN+1]; |
||
79 | if(wordchr(mdef,p[0])==NULL) return; |
||
80 | snprintf(vbuf,sizeof(vbuf),"%s",p[1]); subst(vbuf); |
||
7677 | bpr | 81 | /* the second condition could be removed? |
82 | * To be very careful! */ |
||
10 | reyssat | 83 | if(strchr(vbuf,'!')!=NULL) return; |
84 | fprintf(outf,"m_%s=%s\n",p[0],vbuf); |
||
85 | } |
||
86 | |||
87 | void p_range(char *p[MAX_PARM]) |
||
88 | { |
||
89 | double left, right; |
||
90 | char *pp; |
||
91 | pp=strstr(p[0],".."); |
||
92 | if(pp==NULL) return; |
||
93 | *pp=0;pp+=strlen(".."); |
||
94 | left=atof(p[0]); right=atof(pp); |
||
95 | if(left>=right-1E-50 || left<-1E50 || right>1E50) return; |
||
96 | fprintf(outf,"leftrange=%f\nrightrange=%f\n",left,right); |
||
97 | } |
||
98 | |||
99 | void p_language(char *p[MAX_PARM]) |
||
7677 | bpr | 100 | { |
10 | reyssat | 101 | p[0]=find_word_start(p[0]); |
102 | *find_word_end(p[0])=0; |
||
7677 | bpr | 103 | if(strlen(p[0])==2) fprintf(outf,"language=%s\n",p[0]); |
10 | reyssat | 104 | } |
105 | |||
106 | void p_statement(char *p[MAX_PARM]) |
||
107 | { |
||
108 | if(ex_statement<0) return; |
||
109 | if(ex_statement>0 || p==NULL) { |
||
7677 | bpr | 110 | out_exec(vbuf_statement,"question"); |
111 | ex_statement=-1; return; |
||
10 | reyssat | 112 | } |
113 | if(p==NULL) return; |
||
114 | snprintf(vbuf_statement,sizeof(vbuf_statement),"%s",p[0]); |
||
115 | subst(vbuf_statement); |
||
116 | if(strcmp(format,"html")!=0) { |
||
7677 | bpr | 117 | fprintf(outf,"question=!nosubst %s\n",vbuf_statement); |
118 | ex_statement=-1; |
||
10 | reyssat | 119 | } |
120 | else { |
||
7677 | bpr | 121 | fprintf(outf,"question=%s\n",executed_str); |
122 | ex_statement=1; |
||
10 | reyssat | 123 | } |
124 | } |
||
125 | |||
9093 | bpr | 126 | void p_gen(int *ex_gen, char vbuf_gen[], char *name_gen, char *p[MAX_PARM]) |
10 | reyssat | 127 | { |
9093 | bpr | 128 | if(*ex_gen<0) return; |
129 | if(*ex_gen>0 || p==NULL) { |
||
130 | out_exec(vbuf_gen, name_gen); |
||
131 | *ex_gen=-1; return; |
||
10 | reyssat | 132 | } |
9093 | bpr | 133 | snprintf(vbuf_gen,MAX_LINELEN,"%s",p[0]); subst(vbuf_gen); |
134 | if(strchr(vbuf_gen,'\\')!=NULL) { |
||
135 | fprintf(outf,"%s=%s\n", name_gen, executed_str); |
||
136 | *ex_gen=1; |
||
10 | reyssat | 137 | } |
138 | else { |
||
9093 | bpr | 139 | singlespace(vbuf_gen); |
140 | fprintf(outf,"%s=!nosubst %s\n\n", name_gen, vbuf_gen); |
||
10 | reyssat | 141 | } |
142 | } |
||
143 | |||
9093 | bpr | 144 | void p_hint(char *p[MAX_PARM]) {p_gen(&ex_hint, vbuf_hint, "hint", p);} |
145 | void p_help(char *p[MAX_PARM]) {p_gen(&ex_help, vbuf_help, "help", p);} |
||
146 | void p_solution(char *p[MAX_PARM]) {p_gen(&ex_solution, vbuf_solution, "solution", p);} |
||
10 | reyssat | 147 | |
2656 | bpr | 148 | void p_latex(char *p[MAX_PARM]) |
149 | { |
||
150 | if(ex_latex<0) return; |
||
151 | if(ex_latex>0 || p==NULL) { |
||
7677 | bpr | 152 | out_exec(vbuf_latex,"latex"); |
153 | ex_latex=-1; return; |
||
2656 | bpr | 154 | } |
7677 | bpr | 155 | snprintf(vbuf_latex,sizeof(vbuf_latex),"%s",p[0]); |
2656 | bpr | 156 | subst(vbuf_latex); |
7677 | bpr | 157 | singlespace(vbuf_latex); |
158 | fprintf(outf,"latex=!nosubst %s\n\n", vbuf_latex); |
||
2656 | bpr | 159 | } |
160 | |||
10 | reyssat | 161 | enum {typ_default, typ_num, typ_func, typ_units, typ_text, |
162 | typ_formal,typ_matrix,typ_vector,typ_set,typ_equation, |
||
163 | typ_case, typ_nocase, typ_atext, typ_wlist, typ_comp, |
||
164 | typ_algexp, typ_litexp, typ_menu, typ_coord, typ_fill, |
||
165 | typ_raw, typ_symtext, |
||
166 | typ_java, typ_src, typ_chem |
||
167 | }; |
||
168 | |||
169 | struct { |
||
170 | char *name; |
||
171 | int type; |
||
172 | char *def; |
||
173 | } anstype[]={ |
||
7677 | bpr | 174 | {"algexp", typ_algexp, "algexp"}, |
175 | {"aset", typ_set, "aset"}, |
||
176 | {"atext", typ_atext, "atext"}, |
||
177 | {"case", typ_case, "case"}, |
||
178 | {"checkbox", typ_menu, "checkbox"}, |
||
10 | reyssat | 179 | {"chemeq", typ_chem, "chemeq"}, |
7677 | bpr | 180 | {"chset", typ_atext, "chset"}, |
181 | {"click", typ_menu, "click"}, |
||
182 | {"clickfill", typ_fill, "clickfill"}, |
||
183 | {"code", typ_src, "code"}, |
||
184 | {"compose", typ_comp, "compose"}, |
||
185 | {"coord", typ_coord, "coord"}, |
||
186 | {"coordinates", typ_coord, "coord"}, |
||
187 | {"corresp", typ_comp, "correspond"}, |
||
188 | {"correspond", typ_comp, "correspond"}, |
||
189 | {"default", typ_default, "default"}, |
||
190 | {"dragfill", typ_fill, "dragfill"}, |
||
191 | {"equation", typ_equation, "equation"}, |
||
192 | {"expalg", typ_algexp, "algexp"}, |
||
193 | {"formal", typ_formal, "formal"}, |
||
194 | {"fset", typ_set, "fset"}, |
||
195 | {"function", typ_func, "function"}, |
||
196 | {"imgcomp", typ_comp, "imgcomp"}, |
||
197 | {"javacurve", typ_java, "javacurve"}, |
||
198 | {"link", typ_menu, "click"}, |
||
199 | {"litexp", typ_litexp, "litexp"}, |
||
200 | {"mark", typ_menu, "mark"}, |
||
201 | {"matrix", typ_matrix, "matrix"}, |
||
202 | {"menu", typ_menu, "menu"}, |
||
203 | {"nocase", typ_nocase, "nocase"}, |
||
204 | {"number", typ_num, "numeric"}, |
||
205 | {"numeric", typ_num, "numeric"}, |
||
206 | {"numexp", typ_algexp, "numexp"}, |
||
207 | {"radio", typ_menu, "radio"}, |
||
208 | {"range", typ_func, "range"}, |
||
209 | {"ranges", typ_func, "range"}, |
||
210 | {"raw", typ_raw, "raw"}, |
||
211 | {"reorder", typ_comp, "reorder"}, |
||
212 | {"select", typ_menu, "menu"}, |
||
213 | {"set", typ_set, "set"}, |
||
214 | {"sigunits", typ_units, "sigunits"}, |
||
215 | {"symtext", typ_symtext, "symtext"}, |
||
216 | {"text", typ_text, "case"}, |
||
217 | {"textcomp", typ_comp, "textcomp"}, |
||
218 | {"unit", typ_units, "units"}, |
||
219 | {"units", typ_units, "units"}, |
||
220 | {"vector", typ_vector, "vector"}, |
||
221 | {"wlist", typ_wlist, "wlist"}, |
||
222 | {"wordcomp", typ_comp, "textcomp"} |
||
10 | reyssat | 223 | }; |
224 | |||
225 | #define anstype_no (sizeof(anstype)/sizeof(anstype[0])) |
||
226 | |||
227 | void p_answer(char *p[MAX_PARM]) |
||
228 | { |
||
229 | char *pp, vbuf[MAX_LINELEN+1],nbuf[MAX_LINELEN+1]; |
||
230 | int i,j,k,typ; |
||
7677 | bpr | 231 | |
232 | /* look for type definition */ |
||
10 | reyssat | 233 | typ=typ_default; |
234 | for(i=0;i<5;i++) { |
||
7677 | bpr | 235 | if(p[i]==NULL || p[i][0]==0) continue; |
236 | p[i]=find_word_start(p[i]); |
||
237 | if(strncasecmp(p[i],"type",strlen("type"))==0) { |
||
238 | char *tt; |
||
239 | tt=find_word_start(p[i]+strlen("type")); |
||
240 | if(*tt=='=') { |
||
241 | for(j=i;j<6;j++) p[j]=p[j+1]; i--; |
||
242 | tt=find_word_start(tt+1); *find_word_end(tt)=0; |
||
243 | k=search_list(anstype,anstype_no,sizeof(anstype[0]),tt); |
||
244 | /* unknown type is now substituted */ |
||
245 | if(k>=0) { |
||
246 | fprintf(outf,"replytype%d=%s\n", |
||
247 | answercnt,anstype[k].def); |
||
248 | typ=anstype[k].type; |
||
249 | } |
||
250 | else { |
||
251 | snprintf(nbuf,sizeof(nbuf),"%s",tt); subst(nbuf); |
||
252 | fprintf(outf,"replytype%d=%s\n\n",answercnt,nbuf); |
||
253 | } |
||
254 | } |
||
255 | continue; |
||
256 | } |
||
257 | if(strncasecmp(p[i],"option",strlen("option"))==0) { |
||
258 | char *tt, *tv; |
||
259 | tt=p[i]+strlen("option"); |
||
260 | if(*tt=='s' || *tt=='S') tt++; |
||
261 | tt=find_word_start(tt); |
||
262 | if(*tt=='=') { |
||
263 | for(j=i;j<6;j++) p[j]=p[j+1]; i--; |
||
264 | snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf); |
||
265 | for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' '; |
||
266 | strip_trailing_spaces(nbuf); |
||
267 | fprintf(outf,"replyoption%d=%s \n",answercnt, |
||
268 | find_word_start(nbuf)); |
||
269 | } |
||
270 | continue; |
||
271 | } |
||
272 | if(strncasecmp(p[i],"weight",strlen("weight"))==0) { |
||
273 | char *tt; |
||
274 | tt=p[i]+strlen("weight"); |
||
275 | tt=find_word_start(tt); |
||
276 | if(*tt=='=') { |
||
277 | for(j=i;j<6;j++) p[j]=p[j+1]; i--; |
||
278 | snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf); |
||
279 | strip_trailing_spaces(nbuf); |
||
280 | fprintf(outf,"replyweight%d=%s \n",answercnt, |
||
281 | find_word_start(nbuf)); |
||
282 | } |
||
283 | continue; |
||
284 | } |
||
10 | reyssat | 285 | } |
286 | p[0]=find_word_start(p[0]); |
||
287 | strncpy(nbuf,p[0],MAX_LINELEN); nbuf[MAX_LINELEN]=0; subst(nbuf); |
||
288 | nbuf[MAX_PROMPTLEN]=0; |
||
289 | strip_trailing_spaces(nbuf); pp=nbuf+strlen(nbuf)-1; |
||
290 | if(*pp=='=') *pp=0; |
||
291 | p[1]=find_word_start(p[1]); |
||
292 | if(*p[1]=='\\' && (isalnum(*(p[1]+1)) || *(p[1]+1)=='_')) { |
||
7677 | bpr | 293 | /* check for analyzed answers */ |
294 | int i,n; char *pt; |
||
295 | strncpy(vbuf,p[1]+1,MAX_LINELEN); vbuf[MAX_LINELEN]=0; |
||
296 | pt=strchr(vbuf,';'); if(pt!=NULL) *pt=0; |
||
297 | strip_trailing_spaces(vbuf); n=strlen(vbuf); |
||
298 | if(n>=MAX_NAMELEN) goto normal; |
||
299 | for(i=0;i<n && (isalnum(vbuf[i]) || vbuf[i]=='_');i++); |
||
300 | if(i<n) goto normal; |
||
301 | for(i=varcnt-1;i>=1 && strcmp(vbuf,param[i].name)!=0;i--); |
||
302 | if(i<1) { /* unused name; the answer should be analyzed */ |
||
303 | char *pm; |
||
304 | pm=xmalloc(MAX_NAMELEN+2); |
||
305 | ovlstrcpy(pm,vbuf); param[varcnt].name=pm; |
||
306 | if(pt) { |
||
307 | *pt=';'; |
||
308 | ovlstrcpy(vbuf,pt); subst(vbuf); pt=vbuf; |
||
309 | } |
||
310 | else pt=""; |
||
311 | param[varcnt].type=pt_real; |
||
312 | param[varcnt].save=1; |
||
313 | fprintf(outf,"replyname%d=%s\nreplygood%d=?analyze %d%s\n", |
||
314 | answercnt,nbuf,answercnt,varcnt,pt); |
||
315 | condans++; answercnt++; varcnt++; return; |
||
316 | } |
||
10 | reyssat | 317 | } |
318 | normal: |
||
319 | strncpy(vbuf,p[1],MAX_LINELEN); vbuf[MAX_LINELEN]=0; |
||
320 | subst(vbuf); |
||
321 | switch(typ) { |
||
7677 | bpr | 322 | default: |
323 | case typ_default: { |
||
324 | fprintf(outf,"replyname%d=%s\nreplygood%d=%s\n", |
||
325 | answercnt,nbuf,answercnt,vbuf); |
||
326 | break; |
||
327 | } |
||
328 | case typ_num: { |
||
329 | fprintf(outf,"replyname%d=%s\nreplygood%d=$[%s]\n", |
||
330 | answercnt,nbuf,answercnt,vbuf); |
||
331 | break; |
||
332 | } |
||
333 | case typ_equation: |
||
334 | case typ_func: { |
||
335 | fprintf(outf,"replyname%d=%s\nreplygood%d=!rawmath %s\n", |
||
336 | answercnt,nbuf,answercnt,vbuf); |
||
337 | break; |
||
338 | } |
||
339 | case typ_units: { |
||
340 | fprintf(outf,"replyname%d=%s\nreplygood%d=%s\n", |
||
341 | answercnt,nbuf,answercnt,vbuf); |
||
342 | break; |
||
343 | } |
||
10 | reyssat | 344 | } |
345 | answercnt++; |
||
346 | } |
||
347 | |||
348 | void p_choice(char *p[MAX_PARM]) |
||
349 | { |
||
350 | int i,j; |
||
351 | char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1],nbuf[MAX_LINELEN+1]; |
||
352 | for(i=0;i<5;i++) { |
||
7677 | bpr | 353 | if(p[i]==NULL || p[i][0]==0) continue; |
354 | p[i]=find_word_start(p[i]); |
||
355 | if(strncasecmp(p[i],"option",strlen("option"))==0) { |
||
356 | char *tt, *tv; |
||
357 | tt=p[i]+strlen("option"); |
||
358 | if(*tt=='s' || *tt=='S') tt++; |
||
359 | tt=find_word_start(tt); |
||
360 | if(*tt=='=') { |
||
361 | for(j=i;j<6;j++) p[j]=p[j+1]; i--; |
||
362 | snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf); |
||
363 | for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' '; |
||
364 | strip_trailing_spaces(nbuf); |
||
365 | fprintf(outf,"choiceoption%d=%s \n",choicecnt, |
||
366 | find_word_start(nbuf)); |
||
367 | } |
||
368 | continue; |
||
369 | } |
||
370 | if(strncasecmp(p[i],"weight",strlen("weight"))==0) { |
||
371 | char *tt; |
||
372 | tt=p[i]+strlen("weight"); |
||
373 | tt=find_word_start(tt); |
||
374 | if(*tt=='=') { |
||
375 | for(j=i;j<6;j++) p[j]=p[j+1]; i--; |
||
376 | snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf); |
||
377 | strip_trailing_spaces(nbuf); |
||
378 | fprintf(outf,"choiceweight%d=%s \n",choicecnt, |
||
379 | find_word_start(nbuf)); |
||
380 | } |
||
381 | continue; |
||
382 | } |
||
10 | reyssat | 383 | } |
384 | p[0]=find_word_start(p[0]); |
||
385 | snprintf(buf1,sizeof(buf1),"%s",p[1]); subst(buf1); |
||
386 | snprintf(buf2,sizeof(buf2),"%s",p[2]); subst(buf2); |
||
387 | snprintf(nbuf,sizeof(nbuf),"%s",p[0]); subst(nbuf); |
||
388 | nbuf[MAX_PROMPTLEN]=0; |
||
389 | fprintf(outf,"choicename%d=%s\nchoicegood%d=%s\nchoicebad%d=%s\n", |
||
7677 | bpr | 390 | choicecnt,nbuf,choicecnt,buf1,choicecnt,buf2); |
10 | reyssat | 391 | choicecnt++; |
392 | } |
||
393 | |||
394 | void putval(char *p, int n, int ptype) |
||
395 | { |
||
396 | switch(ptype) { |
||
7677 | bpr | 397 | case pt_int: { |
398 | fprintf(outf,"val%d=$[rint(%s)]\n",n,p); |
||
399 | break; |
||
400 | } |
||
401 | case pt_real: { |
||
402 | fprintf(outf,"val%d=$[%s]\n",n,p); |
||
403 | break; |
||
404 | } |
||
405 | case pt_func: { |
||
406 | fprintf(outf,"val%d=!rawmath %s\n",n,p); |
||
407 | break; |
||
408 | } |
||
409 | case pt_complex: { |
||
410 | fprintf(outf,"t_=!rawmath %s\nt_=!exec pari print($t_)\n\ |
||
10 | reyssat | 411 | val%d=!mathsubst I=i in $t_\n",p,n); |
7677 | bpr | 412 | break; |
413 | } |
||
414 | case pt_matrix: { |
||
415 | fprintf(outf,"tmp=!trim %s\n\ |
||
7688 | bpr | 416 | val%d=!translate internal $ \\\n$ to ;; in $tmp\n",p,n); |
7677 | bpr | 417 | break; |
418 | } |
||
419 | case pt_rat: { |
||
420 | fprintf(outf,"t_=!rawmath %s\n\ |
||
10 | reyssat | 421 | val%d=!exec pari print($t_)\n",p,n); |
7677 | bpr | 422 | break; |
423 | } |
||
424 | default: { |
||
425 | fprintf(outf,"val%d=%s\n",n,p); |
||
426 | break; |
||
427 | } |
||
10 | reyssat | 428 | } |
429 | } |
||
430 | |||
431 | void parm(char *p[MAX_PARM], int ptype) |
||
432 | { |
||
433 | char *pp, *p2; |
||
434 | char vbuf[MAX_LINELEN+1]; |
||
435 | int i; |
||
436 | |||
437 | p[0]=find_word_start(p[0]); |
||
438 | if(*p[0]=='\\') p[0]++; |
||
7677 | bpr | 439 | /* bad name */ |
10 | reyssat | 440 | if(!isalpha(*p[0])) return; |
441 | strip_trailing_spaces(p[0]); |
||
442 | for(pp=p[0];*pp;pp++) if(!isalnum(*pp) && *pp!='_') { |
||
7677 | bpr | 443 | /* bad name and security risk */ |
444 | if(!isspace(*pp)) return; |
||
445 | ovlstrcpy(pp,pp+1); pp--; |
||
10 | reyssat | 446 | } |
447 | for(i=1;i<varcnt && strcmp(p[0],param[i].name)!=0;i++); |
||
448 | p[1]=find_word_start(p[1]); |
||
449 | snprintf(vbuf,sizeof(vbuf),"%s",p[1]); subst(vbuf); |
||
450 | if(deftag) repsubst(vbuf); |
||
451 | if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') { |
||
7677 | bpr | 452 | char buf[MAX_LINELEN+1]; |
453 | if(check_compare(vbuf)==0) goto noif; |
||
454 | p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0; |
||
455 | snprintf(buf,sizeof(buf),"%s",vbuf); |
||
456 | prepcnt=0; parmprep(buf,ptype); |
||
457 | fprintf(outf,"\n!ifval %s\n",buf); |
||
458 | snprintf(buf,sizeof(buf),"%s",pp); |
||
459 | parmprep(buf,ptype); putval(buf,i,ptype); |
||
460 | if(p2!=NULL) { |
||
461 | fprintf(outf,"!else\n"); |
||
462 | snprintf(buf,sizeof(buf),"%s",p2); |
||
463 | parmprep(buf,ptype); putval(buf,i,ptype); |
||
464 | } |
||
465 | fprintf(outf,"!endif\n"); |
||
10 | reyssat | 466 | } |
467 | else { |
||
468 | noif: |
||
7677 | bpr | 469 | prepcnt=0; parmprep(vbuf, ptype); |
470 | putval(vbuf,i,ptype); |
||
10 | reyssat | 471 | } |
472 | if(i>=varcnt && i<MAX_PARAM) { |
||
7677 | bpr | 473 | param[varcnt].name=p[0]; |
474 | param[varcnt].type=ptype; |
||
475 | param[varcnt].save=0; |
||
476 | varcnt++; |
||
10 | reyssat | 477 | } |
478 | } |
||
479 | |||
480 | void p_int(char *p[MAX_PARM]) {parm(p,pt_int);} |
||
481 | void p_rational(char *p[MAX_PARM]) {parm(p,pt_rat);} |
||
482 | void p_real(char *p[MAX_PARM]) {parm(p,pt_real);} |
||
483 | void p_complex(char *p[MAX_PARM]) {parm(p,pt_complex);} |
||
484 | void p_func(char *p[MAX_PARM]) {parm(p,pt_func);} |
||
485 | void p_text(char *p[MAX_PARM]) {parm(p,pt_text);} |
||
486 | void p_matrix(char *p[MAX_PARM]) {parm(p,pt_matrix);} |
||
487 | |||
488 | void p_parm(char *p[MAX_PARM]) |
||
489 | { |
||
490 | parm(p,pt_real); |
||
491 | } |
||
492 | |||
8367 | bpr | 493 | void _p_if(char *p[MAX_PARM], int type) |
10 | reyssat | 494 | { |
495 | char vbuf[MAX_LINELEN+1]; |
||
496 | snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf); |
||
497 | if(deftag) repsubst(vbuf); |
||
498 | prepcnt=0; parmprep(vbuf, pt_real); |
||
8367 | bpr | 499 | switch(type) { |
500 | case 0: fprintf(outf,"!if %s \n",vbuf); break; |
||
501 | case 1: fprintf(outf,"!ifval %s \n",vbuf); |
||
502 | } |
||
10 | reyssat | 503 | } |
8367 | bpr | 504 | void p_if(char *p[MAX_PARM]) { return _p_if(p, 0);} |
505 | void p_ifval(char *p[MAX_PARM]) { return _p_if(p, 1);} |
||
10 | reyssat | 506 | |
507 | void p_else(char *p[MAX_PARM]) |
||
508 | { |
||
509 | fprintf(outf,"!else\n"); |
||
510 | } |
||
511 | |||
512 | void p_endif(char *p[MAX_PARM]) |
||
513 | { |
||
514 | fprintf(outf,"!endif\n"); |
||
515 | } |
||
516 | |||
517 | |||
518 | void p_while(char *p[MAX_PARM]) |
||
519 | { |
||
520 | char vbuf[MAX_LINELEN+1]; |
||
521 | snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf); |
||
522 | if(deftag) repsubst(vbuf); |
||
523 | prepcnt=0; parmprep(vbuf, pt_real); |
||
524 | fprintf(outf,"!while %s \n",vbuf); |
||
525 | } |
||
526 | |||
527 | void p_endwhile(char *p[MAX_PARM]) |
||
528 | { |
||
529 | fprintf(outf,"!endwhile\n"); |
||
530 | } |
||
531 | |||
532 | void p_for(char *p[MAX_PARM]) |
||
533 | { |
||
534 | char *p1, *p2, buf[256]; |
||
535 | char vbuf[MAX_LINELEN+1]; |
||
536 | int i; |
||
537 | |||
538 | p1=find_word_start(p[0]); |
||
539 | if(!isalpha(*p1)) return; |
||
540 | for(p2=p1; isalnum(*p2); p2++); |
||
541 | if(p2-p1>64) return; |
||
542 | memmove(buf,p1,p2-p1); buf[p2-p1]=0; |
||
543 | for(i=1;i<varcnt && strcmp(buf,param[i].name)!=0;i++); |
||
544 | if(i>=varcnt && i<MAX_PARAM) { |
||
7677 | bpr | 545 | param[varcnt].name=p1; |
546 | param[varcnt].type=pt_real; |
||
547 | param[varcnt].save=0; |
||
548 | varcnt++; |
||
10 | reyssat | 549 | } |
550 | snprintf(vbuf,sizeof(vbuf),"%s",p2); subst(vbuf); *p2=0; |
||
551 | if(deftag) repsubst(vbuf); |
||
552 | prepcnt=0; parmprep(vbuf, pt_real); |
||
553 | fprintf(outf,"!for val%d %s \n", i, vbuf); |
||
554 | } |
||
555 | |||
556 | void p_next(char *p[MAX_PARM]) |
||
557 | { |
||
558 | fprintf(outf,"!next\n"); |
||
559 | } |
||
560 | |||
561 | void p_plot(char *p[MAX_PARM]) |
||
562 | { |
||
563 | int i, f, xr, yr; |
||
564 | char *pp, *p2; |
||
565 | char buf[MAX_LINELEN+1]; |
||
7677 | bpr | 566 | f=xr=yr=-1; |
10 | reyssat | 567 | for(i=0;i<3;i++) { |
7677 | bpr | 568 | if(*p[i]==0) continue; |
569 | if((pp=strchr(p[i],'='))==NULL) f=i; |
||
570 | else { |
||
571 | *pp=0; pp++; |
||
572 | p2=find_word_start(p[i]); |
||
573 | if(*p2=='x' || *p2=='X') xr=i; |
||
574 | else if (*p2=='y' || *p2=='Y') yr=i; |
||
575 | ovlstrcpy(p[i],pp); |
||
576 | } |
||
10 | reyssat | 577 | } |
578 | /* if(xr>=0 && (pp=strstr(p[xr],".."))!=NULL) { |
||
7677 | bpr | 579 | |
10 | reyssat | 580 | } |
581 | */ if(f<0) return; |
||
3718 | reyssat | 582 | ovlstrcpy(buf, p[f]); |
10 | reyssat | 583 | prepcnt=0; parmprep(buf,pt_func); |
584 | fprintf(outf,"plot_fn=!rawmath %s\n",buf); |
||
7677 | bpr | 585 | |
10 | reyssat | 586 | } |
587 | |||
588 | void p_condition(char *p[MAX_PARM]) |
||
589 | { |
||
590 | int i,j; |
||
591 | char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1]; |
||
592 | for(i=0;i<5;i++) { |
||
7677 | bpr | 593 | if(p[i]==NULL || p[i][0]==0) continue; |
594 | p[i]=find_word_start(p[i]); |
||
595 | if(strncasecmp(p[i],"option",strlen("option"))==0) { |
||
596 | char *tt, *tv; |
||
597 | tt=p[i]+strlen("option"); |
||
598 | if(*tt=='s' || *tt=='S') tt++; |
||
599 | tt=find_word_start(tt); |
||
600 | if(*tt=='=') { |
||
601 | for(j=i;j<6;j++) p[j]=p[j+1]; i--; |
||
602 | snprintf(buf1,sizeof(buf1),"%s",tt+1); subst(buf1); |
||
603 | for(tv=buf1; *tv; tv++) if(*tv==',' || *tv==';') *tv=' '; |
||
604 | strip_trailing_spaces(buf1); |
||
605 | fprintf(outf,"condoption%d=%s \n",conditioncnt, |
||
606 | find_word_start(buf1)); |
||
607 | } |
||
608 | continue; |
||
609 | } |
||
610 | if(strncasecmp(p[i],"weight",strlen("weight"))==0) { |
||
611 | char *tt; |
||
612 | tt=p[i]+strlen("weight"); |
||
613 | tt=find_word_start(tt); |
||
614 | if(*tt=='=') { |
||
615 | for(j=i;j<6;j++) p[j]=p[j+1]; i--; |
||
616 | snprintf(buf1,sizeof(buf1),"%s",tt+1); subst(buf1); |
||
617 | strip_trailing_spaces(buf1); |
||
618 | fprintf(outf,"condweight%d=%s \n",conditioncnt, |
||
619 | find_word_start(buf1)); |
||
620 | } |
||
621 | continue; |
||
622 | } |
||
10 | reyssat | 623 | } |
624 | if(p[1][0]==0) {p[1]=p[0]; p[0]="";} |
||
625 | snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1); |
||
626 | snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2); |
||
627 | prepcnt=0; parmprep(buf2, pt_real); |
||
628 | repsubst(buf2); |
||
629 | fprintf(outf,"\n!ifval %s\n condtest%d=1\n!else\n condtest%d=0\n!endif\n\ |
||
630 | condname%d=%s\n", buf2,conditioncnt,conditioncnt,conditioncnt,buf1); |
||
631 | conditioncnt++; |
||
632 | } |
||
633 | |||
634 | void p_conditions(char *p[MAX_PARM]) |
||
635 | { |
||
636 | char buf[MAX_LINELEN+1]; |
||
637 | snprintf(buf,sizeof(buf),"%s",p[0]); subst(buf); |
||
638 | prepcnt=0; parmprep(buf, pt_real); |
||
639 | repsubst(buf); |
||
640 | fprintf(outf,"\ncondlist=%s\n",buf); |
||
641 | } |
||
642 | |||
643 | void p_feedback(char *p[MAX_PARM]) |
||
644 | { |
||
645 | char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1]; |
||
646 | char *cmpstr="ifval"; |
||
7677 | bpr | 647 | |
10 | reyssat | 648 | snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1); |
649 | snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2); |
||
650 | repsubst(buf1); repsubst(buf2); |
||
651 | if(strstr(buf1,"$m_choice")!=NULL) cmpstr="if"; |
||
652 | prepcnt=0; setpre="!set "; parmprep(buf1, pt_real); setpre=""; |
||
6450 | obado | 653 | fprintf(outf,"!%s %s\n <div class='oef_feedbacks'>",cmpstr, buf1); |
10 | reyssat | 654 | out_exec(buf2,NULL); |
6450 | obado | 655 | fprintf(outf,"</div>\n!endif\n"); |
10 | reyssat | 656 | } |
657 | |||
7677 | bpr | 658 | /* definition of steps */ |
10 | reyssat | 659 | void p_steps(char *p[MAX_PARM]) |
660 | { |
||
661 | char vbuf[MAX_LINELEN+1]; |
||
662 | char *pp, *p2; |
||
7677 | bpr | 663 | |
10 | reyssat | 664 | snprintf(vbuf,sizeof(vbuf),"%s",find_word_start(p[0])); subst(vbuf); |
665 | strip_trailing_spaces(vbuf); |
||
666 | if(vbuf[0]==0) return; |
||
667 | if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') { |
||
7677 | bpr | 668 | char buf[MAX_LINELEN+1]; |
669 | if(check_compare(vbuf)==0) goto noif; |
||
670 | p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0; |
||
671 | snprintf(buf,sizeof(buf),"%s",vbuf); |
||
672 | prepcnt=0; parmprep(buf,pt_text); |
||
673 | fprintf(outf,"\n!ifval %s \n",buf); |
||
674 | snprintf(buf,sizeof(buf),"%s",pp); |
||
675 | parmprep(buf,pt_text); |
||
676 | fprintf(outf,"oefsteps=%s \n",buf); |
||
677 | if(p2!=NULL) { |
||
678 | fprintf(outf,"!else\n"); |
||
679 | snprintf(buf,sizeof(buf),"%s",p2); |
||
680 | parmprep(buf,pt_text); |
||
681 | fprintf(outf,"oefsteps=%s \n",buf); |
||
682 | } |
||
683 | fprintf(outf,"!endif\n"); |
||
10 | reyssat | 684 | } |
685 | else { |
||
686 | noif: |
||
7677 | bpr | 687 | prepcnt=0; parmprep(vbuf, pt_text); |
688 | fprintf(outf,"oefsteps=%s \nnextstep=!nosubst %s \n",vbuf,vbuf); |
||
10 | reyssat | 689 | } |
690 | fprintf(outf,"!readproc oef/steps.proc\n"); |
||
691 | } |
||
692 | |||
7677 | bpr | 693 | /* dynamic steps */ |
10 | reyssat | 694 | void p_nextstep(char *p[MAX_PARM]) |
695 | { |
||
696 | fprintf(outf,"dynsteps=yes\n"); |
||
697 | p_steps(p); |
||
698 | } |
||
699 |