Subversion Repositories wimsdev

Rev

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 maxima to wims */
10 reyssat 19
 
20
/*************** Customization: change values hereafter ****************/
21
 
7674 bpr 22
/* limit of input/output file sizes */
10 reyssat 23
#define fsizelim 131072
7674 bpr 24
/* This string tells maxima to exit. */
10 reyssat 25
#define quitstring "\nquit();\n"
7674 bpr 26
/* The way to print a string in the program. */
10 reyssat 27
#define stringprinter "\"%s\";\n"
7674 bpr 28
/* This is maxima home page. To be kept up to date. */
10 reyssat 29
#define homepage "http://maxima.sourceforge.net/"
30
 
31
char *nameofcmd="maxima";
32
int precision=20;
33
char header[]="\n\
34
display2d:false;\n\
35
letrat:true;\n\
36
keepfloat:true;\n\
37
rombergmin:5;\n\
38
rombergtol:1.E-6;\n\
39
rombergit:13;\n\
40
simpsum:true;\n\
41
triginverses:true; logabs:true;\n\
3608 bpr 42
e:%e;pi:%pi;Pi:%pi;PI:%pi;I:%i;i:%i;\n\
10 reyssat 43
ln:log;sh:sinh;ch:cosh;th:tanh;\n\
44
arctan:atan;arcsin:asin;arccos:acos;\n\
45
tg:tan;arctg:atan;\n\
46
argsh:asinh;argch:acosh;argth:atanh;\n\
47
Argsh:asinh;Argch:acosh;Argth:atanh;\n\
48
cotan:cot;ctg:cot;\n\
49
log10(x):=block([],return(log(x)/log(10.0)));\n\
50
log2(x):=block([],return(log(x)/log(2.0)));\n\
51
lg(x):=log10(x);\n\
52
sgn:sign;\n\
53
nolabels:true; kill(labels);\n\
54
";
55
 
56
struct {
7674 bpr 57
    char *wname; char *defaultval; char *setname;
10 reyssat 58
} setups[]={
7674 bpr 59
      {"w_maxima_precision", "20", "fpprec"}
10 reyssat 60
};
61
 
7674 bpr 62
/* names which are not allowed */
10 reyssat 63
char *illegal[]={
64
      "system","describe","example",
65
      "save","fassave","stringout","batcon",
66
      "batcount","cursordisp",
67
      "direc","readonly","with_stdout","pscom",
68
      "demo","ttyintfun","bug"
7674 bpr 69
 
10 reyssat 70
};
71
 
7674 bpr 72
/* name parts which are not allowed */
10 reyssat 73
char *illpart[]={
74
    "file", "debug", "plot", "load", "store", "batch"
75
};
76
 
77
/***************** Nothing should need change hereafter *****************/
78
 
79
#define linebyline "\n(%i"
80
#define progname "maxima"
81
#include "common.h"
82
#include "common.c"
83
 
7674 bpr 84
/* check for security violations in command string */
10 reyssat 85
void check_parm(char *pm)
86
{
87
    char *s, *pp;
88
    int l;
7674 bpr 89
/* Underscore replacement */
10 reyssat 90
    for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
7674 bpr 91
/* '?' escapes to Lisp commands. */
10 reyssat 92
    if(strchr(pm,'?')!=NULL) {
7674 bpr 93
        fprintf(stderr,"Illegal under WIMS.\n"); exit(1);
10 reyssat 94
    }
95
    for(s=pm;*s;s++) *s=tolower(*s);
8100 bpr 96
    strip_trailing_spaces2(pm); l=strlen(pm);
10 reyssat 97
    if(l>0 && pm[l-1]!=';') strcat(pm,";");
98
    find_illegal(pm);
99
}
100
 
