[BACK]Return to main.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Annotation of OpenXM_contrib2/asir2000/parse/main.c, Revision 1.37

1.4       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.5       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.4       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.37    ! fujimoto   48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/main.c,v 1.36 2015/08/04 06:20:45 noro Exp $
1.4       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52:
1.35      ohara      53: #include <stdlib.h>
1.37    ! fujimoto   54: #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
1.35      ohara      55: #include <io.h>
                     56: #define R_OK 4
                     57: #else
                     58: #include <unistd.h>
                     59: #include <fcntl.h>
                     60: #endif
                     61:
1.13      noro       62: extern JMP_BUF main_env;
1.1       noro       63:
1.9       saito      64: #ifndef ASIRRCNAME
                     65: #define ASIRRCNAME      "asirrc"
                     66: #endif
                     67:
                     68:
1.1       noro       69: double get_current_time();
1.11      noro       70: void init_socket();
                     71: void recover();
1.30      noro       72: void set_stacksize();
1.11      noro       73:
1.1       noro       74: extern int mpi_nprocs,mpi_myid;
                     75:
1.35      ohara      76: char *find_asirrc()
                     77: {
                     78:        static char name[BUFSIZ];
                     79:        char dir[BUFSIZ];
                     80:        char *env,*env2;
                     81:
                     82: /* if ASIR_CONFIG is set, execute it; else execute .asirrc */
                     83:        env = getenv("ASIR_CONFIG");
                     84:        if( env && !access(env, R_OK) ) {
                     85:                strcpy(name,env);
                     86:                return name;
                     87:        }
                     88:        env = getenv("HOME");
                     89:        if ( env ) {
                     90:                sprintf(name, "%s/.asirrc", env);
                     91:                if (!access(name, R_OK)) {
                     92:                        return name;
                     93:                }
                     94:        }
1.37    ! fujimoto   95: #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
1.35      ohara      96:        env  = getenv("HOMEDRIVE");
                     97:        env2 = getenv("HOMEPATH");
                     98:        if ( env && env2 ) {
                     99:                sprintf(name, "%s%s/.asirrc", env, env2);
                    100:                if (!access(name, R_OK)) {
                    101:                        return name;
                    102:                }
                    103:        }
                    104:        env  = getenv("APPDATA");
                    105:        if ( env ) {
                    106:                sprintf(name, "%s/OpenXM/.asirrc", env);
                    107:                if (!access(name, R_OK)) {
                    108:                        return name;
                    109:                }
                    110:        }
                    111:        get_rootdir(dir, BUFSIZ);
                    112:        sprintf(name, "%s/.asirrc", dir);
                    113:        if (!access(name, R_OK)) {
                    114:                return name;
                    115:        }
                    116: #endif
                    117:        return NULL;
                    118: }
                    119:
1.1       noro      120: #if defined(VISUAL_LIB)
1.11      noro      121: void Main(int argc,char *argv[])
1.1       noro      122: #else
1.37    ! fujimoto  123: #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
1.1       noro      124: void
                    125: #endif
