This file is indexed.

/usr/bin/scinotes is in scilab 5.5.2-4.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
#!/bin/sh
#
# Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
# Copyright (C) INRIA - 2006-2008 - Sylvestre Ledru
# Copyright (C) INRIA - 2008 - Simon Lipp
# Copyright (C) DIGITEO - 2009-2011 - Sylvestre Ledru
# Copyright (C) DIGITEO - 2010-2011 - Bruno JOFRET
# This file must be used under the terms of the CeCILL.
# This source file is licensed as described in the file COPYING, which
# you should have received as part of this distribution.  The terms
# are also available at
# http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

####
#
# Scilab can be installed/used in different ways :
# * ./configure; make install
#    => will install Scilab into /usr/local/ and split files to
#    /usr/local/bin, /usr/local/share/scilab/, /usr/local/lib/scilab/,
#    /usr/local/include/scilab/
# * ./configure --prefix=/my/dir/; make install
#    => will install Scilab into /my/dir/ and split files to
#    /my/dir/bin/, /my/dir/share/scilab/, /my/dir/lib/scilab/
#    /my/dir/include/scilab/
#    Scilab official binary uses this arch
# * ./configure; make install prefix=$(DESTDIR)/usr \
#                   bindir=$(DESTDIR)/usr/bin \
#                   datadir=$(DESTDIR)/usr/share/scilab ...
#    Solution used mainly by Linux packagers
#
## First, this script will look for scilab-bin in :
# * If specified, in the $SCI variable
# * Into the scilab/bin/ directory
# * Into the scilab/ directory (if the user is using a source version and
# scilab has been compiled in this directory)
# * if this file is a symlink to the real one. We browse symlink(s) until we
# find the real "scilab" script file and consider that it is the right
# directory
# * That is all. Don't hesitate to contact us if you see one missing.
#
###

if test ! -z "$SCIVERBOSE"; then
    SCIVERBOSE=1
else
    SCIVERBOSE=0
fi

if test -n "$SCI"; then
    if test ! -d "$SCI/modules"; then
        echo "Cannot find directory $SCI/modules/ !"
        echo "SCI should point to the root data directory of Scilab"
        exit 255
    fi
fi

DISABLE_JAVA_DETECTION=0
IS_SCILAB_BINARY=0

start_debug() {
    if test -n "$DEVENV"; then
        echo "Running debug of Scilab [gdb]  : " "$SCI"/libtool --mode=execute gdb $SCILAB_GDB_OPT --args "$SCILABBIN" "$@"
        "$SCI"/libtool --mode=execute gdb $SCILAB_GDB_OPT --args "$SCILABBIN" "$@"
    else
        echo "Running debug of Scilab [gdb]  : " gdb $SCILAB_GDB_OPT --args "$SCILABBIN" "$@"
        gdb $SCILAB_GDB_OPT --args "$SCILABBIN" "$@"
    fi
}

start_debug_kdbg() {
    if test -n "$DEVENV"; then
        echo "Running debug of Scilab [kdbg]  : " "$SCI"/libtool --mode=execute kdbg "$SCILABBIN"
        "$SCI"/libtool --mode=execute kdbg "$SCILABBIN"
    else
        echo "Running debug of Scilab [kdbg]  : " kdbg "$SCILABBIN"
        kdbg "$SCILABBIN"
    fi
}

start_profiling() {
    VALGRIND_OPTIONS=" --show-below-main=yes --num-callers=12 --demangle=yes --leak-check=full --show-reachable=yes --smc-check=all --db-attach=yes --gen-suppressions=all --show-below-main=yes --track-origins=yes --suppressions=$SCI/tools/profiling/valgrind.supp $SCILAB_VALGRIND_OPT"
    if test -n "$DEVENV"; then
        echo "Running profiling of Scilab  : " "$SCI"/libtool --mode=execute valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
        "$SCI"/libtool --mode=execute valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
    else
        echo "Running profiling of Scilab  : " valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
        valgrind $VALGRIND_OPTIONS "$SCILABBIN" "$@"
    fi

}

start_profiling_visu() {
    VALGRIND_VISU_OPTIONS=" --tool=callgrind --trace-children=yes --smc-check=all --trace-jump=yes --dump-line=yes --separate-threads=yes $SCILAB_VALGRIND_OPT"
#--dump-instr=yes
    if test -n "$DEVENV"; then
        echo "Running profiling visualization of Scilab  : " "$SCI"/libtool --mode=execute valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
        "$SCI"/libtool --mode=execute valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
    else
        echo "Running profiling visualization of Scilab  : " valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
        valgrind $VALGRIND_VISU_OPTIONS "$SCILABBIN" "$@"
    fi
}

find_docbook_path() {
    if test -z "$DOCBOOK_ROOT"; then
        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-*/ /usr/share/sgml/docbook/xsl-stylesheets /usr/share/sgml/docbook/xsl-ns-stylesheets-*/ /usr/share/xml/docbook/stylesheet/docbook-xsl /opt/local/share/xsl/docbook-xsl; do
            if test -r "$dir/fo/docbook.xsl"; then
                if test -z "$DOCBOOK_ROOT"; then
                    DOCBOOK_ROOT=$dir
                    export DOCBOOK_ROOT
                fi
            fi
        done
    fi
    if test $SCIVERBOSE -ne 0; then
        echo "DOCBOOK : $DOCBOOK_ROOT"
    fi
}

