int main(int argc, char **argv) { #if O_CTRLC main_thread_id = GetCurrentThreadId(); SetConsoleCtrlHandler((PHANDLER_ROUTINE)consoleHandlerRoutine, TRUE); #endif #if O_ANSI_COLORS PL_w32_wrap_ansi_console(); /* decode ANSI color sequences (ESC[...m) */ #endif #ifdef READLINE PL_initialise_hook(install_readline); #endif if ( !PL_initialise(argc, argv) ) PL_halt(1); for(;;) { int status = PL_toplevel() ? 0 : 1; PL_halt(status); } return 0; }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { char * argv[100]; int argc; program = program_name(hInstance); argc = breakargs(program, lpszCmdLine, argv); bind_terminal(); PL_set_prolog_flag("verbose", PL_ATOM, "silent"); /* operate silently */ DEBUG(ok("About to start Prolog with %d arguments", argc)); if ( !PL_initialise(argc, argv) ) { ok("Initialisation failed"); PL_halt(1); } if ( PL_toplevel() ) { PL_halt(0); } else { ok("Toplevel failed"); PL_halt(1); } return 0; }
void SWIPLContainer::__init(int argc, char **argv) { if ( !PL_initialise(argc, argv) ) { qDebug() << "Unable to initialize Prolog engine!"; PL_halt(1); // will terminate the process! return; // we never get here, but still } qDebug() << "Prolog successfully initialized!"; }
int main(int argc, char **argv) { char expression[MAXLINE]; char *e = expression; char *program = argv[0]; char *plav[2]; int n; /* combine all the arguments in a single string */ for(n=1; n<argc; n++) { if ( n != 1 ) *e++ = ' '; strcpy(e, argv[n]); e += strlen(e); } /* make the argument vector for Prolog */ plav[0] = program; plav[1] = NULL; /* initialise Prolog */ if ( !PL_initialise(1, plav) ) PL_halt(1); /* Lookup calc/1 and make the arguments and call */ { predicate_t pred = PL_predicate("calc", 1, "user"); term_t h0 = PL_new_term_refs(1); int rval; PL_put_atom_chars(h0, expression); rval = PL_call_predicate(NULL, PL_Q_NORMAL, pred, h0); PL_halt(rval ? 0 : 1); } return 0; }
void initpyswipl() { char *plargs[3]; term_t swipl_load; fid_t swipl_fid; /**********************************************************/ /* Initialize the prolog kernel. */ /* The kernel is embedded (linked in) so I am setting the */ /* the startup path to be the current directory. Also, */ /* I'm sending the -q flag to supress the startup banner. */ /**********************************************************/ plargs[0]="./"; plargs[1]="-q"; plargs[2]="-nosignals"; PL_initialise(3,plargs); /**********************************************************/ /* Load the pyrun predicate. */ /* The pyrun.pl file has to be in the current working */ /* directory. */ /**********************************************************/ swipl_fid=PL_open_foreign_frame(); swipl_load=PL_new_term_ref(); /**********************************************************/ /* Changed by Nathan Denny July 18, 2001 */ /* No longer necessary to include pyrun.pl */ /**********************************************************/ /*PL_chars_to_term("consult('pyrun.pl')", swipl_load);*/ PL_chars_to_term("assert(pyrun(GoalString,BindingList):-(atom_codes(A,GoalString),atom_to_term(A,Goal,BindingList),call(Goal))).", swipl_load); PL_call(swipl_load,NULL); PL_discard_foreign_frame(swipl_fid); /**********************************************************/ /* Call the Python module initializer. */ /**********************************************************/ (void) Py_InitModule("pyswipl",pyswiplMethods); }
// ###################################################################### SWIProlog::SWIProlog(int argc, char **argv) { const char *av[10]; int ac = 0; // av[ac++] = argv[0]; av[ac++] = "DefaultProg"; av[ac++] = "-q"; av[ac++] = "-nosignals"; av[ac] = NULL; #ifdef HAVE_SWI_PROLOG_H if (!PL_initialise(ac, av)) { PL_halt(1); LFATAL("Failed to init prolog"); } #else LINFO("SWI prolog not found"); #endif }
void check_prolog(pTHX_ pMY_CXT) { if (!c_prolog_ok) { if(!PL_is_initialised(NULL, NULL)) { args2argv(); if(!PL_initialise(PL_argc, PL_argv)) { die ("unable to start prolog engine"); } push_frame(aTHX_ aMY_CXT); c_prolog_init=1; } #ifdef MULTIPLICITY if(PL_thread_self()==-1) { if(PL_thread_attach_engine(NULL)==-1) { die ("unable to create prolog thread engine"); } push_frame(aTHX_ aMY_CXT); c_prolog_init=1; } #endif c_prolog_ok=1; } }
static char *prolog_iniciar(modulo_t *modulo, GHashTable *argumentos) { prolog_dato_t *prolog = (prolog_dato_t*)modulo->m_dato; char *av[10]; int ac = 0; av[ac++] = "prolog"; av[ac++] = "-g"; av[ac++] = "true"; av[ac++] = "-f"; av[ac++] = "none"; if(!PL_initialise(ac, av)) { PL_halt(-1); } prolog->m_fid = PL_open_foreign_frame(); g_hash_table_insert(modulo->m_tabla, PUERTO_SALIDA, 0); g_hash_table_insert(modulo->m_tabla, PUERTO_ORDEN, 0); g_hash_table_insert(modulo->m_tabla, PUERTO_PARAMETRO, 0); return "iniciado"; }
int main(int argc, char **argv) { char *program = argv[0]; char *plav[2]; char problem[MAXLINE]; char *p = problem; /* make the argument vector for Prolog */ plav[0] = program; plav[1] = NULL; /* initialize Prolog */ if ( !PL_initialise(1, plav) ) PL_halt(1); /* initialize the input planning problem */ strcpy(p, argv[1]); printf("%s\n", p); /* Lookup solve/1 and make the arguments and call */ predicate_t pred = PL_predicate("solve", 1, "user"); term_t h0 = PL_new_term_refs(1); int rval; PL_put_atom_chars(h0, problem); rval = PL_call_predicate(NULL, PL_Q_NORMAL, pred, h0); PL_halt(rval ? 0 : 1); return 0; }
/************************* * prolog_init *************************/ PROLOG_API int prolog_init(char *argv0, int lsize, int gsize, int tsize, int asize, char *bootfile) { char **argv; int argc, status; (void)argv0; if (initialized) return EBUSY; /* * Notes: * * PL_initialise wants to know the path to the binary that has libpl.a * linked into. It tries to load the binary as a prolog resource file. * If this fails it will practically skip parsing most of the command * line, including our options to silence output and limit the size of * the various stacks. * * In our case, libpl.a is linked to libprolog.so and not to the main * binary. Hence we first need to find the path to libprolog.so and then * pass this in as argv[0] to PL_initialise. Ugly, I know... but necessary * unless we link statically. * * * Notes #2: * * This is unarguably a linux-specific hack. An alternative would be * a GLIBC-specific hack using dl_iterate_phdr(3) to iterate directly * through the list of shared objects loaded into us. This would have * the benefit of not needing to open and parse /proc entries. * * Notes #3: * * Stand-alone precompiled prolog files include a copy of the interpreter * itself. Using one could be an alternative to avoid this problem * altogether. */ #if 0 setenv("SWI_HOME_DIR", PROLOG_HOME, TRUE); /* hmm... is this needed ? */ #endif snprintf(lstack, sizeof(lstack), "-L%dk", lsize ?: 16); snprintf(gstack, sizeof(gstack), "-G%dk", gsize ?: 16); snprintf(tstack, sizeof(tstack), "-T%dk", tsize ?: 16); snprintf(astack, sizeof(astack), "-A%dk", asize ?: 16); if (bootfile != NULL) argv = pl_argv; else argv = pl_argv + 2; /* skip { "-x", bootfile } */ argv[argc=0] = shlib_path(LIBPROLOG_SO, libprolog_so, sizeof(libprolog_so)); if (bootfile != NULL) { pl_argv[++argc] = "-x"; /* must be argv[1] */ pl_argv[++argc] = bootfile; /* and argv[2] */ } argc += NUM_FIXED_ARGS; pl_argv[++argc] = lstack; pl_argv[++argc] = gstack; pl_argv[++argc] = tstack; pl_argv[++argc] = astack; libprolog_clear_errors(); if ((status = libprolog_trace_init()) != 0) return status; if ((status = register_predicates()) != 0) return status; if (!PL_initialise(argc + 1, argv)) { PL_cleanup(0); return EINVAL; } /* libprolog.pl assumed to be part of boot file, otherwise load it */ if (bootfile == NULL) { if (!libprolog_load_file(libprolog_pl, FALSE)) { PL_cleanup(0); return EINVAL; } } initialized = TRUE; return status; }