1.11      noro      126: main(int argc,char *argv[])
1.1       noro      127: #endif
                    128: {
1.12      noro      129:        int tmp;
1.35      ohara     130:        char *ifname;
1.1       noro      131:        extern int GC_dont_gc;
                    132:        extern int do_asirrc;
                    133:        extern int do_file;
1.24      ohara     134:        extern char *do_filename;
                    135:        extern int asir_setenv;
1.1       noro      136:        extern FILE *in_fp;
1.12      noro      137:        extern int *StackBottom;
1.37    ! fujimoto  138: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.17      noro      139:        char *slash,*bslash,*binname,*p;
1.11      noro      140: #endif
1.1       noro      141:
1.30      noro      142:        set_stacksize();
1.12      noro      143:        StackBottom = &tmp;
1.27      noro      144:        GC_init();
1.20      noro      145: #if defined(MPI)
1.1       noro      146:        mpi_init();
                    147:        if ( mpi_myid ) {
                    148:                int slave_argc;
                    149:                char *slave_argv[2];
                    150:
                    151:                ox_mpi_slave_init();
                    152:                slave_argc = 1;
                    153:                slave_argv[0] = "ox_asir"; slave_argv[1]=0;
                    154:                ox_main(argc,argv);
                    155:                exit(0);
                    156:        } else
                    157:                ox_mpi_master_init();
1.37    ! fujimoto  158: #elif !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1       noro      159:        slash = (char *)rindex(argv[0],'/');
1.16      noro      160:        bslash = (char *)rindex(argv[0],'\\');
1.1       noro      161:        if ( slash )
                    162:                binname = slash+1;
1.16      noro      163:        else if ( bslash )
                    164:                binname = bslash+1;
1.1       noro      165:        else
                    166:                binname = argv[0];
1.17      noro      167:        for ( p = binname; *p; p++ )
                    168:                *p = tolower(*p);
1.15      noro      169:        if ( !strncmp(binname,"ox_asir",strlen("ox_asir")) ) {
1.1       noro      170:                /* never return */
                    171:                ox_main(argc,argv);
                    172:                exit(0);
1.20      noro      173: #if defined(DO_PLOT)
1.15      noro      174:        } else if ( !strncmp(binname,"ox_plot",strlen("ox_plot")) ) {
1.1       noro      175:                /* never return */
                    176:                ox_plot_main(argc,argv);
                    177:                exit(0);
1.3       noro      178: #endif
1.15      noro      179:        } else if ( !strncmp(binname,"ox_launch",strlen("ox_launch")) ) {
1.1       noro      180:                /* never return */
                    181:                launch_main(argc,argv);
                    182:                exit(0);
                    183:        }
                    184: #endif
                    185:
                    186:        srandom((int)get_current_time());
                    187: /*     mt_sgenrand((unsigned long)get_current_time()); */
                    188:
                    189:        rtime_init();
                    190:        env_init();
                    191:        endian_init();
1.21      ohara     192:        cppname_init();
1.1       noro      193:        process_args(--argc,++argv);
1.33      noro      194:        if (!do_quiet) {
1.22      ohara     195:                copyright();
                    196:        }
1.1       noro      197:        output_init();
                    198:        arf_init();
                    199:        nglob_init();
                    200:        glob_init();
                    201:        sig_init();
                    202:        tty_init();
                    203:        debug_init();
                    204:        pf_init();
                    205:        sysf_init();
                    206:        parif_init();
1.26      noro      207:        order_init();
                    208:        /* XXX set the default ordering */
1.37    ! fujimoto  209: #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
1.1       noro      210:        init_socket();
                    211: #endif
                    212: #if defined(UINIT)
                    213:        reg_sysf();
                    214: #endif
1.2       noro      215:
1.28      noro      216:        if ( do_file ) {
                    217:                asir_infile=NULL;
                    218:                loadasirfile(do_filename);
                    219:        } else {
                    220:                /* the bottom of the input stack */
                    221:                input_init(stdin,"stdin");
                    222:        }
                    223:
1.35      ohara     224:        if ( do_asirrc && (ifname = find_asirrc()) ) {
1.28      noro      225:                if ( !SETJMP(main_env) )
                    226:                        execasirfile(ifname);
1.1       noro      227:        }
1.2       noro      228:
1.1       noro      229:        prompt();
                    230:        while ( 1 ) {
1.13      noro      231:                if ( SETJMP(main_env) )
1.1       noro      232:                        prompt();
1.29      noro      233:                if ( !do_file ) {
                    234:                        if ( SETJMP(asir_infile->jmpbuf) )
                    235:                                prompt();
                    236:                        else
                    237:                                asir_infile->ready_for_longjmp = 1;
                    238:                }
1.23      noro      239:                restore_handler();
1.1       noro      240:                read_eval_loop();
                    241:        }
                    242: }
                    243:
                    244: #if !defined(VISUAL_LIB)
                    245: /* a dummy function */
                    246:
1.11      noro      247: void set_error(int code,char *reason,char *action)
1.1       noro      248: {}
                    249: #endif
1.30      noro      250:
                    251: void set_stacksize()
                    252: {
1.37    ! fujimoto  253: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.30      noro      254:        struct rlimit rlim;
                    255:        int c,m;
                    256:
                    257:        getrlimit(RLIMIT_STACK,&rlim);
                    258:        if ( rlim.rlim_cur < (1<<26) ) {
                    259:                rlim.rlim_cur = MIN(1<<26,rlim.rlim_max);
                    260:                setrlimit(RLIMIT_STACK,&rlim);
                    261:        }
                    262: #endif
                    263: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>