Subversion Repositories wimsdev

Rev

Rev 5762 | 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 Yacas to wims */
  19.  
  20. /*************** Customization: change values hereafter ****************/
  21.  
  22.         /* This is yacas home page. To be kept up to date. */
  23. #define homepage "http://yacas.sourceforge.net/"
  24.         /* String to tell the program to quit. */
  25. #define quitstring "\nquit\n"
  26.         /* The way to print a string in the program. */
  27. #define stringprinter "\"%s\"\n"
  28.         /* limit of input/output file sizes */
  29. int fsizelim=131072;
  30. int precision=20;       /* default */
  31.  
  32. char *inprompt="\nIn>";
  33. char *outprompt="Out>";
  34.  
  35. char *nameofcmd="yacas -p";
  36.  
  37. #include "yacasheader.c"
  38.  
  39. struct {
  40.     char *wname;    char *defaultval;    char *yacasset;
  41. } setups[]={
  42.       {"w_yacas_precision",     "20",   "\\precision=",},
  43.       {"w_yacas_serieslength",  "8",    "\\serieslength="}
  44. };
  45.  
  46.         /* names which are not allowed */
  47. char *illegal[]={
  48.     "SystemCall", "Use", "Vi", "GetYacasPID", "ShowPS",
  49.       "MakeFunctionPlugin"
  50. };
  51.  
  52.         /* name parts which are not allowed */
  53. char *illpart[]={
  54.     "File", "Load", "Plot"
  55. };
  56.  
  57. /***************** Nothing should need change hereafter *****************/
  58.  
  59. #define progname "yacas"
  60. #include "common.h"
  61. #include "common.c"
  62.  
  63.         /* check for security violations in command string */
  64. void check_parm(char *pm)
  65. {
  66.     char *p, *pp, *p2, buf[16];
  67.     int i;
  68.    
  69.     for(p=pm;*p!=0;p++) {
  70.         if(*p!='\\') continue;
  71.         if(*(p+1)=='\n') *p=*(p+1)=' ';
  72.         if(*(p+1)==0) *p=' ';
  73.     }
  74.     for(p=pm; *p!=0; p++) {
  75.         if(!isalpha(*p)) continue;
  76.         for(p2=p+1; isalpha(*p2); p2++);
  77.         if(p2-p>10) {p=p2-1; continue;}
  78.         memmove(buf,p,p2-p); buf[p2-p]=0; pp=p; p=p2-1;
  79.         for(p2=buf; islower(*p2); p2++);
  80.         if(*p2) continue;
  81.         i=search_list(firstupper,firstupperno,sizeof(firstupper[0]),buf);
  82.         if(i>=0) *pp=toupper(*pp);
  83.     }
  84.     find_illegal(pm);
  85. }
  86.  
  87.  
  88.         /* process and print yacas output */
  89. void output(char *p)
  90. {
  91.     int i,n;
  92.     char *pp, *pe, *p1, *pt;
  93.     char outbuf[MAX_LINELEN+1];
  94.    
  95.     pp=strstr(p,inprompt); if(pp==NULL) return;
  96.     while(pp!=NULL && *pp!=0) {
  97.         pp+=strlen(inprompt); p1=find_word_start(pp);
  98.         pe=strstr(pp,outprompt);
  99.         pt=strstr(pp,inprompt);
  100.         if(pe==NULL || (pt!=NULL && pt<pe)) { /* error */
  101.             if(pt==NULL) pp=pp+strlen(pp); else pp=pt;
  102.             n=pp-p1; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0;
  103.             memmove(outbuf,p1,n); outbuf[n]=0;
  104.             fprintf(stderr,"%s\n",outbuf);
  105.             puts(""); continue;
  106.         }
  107.         else {
  108.             *pe=0; pe=find_word_start(pe+strlen(outprompt));
  109.         }
  110.         pp=strstr(pe,inprompt);
  111.         if(pp==NULL) pp=pe+strlen(pe);
  112.         if(*p1==0) {
  113.             if(pp>=pe+sizeof(outbuf)) break;
  114.             n=pp-pe; if(n>MAX_LINELEN) n=MAX_LINELEN; if(n<0) n=0;
  115.             memmove(outbuf,pe,n); outbuf[n]=0;
  116.         }
  117.         else {
  118.             snprintf(outbuf,sizeof(outbuf),"%s",p1);
  119.             n=strlen(outbuf);
  120.         }
  121.                 /* make every output one-line */
  122.         for(i=0;i<n;i++) {
  123.             if(outbuf[i]=='\n') outbuf[i]=' ';
  124.         }
  125.           /* strip leading and trailing spaces */
  126.         for(i=n-1;i>=0 && isspace(outbuf[i]); i--) outbuf[i]=0;
  127.         if(outbuf[i]==';') outbuf[i]=0;
  128.         for(pe=outbuf; *pe; pe++) if(isupper(*pe)) *pe=tolower(*pe);
  129.         for(pe=outbuf; isspace(*pe); pe++);
  130.         /* strip_zeros(pe); */
  131.         puts(pe);
  132.     }
  133. }
  134.  
  135. void about(void)
  136. {
  137.     cmdparm="-v"; prepabout("",outputfname,NULL);
  138.     if(readabout()>0)
  139.       printf("<A HREF=\"%s\">Yacas %s</A>",homepage,aboutbuf);
  140. }
  141.  
  142. char *dynsetup(char *ptr, char *end)
  143. {
  144.     int i; char *p, *pp;
  145.    
  146.     for(i=0;i<SETUP_NO;i++) {
  147.         p=getenv(setups[i].wname);
  148.         if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
  149.         if(p==NULL || *p==0) p=setups[i].defaultval;
  150.         if(strstr(setups[i].wname,"yacas_precision")!=NULL)
  151.           precision=atoi(p);
  152.         if(precision<0) precision=-precision;
  153.     }
  154.     return ptr;
  155. }
  156.  
  157. int main(int argc,char *argv[])
  158. {
  159.     prepare1();
  160.     run();
  161.     return 0;    
  162. }
  163.  
  164.