Subversion Repositories wimsdev

Rev

Rev 8135 | Rev 8871 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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