Rev 12122 | Rev 13590 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 12122 | Rev 12247 | ||
---|---|---|---|
Line 226... | Line 226... | ||
226 | 226 | ||
227 | #define anstype_no (sizeof(anstype)/sizeof(anstype[0])) |
227 | #define anstype_no (sizeof(anstype)/sizeof(anstype[0])) |
228 | 228 | ||
229 | void p_answer(char *p[MAX_PARM]) |
229 | void p_answer(char *p[MAX_PARM]) |
230 | { |
230 | { |
231 |
|
231 | char *pp, vbuf[MAX_LINELEN+1],nbuf[MAX_LINELEN+1]; |
232 |
|
232 | int i,j,k,typ; |
233 | 233 | ||
234 | /* look for type definition */ |
234 | /* look for type definition */ |
235 |
|
235 | typ=typ_default; |
236 |
|
236 | for(i=0;i<5;i++) { |
237 |
|
237 | if(p[i]==NULL || p[i][0]==0) continue; |
238 |
|
238 | p[i]=find_word_start(p[i]); |
239 |
|
239 | if(strncasecmp(p[i],"type",strlen("type"))==0) { |
240 |
|
240 | char *tt; |
241 |
|
241 | tt=find_word_start(p[i]+strlen("type")); |
242 |
|
242 | if(*tt=='=') { |
243 |
|
243 | for(j=i;j<6;j++) p[j]=p[j+1]; |
244 |
|
244 | i--; |
245 |
|
245 | tt=find_word_start(tt+1); *find_word_end(tt)=0; |
246 |
|
246 | k=search_list(anstype,anstype_no,sizeof(anstype[0]),tt); |
247 | /* unknown type is now substituted */ |
247 | /* unknown type is now substituted */ |
248 |
|
248 | if(k>=0) { |
249 |
|
249 | fprintf(outf,"replytype%d=%s\n", |
250 | answercnt,anstype[k].def); |
250 | answercnt,anstype[k].def); |
251 |
|
251 | typ=anstype[k].type; |
252 |
|
252 | } |
253 |
|
253 | else { |
254 |
|
254 | snprintf(nbuf,sizeof(nbuf),"%s",tt); subst(nbuf); |
255 |
|
255 | fprintf(outf,"replytype%d=%s\n\n",answercnt,nbuf); |
256 | } |
- | |
257 |
|
256 | } |
258 | continue; |
- | |
259 | } |
257 | } |
- | 258 | continue; |
|
- | 259 | } |
|
260 |
|
260 | if(strncasecmp(p[i],"option",strlen("option"))==0) { |
261 |
|
261 | char *tt, *tv; |
262 |
|
262 | tt=p[i]+strlen("option"); |
263 |
|
263 | if(*tt=='s' || *tt=='S') tt++; |
264 |
|
264 | tt=find_word_start(tt); |
265 |
|
265 | if(*tt=='=') { |
266 |
|
266 | for(j=i;j<6;j++) p[j]=p[j+1]; |
267 |
|
267 | i--; |
268 |
|
268 | snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf); |
269 |
|
269 | for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' '; |
270 |
|
270 | strip_trailing_spaces(nbuf); |
271 |
|
271 | fprintf(outf,"replyoption%d=%s \n",answercnt, |
272 | find_word_start(nbuf)); |
- | |
273 | } |
- | |
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 |
|
272 | find_word_start(nbuf)); |
287 | } |
- | |
288 | continue; |
- | |
289 | } |
273 | } |
- | 274 | continue; |
|
290 | } |
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)); |
|
- | 287 | } |
|
- | 288 | continue; |
|
- | 289 | } |
|
- | 290 | } |
|
291 |
|
291 | p[0]=find_word_start(p[0]); |
292 |
|
292 | strncpy(nbuf,p[0],MAX_LINELEN); nbuf[MAX_LINELEN]=0; subst(nbuf); |
293 |
|
293 | strip_trailing_spaces(nbuf);singlespace(nbuf); |
294 |
|
294 | if (strlen(nbuf)>= MAX_PROMPTLEN) oef_error("Answer prompt too long"); |
295 |
|
295 | nbuf[MAX_PROMPTLEN]=0; |
296 |
|
296 | pp=nbuf+strlen(nbuf)-1; |
297 |
|
297 | if(*pp=='=') *pp=0; |
298 |
|
298 | p[1]=find_word_start(p[1]); |
299 |
|
299 | if(*p[1]=='\\' && (isalnum(*(p[1]+1)) || *(p[1]+1)=='_')) { |
300 | /* check for analyzed answers */ |
300 | /* check for analyzed answers */ |
301 |
|
301 | int i,n; char *pt; |
302 |
|
302 | strncpy(vbuf,p[1]+1,MAX_LINELEN); vbuf[MAX_LINELEN]=0; |
303 |
|
303 | pt=strchr(vbuf,';'); if(pt!=NULL) *pt=0; |
304 |
|
304 | strip_trailing_spaces(vbuf); n=strlen(vbuf); |
305 |
|
305 | if(n>=MAX_NAMELEN) goto normal; |
306 |
|
306 | for(i=0;i<n && (isalnum(vbuf[i]) || vbuf[i]=='_');i++); |
307 |
|
307 | if(i<n) goto normal; |
308 |
|
308 | for(i=varcnt-1;i>=1 && strcmp(vbuf,param[i].name)!=0;i--); |
309 |
|
309 | if(i<1) { /* unused name; the answer should be analyzed */ |
310 |
|
310 | char *pm; |
311 |
|
311 | pm=xmalloc(MAX_NAMELEN+2); |
312 |
|
312 | ovlstrcpy(pm,vbuf); param[varcnt].name=pm; |
313 |
|
313 | if(pt) { |
314 |
|
314 | *pt=';'; |
315 |
|
315 | ovlstrcpy(vbuf,pt); subst(vbuf); pt=vbuf; |
316 | } |
- | |
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; |
- | |
323 | } |
316 | } |
- | 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; |
|
324 | } |
323 | } |
- | 324 | } |
|
325 |
|
325 | normal: |
326 |
|
326 | strncpy(vbuf,p[1],MAX_LINELEN); vbuf[MAX_LINELEN]=0; |
327 |
|
327 | subst(vbuf); |
328 |
|
328 | switch(typ) { |
329 |
|
329 | default: |
330 |
|
330 | case typ_default: { |
331 |
|
331 | fprintf(outf,"replyname%d=%s\nreplygood%d=%s\n", |
332 |
|
332 | answercnt,nbuf,answercnt,vbuf); |
333 |
|
333 | break; |
334 |
|
334 | } |
335 |
|
335 | case typ_num: { |
336 |
|
336 | fprintf(outf,"replyname%d=%s\nreplygood%d=$[%s]\n", |
337 |
|
337 | answercnt,nbuf,answercnt,vbuf); |
338 |
|
338 | break; |
339 |
|
339 | } |
340 |
|
340 | case typ_equation: |
341 |
|
341 | case typ_func: { |
342 |
|
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", |
|
343 | answercnt,nbuf,answercnt,vbuf); |
348 | answercnt,nbuf,answercnt,vbuf); |
344 |
|
349 | break; |
345 | } |
- | |
346 | case typ_units: { |
- | |
347 | fprintf(outf,"replyname%d=%s\nreplygood%d=%s\n", |
- | |
348 | answercnt,nbuf,answercnt,vbuf); |
- | |
349 | break; |
- | |
350 | } |
- | |
351 | } |
350 | } |
- | 351 | } |
|
352 |
|
352 | answercnt++; |
353 | } |
353 | } |
354 | 354 | ||
355 | void p_choice(char *p[MAX_PARM]) |
355 | void p_choice(char *p[MAX_PARM]) |
356 | { |
356 | { |
357 |
|
357 | int i,j; |
358 |
|
358 | char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1],nbuf[MAX_LINELEN+1]; |
359 |
|
359 | for(i=0;i<5;i++) { |
360 |
|
360 | if(p[i]==NULL || p[i][0]==0) continue; |
361 |
|
361 | p[i]=find_word_start(p[i]); |
362 |
|
362 | if(strncasecmp(p[i],"option",strlen("option"))==0) { |
363 |
|
363 | char *tt, *tv; |
364 |
|
364 | tt=p[i]+strlen("option"); |
365 |
|
365 | if(*tt=='s' || *tt=='S') tt++; |
366 |
|
366 | tt=find_word_start(tt); |
367 |
|
367 | if(*tt=='=') { |
368 |
|
368 | for(j=i;j<6;j++) p[j]=p[j+1]; |
369 |
|
369 | i--; |
370 |
|
370 | snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf); |
371 |
|
371 | for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' '; |
372 |
|
372 | strip_trailing_spaces(nbuf); |
373 |
|
373 | fprintf(outf,"choiceoption%d=%s \n",choicecnt, |
374 | find_word_start(nbuf)); |
- | |
375 | } |
- | |
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 |
|
374 | find_word_start(nbuf)); |
389 | } |
- | |
390 | continue; |
- | |
391 | } |
375 | } |
- | 376 | continue; |
|
392 | } |
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)); |
|
- | 389 | } |
|
- | 390 | continue; |
|
- | 391 | } |
|
- | 392 | } |
|
393 |
|
393 | p[0]=find_word_start(p[0]); |
394 |
|
394 | snprintf(buf1,sizeof(buf1),"%s",p[1]); subst(buf1); |
395 |
|
395 | snprintf(buf2,sizeof(buf2),"%s",p[2]); subst(buf2); |
396 |
|
396 | snprintf(nbuf,sizeof(nbuf),"%s",p[0]); subst(nbuf); |
397 |
|
397 | nbuf[MAX_PROMPTLEN]=0; |
398 |
|
398 | fprintf(outf,"choicename%d=%s\nchoicegood%d=%s\nchoicebad%d=%s\n", |
399 |
|
399 | choicecnt,nbuf,choicecnt,buf1,choicecnt,buf2); |
400 |
|
400 | choicecnt++; |
401 | } |
401 | } |
402 | 402 | ||
403 | void putval(char *p, int n, int ptype) |
403 | void putval(char *p, int n, int ptype) |
404 | { |
404 | { |
405 |
|
405 | switch(ptype) { |
406 |
|
406 | case pt_int: { |
407 |
|
407 | fprintf(outf,"val%d=$[rint(%s)]\n",n,p); |
408 |
|
408 | break; |
409 |
|
409 | } |
410 |
|
410 | case pt_real: { |
411 |
|
411 | fprintf(outf,"val%d=$[%s]\n",n,p); |
412 |
|
412 | break; |
413 |
|
413 | } |
414 |
|
414 | case pt_func: { |
415 |
|
415 | fprintf(outf,"val%d=!rawmath %s\n",n,p); |
416 |
|
416 | break; |
417 |
|
417 | } |
418 |
|
418 | case pt_complex: { |
419 |
|
419 | fprintf(outf,"t_=!rawmath %s\nt_=!exec pari print($t_)\n\ |
420 | val%d=!mathsubst I=i in $t_\n",p,n); |
420 | val%d=!mathsubst I=i in $t_\n",p,n); |
421 |
|
421 | break; |
422 |
|
422 | } |
423 |
|
423 | case pt_matrix: { |
424 |
|
424 | fprintf(outf,"tmp=!trim %s\n\ |
425 | val%d=!translate internal $ \\\n$ to ;; in $tmp\n",p,n); |
425 | val%d=!translate internal $ \\\n$ to ;; in $tmp\n",p,n); |
426 |
|
426 | break; |
427 |
|
427 | } |
428 |
|
428 | case pt_rat: { |
429 |
|
429 | fprintf(outf,"t_=!rawmath %s\n\ |
430 | val%d=!exec pari print($t_)\n",p,n); |
430 | val%d=!exec pari print($t_)\n",p,n); |
431 |
|
431 | break; |
432 |
|
432 | } |
433 |
|
433 | default: { |
434 |
|
434 | fprintf(outf,"val%d=%s\n",n,p); |
435 |
|
435 | break; |
436 |
|
436 | } |
437 |
|
437 | } |
438 | } |
438 | } |
439 | 439 | ||
440 | void parm(char *p[MAX_PARM], int ptype) |
440 | void parm(char *p[MAX_PARM], int ptype) |
441 | { |
441 | { |
442 |
|
442 | char *pp, *p2; |
443 |
|
443 | char vbuf[MAX_LINELEN+1]; |
444 |
|
444 | int i; |
445 | 445 | ||
446 |
|
446 | p[0]=find_word_start(p[0]); |
447 |
|
447 | if(*p[0]=='\\') p[0]++; |
448 | /* bad name */ |
448 | /* bad name */ |
449 |
|
449 | if(!isalpha(*p[0])) return; |
450 |
|
450 | strip_trailing_spaces(p[0]); |
451 |
|
451 | for(pp=p[0];*pp;pp++) if(!isalnum(*pp) && *pp!='_') { |
452 | /* bad name and security risk */ |
452 | /* bad name and security risk */ |
453 |
|
453 | if(!isspace(*pp)) return; |
454 |
|
454 | ovlstrcpy(pp,pp+1); pp--; |
455 |
|
455 | } |
456 |
|
456 | for(i=1;i<varcnt && strcmp(p[0],param[i].name)!=0;i++); |
457 |
|
457 | p[1]=find_word_start(p[1]); |
458 |
|
458 | snprintf(vbuf,sizeof(vbuf),"%s",p[1]); subst(vbuf); |
459 |
|
459 | if(deftag) repsubst(vbuf); |
460 |
|
460 | if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') { |
461 |
|
461 | char buf[MAX_LINELEN+1]; |
462 |
|
462 | if(check_compare(vbuf)==0) goto noif; |
463 |
|
463 | p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0; |
464 |
|
464 | snprintf(buf,sizeof(buf),"%s",vbuf); |
465 |
|
465 | prepcnt=0; parmprep(buf,ptype); |
466 |
|
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"); |
|
467 | snprintf(buf,sizeof(buf),"%s", |
471 | snprintf(buf,sizeof(buf),"%s",p2); |
468 | parmprep(buf,ptype); putval(buf,i,ptype); |
472 | parmprep(buf,ptype); putval(buf,i,ptype); |
469 | if(p2!=NULL) { |
- | |
470 | fprintf(outf,"!else\n"); |
- | |
471 | snprintf(buf,sizeof(buf),"%s",p2); |
- | |
472 | parmprep(buf,ptype); putval(buf,i,ptype); |
- | |
473 |
|
473 | } |
474 |
|
474 | fprintf(outf,"!endif\n"); |
475 |
|
475 | } |
476 |
|
476 | else { |
477 | noif: |
477 | noif: |
478 |
|
478 | prepcnt=0; parmprep(vbuf, ptype); |
479 |
|
479 | putval(vbuf,i,ptype); |
480 |
|
480 | } |
481 |
|
481 | if(i>=varcnt && i<MAX_PARAM) { |
482 |
|
482 | param[varcnt].name=p[0]; |
483 |
|
483 | param[varcnt].type=ptype; |
484 |
|
484 | param[varcnt].save=0; |
485 |
|
485 | varcnt++; |
486 |
|
486 | } |
487 | } |
487 | } |
488 | 488 | ||
489 | void p_int(char *p[MAX_PARM]) {parm(p,pt_int);} |
489 | void p_int(char *p[MAX_PARM]) {parm(p,pt_int);} |
490 | void p_rational(char *p[MAX_PARM]) {parm(p,pt_rat);} |
490 | void p_rational(char *p[MAX_PARM]) {parm(p,pt_rat);} |
491 | void p_real(char *p[MAX_PARM]) {parm(p,pt_real);} |
491 | void p_real(char *p[MAX_PARM]) {parm(p,pt_real);} |
Line 499... | Line 499... | ||
499 | parm(p,pt_real); |
499 | parm(p,pt_real); |
500 | } |
500 | } |
501 | 501 | ||
502 | void _p_if(char *p[MAX_PARM], int type) |
502 | void _p_if(char *p[MAX_PARM], int type) |
503 | { |
503 | { |
504 |
|
504 | char vbuf[MAX_LINELEN+1]; |
505 |
|
505 | snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf); |
506 |
|
506 | if(deftag) repsubst(vbuf); |
507 |
|
507 | prepcnt=0; parmprep(vbuf, pt_real); |
508 |
|
508 | switch(type) { |
509 |
|
509 | case 0: fprintf(outf,"!if %s \n",vbuf); break; |
510 |
|
510 | case 1: fprintf(outf,"!ifval %s \n",vbuf); |
511 |
|
511 | } |
512 | } |
512 | } |
513 | void p_if(char *p[MAX_PARM]) { return _p_if(p, 0);} |
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);} |
514 | void p_ifval(char *p[MAX_PARM]) { return _p_if(p, 1);} |
515 | 515 | ||
516 | void p_else(char *p[MAX_PARM]) |
516 | void p_else(char *p[MAX_PARM]) |
517 | { |
517 | { |
518 |
|
518 | fprintf(outf,"!else\n"); |
519 | } |
519 | } |
520 | 520 | ||
521 | void p_endif(char *p[MAX_PARM]) |
521 | void p_endif(char *p[MAX_PARM]) |
522 | { |
522 | { |
523 |
|
523 | fprintf(outf,"!endif\n"); |
524 | } |
- | |
525 | - | ||
526 | - | ||
527 | void p_while(char *p[MAX_PARM]) |
- | |
528 | { |
- | |
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); |
- | |
534 | } |
524 | } |
- | 525 | ||
535 | 526 | ||
536 | void |
527 | void p_while(char *p[MAX_PARM]) |
537 | { |
528 | { |
- | 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); |
|
538 |
|
533 | fprintf(outf,"!while %s \n",vbuf); |
539 | } |
534 | } |
540 | 535 | ||
- | 536 | void p_endwhile(char *p[MAX_PARM]) |
|
- | 537 | { |
|
- | 538 | fprintf(outf,"!endwhile\n"); |
|
- | 539 | } |
|
- | 540 | ||
541 | void p_for(char *p[MAX_PARM]) |
541 | void p_for(char *p[MAX_PARM]) |
542 | { |
542 | { |
543 |
|
543 | char *p1, *p2, buf[256]; |
544 |
|
544 | char vbuf[MAX_LINELEN+1]; |
545 |
|
545 | int i; |
546 | 546 | ||
547 |
|
547 | p1=find_word_start(p[0]); |
548 |
|
548 | if(!isalpha(*p1)) return; |
549 |
|
549 | for(p2=p1; isalnum(*p2); p2++); |
550 |
|
550 | if(p2-p1>64) return; |
551 |
|
551 | memmove(buf,p1,p2-p1); buf[p2-p1]=0; |
552 |
|
552 | for(i=1;i<varcnt && strcmp(buf,param[i].name)!=0;i++); |
553 |
|
553 | if(i>=varcnt && i<MAX_PARAM) { |
554 |
|
554 | param[varcnt].name=p1; |
555 |
|
555 | param[varcnt].type=pt_real; |
556 |
|
556 | param[varcnt].save=0; |
557 |
|
557 | varcnt++; |
558 |
|
558 | } |
559 |
|
559 | snprintf(vbuf,sizeof(vbuf),"%s",p2); subst(vbuf); *p2=0; |
560 |
|
560 | if(deftag) repsubst(vbuf); |
561 |
|
561 | prepcnt=0; parmprep(vbuf, pt_real); |
562 |
|
562 | fprintf(outf,"!for val%d %s \n", i, vbuf); |
563 | } |
563 | } |
564 | 564 | ||
565 | void p_next(char *p[MAX_PARM]) |
565 | void p_next(char *p[MAX_PARM]) |
566 | { |
566 | { |
567 |
|
567 | fprintf(outf,"!next\n"); |
568 | } |
568 | } |
569 | 569 | ||
570 | void p_plot(char *p[MAX_PARM]) |
570 | void p_plot(char *p[MAX_PARM]) |
571 | { |
571 | { |
572 |
|
572 | int i, f, xr, yr; |
573 |
|
573 | char *pp, *p2; |
574 |
|
574 | char buf[MAX_LINELEN+1]; |
575 |
|
575 | f=xr=yr=-1; |
576 |
|
576 | for(i=0;i<3;i++) { |
577 |
|
577 | if(*p[i]==0) continue; |
578 |
|
578 | if((pp=strchr(p[i],'='))==NULL) f=i; |
579 |
|
579 | else { |
580 |
|
580 | *pp=0; pp++; |
581 |
|
581 | p2=find_word_start(p[i]); |
582 |
|
582 | if(*p2=='x' || *p2=='X') xr=i; |
583 |
|
583 | else if (*p2=='y' || *p2=='Y') yr=i; |
584 |
|
584 | ovlstrcpy(p[i],pp); |
585 |
|
585 | } |
586 |
|
586 | } |
587 | /* if(xr>=0 && (pp=strstr(p[xr],".."))!=NULL) { |
587 | /* if(xr>=0 && (pp=strstr(p[xr],".."))!=NULL) { |
588 | 588 | ||
589 | } |
589 | } |
590 | */ if(f<0) return; |
590 | */ if(f<0) return; |
591 |
|
591 | ovlstrcpy(buf, p[f]); |
592 |
|
592 | prepcnt=0; parmprep(buf,pt_func); |
593 |
|
593 | fprintf(outf,"plot_fn=!rawmath %s\n",buf); |
594 | 594 | ||
595 | } |
595 | } |
596 | 596 | ||
597 | void p_condition(char *p[MAX_PARM]) |
597 | void p_condition(char *p[MAX_PARM]) |
598 | { |
598 | { |
599 |
|
599 | int i,j; |
600 |
|
600 | char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1]; |
601 |
|
601 | for(i=0;i<5;i++) { |
602 |
|
602 | if(p[i]==NULL || p[i][0]==0) continue; |
603 |
|
603 | p[i]=find_word_start(p[i]); |
604 |
|
604 | if(strncasecmp(p[i],"option",strlen("option"))==0) { |
605 |
|
605 | char *tt, *tv; |
606 |
|
606 | tt=p[i]+strlen("option"); |
607 |
|
607 | if(*tt=='s' || *tt=='S') tt++; |
608 |
|
608 | tt=find_word_start(tt); |
609 |
|
609 | if(*tt=='=') { |
610 |
|
610 | for(j=i;j<6;j++) p[j]=p[j+1]; |
611 |
|
611 | i--; |
612 |
|
612 | snprintf(buf1,sizeof(buf1),"%s",tt+1); subst(buf1); |
613 |
|
613 | for(tv=buf1; *tv; tv++) if(*tv==',' || *tv==';') *tv=' '; |
614 |
|
614 | strip_trailing_spaces(buf1); |
615 |
|
615 | fprintf(outf,"condoption%d=%s \n",conditioncnt, |
616 | find_word_start(buf1)); |
- | |
617 | } |
- | |
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 |
|
616 | find_word_start(buf1)); |
631 | } |
- | |
632 | continue; |
- | |
633 | } |
617 | } |
- | 618 | continue; |
|
634 | } |
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)); |
|
- | 631 | } |
|
- | 632 | continue; |
|
- | 633 | } |
|
- | 634 | } |
|
635 |
|
635 | if(p[1][0]==0) {p[1]=p[0]; p[0]="";} |
636 |
|
636 | snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1); |
637 |
|
637 | snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2); |
638 |
|
638 | prepcnt=0; parmprep(buf2, pt_real); |
639 |
|
639 | repsubst(buf2); |
640 |
|
640 | fprintf(outf,"\n!ifval %s\n condtest%d=1\n!else\n condtest%d=0\n!endif\n\ |
641 | condname%d=%s\n", buf2,conditioncnt,conditioncnt,conditioncnt,buf1); |
641 | condname%d=%s\n", buf2,conditioncnt,conditioncnt,conditioncnt,buf1); |
642 | conditioncnt++; |
642 | conditioncnt++; |
643 | } |
643 | } |
644 | 644 | ||
645 | void p_conditions(char *p[MAX_PARM]) |
645 | void p_conditions(char *p[MAX_PARM]) |
646 | { |
646 | { |
647 |
|
647 | char buf[MAX_LINELEN+1]; |
648 |
|
648 | snprintf(buf,sizeof(buf),"%s",p[0]); subst(buf); |
649 |
|
649 | prepcnt=0; parmprep(buf, pt_real); |
650 |
|
650 | repsubst(buf); |
651 |
|
651 | fprintf(outf,"\ncondlist=%s\n",buf); |
652 | } |
652 | } |
653 | 653 | ||
654 | void p_feedback(char *p[MAX_PARM]) |
654 | void p_feedback(char *p[MAX_PARM]) |
655 | { |
655 | { |
656 |
|
656 | char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1]; |
657 |
|
657 | char *cmpstr="ifval"; |
658 | 658 | ||
659 |
|
659 | snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1); |
660 |
|
660 | snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2); |
661 |
|
661 | repsubst(buf1); repsubst(buf2); |
662 |
|
662 | if(strstr(buf1,"$m_choice")!=NULL) cmpstr="if"; |
663 |
|
663 | prepcnt=0; setpre="!set "; parmprep(buf1, pt_real); setpre=""; |
664 |
|
664 | fprintf(outf,"!%s %s\n <div class='oef_feedbacks'>",cmpstr, buf1); |
665 |
|
665 | out_exec(buf2,NULL); |
666 |
|
666 | fprintf(outf,"</div>\n!endif\n"); |
667 | } |
667 | } |
668 | 668 | ||
669 | /* definition of steps */ |
669 | /* definition of steps */ |
670 | void p_steps(char *p[MAX_PARM]) |
670 | void p_steps(char *p[MAX_PARM]) |
671 | { |
671 | { |
672 |
|
672 | char vbuf[MAX_LINELEN+1]; |
673 |
|
673 | char *pp, *p2; |
674 | 674 | ||
675 |
|
675 | snprintf(vbuf,sizeof(vbuf),"%s",find_word_start(p[0])); subst(vbuf); |
676 |
|
676 | strip_trailing_spaces(vbuf); |
677 |
|
677 | if(vbuf[0]==0) return; |
678 |
|
678 | if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') { |
679 |
|
679 | char buf[MAX_LINELEN+1]; |
680 |
|
680 | if(check_compare(vbuf)==0) goto noif; |
681 |
|
681 | p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0; |
682 |
|
682 | snprintf(buf,sizeof(buf),"%s",vbuf); |
683 |
|
683 | prepcnt=0; parmprep(buf,pt_text); |
684 |
|
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"); |
|
685 | snprintf(buf,sizeof(buf),"%s", |
690 | snprintf(buf,sizeof(buf),"%s",p2); |
686 | parmprep(buf,pt_text); |
691 | parmprep(buf,pt_text); |
687 | fprintf(outf,"oefsteps=%s \n",buf); |
692 | fprintf(outf,"oefsteps=%s \n",buf); |
688 | if(p2!=NULL) { |
- | |
689 | fprintf(outf,"!else\n"); |
- | |
690 | snprintf(buf,sizeof(buf),"%s",p2); |
- | |
691 | parmprep(buf,pt_text); |
- | |
692 | fprintf(outf,"oefsteps=%s \n",buf); |
- | |
693 |
|
693 | } |
694 |
|
694 | fprintf(outf,"!endif\n"); |
695 |
|
695 | } |
696 |
|
696 | else { |
697 | noif: |
697 | noif: |
698 |
|
698 | prepcnt=0; parmprep(vbuf, pt_text); |
699 |
|
699 | fprintf(outf,"oefsteps=%s \nnextstep=!nosubst %s \n",vbuf,vbuf); |
700 |
|
700 | } |
701 |
|
701 | fprintf(outf,"!readproc oef/steps.proc\n"); |
702 | } |
702 | } |
703 | 703 | ||
704 | /* dynamic steps */ |
704 | /* dynamic steps */ |
705 | void p_nextstep(char *p[MAX_PARM]) |
705 | void p_nextstep(char *p[MAX_PARM]) |
706 | { |
706 | { |
707 |
|
707 | fprintf(outf,"dynsteps=yes\n"); |
708 |
|
708 | p_steps(p); |
709 | } |
709 | } |
710 | - |