Back to index

wims  3.65+svn20090927
m2.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018        /* Interface Macaulay2 to wims */
00019 
00020 /*************** Customization: change values hereafter ****************/
00021 
00022        /* limit of input/output file sizes */
00023 #define fsizelim 131072
00024        /* This string tells m2 to exit. */
00025 #define quitstring "\nexit;\n"
00026        /* The way to print a string in the program. */
00027 #define stringprinter "print(\"%s\");\n"
00028        /* This is m2 home page. To be kept up to date. */
00029 #define homepage "http://www.math.uiuc.edu/Macaulay2/"
00030 
00031 char *nameofcmd="M2";
00032 int precision=20;    /* default */
00033 char header[]="\
00034 ";
00035 
00036 struct {
00037     char *wname;    char *defaultval;     char *setname;
00038 } setups[]={
00039 /*     {"w_m2_precision",   "20",  "fpprec"}
00040 */};
00041 
00042        /* names which are not allowed */
00043 char *illegal[]={
00044       "exec","run","fork",
00045       "input",  /* "load","needs", */
00046       "tmpname",
00047       "getWWW",
00048 };
00049 
00050        /* name parts which are not allowed */
00051 char *illpart[]={
00052 };
00053 
00054 /***************** Nothing should need change hereafter *****************/
00055 
00056 #define progname "m2"
00057 #include "common.h"
00058 #include "common.c"
00059 
00060        /* check for security violations in command string */
00061 void check_parm(char *pm)
00062 {
00063     find_illegal(pm);
00064 }
00065 
00066 char *find_prompt(char *p)
00067 {
00068     char *pp=p, *pt;
00069     redo:
00070     if(*pp==0) return NULL;
00071     pp=strstr(pp,"\ni");
00072     pt=pp;
00073     if(pp!=NULL) {
00074        pp+=2; while(isdigit(*pp)) pp++;
00075        if(*pp!=' ') goto redo;
00076        while(*pp==' ') pp++;
00077        if(*pp!=':' || *(pp+1)!=' ') goto redo;
00078     }
00079     return pt;
00080 }
00081 
00082        /* process and print m2 output */
00083 void output(char *p)
00084 {
00085     int i,n;
00086     char *pp, *pe, *pt;
00087 
00088     pp=find_prompt(p);
00089     while(pp!=NULL && *pp!=0) {
00090        pe=find_prompt(pp+1); pp=strchr(pp+1,'\n');
00091        if(pp==NULL) return;
00092        if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
00093        pp++;
00094        if(strlen(pp)==0) {
00095            emptyline:
00096            puts(""); pp=pe; continue;
00097        }
00098        n=strlen(pp); if(n==0) goto emptyline;
00099          /* strip leading and trailing spaces */
00100        while(isspace(*pp) && pp<pe) pp++;
00101        pt=pp+strlen(pp)-1;
00102        while(pt>=pp && isspace(*pt)) *pt--=0;
00103               /* make every output one-line */
00104        for(i=0;i<n;i++) {
00105            if(*(pp+i)=='\n') *(pp+i)='#';
00106        }
00107        puts(pp); pp=pe;
00108     }
00109 }
00110 
00111 void about(void)
00112 {
00113     char *p;
00114 
00115     cmdparm=""; prepabout(quitstring,"/dev/null",outputfname);
00116     if(readabout()>0) {
00117        p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
00118        strip_trailing_spaces(aboutbuf);
00119        printf("<A HREF=\"%s\">%s</A>",homepage,aboutbuf);
00120     }
00121 }
00122 
00123 char *dynsetup(char *ptr, char *end)
00124 {
00125     int i;
00126     char *p, *pp;
00127     
00128     for(i=0;i<SETUP_NO;i++) {
00129        p=getenv(setups[i].wname);
00130        if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
00131        if(p==NULL || *p==0) p=setups[i].defaultval;
00132        snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
00133        ptr+=strlen(ptr);
00134        if(strstr(setups[i].wname,"m2_precision")!=NULL)
00135          precision=atoi(p);
00136        if(precision<0) precision=-precision;
00137     }
00138     return ptr;
00139 }
00140 
00141 int main(int argc,char *argv[])
00142 {
00143     prepare1();
00144     run();
00145     return 0;    
00146 }
00147