Subversion Repositories wimsdev

Rev

Rev 9894 | 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 gap to wims */
10 reyssat 19
 
20
/*************** Customization: change values hereafter ****************/
8120 bpr 21
#include "common.h"
10 reyssat 22
 
7674 bpr 23
/* gap prompt string */
10 reyssat 24
#define gapprompt "gap> "
7674 bpr 25
/* This string tells gap to exit. */
8120 bpr 26
char *quitstring="\nquit;\n";
8529 bpr 27
char *aboutquitstring="GAPInfo.Version;\nquit;\n";
7674 bpr 28
/* The way to print a string in the program. */
8120 bpr 29
char *stringprinter="Print(\"%s\\n\");\n";
7674 bpr 30
/* This is GAP home page. To be kept up to date. */
8501 bpr 31
#define homepage "http://www.gap-system.org/"
10 reyssat 32
 
8120 bpr 33
/* limit of input/output file sizes */
34
int fsizelim=131072;
35
int precision=20; /* default */
36
 
10 reyssat 37
char *nameofcmd="gap.sh -T -n";
38
char header[]="\n\
39
";
40
 
41
struct {
8120 bpr 42
    char *wname; char *defaultval;
10 reyssat 43
} setups[]={
44
};
45
 
7674 bpr 46
/* names which are not allowed */
10 reyssat 47
char *illegal[]={
48
      "Reread","Process","Exec","Filename","SaveWorkspace"
49
};
50
 
8120 bpr 51
int illegal_no=(sizeof(illegal)/sizeof(illegal[0]));
52
 
7674 bpr 53
/* name parts which are not allowed */
10 reyssat 54
char *illpart[]={
55
    "File", "Path", "Read", "To"
56
};
57
 
8120 bpr 58
int illpart_no=(sizeof(illpart)/sizeof(illpart[0]));
59
 
10 reyssat 60
/***************** Nothing should need change hereafter *****************/
61
 
8120 bpr 62
char *progname="gap";
10 reyssat 63
 
7674 bpr 64
/* check for security violations in command string */
10 reyssat 65
void check_parm(char *pm)
66
{
67
    char *pp; int l;
7674 bpr 68
/* Underscore replacement */
10 reyssat 69
    for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
8100 bpr 70
    strip_trailing_spaces2(pm); l=strlen(pm);
10 reyssat 71
    if(l>0 && pm[l-1]!=';') strcat(pm,";");
72
    find_illegal(pm);
73
}
74
 
7674 bpr 75
/* process and print gap output */
10 reyssat 76
void output(char *p)
77
{
78
    int i,n;
79
    char *pp, *pe, *pt;
80
 
81
    pp=strstr(p,gapprompt); if(pp==NULL) return;
3718 reyssat 82
    while((pt=strstr(pp,"\\\n"))!=NULL) ovlstrcpy(pt,pt+2);
10 reyssat 83
    while(pp!=NULL) {
7674 bpr 84
      pp+=strlen(gapprompt);
85
      pe=strstr(pp,gapprompt);
86
      if(pe>=pp) *pe=0;
87
      if(pe!=NULL && pp>=pe) {
88
          emptyline:
89
          puts(""); pp=pe; continue;
90
      }
91
      n=strlen(pp);
92
      if(n==0) goto emptyline;
93
/* make every output one-line */
94
      for(i=0;i<n;i++) {
95
          if(*(pp+i)=='\n') {
96
            if(*(pp+i+1)!='%') *(pp+i)=' ';
97
            else {*(pp+i)=0; break;}
98
          }
99
      }
100
/* strip leading and trailing spaces */
101
      while(isspace(*pp) && pp<pe) pp++;
102
      pt=pp+strlen(pp)-1;
103
      while(isspace(*pt) && pt>pp) *pt--=0;
104
      if(*pp=='[' && *pt==']') {
105
          *(pt--)=0; pp++;
106
      }
107
      puts(pp); pp=pe;
10 reyssat 108
    }
109
}
110
 
111
void about(void)
8529 bpr 112
{    char *p;
113
    prepabout(aboutquitstring,outputfname,NULL);
10 reyssat 114
    if(readabout()>0) {
9894 bpr 115
/* Take first line in version message */
7674 bpr 116
      p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
9894 bpr 117
/* delete garbage before "GAP" */
9893 bpr 118
      p=aboutbuf; while(*p && *p!='G') p++;
119
      strip_trailing_spaces(p);
120
      printf("<a target=\"wims_external\" href=\"%s\">%s</a>",homepage,p);
10 reyssat 121
    }
122
}
123
 
124
char *dynsetup(char *ptr, char *end)
125
{
126
    int i;
127
    char *p, *pp;
12011 bpr 128
/* to adapt
129
    if(wseed!= NULL) snprintf(ptr,end-ptr,"\nwimsseed:make_random_state(%u);\nset_random_state(wimsseed);\n",atoi(wseed)&(0x7FFFFFFF));
130
    ptr+=strlen(ptr);
131
*/
10 reyssat 132
    for(i=0;i<SETUP_NO;i++) {
7674 bpr 133
      p=getenv(setups[i].wname);
134
      if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
135
      if(p==NULL || *p==0) p=setups[i].defaultval;
10 reyssat 136
    }
137
    return ptr;
138
}
139
 
140
int main(int argc,char *argv[])
141
{
142
    prepare1();
8526 bpr 143
    setenv("HOME","/nodir",1);
10 reyssat 144
    run();
7674 bpr 145
    return 0;
10 reyssat 146
}