Subversion Repositories wimsdev

Rev

Rev 8120 | Rev 12011 | 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 maxima to wims */
  19.  
  20. /*************** Customization: change values hereafter ****************/
  21. #include "common.h"
  22.  
  23. /* limit of input/output file sizes */
  24. int fsizelim=131072;
  25. /* This string tells maxima to exit. */
  26. char *quitstring="\nquit();\n";
  27. char *aboutquitstring="build_info();" "\nquit();\n";
  28. /* The way to print a string in the program. */
  29. char *stringprinter="\"%s\";\n";
  30. /* This is maxima home page. To be kept up to date. */
  31. #define homepage "http://maxima.sourceforge.net/"
  32.  
  33. char *nameofcmd="maxima";
  34. int precision=20;
  35. char header[]="\n\
  36. display2d:false;\n\
  37. letrat:true;\n\
  38. keepfloat:true;\n\
  39. rombergmin:5;\n\
  40. rombergtol:1.E-6;\n\
  41. rombergit:13;\n\
  42. simpsum:true;\n\
  43. triginverses:true; logabs:true;\n\
  44. e:%e;pi:%pi;Pi:%pi;PI:%pi;I:%i;i:%i;\n\
  45. ln:log;sh:sinh;ch:cosh;th:tanh;\n\
  46. arctan:atan;arcsin:asin;arccos:acos;\n\
  47. tg:tan;arctg:atan;\n\
  48. argsh:asinh;argch:acosh;argth:atanh;\n\
  49. Argsh:asinh;Argch:acosh;Argth:atanh;\n\
  50. cotan:cot;ctg:cot;\n\
  51. log10(x):=block([],return(log(x)/log(10.0)));\n\
  52. log2(x):=block([],return(log(x)/log(2.0)));\n\
  53. lg(x):=log10(x);\n\
  54. sgn:sign;\n\
  55. nolabels:true; kill(labels);\n\
  56. ";
  57.  
  58. struct {
  59.     char *wname; char *defaultval; char *setname;
  60. } setups[]={
  61.       {"w_maxima_precision", "20", "fpprec"}
  62. };
  63.  
  64. /* names which are not allowed */
  65. char *illegal[]={
  66.       "system","describe","example",
  67.       "save","fassave","stringout","batcon",
  68.       "batcount","cursordisp",
  69.       "direc","readonly","with_stdout","pscom",
  70.       "demo","ttyintfun","bug"
  71.  
  72. };
  73.  
  74. int illegal_no=(sizeof(illegal)/sizeof(illegal[0]));
  75.  
  76. /* name parts which are not allowed */
  77. char *illpart[]={
  78.     "file", "debug", "plot", "load", "store", "batch"
  79. };
  80.  
  81. int illpart_no=(sizeof(illpart)/sizeof(illpart[0]));
  82.  
  83. /***************** Nothing should need change hereafter *****************/
  84.  
  85. #define linebyline "\n(%i"
  86. char *progname="maxima";
  87.  
  88. /* check for security violations in command string */
  89. void check_parm(char *pm)
  90. {
  91.     char *s, *pp;
  92.     int l;
  93. /* Underscore replacement */
  94.     for(pp=strchr(pm,'_'); pp!=NULL; pp=strchr(pp+1,'_')) *pp='K';
  95. /* '?' escapes to Lisp commands. */
  96.     if(strchr(pm,'?')!=NULL) {
  97.         fprintf(stderr,"Illegal under WIMS.\n"); exit(1);
  98.     }
  99.     for(s=pm;*s;s++) *s=tolower(*s);
  100.     strip_trailing_spaces2(pm); l=strlen(pm);
  101.     if(l>0 && pm[l-1]!=';') strcat(pm,";");
  102.     find_illegal(pm);
  103. }
  104.  
  105. char *find_prompt(char *p, char t)
  106. {
  107.     char *pp=p-1, *pt;
  108.     char c;
  109.     int add;
  110.     redo:
  111.     if(*p==0 || (pp>=p && *pp==0)) return NULL;
  112.     add=3;
  113.     do {
  114.       pp=strstr(pp+1,"\n(");
  115.       if(!pp) break;
  116.       c=pp[2]; add=3;
  117.       if(c=='\%') { /* backward compatibility */
  118.           add++; c=pp[3];
  119.           if(c=='i') c='C';
  120.           if(c=='o') c='D';
  121.       }
  122.     }
  123.     while(c!=t);
  124.     pt=pp;
  125.     if(pp!=NULL) {
  126.       pp+=add; while(isdigit(*pp)) pp++;
  127.       if(*pp!=')') goto redo;
  128.       pp++;
  129.     }
  130.     if(pt!=NULL && t=='D') pt=pp;
  131.     return pt;
  132. }
  133.  
  134. /* process and print maxima output */
  135. void output(char *p)
  136. {
  137.     int i,n;
  138.     char *pp, *pe, *pt;
  139.  
  140.     pp=find_prompt(p,'C');
  141.     while(pp!=NULL) {
  142.       pe=find_prompt(pp+1,'C'); pp=find_prompt(pp,'D');
  143.       if(pp==NULL) return;
  144.       if(pe!=NULL && pp>=pe) goto emptyline;
  145.       if(pe==NULL) pe=pp+strlen(pp); else *pe++=0;
  146.       if(pp>=pe) {
  147.           emptyline:
  148.           puts(""); pp=pe; continue;
  149.       }
  150.       n=strlen(pp); if(n==0) goto emptyline;
  151. /* make every output one-line */
  152.       for(i=0;i<n;i++) {
  153.           if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' ';
  154.           else *(pp+i)=tolower(*(pp+i));
  155.       }
  156. /* strip leading and trailing spaces */
  157.       while(isspace(*pp) && pp<pe) pp++;
  158.       pt=pp+strlen(pp)-1;
  159.       while(isspace(*pt) && pt>pp) *pt--=0;
  160.       if(*pp=='[' && *pt==']' && find_matching2(pp+1,']')==pt) {
  161.           *(pt--)=0; pp++;
  162.       }
  163.       for(pt=strchr(pp,'b');pt!=NULL; pt=strchr(pt+1,'b')) {
  164.           if(pt>pp && isdigit(*(pt-1)) &&
  165.              (*(pt+1)=='-' || isdigit(*(pt+1)))) {
  166.             if(*(pt+1)=='0' && !isdigit(*(pt+2))) ovlstrcpy(pt,pt+2);
  167.             else *pt='E';
  168.           }
  169.       }
  170.       puts(pp); pp=pe;
  171.     }
  172. }
  173.  
  174. void about(void)
  175. {
  176.     char *p, *p2, *pp;
  177.     int i;
  178.  
  179. /*    printf("<a href=\"%s\">Maxima</a>",homepage); return; */
  180.     prepabout(aboutquitstring,outputfname,NULL);
  181.     if(readabout()>0) {
  182.       for(p=aboutbuf; *p; p=find_word_start(find_word_end(p))) {
  183.           if(strncasecmp(p,"Maxima",strlen("Maxima"))==0) {
  184.             p2=find_word_start(find_word_end(p));
  185.             if(strncmp(p2,"restarted",9)!=0) break;
  186.           }
  187.       }
  188.       for(p2=p;*p2 && *p2!='\n' && !isdigit(*p2);p2++);
  189.       if(isdigit(*p2)) pp=find_word_end(p2);
  190.       else for(i=0, pp=p;i<2;i++) pp=find_word_end(find_word_start(pp));
  191.       *pp=0;
  192.       if(*p!=0) printf("<a target=\"wims_external\" href=\"%s\">%s</a>",homepage,p);
  193.     }
  194. }
  195.  
  196. char *dynsetup(char *ptr, char *end)
  197. {
  198.     int i;
  199.     char *p, *pp;
  200.     for(i=0;i<SETUP_NO;i++) {
  201.       p=getenv(setups[i].wname);
  202.       if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
  203.       if(p==NULL || *p==0) p=setups[i].defaultval;
  204.       snprintf(ptr,end-ptr,"%s:%s;\n",setups[i].setname,p);
  205.       ptr+=strlen(ptr);
  206.       if(strstr(setups[i].wname,"maxima_precision")!=NULL)
  207.         precision=atoi(p);
  208.       if(precision<0) precision=-precision;
  209.     }
  210.     return ptr;
  211. }
  212.  
  213. int main(int argc,char *argv[])
  214. {
  215.     prepare1();
  216.     run();
  217.     return 0;
  218. }
  219.  
  220.