detect_type_of_scilab(){

    progname="$0"
    SCILAB_MODE="gui"
    SCILABBIN="scilab-bin"

    if (echo "$progname"|grep "scilab-adv-cli$" 2>&1 > /dev/null;) || (echo "$@"|grep "\-nw" 2>&1 > /dev/null;) then
        SCILAB_MODE="nw"
        # We are using scilab-bin here because we are going to force the arg -nw
        SCILABBIN="scilab-bin"
    fi

    if (echo "$progname"|grep "scilab-cli$" 2>&1 > /dev/null;) || (echo "$@"|grep "\-nwni" 2>&1 > /dev/null;) then
        SCILAB_MODE="nwni"
        SCILABBIN="scilab-cli-bin"
        DISABLE_JAVA_DETECTION=1
    fi

    if (echo "$progname"|grep "scinotes$" 2>&1 > /dev/null;) then
        SCILAB_MODE="scinotes"
        SCILABBIN="scilab-bin"
        extraarg=1
    fi

    if (echo "$progname"|grep "xcos$" 2>&1 > /dev/null;) then
        SCILAB_MODE="xcos"
        SCILABBIN="scilab-bin"
        extraarg=1
    fi

    if test $SCIVERBOSE -ne 0; then
        echo "SCILABBIN : $SCILABBIN"
        echo "DISABLE_JAVA_DETECTION : $DISABLE_JAVA_DETECTION"
        echo "SCILAB_MODE : $SCILAB_MODE"
    fi
}

detect_os() {

    if test "${OS}" = ""; then
        OS=$(uname -s) # Retrieve the Operating System
    fi
    if test "${MODEL}" = ""; then
        MODEL=$(uname -m) # Retrieve the model
    fi

    if test $SCIVERBOSE -ne 0; then
        echo "OS : $OS"
        echo "MODEL : $MODEL"
    fi
}

detect_type_of_scilab $@

detect_os

detect_scilab_path() {

    LOCALOLDPWD=$(pwd)

    # If we are running Scilab binary, it is trivial to set paths.
    curdir=$(dirname "$progname")

    # If the script is a symlink, it might be a symlink to the Scilab binary
    # We could run into the bug #9125
    if test -h $progname; then
        while test -h "$progname"; do
            bn=$(basename "$progname")
            cd $(dirname "$progname")

            # Browse the symlink to the real one
            progname=$(/bin/ls -l "$bn" | sed -e 's/^.* -> //' )

            if test ! -x "$progname"; then
                break
            fi
        done
        cd $(dirname "$progname")
        curdir=$(pwd)
    fi

    if test -d $curdir/../thirdparty/ -a -d $curdir/../share/scilab; then
        # We are in the Scilab binary
        IS_SCILAB_BINARY=1
        # export the bin directory to the PATH first (avoid to take the packaged version)
        PATH="$curdir:$PATH"
        cd "$curdir/../"
        SCIBINARYBASE=$(pwd)
        SCI=$SCIBINARYBASE/share/scilab
        export SCI
        return
    fi

    # Use scilab-bin in the current dir if it exists
    # If not, then start resolving symlinks until we find scilab-bin
    found=0
    cd $(dirname "$progname")
    curdir=$(pwd -P)
    PATH="$curdir:$PATH"

    progbase=$(basename "$progname")
    run_sci="$curdir/$SCILABBIN"
    if test -x "$run_sci"; then # scilab-bin is in the /bin/ directory
        cd "$curdir/../"
        SCI=$(pwd)
        SCIBIN=$run_sci
        found=1
    else
        run_sci="$curdir/../$SCILABBIN"
        if test -x "$run_sci"; then # scilab-bin is in the / directory
        # which is the case in a dev env
            cd "$curdir/../"
            SCI=$(pwd)
            SCIBIN=$run_sci
            found=1
        else
            here=$(/bin/pwd)
            while test -h "$progname"; do
                bn=$(basename "$progname")
                cd $(dirname "$progname")
            # Browse the symlink to the real one
                progname=$(/bin/ls -l "$bn" | sed -e 's/^.* -> //' )
                if test ! -x "$progname"; then
                    break
                fi
                curdir=$(dirname "$progname")
                if test -x "$curdir"; then
                    cd "$curdir/../"
                    SCI=$(pwd)
                    SCIBIN="$curdir/$SCILABBIN"
                    found=1

                    break
                fi
            # The current file ($0), probably scilab is a symlink to the
            # real one and here, it is the dev env
                run_sci="$curdir/../$SCILABBIN"
                if test -x "$run_sci"; then
                    cd "$curdir/../"
                    SCI=$(pwd)
                    SCIBIN=$run_sci
                    found=1
                    break
                fi
            done
            cd "$here"
        fi
        if test $SCIVERBOSE -ne 0; then
            echo "I think I found Scilab here : $SCI"
        fi
    fi


    if test -x "$SCI/bin/$SCILABBIN"; then
# real env
        SCILABBIN=$SCI/bin/$SCILABBIN
        SCI=$SCI/share/scilab/
    else
        if test -x "$SCI/$SCILABBIN"; then
        # dev env
            SCILABBIN=$SCI/$SCILABBIN
            DEVENV=1
        # add modelica in the path
            PATH="$PATH:$SCI/modules/scicos/"
        else
            echo "Cannot find $SCILABBIN ..."
            exit 1
        fi
    fi

    export SCI
}


