Subversion Repositories wimsdev

Rev

Rev 8100 | Rev 8149 | 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 Macaulay2 to wims */
10 reyssat 19
 
20
/*************** Customization: change values hereafter ****************/
8120 bpr 21
#include "common.h"
10 reyssat 22
 
7674 bpr 23
/* This string tells m2 to exit. */
8120 bpr 24
char *quitstring="\nexit;\n";
7674 bpr 25
/* The way to print a string in the program. */
8120 bpr 26
char *stringprinter="print(\"%s\");\n";
7674 bpr 27
/* This is m2 home page. To be kept up to date. */
10 reyssat 28
#define homepage "http://www.math.uiuc.edu/Macaulay2/"
8120 bpr 29
/* limit of input/output file sizes */
30
int fsizelim=131072;
31
int precision=20; /* default */
10 reyssat 32
 
33
char *nameofcmd="M2";
3898 bpr 34
char header[]="Thing#{Standard,BeforePrint} = toString; \
35
scan(methods {Standard,AfterPrint}, (a,b) -> installMethod(a,b,identity));\
10 reyssat 36
";
37
 
38
struct {
7674 bpr 39
    char *wname; char *defaultval; char *setname;
10 reyssat 40
} setups[]={
7674 bpr 41
/* {"w_m2_precision", "20", "fpprec"}
10 reyssat 42
*/};
43
 
7674 bpr 44
/* names which are not allowed */
10 reyssat 45
char *illegal[]={
46
      "exec","run","fork",
47
      "input",  /* "load","needs", */
3898 bpr 48
      "tmpname", "path", "processID",
49
      "getWWW", "getenv",
50
      "<<", "close"
10 reyssat 51
};
52
 
8120 bpr 53
int illegal_no=(sizeof(illegal)/sizeof(illegal[0]));
54
 
7674 bpr 55
/* name parts which are not allowed */
10 reyssat 56
char *illpart[]={
57
};
58
 
8120 bpr 59
int illpart_no=(sizeof(illpart)/sizeof(illpart[0]));
60
 
10 reyssat 61
/***************** Nothing should need change hereafter *****************/
62
 
8120 bpr 63
char *progname="m2";
10 reyssat 64
 
8120 bpr 65
/*#include "common.c"*/
66
 
7674 bpr 67
/* check for security violations in command string */
10 reyssat 68
void check_parm(char *pm)
69
{
70
    find_illegal(pm);
71
}
72
 
73
char *find_prompt(char *p)
74
{
75
    char *pp=p, *pt;
76
    redo:
77
    if(*pp==0) return NULL;
78
    pp=strstr(pp,"\ni");
79
    pt=pp;
80
    if(pp!=NULL) {
7674 bpr 81
      pp+=2; while(isdigit(*pp)) pp++;
82
      if(*pp!=' ') goto redo;
83
      while(*pp==' ') pp++;
84
      if(*pp!=':' || *(pp+1)!=' ') goto redo;
10 reyssat 85
    }
86
    return pt;
87
}
88
 
7674 bpr 89
/* process and print m2 output */
10 reyssat 90
void output(char *p)
91
{
92
    int i,n;
93
    char *pp, *pe, *pt;
94
 
95
    pp=find_prompt(p);
96
    while(pp!=NULL && *pp!=0) {
7674 bpr 97
      pe=find_prompt(pp+1); pp=strchr(pp+1,'\n');
98
      if(pp==NULL) return;
99
      if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
100
      pp++;
101
      if(strlen(pp)==0) {
102
          emptyline:
103
          puts(""); pp=pe; continue;
104
      }
105
      n=strlen(pp); if(n==0) goto emptyline;
106
/* strip leading and trailing spaces */
107
      while(isspace(*pp) && pp<pe) pp++;
108
      pt=pp+strlen(pp)-1;
109
      while(pt>=pp && isspace(*pt)) *pt--=0;
110
/* make every output one-line */
111
      for(i=0;i<n;i++) {
112
          if(*(pp+i)=='\n') *(pp+i)='#';
113
      }
114
      puts(pp); pp=pe;
10 reyssat 115
    }
116
}
117
 
118
void about(void)
119
{
120
    char *p;
121
 
122
    cmdparm=""; prepabout(quitstring,"/dev/null",outputfname);
123
    if(readabout()>0) {
7674 bpr 124
      p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
8100 bpr 125
      strip_trailing_spaces2(aboutbuf);
7674 bpr 126
      printf("<a href=\"%s\">%s</a>",homepage,aboutbuf);
10 reyssat 127
    }
128
}
129
 
130
char *dynsetup(char *ptr, char *end)
131
{
132
    int i;
133
    char *p, *pp;
7674 bpr 134
 
10 reyssat 135
    for(i=0;i<SETUP_NO;i++) {
7674 bpr 136
      p=getenv(setups[i].wname);
137
      if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
138
      if(p==NULL || *p==0) p=setups[i].defaultval;
139
      snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
140
      ptr+=strlen(ptr);
141
      if(strstr(setups[i].wname,"m2_precision")!=NULL)
142
        precision=atoi(p);
143
      if(precision<0) precision=-precision;
10 reyssat 144
    }
145
    return ptr;
146
}
147
 
148
int main(int argc,char *argv[])
149
{
150
    prepare1();
151
    run();
7674 bpr 152
    return 0;
10 reyssat 153
}
154