Rev 3898 | Rev 8100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3898 | 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 Macaulay2 to wims */ |
19 | 19 | ||
20 | /*************** Customization: change values hereafter ****************/ |
20 | /*************** Customization: change values hereafter ****************/ |
21 | 21 | ||
22 |
|
22 | /* limit of input/output file sizes */ |
23 | #define fsizelim 131072 |
23 | #define fsizelim 131072 |
24 |
|
24 | /* This string tells m2 to exit. */ |
25 | #define quitstring "\nexit;\n" |
25 | #define quitstring "\nexit;\n" |
26 |
|
26 | /* The way to print a string in the program. */ |
27 | #define stringprinter "print(\"%s\");\n" |
27 | #define stringprinter "print(\"%s\");\n" |
28 |
|
28 | /* This is m2 home page. To be kept up to date. */ |
29 | #define homepage "http://www.math.uiuc.edu/Macaulay2/" |
29 | #define homepage "http://www.math.uiuc.edu/Macaulay2/" |
30 | 30 | ||
31 | char *nameofcmd="M2"; |
31 | char *nameofcmd="M2"; |
32 | int precision=20; |
32 | int precision=20; /* default */ |
33 | char header[]="Thing#{Standard,BeforePrint} = toString; \ |
33 | char header[]="Thing#{Standard,BeforePrint} = toString; \ |
34 | scan(methods {Standard,AfterPrint}, (a,b) -> installMethod(a,b,identity));\ |
34 | scan(methods {Standard,AfterPrint}, (a,b) -> installMethod(a,b,identity));\ |
35 | "; |
35 | "; |
36 | 36 | ||
37 | struct { |
37 | struct { |
38 | char *wname; |
38 | char *wname; char *defaultval; char *setname; |
39 | } setups[]={ |
39 | } setups[]={ |
40 | /* |
40 | /* {"w_m2_precision", "20", "fpprec"} |
41 | */}; |
41 | */}; |
42 | 42 | ||
43 |
|
43 | /* names which are not allowed */ |
44 | char *illegal[]={ |
44 | char *illegal[]={ |
45 | "exec","run","fork", |
45 | "exec","run","fork", |
46 | "input", /* "load","needs", */ |
46 | "input", /* "load","needs", */ |
47 | "tmpname", "path", "processID", |
47 | "tmpname", "path", "processID", |
48 | "getWWW", "getenv", |
48 | "getWWW", "getenv", |
49 | "<<", "close" |
49 | "<<", "close" |
50 | }; |
50 | }; |
51 | 51 | ||
52 |
|
52 | /* name parts which are not allowed */ |
53 | char *illpart[]={ |
53 | char *illpart[]={ |
54 | }; |
54 | }; |
55 | 55 | ||
56 | /***************** Nothing should need change hereafter *****************/ |
56 | /***************** Nothing should need change hereafter *****************/ |
57 | 57 | ||
58 | #define progname "m2" |
58 | #define progname "m2" |
59 | #include "common.h" |
59 | #include "common.h" |
60 | #include "common.c" |
60 | #include "common.c" |
61 | 61 | ||
62 |
|
62 | /* check for security violations in command string */ |
63 | void check_parm(char *pm) |
63 | void check_parm(char *pm) |
64 | { |
64 | { |
65 | find_illegal(pm); |
65 | find_illegal(pm); |
66 | } |
66 | } |
67 | 67 | ||
Line 71... | Line 71... | ||
71 | redo: |
71 | redo: |
72 | if(*pp==0) return NULL; |
72 | if(*pp==0) return NULL; |
73 | pp=strstr(pp,"\ni"); |
73 | pp=strstr(pp,"\ni"); |
74 | pt=pp; |
74 | pt=pp; |
75 | if(pp!=NULL) { |
75 | if(pp!=NULL) { |
76 |
|
76 | pp+=2; while(isdigit(*pp)) pp++; |
77 |
|
77 | if(*pp!=' ') goto redo; |
78 |
|
78 | while(*pp==' ') pp++; |
79 |
|
79 | if(*pp!=':' || *(pp+1)!=' ') goto redo; |
80 | } |
80 | } |
81 | return pt; |
81 | return pt; |
82 | } |
82 | } |
83 | 83 | ||
84 |
|
84 | /* process and print m2 output */ |
85 | void output(char *p) |
85 | void output(char *p) |
86 | { |
86 | { |
87 | int i,n; |
87 | int i,n; |
88 | char *pp, *pe, *pt; |
88 | char *pp, *pe, *pt; |
89 | 89 | ||
90 | pp=find_prompt(p); |
90 | pp=find_prompt(p); |
91 | while(pp!=NULL && *pp!=0) { |
91 | while(pp!=NULL && *pp!=0) { |
92 |
|
92 | pe=find_prompt(pp+1); pp=strchr(pp+1,'\n'); |
93 |
|
93 | if(pp==NULL) return; |
94 |
|
94 | if(pe==NULL) pe=pp+strlen(pp); else *pe++=0; |
95 |
|
95 | pp++; |
96 |
|
96 | if(strlen(pp)==0) { |
97 |
|
97 | emptyline: |
98 |
|
98 | puts(""); pp=pe; continue; |
99 |
|
99 | } |
100 |
|
100 | n=strlen(pp); if(n==0) goto emptyline; |
101 |
|
101 | /* strip leading and trailing spaces */ |
102 |
|
102 | while(isspace(*pp) && pp<pe) pp++; |
103 |
|
103 | pt=pp+strlen(pp)-1; |
104 |
|
104 | while(pt>=pp && isspace(*pt)) *pt--=0; |
105 |
|
105 | /* make every output one-line */ |
106 |
|
106 | for(i=0;i<n;i++) { |
107 |
|
107 | if(*(pp+i)=='\n') *(pp+i)='#'; |
108 |
|
108 | } |
109 |
|
109 | puts(pp); pp=pe; |
110 | } |
110 | } |
111 | } |
111 | } |
112 | 112 | ||
113 | void about(void) |
113 | void about(void) |
114 | { |
114 | { |
115 | char *p; |
115 | char *p; |
116 | 116 | ||
117 | cmdparm=""; prepabout(quitstring,"/dev/null",outputfname); |
117 | cmdparm=""; prepabout(quitstring,"/dev/null",outputfname); |
118 | if(readabout()>0) { |
118 | if(readabout()>0) { |
119 |
|
119 | p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0; |
120 |
|
120 | strip_trailing_spaces(aboutbuf); |
121 |
|
121 | printf("<a href=\"%s\">%s</a>",homepage,aboutbuf); |
122 | } |
122 | } |
123 | } |
123 | } |
124 | 124 | ||
125 | char *dynsetup(char *ptr, char *end) |
125 | char *dynsetup(char *ptr, char *end) |
126 | { |
126 | { |
127 | int i; |
127 | int i; |
128 | char *p, *pp; |
128 | char *p, *pp; |
129 | 129 | ||
130 | for(i=0;i<SETUP_NO;i++) { |
130 | for(i=0;i<SETUP_NO;i++) { |
131 |
|
131 | p=getenv(setups[i].wname); |
132 |
|
132 | if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p=""; |
133 |
|
133 | if(p==NULL || *p==0) p=setups[i].defaultval; |
134 |
|
134 | snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p); |
135 |
|
135 | ptr+=strlen(ptr); |
136 |
|
136 | if(strstr(setups[i].wname,"m2_precision")!=NULL) |
137 |
|
137 | precision=atoi(p); |
138 |
|
138 | if(precision<0) precision=-precision; |
139 | } |
139 | } |
140 | return ptr; |
140 | return ptr; |
141 | } |
141 | } |
142 | 142 | ||
143 | int main(int argc,char *argv[]) |
143 | int main(int argc,char *argv[]) |
144 | { |
144 | { |
145 | prepare1(); |
145 | prepare1(); |
146 | run(); |
146 | run(); |
147 | return 0; |
147 | return 0; |
148 | } |
148 | } |
149 | 149 |