Subversion Repositories wimsdev

Rev

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

Rev 6421 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 Yacas to wims */
18
/* Interface Yacas to wims */
19
 
19
 
20
/*************** Customization: change values hereafter ****************/
20
/*************** Customization: change values hereafter ****************/
21
 
21
 
22
        /* This is yacas home page. To be kept up to date. */
22
/* This is yacas home page. To be kept up to date. */
23
#define homepage "http://yacas.sourceforge.net/"
23
#define homepage "http://yacas.sourceforge.net/"
24
        /* String to tell the program to quit. */
24
/* String to tell the program to quit. */
25
#define quitstring "\nquit\n"
25
#define quitstring "\nquit\n"
26
        /* The way to print a string in the program. */
26
/* The way to print a string in the program. */
27
#define stringprinter "\"%s\"\n"
27
#define stringprinter "\"%s\"\n"
28
        /* limit of input/output file sizes */
28
/* limit of input/output file sizes */
29
int fsizelim=131072;
29
int fsizelim=131072;
30
int precision=20;       /* default */
30
int precision=20;  /* default */
31
 
31
 
32
char *inprompt="\nIn>";
32
char *inprompt="\nIn>";
33
char *outprompt="Out>";
33
char *outprompt="Out>";
34
 
34
 
35
char *nameofcmd="yacas -p";
35
char *nameofcmd="yacas -p";
Line 37... Line 37...
37
#include "yacasheader.c"
37
#include "yacasheader.c"
38
 
38
 
39
struct {
39
struct {
40
    char *wname;    char *defaultval;    char *yacasset;
40
    char *wname;    char *defaultval;    char *yacasset;
41
} setups[]={
41
} setups[]={
42
      {"w_yacas_precision",     "20",   "\\precision=",},
42
      {"w_yacas_precision", "20", "\\precision=",},
43
      {"w_yacas_serieslength",  "8",    "\\serieslength="}
43
      {"w_yacas_serieslength", "8", "\\serieslength="}
44
};
44
};
45
 
45
 
46
        /* names which are not allowed */
46
/* names which are not allowed */
47
char *illegal[]={
47
char *illegal[]={
48
    "SystemCall", "Use", "Vi", "GetYacasPID", "ShowPS",
48
    "SystemCall", "Use", "Vi", "GetYacasPID", "ShowPS",
49
      "MakeFunctionPlugin"
49
      "MakeFunctionPlugin"
50
};
50
};
51
 
51
 
52
        /* name parts which are not allowed */
52
 /* name parts which are not allowed */
53
        /* 11/3/2013 add "@" and "ConcatStrings" */
53
 /* 11/3/2013 add "@" and "ConcatStrings" */
54
char *illpart[]={
54
char *illpart[]={
55
    "File", "Load", "Plot","ConcatStrings" ,"@"
55
    "File", "Load", "Plot","ConcatStrings" ,"@"
56
};
56
};
57
 
57
 
58
/***************** Nothing should need change hereafter *****************/
58
/***************** Nothing should need change hereafter *****************/
59
 
59
 
60
#define progname "yacas"
60
#define progname "yacas"
61
#include "common.h"
61
#include "common.h"
62
#include "common.c"
62
#include "common.c"
63
 
63
 
64
        /* check for security violations in command string */
64
 /* check for security violations in command string */
65
void check_parm(char *pm)
65
void check_parm(char *pm)
66
{
66
{
67
    char *p, *pp, *p2, buf[16];
67
    char *p, *pp, *p2, buf[16];
68
    int i;
68
    int i;
69
   
69
 
70
    for(p=pm;*p!=0;p++) {
70
    for(p=pm;*p!=0;p++) {
71
        if(*p!='\\') continue;
71
      if(*p!='\\') continue;
72
        if(*(p+1)=='\n') *p=*(p+1)=' ';
72
      if(*(p+1)=='\n') *p=*(p+1)=' ';
73
        if(*(p+1)==0) *p=' ';
73
      if(*(p+1)==0) *p=' ';
74
    }
74
    }
75
    for(p=pm; *p!=0; p++) {
75
    for(p=pm; *p!=0; p++) {
76
        if(!isalpha(*p)) continue;
76
      if(!isalpha(*p)) continue;
77
        for(p2=p+1; isalpha(*p2); p2++);
77
      for(p2=p+1; isalpha(*p2); p2++);
78
        if(p2-p>10) {p=p2-1; continue;}
78
      if(p2-p>10) {p=p2-1; continue;}
79
        memmove(buf,p,p2-p); buf[p2-p]=0; pp=p; p=p2-1;
79
      memmove(buf,p,p2-p); buf[p2-p]=0; pp=p; p=p2-1;
80
        for(p2=buf; islower(*p2); p2++);
80
      for(p2=buf; islower(*p2); p2++);
81
        if(*p2) continue;
81
      if(*p2) continue;
82
        i=search_list(firstupper,firstupperno,sizeof(firstupper[0]),buf);
82
      i=search_list(firstupper,firstupperno,sizeof(firstupper[0]),buf);
83
        if(i>=0) *pp=toupper(*pp);
83
      if(i>=0) *pp=toupper(*pp);
84
    }
84
    }
85
    find_illegal(pm);
85
    find_illegal(pm);
86
}
86
}
87
 
87
 
88
 
88
 
89
        /* process and print yacas output */
