Subversion Repositories wimsdev

Rev

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