Subversion Repositories wimsdev

Rev

Rev 12122 | Rev 14873 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12122 Rev 12247
Line 19... Line 19...
19
 
19
 
20
char *setpre="";
20
char *setpre="";
21
 
21
 
22
void sp_asis(char *p, int ptype)
22
void sp_asis(char *p, int ptype)
23
{
23
{
24
    fprintf(outf,"%stmp%d=!nosubst %s\n\n",setpre,prepcnt,p);
24
  fprintf(outf,"%stmp%d=!nosubst %s\n\n",setpre,prepcnt,p);
25
}
25
}
26
 
26
 
27
void sp_evalue(char *p, int ptype)
27
void sp_evalue(char *p, int ptype)
28
{
28
{
29
    char *p1, *p2, *pe;
29
  char *p1, *p2, *pe;
30
 
30
 
31
    p1=strparchr(p,',');
31
  p1=strparchr(p,',');
32
    if(p1==NULL) {
32
  if(p1==NULL) {
33
      fprintf(outf,"%stmp%d=%s\n\n",setpre,prepcnt,p);
33
    fprintf(outf,"%stmp%d=%s\n\n",setpre,prepcnt,p);
34
      return;
34
    return;
35
    }
35
  }
36
    *p1++=0; fprintf(outf,"%sevaltmp=%s\n\n", setpre,p);
36
  *p1++=0; fprintf(outf,"%sevaltmp=%s\n\n", setpre,p);
37
    for(; p1!=NULL; p1=p2){
37
  for(; p1!=NULL; p1=p2){
38
      p1=find_word_start(p1);
38
    p1=find_word_start(p1);
39
      p2=strparchr(p1,',');
39
    p2=strparchr(p1,',');
40
      if(p2!=NULL) *p2++=0;
40
    if(p2!=NULL) *p2++=0;
41
      pe=strchr(p1,'=');
41
    pe=strchr(p1,'=');
42
      if(pe==NULL) continue;
42
    if(pe==NULL) continue;
43
      *pe++=0; *find_word_end(p1)=0;
43
    *pe++=0; *find_word_end(p1)=0;
44
      if(*p1==0) continue;
44
    if(*p1==0) continue;
45
      fprintf(outf,"%sevaltmp=!mathsubst %s=(%s) in $evaltmp\n",
45
    fprintf(outf,"%sevaltmp=!mathsubst %s=(%s) in $evaltmp\n",
46
            setpre,p1,pe);
46
          setpre,p1,pe);
47
    }
47
  }
48
    fprintf(outf,"%stmp%d=($evaltmp)\n",setpre,prepcnt);
48
  fprintf(outf,"%stmp%d=($evaltmp)\n",setpre,prepcnt);
49
}
49
}
50
 
50
 
51
/* simple roots.*/
51
/* simple roots.*/
52
void sp_solve(char *p, int ptype)
52
void sp_solve(char *p, int ptype)
53
{
53
{
54
    fprintf(outf,"%stmp=!replace internal .. by , in %s \n\n\
54
  fprintf(outf,"%stmp=!replace internal .. by , in %s \n\n\
55
!distribute items $tmp into tmp1,tmp2,tmp3\n\
55
!distribute items $tmp into tmp1,tmp2,tmp3\n\
56
%stmp2=!replace internal = by , in $tmp2\n\
56
%stmp2=!replace internal = by , in $tmp2\n\
57
!distribute items $tmp2 into tmp4,tmp5\n\
57
!distribute items $tmp2 into tmp4,tmp5\n\
58
%stmp%d=!solve $tmp1 for $tmp4 = $tmp5 to $tmp3 \n",
58
%stmp%d=!solve $tmp1 for $tmp4 = $tmp5 to $tmp3 \n",
59
          setpre,p,setpre,setpre,prepcnt);
59
          setpre,p,setpre,setpre,prepcnt);
60
}
60
}
61
 
61
 
