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