Back to index

wims  3.65+svn20090927
process.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018 enum {pt_int, pt_rat, pt_real, pt_complex, pt_func, pt_text, pt_matrix};
00019 int prepcnt;
00020 int ex_statement=0, ex_hint=0, ex_help=0, ex_solution=0;
00021 char vbuf_statement[MAX_LINELEN+1];
00022 char vbuf_hint[MAX_LINELEN+1];
00023 char vbuf_help[MAX_LINELEN+1];
00024 char vbuf_solution[MAX_LINELEN+1];
00025 char vbuf_css[MAX_LINELEN+1];
00026 
00027 #include "sp.c"
00028 
00029        /* empty processor, template. */
00030 void empty(char *p[MAX_PARM]) {}
00031 
00032 void p_author(char *p[MAX_PARM])
00033 {
00034     p[0]=find_word_start(p[0]);
00035     if(strlen(p[0])>128) p[0][128]=0;
00036     fprintf(outf,"author=%s\n",p[0]);
00037 }
00038 
00039 void p_email(char *p[MAX_PARM])
00040 {
00041     p[0]=find_word_start(p[0]);
00042     if(strlen(p[0])>128) p[0][128]=0;
00043     fprintf(outf,"email=%s\n",p[0]);
00044 }
00045 
00046 void p_computeanswer(char *p[MAX_PARM])
00047 {   
00048     p[0]=find_word_start(p[0]);
00049     *find_word_end(p[0])=0;
00050     if(strcasecmp(p[0],"yes"))
00051       fprintf(outf,"computeanswer=no\n");
00052     else fprintf(outf,"computeanswer=%s\n",p[0]);
00053 }
00054 
00055 void p_precision(char *p[MAX_PARM])
00056 {
00057     int pr;
00058     pr=atoi(p[0]);
00059     if(pr<0 || pr>100000000) return;
00060     fprintf(outf,"precision=%d\n",pr);
00061 }
00062 
00063 /* ajout de bpr */
00064 void p_css(char *p[MAX_PARM])
00065 {   
00066     char vbuf_css[MAX_LINELEN+1];
00067     if(p==NULL) return;
00068     snprintf(vbuf_css,sizeof(vbuf_css),"%s",p[0]); subst(vbuf_css);
00069        fprintf(outf,"oefcss=%s\n",vbuf_css); 
00070 }
00071 /* */
00072 
00073 void p_wims(char *p[MAX_PARM])
00074 {
00075     char vbuf[MAX_LINELEN+1];
00076     snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf);
00077        /* the second condition could be removed?
00078         * To be very careful! */
00079     if(strchr(vbuf,'=')==NULL || strchr(vbuf,'!')!=NULL) return;
00080     fprintf(outf,"%s\n",vbuf);    
00081 }
00082 
00083 void p_mdef(char *p[MAX_PARM])
00084 {
00085     char vbuf[MAX_LINELEN+1];
00086     if(wordchr(mdef,p[0])==NULL) return;
00087     snprintf(vbuf,sizeof(vbuf),"%s",p[1]); subst(vbuf);
00088        /* the second condition could be removed?
00089         * To be very careful! */
00090     if(strchr(vbuf,'!')!=NULL) return;
00091     fprintf(outf,"m_%s=%s\n",p[0],vbuf);
00092 }
00093 
00094 void p_range(char *p[MAX_PARM])
00095 {
00096     double left, right;
00097     char *pp;
00098     pp=strstr(p[0],"..");
00099     if(pp==NULL) return;
00100     *pp=0;pp+=strlen("..");
00101     left=atof(p[0]); right=atof(pp);
00102     if(left>=right-1E-50 || left<-1E50 || right>1E50) return;
00103     fprintf(outf,"leftrange=%f\nrightrange=%f\n",left,right);
00104 }
00105 
00106 void p_language(char *p[MAX_PARM])
00107 {   
00108     p[0]=find_word_start(p[0]);
00109     *find_word_end(p[0])=0;
00110     if(strlen(p[0])==2) fprintf(outf,"language=%s\n",p[0]); 
00111 }
00112 
00113 void p_statement(char *p[MAX_PARM])
00114 {
00115     if(ex_statement<0) return;
00116     if(ex_statement>0 || p==NULL) {
00117        out_exec(vbuf_statement,"question");
00118        ex_statement=-1; return;
00119     }
00120     if(p==NULL) return;
00121     snprintf(vbuf_statement,sizeof(vbuf_statement),"%s",p[0]);
00122     subst(vbuf_statement);
00123     if(strcmp(format,"html")!=0) {
00124        fprintf(outf,"question=!nosubst %s\n",vbuf_statement);
00125        ex_statement=-1;
00126     }
00127     else {
00128        fprintf(outf,"question=%s\n",executed_str);
00129        ex_statement=1;
00130     }
00131 }
00132 
00133 void p_hint(char *p[MAX_PARM])
00134 {
00135     if(ex_hint<0) return;
00136     if(ex_hint>0 || p==NULL) {
00137        out_exec(vbuf_hint,"hint");
00138        ex_hint=-1; return;
00139     }
00140     snprintf(vbuf_hint,sizeof(vbuf_hint),"%s",p[0]); subst(vbuf_hint);
00141     if(strchr(vbuf_hint,'\\')!=NULL) {
00142        fprintf(outf,"hint=%s\n",executed_str);
00143        ex_hint=1;
00144     }
00145     else {
00146        singlespace(vbuf_hint);
00147        fprintf(outf,"hint=!nosubst %s\n\n", vbuf_hint);
00148     }
00149 }
00150 
00151 void p_help(char *p[MAX_PARM])
00152 {
00153     if(ex_help<0) return;
00154     if(ex_help>0 || p==NULL) {
00155        out_exec(vbuf_help,"help");
00156        ex_help=-1; return;
00157     }
00158     snprintf(vbuf_help,sizeof(vbuf_help),"%s",p[0]); subst(vbuf_help);
00159     if(strchr(vbuf_help,'\\')!=NULL) {
00160        fprintf(outf,"help=%s\n",executed_str);
00161        ex_help=1;
00162     }
00163     else {
00164        singlespace(vbuf_help);
00165        fprintf(outf,"help=!nosubst %s\n\n", vbuf_help);
00166     }
00167 }
00168 
00169 void p_solution(char *p[MAX_PARM])
00170 {
00171     if(ex_solution<0) return;
00172     if(ex_solution>0 || p==NULL) {
00173        out_exec(vbuf_solution,"solution");
00174        ex_solution=-1; return;
00175     }
00176     snprintf(vbuf_solution,sizeof(vbuf_solution),"%s",p[0]);
00177     subst(vbuf_solution);
00178     if(strchr(vbuf_solution,'\\')!=NULL) {
00179        fprintf(outf,"solution=%s\n",executed_str);
00180        ex_solution=1;
00181     }
00182     else {
00183        singlespace(vbuf_solution);
00184        fprintf(outf,"solution=!nosubst %s\n\n", vbuf_solution);
00185     }
00186 }
00187 
00188 enum {typ_default, typ_num, typ_func, typ_units, typ_text,
00189       typ_formal,typ_matrix,typ_vector,typ_set,typ_equation,
00190       typ_case, typ_nocase, typ_atext, typ_wlist, typ_comp,
00191       typ_algexp, typ_litexp, typ_menu, typ_coord, typ_fill,
00192       typ_raw, typ_symtext,
00193       typ_java, typ_src, typ_chem
00194 };
00195 
00196 struct {
00197     char *name;
00198     int  type;
00199     char *def;
00200 } anstype[]={
00201       {"algexp",     typ_algexp,   "algexp"},
00202       {"aset",              typ_set,      "aset"},
00203       {"atext",             typ_atext,    "atext"},
00204       {"case",              typ_case,     "case"},
00205       {"checkbox",   typ_menu,     "checkbox"},
00206       {"chemeq",        typ_chem,       "chemeq"},
00207       {"chset",             typ_atext,    "chset"},
00208       {"click",             typ_menu,     "click"},
00209       {"clickfill",  typ_fill,     "clickfill"},
00210       {"code",              typ_src,      "code"},
00211       {"compose",    typ_comp,     "compose"},
00212       {"coord",             typ_coord,    "coord"},
00213       {"coordinates",       typ_coord,    "coord"},
00214       {"corresp",    typ_comp,     "correspond"},
00215       {"correspond", typ_comp,     "correspond"},
00216       {"default",    typ_default,  "default"},
00217       {"dragfill",   typ_fill,     "dragfill"},
00218       {"equation",   typ_equation, "equation"},
00219       {"expalg",     typ_algexp,   "algexp"},
00220       {"formal",     typ_formal,   "formal"},
00221       {"fset",              typ_set,      "fset"},
00222       {"function",   typ_func,     "function"},
00223       {"imgcomp",    typ_comp,     "imgcomp"},
00224       {"javacurve",  typ_java,     "javacurve"},
00225       {"link",              typ_menu,     "click"},
00226       {"litexp",     typ_litexp,   "litexp"},
00227       {"mark",              typ_menu,     "mark"},
00228       {"matrix",     typ_matrix,   "matrix"},
00229       {"menu",              typ_menu,     "menu"},
00230       {"nocase",     typ_nocase,   "nocase"},
00231       {"number",     typ_num,      "numeric"},
00232       {"numeric",    typ_num,      "numeric"},
00233       {"numexp",     typ_algexp,   "numexp"},
00234       {"radio",             typ_menu,     "radio"},
00235       {"range",             typ_func,     "range"},
00236       {"ranges",     typ_func,     "range"},
00237       {"raw",        typ_raw,      "raw"},
00238       {"reorder",    typ_comp,     "reorder"},
00239       {"select",     typ_menu,     "menu"},
00240       {"set",        typ_set,      "set"},
00241       {"sigunits",   typ_units,    "sigunits"},
00242       {"symtext",    typ_symtext,  "symtext"},
00243       {"text",              typ_text,     "case"},
00244       {"textcomp",   typ_comp,     "textcomp"},
00245       {"unit",              typ_units,    "units"},
00246       {"units",             typ_units,    "units"},
00247       {"vector",     typ_vector,   "vector"},
00248       {"wlist",             typ_wlist,    "wlist"},
00249       {"wordcomp",   typ_comp,     "textcomp"}
00250 };
00251 
00252 #define anstype_no (sizeof(anstype)/sizeof(anstype[0]))
00253 
00254 void p_answer(char *p[MAX_PARM])
00255 {
00256     char *pp, vbuf[MAX_LINELEN+1],nbuf[MAX_LINELEN+1];
00257     int i,j,k,typ;
00258     
00259        /* look for type definition */
00260     typ=typ_default;
00261     for(i=0;i<5;i++) {
00262        if(p[i]==NULL || p[i][0]==0) continue;
00263        p[i]=find_word_start(p[i]);
00264        if(strncasecmp(p[i],"type",strlen("type"))==0) {
00265            char *tt;
00266            tt=find_word_start(p[i]+strlen("type"));
00267            if(*tt=='=') {
00268               for(j=i;j<6;j++) p[j]=p[j+1]; i--;
00269               tt=find_word_start(tt+1); *find_word_end(tt)=0;
00270               k=search_list(anstype,anstype_no,sizeof(anstype[0]),tt);
00271                      /* unknown type is now substituted */
00272               if(k>=0) {
00273                   fprintf(outf,"replytype%d=%s\n",
00274                          answercnt,anstype[k].def);
00275                   typ=anstype[k].type;
00276               }
00277               else {
00278                   snprintf(nbuf,sizeof(nbuf),"%s",tt); subst(nbuf);
00279                   fprintf(outf,"replytype%d=%s\n\n",answercnt,nbuf);
00280               }
00281            }
00282            continue;
00283        }
00284        if(strncasecmp(p[i],"option",strlen("option"))==0) {
00285            char *tt, *tv;
00286            tt=p[i]+strlen("option");
00287            if(*tt=='s' || *tt=='S') tt++;
00288            tt=find_word_start(tt);
00289            if(*tt=='=') {
00290               for(j=i;j<6;j++) p[j]=p[j+1]; i--;
00291               snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf);
00292               for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
00293               strip_trailing_spaces(nbuf);
00294               fprintf(outf,"replyoption%d=%s \n",answercnt,
00295                      find_word_start(nbuf));
00296            }
00297            continue;
00298        }
00299        if(strncasecmp(p[i],"weight",strlen("weight"))==0) {
00300            char *tt;
00301            tt=p[i]+strlen("weight");
00302            tt=find_word_start(tt);
00303            if(*tt=='=') {
00304               for(j=i;j<6;j++) p[j]=p[j+1]; i--;
00305               snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf);
00306               strip_trailing_spaces(nbuf);
00307               fprintf(outf,"replyweight%d=%s \n",answercnt,
00308                      find_word_start(nbuf));
00309            }
00310            continue;
00311        }
00312     }
00313     p[0]=find_word_start(p[0]);
00314     strncpy(nbuf,p[0],MAX_LINELEN); nbuf[MAX_LINELEN]=0; subst(nbuf);
00315     nbuf[MAX_PROMPTLEN]=0;
00316     strip_trailing_spaces(nbuf); pp=nbuf+strlen(nbuf)-1;
00317     if(*pp=='=') *pp=0;
00318     p[1]=find_word_start(p[1]);
00319     if(*p[1]=='\\' && (isalnum(*(p[1]+1)) || *(p[1]+1)=='_')) {
00320               /* check for analyzed answers */
00321        int i,n; char *pt;
00322        strncpy(vbuf,p[1]+1,MAX_LINELEN); vbuf[MAX_LINELEN]=0;
00323        pt=strchr(vbuf,';'); if(pt!=NULL) *pt=0;
00324        strip_trailing_spaces(vbuf); n=strlen(vbuf);
00325        if(n>=MAX_NAMELEN) goto normal;
00326        for(i=0;i<n && (isalnum(vbuf[i]) || vbuf[i]=='_');i++);
00327        if(i<n) goto normal;
00328        for(i=varcnt-1;i>=1 && strcmp(vbuf,param[i].name)!=0;i--);
00329        if(i<1) {     /* unused name; the answer should be analyzed */
00330            char *pm;
00331            pm=xmalloc(MAX_NAMELEN+2);
00332            strcpy(pm,vbuf); param[varcnt].name=pm;
00333            if(pt) {
00334               *pt=';'; 
00335               strcpy(vbuf,pt); subst(vbuf); pt=vbuf;
00336            }
00337            else pt="";
00338            param[varcnt].type=pt_real;
00339            param[varcnt].save=1;
00340            fprintf(outf,"replyname%d=%s\nreplygood%d=?analyze %d%s\n",
00341                   answercnt,nbuf,answercnt,varcnt,pt);
00342            condans++; answercnt++; varcnt++; return;
00343        }
00344     }
00345     normal:
00346     strncpy(vbuf,p[1],MAX_LINELEN); vbuf[MAX_LINELEN]=0;
00347     subst(vbuf);
00348     switch(typ) {
00349        default:
00350        case typ_default: {
00351            fprintf(outf,"replyname%d=%s\nreplygood%d=%s\n",
00352                   answercnt,nbuf,answercnt,vbuf);
00353            break;
00354        }
00355        case typ_num: {
00356            fprintf(outf,"replyname%d=%s\nreplygood%d=$[%s]\n",
00357                   answercnt,nbuf,answercnt,vbuf);
00358            break;
00359        }
00360        case typ_equation:
00361        case typ_func: {
00362            fprintf(outf,"replyname%d=%s\nreplygood%d=!rawmath %s\n",
00363                   answercnt,nbuf,answercnt,vbuf);
00364            break;
00365        }
00366        case typ_units: {
00367            fprintf(outf,"replyname%d=%s\nreplygood%d=%s\n",
00368                   answercnt,nbuf,answercnt,vbuf);
00369            break;
00370        }
00371     }
00372     answercnt++;
00373 }
00374 
00375 void p_choice(char *p[MAX_PARM])
00376 {
00377     int i,j;
00378     char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1],nbuf[MAX_LINELEN+1];
00379     for(i=0;i<5;i++) {
00380        if(p[i]==NULL || p[i][0]==0) continue;
00381        p[i]=find_word_start(p[i]);
00382        if(strncasecmp(p[i],"option",strlen("option"))==0) {
00383            char *tt, *tv;
00384            tt=p[i]+strlen("option");
00385            if(*tt=='s' || *tt=='S') tt++;
00386            tt=find_word_start(tt);
00387            if(*tt=='=') {
00388               for(j=i;j<6;j++) p[j]=p[j+1]; i--;
00389               snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf);
00390               for(tv=nbuf; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
00391               strip_trailing_spaces(nbuf);
00392               fprintf(outf,"choiceoption%d=%s \n",choicecnt,
00393                      find_word_start(nbuf));
00394            }
00395            continue;
00396        }
00397        if(strncasecmp(p[i],"weight",strlen("weight"))==0) {
00398            char *tt;
00399            tt=p[i]+strlen("weight");
00400            tt=find_word_start(tt);
00401            if(*tt=='=') {
00402               for(j=i;j<6;j++) p[j]=p[j+1]; i--;
00403               snprintf(nbuf,sizeof(nbuf),"%s",tt+1); subst(nbuf);
00404               strip_trailing_spaces(nbuf);
00405               fprintf(outf,"choiceweight%d=%s \n",choicecnt,
00406                      find_word_start(nbuf));
00407            }
00408            continue;
00409        }
00410     }
00411     p[0]=find_word_start(p[0]);
00412     snprintf(buf1,sizeof(buf1),"%s",p[1]); subst(buf1);
00413     snprintf(buf2,sizeof(buf2),"%s",p[2]); subst(buf2);
00414     snprintf(nbuf,sizeof(nbuf),"%s",p[0]); subst(nbuf);
00415     nbuf[MAX_PROMPTLEN]=0;
00416     fprintf(outf,"choicename%d=%s\nchoicegood%d=%s\nchoicebad%d=%s\n",
00417            choicecnt,nbuf,choicecnt,buf1,choicecnt,buf2);
00418     choicecnt++;
00419 }
00420 
00421 void putval(char *p, int n, int ptype)
00422 {
00423     switch(ptype) {
00424        case pt_int: {
00425            fprintf(outf,"val%d=$[rint(%s)]\n",n,p);
00426            break;
00427        }
00428        case pt_real: {
00429            fprintf(outf,"val%d=$[%s]\n",n,p);
00430            break;
00431        }
00432        case pt_func: {
00433            fprintf(outf,"val%d=!rawmath %s\n",n,p);
00434            break;
00435        }
00436        case pt_complex: {
00437            fprintf(outf,"t_=!rawmath %s\nt_=!exec pari print($t_)\n\
00438 val%d=!mathsubst I=i in $t_\n",p,n);
00439            break;
00440        }
00441        case pt_matrix: {
00442            fprintf(outf,"tmp=!trim %s\n\
00443 val%d=!translate internal $ \\\n$ to ;; in $tmp\n",p,n);
00444            break;
00445        }
00446        case pt_rat: {
00447            fprintf(outf,"t_=!rawmath %s\n\
00448 val%d=!exec pari print($t_)\n",p,n);
00449            break;
00450        }
00451        default: {
00452            fprintf(outf,"val%d=%s\n",n,p);
00453            break;
00454        }
00455     }
00456 }
00457 
00458 void parm(char *p[MAX_PARM], int ptype)
00459 {
00460     char *pp, *p2;
00461     char vbuf[MAX_LINELEN+1];
00462     int i;
00463 
00464     p[0]=find_word_start(p[0]);
00465     if(*p[0]=='\\') p[0]++;
00466        /* bad name */
00467     if(!isalpha(*p[0])) return;
00468     strip_trailing_spaces(p[0]);
00469     for(pp=p[0];*pp;pp++) if(!isalnum(*pp) && *pp!='_') {
00470        /* bad name and security risk */
00471        if(!isspace(*pp)) return;
00472        strcpy(pp,pp+1); pp--;
00473     }
00474     for(i=1;i<varcnt && strcmp(p[0],param[i].name)!=0;i++);
00475     p[1]=find_word_start(p[1]);
00476     snprintf(vbuf,sizeof(vbuf),"%s",p[1]); subst(vbuf);
00477     if(deftag) repsubst(vbuf);
00478     if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') {
00479        char buf[MAX_LINELEN+1];
00480        if(check_compare(vbuf)==0) goto noif;
00481        p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0;
00482        snprintf(buf,sizeof(buf),"%s",vbuf);
00483        prepcnt=0; parmprep(buf,ptype);
00484        fprintf(outf,"\n!ifval %s\n",buf);
00485        snprintf(buf,sizeof(buf),"%s",pp);
00486        parmprep(buf,ptype); putval(buf,i,ptype);
00487        if(p2!=NULL) {
00488            fprintf(outf,"!else\n");
00489            snprintf(buf,sizeof(buf),"%s",p2);
00490            parmprep(buf,ptype); putval(buf,i,ptype);
00491        }
00492        fprintf(outf,"!endif\n");
00493     }
00494     else {
00495 noif:
00496        prepcnt=0; parmprep(vbuf, ptype);
00497        putval(vbuf,i,ptype);
00498     }
00499     if(i>=varcnt && i<MAX_PARAM) {
00500        param[varcnt].name=p[0];
00501        param[varcnt].type=ptype;
00502        param[varcnt].save=0;
00503        varcnt++;
00504     }
00505 }
00506 
00507 void p_int(char *p[MAX_PARM]) {parm(p,pt_int);}
00508 void p_rational(char *p[MAX_PARM]) {parm(p,pt_rat);}
00509 void p_real(char *p[MAX_PARM]) {parm(p,pt_real);}
00510 void p_complex(char *p[MAX_PARM]) {parm(p,pt_complex);}
00511 void p_func(char *p[MAX_PARM]) {parm(p,pt_func);}
00512 void p_text(char *p[MAX_PARM]) {parm(p,pt_text);}
00513 void p_matrix(char *p[MAX_PARM]) {parm(p,pt_matrix);}
00514 
00515 void p_parm(char *p[MAX_PARM])
00516 {
00517     parm(p,pt_real);
00518 }
00519 
00520 void p_if(char *p[MAX_PARM])
00521 {
00522     char vbuf[MAX_LINELEN+1];
00523     snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf);
00524     if(deftag) repsubst(vbuf);
00525     prepcnt=0; parmprep(vbuf, pt_real);
00526     fprintf(outf,"!if %s \n",vbuf);
00527 }
00528 
00529 void p_else(char *p[MAX_PARM])
00530 {
00531     fprintf(outf,"!else\n");
00532 }
00533 
00534 void p_endif(char *p[MAX_PARM])
00535 {
00536     fprintf(outf,"!endif\n");
00537 }
00538 
00539 
00540 void p_while(char *p[MAX_PARM])
00541 {
00542     char vbuf[MAX_LINELEN+1];
00543     snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf);
00544     if(deftag) repsubst(vbuf);
00545     prepcnt=0; parmprep(vbuf, pt_real);
00546     fprintf(outf,"!while %s \n",vbuf);
00547 }
00548 
00549 void p_endwhile(char *p[MAX_PARM])
00550 {
00551     fprintf(outf,"!endwhile\n");
00552 }
00553 
00554 void p_for(char *p[MAX_PARM])
00555 {
00556     char *p1, *p2, buf[256];
00557     char vbuf[MAX_LINELEN+1];
00558     int i;
00559 
00560     p1=find_word_start(p[0]);
00561     if(!isalpha(*p1)) return;
00562     for(p2=p1; isalnum(*p2); p2++);
00563     if(p2-p1>64) return;
00564     memmove(buf,p1,p2-p1); buf[p2-p1]=0;
00565     for(i=1;i<varcnt && strcmp(buf,param[i].name)!=0;i++);
00566     if(i>=varcnt && i<MAX_PARAM) {
00567        param[varcnt].name=p1;
00568        param[varcnt].type=pt_real;
00569        param[varcnt].save=0;
00570        varcnt++;
00571     }
00572     snprintf(vbuf,sizeof(vbuf),"%s",p2); subst(vbuf); *p2=0;
00573     if(deftag) repsubst(vbuf);
00574     prepcnt=0; parmprep(vbuf, pt_real);
00575     fprintf(outf,"!for val%d %s \n", i, vbuf);
00576 }
00577 
00578 void p_next(char *p[MAX_PARM])
00579 {
00580     fprintf(outf,"!next\n");
00581 }
00582 
00583 void p_plot(char *p[MAX_PARM])
00584 {
00585     int i, f, xr, yr;
00586     char *pp, *p2;
00587     char buf[MAX_LINELEN+1];
00588     f=xr=yr=-1;      
00589     for(i=0;i<3;i++) {
00590        if(*p[i]==0) continue;
00591        if((pp=strchr(p[i],'='))==NULL) f=i;
00592        else {
00593            *pp=0; pp++;
00594            p2=find_word_start(p[i]);
00595            if(*p2=='x' || *p2=='X') xr=i;
00596            else if (*p2=='y' || *p2=='Y') yr=i;
00597            strcpy(p[i],pp);
00598        }
00599     }
00600 /*    if(xr>=0 && (pp=strstr(p[xr],".."))!=NULL) {
00601        
00602     }
00603 */    if(f<0) return;
00604     strcpy(buf, p[f]);
00605     prepcnt=0; parmprep(buf,pt_func);
00606     fprintf(outf,"plot_fn=!rawmath %s\n",buf);
00607     
00608 }
00609 
00610 void p_condition(char *p[MAX_PARM])
00611 {
00612     int i,j;
00613     char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1];
00614     for(i=0;i<5;i++) {
00615        if(p[i]==NULL || p[i][0]==0) continue;
00616        p[i]=find_word_start(p[i]);
00617        if(strncasecmp(p[i],"option",strlen("option"))==0) {
00618            char *tt, *tv;
00619            tt=p[i]+strlen("option");
00620            if(*tt=='s' || *tt=='S') tt++;
00621            tt=find_word_start(tt);
00622            if(*tt=='=') {
00623               for(j=i;j<6;j++) p[j]=p[j+1]; i--;
00624               snprintf(buf1,sizeof(buf1),"%s",tt+1); subst(buf1);
00625               for(tv=buf1; *tv; tv++) if(*tv==',' || *tv==';') *tv=' ';
00626               strip_trailing_spaces(buf1);
00627               fprintf(outf,"condoption%d=%s \n",conditioncnt,
00628                      find_word_start(buf1));
00629            }
00630            continue;
00631        }
00632        if(strncasecmp(p[i],"weight",strlen("weight"))==0) {
00633            char *tt;
00634            tt=p[i]+strlen("weight");
00635            tt=find_word_start(tt);
00636            if(*tt=='=') {
00637               for(j=i;j<6;j++) p[j]=p[j+1]; i--;
00638               snprintf(buf1,sizeof(buf1),"%s",tt+1); subst(buf1);
00639               strip_trailing_spaces(buf1);
00640               fprintf(outf,"condweight%d=%s \n",conditioncnt,
00641                      find_word_start(buf1));
00642            }
00643            continue;
00644        }
00645     }
00646     if(p[1][0]==0) {p[1]=p[0]; p[0]="";}
00647     snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1);
00648     snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2);
00649     prepcnt=0; parmprep(buf2, pt_real);
00650     repsubst(buf2);
00651     fprintf(outf,"\n!ifval %s\n condtest%d=1\n!else\n condtest%d=0\n!endif\n\
00652 condname%d=%s\n", buf2,conditioncnt,conditioncnt,conditioncnt,buf1);
00653     conditioncnt++;
00654 }
00655 
00656 void p_conditions(char *p[MAX_PARM])
00657 {
00658     char buf[MAX_LINELEN+1];
00659     snprintf(buf,sizeof(buf),"%s",p[0]); subst(buf);
00660     prepcnt=0; parmprep(buf, pt_real);
00661     repsubst(buf);
00662     fprintf(outf,"\ncondlist=%s\n",buf);
00663 }
00664 
00665 void p_feedback(char *p[MAX_PARM])
00666 {
00667     char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1];
00668     char *cmpstr="ifval";
00669     
00670     snprintf(buf1,sizeof(buf1),"%s",p[0]); subst(buf1);
00671     snprintf(buf2,sizeof(buf2),"%s",p[1]); subst(buf2);
00672     repsubst(buf1); repsubst(buf2);
00673     if(strstr(buf1,"$m_choice")!=NULL) cmpstr="if";
00674     prepcnt=0; setpre="!set "; parmprep(buf1, pt_real); setpre="";
00675     fprintf(outf,"!%s %s\n <p>",cmpstr, buf1);
00676     out_exec(buf2,NULL);
00677     fprintf(outf,"\n!endif\n");
00678 }
00679 
00680        /* definition of steps */
00681 void p_steps(char *p[MAX_PARM])
00682 {
00683     char vbuf[MAX_LINELEN+1];
00684     char *pp, *p2;
00685     
00686     snprintf(vbuf,sizeof(vbuf),"%s",find_word_start(p[0])); subst(vbuf);
00687     strip_trailing_spaces(vbuf);
00688     if(vbuf[0]==0) return;
00689     if((pp=strparchr(vbuf,'?'))!=NULL && pp[1]!='?') {
00690        char buf[MAX_LINELEN+1];
00691        if(check_compare(vbuf)==0) goto noif;
00692        p2=strparchr(pp,':'); *pp++=0; if(p2!=NULL) *p2++=0;
00693        snprintf(buf,sizeof(buf),"%s",vbuf);
00694        prepcnt=0; parmprep(buf,pt_text);
00695        fprintf(outf,"\n!ifval %s \n",buf);
00696        snprintf(buf,sizeof(buf),"%s",pp);
00697        parmprep(buf,pt_text); 
00698        fprintf(outf,"oefsteps=%s \n",buf);
00699        if(p2!=NULL) {
00700            fprintf(outf,"!else\n");
00701            snprintf(buf,sizeof(buf),"%s",p2);
00702            parmprep(buf,pt_text);
00703            fprintf(outf,"oefsteps=%s \n",buf);
00704        }
00705        fprintf(outf,"!endif\n");
00706     }
00707     else {
00708 noif:
00709        prepcnt=0; parmprep(vbuf, pt_text);
00710        fprintf(outf,"oefsteps=%s \nnextstep=!nosubst %s \n",vbuf,vbuf);
00711     }
00712     fprintf(outf,"!readproc oef/steps.proc\n");
00713 }
00714 
00715        /* dynamic steps */
00716 void p_nextstep(char *p[MAX_PARM])
00717 {
00718     fprintf(outf,"dynsteps=yes\n");
00719     p_steps(p);
00720 }
00721