62
/* use maxima to do formal derivation. */
62
/* use maxima to do formal derivation. */
63
void sp_diff(char *p, int ptype)
63
void sp_diff(char *p, int ptype)
64
{
64
{
65
    fprintf(outf,"%stmp=!translate ;\";': to $     $ in %s\n\n\
65
  fprintf(outf,"%stmp=!translate ;\";': to $     $ in %s\n\n\
66
%stmp=!lower $tmp\n\
66
%stmp=!lower $tmp\n\
67
%stmp%d=!exec maxima diff($tmp);\n",
67
%stmp%d=!exec maxima diff($tmp);\n",
68
          setpre,p,setpre,setpre,prepcnt);
68
          setpre,p,setpre,setpre,prepcnt);
69
}
69
}
70
 
70
 
71
/* use pari to compute matrix determinant. */
71
/* use pari to compute matrix determinant. */
72
void sp_det(char *p, int ptype)
72
void sp_det(char *p, int ptype)
73
{
73
{
74
    fprintf(outf,"%stmp=!translate $    $ to ; in %s\n\n\
74
  fprintf(outf,"%stmp=!translate $      $ to ; in %s\n\n\
75
%stmp%d=!exec pari matdet([$tmp])\n",
75
%stmp%d=!exec pari matdet([$tmp])\n",
76
          setpre,p,setpre,prepcnt);
76
          setpre,p,setpre,prepcnt);
77
}
77
}
78
 
78
 
79
/* use maxima to do formal integration,
79
/* use maxima to do formal integration,
80
 * but pari for numerical integration. */
80
 * but pari for numerical integration. */
81
void sp_int(char *p, int ptype)
81
void sp_int(char *p, int ptype)
82
{
82
{
83
    char *s;
83
  char *s;
84
 
84
 
85
    if((s=strchr(p,'='))!=NULL) *s=',';
85
  if((s=strchr(p,'='))!=NULL) *s=',';
86
    if((s=strstr(p,".."))!=NULL) {*s=','; *(s+1)=' ';}
86
  if((s=strstr(p,".."))!=NULL) {*s=','; *(s+1)=' ';}
87
    fprintf(outf,"%stmp=!translate ;\";': to $     $ in %s \n\
87
  fprintf(outf,"%stmp=!translate ;\";': to $     $ in %s \n\
88
%stmp=!lower $tmp\n\
88
%stmp=!lower $tmp\n\
89
!readproc slib/function/integrate $tmp\n\
89
!readproc slib/function/integrate $tmp\n\
90
%stmp%d=$slib_out\n",
90
%stmp%d=$slib_out\n",
91
          setpre,p,setpre,setpre,prepcnt);
91
          setpre,p,setpre,setpre,prepcnt);
92
}
92
}
93
 
93
 
94
void sp_htmlmath(char *p, int ptype)
94
void sp_htmlmath(char *p, int ptype)
95
{
95
{
96
    fprintf(outf,"%stmp%d=!htmlmath %s\n\n",setpre,prepcnt,p);
96
  fprintf(outf,"%stmp%d=!htmlmath %s\n\n",setpre,prepcnt,p);
97
}
97
}
98
 
98
 
