Subversion Repositories wimsdev

Rev

Rev 7674 | Rev 8120 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 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
 
7674 bpr 18
/* Interface Scilab to wims */
10 reyssat 19
 
20
/*************** Customization: change values hereafter ****************/
21
 
7674 bpr 22
/* limit of input/output file sizes */
10 reyssat 23
#define fsizelim 131072
7674 bpr 24
/* This string tells scilab to exit. */
10 reyssat 25
#define quitstring "\nquit\n"
7674 bpr 26
/* The way to print a string in the program. */
10 reyssat 27
#define stringprinter "\"%s\"\n"
7674 bpr 28
/* This is scilab home page. To be kept up to date. */
4417 bpr 29
#define homepage "http://www.scilab.org/"
7674 bpr 30
/* String to search for answers */
10 reyssat 31
 
4434 schaersvoo 32
// old chroot:  char ans_str[]="\n-->";
33
char ans_str[]="\n";
34
 
10 reyssat 35
char *nameofcmd="scilab -nw -ns";
36
int precision=9;
37
char header[]="\
38
";
39
 
40
struct {
7674 bpr 41
    char *wname; char *defaultval; char *setname;
10 reyssat 42
} setups[]={
7674 bpr 43
      {"w_scilab_precision", "9", "output_precision"}
10 reyssat 44
};
45
 
7674 bpr 46
/* names which are not allowed */
10 reyssat 47
char *illegal[]={
48
};
49
 
7674 bpr 50
/* name parts which are not allowed */
10 reyssat 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
 
7674 bpr 60
/* check for security violations in command string */
10 reyssat 61
void check_parm(char *p)
62
{
63
    char *pp, *s;
7674 bpr 64
/* Underscore replacement */
10 reyssat 65
    for(pp=strchr(p,'_'); pp!=NULL; pp=strchr(pp+1,'_')) {
7674 bpr 66
      if(pp==p || !isalnum(*(pp-1))) *pp='K';
10 reyssat 67
    }
68
    for(s=p;*s;s++) *s=tolower(*s);
69
    find_illegal(p);
70
}
71
 
7674 bpr 72
/* process and print Scilab output */
10 reyssat 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) {
7674 bpr 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);
10 reyssat 99
    }
100
}
101
 
102
void about(void)
103
{
104
    char *p;
105
 
106
    prepabout(quitstring,outputfname,NULL);
107
    if(readabout()>0) {
7674 bpr 108
      p=strchr(aboutbuf,'\n'); if(p!=NULL) *p=0;
109
      p=strchr(aboutbuf,'('); if(p!=NULL) *p=0;
8100 bpr 110
      strip_trailing_spaces2(aboutbuf);
7674 bpr 111
      printf("<a href=\"%s\">%s</a>",homepage,aboutbuf);
10 reyssat 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++) {
7674 bpr 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;
10 reyssat 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();
7674 bpr 139
    return 0;
10 reyssat 140
}
141