static void initDefaults(void) { GET_LD systemDefaults.arch = PLARCH; systemDefaults.local = DEFLOCAL; systemDefaults.global = DEFGLOBAL; systemDefaults.trail = DEFTRAIL; systemDefaults.goal = "version"; systemDefaults.toplevel = "prolog"; systemDefaults.notty = NOTTYCONTROL; #ifdef __WINDOWS__ getDefaultsFromRegistry(); #endif GD->io_initialised = FALSE; GD->initialised = FALSE; GD->bootsession = FALSE; if ( systemDefaults.notty ) clearPrologFlagMask(PLFLAG_TTY_CONTROL); else setPrologFlagMask(PLFLAG_TTY_CONTROL); setPrologFlagMask(PLFLAG_DEBUGINFO); }
static void initDefaults(void) { GET_LD systemDefaults.arch = PLARCH; systemDefaults.stack_limit = DEFSTACKLIMIT; systemDefaults.table_space = DEFTABLE; systemDefaults.goal = NULL; systemDefaults.toplevel = "default"; systemDefaults.notty = NOTTYCONTROL; #ifdef __WINDOWS__ getDefaultsFromRegistry(); #endif GD->io_initialised = FALSE; GD->initialised = FALSE; GD->bootsession = FALSE; #ifdef SIG_ALERT GD->signals.sig_alert = SIG_ALERT; #endif if ( systemDefaults.notty ) clearPrologFlagMask(PLFLAG_TTY_CONTROL); else setPrologFlagMask(PLFLAG_TTY_CONTROL); setPrologFlagMask(PLFLAG_DEBUGINFO|PLFLAG_GCTHREAD); }
int query_loop(atom_t goal, int loop) { GET_LD int rc; int clear_stacks = (LD->query == NULL); do { fid_t fid; qid_t qid = 0; term_t except = 0; predicate_t p; if ( !resetProlog(clear_stacks) ) goto error; if ( !(fid = PL_open_foreign_frame()) ) goto error; p = PL_pred(PL_new_functor(goal, 0), MODULE_system); if ( (qid = PL_open_query(MODULE_system, PL_Q_NORMAL, p, 0)) ) { rc = PL_next_solution(qid); } else { error: except = exception_term; rc = FALSE; /* Won't get any better */ break; } if ( !rc && (except = PL_exception(qid)) ) { atom_t a; tracemode(FALSE, NULL); debugmode(DBG_OFF, NULL); setPrologFlagMask(PLFLAG_LASTCALL); if ( PL_get_atom(except, &a) && a == ATOM_aborted ) { #ifdef O_DEBUGGER callEventHook(PLEV_ABORT); #endif printMessage(ATOM_informational, PL_ATOM, ATOM_aborted); } } if ( qid ) PL_close_query(qid); if ( fid ) PL_discard_foreign_frame(fid); if ( !except ) break; } while(loop); return rc; }
static int restore_after_exception(term_t except) { GET_LD atom_t a; int rc = TRUE; tracemode(FALSE, NULL); debugmode(DBG_OFF, NULL); setPrologFlagMask(PLFLAG_LASTCALL); if ( PL_get_atom(except, &a) && a == ATOM_aborted ) { rc = ( callEventHook(PLEV_ABORT) && printMessage(ATOM_informational, PL_ATOM, ATOM_aborted) ); } return rc; }
int PL_initialise(int argc, char **argv) { int n; bool compile = FALSE; const char *rcpath = "<none>"; if ( GD->initialised ) succeed; initAlloc(); initPrologThreads(); /* initialise thread system */ SinitStreams(); GD->cmdline.os_argc = argc; GD->cmdline.os_argv = argv; initOs(); /* Initialise OS bindings */ initDefaults(); /* Initialise global defaults */ initPaths(argc, (const char**)argv); /* fetch some useful paths */ { GET_LD #ifdef HAVE_SIGNAL setPrologFlagMask(PLFLAG_SIGNALS); /* default: handle signals */ #endif if ( (GD->resourceDB = rc_open_archive(GD->paths.executable, RC_RDONLY)) #ifdef __WINDOWS__ || (GD->resourceDB = rc_open_archive(GD->paths.module, RC_RDONLY)) #endif ) { rcpath = ((RcArchive)GD->resourceDB)->path; initDefaultOptions(); } if ( !GD->resourceDB || !streq(GD->options.saveclass, "runtime") ) { int done; argc--; argv++; if ( argc == 1 && giveVersionInfo(argv[0]) ) /* -help, -v, etc */ { exit(0); } for(n=0; n<argc; n++) /* need to check this first */ { if ( streq(argv[n], "--" ) ) /* --: terminates argument list */ break; if ( streq(argv[n], "-b" ) ) /* -b: boot compilation */ { GD->bootsession = TRUE; break; } } DEBUG(1, if (GD->bootsession) Sdprintf("Boot session\n");); if ( !GD->resourceDB ) { if ( !(GD->resourceDB = openResourceDB(argc, argv)) ) { fatalError("Could not find system resources"); } rcpath = ((RcArchive)GD->resourceDB)->path; initDefaultOptions(); } if ( (done = parseCommandLineOptions(argc, argv, &compile)) < 0 ) { usage(); fail; } argc -= done; argv += done; }
static int parseCommandLineOptions(int argc0, char **argv, int *compile) { GET_LD int argc = argc0; for( ; argc > 0 && (argv[0][0] == '-' || argv[0][0] == '+'); argc--, argv++ ) { char *s = &argv[0][1]; if ( streq(s, "-" ) ) /* swipl <plargs> -- <app-args> */ { break; } if ( streq(s, "tty") ) /* +/-tty */ { if ( s[-1] == '+' ) setPrologFlagMask(PLFLAG_TTY_CONTROL); else clearPrologFlagMask(PLFLAG_TTY_CONTROL); continue; } else if ( isoption(s, "nosignals") ) { clearPrologFlagMask(PLFLAG_SIGNALS); continue; } else if ( isoption(s, "nodebug") ) { clearPrologFlagMask(PLFLAG_DEBUGINFO); continue; } else if ( streq(s, "-quiet") ) { GD->options.silent = TRUE; continue; } if ( *s == '-' ) { const char *optval; s++; if ( (optval=is_longopt(s, "pldoc")) ) { GD->options.pldoc_server = store_string(optval); } else if ( is_longopt(s, "home") ) { /* already handled */ #ifdef __WINDOWS__ } else if ( (optval=is_longopt(s, "win_app")) ) { GD->options.win_app = TRUE; #endif } else if ( (optval=is_longopt(s, "traditional")) ) { setTraditional(); } continue; /* don't handle --long=value */ } while(*s) { switch(*s) { case 'd': if (argc > 1) { prolog_debug_from_string(argv[1], TRUE); argc--, argv++; } else return -1; break; case 'p': optionList(&GD->options.search_paths); break; case 'O': GD->cmdline.optimise = TRUE; /* see initFeatures() */ break; case 'x': case 'o': optionString(GD->options.compileOut); break; case 'f': optionString(GD->options.initFile); break; case 'F': optionString(GD->options.systemInitFile); break; case 'l': case 's': optionList(&GD->options.scriptFiles); break; case 'g': optionString(GD->options.goal); break; case 't': optionString(GD->options.topLevel); break; case 'c': *compile = TRUE; break; case 'b': GD->bootsession = TRUE; break; case 'q': GD->options.silent = TRUE; break; case 'L': case 'G': case 'T': case 'A': case 'H': { uintptr_t size = memarea_limit(&s[1]); if ( size == MEMAREA_INVALID_SIZE ) return -1; switch(*s) { case 'L': GD->options.localSize = size; goto next; case 'G': GD->options.globalSize = size; goto next; case 'T': GD->options.trailSize = size; goto next; case 'H': case 'A': Sdprintf("% Warning: -%csize is no longer supported\n", *s); goto next; } } } s++; } next:; } return argc0-argc; }