Subversion Repositories wimsdev

Rev

Rev 8100 | Rev 8149 | 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 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 "http://www.math.uiuc.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. /*#include "common.c"*/
  66.  
  67. /* check for security violations in command string */
  68. void check_parm(char *pm)
  69. {
  70.     find_illegal(pm);
  71. }
  72.  
  73. char *find_prompt(char *p)
  74. {
  75.     char *pp=p, *pt;
  76.     redo:
  77.     if(*pp==0) return NULL;
  78.     pp=strstr(pp,"\ni");
  79.     pt=pp;
  80.     if(pp!=NULL) {
  81.       pp+=2; while(isdigit(*pp)) pp++;
  82.       if(*pp!=' ') goto redo;
  83.       while(*pp==' ') pp++;
  84.       if(*pp!=':' || *(pp+1)!=' ') goto redo;
  85.     }
  86.     return pt;
  87. }
  88.  
  89. /* process and print m2 output */
  90. void output(char *p)
  91. {
  92.     int i,n;
  93.     char *pp, *pe, *pt;
  94.  
  95.     pp=find_prompt(p);
  96.     while(pp!=NULL && *pp!=0) {
  97.       pe=find_prompt(pp+1); pp=strchr(pp+1,'\n');
  98.       if(pp==NULL) return;
  99.       if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
  100.       pp++;
  101.       if(strlen(pp)==0) {
  102.           emptyline:
  103.           puts(""); pp=pe; continue;
  104.       }
  105.       n=strlen(pp); if(n==0) goto emptyline;
  106. /* strip leading and trailing spaces */
  107.       while(isspace(*pp) && pp<pe) pp++;
  108.       pt=pp+strlen(pp)-1;
  109.       while(pt>=pp && isspace(*pt)) *pt--=0;
  110. /* make every output one-line */
  111.       for(i=0;i<n;i++) {
  112.           if(*(pp+i)=='\n') *(pp+i)='#';
  113.       }
  114.       puts(pp); pp=pe;
  115.     }
  116. }
  117.  
  118. void about(void)
  119. {
  120.     char *p;
  121.  
  122.     cmdparm=""; prepabout(quitstring,"/dev/null",outputfname);
  123.     if(readabout()>0) {
  124.       p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
  125.       strip_trailing_spaces2(aboutbuf);
  126.       printf("<a href=\"%s\">%s</a>",homepage,aboutbuf);
  127.     }
  128. }
  129.  
  130. char *dynsetup(char *ptr, char *end)
  131. {
  132.     int i;
  133.     char *p, *pp;
  134.  
  135.     for(i=0;i<SETUP_NO;i++) {
  136.       p=getenv(setups[i].wname);
  137.       if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
  138.       if(p==NULL || *p==0) p=setups[i].defaultval;
  139.       snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
  140.       ptr+=strlen(ptr);
  141.       if(strstr(setups[i].wname,"m2_precision")!=NULL)
  142.         precision=atoi(p);
  143.       if(precision<0) precision=-precision;
  144.     }
  145.     return ptr;
  146. }
  147.  
  148. int main(int argc,char *argv[])
  149. {
  150.     prepare1();
  151.     run();
  152.     return 0;
  153. }
  154.  
  155.