Subversion Repositories wimsdev

Rev

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