Subversion Repositories wimsdev

Rev

Rev 4326 | Rev 8100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4326 Rev 7674
Line 13... Line 13...
13
 *  You should have received a copy of the GNU General Public License
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
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
16
 */
17
 
17
 
18
        /* Interface octave to wims */
18
/* Interface octave to wims */
19
 
19
 
20
/* 'Permission denied' error generated by Octave: it is trying to
20
/* 'Permission denied' error generated by Octave: it is trying to
21
 * write to .octave.history even with the -H switch. */
21
 * write to .octave.history even with the -H switch. */
22
 
22
 
23
/*************** Customization: change values hereafter ****************/
23
/*************** Customization: change values hereafter ****************/
24
 
24
 
25
        /* limit of input/output file sizes */
25
/* limit of input/output file sizes */
26
#define fsizelim 131072
26
#define fsizelim 131072
27
        /* This string tells octave to exit. */
27
/* This string tells octave to exit. */
28
#define quitstring "\nquit\n"
28
#define quitstring "\nquit\n"
29
        /* The way to print a string in the program. */
29
/* The way to print a string in the program. */
30
#define stringprinter "\"%s\"\n"
30
#define stringprinter "\"%s\"\n"
31
        /* This is octave home page. To be kept up to date. */
31
/* This is octave home page. To be kept up to date. */
32
#define homepage "http://www.gnu.org/software/octave/"
32
#define homepage "http://www.gnu.org/software/octave/"
33
        /* String to search for answers */
33
/* String to search for answers */
34
char ans_str[]="ans =";
34
char ans_str[]="ans =";
35
 
35
 
36
char *nameofcmd="octave -Hf --no-line-editing";
36
char *nameofcmd="octave -Hf --no-line-editing";
37
int precision=9;
37
int precision=9;
38
char header[]="split_long_rows(0)\n\
38
char header[]="split_long_rows(0)\n\
Line 60... Line 60...
60
PI=pi\n\
60
PI=pi\n\
61
Pi=pi\n\
61
Pi=pi\n\
62
";
62
";
63
 
63
 
64
struct {
64
struct {
65
    char *wname;    char *defaultval;   char *setname;
65
    char *wname; char *defaultval; char *setname;
66
} setups[]={
66
} setups[]={
67
        {"w_octave_precision",  "9",    "output_precision"}
67
      {"w_octave_precision", "9", "output_precision"}
68
};
68
};
69
 
69
 
70
        /* names which are not allowed */
70
/* names which are not allowed */
71
char *illegal[]={
71
char *illegal[]={
72
      "system","fopen","fclose","readdir","popen","mkdir","rmdir",
72
      "system","fopen","fclose","readdir","popen","mkdir","rmdir",
73
      "dir","ls","cd","chdir","more","save","load","diary",
73
      "dir","ls","cd","chdir","more","save","load","diary",
74
      "fork","putenv","graw","eval",
74
      "fork","putenv","graw","eval",
75
      "scanf","exec","unlink","umask","lstat","stat","rename",
75
      "scanf","exec","unlink","umask","lstat","stat","rename",
76
      "glob","tilde_expand","pclose","popen2","waitpid",
76
      "glob","tilde_expand","pclose","popen2","waitpid",
77
     
-
 
78
};
77
};
79
 
78
 
80
        /* name parts which are not allowed */
79
/* name parts which are not allowed */
81
char *illpart[]={
80
char *illpart[]={
82
    "file", "debug", "plot"
81
    "file", "debug", "plot"
83
};
82
};
84
 
83
 
85
/***************** Nothing should need change hereafter *****************/
84
/***************** Nothing should need change hereafter *****************/
86
 
85
 
87
#define progname "octave"
86
#define progname "octave"
88
#include "common.h"
87
#include "common.h"
89
#include "common.c"
88
#include "common.c"
90
 
89
 
91
        /* check for security violations in command string */
90
/* check for security violations in command string */
92
void check_parm(char *p)
91
void check_parm(char *p)
93
{
92
{
94
    char *pp, *s;
93
    char *pp, *s;
95
   
94
 
96
          /* Underscore replacement */
95
 /* Underscore replacement */
97
    for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) {
96
    for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) {
98
        if(pp==p || !isalnum(*(pp-1))) *pp='K';
97
      if(pp==p || !isalnum(*(pp-1))) *pp='K';
99
    }
98
    }
100
    for(s=p;*s;s++) *s=tolower(*s);
99
    for(s=p;*s;s++) *s=tolower(*s);