set_macosx_java_vm () {
    # For Mac OS X, Since path are different from the JVM normal tree,
    # don't need to detect the CPU
    JAVA_SHLIB="libjava.jnilib"
    if test -z "$JAVA_HOME"; then
      JAVA_HOME=$(/usr/libexec/java_home --arch x86_64 --failfast --version 1.6+)
    fi
    DYLD_LIBRARY_PATH="$JAVA_HOME/../Libraries${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"

}

set_embedded_java_vm () {

       # Scilab binary => no Java detection since we are using the embeded JRE
        # Here, we are handling 3 cases: GNU/Linux 32bit, GNU/Linux 64bit,
        # Mac OS X
        case $OS in
            "Linux")
                case $MODEL in
                    "x86_64")
                        proc="amd64"
                        ;;
                    i?86)
                        # We embed java/lib/i386 with Scilab Binary
                        # force proc to i386 even if systems answer i686
                        proc="i386"
                        ;;
                    *)
                        echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us on http://bugzilla.scilab.org"
                        ;;
                esac
                ;;
            *darwin* | *Darwin*) # MacOS X
                set_macosx_java_vm
                ;;
            *)
            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/"
            echo "Fallback on the model <${MODEL}> found by uname -m"
            proc=$MODEL
            ;;
    esac
    JRE_HOME="$SCIBINARYBASE/thirdparty/java/"

}

# If enabled, disable se_linux
check_and_disable_selinux() {
    if test -x /usr/sbin/selinuxenabled -a $IS_SCILAB_BINARY -eq 1; then
        /usr/sbin/selinuxenabled
        if test $? = 0; then
            if test $SCIVERBOSE -ne 0; then
                echo "Disabling SELinux on Scilab"
            fi

            JVMLIB_32=$SCIBINARYBASE/java/lib/i386/server/libjvm.so
            if test -f $JVMLIB_32; then
                /usr/bin/chcon -t textrel_shlib_t "$JVMLIB_32"
                if test $? != 0; then
                    echo "Error: Cannot chcon $JVMLIB_32"
                fi
            fi
            JVMLIB_64=$SCIBINARYBASE/java/lib/amd64/server/libjvm.so
            if test -f $JVMLIB_64; then
                /usr/bin/chcon -t textrel_shlib_t "$JVMLIB_64"
                if test $? != 0; then
                    echo "Error: Cannot chcon $JVMLIB_64"
                fi
            fi
            /usr/bin/chcon -t execmem_exec_t "$SCIBINARYBASE/bin/scilab-bin"
            if test $? != 0; then
                echo "Error: Cannot chcon 'scilab-bin'"
            fi

            /usr/bin/chcon -t execmem_exec_t "$SCIBINARYBASE/bin/scilab-cli-bin"
            if test $? != 0; then
                echo "Error: Cannot chcon 'scilab-cli-bin'"
            fi

        fi
    fi
}

detect_java_vm() {

    JAVA_SHLIB="libjava.so"

    if test $IS_SCILAB_BINARY -eq 1; then
        set_embedded_java_vm
    else  # NOT IS_SCILAB_BINARY

############# JAVA DETECTION ##############
# Basic inspiration from Eclipse
#
# Scilab is looking for Java in various places with different ways :
# * if JAVA_HOME is specificed, use it
# * Check in 'standard' places we know Java could be installed
# if some are missing, please contact us
# * look in the PATH if there is a java binary
# if it is the case, resolve the symlink and set the JAVA_HOME from it
#
# Once we have JAVA_HOME, we check that native libraries (libjava.so and
# 2 others) are available
###

# Get the proc name matching to the one of the JVM
# 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
# For Mac OS X, we will get stuff like that:
# uname -s Power Macintosh
# uname -m Darwin

# If the user has the variable JAVA_HOME in the ENV
        if test -n "$JAVA_HOME" ; then
                if test $SCIVERBOSE -ne 0; then
                    echo "Using specified vm: $JAVA_HOME"
                fi
                if test ! -x "$JAVA_HOME/bin/java" ; then
                    echo "Cannot find $JAVA_HOME/bin/java"
                    exit 1
                fi
        else

            case $OS in
                *darwin* | *Darwin*)
                    set_macosx_java_vm
                    if test $SCIVERBOSE -ne 0; then
                        echo "Using default Mac OS X vm: $JAVA_HOME"
                        echo "And LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
                        echo "And DYLD_LIBRARY_PATH: $DYLD_LIBRARY_PATH"
                    fi
                    ;;
                *)
                    ;;
            esac

