Subversion Repositories wimsdev

Rev

Rev 8529 | 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 Scilab 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 scilab to exit. */
  26. char *quitstring="\nquit\n";
  27. /* The way to print a string in the program. */
  28. char *stringprinter="\"%s\"\n";
  29. /* This is scilab home page. To be kept up to date. */
  30. #define homepage "http://www.scilab.org/"
  31. /* String to search for answers */
  32.  
  33. // old chroot:  char ans_str[]="\n-->";
  34. char ans_str[]="\n";
  35.  
  36. char *nameofcmd="scilab -nw -ns";
  37. int precision=9;
  38. char header[]="\
  39. ";
  40.  
  41. struct {
  42.     char *wname; char *defaultval; char *setname;
  43. } setups[]={
  44.       {"w_scilab_precision", "9", "output_precision"}
  45. };
  46.  
  47. /* names which are not allowed */
  48. char *illegal[]={
  49. };
  50.  
  51. int illegal_no=(sizeof(illegal)/sizeof(illegal[0]));
  52.  
  53. /* name parts which are not allowed */
  54. char *illpart[]={
  55. };
  56.  
  57. int illpart_no=(sizeof(illpart)/sizeof(illpart[0]));
  58.  
  59. /***************** Nothing should need change hereafter *****************/
  60.  
  61. char *progname="scilab";
  62.  
  63. /* check for security violations in command string */
  64. void check_parm(char *p)
  65. {
  66.     char *pp, *s;
  67. /* Underscore replacement */
  68.     for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) {
  69.       if(pp==p || !isalnum(*(pp-1))) *pp='K';
  70.     }
  71.     for(s=p;*s;s++) *s=tolower(*s);
  72.     find_illegal(p);
  73. }
  74.  
  75. /* process and print Scilab output */
  76. void output(char *p)
  77. {
  78.     int i,n;
  79.     char *pp, *pe, *pt;
  80.  
  81.     for(pp=strstr(p,ans_str); pp; pp=pe) {
  82.       pp+=strlen(ans_str); pe=strstr(pp,ans_str);
  83.       if(pe) *pe=0;
  84.       pp=find_word_start(pp); if(memcmp(pp,"ans  =",strlen("ans  ="))==0) {
  85.           pp+=strlen("ans  ="); pp=find_word_start(pp);
  86.       }
  87.       if(pe!=NULL && pp>=pe) {
  88.           emptyline:
  89.           puts(""); continue;
  90.       }
  91.       n=strlen(pp); if(n==0) goto emptyline;
  92. /* strip leading and trailing spaces */
  93.       while(isspace(*pp) && pp<pe) pp++;
  94.       pt=pp+strlen(pp)-1;
  95.       while(isspace(*pt) && pt>pp) *pt--=0;
  96. /* make every output one-line */
  97.       for(i=0;i<n;i++) {
  98.           if(*(pp+i)=='\n') *(pp+i)=';';
  99.       }
  100. /* strip_zeros(pp); */
  101.       puts(pp);
  102.     }
  103. }
  104.  
  105. void about(void)
  106. {
  107.     char *p;
  108.  
  109.     prepabout(quitstring,outputfname,NULL);
  110.     if(readabout()>0) {
  111.       p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
  112.       p=strchr(aboutbuf,'('); if(p!=NULL) *p=0;
  113.       strip_trailing_spaces2(aboutbuf);
  114.       printf("<a target=\"wims_external\" href=\"%s\">%s</a>",homepage,aboutbuf);
  115.     }
  116. }
  117.  
  118. char *dynsetup(char *ptr, char *end)
  119. {
  120.     int i;
  121.     char *p, *pp;
  122. /* to adapt
  123.     if(wseed!= NULL) {
  124.       snprintf(ptr,end-ptr,"\nwimsseed:make_random_state(%u);\nset_random_state(wimsseed);\n",atoi(wseed)&(0x7FFFFFFF));
  125.       ptr+=strlen(ptr);
  126.     }
  127. */
  128.     for(i=0;i<SETUP_NO;i++) {
  129.       p=getenv(setups[i].wname);
  130.       if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
  131.       if(p==NULL || *p==0) p=setups[i].defaultval;
  132.       snprintf(ptr,end-ptr,"%s=%s\n",setups[i].setname,p);
  133.       ptr+=strlen(ptr);
  134.       if(strstr(setups[i].wname,"scilab_precision")!=NULL)
  135.         precision=atoi(p);
  136.       if(precision<0) precision=-precision;
  137.     }
  138.     return ptr;
  139. }
  140.  
  141. int main(int argc,char *argv[])
  142. {
  143.     setenv("chroot","must",1);
  144.     setenv("sysmask","must",1);
  145.     must_chroot=1;
  146.     prepare1();
  147.     run();
  148.     return 0;
  149. }
  150.  
  151.