99
void sp_teximg(char *p, int ptype)
99
void sp_teximg(char *p, int ptype)
100
{
100
{
101
    fprintf(outf,"!readproc %s/teximg.phtml %s \n\
101
  fprintf(outf,"!readproc %s/teximg.phtml %s \n\
102
%stmp%d=$ins_url\n", primitive_dir, p, setpre,prepcnt);
102
%stmp%d=$ins_url\n", primitive_dir, p, setpre,prepcnt);
103
}
103
}
104
 
104
 
105
void sp_texmath(char *p, int ptype)
105
void sp_texmath(char *p, int ptype)
106
{
106
{
107
    fprintf(outf,"%stmp%d=!texmath %s\n\n",setpre,prepcnt,p);
107
  fprintf(outf,"%stmp%d=!texmath %s\n\n",setpre,prepcnt,p);
108
}
108
}
109
 
109
 
110
void sp_maxima(char *p, int ptype)
110
void sp_maxima(char *p, int ptype)
111
{
111
{
112
    fprintf(outf,"%st_=!replace internal \\( by ( in %s\n\
112
  fprintf(outf,"%st_=!replace internal \\( by ( in %s\n\
113
%stmp%d=!exec maxima $t_\n\n",setpre,p,setpre,prepcnt);
113
%stmp%d=!exec maxima $t_\n\n",setpre,p,setpre,prepcnt);
114
}
114
}
115
 
115
 
116
void sp_yacas(char *p, int ptype)
116
void sp_yacas(char *p, int ptype)
117
{
117
{
118
    fprintf(outf,"%st_=!replace internal \\( by ( in %s\n\
118
  fprintf(outf,"%st_=!replace internal \\( by ( in %s\n\
119
%stmp%d=!exec yacas $t_\n\n",setpre,p,setpre,prepcnt);
119
%stmp%d=!exec yacas $t_\n\n",setpre,p,setpre,prepcnt);
120
}
120
}
121
 
121
 
122
void sp_pari(char *p, int ptype)
122
void sp_pari(char *p, int ptype)
123
{
123
{
124
    fprintf(outf,"%st_=!replace internal \\( by ( in %s\n\
124
  fprintf(outf,"%st_=!replace internal \\( by ( in %s\n\
125
%stmp%d=!exec pari $t_\n\n",setpre,p,setpre,prepcnt);
125
%stmp%d=!exec pari $t_\n\n",setpre,p,setpre,prepcnt);
126
}
126
}
127
 
127
 
128
void sp_simplify(char *p, int ptype)
128
void sp_simplify(char *p, int ptype)
129
{
129
{
130
    fprintf(outf,"%stmp=!translate \";': to $     $ in %s\n\n\
130
  fprintf(outf,"%stmp=!translate \";': to $     $ in %s\n\n\
131
%stmp=!lower $tmp\n\
131
%stmp=!lower $tmp\n\
132
%stmp%d=!exec maxima fullratsimp($tmp);\n",
132
%stmp%d=!exec maxima fullratsimp($tmp);\n",
133
          setpre,p,setpre,setpre,prepcnt);
133
          setpre,p,setpre,setpre,prepcnt);
134
}
134
}
135
 
135
 
136
void sp_slib(char *p, int ptype)
136
void sp_slib(char *p, int ptype)
137
{
137
{
138
    char *p2;
138
  char *p2;
139
    p=find_word_start(p);
139
  p=find_word_start(p);
140
    for(p2=p;*p2!=0 && !isspace(*p2) && *p2!=',' && *p2!=';';p2++);
140
  for(p2=p;*p2!=0 && !isspace(*p2) && *p2!=',' && *p2!=';';p2++);
141
    if(*p2!=0 && !isspace(*p2)) *p2=' ';
141
  if(*p2!=0 && !isspace(*p2)) *p2=' ';
142
    fprintf(outf,"!readproc slib/%s \n\
142
  fprintf(outf,"!readproc slib/%s \n\
143
%stmp%d=$slib_out\n",p,setpre,prepcnt);
143
%stmp%d=$slib_out\n",p,setpre,prepcnt);
144
}
144
}
145
 
145
 
146
void sp_draw(char *p, int ptype)
146
void sp_draw(char *p, int ptype)
147
{
147
{
148
    char *p2;
148
  char *p2;
149
    p2=strchr(p,'       '); if(p2==NULL) p2=strchr(p,'\n');
149
  p2=strchr(p,' '); if(p2==NULL) p2=strchr(p,'\n');
150
    if(p2==NULL) return;
150
  if(p2==NULL) return;
151
    *p2++=0;
151
  *p2++=0;
152
    fprintf(outf,"!readproc %s/draw.phtml %s \\\n%s \n\
152
  fprintf(outf,"!readproc %s/draw.phtml %s \\\n%s \n\
153
%stmp%d=$ins_url\n", primitive_dir, p, p2, setpre,prepcnt);
153
%stmp%d=$ins_url\n", primitive_dir, p, p2, setpre,prepcnt);
154
}
154
}
155
 
155
 
156
void sp_canvasdraw(char *p, int ptype)
156
void sp_canvasdraw(char *p, int ptype)
157
{
157
{
158
    char *p2;
158
  char *p2;
159
    p2=strchr(p,'       '); if(p2==NULL) p2=strchr(p,'\n');
159
  p2=strchr(p,' '); if(p2==NULL) p2=strchr(p,'\n');
160
    if(p2==NULL) return;
160
  if(p2==NULL) return;
161
    *p2++=0;
161
  *p2++=0;
162
    fprintf(outf,"!readproc %s/canvasdraw.phtml %s \\\n%s \n\
162
  fprintf(outf,"!readproc %s/canvasdraw.phtml %s \\\n%s \n\
163
%stmp%d=$canvasdraw_out\n", primitive_dir, p, p2, setpre,prepcnt);
163
%stmp%d=$canvasdraw_out\n", primitive_dir, p, p2, setpre,prepcnt);
164
}
164
}
165
 
165
 
166
void sp_shuffle(char *p, int ptype)
166
void sp_shuffle(char *p, int ptype)
167
{
167
{
168
    fprintf(outf,"%stmp%d=!shuffle %s\n\n",setpre,prepcnt,p);
168
  fprintf(outf,"%stmp%d=!shuffle %s\n\n",setpre,prepcnt,p);
169
}
169
}
170
 
170
 
171
void sp_positionof(char *p, int ptype)
171
void sp_positionof(char *p, int ptype)
172
{
172
{
173
    char *p1;
173
  char *p1;
174
    p1=strparchr(p,','); if(p1==NULL) {
174
  p1=strparchr(p,','); if(p1==NULL) {
175
      fprintf(outf,"%stmp%d=%s\n\n",setpre,prepcnt,p); return;
175
    fprintf(outf,"%stmp%d=%s\n\n",setpre,prepcnt,p); return;
176
    }
176
  }
177
    *p1++=0;
177
  *p1++=0;
178
    fprintf(outf,"%stmp%d=!positionof item %s in %s\n\n",setpre,prepcnt,p, p1);
178
  fprintf(outf,"%stmp%d=!positionof item %s in %s\n\n",setpre,prepcnt,p, p1);
179
}
179
}
180
 
180
 
181
void sp_random(char *p, int ptype)
181
void sp_random(char *p, int ptype)
182
{
182
{
183
    char *pr, *p2, buf[MAX_LINELEN+1];
183
  char *pr, *p2, buf[MAX_LINELEN+1];
184
    snprintf(buf,sizeof(buf),"%s",p);
184
  snprintf(buf,sizeof(buf),"%s",p);
185
    for(p2=buf; *p2 && p2-buf<MAX_LINELEN; p2++) {
185
  for(p2=buf; *p2 && p2-buf<MAX_LINELEN; p2++) {
186
      if(*p2=='(') {
186
    if(*p2=='(') {
187
          p2=find_matching(p2+1,')'); continue;
187
      p2=find_matching(p2+1,')'); continue;
188
      }
188
    }
189
      if(*p2==',' || (*p2=='.' && *(p2+1)=='.')) break;
189
    if(*p2==',' || (*p2=='.' && *(p2+1)=='.')) break;
190
    }
190
  }
191
    if(*p2==',') pr="randitem";
191
  if(*p2==',') pr="randitem";
192
    else {
192
  else {
193
      if(*p2=='.') {
193
    if(*p2=='.') {
194
          *p2=','; *(p2+1)=' ';
194
      *p2=','; *(p2+1)=' ';
195
      }
-
 
196
      if(ptype==pt_int) pr="randint"; else pr="random";
-
 
197
    }
195
    }
-
 
196
    if(ptype==pt_int) pr="randint"; else pr="random";
-
 
197
  }
198
    fprintf(outf,"%stmp%d=!%s %s\n\n",setpre,prepcnt,pr,buf);
198
  fprintf(outf,"%stmp%d=!%s %s\n\n",setpre,prepcnt,pr,buf);
199
}
199
}
200
 
200
 
201
void sp_pickone(char *p, int ptype)
201
void sp_pickone(char *p, int ptype)
202
{
202
{
203
    sp_random(p,pt_int);
203
  sp_random(p,pt_int);
204
}
204
}
205
 
205
 
206
void sp_item(char *p, int ptype)
206
void sp_item(char *p, int ptype)
207
{
207
{
208
    char *pp, *p2, buf[MAX_LINELEN+1];
208
  char *pp, *p2, buf[MAX_LINELEN+1];
209
    pp=strparchr(p,',');
209
  pp=strparchr(p,',');
210
    if(pp==NULL) pp=""; else *pp++=0;
210
  if(pp==NULL) pp=""; else *pp++=0;
211
    strncpy(buf,p,MAX_LINELEN);buf[MAX_LINELEN]=0;
211
  strncpy(buf,p,MAX_LINELEN);buf[MAX_LINELEN]=0;
212
    strip_enclosing_par(buf);
212
  strip_enclosing_par(buf);
213
    if((p2=strstr(buf,".."))!=NULL) string_modify(buf,p2,p2+2," to ");
213
  if((p2=strstr(buf,".."))!=NULL) string_modify(buf,p2,p2+2," to ");
214
    fprintf(outf,"%stmp%d=!item %s of %s\n\n",setpre,prepcnt,buf,pp);
214
  fprintf(outf,"%stmp%d=!item %s of %s\n\n",setpre,prepcnt,buf,pp);
215
}
215
}
216
 
216
 
217
void sp_items(char *p, int ptype)
217
void sp_items(char *p, int ptype)
218
{
218
{
219
    fprintf(outf,"%stmp%d=!itemcnt %s\n\n",setpre,prepcnt,p);
219
  fprintf(outf,"%stmp%d=!itemcnt %s\n\n",setpre,prepcnt,p);
220
}
220
}
221
 
221
 
222
void sp_randitem(char *p, int ptype)
222
void sp_randitem(char *p, int ptype)
223
{
223
{
224
    fprintf(outf,"%stmp=!nonempty items %s\n\n\
224
  fprintf(outf,"%stmp=!nonempty items %s\n\n\
225
%stmp%d=!randitem $tmp\n",setpre,p,setpre,prepcnt);
225
%stmp%d=!randitem $tmp\n",setpre,p,setpre,prepcnt);
226
}
226
}
227
 
227
 
228
void sp_column(char *p, int ptype)
228
void sp_column(char *p, int ptype)
229
{
229
{
230
    char *pp, *p2, buf[MAX_LINELEN+1];
230
  char *pp, *p2, buf[MAX_LINELEN+1];
231
    pp=strparchr(p,',');
231
  pp=strparchr(p,',');
232
    if(pp==NULL) pp=""; else *pp++=0;
232
  if(pp==NULL) pp=""; else *pp++=0;
233
    strncpy(buf,p,MAX_LINELEN);buf[MAX_LINELEN]=0;
233
  strncpy(buf,p,MAX_LINELEN);buf[MAX_LINELEN]=0;
234
    strip_enclosing_par(buf);
234
  strip_enclosing_par(buf);
235
    if((p2=strstr(buf,".."))!=NULL) string_modify(buf,p2,p2+2," to ");
235
  if((p2=strstr(buf,".."))!=NULL) string_modify(buf,p2,p2+2," to ");
236
    fprintf(outf,"%stmp=!translate internal $   $ to ; in %s\n\n\
236
  fprintf(outf,"%stmp=!translate internal $     $ to ; in %s\n\n\
237
%stmp=!column %s of $tmp\n\
237
%stmp=!column %s of $tmp\n\
238
%stmp%d=!translate internal $\\\n$ to ; in $tmp\n",
238
%stmp%d=!translate internal $\\\n$ to ; in $tmp\n",
239
          setpre,pp,setpre, buf, setpre, prepcnt);
239
          setpre,pp,setpre, buf, setpre, prepcnt);
240
}
240
}
241
 
241
 
242
void sp_row(char *p, int ptype)
242
void sp_row(char *p, int ptype)
243
{
243
{
244
    char *pp, *p2, buf[MAX_LINELEN+1];
244
  char *pp, *p2, buf[MAX_LINELEN+1];
245
    pp=strparchr(p,',');
245
  pp=strparchr(p,',');
246
    if(pp==NULL) pp=""; else *pp++=0;
246
  if(pp==NULL) pp=""; else *pp++=0;
247
    strncpy(buf,p,MAX_LINELEN);buf[MAX_LINELEN]=0;
247
  strncpy(buf,p,MAX_LINELEN);buf[MAX_LINELEN]=0;
248
    strip_enclosing_par(buf);
248
  strip_enclosing_par(buf);
249
    fprintf(outf,"%stmp=!translate internal $   $ to ; in %s\n\n",
249
  fprintf(outf,"%stmp=!translate internal $     $ to ; in %s\n\n",
250
          setpre,pp);
250
        setpre,pp);
251
    if(strstr(buf,"column")!=NULL) {
251
  if(strstr(buf,"column")!=NULL) {
252
      fprintf(outf,"%stmp%d=!select $tmp where %s\n\n",setpre,prepcnt,buf);
252
    fprintf(outf,"%stmp%d=!select $tmp where %s\n\n",setpre,prepcnt,buf);
253
      return;
253
    return;
254
    }
254
  }
255
    while((p2=strstr(buf,".."))!=NULL)
255
  while((p2=strstr(buf,".."))!=NULL)
256
      string_modify(buf,p2,p2+2," to ");
256
    string_modify(buf,p2,p2+2," to ");
257
    fprintf(outf,"%stmp=!row %s of $tmp\n\
257
  fprintf(outf,"%stmp=!row %s of $tmp\n\
258
%stmp%d=!translate internal $\\\n$ to ; in $tmp\n",
258
%stmp%d=!translate internal $\\\n$ to ; in $tmp\n",
259
          setpre, buf, setpre, prepcnt);
259
          setpre, buf, setpre, prepcnt);
260
}
260
}
261
 
261
 
262
void sp_rows(char *p, int ptype)
262
void sp_rows(char *p, int ptype)
263
{
263
{
264
    fprintf(outf,"%stmp=!translate internal $   $ to ; in %s\n\n\
264
  fprintf(outf,"%stmp=!translate internal $     $ to ; in %s\n\n\
265
%stmp%d=!rowcnt $tmp\n",setpre,p,setpre,prepcnt);
265
%stmp%d=!rowcnt $tmp\n",setpre,p,setpre,prepcnt);
266
}
266
}
267
 
267
 
268
void sp_randrow(char *p, int ptype)
268
void sp_randrow(char *p, int ptype)
269
{
269
{
270
    fprintf(outf,"%stmp=!translate internal $   $ to ; in %s\n\n\
270
  fprintf(outf,"%stmp=!translate internal $     $ to ; in %s\n\n\
271
%stmp=!nonempty rows $tmp\n\
271
%stmp=!nonempty rows $tmp\n\
272
%stmp=!randrow $tmp\n\
272
%stmp=!randrow $tmp\n\
273
%stmp%d=!translate internal $\\\n$ to ; in $tmp\n",
273
%stmp%d=!translate internal $\\\n$ to ; in $tmp\n",
274
          setpre,p,setpre,setpre,setpre,prepcnt);
274
          setpre,p,setpre,setpre,setpre,prepcnt);
275
}
275
}
276
 
276
 
277
void sp_mathexp_cut(char *p, int ptype)
277
void sp_mathexp_cut(char *p, int ptype)
278
{
278
{
279
    char *p2;
279
  char *p2;
280
    p2=find_word_end(find_word_start(p)); if(isspace(*p2)) *p2++=0;
280
  p2=find_word_end(find_word_start(p)); if(isspace(*p2)) *p2++=0;
281
    p2=find_word_start(p2);
281
  p2=find_word_start(p2);
282
    fprintf(outf,"%stmp%d=!exec mathexp cut %s\\\n%s\n\n",
282
  fprintf(outf,"%stmp%d=!exec mathexp cut %s\\\n%s\n\n",
283
          setpre,prepcnt,p,p2);
283
        setpre,prepcnt,p,p2);
284
}
284
}
285
 
285
 
286
void sp_wims(char *p, int ptype)
286
void sp_wims(char *p, int ptype)
287
{
287
{
288
    p=find_word_start(p);
288
  p=find_word_start(p);
289
    if(!isalpha(*p) || strncasecmp(p,"ins",3)==0)
289
  if(!isalpha(*p) || strncasecmp(p,"ins",3)==0)
290
      fprintf(outf,"%stmp%d=%s\n\n",setpre,prepcnt,p);
290
    fprintf(outf,"%stmp%d=%s\n\n",setpre,prepcnt,p);
291
    else
291
  else
292
      fprintf(outf,"%stmp%d=!%s\n\n",setpre,prepcnt,p);
292
    fprintf(outf,"%stmp%d=!%s\n\n",setpre,prepcnt,p);
293
}
293
}
294
 
294
 
295
struct specialfn specialfn[]={
295
struct specialfn specialfn[]={
296
      {"asis",  sp_asis},
296
  {"asis",  sp_asis},
297
      {"canvasdraw", sp_canvasdraw},
297
  {"canvasdraw", sp_canvasdraw},
298
      {"column", sp_column},
298
  {"column", sp_column},
299
      {"deriv",  sp_diff},
299
  {"deriv",  sp_diff},
300
      {"derivative", sp_diff},
300
  {"derivative", sp_diff},
301
      {"det",  sp_det},
301
  {"det",  sp_det},
302
      {"determinant", sp_det},
302
  {"determinant", sp_det},
303
      {"diff",  sp_diff},
303
  {"diff",  sp_diff},
304
      {"draw",  sp_draw},
304
  {"draw",  sp_draw},
305
      {"evaluate", sp_evalue},
305
  {"evaluate", sp_evalue},
306
      {"evalue", sp_evalue},
306
  {"evalue", sp_evalue},
307
      {"htmlmath", sp_htmlmath},
307
  {"htmlmath", sp_htmlmath},
308
      {"int",  sp_int},
308
  {"int",  sp_int},
309
      {"integral", sp_int},
309
  {"integral", sp_int},
310
      {"integrate", sp_int},
310
  {"integrate", sp_int},
311
      {"item",  sp_item},
311
  {"item",  sp_item},
312
      {"items",  sp_items},
312
  {"items",  sp_items},
313
      {"mathexp_cut", sp_mathexp_cut},
313
  {"mathexp_cut", sp_mathexp_cut},
314
      {"maxima", sp_maxima},
314
  {"maxima", sp_maxima},
315
      {"pari",  sp_pari},
315
  {"pari",  sp_pari},
316
      {"pickone", sp_pickone},
316
  {"pickone", sp_pickone},
317
      {"position", sp_positionof},
317
  {"position", sp_positionof},
318
      {"positionof", sp_positionof},
318
  {"positionof", sp_positionof},
319
      {"randint", sp_pickone},
319
  {"randint", sp_pickone},
320
      {"randitem", sp_randitem},
320
  {"randitem", sp_randitem},
321
      {"random", sp_random},
321
  {"random", sp_random},
322
      {"randomitem", sp_randitem},
322
  {"randomitem", sp_randitem},
323
      {"randomrow", sp_randrow},
323
  {"randomrow", sp_randrow},
324
      {"randrow", sp_randrow},
324
  {"randrow", sp_randrow},
325
      {"row",  sp_row},
325
  {"row",  sp_row},
326
      {"rows",  sp_rows},
326
  {"rows",  sp_rows},
327
      {"shuffle", sp_shuffle},
327
  {"shuffle", sp_shuffle},
328
      {"simplify", sp_simplify},
328
  {"simplify", sp_simplify},
329
      {"slib",  sp_slib},
329
  {"slib",  sp_slib},
330
      {"solve",  sp_solve},
330
  {"solve",  sp_solve},
331
      {"teximg", sp_teximg},
331
  {"teximg", sp_teximg},
332
      {"texmath", sp_texmath},
332
  {"texmath", sp_texmath},
333
      {"wims",  sp_wims},
333
  {"wims",  sp_wims},
334
      {"yacas", sp_yacas}
334
  {"yacas", sp_yacas}
335
};
335
};
336
int specialfn_no=(sizeof(specialfn)/sizeof(specialfn[0]));
336
int specialfn_no=(sizeof(specialfn)/sizeof(specialfn[0]));
337
 
337
 
338
/* This routine treats special functions */
338
/* This routine treats special functions */
339
void parmprep(char *p,int ptype)
339
void parmprep(char *p,int ptype)
340
{
340
{
341
    char *pp, *p2, *pn, namebuf[32], buf[MAX_LINELEN+1];
341
  char *pp, *p2, *pn, namebuf[32], buf[MAX_LINELEN+1];
342
    int i;
342
  int i;
343
 
343
 
344
    while((pp=strchr(p,'\n'))!=NULL) *pp='      ';
344
  while((pp=strchr(p,'\n'))!=NULL) *pp='        ';
345
    for(pp=p;*pp && pp-p<MAX_LINELEN;pp++) {
345
  for(pp=p;*pp && pp-p<MAX_LINELEN;pp++) {
346
/* function names */
346
/* function names */
347
      if(isalpha(*pp)) {
347
    if(isalpha(*pp)) {
348
          for(i=0;i<30 && (isalnum(pp[i]) || pp[i]=='_');i++) namebuf[i]=pp[i];
348
      for(i=0;i<30 && (isalnum(pp[i]) || pp[i]=='_');i++) namebuf[i]=pp[i];
349
          namebuf[i]=0; p2=find_word_start(pp+i);
349
      namebuf[i]=0; p2=find_word_start(pp+i);
350
          if((pp>p && isalnum(*(pp-1))) || *p2!='(') {
350
      if((pp>p && isalnum(*(pp-1))) || *p2!='(') {
351
/* if(*p2=='\\' && *(p2+1)=='(') ovlstrcpy(p2,p2+1); */
351
/* if(*p2=='\\' && *(p2+1)=='(') ovlstrcpy(p2,p2+1); */
352
            pp=p2-1; continue;
352
        pp=p2-1; continue;
353
          }
353
      }
354
          pn=pp; pp=p2+1; p2=find_matching(pp,')');
354
      pn=pp; pp=p2+1; p2=find_matching(pp,')');
355
          if(p2==NULL) {
355
      if(p2==NULL) {
356
            sp_error("unmatched_parentheses");
356
        sp_error("unmatched_parentheses");
357
            pp=p2; continue;
357
        pp=p2; continue;
358
          }
358
      }
359
          i=search_list(specialfn,specialfn_no,sizeof(specialfn[0]),namebuf);
359
      i=search_list(specialfn,specialfn_no,sizeof(specialfn[0]),namebuf);
360
          if(i<0) {
360
      if(i<0) {
361
            pp--; continue;
361
        pp--; continue;
362
          }
-
 
363
          *p2=0;
-
 
364
          snprintf(buf,sizeof(buf),"%s",pp);
-
 
365
          if(specialfn[i].processor!=sp_asis) parmprep(buf,ptype);
-
 
366
          specialfn[i].processor(buf,ptype);
-
 
367
          string_modify(p, pn, p2+1, "$(tmp%d)",prepcnt); prepcnt++;
-
 
368
          pp=pn+6;
-
 
369
      }
362
      }
-
 
363
      *p2=0;
-
 
364
      snprintf(buf,sizeof(buf),"%s",pp);
-
 
365
      if(specialfn[i].processor!=sp_asis) parmprep(buf,ptype);
-
 
366
      specialfn[i].processor(buf,ptype);
-
 
367
      string_modify(p, pn, p2+1, "$(tmp%d)",prepcnt); prepcnt++;
-
 
368
      pp=pn+6;
370
    }
369
    }
-
 
370
  }
371
}
371
}
372
 
372