Rev 6421 | Rev 8120 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6421 | Rev 7674 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | * You should have received a copy of the GNU General Public License |
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 |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | */ |
16 | */ |
17 | 17 | ||
18 |
|
18 | /* Interface Yacas to wims */ |
19 | 19 | ||
20 | /*************** Customization: change values hereafter ****************/ |
20 | /*************** Customization: change values hereafter ****************/ |
21 | 21 | ||
22 |
|
22 | /* This is yacas home page. To be kept up to date. */ |
23 | #define homepage "http://yacas.sourceforge.net/" |
23 | #define homepage "http://yacas.sourceforge.net/" |
24 |
|
24 | /* String to tell the program to quit. */ |
25 | #define quitstring "\nquit\n" |
25 | #define quitstring "\nquit\n" |
26 |
|
26 | /* The way to print a string in the program. */ |
27 | #define stringprinter "\"%s\"\n" |
27 | #define stringprinter "\"%s\"\n" |
28 |
|
28 | /* limit of input/output file sizes */ |
29 | int fsizelim=131072; |
29 | int fsizelim=131072; |
30 | int precision=20; |
30 | int precision=20; /* default */ |
31 | 31 | ||
32 | char *inprompt="\nIn>"; |
32 | char *inprompt="\nIn>"; |
33 | char *outprompt="Out>"; |
33 | char *outprompt="Out>"; |
34 | 34 | ||
35 | char *nameofcmd="yacas -p"; |
35 | char *nameofcmd="yacas -p"; |
Line 37... | Line 37... | ||
37 | #include "yacasheader.c" |
37 | #include "yacasheader.c" |
38 | 38 | ||
39 | struct { |
39 | struct { |
40 | char *wname; char *defaultval; char *yacasset; |
40 | char *wname; char *defaultval; char *yacasset; |
41 | } setups[]={ |
41 | } setups[]={ |
42 | {"w_yacas_precision", |
42 | {"w_yacas_precision", "20", "\\precision=",}, |
43 | {"w_yacas_serieslength", |
43 | {"w_yacas_serieslength", "8", "\\serieslength="} |
44 | }; |
44 | }; |
45 | 45 | ||
46 |
|
46 | /* names which are not allowed */ |
47 | char *illegal[]={ |
47 | char *illegal[]={ |
48 | "SystemCall", "Use", "Vi", "GetYacasPID", "ShowPS", |
48 | "SystemCall", "Use", "Vi", "GetYacasPID", "ShowPS", |
49 | "MakeFunctionPlugin" |
49 | "MakeFunctionPlugin" |
50 | }; |
50 | }; |
51 | 51 | ||
52 |
|
52 | /* name parts which are not allowed */ |
53 |
|
53 | /* 11/3/2013 add "@" and "ConcatStrings" */ |
54 | char *illpart[]={ |
54 | char *illpart[]={ |
55 | "File", "Load", "Plot","ConcatStrings" ,"@" |
55 | "File", "Load", "Plot","ConcatStrings" ,"@" |
56 | }; |
56 | }; |
57 | 57 | ||
58 | /***************** Nothing should need change hereafter *****************/ |
58 | /***************** Nothing should need change hereafter *****************/ |
59 | 59 | ||
60 | #define progname "yacas" |
60 | #define progname "yacas" |
61 | #include "common.h" |
61 | #include "common.h" |
62 | #include "common.c" |
62 | #include "common.c" |
63 | 63 | ||
64 |
|
64 | /* check for security violations in command string */ |
65 | void check_parm(char *pm) |
65 | void check_parm(char *pm) |
66 | { |
66 | { |
67 | char *p, *pp, *p2, buf[16]; |
67 | char *p, *pp, *p2, buf[16]; |
68 | int i; |
68 | int i; |
69 | 69 | ||
70 | for(p=pm;*p!=0;p++) { |
70 | for(p=pm;*p!=0;p++) { |
71 |
|
71 | if(*p!='\\') continue; |
72 |
|
72 | if(*(p+1)=='\n') *p=*(p+1)=' '; |
73 |
|
73 | if(*(p+1)==0) *p=' '; |
74 | } |
74 | } |
75 | for(p=pm; *p!=0; p++) { |
75 | for(p=pm; *p!=0; p++) { |
76 |
|
76 | if(!isalpha(*p)) continue; |
77 |
|
77 | for(p2=p+1; isalpha(*p2); p2++); |
78 |
|
78 | if(p2-p>10) {p=p2-1; continue;} |
79 |
|
79 | memmove(buf,p,p2-p); buf[p2-p]=0; pp=p; p=p2-1; |
80 |
|
80 | for(p2=buf; islower(*p2); p2++); |
81 |
|
81 | if(*p2) continue; |
82 |
|
82 | i=search_list(firstupper,firstupperno,sizeof(firstupper[0]),buf); |
83 |
|
83 | if(i>=0) *pp=toupper(*pp); |
84 | } |
84 | } |
85 | find_illegal(pm); |
85 | find_illegal(pm); |
86 | } |
86 | } |
87 | 87 | ||
88 | 88 | ||
89 |
|
89 | /* process and print yacas output */ |
90 | void output(char *p) |
90 | void output(char *p) |
91 | { |
91 | { |
92 | int i,n; |
92 | int i,n; |
93 | char *pp, *pe, *p1, *pt; |
93 | char *pp, *pe, *p1, *pt; |
94 | char outbuf[MAX_LINELEN+1]; |
94 | char outbuf[MAX_LINELEN+1]; |
95 | 95 | ||
96 | pp=strstr(p,inprompt); if(pp==NULL) return; |
96 | pp=strstr(p,inprompt); if(pp==NULL) return; |
97 | while(pp!=NULL && *pp!=0) { |
97 | while(pp!=NULL && *pp!=0) { |
98 |
|
98 | pp+=strlen(inprompt); p1=find_word_start(pp); |
99 |
|
99 | pe=strstr(pp,outprompt); |
100 |
|
100 | pt=strstr(pp,inprompt); |
101 |
|
101 | if(pe==NULL || (pt!=NULL && pt<pe)) { /* error */ |
102 |
|
102 | if(pt==NULL) pp=pp+strlen(pp); else pp=pt; |
103 |
|
103 | n=pp-p1; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0; |
104 |
|
104 | memmove(outbuf,p1,n); outbuf[n]=0; |
105 |
|
105 | fprintf(stderr,"%s\n",outbuf); |
106 |
|
106 | puts(""); continue; |
107 |
|
107 | } |
108 |
|
108 | else { |
109 |
|
109 | *pe=0; pe=find_word_start(pe+strlen(outprompt)); |
110 |
|
110 | } |
111 |
|
111 | pp=strstr(pe,inprompt); |
112 |
|
112 | if(pp==NULL) pp=pe+strlen(pe); |
113 |
|
113 | if(*p1==0) { |
114 |
|
114 | if(pp>=pe+sizeof(outbuf)) break; |
115 |
|
115 | n=pp-pe; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0; |
116 |
|
116 | memmove(outbuf,pe,n); outbuf[n]=0; |
117 |
|
117 | } |
118 |
|
118 | else { |
119 |
|
119 | snprintf(outbuf,sizeof(outbuf),"%s",p1); |
120 |
|
120 | n=strlen(outbuf); |
121 |
|
121 | } |
122 |
|
122 | /* make every output one-line */ |
123 |
|
123 | for(i=0;i<n;i++) { |
124 |
|
124 | if(outbuf[i]=='\n') outbuf[i]=' '; |
125 |
|
125 | } |
126 |
|
126 | /* strip leading and trailing spaces */ |
127 |
|
127 | for(i=n-1;i>=0 && isspace(outbuf[i]); i--) outbuf[i]=0; |
128 |
|
128 | if(outbuf[i]==';') outbuf[i]=0; |
129 |
|
129 | for(pe=outbuf; *pe; pe++) if(isupper(*pe)) *pe=tolower(*pe); |
130 |
|
130 | for(pe=outbuf; isspace(*pe); pe++); |
131 |
|
131 | /* strip_zeros(pe); */ |
132 |
|
132 | puts(pe); |
133 | } |
133 | } |
134 | } |
134 | } |
135 | 135 | ||
136 | void about(void) |
136 | void about(void) |
137 | { |
137 | { |
138 | cmdparm="-v"; prepabout("",outputfname,NULL); |
138 | cmdparm="-v"; prepabout("",outputfname,NULL); |
139 | if(readabout()>0) |
139 | if(readabout()>0) |
140 | printf("<a href=\"%s\">Yacas %s</a>",homepage,aboutbuf); |
140 | printf("<a href=\"%s\">Yacas %s</a>",homepage,aboutbuf); |
141 | } |
141 | } |
142 | 142 | ||
143 | char *dynsetup(char *ptr, char *end) |
143 | char *dynsetup(char *ptr, char *end) |
144 | { |
144 | { |
145 | int i; char *p, *pp; |
145 | int i; char *p, *pp; |
146 | 146 | ||
147 | for(i=0;i<SETUP_NO;i++) { |
147 | for(i=0;i<SETUP_NO;i++) { |
148 |
|
148 | p=getenv(setups[i].wname); |
149 |
|
149 | if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p=""; |
150 |
|
150 | if(p==NULL || *p==0) p=setups[i].defaultval; |
151 |
|
151 | if(strstr(setups[i].wname,"yacas_precision")!=NULL) |
152 |
|
152 | precision=atoi(p); |
153 |
|
153 | if(precision<0) precision=-precision; |
154 | } |
154 | } |
155 | return ptr; |
155 | return ptr; |
156 | } |
156 | } |
157 | 157 | ||
158 | int main(int argc,char *argv[]) |
158 | int main(int argc,char *argv[]) |
159 | { |
159 | { |
160 | prepare1(); |
160 | prepare1(); |
161 | run(); |
161 | run(); |
162 | return 0; |
162 | return 0; |
163 | } |
163 | } |
164 | 164 |