Subversion Repositories wimsdev

Rev

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