101
    find_illegal(p);
100
    find_illegal(p);
102
}
101
}
103
 
102
 
104
        /* process and print octave output */
103
/* process and print octave output */
105
void output(char *p)
104
void output(char *p)
106
{
105
{
107
    int i,n;
106
    int i,n;
108
    char *pp, *pe, *pt;
107
    char *pp, *pe, *pt;
109
 
108
 
110
    pp=strchr(p,'\n');
109
    pp=strchr(p,'\n');
111
    for(pp++; *pp; pp=pe) {
110
    for(pp++; *pp; pp=pe) {
112
        pe=strchr(pp,'\n'); if(pe) *pe++=0; else pe=pp+strlen(pp);
111
      pe=strchr(pp,'\n'); if(pe) *pe++=0; else pe=pp+strlen(pp);
113
        if(memcmp(pp,ans_str,strlen(ans_str))==0) pp+=strlen(ans_str);
112
      if(memcmp(pp,ans_str,strlen(ans_str))==0) pp+=strlen(ans_str);
114
        n=strlen(pp); if(n==0) {
113
      n=strlen(pp); if(n==0) {
115
            puts(""); continue;
114
          puts(""); continue;
116
        }
115
      }
117
                /* make every output one-line */
116
/* make every output one-line */
118
        for(i=0;i<n;i++) {
117
      for(i=0;i<n;i++) {
119
            if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' ';
118
          if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' ';
120
        }
119
      }
121
          /* strip leading and trailing spaces */
120
/* strip leading and trailing spaces */
122
        while(isspace(*pp) && pp<pe) pp++;
121
      while(isspace(*pp) && pp<pe) pp++;
123
        pt=pp+strlen(pp)-1;
122
      pt=pp+strlen(pp)-1;
124
        while(isspace(*pt) && pt>pp) *pt--=0;
123
      while(isspace(*pt) && pt>pp) *pt--=0;
125
        strip_zeros(pp);
124
      strip_zeros(pp);
126
        puts(pp);
125
      puts(pp);
127
    }
126
    }
128
}
127
}
129
 
128
 
130
void about(void)
129
void about(void)
131
{
130
{
132
    char *p;
131
    char *p;
133
 
132
 
134
    prepabout(quitstring,outputfname,NULL);
133
    prepabout(quitstring,outputfname,NULL);
135
    if(readabout()>0) {
134
    if(readabout()>0) {
136
        p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
135
      p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
137
        p=strchr(aboutbuf,'('); if(p!=NULL) *p=0;
136
      p=strchr(aboutbuf,'('); if(p!=NULL) *p=0;
138
        strip_trailing_spaces(aboutbuf);
137
      strip_trailing_spaces(aboutbuf);
139
        printf("<a href=\"%s\">%s</a>",homepage,aboutbuf);
138
      printf("<a href=\"%s\">%s</a>",homepage,aboutbuf);
140
    }
139
    }
141
}
140
}
142
 
141
 
143
char *dynsetup(char *ptr, char *end)
142
char *dynsetup(char *ptr, char *end)
144
{
143
{
145
    int i;
144
    int i;
146
    char *p, *pp;
145
    char *p, *pp;
147
    for(i=0;i<SETUP_NO;i++) {
146
    for(i=0;i<SETUP_NO;i++) {
148
        p=getenv(setups[i].wname);
147
      p=getenv(setups[i].wname);
149
        if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
148
      if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
150
        if(p==NULL || *p==0) p=setups[i].defaultval;
149
      if(p==NULL || *p==0) p=setups[i].defaultval;
151
        snprintf(ptr,end-ptr,"%s(%s)\n",setups[i].setname,p);
150
      snprintf(ptr,end-ptr,"%s(%s)\n",setups[i].setname,p);
152
        ptr+=strlen(ptr);
151
      ptr+=strlen(ptr);
153
        if(strstr(setups[i].wname,"octave_precision")!=NULL)
152
      if(strstr(setups[i].wname,"octave_precision")!=NULL)
154
          precision=atoi(p);
153
        precision=atoi(p);
155
        if(precision<0) precision=-precision;
154
      if(precision<0) precision=-precision;
156
    }
155
    }
157
    return ptr;
156
    return ptr;
158
}
157
}
159
 
158
 
160
int main(int argc,char *argv[])
159
int main(int argc,char *argv[])
161
{
160
{
162
    prepare1();
161
    prepare1();
163
    run();
162
    run();
164
    return 0;    
163
    return 0;
165
}
164
}
166
 
165