Rev 13769 | 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 maxima to wims */ |
10 | reyssat | 19 | |
20 | /*************** Customization: change values hereafter ****************/ |
||
8120 | bpr | 21 | #include "common.h" |
10 | reyssat | 22 | |
7674 | bpr | 23 | /* limit of input/output file sizes */ |
8120 | bpr | 24 | int fsizelim=131072; |
7674 | bpr | 25 | /* This string tells maxima to exit. */ |
8120 | bpr | 26 | char *quitstring="\nquit();\n"; |
27 | char *aboutquitstring="build_info();" "\nquit();\n"; |
||
7674 | bpr | 28 | /* The way to print a string in the program. */ |
8120 | bpr | 29 | char *stringprinter="\"%s\";\n"; |
7674 | bpr | 30 | /* This is maxima home page. To be kept up to date. */ |
10 | reyssat | 31 | #define homepage "http://maxima.sourceforge.net/" |
32 | |||
33 | char *nameofcmd="maxima"; |
||
34 | int precision=20; |
||
35 | char header[]="\n\ |
||
36 | display2d:false;\n\ |
||
37 | letrat:true;\n\ |
||
38 | keepfloat:true;\n\ |
||
39 | rombergmin:5;\n\ |
||
40 | rombergtol:1.E-6;\n\ |
||
41 | rombergit:13;\n\ |
||
42 | simpsum:true;\n\ |
||
43 | triginverses:true; logabs:true;\n\ |
||
3608 | bpr | 44 | e:%e;pi:%pi;Pi:%pi;PI:%pi;I:%i;i:%i;\n\ |
10 | reyssat | 45 | ln:log;sh:sinh;ch:cosh;th:tanh;\n\ |
46 | arctan:atan;arcsin:asin;arccos:acos;\n\ |
||
47 | tg:tan;arctg:atan;\n\ |
||
48 | argsh:asinh;argch:acosh;argth:atanh;\n\ |
||
49 | Argsh:asinh;Argch:acosh;Argth:atanh;\n\ |
||
50 | cotan:cot;ctg:cot;\n\ |
||
13769 | bpr | 51 | log10(x):=block([],return(log(x)/log(10)));\n\ |
52 | log2(x):=block([],return(log(x)/log(2)));\n\ |
||
10 | reyssat | 53 | lg(x):=log10(x);\n\ |
54 | sgn:sign;\n\ |
||
55 | nolabels:true; kill(labels);\n\ |
||
56 | "; |
||
57 | |||
58 | struct { |
||
7674 | bpr | 59 | char *wname; char *defaultval; char *setname; |
10 | reyssat | 60 | } setups[]={ |
7674 | bpr | 61 | {"w_maxima_precision", "20", "fpprec"} |
10 | reyssat | 62 | }; |
63 | |||
7674 | bpr | 64 | /* names which are not allowed */ |
10 | reyssat | 65 | char *illegal[]={ |
66 | "system","describe","example", |
||
67 | "save","fassave","stringout","batcon", |
||
68 | "batcount","cursordisp", |
||
69 | "direc","readonly","with_stdout","pscom", |
||
70 | "demo","ttyintfun","bug" |
||
7674 | bpr | 71 | |
10 | reyssat | 72 | }; |
73 | |||
8120 | bpr | 74 | int illegal_no=(sizeof(illegal)/sizeof(illegal[0])); |
75 | |||
7674 | bpr | 76 | /* name parts which are not allowed */ |
10 | reyssat | 77 | char *illpart[]={ |
78 | "file", "debug", "plot", "load", "store", "batch" |
||
79 | }; |
||
80 | |||
8120 | bpr | 81 | int illpart_no=(sizeof(illpart)/sizeof(illpart[0])); |
82 | |||
10 | reyssat | 83 | /***************** Nothing should need change hereafter *****************/ |
84 | |||
85 | #define linebyline "\n(%i" |
||
8120 | bpr | 86 | char *progname="maxima"; |
10 | reyssat | 87 | |
7674 | bpr | 88 | /* check for security violations in command string */ |
10 | reyssat | 89 | void check_parm(char *pm) |
90 | { |
||
91 | char *s, *pp; |
||
92 | int l; |
||
7674 | bpr | 93 | /* Underscore replacement */ |
10 | reyssat | 94 | for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K'; |
7674 | bpr | 95 | /* '?' escapes to Lisp commands. */ |
17674 | bpr | 96 | for(pp=strchr(pm,'?'); pp!=NULL; pp=strchr(pp+1,'?')) *pp=' '; |
97 | /* if(strchr(pm,'?')!=NULL) { |
||
98 | fprintf(stderr,"Illegal under WIMS.\n"); exit(1); |
||
99 | }*/ |
||
10 | reyssat | 100 | for(s=pm;*s;s++) *s=tolower(*s); |
8100 | bpr | 101 | strip_trailing_spaces2(pm); l=strlen(pm); |
10 | reyssat | 102 | if(l>0 && pm[l-1]!=';') strcat(pm,";"); |
103 | find_illegal(pm); |
||
104 | } |
||
105 | |||
106 | char *find_prompt(char *p, char t) |
||
107 | { |
||
108 | char *pp=p-1, *pt; |
||
109 | char c; |
||
110 | int add; |
||
111 | redo: |
||
112 | if(*p==0 || (pp>=p && *pp==0)) return NULL; |
||
113 | add=3; |
||
114 | do { |
||
7674 | bpr | 115 | pp=strstr(pp+1,"\n("); |
116 | if(!pp) break; |
||
117 | c=pp[2]; add=3; |
||
118 | if(c=='\%') { /* backward compatibility */ |
||
119 | add++; c=pp[3]; |
||
120 | if(c=='i') c='C'; |
||
121 | if(c=='o') c='D'; |
||
122 | } |
||
10 | reyssat | 123 | } |
124 | while(c!=t); |
||
125 | pt=pp; |
||
126 | if(pp!=NULL) { |
||
7674 | bpr | 127 | pp+=add; while(isdigit(*pp)) pp++; |
128 | if(*pp!=')') goto redo; |
||
129 | pp++; |
||
10 | reyssat | 130 | } |
131 | if(pt!=NULL && t=='D') pt=pp; |
||
132 | return pt; |
||
133 | } |
||
134 | |||
7674 | bpr | 135 | /* process and print maxima output */ |
10 | reyssat | 136 | void output(char *p) |
137 | { |
||
138 | int i,n; |
||
139 | char *pp, *pe, *pt; |
||
140 | |||
141 | pp=find_prompt(p,'C'); |
||
142 | while(pp!=NULL) { |
||
7674 | bpr | 143 | pe=find_prompt(pp+1,'C'); pp=find_prompt(pp,'D'); |
144 | if(pp==NULL) return; |
||
145 | if(pe!=NULL && pp>=pe) goto emptyline; |
||
146 | if(pe==NULL) pe=pp+strlen(pp); else *pe++=0; |
||
147 | if(pp>=pe) { |
||
148 | emptyline: |
||
149 | puts(""); pp=pe; continue; |
||
150 | } |
||
151 | n=strlen(pp); if(n==0) goto emptyline; |
||
152 | /* make every output one-line */ |
||
153 | for(i=0;i<n;i++) { |
||
154 | if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' '; |
||
155 | else *(pp+i)=tolower(*(pp+i)); |
||
156 | } |
||
157 | /* strip leading and trailing spaces */ |
||
158 | while(isspace(*pp) && pp<pe) pp++; |
||
159 | pt=pp+strlen(pp)-1; |
||
160 | while(isspace(*pt) && pt>pp) *pt--=0; |
||
8100 | bpr | 161 | if(*pp=='[' && *pt==']' && find_matching2(pp+1,']')==pt) { |
7674 | bpr | 162 | *(pt--)=0; pp++; |
163 | } |
||
164 | for(pt=strchr(pp,'b');pt!=NULL; pt=strchr(pt+1,'b')) { |
||
165 | if(pt>pp && isdigit(*(pt-1)) && |
||
166 | (*(pt+1)=='-' || isdigit(*(pt+1)))) { |
||
167 | if(*(pt+1)=='0' && !isdigit(*(pt+2))) ovlstrcpy(pt,pt+2); |
||
168 | else *pt='E'; |
||
169 | } |
||
170 | } |
||
171 | puts(pp); pp=pe; |
||
10 | reyssat | 172 | } |
173 | } |
||
174 | |||
175 | void about(void) |
||
176 | { |
||
177 | char *p, *p2, *pp; |
||
178 | int i; |
||
179 | |||
5762 | bpr | 180 | /* printf("<a href=\"%s\">Maxima</a>",homepage); return; */ |
8120 | bpr | 181 | prepabout(aboutquitstring,outputfname,NULL); |
10 | reyssat | 182 | if(readabout()>0) { |
7674 | bpr | 183 | for(p=aboutbuf; *p; p=find_word_start(find_word_end(p))) { |
184 | if(strncasecmp(p,"Maxima",strlen("Maxima"))==0) { |
||
185 | p2=find_word_start(find_word_end(p)); |
||
186 | if(strncmp(p2,"restarted",9)!=0) break; |
||
187 | } |
||
188 | } |
||
189 | for(p2=p;*p2 && *p2!='\n' && !isdigit(*p2);p2++); |
||
190 | if(isdigit(*p2)) pp=find_word_end(p2); |
||
191 | else for(i=0, pp=p;i<2;i++) pp=find_word_end(find_word_start(pp)); |
||
192 | *pp=0; |
||
8529 | bpr | 193 | if(*p!=0) printf("<a target=\"wims_external\" href=\"%s\">%s</a>",homepage,p); |
10 | reyssat | 194 | } |
195 | } |
||
196 | |||
197 | char *dynsetup(char *ptr, char *end) |
||
198 | { |
||
199 | int i; |
||
200 | char *p, *pp; |
||
12011 | bpr | 201 | if(wseed!= NULL) { |
202 | snprintf(ptr,end-ptr,"\nwimsseed:make_random_state(%u);\nset_random_state(wimsseed);\n",atoi(wseed)&(0x7FFFFFFF)); |
||
203 | ptr+=strlen(ptr); |
||
204 | } |
||
10 | reyssat | 205 | for(i=0;i<SETUP_NO;i++) { |
7674 | bpr | 206 | p=getenv(setups[i].wname); |
207 | if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p=""; |
||
208 | if(p==NULL || *p==0) p=setups[i].defaultval; |
||
209 | snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p); |
||
210 | ptr+=strlen(ptr); |
||
211 | if(strstr(setups[i].wname,"maxima_precision")!=NULL) |
||
212 | precision=atoi(p); |
||
213 | if(precision<0) precision=-precision; |
||
10 | reyssat | 214 | } |
215 | return ptr; |
||
216 | } |
||
217 | |||
218 | int main(int argc,char *argv[]) |
||
219 | { |
||
220 | prepare1(); |
||
221 | run(); |
||
7674 | bpr | 222 | return 0; |
10 | reyssat | 223 | } |
224 |