Merge remote-tracking branch 'origin/5.5'
[scilab.git] / scilab / bin / scilab
1 #!/bin/sh
2 #
3 # Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 # Copyright (C) INRIA - 2006-2008 - Sylvestre Ledru
5 # Copyright (C) INRIA - 2008 - Simon Lipp
6 # Copyright (C) DIGITEO - 2009 - Sylvestre Ledru
7 # This file must be used under the terms of the CeCILL.
8 # This source file is licensed as described in the file COPYING, which
9 # you should have received as part of this distribution.  The terms
10 # are also available at    
11 # http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 #
13 # Simon Lipp 2008:
14 # - clean up (get rid of unnecessary sci_args)
15 #                            - accept arguments with spaces, e.g.
16 #                               -e "disp(1); disp(2)" (fix bug #2606)
17
18 ####
19 #
20 # Scilab can be installed/used in different ways :
21 # * ./configure; make install
22 #    => will install Scilab into /usr/local/ and split files to
23 #    /usr/local/bin, /usr/local/share/scilab/, /usr/local/lib/scilab/,
24 #    /usr/local/include/scilab/
25 # * ./configure --prefix=/my/dir/; make install
26 #    => will install Scilab into /my/dir/ and split files to
27 #    /my/dir/bin/, /my/dir/share/scilab/, /my/dir/lib/scilab/
28 #    /my/dir/include/scilab/
29 #    Scilab official binary uses this arch
30 # * ./configure; make install prefix=$(DESTDIR)/usr \
31 #                                  bindir=$(DESTDIR)/usr/bin \
32 #                                  datadir=$(DESTDIR)/usr/share/scilab ...
33 #    Solution used mainly by Linux packagers
34 #
35 ## First, this script will look for scilab-bin in :
36 # * If specified, in the $SCI variable
37 # * Into the scilab/bin/ directory
38 # * Into the scilab/ directory (if the user is using a source version and
39 # scilab has been compiled in this directory)
40 # * if this file is a symlink to the real one. We browse symlink(s) until we
41 # find the real "scilab" script file and consider that it is the right
42 # directory
43 # * That is all. Don't hesitate to contact us if you see one missing.
44 #
45 ###
46
47 if test ! -z "$SCIVERBOSE"; then
48         SCIVERBOSE=1
49 else
50         SCIVERBOSE=0
51 fi
52
53 if test -n "$SCI"; then
54         if test ! -d "$SCI/modules"; then
55                 echo "Cannot find directory $SCI/modules/ !"
56                 echo "SCI should point to the root data directory of Scilab"
57                 exit -1
58         fi
59 fi
60
61 DISABLE_JAVA_DETECTION=0
62
63 # Electric fence is a tool to check problem of memory
64 start_electric_fence() {
65         echo "Running Scilab with Electric Fence : "  LD_PRELOAD=libefence.so.0.0 "$SCILABBIN" "$@"
66         LD_PRELOAD=libefence.so.0.0 "$SCILABBIN" "$@"
67 }
68
69 start_debug() {
70           if test -n "$DEVENV"; then
71                   echo "Running debug of Scilab [gdb]  : " "$SCI"/libtool --mode=execute gdb --args "$SCILABBIN" "$@"
72                   "$SCI"/libtool --mode=execute gdb --args "$SCILABBIN" "$@"
73           else
74                   echo "Running debug of Scilab [gdb]  : " gdb --args "$SCILABBIN" "$@"
75                   gdb --args "$SCILABBIN" "$@"
76           fi
77 }
78
79 start_debug_kdbg() {
80           if test -n "$DEVENV"; then
81                   echo "Running debug of Scilab [kdbg]  : " "$SCI"/libtool --mode=execute kdbg "$SCILABBIN"
82                   "$SCI"/libtool --mode=execute kdbg "$SCILABBIN"
83           else
84                   echo "Running debug of Scilab [kdbg]  : " kdbg "$SCILABBIN"
85                   kdbg "$SCILABBIN"
86           fi
87 }
88
89 start_profiling() {
90         VALGRIND_OPTIONS=" --show-below-main=yes --num-callers=6 --demangle=no --leak-check=full --show-reachable=yes --smc-check=all --db-attach=yes --gen-suppressions=all --suppressions=$SCI/tools/profiling/valgrind.supp"
91           if test -n "$DEVENV"; then
92                   echo "Running profiling of Scilab  : " "$SCI"/libtool --mode=execute valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
93                   "$SCI"/libtool --mode=execute valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
94           else
95                   echo "Running profiling of Scilab  : " valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
96                   valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
97           fi
98
99 }
100
101 start_profiling_visu() {
102         VALGRIND_VISU_OPTIONS=" --tool=callgrind --trace-children=yes --smc-check=all --trace-jump=yes --dump-line=yes --separate-threads=yes"
103 #--dump-instr=yes 
104         if test -n "$DEVENV"; then
105                 echo "Running profiling visualization of Scilab  : " "$SCI"/libtool --mode=execute valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
106                 "$SCI"/libtool --mode=execute valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
107         else
108                 echo "Running profiling visualization of Scilab  : " valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
109                 valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
110           fi
111 }
112
113 find_docbook_path() {
114         if test -z "$DOCBOOK_ROOT"; then
115                 for dir in $SCI/thirdparty/docbook /usr/share/sgml/docbook/stylesheet/xsl/nwalsh /usr/share/docbook2X/xslt/man/ /usr/share/xml/docbook/stylesheet/nwalsh/ /usr/share/xml/docbook/stylesheet/nwalsh/current/ /sw/share/xml/xsl/docbook-xsl /usr/share/xml/docbook/xsl-stylesheets-*/ /usr/share/sgml/docbook/xsl-stylesheets-*/; do
116                         if test -r "$dir/javahelp/javahelp.xsl"; then
117                                 if test -z "$DOCBOOK_ROOT"; then
118                                         DOCBOOK_ROOT=$dir
119                                         export DOCBOOK_ROOT
120                                 fi
121                         fi
122                 done
123         fi
124         if test $SCIVERBOSE -ne 0; then
125                 echo "DOCBOOK : $DOCBOOK_ROOT"
126         fi
127 }
128
129 detect_type_of_scilab(){
130         progname="$0"
131         SCILAB_MODE="gui"
132         SCILABBIN="scilab-bin"
133         if echo "$progname"|grep "scilab-adv-cli$" 2>&1 > /dev/null; then
134                 SCILAB_MODE="nw"
135                 # We are using scilab-bin here because we are going to force the arg -nw
136                 SCILABBIN="scilab-bin"
137         fi
138                 
139         if echo "$progname"|grep "scilab-cli$" 2>&1 > /dev/null; then
140                 SCILAB_MODE="nwni"
141                 SCILABBIN="scilab-cli-bin"
142                 DISABLE_JAVA_DETECTION=1
143         fi
144         if test $SCIVERBOSE -ne 0; then
145                 echo "SCILABBIN : $SCILABBIN"
146                 echo "DISABLE_JAVA_DETECTION : $DISABLE_JAVA_DETECTION"
147                 echo "SCILAB_MODE : $SCILAB_MODE"
148         fi
149 }
150
151 detect_type_of_scilab
152
153 detect_scilab_path() {
154
155 LOCALOLDPWD=`pwd`
156
157 # Use scilab-bin in the current dir if it exists
158 # If not, then start resolving symlinks until we find scilab-bin
159         found=0
160         progname="$0"
161         curdir=`dirname "$progname"`
162         PATH="$curdir:$PATH"
163
164         progbase=`basename "$progname"`
165         run_sci="$curdir/$SCILABBIN"
166         if test -x "$run_sci"; then # scilab-bin is in the /bin/ directory
167                 cd "$curdir/../"
168                 SCI=`pwd`
169                 SCIBIN=$run_sci
170                 found=1
171         else
172                 run_sci="$curdir/../$SCILABBIN"
173                 if test -x "$run_sci"; then # scilab-bin is in the / directory
174                 # which is the case in a dev env
175                         cd "$curdir/../"
176                         SCI=`pwd`
177                         SCIBIN=$run_sci
178                         found=1
179                 else
180                         here=`/bin/pwd`
181                         while test -h "$progname"; do
182                                 bn=`basename "$progname"`
183                                 cd `dirname "$progname"`
184                         # Browse the symlink to the real one
185                                 progname=`/bin/ls -l "$bn" | sed -e 's/^.* -> //' `
186                                 if test ! -x "$progname"; then
187                                         break
188                                 fi
189                                 curdir=`dirname "$progname"`
190                                 if test -x "$curdir"; then
191                                         cd "$curdir/../"
192                                         SCI=`pwd`
193                                         SCIBIN="$curdir/$SCILABBIN"
194                                         found=1
195                                         break
196                                 fi
197                         # The current file ($0), probably scilab is a symlink to the 
198                         # real one and here, it is the dev env
199                                 run_sci="$curdir/../$SCILABBIN"
200                                 if test -x "$run_sci"; then
201                                         cd "$curdir/../"
202                                         SCI=`pwd`
203                                         SCIBIN=$run_sci
204                                         found=1
205                                         break
206                                 fi
207                         done
208                         cd "$here"
209                 fi
210                 if test $SCIVERBOSE -ne 0; then
211                         echo "I think I found Scilab here : $SCI"
212                 fi
213         fi
214
215
216         if test -x "$SCI/bin/$SCILABBIN"; then
217 # real env
218                 SCILABBIN=$SCI/bin/$SCILABBIN
219                 SCI=$SCI/share/scilab/
220         else
221                 if test -x "$SCI/$SCILABBIN"; then
222                 # dev env
223                         SCILABBIN=$SCI/$SCILABBIN
224                         DEVENV=1
225                 # add modelica in the path
226                         PATH="$PATH:$SCI/modules/scicos/"
227                 else
228                         echo "Cannot find $SCILABBIN ..."
229                         exit 1
230                 fi
231         fi
232
233         export SCI
234 }
235
236 detect_java_vm() {
237 ############# JAVA DETECTION ##############
238 # Basic inspiration from Eclipse
239 #
240 # Scilab is looking for Java in various places with different ways :
241 # * if JAVA_HOME is specificed, use it
242 # * Check in 'standard' places we know Java could be installed
243 # if some are missing, please contact us
244 # * look in the PATH if there is a java binary
245 # if it is the case, resolve the symlink and set the JAVA_HOME from it
246 #
247 # Once we have JAVA_HOME, we check that native libraries (libjava.so and
248 # 2 others) are available
249 ###
250
251         if test "${OS}" = ""; then
252         OS=`uname -s` # Retrieve the Operating System                                                                                                         
253         fi
254         if test "${MODEL}" = ""; then
255         MODEL=`uname -m` # Retrieve the model                                                                                                                 
256         fi
257
258 # Get the proc name matching to the one of the JVM
259 # Inspiration and data are from http://www.google.com/codesearch?hl=en&q=+java+ppc+libjava.so+show:a78sz0SP41k:zxNozD-vc0A:FWiIy7Hinmg&sa=N&cd=2&ct=rc&cs_p=http://fresh.t-systems-sfr.com/unix/src/misc/tclBlendSrc1.2.5.tar.gz&cs_f=tclBlend1.2.5/configure.in#a0
260 # For Mac OS X, we will get stuff like that:
261 # uname -s Power Macintosh
262 # uname -m Darwin
263
264 # If the user has the variable JAVA_HOME in the ENV
265         if test -n "$JAVA_HOME" ; then
266                 if test $SCIVERBOSE -ne 0; then
267                         echo "Using specified vm: $JAVA_HOME"
268                 fi
269                 if test ! -x "$JAVA_HOME/bin/java" ; then
270                         echo "Cannot find $JAVA_HOME/bin/java"
271                         exit 1
272                 fi
273         fi
274
275         if test -z "$JAVA_HOME"; then
276         case $OS in
277             *darwin* | *Darwin*)
278                     # Seems to be always that under Mac OS X. Don't hesitate to submit a bug report if it is not the case.
279                     JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home/"
280                     LD_LIBRARY_PATH="$JAVA_HOME/../Libraries:$LD_LIBRARY_PATH"
281                     if test $SCIVERBOSE -ne 0; then
282                         echo "Using default Mac OS X vm: $JAVA_HOME"
283                         echo "And LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
284                     fi
285                     ;;
286                 *)
287                                         ;;
288                         esac
289 fi
290
291 # Browse "default directory" (if it means anything under Unix/Linux) of Java
292 # to find where it could be !
293         if test -z "$JAVA_HOME"; then
294                 JAVA_DEFAULT_DIR="/usr/lib/jvm/java-6-openjdk/ /usr/lib/jvm/java/ /usr/lib/jvm/java-6-sun/ /usr/lib/j2se/1.6 /usr/java/jdk1.6.0*/ /usr/java/jdk1.5.0*/ /usr/lib/j2sdk1.6-ibm /usr/lib/jvm/java-1.5.0-sun /usr/java/ /usr/lib/j2se/1.5 /usr/lib/j2se/1.4 /usr/java/jre1.6.0*/ /usr/java/jre1.5.0*/ /usr/lib/j2sdk1.5-ibm /usr/lib/j2sdk1.4-ibm /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.4-sun /usr/lib/jvm/java-gcj /usr/lib/jvm/java-1.5.0-gcj/ /usr/lib/kaffe/pthreads /usr/lib/jvm/java-1.7.0-icedtea-*/ /usr/lib/jvm/jre/"
295                 for JAVA_HOME in $JAVA_DEFAULT_DIR ; do
296                         if test $SCIVERBOSE -ne 0; then
297                                 echo "Trying to find Java in $JAVA_HOME "
298                         fi
299                         if test -x "${JAVA_HOME}/bin/java" ; then
300                                 export JAVA_HOME
301                                 if test $SCIVERBOSE -ne 0; then
302                                         echo "found"
303                                 fi
304                                 break
305                         fi
306                 done
307         fi
308
309 # JAVA_HOME still haven't been found. Well, we can now try to find it in the path
310
311         if test -z "$JAVA_HOME"; then
312                 PATH_SEPARATOR=:
313                 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
314                 if test $SCIVERBOSE -ne 0; then
315                         echo "Look the binary java in the PATH. If it is a symlink, try to resolve it"
316                 fi
317                 for DIR in $PATH; do
318                         if test -f $DIR/java; then
319
320                                 _cur=$DIR/java
321                         # resolve symlink
322                         # Will probably bug if a file contains -> in the name
323                                 while ls -ld "$_cur" 2>/dev/null | grep " -> " >/dev/null; do
324                                         _cur=`ls -ld "$_cur" | sed 's/.* -> //'`
325                                 done
326                         # symlink resolved to the real file
327
328                         # Now, create JAVA_HOME
329                                 TMP=`dirname $_cur`
330                                 JAVA_HOME=`dirname $TMP`
331                                 if test ! -z "$JAVA_HOME"; then
332                                         break;
333                                 fi
334                         fi
335                 done
336                 IFS=$as_save_IFS
337         fi
338         if test ! -z "$JAVA_HOME"; then
339                 if test $SCIVERBOSE -ne 0; then
340                         echo "JAVA_HOME : $JAVA_HOME"
341                 fi
342
343 # Manage JRE & JDK because libjava.so and others are stored in the JRE
344                 if test -d $JAVA_HOME/jre; then
345                         JRE_HOME=$JAVA_HOME/jre
346                 else
347                         JRE_HOME=$JAVA_HOME
348                 fi
349
350 # Configuring LD_LIBRARY_PATH for libjava.so libhpi.so and libxxxx.so
351
352                 JAVA_SHLIB="libjava.so"
353
354                 case $OS in
355                         "Linux")
356                                 case $MODEL in
357                                         "x86_64")
358                                                 proc="amd64"
359                                                 ;;
360                                         i?86)
361
362                                                 if test -d ${JRE_HOME}/lib/`uname -m` ; then
363                                                         proc=`uname -m`
364                                                 else
365                                                         proc="i386"
366                                                 fi
367                                                 ;;
368                                         "ia64")
369                                                 proc="i64"
370                                                 ;;
371                                         "ppc")
372                                                 proc="ppc"
373                                                 ;;
374                                         "alpha")  
375                                                 proc="alpha"
376                                                 ;;
377                                         *)
378                                                 echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us."
379                                                 ;;
380                                 esac
381                                 ;;
382                         "HP-UX")
383                                 JAVA_SHLIB="libjava.sl"
384                                 proc="lib" # TODO : check if it is right or not ... seems not !
385                                 ;;
386                         "IRIX")
387                                 proc="lib32"
388                                 ;;
389                         "SunOS")
390                         case $MODEL in
391                                         "i86pc") # solaris x86
392                                                 proc="i386"
393                                                 ;;
394                                 # check for the 64 bits syntax
395                                         "sparc")
396                                                 proc="sparc"
397                                                 ;;
398                                         *)
399                                                 echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us."
400                                                 ;;
401                                 esac
402                                 ;;
403                         *win32* | *WIN32* | *CYGWIN_NT*)
404                                 proc="win32"
405                                 JAVA_SHLIB="jvm.dll"
406                                 ;;
407                         *darwin* | *Darwin*) # MacOS X
408         # For Mac OS X, Since path are different from the JVM normal tree, 
409                 # don't need to detect the CPU
410                                 JAVA_SHLIB="libjava.jnilib"
411                                 ;;
412                         *)
413                 echo "Could not find the Java configuration for the OS <${OS}>. Please contact us or submit a bug report with your detailed configuration http://bugzilla.scilab.org/"
414                 ;;
415                 esac
416                 
417
418 # Check if the lib exists or not (we should manage system where .so is not the
419 # ext for library
420                 LIBJAVA="$JRE_HOME/lib/$proc/$JAVA_SHLIB"
421                 if test ! -f $LIBJAVA; then
422                         if test $SCIVERBOSE -ne 0; then
423                                 echo "Cannot find $LIBJAVA"
424                         fi
425                 else
426             CLASSPATH="$CLASSPATH:$SCI/modules/jvm/jar/org.scilab.modules.jvm.jar"
427                 # @TODO This is the default path of the official sun JVM. 
428                 # It is different for other implementation of the JVM....
429                     LD_LIBRARY_PATH="$JRE_HOME/lib/$proc/:$JRE_HOME/lib/$proc/server/:$JRE_HOME/lib/$proc/native_threads/:$LD_LIBRARY_PATH"
430                 fi
431         else
432                 if test $SCIVERBOSE -ne 0; then
433                         echo "Have not been able to find any Java VM on this computer. Some features may be broken."
434                 fi
435         fi
436
437 ####### END OF JAVA ENV DETECTION/SETTING ######
438 }
439
440 detect_scilab_path
441
442 PATH="$SCI:$SCI/bin:$PATH"
443
444 # If we are calling scilab-cli, no need to detect java.
445 if test $DISABLE_JAVA_DETECTION -ne 1; then
446         detect_java_vm
447 fi
448
449 # See http://bugzilla.scilab.org/show_bug.cgi?id=3486
450 # Some Java stuff raises spurious SIGSEGV. The problem is that when bug-buddy
451 # is enabled, it catches the signal and terminate Scilab. We have to 
452 # desactivate bug-buddy.
453 # See also https://bugzilla.novell.com/show_bug.cgi?id=331618
454 # and: http://bugzilla.gnome.org/show_bug.cgi?id=479929
455 GTK_MODULES=`echo $GTK_MODULES | sed s/gnomebreakpad//g`
456 export GTK_MODULES
457
458 if test $SCIVERBOSE -ne 0; then
459         echo "SCI : $SCI"
460         echo "SCIBIN : $SCIBIN"
461         echo "PATH : $PATH"
462 fi
463
464 # Returns to the original path
465 cd "$LOCALOLDPWD"
466
467 #if test "$DISPLAY" = ""; then
468 #  DISPLAY="unix:0.0"
469 #fi
470 #export DISPLAY
471
472 #if test "$PVM_ROOT" = ""; then
473 #  PVM_ROOT="@PVMROOTR@"
474 #fi
475 #export PVM_ROOT
476
477 #if test "$PVM_ARCH" = ""; then
478 #  PVM_ARCH=`$PVM_ROOT/lib/pvmgetarch`
479 #fi
480 #export PVM_ARCH
481
482 SCILIB=$SCI/bin:$SCI/lib/scilab/:$SCI/lib64/scilab/
483 LD_LIBRARY_PATH=$SCILIB${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
484
485 case $OS in
486     *darwin* | *Darwin*) # MacOS X
487         # When using some packaging tools like fink which are storing the info in /sw/lib
488         LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/sw/lib/"
489         # Export the path to the Scilab lib when Scilab has been install ...
490         # to a Mac os x specific variable used by the linker before LD_LIBRARY_PATH
491         DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$SCI/../../lib/scilab/
492         export DYLD_LIBRARY_PATH
493         ;;
494     *)
495 esac
496
497
498 if test $SCIVERBOSE -ne 0; then
499         echo "LD_LIBRARY_PATH : $LD_LIBRARY_PATH"
500         if test ! -z "$DYLD_LIBRARY_PATH"; then
501             echo "DYLD_LIBRARY_PATH: $DYLD_LIBRARY_PATH"
502         fi
503 fi
504 export LD_LIBRARY_PATH
505 export PATH
506
507 find_docbook_path
508
509 do_scilex()
510 {
511     "$SCILABBIN" "$@"
512
513 }
514
515 do_help()
516 {
517         echo "Usage:"
518         echo     "scilab <options>"
519         echo     " "
520         echo     "      Possible options are:"
521         echo     "      -display Display: for use under Xwindow systems to set a specific X server display."
522         echo     "      -d Display      : equivalent to display Display."
523         echo     "      -debug          : Start Scilab under gdb (Unix/linux only)."
524         echo     "      -debug-kdbg     : Start Scilab under kdbg (Unix/linux only)."
525         echo     "      -profiling      : Start Scilab under valgrind (Unix/linux only)."
526         echo     "      -profiling-visu : Start Scilab under callgrind (Unix/linux only)."
527         echo     "      -electric-fence : Start Scilab with the Electric Fence (Unix/linux only)."
528         echo     "      -e Instruction  : execute the scilab instruction given in Instruction argument."
529         echo     "                        -e and -f options are mutually exclusive."
530         echo     "      -f File         : execute the scilab script given in File argument."
531         echo     "                        -e and -f options are mutually exclusive."
532         echo     "      -l Lang         : set the current language. Lang can be equal to fr or en."
533         echo     "      -mem N          : set the initial stacksize, for use with -ns option."
534         echo     "      -nb             : do not display the Scilab banner at starting time."
535         echo     "      -ns             : do not execute scilab.start startup file."
536         echo     "      -nouserstartup  : do not execute the user startup files SCIHOME/.scilab or SCIHOME/scilab.ini."
537         echo     "      -nw             : start Scilab without specialized Scilab Window."
538         echo     "      -nwni           : start Scilab without the GUI, graphic and help features (batch mode). This option disables the need of Java."
539         echo     "      -nogui          : start Scilab without user GUI (batch mode)."
540         echo     "      -version        : print product version and exit."
541         echo     "      --texmacs       : reserved for TeXMacs."
542         echo     " "
543         echo     "      All these arguments can be retrieved by the Scilab function sciargs."
544         echo     " "
545         exit
546 }
547
548 do_compile()
549 {
550         umask 002
551         rm -f report
552         name=`basename $1 .sci`
553         echo generating $name.bin
554         echo "predef();getf('$name.sci');save('$name.bin');quit"\
555               | $SCILABBIN -ns -nwni | sed 1,8d 1>report 2>&1
556         if (grep error report 1> /dev/null  2>&1);
557         then cat report;echo " "
558            echo see `pwd`/report for more informations
559            grep libok report>/dev/null;
560         else rm -f report;
561         fi
562         umask 022
563         exit 0
564 }
565
566 do_lib()
567 {
568         umask 002
569         rm -f report
570         echo "$1=lib('$2/');save('$2/lib',$1);quit"\
571               | $SCILABBIN -ns -nwni |sed 1,/--\>/d 1>report 2>&1
572         if (grep error report 1> /dev/null  2>&1);
573         then cat report;echo " "
574                 echo see `pwd`/report for more informations
575                 grep libok report>/dev/null;
576         else rm -f report;
577         fi
578         umask 022
579         exit 0
580 }
581
582 MORE_OPT=""
583 if test "$SCILAB_MODE" = "nw"; then
584         MORE_OPT="-nw"
585 fi
586
587 # calling Scilab with no argument or special cases of calling Scilab
588 rest="no"
589 case $# in
590     0) # No arg, run Scilab
591                 do_scilex $MORE_OPT
592         ;;
593     2) # Only two arg
594         case $1 in
595             -comp)
596                                 do_compile $2
597                 ;;
598             *)
599                                 rest="yes"
600                 ;;
601         esac
602         ;;
603     3)
604         case $1 in
605             -lib)
606                                 do_lib $2 $3
607                 ;;
608             *)
609                                 rest="yes"
610                 ;;
611         esac
612         ;;
613     *)
614         case $1 in
615             *)
616                                 rest="yes"
617                 ;;
618         esac
619         ;;
620 esac
621
622 # really calling Scilab with arguments
623
624 if test "$rest" = "yes"; then
625         
626   debug=
627   debug_kdbg=
628   profiling=
629   profiling_visu=
630   electric_fence=
631   prevarg=
632   for sciarg in "$@"
633   do
634
635     # If the previous argument needs an argument, skip current one.
636     if test -n "$prevarg"; then
637       prevarg=
638       continue
639     fi
640
641     case $sciarg in
642       -nogui|-version|-ns|-nb|-nw|-nouserstartup|--texmacs|-nwni)
643               ;;
644       -psn_*)
645             # Under Mac OS X, .app is adding the arg -psn_0_xxxx 
646             # (psn = ProcessSerialNumber). It is not used (but could be in the future)
647             ;;
648       -display|-f|-l|-e|-d|-args|-mem)
649               prevarg=1
650               ;;
651       -debug)
652           DEBUG="-debug"
653           ;;
654       -debug-kdbg)
655           DEBUG_KDBG="-debug-kdbg"
656           ;;
657       -profiling)
658           PROFILING="-profiling"
659           ;;
660       -profiling-visu)
661           PROFILING_VISU="-profiling-visu"
662           ;;
663       -electric-fence)
664           ELECTRIC_FENCE="-electric-fence"
665           ;;
666       *)
667           do_help
668           ;;
669     esac
670   done
671
672   if test -n "$DEBUG"; then
673           start_debug "$@" $MORE_OPT
674   else
675   if test -n "$DEBUG_KDBG"; then
676           start_debug_kdbg "$@" $MORE_OPT
677   else
678         if test -n "$PROFILING"; then
679                 start_profiling "$@" $MORE_OPT
680         else
681                 if test -n "$PROFILING_VISU"; then
682                         start_profiling_visu "$@" $MORE_OPT
683                 else
684                         if test -n "$ELECTRIC_FENCE"; then
685                                 start_electric_fence "$@" $MORE_OPT
686                         else
687                                 do_scilex "$@" $MORE_OPT
688                         fi # not electric fense
689                 fi # not profiling visu
690         fi # not profiling
691   fi # not debug kdbg
692   fi # not debug
693 fi # if rest