Subversion Repositories wimsdev

Rev

Rev 12011 | 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. char *aboutquitstring="GAPInfo.Version;\nquit;\n";
  28. /* The way to print a string in the program. */
  29. char *stringprinter="Print(\"%s\\n\");\n";
  30. /* This is GAP home page. To be kept up to date. */
  31. #define homepage "http://www.gap-system.org/"
  32.  
  33. /* limit of input/output file sizes */
  34. int fsizelim=131072;
  35. int precision=20; /* default */
  36.  
  37. char *nameofcmd="gap.sh -T -n";
  38. char header[]="\n\
  39. ";
  40.  
  41. struct {
  42.     char *wname; char *defaultval;
  43. } setups[]={
  44. };
  45.  
  46. /* names which are not allowed */
  47. char *illegal[]={
  48.       "Reread","Process","Exec","Filename","SaveWorkspace"
  49. };
  50.  
  51. int illegal_no=(sizeof(illegal)/sizeof(illegal[0]));
  52.  
  53. /* name parts which are not allowed */
  54. char *illpart[]={
  55.     "File", "Path", "Read", "To"
  56. };
  57.  
  58. int illpart_no=(sizeof(illpart)/sizeof(illpart[0]));
  59.  
  60. /***************** Nothing should need change hereafter *****************/
  61.  
  62. char *progname="gap";
  63.  
  64. /* check for security violations in command string */
  65. void check_parm(char *pm)
  66. {
  67.     char *pp; int l;
  68. /* Underscore replacement */
  69.     for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
  70.     strip_trailing_spaces2(pm); l=strlen(pm);
  71.     if(l>0 && pm[l-1]!=';') strcat(pm,";");
  72.     find_illegal(pm);
  73. }
  74.  
  75. /* process and print gap output */
  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;
  82.     while((pt=strstr(pp,"\\\n"))!=NULL) ovlstrcpy(pt,pt+2);
  83.     while(pp!=NULL) {
  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;
  108.     }
  109. }
  110.  
  111. void about(void)
  112. {    char *p;
  113.     prepabout(aboutquitstring,outputfname,NULL);
  114.     if(readabout()>0) {
  115. /* Take first line in version message */
  116.       p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
  117. /* delete garbage before "GAP" */
  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);
  121.     }
  122. }
  123.  
  124. char *dynsetup(char *ptr, char *end)
  125. {
  126.     int i;
  127.     char *p, *pp;
  128.     if(wseed!= NULL) snprintf(ptr,end-ptr,"\nReset(GlobalMersenneTwister,%u);",atoi(wseed)&(0x7FFFFFFF));
  129.     ptr+=strlen(ptr);
  130.  
  131.     for(i=0;i<SETUP_NO;i++) {
  132.       p=getenv(setups[i].wname);
  133.       if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
  134.       if(p==NULL || *p==0) p=setups[i].defaultval;
  135.     }
  136.     return ptr;
  137. }
  138.  
  139. int main(int argc,char *argv[])
  140. {
  141.     prepare1();
  142.     setenv("HOME","/nodir",1);
  143.     run();
  144.     return 0;
  145. }
  146.