# Browse "default directory" (if it means anything under Unix/Linux) of Java
# to find where it could be !
            if test -z "$JAVA_HOME"; then
                JAVA_DEFAULT_DIR="/usr/lib/jvm/default-java /usr/lib/jvm/java-6-openjdk/ /usr/lib/jvm/java-7-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/ /usr/local/diablo-jdk1.6.0/"
                for DIR in $JAVA_DEFAULT_DIR ; do
                    if test $SCIVERBOSE -ne 0; then
                        echo "Trying to find Java in $DIR "
                    fi
                    if test -x "${DIR}/bin/java" ; then
                        # resolve symlinked dir
                        cd $DIR
                        JAVA_HOME=$(pwd -P)
                        cd $OLDPWD

                        export JAVA_HOME
                        if test $SCIVERBOSE -ne 0; then
                            echo "Java found in $JAVA_HOME"
                        fi
                        break
                    fi
                done
            fi

# if JAVA_HOME still haven't been found. Well, we can now try to find it in the path
            if test ! -d "$JAVA_HOME"; then

                PATH_SEPARATOR=:
                as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
                if test $SCIVERBOSE -ne 0; then
                    echo "Look for the java binary in the PATH. If it is a symlink, try to resolve it"
                fi
                for DIR in $PATH; do
                    if test -f $DIR/java; then

                        _cur=$DIR/java
                # resolve symlink
                # Will probably bug if a file contains -> in the name
                        while ls -ld "$_cur" 2>/dev/null | grep " -> " >/dev/null; do
                            _cur=$(ls -ld "$_cur" | sed 's/.* -> //')
                        done
                # symlink resolved to the real file

                # Now, create JAVA_HOME
                        TMP=$(dirname $_cur)
                        JAVA_HOME=$(dirname $TMP)
                        if test ! -z "$JAVA_HOME"; then
                            break;
                        fi
                    fi
                done
                IFS=$as_save_IFS
            fi
        fi
        if test ! -z "$JAVA_HOME"; then
            if test $SCIVERBOSE -ne 0; then
                echo "JAVA_HOME : $JAVA_HOME"
            fi
# Manage JRE & JDK because libjava.so and others are stored in the JRE
            if test -d $JAVA_HOME/jre; then
                JRE_HOME=$JAVA_HOME/jre
            else
                JRE_HOME=$JAVA_HOME
            fi
# Configuring LD_LIBRARY_PATH for libjava.so libhpi.so and libxxxx.so

            case $OS in
                "Linux")
                    case $MODEL in
                        "x86_64")
                            proc="amd64"
                            ;;
                        i?86)

                            if test -d ${JRE_HOME}/lib/$(uname -m) ; then
                                proc=$(uname -m)
                            else
                                proc="i386"
                            fi
                            ;;
                        "alpha")
                            proc="alpha"
                            ;;
                        "sparc"|"sparc64")
                            proc="sparc"
                            ;;
                        sh*)
                            proc="sh"
                            ;;
                        "ia64")
                            proc="ia64"
                            ;;
                        mips*) # under mipsel, uname -m is
                    # usually returning mips or mips64...
                    # but binary are in mipsel
                            if test -d ${JRE_HOME}/lib/mipsel ; then
                                proc="mipsel"
                            else
                                proc="mips"
                            fi
                            ;;
                        "ppc"|"powerpc")
                            proc="ppc"
                            ;;
                        "ppc64")
                            proc="ppc64"
                            ;;
                        "ppc64le")
                            proc="ppc64le"
                            ;;
                        "s390")
                            proc="s390"
                            ;;
                        "s390x")
                            proc="s390x"
                            ;;
                        armv*)
                            proc="arm"
                            ;;
                        aarch64)
                            proc="aarch64"
                            ;;
                        *)
                            echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us on http://bugzilla.scilab.org"
                            ;;
                    esac
                    ;;
                "HP-UX")
                    JAVA_SHLIB="libjava.sl"
                    proc="lib" # TODO : check if it is right or not ... seems not !
                    ;;
                "IRIX")
                    proc="lib32"
                    ;;
                "SunOS")
                    case $MODEL in
                        "i86pc") # solaris x86
                            proc="i386"
                            ;;
                # check for the 64 bits syntax
                        "sparc"|"sparc64")
                            proc="sparc"
                            ;;
                        *)
                            echo "Could not find the Java configuration for the model <${MODEL}>. Please contact us."
                            ;;
                    esac
                    ;;

                *win32* | *WIN32* | *CYGWIN_NT*)
                    proc="win32"
                    JAVA_SHLIB="jvm.dll"
                    ;;
                *darwin* | *Darwin*) # MacOS X
                    set_macosx_java_vm
                    ;;
                *FreeBSD*)
                    proc=$MODEL
                    ;;
                *)
                    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/"
                    echo "Fallback on the model <${MODEL}> found by uname -m"
                    proc=$MODEL
                    ;;
            esac
        fi # JAVA_HOME provided or found
    fi # IS_SCILAB_BINARY

