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