Annotation of OpenXM_contrib2/asir2018/parse/main.c, Revision 1.1
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: *
! 48: * $OpenXM$
! 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: #if defined(VISUAL) || defined(__MINGW32__)
! 124: void
! 125: #endif
! 126: int main(int argc,char *argv[])
! 127: #endif
! 128: {
! 129: int tmp;
! 130: char *ifname;
! 131: extern int GC_dont_gc;
! 132: extern int do_asirrc;
! 133: extern int do_file;
! 134: extern char *do_filename;
! 135: extern int asir_setenv;
! 136: extern FILE *in_fp;
! 137: extern int *StackBottom;
! 138: #if !defined(VISUAL) && !defined(__MINGW32__)
! 139: char *slash,*bslash,*binname,*p;
! 140: #endif
! 141:
! 142: set_stacksize();
! 143: StackBottom = &tmp;
! 144: GC_init();
! 145: #if defined(MPI)
! 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();
! 158: #elif !defined(VISUAL) && !defined(__MINGW32__)
! 159: slash = (char *)rindex(argv[0],'/');
! 160: bslash = (char *)rindex(argv[0],'\\');
! 161: if ( slash )
! 162: binname = slash+1;
! 163: else if ( bslash )
! 164: binname = bslash+1;
! 165: else
! 166: binname = argv[0];
! 167: for ( p = binname; *p; p++ )
! 168: *p = tolower(*p);
! 169: if ( !strncmp(binname,"ox_asir",strlen("ox_asir")) ) {
! 170: /* never return */
! 171: ox_main(argc,argv);
! 172: exit(0);
! 173: #if defined(DO_PLOT)
! 174: } else if ( !strncmp(binname,"ox_plot",strlen("ox_plot")) ) {
! 175: /* never return */
! 176: ox_plot_main(argc,argv);
! 177: exit(0);
! 178: #endif
! 179: } else if ( !strncmp(binname,"ox_launch",strlen("ox_launch")) ) {
! 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();
! 192: cppname_init();
! 193: process_args(--argc,++argv);
! 194: if (!do_quiet) {
! 195: copyright();
! 196: }
! 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();
! 207: order_init();
! 208: /* XXX set the default ordering */
! 209: #if defined(VISUAL) || defined(__MINGW32__)
! 210: init_socket();
! 211: #endif
! 212: #if defined(UINIT)
! 213: reg_sysf();
! 214: #endif
! 215:
! 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:
! 224: if ( do_asirrc && (ifname = find_asirrc()) ) {
! 225: if ( !SETJMP(main_env) )
! 226: execasirfile(ifname);
! 227: }
! 228:
! 229: prompt();
! 230: while ( 1 ) {
! 231: if ( SETJMP(main_env) )
! 232: prompt();
! 233: if ( !do_file ) {
! 234: if ( SETJMP(asir_infile->jmpbuf) )
! 235: prompt();
! 236: else
! 237: asir_infile->ready_for_longjmp = 1;
! 238: }
! 239: restore_handler();
! 240: read_eval_loop();
! 241: }
! 242: }
! 243:
! 244: #if !defined(VISUAL_LIB)
! 245: /* a dummy function */
! 246:
! 247: void set_error(int code,char *reason,char *action)
! 248: {}
! 249: #endif
! 250:
! 251: void set_stacksize()
! 252: {
! 253: #if !defined(VISUAL) && !defined(__MINGW32__)
! 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>