# Check if the lib exists or not
    LIBJAVA="$JRE_HOME/lib/$proc/$JAVA_SHLIB"
    if test ! -f $LIBJAVA; then
        if test $SCIVERBOSE -ne 0; then
            echo "Cannot find $LIBJAVA"
        fi
    else
        CLASSPATH="${CLASSPATH:+:$CLASSPATH}$SCI/modules/core/jar/org.scilab.modules.core.jar"
        # @TODO This is the default path of the official sun JVM.
        # It is different for other implementation of the JVM....
        LD_LIBRARY_PATH="$JRE_HOME/lib/$proc/:$JRE_HOME/lib/$proc/server/:$JRE_HOME/lib/$proc/native_threads/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
    fi

####### END OF JAVA ENV DETECTION/SETTING ######
}

detect_scilab_path
if test $SCIVERBOSE -ne 0; then
    echo "IS_SCILAB_BINARY : $IS_SCILAB_BINARY"
fi


# If we are calling scilab-cli, no need to detect java.
if test $DISABLE_JAVA_DETECTION -ne 1; then
    detect_java_vm
fi

if test $IS_SCILAB_BINARY -eq 1; then

    if test ! -d "$SCIBINARYBASE/thirdparty/tcl8.5"; then
        # New packaging path (similar to Windows one)
        TCL_LIBRARY="$SCIBINARYBASE/share/scilab/modules/tclsci/tcl/tcl8.5"
        TK_LIBRARY="$SCIBINARYBASE/share/scilab/modules/tclsci/tcl/tk8.5"
    else
        # Old packaging path
        TCL_LIBRARY="$SCIBINARYBASE/thirdparty/tcl8.5"
        TK_LIBRARY="$SCIBINARYBASE/thirdparty/tk8.5"
    fi
    LD_LIBRARY_PATH=$SCIBINARYBASE/lib/scilab:$SCIBINARYBASE/lib/thirdparty${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}:$SCIBINARYBASE/lib/thirdparty/redist
    DOCBOOK_ROOT="$SCI/../../thirdparty/docbook"
    PATH="$PATH:$SCI/modules/scicos/"

    export DOCBOOK_ROOT
    export PATH
    export LD_LIBRARY_PATH
    export TCL_LIBRARY
    export TK_LIBRARY

    case $OS in
        *darwin* | *Darwin*)
            DYLD_LIBRARY_PATH=$SCIBINARYBASE/lib/scilab:$SCIBINARYBASE/lib/thirdparty${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
            export DYLD_LIBRARY_PATH
            PATH="/sw/bin:/sw64/bin:$PATH"
            export PATH
            ;;
    esac

else
    # Scilab compiled using prerequirements
    if test -d $curdir/../usr; then
        TCL_LIBRARY="$SCI/usr/lib/tcl8.5"
        TK_LIBRARY="$SCI/usr/lib/tk8.5"
        export TCL_LIBRARY
        export TK_LIBRARY
    fi
    PATH="$SCI:$SCI/bin:$PATH"
fi


# See http://bugzilla.scilab.org/show_bug.cgi?id=3486
# Some Java stuff raises spurious SIGSEGV. The problem is that when bug-buddy
# is enabled, it catches the signal and terminate Scilab. We have to
# desactivate bug-buddy.
# See also https://bugzilla.novell.com/show_bug.cgi?id=331618
# and: http://bugzilla.gnome.org/show_bug.cgi?id=479929
GTK_MODULES=$(echo $GTK_MODULES | sed s/gnomebreakpad//g)
export GTK_MODULES

# libEGL may be partially supported by the closed-source NVIDIA driver.
# Until they release an EGL driver, we force the egl_glx driver.
# http://bugzilla.scilab.org/show_bug.cgi?id=12940
if test -x /usr/bin/glxinfo; then
    NVIDIA_GLX_VENDOR=$(/usr/bin/glxinfo |grep "NVIDIA Corporation")
    if test ! -z "$NVIDIA_GLX_VENDOR"; then
        EGL_DRIVER=egl_glx
        export EGL_DRIVER
    fi
fi

if test $SCIVERBOSE -ne 0; then
    echo "SCI : $SCI"
    echo "SCIBIN : $SCIBIN"
    echo "PATH : $PATH"
    echo "CLASSPATH : $CLASSPATH"
    echo "EGL_DRIVER : $EGL_DRIVER"
fi

# Returns to the original path
cd "$LOCALOLDPWD"

#if test "$DISPLAY" = ""; then
#  DISPLAY="unix:0.0"
#fi
#export DISPLAY


detect_macosx_version()
{
    macosxVersion=`sw_vers | grep '^ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*'`
    if test "${macosxVersion}" = ""; then
      macosxVersion=`sw_vers | grep '^ProductVersion:' | grep -o '[0-9]*\.[0-9]*'`
    fi
    macosxMajorVersion=`echo $macosxVersion | cut -d . -f 1`
    macosxMinorVersion=`echo $macosxVersion | cut -d . -f 2`
    macosxBuildVersion=`echo $macosxVersion | cut -d . -f 3`

    if test $SCIVERBOSE -ne 0; then
        echo "Found MacOSX Version: $macosxVersion"
    fi

}

set_macox_specific_path()
{

    PATH_TO_SPECIFIC_10_6=$SCIBINARYBASE/lib/thirdparty/10.6/
    PATH_TO_SPECIFIC_10_5=$SCIBINARYBASE/lib/thirdparty/10.5/

    case $macosxMajorVersion in
        10)
            case $macosxMinorVersion in
                6)
		    # the iconv lib fails under 10.7, just declare it for 10.5 & 10.6
                    LD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_6${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
                    DYLD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_6${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
                    ;;
                 5)
                    # the iconv lib fails under 10.7, just declare it for 10.5 & 10.6
                    LD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_6${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
                    DYLD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_6${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
                    LD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_5${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
                    DYLD_LIBRARY_PATH=$PATH_TO_SPECIFIC_10_5${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
                    ;;
            esac
            ;;
    esac

}

#
# Scilab will not work on some Mac OSX version
# Check version number and ask user if he wants to go on.
#
check_macosx_version()
{

    case $macosxMajorVersion in
        10)
            case $macosxMinorVersion in
                7|8|9|10)
                   # We force to install JRE on Lion
                   /usr/libexec/java_home --request > /dev/null
                   ;;
                6)

                    if test $macosxBuildVersion -le 4; then
                        # Version <= 10.6.4
                        osascript $BINPATH/checkmacosx.applescript $macosxVersion "10.6.5 (Snow Leopard) or newer system" || exit 128
                    fi
                    ;;
                 5)
                     if test $macosxBuildVersion -le 7; then
                         # Version <= 10.5.8
                         osascript $BINPATH/checkmacosx.applescript $macosxVersion "10.5.8 (Leopard) or newer system" || exit 128
                     fi
                     # Check if the default java is not 1.5 (magic)
                     VERSION=$(/usr/libexec/java_home -v 1.5|grep 1.5.0)
                     if test "$VERSION"; then
                         open /Applications/Utilities/Java\ Preferences.app/ &
                         osascript $BINPATH/checkmacosx.applescript $macosxVersion "Java 6 or newer. Please disable any version of Java 1.5 in the Java Preferences menu. An other workaround is to rename /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries/libjava.jnilib to libjava.jnilib_" || exit 128
                     fi

                     ;;
                *)
                    osascript $BINPATH/checkmacosx.applescript $macosxVersion "10.6.5 (Snow Leopard) or newer system" || exit 128
                    ;;
            esac
            ;;
        *)
            osascript $BINPATH/checkmacosx.applescript $macosxVersion "10.6.5 (Snow Leopard) or newer system" || exit 128
            ;;
    esac
}

