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