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