# . is used by the dynamic link. The build lib are copied into the PWD
SCILIB=$SCI/bin:$SCI/lib/scilab/:$SCI/lib64/scilab/:.
if test -d $SCI/lib/thirdparty; then
    SCILIB=$SCI/lib/thirdparty:$SCILIB;
fi
#LD_LIBRARY_PATH=$SCILIB${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}

case $OS in
    *darwin* | *Darwin*) # MacOS X
        # When using some packaging tools like fink which are storing the info in /sw/lib
        LD_LIBRARY_PATH="/sw/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
    # Export the path to the Scilab lib when Scilab has been install ...
    # to a Mac os x specific variable used by the linker before LD_LIBRARY_PATH
        DYLD_LIBRARY_PATH=$SCI/../../lib/scilab/${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}:
        # Crappy workaround for the dynamic load of sundials under Mac OS X
        # in the source tree version. This does not occur in the binary
        # thanks to the previous declaration on ../../lib/scilab
        # See bug #4949
        if test -d "$SCI/modules/scicos_blocks/.libs/"; then
            DYLD_LIBRARY_PATH=$SCI/modules/scicos_blocks/.libs/${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
        fi
        if test -d "$SCI/modules/scicos/.libs/"; then
            DYLD_LIBRARY_PATH=$SCI/modules/scicos/.libs/${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
        fi
        export DYLD_LIBRARY_PATH

        # Now, check that I can run Scilab on this version of Mac OS X and
        # display a standard window
        BINPATH=$(dirname $0)
        # Do not perform the check with Scilab is started in CLI mode

        detect_macosx_version
        set_macox_specific_path

        if test "$SCILAB_MODE" = "gui"; then
            check_macosx_version
        fi

        # When started as an Application, the default path was "/"
        # It is not really useful. Changing to HOME.
        # See bugs 8339 and 10575 for rational
        if test "$(pwd)" = "/"; then
            cd $HOME
        fi

        ;;
    *)
esac

LD_LIBRARY_PATH=/usr/lib/scilab/:/usr/lib64/scilab/:.${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

if test $SCIVERBOSE -ne 0; then
    echo "LD_LIBRARY_PATH : $LD_LIBRARY_PATH"
    if test ! -z "$DYLD_LIBRARY_PATH"; then
        echo "DYLD_LIBRARY_PATH: $DYLD_LIBRARY_PATH"
    fi
fi
export LD_LIBRARY_PATH
export PATH

# Scilab does not support the LANGUAGE variable.
# Unset to avoid some weird issue. CF bug #10032
unset LANGUAGE

if test $IS_SCILAB_BINARY -ne 1; then
# We are not using the Scilab binary, find out where docbook is.
    find_docbook_path
fi

# Check if SELINUX is enable. If it is the case, disable it for Scilab
check_and_disable_selinux

do_scinotes()
{
    INDENT=""
    if test $# -gt 0; then
    # scinotes is called. We process the arguments
    ARGS="["

    for SCIARG in "$@"; do
        if test "$SCIARG" = "-indent"; then
            INDENT="['indent','trailing','quote']"
        else
            ARGS="$ARGS '$SCIARG', "
        fi
    done
    ARGS="$ARGS]"
    fi

    if test -n "$INDENT"; then
    # Call scinotes with the arguments
        if test $SCIVERBOSE -ne 0; then
            echo "Will start scinotes with: $SCILABBIN -nb -nw -e scinotes($ARGS, $INDENT);exit()"
        fi
        "$SCILABBIN" -nb -nw -e "scinotes($ARGS, $INDENT);exit()"
    else
        if test $SCIVERBOSE -ne 0; then
            echo "Will start scinotes with: $SCILABBIN -e scinotes($ARGS)"
        fi

    # Call scinotes with no argument
        "$SCILABBIN" -e "scinotes($ARGS)"
        exit $?
    fi
}

do_xcos()
{
    SIMULATE=0
    if test $# -gt 0; then
    # xcos is called. We process the arguments
        ARGS="["
        for SCIARG in "$@"; do
            if test "$SCIARG" = "-simulate"; then
                if test $# -ne 2; then
                    echo "Wrong syntax: When -simulate is used, only one file must be provided."
                    exit 43
                fi
                SIMULATE=1
            else
                ARGS="$ARGS '$SCIARG', "
            fi
        done
        ARGS="$ARGS ]"
    fi

    if test $SIMULATE -eq 1; then
        if test $SCIVERBOSE -ne 0; then
            echo "Will start Xcos with: $SCILABBIN -e 'importXcosDiagram($ARGS);xcos_simulate(scs_m, 4)'"
        fi

    # Call xcos with the arguments to simulate
        "$SCILABBIN" -e "importXcosDiagram($ARGS);xcos_simulate(scs_m, 4)"
    else
        if test $SCIVERBOSE -ne 0; then
            echo "Will start Xcos with: $SCILABBIN -e xcos($ARGS)"
        fi

    # Call xcos with the arguments
        "$SCILABBIN" -e "xcos($ARGS)"
        exit $?
    fi

}

do_scilex()
{
    if test "$SCILAB_MODE" = "xcos"; then
        do_xcos "$@"
    else
        if test "$SCILAB_MODE" = "scinotes"; then
            do_scinotes "$@"
        else
            "$SCILABBIN" "$@"
            exit $?
        fi
    fi
}

do_help()
{
    if test "$SCILAB_MODE" = "xcos"; then
        echo "Start Xcos, the hybrid simulator"
        echo "Usage:"
        echo "xcos [ file1.xcos, [ file2.xcos ]]"
        echo     " "
        echo     "  Possible arguments are:"
        echo     "  -simulate : Start the simulation. Only one file will be accepted."
        exit
    fi
    if test "$SCILAB_MODE" = "scinotes"; then
        echo "Start Scinotes, the Scilab text editor"
        echo "Usage:"
        echo     "scinotes [ file1.sci, [ file2.sce ]]"
        echo     " "
        echo     "  Possible arguments are:"
        echo     "  -indent : format (indent, trailing spaces, quote mismatch) the files"
        exit
    fi

    echo "Usage:"
    echo     "scilab <arguments>"
    echo     "scilab-cli <arguments>"
    echo     "scilab-adv-cli <arguments>"
    echo     " "
    echo     "  Possible arguments are:"
    echo     "  -display Display: for use under Xwindow systems to set a specific X server display."
    echo     "  -d Display      : equivalent to -display Display."
    echo     "  -e Instruction  : execute the scilab instruction given in Instruction argument."
    echo     "                    -e and -f arguments are mutually exclusive."
    echo     "  -f File         : execute the scilab script given in File argument."
    echo     "                    -e and -f arguments are mutually exclusive."
    echo     "  -l Lang         : set the current language. Lang can be equal to fr or en."
    echo     "  -mem N          : set the initial stacksize, for use with -ns argument."
    echo     "  -nb             : do not display Scilab loading on start."
    echo     "  -ns             : do not execute scilab.start startup file. This argument will disable many features in Scilab (Only use if you know what you are doing)."
    echo     "  -nouserstartup  : do not execute the user startup files SCIHOME/.scilab or SCIHOME/scilab.ini."
    echo     "  -noatomsautoload: do not load ATOMS installed module."
    echo     "  -nw             : start Scilab without dedicated Scilab Window."
    echo     "  -nwni           : start Scilab without the GUI, graphic and help features (batch mode). This argument disables the need of Java."
    echo     "  -nogui          : See -nwni"
    echo     "  -nocolor        : Remove the color in the cli and adv-cli modes"
    echo     "  -args           : accept all extra arguments and make them available through sciargs"
    echo     "  -version        : print product version and exit."
    echo     "  -h/--help       : display help about this command."
    echo     "  --texmacs       : reserved for TeXMacs."
    echo     " "

    echo     "Developer arguments:"
    echo     "  -debug          : Start Scilab under gdb (Unix/linux only)."
    echo     "                    define the variable SCILAB_GDB_OPT to add custom arguments to gdb."
    echo     "  -debug-kdbg     : Start Scilab under kdbg (Unix/linux only)."
    echo     "  -profiling      : Start Scilab under valgrind (Unix/linux only)."
    echo     "                    define the variable SCILAB_VALGRIND_OPT to add custom arguments to"
    echo     "                    valgrind (and override the existing valgrind arguments)."
    echo     "  -profiling-visu : Start Scilab under callgrind (Unix/linux only)."
    echo     "                    define the variable SCILAB_VALGRIND_OPT to add custom arguments to"
    echo     "                    callgrind (and override the existing callgrind arguments)."
    echo     "  -disable-exception-catching : Disable Scilab exception catching system."
    echo     " "
    echo     "  All these arguments can be retrieved by the Scilab function sciargs."
    echo     " "

    echo     "  Several environment variables can be declared:"
    echo     "  SCIVERBOSE               Provides debugging information of the startup"
    echo     "  JAVA_HOME                Declares which Java Virtual Machine to use"
    echo     "  SCI_DISABLE_TK           Disable Tk (but not Tcl) features"
    echo     "  SCI_JAVA_ENABLE_HEADLESS Enable Java Headless VM (ie without GUI features)"
    echo     "  SCI_DISABLE_EXCEPTION_CATCHING Disable the catch by Scilab of exception (segfault, ...)"

    exit
}

MORE_OPT=""
if test "$SCILAB_MODE" = "nw"; then
    MORE_OPT="-nw"
fi

# calling Scilab with no argument or special cases of calling Scilab
rest="no"
case $# in
    0) # No arg, run Scilab
        do_scilex $MORE_OPT
        ;;
    *)
        case $1 in
            *)
                rest="yes"
                ;;
        esac
        ;;
