Subversion Repositories wimsdev

Rev

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