Back to index

wims  3.65+svn20090927
gap.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018        /* Interface gap to wims */
00019 
00020 /*************** Customization: change values hereafter ****************/
00021 
00022        /* limit of input/output file sizes */
00023 #define fsizelim 131072
00024        /* gap prompt string */
00025 #define gapprompt "gap> "
00026        /* This string tells gap to exit. */
00027 #define quitstring "\nquit;\n"
00028        /* The way to print a string in the program. */
00029 #define stringprinter "Print(\"%s\\n\");\n"
00030        /* This is GAP home page. To be kept up to date. */
00031 #define homepage "http://www-gap.dcs.st-and.ac.uk/~gap"
00032 
00033 char *nameofcmd="gap.sh -T -n";
00034 int precision=20; /* default */
00035 char header[]="\n\
00036 ";
00037 
00038 struct {
00039     char *wname;    char *defaultval;
00040 } setups[]={
00041 };
00042 
00043        /* names which are not allowed */
00044 char *illegal[]={
00045       "Reread","Process","Exec","Filename","SaveWorkspace"
00046 };
00047 
00048        /* name parts which are not allowed */
00049 char *illpart[]={
00050     "File", "Path", "Read", "To"
00051 };
00052 
00053 /***************** Nothing should need change hereafter *****************/
00054 
00055 #define progname "gap"
00056 #include "common.h"
00057 #include "common.c"
00058 
00059        /* check for security violations in command string */
00060 void check_parm(char *pm)
00061 {
00062     char *pp; int l;
00063          /* Underscore replacement */
00064     for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
00065     strip_trailing_spaces(pm); l=strlen(pm);
00066     if(l>0 && pm[l-1]!=';') strcat(pm,";");
00067     find_illegal(pm);
00068 }
00069 
00070        /* process and print gap output */
00071 void output(char *p)
00072 {
00073     int i,n;
00074     char *pp, *pe, *pt;
00075 
00076     pp=strstr(p,gapprompt); if(pp==NULL) return;
00077     while((pt=strstr(pp,"\\\n"))!=NULL) strcpy(pt,pt+2);
00078     while(pp!=NULL) {
00079        pp+=strlen(gapprompt);
00080        pe=strstr(pp,gapprompt);
00081        if(pe>=pp) *pe=0;
00082        if(pe!=NULL && pp>=pe) {
00083            emptyline:
00084            puts(""); pp=pe; continue;
00085        }
00086        n=strlen(pp);
00087        if(n==0) goto emptyline;
00088               /* make every output one-line */
00089        for(i=0;i<n;i++) {
00090            if(*(pp+i)=='\n') {
00091               if(*(pp+i+1)!='%') *(pp+i)=' ';
00092               else {*(pp+i)=0; break;}
00093            }
00094        }
00095          /* strip leading and trailing spaces */
00096        while(isspace(*pp) && pp<pe) pp++;
00097        pt=pp+strlen(pp)-1;
00098        while(isspace(*pt) && pt>pp) *pt--=0;
00099        if(*pp=='[' && *pt==']') {
00100            *(pt--)=0; pp++;
00101        }
00102        puts(pp); pp=pe;
00103     }
00104 }
00105 
00106 void about(void)
00107 {
00108 /*    char *p;
00109 */
00110     printf("<A HREF=\"%s\">GAP4</A>",homepage); return;
00111 /*    prepabout(quitstring,outputfname,NULL);
00112     if(readabout()>0) {
00113        p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
00114        strip_trailing_spaces(aboutbuf);
00115        printf("<A HREF=\"%s\">%s</A>",homepage,aboutbuf);
00116     }
00117 */
00118 }
00119 
00120 char *dynsetup(char *ptr, char *end)
00121 {
00122     int i;
00123     char *p, *pp;
00124     for(i=0;i<SETUP_NO;i++) {
00125        p=getenv(setups[i].wname);
00126        if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
00127        if(p==NULL || *p==0) p=setups[i].defaultval;
00128     }
00129     return ptr;
00130 }
00131 
00132 int main(int argc,char *argv[])
00133 {
00134     prepare1();
00135     run();
00136     return 0;    
00137 }
00138