Subversion Repositories wimsdev

Rev

Rev 8529 | 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 Macaulay2 to wims */
  19.  
  20. /*************** Customization: change values hereafter ****************/
  21. #include "common.h"
  22.  
  23. /* This string tells m2 to exit. */
  24. char *quitstring="\nexit;\n";
  25. /* The way to print a string in the program. */
  26. char *stringprinter="print(\"%s\");\n";
  27. /* This is m2 home page. To be kept up to date. */
  28. #define homepage "https://faculty.math.illinois.edu/Macaulay2/"
  29. /* limit of input/output file sizes */
  30. int fsizelim=131072;
  31. int precision=20; /* default */
  32.  
  33. char *nameofcmd="M2";
  34. char header[]="Thing#{Standard,BeforePrint} = toString; \
  35. scan(methods {Standard,AfterPrint}, (a,b) -> installMethod(a,b,identity));\
  36. ";
  37.  
  38. struct {
  39.     char *wname; char *defaultval; char *setname;
  40. } setups[]={
  41. /* {"w_m2_precision", "20", "fpprec"}
  42. */};
  43.  
  44. /* names which are not allowed */
  45. char *illegal[]={
  46.       "exec","run","fork",
  47.       "input",  /* "load","needs", */
  48.       "tmpname", "path", "processID",
  49.       "getWWW", "getenv",
  50.       "<<", "close"
  51. };
  52.  
  53. int illegal_no=(sizeof(illegal)/sizeof(illegal[0]));
  54.  
  55. /* name parts which are not allowed */
  56. char *illpart[]={
  57. };
  58.  
  59. int illpart_no=(sizeof(illpart)/sizeof(illpart[0]));
  60.  
  61. /***************** Nothing should need change hereafter *****************/
  62.  
  63. char *progname="m2";
  64.  
  65. /* check for security violations in command string */
  66. void check_parm(char *pm)
  67. {
  68.     find_illegal(pm);
  69. }
  70.  
  71. char *find_prompt(char *p)
  72. {
  73.     char *pp=p, *pt;
  74.     redo:
  75.     if(*pp==0) return NULL;
  76.     pp=strstr(pp,"\ni");
  77.     pt=pp;
  78.     if(pp!=NULL) {
  79.       pp+=2; while(isdigit(*pp)) pp++;
  80.       if(*pp!=' ') goto redo;
  81.       while(*pp==' ') pp++;
  82.       if(*pp!=':' || *(pp+1)!=' ') goto redo;
  83.     }
  84.     return pt;
  85. }
  86.  
  87. /* process and print m2 output */
  88. void output(char *p)
  89. {
  90.     int i,n;
  91.     char *pp, *pe, *pt;
  92.  
  93.     pp=find_prompt(p);
  94.     while(pp!=NULL && *pp!=0) {
  95.       pe=find_prompt(pp+1); pp=strchr(pp+1,'\n');
  96.       if(pp==NULL) return;
  97.       if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
  98.       pp++;
  99.       if(strlen(pp)==0) {
  100.           emptyline:
  101.           puts(""); pp=pe; continue;
  102.       }
  103.       n=strlen(pp); if(n==0) goto emptyline;
  104. /* strip leading and trailing spaces */
  105.       while(isspace(*pp) && pp<pe) pp++;
  106.       pt=pp+strlen(pp)-1;
  107.       while(pt>=pp && isspace(*pt)) *pt--=0;
  108. /* make every output one-line */
  109.       for(i=0;i<n;i++) {
  110.           if(*(pp+i)=='\n') *(pp+i)='#';
  111.       }
  112.       puts(pp); pp=pe;
  113.     }
  114. }
  115.  
  116. void about(void)
  117. {
  118.     char *p;
  119.  
  120.     cmdparm=""; prepabout(quitstring,"/dev/null",outputfname);
  121.     if(readabout()>0) {
  122.       p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
  123.       strip_trailing_spaces2(aboutbuf);
  124.       printf("<a target=\"wims_external\" href=\"%s\">%s</a>",homepage,aboutbuf);
  125.     }
  126. }
  127.  
  128. char *dynsetup(char *ptr, char *end)
  129. {
  130.     int i;
  131.     char *p, *pp;
  132.  
  133.     for(i=0;i<SETUP_NO;i++) {
  134.       p=getenv(setups[i].wname);
  135.       if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
  136.       if(p==NULL || *p==0) p=setups[i].defaultval;
  137.       snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
  138.       ptr+=strlen(ptr);
  139.       if(strstr(setups[i].wname,"m2_precision")!=NULL)
  140.         precision=atoi(p);
  141.       if(precision<0) precision=-precision;
  142.     }
  143.     return ptr;
  144. }
  145.  
  146. int main(int argc,char *argv[])
  147. {
  148.     prepare1();
  149.     run();
  150.     return 0;
  151. }
  152.  
  153.