Subversion Repositories wimsdev

Rev

Rev 8529 | 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. */
13285 obado 28
#define homepage "https://faculty.math.illinois.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
 
7674 bpr 65
/* check for security violations in command string */
10 reyssat 66
void check_parm(char *pm)
67
{
68
    find_illegal(pm);
69
}
70
 
71
char *find_prompt(char *p)
72
{
73
    char *pp=p, *pt;
74
    redo:
75
    if(*pp==0) return NULL;
76
    pp=strstr(pp,"\ni");
77
    pt=pp;
78
    if(pp!=NULL) {
7674 bpr 79
      pp+=2; while(isdigit(*pp)) pp++;
80
      if(*pp!=' ') goto redo;
81
      while(*pp==' ') pp++;
82
      if(*pp!=':' || *(pp+1)!=' ') goto redo;
10 reyssat 83
    }
84
    return pt;
85
}
86
 
7674 bpr 87
/* process and print m2 output */
10 reyssat 88
void output(char *p)
89
{
90
    int i,n;
91
    char *pp, *pe, *pt;
92
 
93
    pp=find_prompt(p);
94
    while(pp!=NULL && *pp!=0) {
7674 bpr 95
      pe=find_prompt(pp+1); pp=strchr(pp+1,'\n');
96
      if(pp==NULL) return;
97
      if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
98
      pp++;
99
      if(strlen(pp)==0) {
100
          emptyline:
101
          puts(""); pp=pe; continue;
102
      }
103
      n=strlen(pp); if(n==0) goto emptyline;
104
/* strip leading and trailing spaces */
105
      while(isspace(*pp) && pp<pe) pp++;
106
      pt=pp+strlen(pp)-1;
107
      while(pt>=pp && isspace(*pt)) *pt--=0;
108
/* make every output one-line */
109
      for(i=0;i<n;i++) {
110
          if(*(pp+i)=='\n') *(pp+i)='#';
111
      }
112
      puts(pp); pp=pe;
10 reyssat 113
    }
114
}
115
 
116
void about(void)
117
{
118
    char *p;
119
 
120
    cmdparm=""; prepabout(quitstring,"/dev/null",outputfname);
121
    if(readabout()>0) {
7674 bpr 122
      p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
8100 bpr 123
      strip_trailing_spaces2(aboutbuf);
8529 bpr 124
      printf("<a target=\"wims_external\" href=\"%s\">%s</a>",homepage,aboutbuf);
10 reyssat 125
    }
126
}
127
 
128
char *dynsetup(char *ptr, char *end)
129
{
130
    int i;
131
    char *p, *pp;
7674 bpr 132
 
10 reyssat 133
    for(i=0;i<SETUP_NO;i++) {
7674 bpr 134
      p=getenv(setups[i].wname);
135
      if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
136
      if(p==NULL || *p==0) p=setups[i].defaultval;
137
      snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
138
      ptr+=strlen(ptr);
139
      if(strstr(setups[i].wname,"m2_precision")!=NULL)
140
        precision=atoi(p);
141
      if(precision<0) precision=-precision;
10 reyssat 142
    }
143
    return ptr;
144
}
145
 
146
int main(int argc,char *argv[])
147
{
148
    prepare1();
149
    run();
7674 bpr 150
    return 0;
10 reyssat 151
}
152