esac

# really calling Scilab with arguments

if test "$rest" = "yes"; then
    debug=
    debug_kdbg=
    profiling=
    profiling_visu=
    prevarg=
    for sciarg in "$@"
    do

    # If the previous argument needs an argument, skip current one.
        if test -n "$prevarg"; then
            prevarg=
            continue
        fi

        case $sciarg in
            -nogui|-version|-ns|-nb|-nouserstartup|-noatomsautoload|-nocolor|--texmacs)
                ;;
            -nw)
                if test "$SCILAB_MODE" = "nwni"; then
                    echo "Cannot use scilab-cli with option -nw"
                    exit 5
                fi
                ;;
            -nwni)
                if test "$SCILAB_MODE" = "nw"; then
                    echo "Cannot use scilab-adv-cli with option -nwni"
                    exit 5
                fi
                ;;
            -psn_*)
            # Under Mac OS X, .app is adding the arg -psn_0_xxxx
            # (psn = ProcessSerialNumber). It is not used (but could be in the future)
                ;;
            -display|-f|-l|-e|-d|-mem)
                prevarg=1
                ;;
            -args) # Accept extra arguments
                extraarg=1
                ;;
            -debug)
                DEBUG="-debug"
                ;;
            -debug-kdbg)
                DEBUG_KDBG="-debug-kdbg"
                ;;
            -profiling)
                PROFILING="-profiling"
                ;;
            -profiling-visu)
                PROFILING_VISU="-profiling-visu"
                ;;
            -disable-exception-catching)
                SCI_DISABLE_EXCEPTION_CATCHING=1
                export SCI_DISABLE_EXCEPTION_CATCHING
                ;;
            -h|--help)
                do_help
                ;;
            *)
                foundUnknownArg=1
                wrongArg=$sciarg
                # Do nothing. Gives unknown args to Scilab binaries if -args is provided
                ;;
        esac
    done

LD_LIBRARY_PATH=/usr/lib/scilab/:/usr/lib64/scilab/:.${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

# If the argument -a is not provided (extraarg) and we found unknown args
# fail and provide help
    if test -z "$extraarg" -a -n "$foundUnknownArg"; then
        echo "Unknown argument: $wrongArg"
        echo ""
        do_help
    fi

    if test -n "$DEBUG"; then
        start_debug "$@" $MORE_OPT
    else
        if test -n "$DEBUG_KDBG"; then
            start_debug_kdbg "$@" $MORE_OPT
        else
            if test -n "$PROFILING"; then
                start_profiling "$@" $MORE_OPT
            else
                if test -n "$PROFILING_VISU"; then
                    start_profiling_visu "$@" $MORE_OPT
                else
                    do_scilex "$@" $MORE_OPT
                fi # not profiling visu
            fi # not profiling
        fi # not debug kdbg
    fi # not debug
fi # if rest