Subversion Repositories wimsdev

Rev

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

Rev 5762 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 maxima to wims */
18
/* Interface maxima to wims */
19
 
19
 
20
/*************** Customization: change values hereafter ****************/
20
/*************** Customization: change values hereafter ****************/
21
 
21
 
22
        /* limit of input/output file sizes */
22
/* limit of input/output file sizes */
23
#define fsizelim 131072
23
#define fsizelim 131072
24
        /* This string tells maxima to exit. */
24
/* This string tells maxima to exit. */
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
        /* This is maxima home page. To be kept up to date. */
28
/* This is maxima home page. To be kept up to date. */
29
#define homepage "http://maxima.sourceforge.net/"
29
#define homepage "http://maxima.sourceforge.net/"
30
 
30
 
31
char *nameofcmd="maxima";
31
char *nameofcmd="maxima";
32
int precision=20;
32
int precision=20;
33
char header[]="\n\
33
char header[]="\n\
Line 52... Line 52...
52
sgn:sign;\n\
52
sgn:sign;\n\
53
nolabels:true; kill(labels);\n\
53
nolabels:true; kill(labels);\n\
54
";
54
";
55
 
55
 
56
struct {
56
struct {
57
    char *wname;    char *defaultval;   char *setname;
57
    char *wname; char *defaultval; char *setname;
58
} setups[]={
58
} setups[]={
59
        {"w_maxima_precision",  "20",   "fpprec"}
59
      {"w_maxima_precision", "20", "fpprec"}
60
};
60
};
61
 
61
 
62
        /* names which are not allowed */
62
/* names which are not allowed */
63
char *illegal[]={
63
char *illegal[]={
64
      "system","describe","example",
64
      "system","describe","example",
65
      "save","fassave","stringout","batcon",
65
      "save","fassave","stringout","batcon",
66
      "batcount","cursordisp",
66
      "batcount","cursordisp",
67
      "direc","readonly","with_stdout","pscom",
67
      "direc","readonly","with_stdout","pscom",
68
      "demo","ttyintfun","bug"
68
      "demo","ttyintfun","bug"
69
     
69
 
70
};
70
};
71
 
71
 
72
        /* name parts which are not allowed */
72
/* name parts which are not allowed */
73
char *illpart[]={
73
char *illpart[]={
74
    "file", "debug", "plot", "load", "store", "batch"
74
    "file", "debug", "plot", "load", "store", "batch"
75
};
75
};
76
 
76
 
77
/***************** Nothing should need change hereafter *****************/
77
/***************** Nothing should need change hereafter *****************/
Line 79... Line 79...
79
#define linebyline "\n(%i"
79
#define linebyline "\n(%i"
80
#define progname "maxima"
80
#define progname "maxima"
81
#include "common.h"
81
#include "common.h"
82
#include "common.c"
82
#include "common.c"
83
 
83
 
84
        /* check for security violations in command string */
