Rev 8120 | Rev 10072 | 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 | |||
7674 | bpr | 18 | /* Interface octave to wims */ |
10 | reyssat | 19 | |
20 | /* 'Permission denied' error generated by Octave: it is trying to |
||
21 | * write to .octave.history even with the -H switch. */ |
||
22 | |||
23 | /*************** Customization: change values hereafter ****************/ |
||
8120 | bpr | 24 | #include "common.h" |
10 | reyssat | 25 | |
7674 | bpr | 26 | /* limit of input/output file sizes */ |
8120 | bpr | 27 | int fsizelim=131072; |
7674 | bpr | 28 | /* This string tells octave to exit. */ |
8120 | bpr | 29 | char *quitstring="\nquit\n"; |
7674 | bpr | 30 | /* The way to print a string in the program. */ |
8120 | bpr | 31 | char *stringprinter="\"%s\"\n"; |
7674 | bpr | 32 | /* This is octave home page. To be kept up to date. */ |
4326 | bpr | 33 | #define homepage "http://www.gnu.org/software/octave/" |
7674 | bpr | 34 | /* String to search for answers */ |
10 | reyssat | 35 | char ans_str[]="ans ="; |
36 | |||
37 | char *nameofcmd="octave -Hf --no-line-editing"; |
||
38 | int precision=9; |
||
3901 | bpr | 39 | char header[]="split_long_rows(0)\n\ |
40 | page_screen_output(0)\n\ |
||
10 | reyssat | 41 | function y=sh(x) y=sinh(x); endfunction\n\ |
42 | function y=ch(x) y=cosh(x); endfunction\n\ |
||
43 | function y=th(x) y=tanh(x); endfunction\n\ |
||
44 | function y=ln(x) y=log(x); endfunction\n\ |
||
45 | function y=lg(x) y=log10(x); endfunction\n\ |
||
46 | function y=sgn(x) y=sign(x); endfunction\n\ |
||
47 | function y=tg(x) y=tan(x); endfunction\n\ |
||
48 | function y=cotan(x) y=cot(x); endfunction\n\ |
||
49 | function y=ctg(x) y=cot(x); endfunction\n\ |
||
50 | function y=arcsin(x) y=asin(x); endfunction\n\ |
||
51 | function y=arccos(x) y=acos(x); endfunction\n\ |
||
52 | function y=arctan(x) y=atan(x); endfunction\n\ |
||
53 | function y=arctg(x) y=atan(x); endfunction\n\ |
||
54 | function y=argsh(x) y=asinh(x); endfunction\n\ |
||
55 | function y=argch(x) y=acosh(x); endfunction\n\ |
||
56 | function y=argth(x) y=atanh(x); endfunction\n\ |
||
57 | function y=Argsh(x) y=asinh(x); endfunction\n\ |
||
58 | function y=Argch(x) y=acosh(x); endfunction\n\ |
||
59 | function y=Argth(x) y=atanh(x); endfunction\n\ |
||
60 | function y=rint(x) y=round(x); endfunction\n\ |
||
61 | PI=pi\n\ |
||
62 | Pi=pi\n\ |
||
63 | "; |
||
64 | |||
65 | struct { |
||
7674 | bpr | 66 | char *wname; char *defaultval; char *setname; |
10 | reyssat | 67 | } setups[]={ |
7674 | bpr | 68 | {"w_octave_precision", "9", "output_precision"} |
10 | reyssat | 69 | }; |
70 | |||
7674 | bpr | 71 | /* names which are not allowed */ |
10 | reyssat | 72 | char *illegal[]={ |
73 | "system","fopen","fclose","readdir","popen","mkdir","rmdir", |
||
74 | "dir","ls","cd","chdir","more","save","load","diary", |
||
75 | "fork","putenv","graw","eval", |
||
76 | "scanf","exec","unlink","umask","lstat","stat","rename", |
||
77 | "glob","tilde_expand","pclose","popen2","waitpid", |
||
78 | }; |
||
79 | |||
8120 | bpr | 80 | int illegal_no=(sizeof(illegal)/sizeof(illegal[0])); |
81 | |||
7674 | bpr | 82 | /* name parts which are not allowed */ |
10 | reyssat | 83 | char *illpart[]={ |
84 | "file", "debug", "plot" |
||
85 | }; |
||
86 | |||
8120 | bpr | 87 | int illpart_no=(sizeof(illpart)/sizeof(illpart[0])); |
88 | |||
10 | reyssat | 89 | /***************** Nothing should need change hereafter *****************/ |
90 | |||
8120 | bpr | 91 | char *progname="octave"; |
10 | reyssat | 92 | |
7674 | bpr | 93 | /* check for security violations in command string */ |
10 | reyssat | 94 | void check_parm(char *p) |
95 | { |
||
96 | char *pp, *s; |
||
7674 | bpr | 97 | |
98 | /* Underscore replacement */ |
||
10 | reyssat | 99 | for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) { |
7674 | bpr | 100 | if(pp==p || !isalnum(*(pp-1))) *pp='K'; |
10 | reyssat | 101 | } |
102 | for(s=p;*s;s++) *s=tolower(*s); |
||
103 | find_illegal(p); |
||
104 | } |
||
105 | |||
7674 | bpr | 106 | /* process and print octave output */ |
10 | reyssat | 107 | void output(char *p) |
108 | { |
||
109 | int i,n; |
||
110 | char *pp, *pe, *pt; |
||
111 | |||
112 | pp=strchr(p,'\n'); |
||
113 | for(pp++; *pp; pp=pe) { |
||
7674 | bpr | 114 | pe=strchr(pp,'\n'); if(pe) *pe++=0; else pe=pp+strlen(pp); |
115 | if(memcmp(pp,ans_str,strlen(ans_str))==0) pp+=strlen(ans_str); |
||
116 | n=strlen(pp); if(n==0) { |
||
117 | puts(""); continue; |
||
118 | } |
||
119 | /* make every output one-line */ |
||
120 | for(i=0;i<n;i++) { |
||
121 | if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' '; |
||
122 | } |
||
123 | /* strip leading and trailing spaces */ |
||
124 | while(isspace(*pp) && pp<pe) pp++; |
||
125 | pt=pp+strlen(pp)-1; |
||
126 | while(isspace(*pt) && pt>pp) *pt--=0; |
||
127 | strip_zeros(pp); |
||
128 | puts(pp); |
||
10 | reyssat | 129 | } |
130 | } |
||
131 | |||
132 | void about(void) |
||
133 | { |
||
134 | char *p; |
||
135 | |||
136 | prepabout(quitstring,outputfname,NULL); |
||
137 | if(readabout()>0) { |
||
7674 | bpr | 138 | p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0; |
139 | p=strchr(aboutbuf,'('); if(p!=NULL) *p=0; |
||
8100 | bpr | 140 | strip_trailing_spaces2(aboutbuf); |
8529 | bpr | 141 | printf("<a target=\"wims_external\" href=\"%s\">%s</a>",homepage,aboutbuf); |
10 | reyssat | 142 | } |
143 | } |
||
144 | |||
145 | char *dynsetup(char *ptr, char *end) |
||
146 | { |
||
147 | int i; |
||
148 | char *p, *pp; |
||
149 | for(i=0;i<SETUP_NO;i++) { |
||
7674 | bpr | 150 | p=getenv(setups[i].wname); |
151 | if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p=""; |
||
152 | if(p==NULL || *p==0) p=setups[i].defaultval; |
||
153 | snprintf(ptr,end-ptr,"%s(%s)\n",setups[i].setname,p); |
||
154 | ptr+=strlen(ptr); |
||
155 | if(strstr(setups[i].wname,"octave_precision")!=NULL) |
||
156 | precision=atoi(p); |
||
157 | if(precision<0) precision=-precision; |
||
10 | reyssat | 158 | } |
159 | return ptr; |
||
160 | } |
||
161 | |||
162 | int main(int argc,char *argv[]) |
||
163 | { |
||
164 | prepare1(); |
||
165 | run(); |
||
7674 | bpr | 166 | return 0; |
10 | reyssat | 167 | } |
168 |