Subversion Repositories wimsdev

Rev

Rev 5762 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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