Back to index

wims  3.65+svn20090927
scilab.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018        /* Interface Scilab to wims */
00019 
00020 /*************** Customization: change values hereafter ****************/
00021 
00022        /* limit of input/output file sizes */
00023 #define fsizelim 131072
00024        /* This string tells scilab to exit. */
00025 #define quitstring "\nquit\n"
00026        /* The way to print a string in the program. */
00027 #define stringprinter "\"%s\"\n"
00028        /* This is scilab home page. To be kept up to date. */
00029 #define homepage "http://scilabsoft.inria.fr/"
00030        /* String to search for answers */
00031 char ans_str[]="\n-->";
00032 
00033 char *nameofcmd="scilab -nw -ns";
00034 int precision=9;
00035 char header[]="\
00036 ";
00037 
00038 struct {
00039     char *wname;    char *defaultval;     char *setname;
00040 } setups[]={
00041        {"w_scilab_precision",      "9",   "output_precision"}
00042 };
00043 
00044        /* names which are not allowed */
00045 char *illegal[]={
00046 };
00047 
00048        /* name parts which are not allowed */
00049 char *illpart[]={
00050 };
00051 
00052 /***************** Nothing should need change hereafter *****************/
00053 
00054 #define progname "scilab"
00055 #include "common.h"
00056 #include "common.c"
00057 
00058        /* check for security violations in command string */
00059 void check_parm(char *p)
00060 {
00061     char *pp, *s;
00062     
00063          /* Underscore replacement */
00064     for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) {
00065        if(pp==p || !isalnum(*(pp-1))) *pp='K';
00066     }
00067     for(s=p;*s;s++) *s=tolower(*s);
00068     find_illegal(p);
00069 }
00070 
00071        /* process and print Scilab output */
00072 void output(char *p)
00073 {
00074     int i,n;
00075     char *pp, *pe, *pt;
00076 
00077     for(pp=strstr(p,ans_str); pp; pp=pe) {
00078        pp+=strlen(ans_str); pe=strstr(pp,ans_str);
00079        if(pe) *pe=0;
00080        pp=find_word_start(pp); if(memcmp(pp,"ans  =",strlen("ans  ="))==0) {
00081            pp+=strlen("ans  ="); pp=find_word_start(pp);
00082        }
00083        if(pe!=NULL && pp>=pe) {
00084            emptyline:
00085            puts(""); continue;
00086        }
00087        n=strlen(pp); if(n==0) goto emptyline;
00088          /* strip leading and trailing spaces */
00089        while(isspace(*pp) && pp<pe) pp++;
00090        pt=pp+strlen(pp)-1;
00091        while(isspace(*pt) && pt>pp) *pt--=0;
00092               /* make every output one-line */
00093        for(i=0;i<n;i++) {
00094            if(*(pp+i)=='\n') *(pp+i)=';';
00095        }
00096 /*     strip_zeros(pp); */
00097        puts(pp);
00098     }
00099 }
00100 
00101 void about(void)
00102 {
00103     char *p;
00104 
00105     prepabout(quitstring,outputfname,NULL);
00106     if(readabout()>0) {
00107        p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
00108        p=strchr(aboutbuf,'('); if(p!=NULL) *p=0;
00109        strip_trailing_spaces(aboutbuf);
00110        printf("<A HREF=\"%s\">%s</A>",homepage,aboutbuf);
00111     }
00112 }
00113 
00114 char *dynsetup(char *ptr, char *end)
00115 {
00116     int i;
00117     char *p, *pp;
00118     for(i=0;i<SETUP_NO;i++) {
00119        p=getenv(setups[i].wname);
00120        if(p!=NULL) for(pp=p;*pp;pp++) if(!isspace(*pp) && !isalnum(*pp)) p="";
00121        if(p==NULL || *p==0) p=setups[i].defaultval;
00122        snprintf(ptr,end-ptr,"%s=%s\n",setups[i].setname,p);
00123        ptr+=strlen(ptr);
00124        if(strstr(setups[i].wname,"scilab_precision")!=NULL)
00125          precision=atoi(p);
00126        if(precision<0) precision=-precision;
00127     }
00128     return ptr;
00129 }
00130 
00131 int main(int argc,char *argv[])
00132 {
00133     setenv("chroot","must",1);
00134     setenv("sysmask","must",1);
00135     must_chroot=1;
00136     prepare1();
00137     run();
00138     return 0;    
00139 }
00140