Subversion Repositories wimsdev

Rev

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
    char *pp, vbuf[MAX_LINELEN+1],nbuf[MAX_LINELEN+1];
231
  char *pp, vbuf[MAX_LINELEN+1],nbuf[MAX_LINELEN+1];
232
    int i,j,k,typ;
232
  int i,j,k,typ;
233
 
233
 
234
/* look for type definition */
234
/* look for type definition */
235
    typ=typ_default;
235
  typ=typ_default;
236
    for(i=0;i<5;i++) {
236
  for(i=0;i<5;i++) {
237
      if(p[i]==NULL || p[i][0]==0) continue;
237
    if(p[i]==NULL || p[i][0]==0) continue;
238
      p[i]=find_word_start(p[i]);
238
    p[i]=find_word_start(p[i]);
239
      if(strncasecmp(p[i],"type",strlen("type"))==0) {
239
    if(strncasecmp(p[i],"type",strlen("type"))==0) {
240
          char *tt;
240
      char *tt;
241
          tt=find_word_start(p[i]+strlen("type"));
241
      tt=find_word_start(p[i]+strlen("type"));
242
          if(*tt=='=') {
242
      if(*tt=='=') {
243
            for(j=i;j<6;j++) p[j]=p[j+1];
243
        for(j=i;j<6;j++) p[j]=p[j+1];
244
            i--;
244
        i--;
245
            tt=find_word_start(tt+1); *find_word_end(tt)=0;
245
        tt=find_word_start(tt+1); *find_word_end(tt)=0;
246
            k=search_list(anstype,anstype_no,sizeof(anstype[0]),tt);
246
        k=search_list(anstype,anstype_no,sizeof(anstype[0]),tt);
247
/* unknown type is now substituted */
247
/* unknown type is now substituted */
248
            if(k>=0) {
248
        if(k>=0) {
249
                fprintf(outf,"replytype%d=%s\n",
249
          fprintf(outf,"replytype%d=%s\n",
250
                      answercnt,anstype[k].def);
250
                      answercnt,anstype[k].def);
251
                typ=anstype[k].type;
251
          typ=anstype[k].type;
252
            }
252
        }
253
            else {
253
        else {
254
                snprintf(nbuf,sizeof(nbuf),"%s",tt); subst(nbuf);
254
          snprintf(nbuf,sizeof(nbuf),"%s",tt); subst(nbuf);
255
                fprintf(outf,"replytype%d=%s\n\n",answercnt,nbuf);
255
          fprintf(outf,"replytype%d=%s\n\n",answercnt,nbuf);
256
            }
-
 
257
          }
256
        }
258
          continue;
-
 
259
      }
257
      }
-
 
258
      continue;
-
 
259
    }
260
      if(strncasecmp(p[i],"option",strlen("option"))==0) {
260
    if(strncasecmp(p[i],"option",strlen("option"))==0) {
261
          char *tt, *tv;
261
      char *tt, *tv;
262
          tt=p[i]+strlen("option");
262
      tt=p[i]+strlen("option");
263
          if(*tt=='s' || *tt=='S') tt++;
263
      if(*tt=='s' || *tt=='S') tt++;
264
          tt=find_word_start(tt);
264
      tt=find_word_start(tt);
265
          if(*tt=='=') {
265
      if(*tt=='=') {
266
            for(j=i;j<6;j++) p[j]=p[j+1];
266
        for(j=i;j<6;j++) p[j]=p[j+1];
267
            i--;
267
        i--;
268
            snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf);
268
        snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf);
269
            for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
269
        for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
270
            strip_trailing_spaces(nbuf);
270
        strip_trailing_spaces(nbuf);
271
            fprintf(outf,"replyoption%d=%s \n",answercnt,
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
                  find_word_start(nbuf));
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
    p[0]=find_word_start(p[0]);
291
  p[0]=find_word_start(p[0]);
292
    strncpy(nbuf,p[0],MAX_LINELEN); nbuf[MAX_LINELEN]=0; subst(nbuf);
292
  strncpy(nbuf,p[0],MAX_LINELEN); nbuf[MAX_LINELEN]=0; subst(nbuf);
293
    strip_trailing_spaces(nbuf);singlespace(nbuf);
293
  strip_trailing_spaces(nbuf);singlespace(nbuf);
294
    if (strlen(nbuf)>= MAX_PROMPTLEN) oef_error("Answer prompt too long");
294
  if (strlen(nbuf)>= MAX_PROMPTLEN) oef_error("Answer prompt too long");
295
    nbuf[MAX_PROMPTLEN]=0;
295
  nbuf[MAX_PROMPTLEN]=0;
296
    pp=nbuf+strlen(nbuf)-1;
296
  pp=nbuf+strlen(nbuf)-1;
297
    if(*pp=='=') *pp=0;
297
  if(*pp=='=') *pp=0;
298
    p[1]=find_word_start(p[1]);
298
  p[1]=find_word_start(p[1]);
299
    if(*p[1]=='\\' && (isalnum(*(p[1]+1)) || *(p[1]+1)=='_')) {
299
  if(*p[1]=='\\' && (isalnum(*(p[1]+1)) || *(p[1]+1)=='_')) {
300
/* check for analyzed answers */
300
/* check for analyzed answers */
301
      int i,n; char *pt;
301
    int i,n; char *pt;
302
      strncpy(vbuf,p[1]+1,MAX_LINELEN); vbuf[MAX_LINELEN]=0;
302
    strncpy(vbuf,p[1]+1,MAX_LINELEN); vbuf[MAX_LINELEN]=0;
303
      pt=strchr(vbuf,';'); if(pt!=NULL) *pt=0;
303
    pt=strchr(vbuf,';'); if(pt!=NULL) *pt=0;
304
      strip_trailing_spaces(vbuf); n=strlen(vbuf);
304
    strip_trailing_spaces(vbuf); n=strlen(vbuf);
305
      if(n>=MAX_NAMELEN) goto normal;
305
    if(n>=MAX_NAMELEN) goto normal;
306
      for(i=0;i<n && (isalnum(vbuf[i]) || vbuf[i]=='_');i++);
306
    for(i=0;i<n && (isalnum(vbuf[i]) || vbuf[i]=='_');i++);
307
      if(i<n) goto normal;
307
    if(i<n) goto normal;
308
      for(i=varcnt-1;i>=1 && strcmp(vbuf,param[i].name)!=0;i--);
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 */
309
    if(i<1) { /* unused name; the answer should be analyzed */
310
          char *pm;
310
      char *pm;
311
          pm=xmalloc(MAX_NAMELEN+2);
311
      pm=xmalloc(MAX_NAMELEN+2);
312
          ovlstrcpy(pm,vbuf); param[varcnt].name=pm;
312
      ovlstrcpy(pm,vbuf); param[varcnt].name=pm;
313
          if(pt) {
313
      if(pt) {
314
            *pt=';';
314
        *pt=';';
315
            ovlstrcpy(vbuf,pt); subst(vbuf); pt=vbuf;
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
    normal:
325
  normal:
326
    strncpy(vbuf,p[1],MAX_LINELEN); vbuf[MAX_LINELEN]=0;
326
  strncpy(vbuf,p[1],MAX_LINELEN); vbuf[MAX_LINELEN]=0;
327
    subst(vbuf);
327
  subst(vbuf);
328
    switch(typ) {
328
  switch(typ) {
329
      default:
329
    default:
330
      case typ_default: {
330
    case typ_default: {
331
          fprintf(outf,"replyname%d=%s\nreplygood%d=%s\n",
331
      fprintf(outf,"replyname%d=%s\nreplygood%d=%s\n",
332
                answercnt,nbuf,answercnt,vbuf);
332
              answercnt,nbuf,answercnt,vbuf);
333
          break;
333
      break;
334
      }
334
    }
335
      case typ_num: {
335
    case typ_num: {
336
          fprintf(outf,"replyname%d=%s\nreplygood%d=$[%s]\n",
336
      fprintf(outf,"replyname%d=%s\nreplygood%d=$[%s]\n",
337
                answercnt,nbuf,answercnt,vbuf);
337
              answercnt,nbuf,answercnt,vbuf);
338
          break;
338
      break;
339
      }
339
    }
340
      case typ_equation:
340
    case typ_equation:
341
      case typ_func: {
341
    case typ_func: {
342
          fprintf(outf,"replyname%d=%s\nreplygood%d=!rawmath %s\n",
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
          break;
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
    answercnt++;
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
    int i,j;
357
  int i,j;
358
    char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1],nbuf[MAX_LINELEN+1];
358
  char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1],nbuf[MAX_LINELEN+1];
359
    for(i=0;i<5;i++) {
359
  for(i=0;i<5;i++) {
360
      if(p[i]==NULL || p[i][0]==0) continue;
360
    if(p[i]==NULL || p[i][0]==0) continue;
361
      p[i]=find_word_start(p[i]);
361
    p[i]=find_word_start(p[i]);
362
      if(strncasecmp(p[i],"option",strlen("option"))==0) {
362
    if(strncasecmp(p[i],"option",strlen("option"))==0) {
363
          char *tt, *tv;
363
      char *tt, *tv;
364
          tt=p[i]+strlen("option");
364
      tt=p[i]+strlen("option");
365
          if(*tt=='s' || *tt=='S') tt++;
365
      if(*tt=='s' || *tt=='S') tt++;
366
          tt=find_word_start(tt);
366
      tt=find_word_start(tt);
367
          if(*tt=='=') {
367
      if(*tt=='=') {
368
            for(j=i;j<6;j++) p[j]=p[j+1];
368
        for(j=i;j<6;j++) p[j]=p[j+1];
369
            i--;
369
        i--;
370
            snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf);
370
        snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf);
371
            for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
371
        for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
372
            strip_trailing_spaces(nbuf);
372
        strip_trailing_spaces(nbuf);
373
            fprintf(outf,"choiceoption%d=%s \n",choicecnt,
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
                  find_word_start(nbuf));
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
    p[0]=find_word_start(p[0]);
393
  p[0]=find_word_start(p[0]);
394
    snprintf(buf1,sizeof(buf1),"%s",p[1]); subst(buf1);
394
  snprintf(buf1,sizeof(buf1),"%s",p[1]); subst(buf1);
395
    snprintf(buf2,sizeof(buf2),"%s",p[2]); subst(buf2);
395
  snprintf(buf2,sizeof(buf2),"%s",p[2]); subst(buf2);
396
    snprintf(nbuf,sizeof(nbuf),"%s",p[0]); subst(nbuf);
396
  snprintf(nbuf,sizeof(nbuf),"%s",p[0]); subst(nbuf);
397
    nbuf[MAX_PROMPTLEN]=0;
397
  nbuf[MAX_PROMPTLEN]=0;
398
    fprintf(outf,"choicename%d=%s\nchoicegood%d=%s\nchoicebad%d=%s\n",
398
  fprintf(outf,"choicename%d=%s\nchoicegood%d=%s\nchoicebad%d=%s\n",
399
          choicecnt,nbuf,choicecnt,buf1,choicecnt,buf2);
399
        choicecnt,nbuf,choicecnt,buf1,choicecnt,buf2);
400
    choicecnt++;
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
    switch(ptype) {
405
  switch(ptype) {
406
      case pt_int: {
406
    case pt_int: {
407
          fprintf(outf,"val%d=$[rint(%s)]\n",n,p);
407
      fprintf(outf,"val%d=$[rint(%s)]\n",n,p);
408
          break;
408
      break;
409
      }
409
    }
410
      case pt_real: {
410
    case pt_real: {
411
          fprintf(outf,"val%d=$[%s]\n",n,p);
411
      fprintf(outf,"val%d=$[%s]\n",n,p);
412
          break;
412
      break;
413
      }
413
    }
414
      case pt_func: {
414
    case pt_func: {
415
          fprintf(outf,"val%d=!rawmath %s\n",n,p);
415
      fprintf(outf,"val%d=!rawmath %s\n",n,p);
416
          break;
416
      break;
417
      }
417
    }
418
      case pt_complex: {
418
    case pt_complex: {
419
          fprintf(outf,"t_=!rawmath %s\nt_=!exec pari print($t_)\n\
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
          break;
421
      break;
422
      }
422
    }
423
      case pt_matrix: {
423
    case pt_matrix: {
424
          fprintf(outf,"tmp=!trim %s\n\
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
          break;
426
      break;
427
      }
427
    }
428
      case pt_rat: {
428
    case pt_rat: {
429
          fprintf(outf,"t_=!rawmath %s\n\
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
          break;
431
      break;
432
      }
432
    }
433
      default: {
433
    default: {
434
          fprintf(outf,"val%d=%s\n",n,p);
434
      fprintf(outf,"val%d=%s\n",n,p);
435
          break;
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
    char *pp, *p2;
442
  char *pp, *p2;
443
    char vbuf[MAX_LINELEN+1];
443
  char vbuf[MAX_LINELEN+1];
444
    int i;
444
  int i;
445
 
445
 
446
    p[0]=find_word_start(p[0]);
446
  p[0]=find_word_start(p[0]);
447
    if(*p[0]=='\\') p[0]++;
447
  if(*p[0]=='\\') p[0]++;
448
/* bad name */
448
/* bad name */
449
    if(!isalpha(*p[0])) return;
449
  if(!isalpha(*p[0])) return;
450
    strip_trailing_spaces(p[0]);
450
  strip_trailing_spaces(p[0]);
451
    for(pp=p[0];*pp;pp++) if(!isalnum(*pp) && *pp!='_') {
451
  for(pp=p[0];*pp;pp++) if(!isalnum(*pp) && *pp!='_') {
452
/* bad name and security risk */
452
/* bad name and security risk */
453
      if(!isspace(*pp)) return;
453
    if(!isspace(*pp)) return;
454
      ovlstrcpy(pp,pp+1); pp--;
454
    ovlstrcpy(pp,pp+1); pp--;
455
    }
455
  }
456
    for(i=1;i<varcnt && strcmp(p[0],param[i].name)!=0;i++);
456
  for(i=1;i<varcnt && strcmp(p[0],param[i].name)!=0;i++);
457
    p[1]=find_word_start(p[1]);
457
  p[1]=find_word_start(p[1]);
458
    snprintf(vbuf,sizeof(vbuf),"%s",p[1]); subst(vbuf);
458
  snprintf(vbuf,sizeof(vbuf),"%s",p[1]); subst(vbuf);
459
    if(deftag) repsubst(vbuf);
459
  if(deftag) repsubst(vbuf);
460
    if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') {
460
  if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') {
461
      char buf[MAX_LINELEN+1];
461
    char buf[MAX_LINELEN+1];
462
      if(check_compare(vbuf)==0) goto noif;
462
    if(check_compare(vbuf)==0) goto noif;
463
      p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0;
463
    p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0;
464
      snprintf(buf,sizeof(buf),"%s",vbuf);
464
    snprintf(buf,sizeof(buf),"%s",vbuf);
465
      prepcnt=0; parmprep(buf,ptype);
465
    prepcnt=0; parmprep(buf,ptype);
466
      fprintf(outf,"\n!ifval %s\n",buf);
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",pp);
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
      fprintf(outf,"!endif\n");
474
    fprintf(outf,"!endif\n");
475
    }
475
  }
476
    else {
476
  else {
477
noif:
477
noif:
478
      prepcnt=0; parmprep(vbuf, ptype);
478
    prepcnt=0; parmprep(vbuf, ptype);
479
      putval(vbuf,i,ptype);
479
    putval(vbuf,i,ptype);
480
    }
480
  }
481
    if(i>=varcnt && i<MAX_PARAM) {
481
  if(i>=varcnt && i<MAX_PARAM) {
482
      param[varcnt].name=p[0];
482
    param[varcnt].name=p[0];
483
      param[varcnt].type=ptype;
483
    param[varcnt].type=ptype;
484
      param[varcnt].save=0;
484
    param[varcnt].save=0;
485
      varcnt++;
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
    char vbuf[MAX_LINELEN+1];
504
  char vbuf[MAX_LINELEN+1];
505
    snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf);
505
  snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf);
506
    if(deftag) repsubst(vbuf);
506
  if(deftag) repsubst(vbuf);
507
    prepcnt=0; parmprep(vbuf, pt_real);
507
  prepcnt=0; parmprep(vbuf, pt_real);
508
    switch(type) {
508
  switch(type) {
509
          case 0: fprintf(outf,"!if %s \n",vbuf); break;
509
    case 0: fprintf(outf,"!if %s \n",vbuf); break;
510
          case 1: fprintf(outf,"!ifval %s \n",vbuf);
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
    fprintf(outf,"!else\n");
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
    fprintf(outf,"!endif\n");
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 p_endwhile(char *p[MAX_PARM])
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
    fprintf(outf,"!endwhile\n");
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
    char *p1, *p2, buf[256];
543
  char *p1, *p2, buf[256];
544
    char vbuf[MAX_LINELEN+1];
544
  char vbuf[MAX_LINELEN+1];
545
    int i;
545
  int i;
546
 
546
 
547
    p1=find_word_start(p[0]);
547
  p1=find_word_start(p[0]);
548
    if(!isalpha(*p1)) return;
548
  if(!isalpha(*p1)) return;
549
    for(p2=p1; isalnum(*p2); p2++);
549
  for(p2=p1; isalnum(*p2); p2++);
550
    if(p2-p1>64) return;
550
  if(p2-p1>64) return;
551
    memmove(buf,p1,p2-p1); buf[p2-p1]=0;
551
  memmove(buf,p1,p2-p1); buf[p2-p1]=0;
552
    for(i=1;i<varcnt && strcmp(buf,param[i].name)!=0;i++);
552
  for(i=1;i<varcnt && strcmp(buf,param[i].name)!=0;i++);
553
    if(i>=varcnt && i<MAX_PARAM) {
553
  if(i>=varcnt && i<MAX_PARAM) {
554
      param[varcnt].name=p1;
554
    param[varcnt].name=p1;
555
      param[varcnt].type=pt_real;
555
    param[varcnt].type=pt_real;
556
      param[varcnt].save=0;
556
    param[varcnt].save=0;
557
      varcnt++;
557
    varcnt++;
558
    }
558
  }
559
    snprintf(vbuf,sizeof(vbuf),"%s",p2); subst(vbuf); *p2=0;
559
  snprintf(vbuf,sizeof(vbuf),"%s",p2); subst(vbuf); *p2=0;
560
    if(deftag) repsubst(vbuf);
560
  if(deftag) repsubst(vbuf);
561
    prepcnt=0; parmprep(vbuf, pt_real);
561
  prepcnt=0; parmprep(vbuf, pt_real);
562
    fprintf(outf,"!for val%d %s \n", i, vbuf);
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
    fprintf(outf,"!next\n");
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
    int i, f, xr, yr;
572
  int i, f, xr, yr;
573
    char *pp, *p2;
573
  char *pp, *p2;
574
    char buf[MAX_LINELEN+1];
574
  char buf[MAX_LINELEN+1];
575
    f=xr=yr=-1;
575
  f=xr=yr=-1;
576
    for(i=0;i<3;i++) {
576
  for(i=0;i<3;i++) {
577
      if(*p[i]==0) continue;
577
    if(*p[i]==0) continue;
578
      if((pp=strchr(p[i],'='))==NULL) f=i;
578
    if((pp=strchr(p[i],'='))==NULL) f=i;
579
      else {
579
    else {
580
          *pp=0; pp++;
580
      *pp=0; pp++;
581
          p2=find_word_start(p[i]);
581
      p2=find_word_start(p[i]);
582
          if(*p2=='x' || *p2=='X') xr=i;
582
      if(*p2=='x' || *p2=='X') xr=i;
583
          else if (*p2=='y' || *p2=='Y') yr=i;
583
      else if (*p2=='y' || *p2=='Y') yr=i;
584
          ovlstrcpy(p[i],pp);
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
    ovlstrcpy(buf, p[f]);
591
  ovlstrcpy(buf, p[f]);
592
    prepcnt=0; parmprep(buf,pt_func);
592
  prepcnt=0; parmprep(buf,pt_func);
593
    fprintf(outf,"plot_fn=!rawmath %s\n",buf);
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
    int i,j;
599
  int i,j;
600
    char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1];
600
  char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1];
601
    for(i=0;i<5;i++) {
601
  for(i=0;i<5;i++) {
602
      if(p[i]==NULL || p[i][0]==0) continue;
602
    if(p[i]==NULL || p[i][0]==0) continue;
603
      p[i]=find_word_start(p[i]);
603
    p[i]=find_word_start(p[i]);
604
      if(strncasecmp(p[i],"option",strlen("option"))==0) {
604
    if(strncasecmp(p[i],"option",strlen("option"))==0) {
605
          char *tt, *tv;
605
      char *tt, *tv;
606
          tt=p[i]+strlen("option");
606
      tt=p[i]+strlen("option");
607
          if(*tt=='s' || *tt=='S') tt++;
607
      if(*tt=='s' || *tt=='S') tt++;
608
          tt=find_word_start(tt);
608
      tt=find_word_start(tt);
609
          if(*tt=='=') {
609
      if(*tt=='=') {
610
            for(j=i;j<6;j++) p[j]=p[j+1];
610
        for(j=i;j<6;j++) p[j]=p[j+1];
611
            i--;
611
        i--;
612
            snprintf(buf1,sizeof(buf1),"%s",tt+1); subst(buf1);
612
        snprintf(buf1,sizeof(buf1),"%s",tt+1); subst(buf1);
613
            for(tv=buf1; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
613
        for(tv=buf1; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
614
            strip_trailing_spaces(buf1);
614
        strip_trailing_spaces(buf1);
615
            fprintf(outf,"condoption%d=%s \n",conditioncnt,
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
                  find_word_start(buf1));
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
    if(p[1][0]==0) {p[1]=p[0]; p[0]="";}
635
  if(p[1][0]==0) {p[1]=p[0]; p[0]="";}
636
    snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1);
636
  snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1);
637
    snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2);
637
  snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2);
638
    prepcnt=0; parmprep(buf2, pt_real);
638
  prepcnt=0; parmprep(buf2, pt_real);
639
    repsubst(buf2);
639
  repsubst(buf2);
640
    fprintf(outf,"\n!ifval %s\n condtest%d=1\n!else\n condtest%d=0\n!endif\n\
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
    char buf[MAX_LINELEN+1];
647
  char buf[MAX_LINELEN+1];
648
    snprintf(buf,sizeof(buf),"%s",p[0]); subst(buf);
648
  snprintf(buf,sizeof(buf),"%s",p[0]); subst(buf);
649
    prepcnt=0; parmprep(buf, pt_real);
649
  prepcnt=0; parmprep(buf, pt_real);
650
    repsubst(buf);
650
  repsubst(buf);
651
    fprintf(outf,"\ncondlist=%s\n",buf);
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
    char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1];
656
  char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1];
657
    char *cmpstr="ifval";
657
  char *cmpstr="ifval";
658
 
658
 
659
    snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1);
659
  snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1);
660
    snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2);
660
  snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2);
661
    repsubst(buf1); repsubst(buf2);
661
  repsubst(buf1); repsubst(buf2);
662
    if(strstr(buf1,"$m_choice")!=NULL) cmpstr="if";
662
  if(strstr(buf1,"$m_choice")!=NULL) cmpstr="if";
663
    prepcnt=0; setpre="!set "; parmprep(buf1, pt_real); setpre="";
663
  prepcnt=0; setpre="!set "; parmprep(buf1, pt_real); setpre="";
664
    fprintf(outf,"!%s %s\n <div class='oef_feedbacks'>",cmpstr, buf1);
664
  fprintf(outf,"!%s %s\n <div class='oef_feedbacks'>",cmpstr, buf1);
665
    out_exec(buf2,NULL);
665
  out_exec(buf2,NULL);
666
    fprintf(outf,"</div>\n!endif\n");
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
    char vbuf[MAX_LINELEN+1];
672
  char vbuf[MAX_LINELEN+1];
673
    char *pp, *p2;
673
  char *pp, *p2;
674
 
674
 
675
    snprintf(vbuf,sizeof(vbuf),"%s",find_word_start(p[0])); subst(vbuf);
675
  snprintf(vbuf,sizeof(vbuf),"%s",find_word_start(p[0])); subst(vbuf);
676
    strip_trailing_spaces(vbuf);
676
  strip_trailing_spaces(vbuf);
677
    if(vbuf[0]==0) return;
677
  if(vbuf[0]==0) return;
678
    if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') {
678
  if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') {
679
      char buf[MAX_LINELEN+1];
679
    char buf[MAX_LINELEN+1];
680
      if(check_compare(vbuf)==0) goto noif;
680
    if(check_compare(vbuf)==0) goto noif;
681
      p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0;
681
    p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0;
682
      snprintf(buf,sizeof(buf),"%s",vbuf);
682
    snprintf(buf,sizeof(buf),"%s",vbuf);
683
      prepcnt=0; parmprep(buf,pt_text);
683
    prepcnt=0; parmprep(buf,pt_text);
684
      fprintf(outf,"\n!ifval %s \n",buf);
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",pp);
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
      fprintf(outf,"!endif\n");
694
    fprintf(outf,"!endif\n");
695
    }
695
  }
696
    else {
696
  else {
697
noif:
697
noif:
698
      prepcnt=0; parmprep(vbuf, pt_text);
698
    prepcnt=0; parmprep(vbuf, pt_text);
699
      fprintf(outf,"oefsteps=%s \nnextstep=!nosubst %s \n",vbuf,vbuf);
699
    fprintf(outf,"oefsteps=%s \nnextstep=!nosubst %s \n",vbuf,vbuf);
700
    }
700
  }
701
    fprintf(outf,"!readproc oef/steps.proc\n");
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
    fprintf(outf,"dynsteps=yes\n");
707
  fprintf(outf,"dynsteps=yes\n");
708
    p_steps(p);
708
  p_steps(p);
709
}
709
}
710
 
-