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