Rev 4716 | Rev 8100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4716 | 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 gp to wims */ |
19 | 19 | ||
20 | /* This program is now limited to pari version 2.??. */ |
20 | /* This program is now limited to pari version 2.??. */ |
21 | 21 | ||
22 | /*************** Customization: change values hereafter ****************/ |
22 | /*************** Customization: change values hereafter ****************/ |
23 | 23 | ||
24 |
|
24 | /* gp prompt string */ |
25 | #define gpprompt "\n? " |
25 | #define gpprompt "\n? " |
26 |
|
26 | /* This is the good bye string of gp, signaling end of output. */ |
27 | #define goodbyestring "Good bye!" |
27 | #define goodbyestring "Good bye!" |
28 |
|
28 | /* This is PARI home page. To be kept up to date. */ |
29 | #define homepage "http://pari.math.u-bordeaux.fr/" |
29 | #define homepage "http://pari.math.u-bordeaux.fr/" |
30 |
|
30 | /* String to tell the program to quit. */ |
31 | #define quitstring "\nquit\n" |
31 | #define quitstring "\nquit\n" |
32 |
|
32 | /* The way to print a string in the program. */ |
33 | #define stringprinter "print(\"%s\")\n" |
33 | #define stringprinter "print(\"%s\")\n" |
34 |
|
34 | /* limit of input/output file sizes */ |
35 | int fsizelim=131072; |
35 | int fsizelim=131072; |
36 | int precision=28; |
36 | int precision=28; /* default */ |
37 | 37 | ||
38 | char *nameofcmd="gp"; |
38 | char *nameofcmd="gp"; |
39 | char *gprcenv="GPRC"; |
39 | char *gprcenv="GPRC"; |
40 | char *gprc="../.gprc"; |
40 | char *gprc="../.gprc"; |
41 | char header[]="default(output,0)\n\ |
41 | char header[]="default(output,0)\n\ |
Line 77... | Line 77... | ||
77 | "; |
77 | "; |
78 | 78 | ||
79 | struct { |
79 | struct { |
80 | char *wname; char *defaultval; char *gpset; |
80 | char *wname; char *defaultval; char *gpset; |
81 | } setups[]={ |
81 | } setups[]={ |
82 | {"w_pari_precision", |
82 | {"w_pari_precision", "20", "\\p "}, |
83 | {"w_pari_serieslength", |
83 | {"w_pari_serieslength", "8", "\\ps "} |
84 | }; |
84 | }; |
85 | 85 | ||
86 |
|
86 | /* names which are not allowed */ |
87 | char *illegal[]={ |
87 | char *illegal[]={ |
88 | }; |
88 | }; |
89 | 89 | ||
90 |
|
90 | /* name parts which are not allowed */ |
91 | char *illpart[]={ |
91 | char *illpart[]={ |
92 | "plot", "write", "help" |
92 | "plot", "write", "help" |
93 | }; |
93 | }; |
94 | 94 | ||
95 | /***************** Nothing should need change hereafter *****************/ |
95 | /***************** Nothing should need change hereafter *****************/ |
Line 98... | Line 98... | ||
98 | #include "common.h" |
98 | #include "common.h" |
99 | #include "common.c" |
99 | #include "common.c" |
100 | 100 | ||
101 | int pariray=0; |
101 | int pariray=0; |
102 | 102 | ||
103 |
|
103 | /* check for security violations in command string */ |
104 | void check_parm(char *pm) |
104 | void check_parm(char *pm) |
105 | { |
105 | { |
106 | char *p; |
106 | char *p; |
107 | for(p=pm;*p!=0;p++) { |
107 | for(p=pm;*p!=0;p++) { |
108 |
|
108 | /* Underscore replacement */ |
109 |
|
109 | if(*p=='_') {*p='K'; continue;} |
110 |
|
110 | /* no escape commands. */ |
111 |
|
111 | if(*p!='\n') continue; |
112 |
|
112 | while(*p!=0 && isspace(*p)) p++; |
113 |
|
113 | if(*p=='\\' && *(p+1)!='\\' && *(p+1)!='v' && *(p+1)!='p') *p='.'; |
114 |
|
114 | if(*p=='\\') p++; |
115 | } |
115 | } |
116 | find_illegal(pm); |
116 | find_illegal(pm); |
117 | } |
117 | } |
118 | 118 | ||
119 |
|
119 | /* process and print gp output */ |
120 | void output(char *p) |
120 | void output(char *p) |
121 | { |
121 | { |
122 | int i,n; |
122 | int i,n; |
123 | char *pp, *pe, *pt; |
123 | char *pp, *pe, *pt; |
124 | - | ||
125 | if(pariray) {puts(p); return;} |
124 | if(pariray) {puts(p); return;} |
126 | pp=strstr(p,gpprompt); if(pp==NULL) return; |
125 | pp=strstr(p,gpprompt); if(pp==NULL) return; |
127 | pe=strstr(pp,goodbyestring); |
126 | pe=strstr(pp,goodbyestring); |
128 | if(pe>=pp) *pe=0; |
127 | if(pe>=pp) *pe=0; |
129 | while(pp!=NULL) { |
128 | while(pp!=NULL) { |
130 |
|
129 | pp++; |
131 |
|
130 | pe=strstr(pp,gpprompt); |
132 |
|
131 | if(pe>=pp) *pe=0; |
133 |
|
132 | pp=strchr(pp,'\n'); |
134 |
|
133 | if(pp==NULL) { |
135 |
|
134 | emptyline: |
136 |
|
135 | puts(""); pp=pe; continue; |
137 |
|
136 | } |
138 |
|
137 | pp++; n=strlen(pp); |
139 |
|
138 | if(n==0) goto emptyline; |
140 |
|
139 | /* make every output one-line */ |
141 |
|
140 | for(i=0;i<n;i++) { |
142 |
|
141 | if(*(pp+i)=='\n') { |
143 |
|
142 | if(*(pp+i+1)!='%') *(pp+i)=' '; |
144 |
|
143 | else {*(pp+i)=0; break;} |
145 |
|
144 | } |
146 |
|
145 | } |
147 |
|
146 | /* strip leading and trailing spaces */ |
148 |
|
147 | while(isspace(*pp) && pp<pe) pp++; |
149 |
|
148 | pt=pp+strlen(pp)-1; |
150 |
|
149 | while(isspace(*pt) && pt>pp) *pt--=0; |
151 |
|
150 | /* remove parentheses of matrix output */ |
152 |
|
151 | if(memcmp(pp,"Mat(",4)==0 && *pt==')' && find_matching(pp+4,')')==pt) { |
153 |
|
152 | *(pt--)=0; pp+=4; |
154 |
|
153 | } |
155 |
|
154 | if(memcmp(pp,"Vecsmall(",9)==0 && *pt==')' && find_matching(pp+9,')')==pt) { |
156 |
|
155 | *(pt--)=0; pp+=9; |
157 |
|
156 | } |
158 |
|
157 | if(*pp=='[' && *pt==']' && find_matching(pp+1,']')==pt) { |
159 |
|
158 | *(pt--)=0; pp++; |
160 |
|
159 | } |
161 |
|
160 | strip_zeros(pp); |
162 |
|
161 | puts(pp); pp=pe; |
163 | } |
162 | } |
164 | } |
163 | } |
165 | 164 | ||
166 | void about(void) |
165 | void about(void) |
167 | { |
166 | { |
168 | char *p; |
167 | char *p; |
169 | 168 | ||
170 | prepabout("\\v\nquit\n",outputfname,NULL); |
169 | prepabout("\\v\nquit\n",outputfname,NULL); |
171 | if(readabout()>0) { |
170 | if(readabout()>0) { |
172 |
|
171 | p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0; |
173 |
|
172 | strip_trailing_spaces(aboutbuf); |
174 |
|
173 | printf("<a href=\"%s\">%s</a>",homepage,aboutbuf); |
175 | } |
174 | } |
176 | } |
175 | } |
177 | 176 | ||
178 | char *dynsetup(char *ptr, char *end) |
177 | char *dynsetup(char *ptr, char *end) |
179 | { |
178 | { |
Line 181... | Line 180... | ||
181 | char *p, *pp; |
180 | char *p, *pp; |
182 | 181 | ||
183 | snprintf(ptr,end-ptr,"\nsetrand(%u);\n",seed&(0x7FFFFFFF)); |
182 | snprintf(ptr,end-ptr,"\nsetrand(%u);\n",seed&(0x7FFFFFFF)); |
184 | ptr+=strlen(ptr); |
183 | ptr+=strlen(ptr); |
185 | for(i=0;i<SETUP_NO;i++) { |
184 | for(i=0;i<SETUP_NO;i++) { |
186 |
|
185 | p=getenv(setups[i].wname); |
187 |
|
186 | if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p=""; |
188 |
|
187 | if(p==NULL || *p==0) p=setups[i].defaultval; |
189 |
|
188 | snprintf(ptr,end-ptr,"%s%s\n",setups[i].gpset,p); |
190 |
|
189 | ptr+=strlen(ptr); |
191 |
|
190 | if(strstr(setups[i].wname,"pari_precision")!=NULL) |
192 |
|
191 | precision=atoi(p); |
193 |
|
192 | if(precision<0) precision=-precision; |
194 | } |
193 | } |
195 | if(pariray) snprintf(ptr,end-ptr,"\\e0\n"); |
194 | if(pariray) snprintf(ptr,end-ptr,"\\e0\n"); |
196 | else snprintf(ptr,end-ptr,"\\e1\n"); |
195 | else snprintf(ptr,end-ptr,"\\e1\n"); |
197 | ptr+=strlen(ptr); |
196 | ptr+=strlen(ptr); |
198 | return ptr; |
197 | return ptr; |
Line 206... | Line 205... | ||
206 | if(p!=NULL && *p!=0) {pariray=1; fsizelim=4*1024*1024;} |
205 | if(p!=NULL && *p!=0) {pariray=1; fsizelim=4*1024*1024;} |
207 | setenv(gprcenv,gprc,1); |
206 | setenv(gprcenv,gprc,1); |
208 | prepare1(); |
207 | prepare1(); |
209 | setenv("GPTMPDIR",tmp_dir,1); |
208 | setenv("GPTMPDIR",tmp_dir,1); |
210 | run(); |
209 | run(); |
211 | return 0; |
210 | return 0; |
212 | } |
211 | } |
213 | 212 |