Subversion Repositories wimsdev

Rev

Rev 10072 | 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 octave to wims */
  19.  
  20. /* 'Permission denied' error generated by Octave: it is trying to
  21.  * write to .octave.history even with the -H switch. */
  22.  
  23. /*************** Customization: change values hereafter ****************/
  24. #include "common.h"
  25.  
  26. /* limit of input/output file sizes */
  27. int fsizelim=131072;
  28. /* This string tells octave to exit. */
  29. char *quitstring="\nquit\n";
  30. /* The way to print a string in the program. */
  31. char *stringprinter="\"%s\"\n";
  32. /* This is octave home page. To be kept up to date. */
  33. #define homepage "http://www.gnu.org/software/octave/"
  34. /* String to search for answers */
  35. char ans_str[]="ans =";
  36.  
  37. char *nameofcmd="octave -Hf --no-line-editing";
  38. int precision=9;
  39. char header[]="split_long_rows(0)\n\
  40. page_screen_output(0)\n\
  41. sh=@sinh\n\
  42. ch=@cosh\n\
  43. th=@tanh\n\
  44. ln=@log\n\
  45. lg=@log10\n\
  46. sgn=@sign\n\
  47. tg=@tan\n\
  48. cotan=@cot\n\
  49. ctg=@cot\n\
  50. arcsin=@asin\n\
  51. arccos=@acos\n\
  52. arctan=@atan\n\
  53. arctg=@atan\n\
  54. argsh=@asinh\n\
  55. argch=@acosh\n\
  56. argth=@atanh\n\
  57. Argsh=@asinh\n\
  58. Argch=@acosh\n\
  59. Argth=@atanh\n\
  60. rint=@round\n\
  61. PI=pi\n\
  62. Pi=pi\n\
  63. ";
  64.  
  65. struct {
  66.     char *wname; char *defaultval; char *setname;
  67. } setups[]={
  68.       {"w_octave_precision", "9", "output_precision"}
  69. };
  70.  
  71. /* names which are not allowed */
  72. char *illegal[]={
  73.       "system","fopen","fclose","readdir","popen","mkdir","rmdir",
  74.       "dir","ls","cd","chdir","more","save","load","diary",
  75.       "fork","putenv","graw","eval",
  76.       "scanf","exec","unlink","umask","lstat","stat","rename",
  77.       "glob","tilde_expand","pclose","popen2","waitpid",
  78. };
  79.  
  80. int illegal_no=(sizeof(illegal)/sizeof(illegal[0]));
  81.  
  82. /* name parts which are not allowed */
  83. char *illpart[]={
  84.     "file", "debug", "plot"
  85. };
  86.  
  87. int illpart_no=(sizeof(illpart)/sizeof(illpart[0]));
  88.  
  89. /***************** Nothing should need change hereafter *****************/
  90.  
  91. char *progname="octave";
  92.  
  93. /* check for security violations in command string */
  94. void check_parm(char *p)
  95. {
  96.     char *pp, *s;
  97.  
  98.  /* Underscore replacement */
  99.     for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) {
  100.       if(pp==p || !isalnum(*(pp-1))) *pp='K';
  101.     }
  102.     for(s=p;*s;s++) *s=tolower(*s);
  103.     find_illegal(p);
  104. }
  105.  
  106. /* process and print octave output */
  107. void output(char *p)
  108. {
  109.     int i,n;
  110.     char *pp, *pe, *pt;
  111.  
  112.     pp=strchr(p,'\n');
  113.     for(pp++; *pp; pp=pe) {
  114.       pe=strchr(pp,'\n'); if(pe) *pe++=0; else pe=pp+strlen(pp);
  115.       if(memcmp(pp,ans_str,strlen(ans_str))==0) pp+=strlen(ans_str);
  116.       n=strlen(pp); if(n==0) {
  117.           puts(""); continue;
  118.       }
  119. /* make every output one-line */
  120.       for(i=0;i<n;i++) {
  121.           if(*(pp+i)=='\n' || *(pp+i)=='\%') *(pp+i)=' ';
  122.       }
  123. /* strip leading and trailing spaces */
  124.       while(isspace(*pp) && pp<pe) pp++;
  125.       pt=pp+strlen(pp)-1;
  126.       while(isspace(*pt) && pt>pp) *pt--=0;
  127.       strip_zeros(pp);
  128.       puts(pp);
  129.     }
  130. }
  131.  
  132. void about(void)
  133. {
  134.     char *p;
  135.  
  136.     prepabout("version\nquit\n",outputfname,NULL);
  137.     if(readabout()>0) {
  138.       p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
  139.       p=aboutbuf;while(*p && *p!='=') p++;
  140.       p++;
  141.       strip_trailing_spaces2(p);
  142.       printf("<a target=\"wims_external\" href=\"%s\">Octave%s</a>",homepage,p);
  143.     }
  144. }
  145.  
  146. char *dynsetup(char *ptr, char *end)
  147. {
  148.     int i;
  149.     char *p, *pp;
  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.       snprintf(ptr,end-ptr,"%s(%s)\n",setups[i].setname,p);
  155.       ptr+=strlen(ptr);
  156.       if(strstr(setups[i].wname,"octave_precision")!=NULL)
  157.         precision=atoi(p);
  158.       if(precision<0) precision=-precision;
  159.     }
  160.     return ptr;
  161. }
  162.  
  163. int main(int argc,char *argv[])
  164. {
  165.     prepare1();
  166.     run();
  167.     return 0;
  168. }
  169.  
  170.