Subversion Repositories wimsdev

Rev

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