84
/* check for security violations in command string */
85
void check_parm(char *pm)
85
void check_parm(char *pm)
86
{
86
{
87
    char *s, *pp;
87
    char *s, *pp;
88
    int l;
88
    int l;
89
          /* Underscore replacement */
89
/* Underscore replacement */
90
    for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
90
    for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
91
        /* '?' escapes to Lisp commands. */
91
/* '?' escapes to Lisp commands. */
92
    if(strchr(pm,'?')!=NULL) {
92
    if(strchr(pm,'?')!=NULL) {
93
          fprintf(stderr,"Illegal under WIMS.\n"); exit(1);
93
        fprintf(stderr,"Illegal under WIMS.\n"); exit(1);
94
    }
94
    }
95
    for(s=pm;*s;s++) *s=tolower(*s);
95
    for(s=pm;*s;s++) *s=tolower(*s);
96
    strip_trailing_spaces(pm); l=strlen(pm);
96
    strip_trailing_spaces(pm); l=strlen(pm);
97
    if(l>0 && pm[l-1]!=';') strcat(pm,";");
97
    if(l>0 && pm[l-1]!=';') strcat(pm,";");
98
    find_illegal(pm);
98
    find_illegal(pm);
Line 105... Line 105...
105
    int add;
105
    int add;
106
    redo:
106
    redo:
107
    if(*p==0 || (pp>=p && *pp==0)) return NULL;
107
    if(*p==0 || (pp>=p && *pp==0)) return NULL;
108
    add=3;
108
    add=3;
109
    do {
109
    do {
110
        pp=strstr(pp+1,"\n(");
110
      pp=strstr(pp+1,"\n(");
111
        if(!pp) break;
111
      if(!pp) break;
112
        c=pp[2]; add=3;
112
      c=pp[2]; add=3;
113
        if(c=='\%') {   /* backward compatibility */
113
      if(c=='\%') { /* backward compatibility */
114
            add++; c=pp[3];
114
          add++; c=pp[3];
115
            if(c=='i') c='C';
115
          if(c=='i') c='C';
116
            if(c=='o') c='D';
116
          if(c=='o') c='D';
117
        }
117
      }
118
    }
118
    }
119
    while(c!=t);
119
    while(c!=t);
120
    pt=pp;
120
    pt=pp;
121
    if(pp!=NULL) {
121
    if(pp!=NULL) {
122
        pp+=add; while(isdigit(*pp)) pp++;
122
      pp+=add; while(isdigit(*pp)) pp++;
123
        if(*pp!=')') goto redo;
123
      if(*pp!=')') goto redo;
124
        pp++;
124
      pp++;
125
    }
125
    }
126
    if(pt!=NULL && t=='D') pt=pp;
126
    if(pt!=NULL && t=='D') pt=pp;
127
    return pt;
127
    return pt;
128
}
128
}
129
 
129
 
130
        /* process and print maxima output */
130
/* process and print maxima output */
131
void output(char *p)
131
void output(char *p)
132
{
132
{
133
    int i,n;
133
    int i,n;
134
    char *pp, *pe, *pt;
134
    char *pp, *pe, *pt;
135
 
135
 
136
    pp=find_prompt(p,'C');
136
    pp=find_prompt(p,'C');
137
    while(pp!=NULL) {
137
    while(pp!=NULL) {
138
        pe=find_prompt(pp+1,'C'); pp=find_prompt(pp,'D');
138
      pe=find_prompt(pp+1,'C'); pp=find_prompt(pp,'D');
139
        if(pp==NULL) return;
139
      if(pp==NULL) return;
140
        if(pe!=NULL && pp>=pe) goto emptyline;
140
      if(pe!=NULL && pp>=pe) goto emptyline;
141
        if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
141
      if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
142
        if(pp>=pe) {
142
      if(pp>=pe) {
143
            emptyline:
143
          emptyline:
144
            puts(""); pp=pe; continue;
144
          puts(""); pp=pe; continue;
145
        }
145
      }
146
        n=strlen(pp); if(n==0) goto emptyline;
146
      n=strlen(pp); if(n==0) goto emptyline;
147
                /* make every output one-line */
147
/* make every output one-line */
148
        for(i=0;i<n;i++) {
148
      for(i=0;i<n;i++) {
149
            if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' ';
149
          if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' ';
150
            else *(pp+i)=tolower(*(pp+i));
150
          else *(pp+i)=tolower(*(pp+i));
151
        }
151
      }
152
          /* strip leading and trailing spaces */
152
/* strip leading and trailing spaces */
153
        while(isspace(*pp) && pp<pe) pp++;
153
      while(isspace(*pp) && pp<pe) pp++;
154
        pt=pp+strlen(pp)-1;
154
      pt=pp+strlen(pp)-1;
155
        while(isspace(*pt) && pt>pp) *pt--=0;
155
      while(isspace(*pt) && pt>pp) *pt--=0;
156
        if(*pp=='[' && *pt==']' && find_matching(pp+1,']')==pt) {
156
      if(*pp=='[' && *pt==']' && find_matching(pp+1,']')==pt) {
157
            *(pt--)=0; pp++;
157
          *(pt--)=0; pp++;
158
        }
158
      }
159
        for(pt=strchr(pp,'b');pt!=NULL; pt=strchr(pt+1,'b')) {
159
      for(pt=strchr(pp,'b');pt!=NULL; pt=strchr(pt+1,'b')) {
160
            if(pt>pp && isdigit(*(pt-1)) &&
160
          if(pt>pp && isdigit(*(pt-1)) &&
161
               (*(pt+1)=='-' || isdigit(*(pt+1)))) {
161
             (*(pt+1)=='-' || isdigit(*(pt+1)))) {
162
                if(*(pt+1)=='0' && !isdigit(*(pt+2))) ovlstrcpy(pt,pt+2);
162
            if(*(pt+1)=='0' && !isdigit(*(pt+2))) ovlstrcpy(pt,pt+2);
163
                else *pt='E';
163
            else *pt='E';
164
            }
164
          }
165
        }
165
      }
166
        puts(pp); pp=pe;
166
      puts(pp); pp=pe;
167
    }
167
    }
168
}
168
}
169
 