89
/* process and print yacas output */
90
void output(char *p)
90
void output(char *p)
91
{
91
{
92
    int i,n;
92
    int i,n;
93
    char *pp, *pe, *p1, *pt;
93
    char *pp, *pe, *p1, *pt;
94
    char outbuf[MAX_LINELEN+1];
94
    char outbuf[MAX_LINELEN+1];
95
   
95
 
96
    pp=strstr(p,inprompt); if(pp==NULL) return;
96
    pp=strstr(p,inprompt); if(pp==NULL) return;
97
    while(pp!=NULL && *pp!=0) {
97
    while(pp!=NULL && *pp!=0) {
98
        pp+=strlen(inprompt); p1=find_word_start(pp);
98
      pp+=strlen(inprompt); p1=find_word_start(pp);
99
        pe=strstr(pp,outprompt);
99
      pe=strstr(pp,outprompt);
100
        pt=strstr(pp,inprompt);
100
      pt=strstr(pp,inprompt);
101
        if(pe==NULL || (pt!=NULL && pt<pe)) { /* error */
101
      if(pe==NULL || (pt!=NULL && pt<pe)) { /* error */
102
            if(pt==NULL) pp=pp+strlen(pp); else pp=pt;
102
          if(pt==NULL) pp=pp+strlen(pp); else pp=pt;
103
            n=pp-p1; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0;
103
          n=pp-p1; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0;
104
            memmove(outbuf,p1,n); outbuf[n]=0;
104
          memmove(outbuf,p1,n); outbuf[n]=0;
105
            fprintf(stderr,"%s\n",outbuf);
105
          fprintf(stderr,"%s\n",outbuf);
106
            puts(""); continue;
106
          puts(""); continue;
107
        }
107
      }
108
        else {
108
      else {
109
            *pe=0; pe=find_word_start(pe+strlen(outprompt));
109
          *pe=0; pe=find_word_start(pe+strlen(outprompt));
110
        }
110
      }
111
        pp=strstr(pe,inprompt);
111
      pp=strstr(pe,inprompt);
112
        if(pp==NULL) pp=pe+strlen(pe);
112
      if(pp==NULL) pp=pe+strlen(pe);
113
        if(*p1==0) {
113
      if(*p1==0) {
114
            if(pp>=pe+sizeof(outbuf)) break;
114
          if(pp>=pe+sizeof(outbuf)) break;
115
            n=pp-pe; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0;
115
          n=pp-pe; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0;
116
            memmove(outbuf,pe,n); outbuf[n]=0;
116
          memmove(outbuf,pe,n); outbuf[n]=0;
117
        }
117
      }
118
        else {
118
      else {
119
            snprintf(outbuf,sizeof(outbuf),"%s",p1);
119
          snprintf(outbuf,sizeof(outbuf),"%s",p1);
120
            n=strlen(outbuf);
120
          n=strlen(outbuf);
121
        }
121
      }
122
                /* make every output one-line */
122
/* make every output one-line */
123
        for(i=0;i<n;i++) {
123
      for(i=0;i<n;i++) {
124
            if(outbuf[i]=='\n') outbuf[i]=' ';
124
          if(outbuf[i]=='\n') outbuf[i]=' ';
125
        }
125
      }
126
          /* strip leading and trailing spaces */
126
/* strip leading and trailing spaces */
127
        for(i=n-1;i>=0 && isspace(outbuf[i]); i--) outbuf[i]=0;
127
      for(i=n-1;i>=0 && isspace(outbuf[i]); i--) outbuf[i]=0;
128
        if(outbuf[i]==';') outbuf[i]=0;
128
      if(outbuf[i]==';') outbuf[i]=0;
129
        for(pe=outbuf; *pe; pe++) if(isupper(*pe)) *pe=tolower(*pe);
129
      for(pe=outbuf; *pe; pe++) if(isupper(*pe)) *pe=tolower(*pe);
130
        for(pe=outbuf; isspace(*pe); pe++);
130
      for(pe=outbuf; isspace(*pe); pe++);
131
        /* strip_zeros(pe); */
131
      /* strip_zeros(pe); */
132
        puts(pe);
132
      puts(pe);
133
    }
133
    }
134
}
134
}
135
 
135
 
136
void about(void)
136
void about(void)
137
{
137
{
138
    cmdparm="-v"; prepabout("",outputfname,NULL);
138
    cmdparm="-v"; prepabout("",outputfname,NULL);
139
    if(readabout()>0)
139
    if(readabout()>0)
140
      printf("<a href=\"%s\">Yacas %s</a>",homepage,aboutbuf);
140
      printf("<a href=\"%s\">Yacas %s</a>",homepage,aboutbuf);
141
}
141
}
142
 
142
 
143
char *dynsetup(char *ptr, char *end)
143
char *dynsetup(char *ptr, char *end)
144
{
144
{
145
    int i; char *p, *pp;
145
    int i; char *p, *pp;
146
   
146
 
147
    for(i=0;i<SETUP_NO;i++) {
147
    for(i=0;i<SETUP_NO;i++) {
148
        p=getenv(setups[i].wname);
148
      p=getenv(setups[i].wname);
149
        if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
149
      if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
150
        if(p==NULL || *p==0) p=setups[i].defaultval;
150
      if(p==NULL || *p==0) p=setups[i].defaultval;
151
        if(strstr(setups[i].wname,"yacas_precision")!=NULL)
151
      if(strstr(setups[i].wname,"yacas_precision")!=NULL)
152
          precision=atoi(p);
152
        precision=atoi(p);
153
        if(precision<0) precision=-precision;
153
      if(precision<0) precision=-precision;
154
    }
154
    }
155
    return ptr;
155
    return ptr;
156
}
156
}
157
 
157
 
158
int main(int argc,char *argv[])
158
int main(int argc,char *argv[])
159
{
159
{
160
    prepare1();
160
    prepare1();
161
    run();
161
    run();
162
    return 0;    
162
    return 0;
163
}
163
}
164
 
164