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 gap to wims */
18
/* Interface gap 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
        /* gap prompt string */
24
/* gap prompt string */
25
#define gapprompt "gap> "
25
#define gapprompt "gap> "
26
        /* This string tells gap to exit. */
26
/* This string tells gap to exit. */
27
#define quitstring "\nquit;\n"
27
#define quitstring "\nquit;\n"
28
        /* The way to print a string in the program. */
28
/* The way to print a string in the program. */
29
#define stringprinter "Print(\"%s\\n\");\n"
29
#define stringprinter "Print(\"%s\\n\");\n"
30
        /* This is GAP home page. To be kept up to date. */
30
/* This is GAP home page. To be kept up to date. */
31
#define homepage "http://www-gap.dcs.st-and.ac.uk/~gap"
31
#define homepage "http://www-gap.dcs.st-and.ac.uk/~gap"
32
 
32
 
33
char *nameofcmd="gap.sh -T -n";
33
char *nameofcmd="gap.sh -T -n";
34
int precision=20; /* default */
34
int precision=20; /* default */
35
char header[]="\n\
35
char header[]="\n\
Line 38... Line 38...
38
struct {
38
struct {
39
    char *wname;    char *defaultval;
39
    char *wname;    char *defaultval;
40
} setups[]={
40
} setups[]={
41
};
41
};
42
 
42
 
43
        /* names which are not allowed */
43
/* names which are not allowed */
44
char *illegal[]={
44
char *illegal[]={
45
      "Reread","Process","Exec","Filename","SaveWorkspace"
45
      "Reread","Process","Exec","Filename","SaveWorkspace"
46
};
46
};
47
 
47
 
48
        /* name parts which are not allowed */
48
/* name parts which are not allowed */
49
char *illpart[]={
49
char *illpart[]={
50
    "File", "Path", "Read", "To"
50
    "File", "Path", "Read", "To"
51
};
51
};
52
 
52
 
53
/***************** Nothing should need change hereafter *****************/
53
/***************** Nothing should need change hereafter *****************/
54
 
54
 
55
#define progname "gap"
55
#define progname "gap"
56
#include "common.h"
56
#include "common.h"
57
#include "common.c"
57
#include "common.c"
58
 
58
 
59
        /* check for security violations in command string */
59
/* check for security violations in command string */
60
void check_parm(char *pm)
60
void check_parm(char *pm)
61
{
61
{
62
    char *pp; int l;
62
    char *pp; int l;
63
          /* Underscore replacement */
63
/* Underscore replacement */
64
    for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
64
    for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
65
    strip_trailing_spaces(pm); l=strlen(pm);
65
    strip_trailing_spaces(pm); l=strlen(pm);
66
    if(l>0 && pm[l-1]!=';') strcat(pm,";");
66
    if(l>0 && pm[l-1]!=';') strcat(pm,";");
67
    find_illegal(pm);
67
    find_illegal(pm);
68
}
68
}
69
 
69
 
70
        /* process and print gap output */
70
/* process and print gap output */
71
void output(char *p)
71
void output(char *p)
72
{
72
{
73
    int i,n;
73
    int i,n;
74
    char *pp, *pe, *pt;
74
    char *pp, *pe, *pt;
75
 
75
 
76
    pp=strstr(p,gapprompt); if(pp==NULL) return;
76
    pp=strstr(p,gapprompt); if(pp==NULL) return;
77
    while((pt=strstr(pp,"\\\n"))!=NULL) ovlstrcpy(pt,pt+2);
77
    while((pt=strstr(pp,"\\\n"))!=NULL) ovlstrcpy(pt,pt+2);
78
    while(pp!=NULL) {
78
    while(pp!=NULL) {
79
        pp+=strlen(gapprompt);
79
      pp+=strlen(gapprompt);
80
        pe=strstr(pp,gapprompt);
80
      pe=strstr(pp,gapprompt);
81
        if(pe>=pp) *pe=0;
81
      if(pe>=pp) *pe=0;
82
        if(pe!=NULL && pp>=pe) {
82
      if(pe!=NULL && pp>=pe) {
83
            emptyline:
83
          emptyline:
84
            puts(""); pp=pe; continue;
84
          puts(""); pp=pe; continue;
85
        }
85
      }
86
        n=strlen(pp);
86
      n=strlen(pp);
87
        if(n==0) goto emptyline;
87
      if(n==0) goto emptyline;
88
                /* make every output one-line */
88
/* make every output one-line */
89
        for(i=0;i<n;i++) {
89
      for(i=0;i<n;i++) {
90
            if(*(pp+i)=='\n') {
90
          if(*(pp+i)=='\n') {
91
                if(*(pp+i+1)!='%') *(pp+i)=' ';
91
            if(*(pp+i+1)!='%') *(pp+i)=' ';
92
                else {*(pp+i)=0; break;}
92
            else {*(pp+i)=0; break;}
93
            }
93
          }
94
        }
94
      }
95
          /* strip leading and trailing spaces */
95
/* strip leading and trailing spaces */
96
        while(isspace(*pp) && pp<pe) pp++;
96
      while(isspace(*pp) && pp<pe) pp++;
97
        pt=pp+strlen(pp)-1;
97
      pt=pp+strlen(pp)-1;
98
        while(isspace(*pt) && pt>pp) *pt--=0;
98
      while(isspace(*pt) && pt>pp) *pt--=0;
99
        if(*pp=='[' && *pt==']') {
99
      if(*pp=='[' && *pt==']') {
100
            *(pt--)=0; pp++;
100
          *(pt--)=0; pp++;
101
        }
101
      }
102
        puts(pp); pp=pe;
102
      puts(pp); pp=pe;
103
    }
103
    }
104
}
104
}
105
 
105
 
106
void about(void)
106
void about(void)
107
{
107
{
108
/*    char *p;
108
/*    char *p;
109
*/
109
*/
110
    printf("<a href=\"%s\">GAP4</a>",homepage); return;
110
    printf("<a href=\"%s\">GAP4</a>",homepage); return;
111
/*    prepabout(quitstring,outputfname,NULL);
111
/*    prepabout(quitstring,outputfname,NULL);
112
    if(readabout()>0) {
112
    if(readabout()>0) {
113
        p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
113
      p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
114
        strip_trailing_spaces(aboutbuf);
114
      strip_trailing_spaces(aboutbuf);
115
        printf("<A HREF=\"%s\">%s</A>",homepage,aboutbuf);
115
      printf("<A HREF=\"%s\">%s</A>",homepage,aboutbuf);
116
    }
116
    }
117
*/
117
*/
118
}
118
}
119
 
119
 
120
char *dynsetup(char *ptr, char *end)
120
char *dynsetup(char *ptr, char *end)
121
{
121
{
122
    int i;
122
    int i;
123
    char *p, *pp;
123
    char *p, *pp;
124
    for(i=0;i<SETUP_NO;i++) {
124
    for(i=0;i<SETUP_NO;i++) {
125
        p=getenv(setups[i].wname);
125
      p=getenv(setups[i].wname);
126
        if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
126
      if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
127
        if(p==NULL || *p==0) p=setups[i].defaultval;
127
      if(p==NULL || *p==0) p=setups[i].defaultval;
128
    }
128
    }
129
    return ptr;
129
    return ptr;
130
}
130
}
131
 
131
 
132
int main(int argc,char *argv[])
132
int main(int argc,char *argv[])
133
{
133
{
134
    prepare1();
134
    prepare1();
135
    run();
135
    run();
136
    return 0;    
136
    return 0;
137
}
137
}
138
 
-