169
 
170
void about(void)
170
void about(void)
171
{
171
{
Line 173... Line 173...
173
    int i;
173
    int i;
174
 
174
 
175
/*    printf("<a href=\"%s\">Maxima</a>",homepage); return; */
175
/*    printf("<a href=\"%s\">Maxima</a>",homepage); return; */
176
    prepabout("build_info();\n" quitstring,outputfname,NULL);
176
    prepabout("build_info();\n" quitstring,outputfname,NULL);
177
    if(readabout()>0) {
177
    if(readabout()>0) {
178
        for(p=aboutbuf; *p; p=find_word_start(find_word_end(p))) {
178
      for(p=aboutbuf; *p; p=find_word_start(find_word_end(p))) {
179
            if(strncasecmp(p,"Maxima",strlen("Maxima"))==0) {
179
          if(strncasecmp(p,"Maxima",strlen("Maxima"))==0) {
180
                p2=find_word_start(find_word_end(p));
180
            p2=find_word_start(find_word_end(p));
181
                if(strncmp(p2,"restarted",9)!=0) break;
181
            if(strncmp(p2,"restarted",9)!=0) break;
182
            }
182
          }
183
        }
183
      }
184
        for(p2=p;*p2 && *p2!='\n' && !isdigit(*p2);p2++);
184
      for(p2=p;*p2 && *p2!='\n' && !isdigit(*p2);p2++);
185
        if(isdigit(*p2)) pp=find_word_end(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));
186
      else for(i=0, pp=p;i<2;i++) pp=find_word_end(find_word_start(pp));
187
        *pp=0;
187
      *pp=0;
188
        if(*p!=0) printf("<a href=\"%s\">%s</a>",homepage,p);
188
      if(*p!=0) printf("<a href=\"%s\">%s</a>",homepage,p);
189
    }
189
    }
190
}
190
}
191
 
191
 
192
char *dynsetup(char *ptr, char *end)
192
char *dynsetup(char *ptr, char *end)
193
{
193
{
194
    int i;
194
    int i;
195
    char *p, *pp;
195
    char *p, *pp;
196
    for(i=0;i<SETUP_NO;i++) {
196
    for(i=0;i<SETUP_NO;i++) {
197
        p=getenv(setups[i].wname);
197
      p=getenv(setups[i].wname);
198
        if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
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;
199
      if(p==NULL || *p==0) p=setups[i].defaultval;
200
        snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
200
      snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
201
        ptr+=strlen(ptr);
201
      ptr+=strlen(ptr);
202
        if(strstr(setups[i].wname,"maxima_precision")!=NULL)
202
      if(strstr(setups[i].wname,"maxima_precision")!=NULL)
203
          precision=atoi(p);
203
        precision=atoi(p);
204
        if(precision<0) precision=-precision;
204
      if(precision<0) precision=-precision;
205
    }
205
    }
206
    return ptr;
206
    return ptr;
207
}
207
}
208
 
208
 
209
int main(int argc,char *argv[])
209
int main(int argc,char *argv[])
210
{
210
{
211
    prepare1();
211
    prepare1();
212
    run();
212
    run();
213
    return 0;    
213
    return 0;
214
}
214
}
215
 
215