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

Annotation of OpenXM_contrib2/asir2018/parse/main.c, Revision 1.2

1.1       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
                     26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
                     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.2     ! ohara      48:  * $OpenXM: OpenXM_contrib2/asir2018/parse/main.c,v 1.1 2018/09/19 05:45:08 noro Exp $
1.1       noro       49: */
                     50: #include "ca.h"
                     51: #include "parse.h"
                     52:
                     53: #include <stdlib.h>
                     54: #if defined(VISUAL) || defined(__MINGW32__)
                     55: #include <io.h>
                     56: #define R_OK 4
                     57: #else
                     58: #include <unistd.h>
                     59: #include <fcntl.h>
                     60: #endif
                     61:
                     62: extern JMP_BUF main_env;
                     63:
                     64: #ifndef ASIRRCNAME
                     65: #define ASIRRCNAME      "asirrc"
                     66: #endif
                     67:
                     68:
                     69: double get_current_time();
                     70: void init_socket();
                     71: void recover();
                     72: void set_stacksize();
                     73:
                     74: extern int mpi_nprocs,mpi_myid;
                     75:
                     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:   }
                     95: #if defined(VISUAL) || defined(__MINGW32__)
                     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:
                    120: #if defined(VISUAL_LIB)
                    121: void Main(int argc,char *argv[])
                    122: #else
                    123: int main(int argc,char *argv[])
                    124: #endif
                    125: {
                    126:   int tmp;
                    127:   char *ifname;
                    128:   extern int GC_dont_gc;
                    129:   extern int do_asirrc;
                    130:   extern int do_file;
                    131:   extern char *do_filename;
                    132:   extern int asir_setenv;
                    133:   extern FILE *in_fp;
                    134:   extern int *StackBottom;
                    135: #if !defined(VISUAL) && !defined(__MINGW32__)
                    136:   char *slash,*bslash,*binname,*p;
                    137: #endif
                    138:
                    139:   set_stacksize();
                    140:   StackBottom = &tmp;
                    141:   GC_init();
                    142: #if defined(MPI)
                    143:   mpi_init();
                    144:   if ( mpi_myid ) {
                    145:     int slave_argc;
                    146:     char *slave_argv[2];
                    147:
                    148:     ox_mpi_slave_init();
                    149:     slave_argc = 1;
                    150:     slave_argv[0] = "ox_asir"; slave_argv[1]=0;
                    151:     ox_main(argc,argv);
                    152:     exit(0);
                    153:   } else
                    154:     ox_mpi_master_init();
                    155: #elif !defined(VISUAL) && !defined(__MINGW32__)
                    156:   slash = (char *)rindex(argv[0],'/');
                    157:   bslash = (char *)rindex(argv[0],'\\');
                    158:   if ( slash )
                    159:     binname = slash+1;
                    160:   else if ( bslash )
                    161:     binname = bslash+1;
                    162:   else
                    163:     binname = argv[0];
                    164:   for ( p = binname; *p; p++ )
                    165:     *p = tolower(*p);
                    166:   if ( !strncmp(binname,"ox_asir",strlen("ox_asir")) ) {
                    167:     /* never return */
                    168:     ox_main(argc,argv);
                    169:     exit(0);
                    170: #if defined(DO_PLOT)
                    171:   } else if ( !strncmp(binname,"ox_plot",strlen("ox_plot")) ) {
                    172:     /* never return */
                    173:     ox_plot_main(argc,argv);
                    174:     exit(0);
                    175: #endif
                    176:   } else if ( !strncmp(binname,"ox_launch",strlen("ox_launch")) ) {
                    177:     /* never return */
                    178:     launch_main(argc,argv);
                    179:     exit(0);
                    180:   }
                    181: #endif
                    182:
                    183:   srandom((int)get_current_time());
                    184: /*  mt_sgenrand((unsigned long)get_current_time()); */
                    185:
                    186:   rtime_init();
                    187:   env_init();
                    188:   endian_init();
                    189:   cppname_init();
                    190:   process_args(--argc,++argv);
                    191:   if (!do_quiet) {
                    192:     copyright();
                    193:   }
                    194:   output_init();
                    195:   arf_init();
                    196:   nglob_init();
                    197:   glob_init();
                    198:   sig_init();
                    199:   tty_init();
                    200:   debug_init();
                    201:   pf_init();
                    202:   sysf_init();
                    203:   parif_init();
                    204:   order_init();
                    205:   /* XXX set the default ordering */
                    206: #if defined(VISUAL) || defined(__MINGW32__)
                    207:   init_socket();
                    208: #endif
                    209: #if defined(UINIT)
                    210:   reg_sysf();
                    211: #endif
                    212:
                    213:   if ( do_file ) {
                    214:     asir_infile=NULL;
                    215:     loadasirfile(do_filename);
                    216:   } else {
                    217:     /* the bottom of the input stack */
                    218:     input_init(stdin,"stdin");
                    219:   }
                    220:
                    221:   if ( do_asirrc && (ifname = find_asirrc()) ) {
                    222:     if ( !SETJMP(main_env) )
                    223:       execasirfile(ifname);
                    224:   }
                    225:
                    226:   prompt();
                    227:   while ( 1 ) {
                    228:     if ( SETJMP(main_env) )
                    229:       prompt();
                    230:     if ( !do_file ) {
                    231:       if ( SETJMP(asir_infile->jmpbuf) )
                    232:         prompt();
                    233:       else
                    234:         asir_infile->ready_for_longjmp = 1;
                    235:     }
                    236:     restore_handler();
                    237:     read_eval_loop();
                    238:   }
                    239: }
                    240:
                    241: #if !defined(VISUAL_LIB)
                    242: /* a dummy function */
                    243:
                    244: void set_error(int code,char *reason,char *action)
                    245: {}
                    246: #endif
                    247:
                    248: void set_stacksize()
                    249: {
                    250: #if !defined(VISUAL) && !defined(__MINGW32__)
                    251:   struct rlimit rlim;
                    252:   int c,m;
                    253:
                    254:   getrlimit(RLIMIT_STACK,&rlim);
                    255:   if ( rlim.rlim_cur < (1<<26) ) {
                    256:     rlim.rlim_cur = MIN(1<<26,rlim.rlim_max);
                    257:     setrlimit(RLIMIT_STACK,&rlim);
                    258:   }
                    259: #endif
                    260: }

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