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