Rev 5762 | Rev 8100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5762 | 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 Scilab 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 scilab to exit. */ |
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 | /* This is scilab home page. To be kept up to date. */ |
29 | #define homepage "http://www.scilab.org/" |
29 | #define homepage "http://www.scilab.org/" |
30 |
|
30 | /* String to search for answers */ |
31 | 31 | ||
32 | // old chroot: char ans_str[]="\n-->"; |
32 | // old chroot: char ans_str[]="\n-->"; |
33 | char ans_str[]="\n"; |
33 | char ans_str[]="\n"; |
34 | 34 | ||
35 | char *nameofcmd="scilab -nw -ns"; |
35 | char *nameofcmd="scilab -nw -ns"; |
36 | int precision=9; |
36 | int precision=9; |
37 | char header[]="\ |
37 | char header[]="\ |
38 | "; |
38 | "; |
39 | 39 | ||
40 | struct { |
40 | struct { |
41 | char *wname; |
41 | char *wname; char *defaultval; char *setname; |
42 | } setups[]={ |
42 | } setups[]={ |
43 |
|
43 | {"w_scilab_precision", "9", "output_precision"} |
44 | }; |
44 | }; |
45 | 45 | ||
46 |
|
46 | /* names which are not allowed */ |
47 | char *illegal[]={ |
47 | char *illegal[]={ |
48 | }; |
48 | }; |
49 | 49 | ||
50 |
|
50 | /* name parts which are not allowed */ |
51 | char *illpart[]={ |
51 | char *illpart[]={ |
52 | }; |
52 | }; |
53 | 53 | ||
54 | /***************** Nothing should need change hereafter *****************/ |
54 | /***************** Nothing should need change hereafter *****************/ |
55 | 55 | ||
56 | #define progname "scilab" |
56 | #define progname "scilab" |
57 | #include "common.h" |
57 | #include "common.h" |
58 | #include "common.c" |
58 | #include "common.c" |
59 | 59 | ||
60 |
|
60 | /* check for security violations in command string */ |
61 | void check_parm(char *p) |
61 | void check_parm(char *p) |
62 | { |
62 | { |
63 | char *pp, *s; |
63 | char *pp, *s; |
64 | - | ||
65 |
|
64 | /* Underscore replacement */ |
66 | for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) { |
65 | for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) { |
67 |
|
66 | if(pp==p || !isalnum(*(pp-1))) *pp='K'; |
68 | } |
67 | } |
69 | for(s=p;*s;s++) *s=tolower(*s); |
68 | for(s=p;*s;s++) *s=tolower(*s); |
70 | find_illegal(p); |
69 | find_illegal(p); |
71 | } |
70 | } |
72 | 71 | ||
73 |
|
72 | /* process and print Scilab output */ |
74 | void output(char *p) |
73 | void output(char *p) |
75 | { |
74 | { |
76 | int i,n; |
75 | int i,n; |
77 | char *pp, *pe, *pt; |
76 | char *pp, *pe, *pt; |
78 | 77 | ||
79 | for(pp=strstr(p,ans_str); pp; pp=pe) { |
78 | for(pp=strstr(p,ans_str); pp; pp=pe) { |
80 |
|
79 | pp+=strlen(ans_str); pe=strstr(pp,ans_str); |
81 |
|
80 | if(pe) *pe=0; |
82 |
|
81 | pp=find_word_start(pp); if(memcmp(pp,"ans =",strlen("ans ="))==0) { |
83 |
|
82 | pp+=strlen("ans ="); pp=find_word_start(pp); |
84 |
|
83 | } |
85 |
|
84 | if(pe!=NULL && pp>=pe) { |
86 |
|
85 | emptyline: |
87 |
|
86 | puts(""); continue; |
88 |
|
87 | } |
89 |
|
88 | n=strlen(pp); if(n==0) goto emptyline; |
90 |
|
89 | /* strip leading and trailing spaces */ |
91 |
|
90 | while(isspace(*pp) && pp<pe) pp++; |
92 |
|
91 | pt=pp+strlen(pp)-1; |
93 |
|
92 | while(isspace(*pt) && pt>pp) *pt--=0; |
94 |
|
93 | /* make every output one-line */ |
95 |
|
94 | for(i=0;i<n;i++) { |
96 |
|
95 | if(*(pp+i)=='\n') *(pp+i)=';'; |
97 |
|
96 | } |
98 | /* |
97 | /* strip_zeros(pp); */ |
99 |
|
98 | puts(pp); |
100 | } |
99 | } |
101 | } |
100 | } |
102 | 101 | ||
103 | void about(void) |
102 | void about(void) |
104 | { |
103 | { |
105 | char *p; |
104 | char *p; |
106 | 105 | ||
107 | prepabout(quitstring,outputfname,NULL); |
106 | prepabout(quitstring,outputfname,NULL); |
108 | if(readabout()>0) { |
107 | if(readabout()>0) { |
109 |
|
108 | p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0; |
110 |
|
109 | p=strchr(aboutbuf,'('); if(p!=NULL) *p=0; |
111 |
|
110 | strip_trailing_spaces(aboutbuf); |
112 |
|
111 | printf("<a href=\"%s\">%s</a>",homepage,aboutbuf); |
113 | } |
112 | } |
114 | } |
113 | } |
115 | 114 | ||
116 | char *dynsetup(char *ptr, char *end) |
115 | char *dynsetup(char *ptr, char *end) |
117 | { |
116 | { |
118 | int i; |
117 | int i; |
119 | char *p, *pp; |
118 | char *p, *pp; |
120 | for(i=0;i<SETUP_NO;i++) { |
119 | for(i=0;i<SETUP_NO;i++) { |
121 |
|
120 | p=getenv(setups[i].wname); |
122 |
|
121 | if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p=""; |
123 |
|
122 | if(p==NULL || *p==0) p=setups[i].defaultval; |
124 |
|
123 | snprintf(ptr,end-ptr,"%s=%s\n",setups[i].setname,p); |
125 |
|
124 | ptr+=strlen(ptr); |
126 |
|
125 | if(strstr(setups[i].wname,"scilab_precision")!=NULL) |
127 |
|
126 | precision=atoi(p); |
128 |
|
127 | if(precision<0) precision=-precision; |
129 | } |
128 | } |
130 | return ptr; |
129 | return ptr; |
131 | } |
130 | } |
132 | 131 | ||
133 | int main(int argc,char *argv[]) |
132 | int main(int argc,char *argv[]) |
Line 135... | Line 134... | ||
135 | setenv("chroot","must",1); |
134 | setenv("chroot","must",1); |
136 | setenv("sysmask","must",1); |
135 | setenv("sysmask","must",1); |
137 | must_chroot=1; |
136 | must_chroot=1; |
138 | prepare1(); |
137 | prepare1(); |
139 | run(); |
138 | run(); |
140 | return 0; |
139 | return 0; |
141 | } |
140 | } |
142 | 141 |