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