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