Rev 8529 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 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 | |||
7674 | bpr | 18 | /* Interface Yacas to wims */ |
10 | reyssat | 19 | |
20 | /*************** Customization: change values hereafter ****************/ |
||
8120 | bpr | 21 | #include "common.h" |
10 | reyssat | 22 | |
7674 | bpr | 23 | /* This is yacas home page. To be kept up to date. */ |
10 | reyssat | 24 | #define homepage "http://yacas.sourceforge.net/" |
7674 | bpr | 25 | /* String to tell the program to quit. */ |
8120 | bpr | 26 | char *quitstring="\nquit\n"; |
7674 | bpr | 27 | /* The way to print a string in the program. */ |
8120 | bpr | 28 | char *stringprinter="\"%s\"\n"; |
7674 | bpr | 29 | /* limit of input/output file sizes */ |
10 | reyssat | 30 | int fsizelim=131072; |
8120 | bpr | 31 | int precision=20; /* default */ |
10 | reyssat | 32 | |
33 | char *inprompt="\nIn>"; |
||
34 | char *outprompt="Out>"; |
||
35 | |||
36 | char *nameofcmd="yacas -p"; |
||
37 | |||
8137 | bpr | 38 | char *firstupper[]={ |
39 | "abs", |
||
40 | "and", |
||
41 | "arg", |
||
42 | "complex", |
||
43 | "conjugate", |
||
44 | "cos", |
||
45 | "cosh", |
||
46 | "cot", |
||
47 | "coth", |
||
48 | "csc", |
||
49 | "csch", |
||
50 | "denom", |
||
51 | "echo", |
||
52 | "exp", |
||
53 | "factor", |
||
54 | "factorize", |
||
55 | "for", |
||
56 | "i", |
||
57 | "if", |
||
58 | "im", |
||
59 | "infinity", |
||
60 | "integrate", |
||
61 | "limit", |
||
62 | "ln", |
||
63 | "max", |
||
64 | "min", |
||
65 | "not", |
||
66 | "or", |
||
67 | "pi", |
||
68 | "print", |
||
69 | "random", |
||
70 | "re", |
||
71 | "round", |
||
72 | "sec", |
||
73 | "sech", |
||
74 | "sign", |
||
75 | "simplify", |
||
76 | "sin", |
||
77 | "sinh", |
||
78 | "solve", |
||
79 | "sqrt", |
||
80 | "tan", |
||
81 | "tanh", |
||
82 | "undefined", |
||
83 | "until", |
||
84 | "while", |
||
85 | }; |
||
86 | int firstupperno=(sizeof(firstupper)/sizeof(firstupper[0])); |
||
10 | reyssat | 87 | |
8137 | bpr | 88 | char header[]="\ |
89 | tg(x) := Tan(x)\n\ |
||
90 | log(x) := Ln(x)\n\ |
||
91 | e := Exp(1)\n\ |
||
92 | E := Exp(1)\n\ |
||
93 | sgn(x) := Sign(x)\n\ |
||
94 | ch(x) := Cosh(x)\n\ |
||
95 | sh(x) := Sinh(x)\n\ |
||
96 | th(x) := Tanh(x)\n\ |
||
97 | acos(x) := ArcCos(x)\n\ |
||
98 | arccos(x) := ArcCos(x)\n\ |
||
99 | asin(x) := ArcSin(x)\n\ |
||
100 | arcsin(x) := ArcSin(x)\n\ |
||
101 | atan(x) := ArcTan(x)\n\ |
||
102 | arctan(x) := ArcTan(x)\n\ |
||
103 | arctg(x) := ArcTan(x)\n\ |
||
104 | Argch(x) := ArcCosh(x)\n\ |
||
105 | argch(x) := ArcCosh(x)\n\ |
||
106 | acosh(x) := ArcCosh(x)\n\ |
||
107 | Argsh(x) := ArcSinh(x)\n\ |
||
108 | argsh(x) := ArcSinh(x)\n\ |
||
109 | asinh(x) := ArcSinh(x)\n\ |
||
110 | Argth(x) := ArcTanh(x)\n\ |
||
111 | argth(x) := ArcTanh(x)\n\ |
||
112 | atanh(x) := ArcTanh(x)\n\ |
||
113 | ctg(x) := Cot(x)\n\ |
||
114 | rint(x) := Round(x)\n\ |
||
115 | RANDOM() := Random()\n\ |
||
116 | SOLVE(x,y) := Solve(x,y)\n\ |
||
117 | "; |
||
118 | |||
119 | |||
10 | reyssat | 120 | struct { |
8137 | bpr | 121 | char *wname; char *defaultval; char *yacasset; |
10 | reyssat | 122 | } setups[]={ |
7674 | bpr | 123 | {"w_yacas_precision", "20", "\\precision=",}, |
124 | {"w_yacas_serieslength", "8", "\\serieslength="} |
||
10 | reyssat | 125 | }; |
126 | |||
7674 | bpr | 127 | /* names which are not allowed */ |
10 | reyssat | 128 | char *illegal[]={ |
129 | "SystemCall", "Use", "Vi", "GetYacasPID", "ShowPS", |
||
130 | "MakeFunctionPlugin" |
||
131 | }; |
||
132 | |||
8120 | bpr | 133 | int illegal_no=(sizeof(illegal)/sizeof(illegal[0])); |
134 | |||
7674 | bpr | 135 | /* name parts which are not allowed */ |
136 | /* 11/3/2013 add "@" and "ConcatStrings" */ |
||
10 | reyssat | 137 | char *illpart[]={ |
6421 | schaersvoo | 138 | "File", "Load", "Plot","ConcatStrings" ,"@" |
10 | reyssat | 139 | }; |
140 | |||
8120 | bpr | 141 | int illpart_no=(sizeof(illpart)/sizeof(illpart[0])); |
142 | |||
10 | reyssat | 143 | /***************** Nothing should need change hereafter *****************/ |
144 | |||
8120 | bpr | 145 | char *progname="yacas"; |
10 | reyssat | 146 | |
7674 | bpr | 147 | /* check for security violations in command string */ |
10 | reyssat | 148 | void check_parm(char *pm) |
149 | { |
||
150 | char *p, *pp, *p2, buf[16]; |
||
151 | int i; |
||
7674 | bpr | 152 | |
10 | reyssat | 153 | for(p=pm;*p!=0;p++) { |
7674 | bpr | 154 | if(*p!='\\') continue; |
155 | if(*(p+1)=='\n') *p=*(p+1)=' '; |
||
156 | if(*(p+1)==0) *p=' '; |
||
10 | reyssat | 157 | } |
158 | for(p=pm; *p!=0; p++) { |
||
7674 | bpr | 159 | if(!isalpha(*p)) continue; |
160 | for(p2=p+1; isalpha(*p2); p2++); |
||
161 | if(p2-p>10) {p=p2-1; continue;} |
||
162 | memmove(buf,p,p2-p); buf[p2-p]=0; pp=p; p=p2-1; |
||
163 | for(p2=buf; islower(*p2); p2++); |
||
164 | if(*p2) continue; |
||
165 | i=search_list(firstupper,firstupperno,sizeof(firstupper[0]),buf); |
||
166 | if(i>=0) *pp=toupper(*pp); |
||
10 | reyssat | 167 | } |
168 | find_illegal(pm); |
||
169 | } |
||
170 | |||
171 | |||
7674 | bpr | 172 | /* process and print yacas output */ |
10 | reyssat | 173 | void output(char *p) |
174 | { |
||
175 | int i,n; |
||
176 | char *pp, *pe, *p1, *pt; |
||
177 | char outbuf[MAX_LINELEN+1]; |
||
7674 | bpr | 178 | |
10 | reyssat | 179 | pp=strstr(p,inprompt); if(pp==NULL) return; |
180 | while(pp!=NULL && *pp!=0) { |
||
7674 | bpr | 181 | pp+=strlen(inprompt); p1=find_word_start(pp); |
182 | pe=strstr(pp,outprompt); |
||
183 | pt=strstr(pp,inprompt); |
||
184 | if(pe==NULL || (pt!=NULL && pt<pe)) { /* error */ |
||
185 | if(pt==NULL) pp=pp+strlen(pp); else pp=pt; |
||
186 | n=pp-p1; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0; |
||
187 | memmove(outbuf,p1,n); outbuf[n]=0; |
||
188 | fprintf(stderr,"%s\n",outbuf); |
||
189 | puts(""); continue; |
||
190 | } |
||
191 | else { |
||
192 | *pe=0; pe=find_word_start(pe+strlen(outprompt)); |
||
193 | } |
||
194 | pp=strstr(pe,inprompt); |
||
195 | if(pp==NULL) pp=pe+strlen(pe); |
||
196 | if(*p1==0) { |
||
197 | if(pp>=pe+sizeof(outbuf)) break; |
||
198 | n=pp-pe; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0; |
||
199 | memmove(outbuf,pe,n); outbuf[n]=0; |
||
200 | } |
||
201 | else { |
||
202 | snprintf(outbuf,sizeof(outbuf),"%s",p1); |
||
203 | n=strlen(outbuf); |
||
204 | } |
||
205 | /* make every output one-line */ |
||
206 | for(i=0;i<n;i++) { |
||
207 | if(outbuf[i]=='\n') outbuf[i]=' '; |
||
208 | } |
||
209 | /* strip leading and trailing spaces */ |
||
210 | for(i=n-1;i>=0 && isspace(outbuf[i]); i--) outbuf[i]=0; |
||
211 | if(outbuf[i]==';') outbuf[i]=0; |
||
212 | for(pe=outbuf; *pe; pe++) if(isupper(*pe)) *pe=tolower(*pe); |
||
213 | for(pe=outbuf; isspace(*pe); pe++); |
||
214 | /* strip_zeros(pe); */ |
||
215 | puts(pe); |
||
10 | reyssat | 216 | } |
217 | } |
||
218 | |||
219 | void about(void) |
||
220 | { |
||
221 | cmdparm="-v"; prepabout("",outputfname,NULL); |
||
222 | if(readabout()>0) |
||
8529 | bpr | 223 | printf("<a target=\"wims_external\" href=\"%s\" >Yacas %s</a>",homepage,aboutbuf); |
10 | reyssat | 224 | } |
225 | |||
226 | char *dynsetup(char *ptr, char *end) |
||
227 | { |
||
228 | int i; char *p, *pp; |
||
12011 | bpr | 229 | /* to adapt |
230 | if(wseed!= NULL) { |
||
231 | snprintf(ptr,end-ptr,"\nwimsseed:make_random_state(%u);\nset_random_state(wimsseed);\n",atoi(wseed)&(0x7FFFFFFF)); |
||
232 | ptr+=strlen(ptr); |
||
233 | } |
||
234 | */ for(i=0;i<SETUP_NO;i++) { |
||
7674 | bpr | 235 | p=getenv(setups[i].wname); |
236 | if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p=""; |
||
237 | if(p==NULL || *p==0) p=setups[i].defaultval; |
||
238 | if(strstr(setups[i].wname,"yacas_precision")!=NULL) |
||
239 | precision=atoi(p); |
||
240 | if(precision<0) precision=-precision; |
||
10 | reyssat | 241 | } |
242 | return ptr; |
||
243 | } |
||
244 | |||
245 | int main(int argc,char *argv[]) |
||
246 | { |
||
247 | prepare1(); |
||
248 | run(); |
||
7674 | bpr | 249 | return 0; |
10 | reyssat | 250 | } |
251 |