Subversion Repositories wimsdev

Rev

Rev 10075 | 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\
10072 bpr 41
sh=@sinh\n\
42
ch=@cosh\n\
43
th=@tanh\n\
44
ln=@log\n\
45
lg=@log10\n\
46
sgn=@sign\n\
47
tg=@tan\n\
48
cotan=@cot\n\
49
ctg=@cot\n\
50
arcsin=@asin\n\
51
arccos=@acos\n\
52
arctan=@atan\n\
53
arctg=@atan\n\
54
argsh=@asinh\n\
55
argch=@acosh\n\
56
argth=@atanh\n\
57
Argsh=@asinh\n\
58
Argch=@acosh\n\
59
Argth=@atanh\n\
60
rint=@round\n\
10 reyssat 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
 
10075 bpr 136
    prepabout("version\nquit\n",outputfname,NULL);
10 reyssat 137
    if(readabout()>0) {
7674 bpr 138
      p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
10075 bpr 139
      p=aboutbuf;while(*p && *p!='=') p++;
140
      p++;
141
      strip_trailing_spaces2(p);
142
      printf("<a target=\"wims_external\" href=\"%s\">Octave%s</a>",homepage,p);
10 reyssat 143
    }
144
}
145
 
146
char *dynsetup(char *ptr, char *end)
147
{
148
    int i;
149
    char *p, *pp;
12011 bpr 150
    if(wseed!= NULL) {
151
      int ws=atoi(wseed)&(0x7FFFFFFF);
152
      snprintf(ptr,end-ptr,"\nrand(\"state\",%u);\nrand(\"state\",%u);randn(\"state\",%u);rande(\"state\",%u);randg(\"state\",%u);randp(\"state\",%u);",ws,ws,ws,ws,ws,ws);
153
      ptr+=strlen(ptr);
154
    }
10 reyssat 155
    for(i=0;i<SETUP_NO;i++) {
7674 bpr 156
      p=getenv(setups[i].wname);
157
      if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
158
      if(p==NULL || *p==0) p=setups[i].defaultval;
159
      snprintf(ptr,end-ptr,"%s(%s)\n",setups[i].setname,p);
160
      ptr+=strlen(ptr);
161
      if(strstr(setups[i].wname,"octave_precision")!=NULL)
162
        precision=atoi(p);
163
      if(precision<0) precision=-precision;
10 reyssat 164
    }
165
    return ptr;
166
}
167
 
168
int main(int argc,char *argv[])
169
{
170
    prepare1();
171
    run();
7674 bpr 172
    return 0;
10 reyssat 173
}
174