101
char *find_prompt(char *p, char t)
102
{
103
    char *pp=p-1, *pt;
104
    char c;
105
    int add;
106
    redo:
107
    if(*p==0 || (pp>=p && *pp==0)) return NULL;
108
    add=3;
109
    do {
7674 bpr 110
      pp=strstr(pp+1,"\n(");
111
      if(!pp) break;
112
      c=pp[2]; add=3;
113
      if(c=='\%') { /* backward compatibility */
114
          add++; c=pp[3];
115
          if(c=='i') c='C';
116
          if(c=='o') c='D';
117
      }
10 reyssat 118
    }
119
    while(c!=t);
120
    pt=pp;
121
    if(pp!=NULL) {
7674 bpr 122
      pp+=add; while(isdigit(*pp)) pp++;
123
      if(*pp!=')') goto redo;
124
      pp++;
10 reyssat 125
    }
126
    if(pt!=NULL && t=='D') pt=pp;
127
    return pt;
128
}
129
 
7674 bpr 130
/* process and print maxima output */
10 reyssat 131
void output(char *p)
132
{
133
    int i,n;
134
    char *pp, *pe, *pt;
135
 
136
    pp=find_prompt(p,'C');
137
    while(pp!=NULL) {
7674 bpr 138
      pe=find_prompt(pp+1,'C'); pp=find_prompt(pp,'D');
139
      if(pp==NULL) return;
140
      if(pe!=NULL && pp>=pe) goto emptyline;
141
      if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
142
      if(pp>=pe) {
143
          emptyline:
144
          puts(""); pp=pe; continue;
145
      }
146
      n=strlen(pp); if(n==0) goto emptyline;
147
/* make every output one-line */
148
      for(i=0;i<n;i++) {
149
          if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' ';
150
          else *(pp+i)=tolower(*(pp+i));
151
      }
152
/* strip leading and trailing spaces */
153
      while(isspace(*pp) && pp<pe) pp++;
154
      pt=pp+strlen(pp)-1;
155
      while(isspace(*pt) && pt>pp) *pt--=0;
8100 bpr 156
      if(*pp=='[' && *pt==']' && find_matching2(pp+1,']')==pt) {
7674 bpr 157
          *(pt--)=0; pp++;
158
      }
159
      for(pt=strchr(pp,'b');pt!=NULL; pt=strchr(pt+1,'b')) {
160
          if(pt>pp && isdigit(*(pt-1)) &&
161
             (*(pt+1)=='-' || isdigit(*(pt+1)))) {
162
            if(*(pt+1)=='0' && !isdigit(*(pt+2))) ovlstrcpy(pt,pt+2);
163
            else *pt='E';
164
          }
165
      }
166
      puts(pp); pp=pe;
10 reyssat 167
    }
168
}
169
 
170
void about(void)
171
{
172
    char *p, *p2, *pp;
173
    int i;
174
 
5762 bpr 175
/*    printf("<a href=\"%s\">Maxima</a>",homepage); return; */
10 reyssat 176
    prepabout("build_info();\n" quitstring,outputfname,NULL);
177
    if(readabout()>0) {
7674 bpr 178
      for(p=aboutbuf; *p; p=find_word_start(find_word_end(p))) {
179
          if(strncasecmp(p,"Maxima",strlen("Maxima"))==0) {
180
            p2=find_word_start(find_word_end(p));
181
            if(strncmp(p2,"restarted",9)!=0) break;
182
          }
183
      }
184
      for(p2=p;*p2 && *p2!='\n' && !isdigit(*p2);p2++);
185
      if(isdigit(*p2)) pp=find_word_end(p2);
186
      else for(i=0, pp=p;i<2;i++) pp=find_word_end(find_word_start(pp));
187
      *pp=0;
188
      if(*p!=0) printf("<a href=\"%s\">%s</a>",homepage,p);
10 reyssat 189
    }
190
}
191
 
192
char *dynsetup(char *ptr, char *end)
193
{
194
    int i;
195
    char *p, *pp;
196
    for(i=0;i<SETUP_NO;i++) {
7674 bpr 197
      p=getenv(setups[i].wname);
198
      if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
199
      if(p==NULL || *p==0) p=setups[i].defaultval;
200
      snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
201
      ptr+=strlen(ptr);
202
      if(strstr(setups[i].wname,"maxima_precision")!=NULL)
203
        precision=atoi(p);
204
      if(precision<0) precision=-precision;
10 reyssat 205
    }
206
    return ptr;
207
}
208
 
209
int main(int argc,char *argv[])
210
{
211
    prepare1();
212
    run();
7674 bpr 213
    return 0;
10 reyssat 214
}
215