small cleanups

This commit is contained in:
Vítor Santos Costa 2016-01-31 10:21:50 +00:00
parent 5c1c9a8570
commit 4ff7bdd340

View File

@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "Yap.h" #include "Yap.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "YapInterface.h"
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -28,8 +29,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */ #ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#undef HAVE_UNISTD_H #undef HAVE_UNISTD_H
#endif #endif
#endif #endif
@ -44,78 +45,77 @@
#include <direct.h> #include <direct.h>
#endif #endif
void YAP_SetOutputMessage(void);
int YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap);
#if (DefTrailSpace < MinTrailSpace) #if (DefTrailSpace < MinTrailSpace)
#undef DefTrailSpace #undef DefTrailSpace
#define DefTrailSpace MinTrailSpace #define DefTrailSpace MinTrailSpace
#endif #endif
#if (DefStackSpace < MinStackSpace) #if (DefStackSpace < MinStackSpace)
#undef DefStackSpace #undef DefStackSpace
#define DefStackSpace MinStackSpace #define DefStackSpace MinStackSpace
#endif #endif
#if (DefHeapSpace < MinHeapSpace) #if (DefHeapSpace < MinHeapSpace)
#undef DefHeapSpace #undef DefHeapSpace
#define DefHeapSpace MinHeapSpace #define DefHeapSpace MinHeapSpace
#endif #endif
#define DEFAULT_NUMBERWORKERS 1 #define DEFAULT_NUMBERWORKERS 1
#define DEFAULT_SCHEDULERLOOP 10 #define DEFAULT_SCHEDULERLOOP 10
#define DEFAULT_DELAYEDRELEASELOAD 3 #define DEFAULT_DELAYEDRELEASELOAD 3
static void static void print_usage(void) {
print_usage(void) fprintf(stderr, "\n[ Valid switches for command line arguments: ]\n");
{ fprintf(stderr, " -? Shows this screen\n");
fprintf(stderr,"\n[ Valid switches for command line arguments: ]\n"); fprintf(stderr, " -b Boot file \n");
fprintf(stderr," -? Shows this screen\n"); fprintf(stderr, " -dump-runtime-variables\n");
fprintf(stderr," -b Boot file \n"); fprintf(stderr, " -f initialization file or \"none\"\n");
fprintf(stderr," -dump-runtime-variables\n"); fprintf(stderr, " -g Run Goal Before Top-Level \n");
fprintf(stderr," -f initialization file or \"none\"\n"); fprintf(stderr, " -z Run Goal Before Top-Level \n");
fprintf(stderr," -g Run Goal Before Top-Level \n"); fprintf(stderr, " -q start with informational messages off\n");
fprintf(stderr," -z Run Goal Before Top-Level \n"); fprintf(stderr, " -l load Prolog file\n");
fprintf(stderr," -q start with informational messages off\n"); fprintf(stderr, " -L run Prolog file and exit\n");
fprintf(stderr," -l load Prolog file\n"); fprintf(stderr, " -p extra path for file-search-path\n");
fprintf(stderr," -L run Prolog file and exit\n"); fprintf(stderr, " -hSize Heap area in Kbytes (default: %d, minimum: %d)\n",
fprintf(stderr," -p extra path for file-search-path\n"); DefHeapSpace, MinHeapSpace);
fprintf(stderr," -hSize Heap area in Kbytes (default: %d, minimum: %d)\n", fprintf(stderr,
DefHeapSpace, MinHeapSpace); " -sSize Stack area in Kbytes (default: %d, minimum: %d)\n",
fprintf(stderr," -sSize Stack area in Kbytes (default: %d, minimum: %d)\n", DefStackSpace, MinStackSpace);
DefStackSpace, MinStackSpace); fprintf(stderr,
fprintf(stderr," -tSize Trail area in Kbytes (default: %d, minimum: %d)\n", " -tSize Trail area in Kbytes (default: %d, minimum: %d)\n",
DefTrailSpace, MinTrailSpace); DefTrailSpace, MinTrailSpace);
fprintf(stderr," -GSize Max Area for Global Stack\n"); fprintf(stderr, " -GSize Max Area for Global Stack\n");
fprintf(stderr," -LSize Max Area for Local Stack (number must follow L)\n"); fprintf(stderr,
fprintf(stderr," -TSize Max Area for Trail (number must follow L)\n"); " -LSize Max Area for Local Stack (number must follow L)\n");
fprintf(stderr," -nosignals disable signal handling from Prolog\n"); fprintf(stderr, " -TSize Max Area for Trail (number must follow L)\n");
fprintf(stderr,"\n[Execution Modes]\n"); fprintf(stderr, " -nosignals disable signal handling from Prolog\n");
fprintf(stderr," -J0 Interpreted mode (default)\n"); fprintf(stderr, "\n[Execution Modes]\n");
fprintf(stderr," -J1 Mixed mode only for user predicates\n"); fprintf(stderr, " -J0 Interpreted mode (default)\n");
fprintf(stderr," -J2 Mixed mode for all predicates\n"); fprintf(stderr, " -J1 Mixed mode only for user predicates\n");
fprintf(stderr," -J3 Compile all user predicates\n"); fprintf(stderr, " -J2 Mixed mode for all predicates\n");
fprintf(stderr," -J4 Compile all predicates\n"); fprintf(stderr, " -J3 Compile all user predicates\n");
fprintf(stderr, " -J4 Compile all predicates\n");
#ifdef TABLING #ifdef TABLING
fprintf(stderr," -ts Maximum table space area in Mbytes (default: unlimited)\n"); fprintf(stderr,
" -ts Maximum table space area in Mbytes (default: unlimited)\n");
#endif /* TABLING */ #endif /* TABLING */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS) #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
fprintf(stderr," -w Number of workers (default: %d)\n", defined(YAPOR_THREADS)
DEFAULT_NUMBERWORKERS); fprintf(stderr, " -w Number of workers (default: %d)\n",
fprintf(stderr," -sl Loop scheduler executions before look for hiden shared work (default: %d)\n", DEFAULT_NUMBERWORKERS);
fprintf(stderr, " -sl Loop scheduler executions before look for hiden "
"shared work (default: %d)\n",
DEFAULT_SCHEDULERLOOP); DEFAULT_SCHEDULERLOOP);
fprintf(stderr," -d Value of delayed release of load (default: %d)\n", fprintf(stderr, " -d Value of delayed release of load (default: %d)\n",
DEFAULT_DELAYEDRELEASELOAD); DEFAULT_DELAYEDRELEASELOAD);
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */ #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */
/* nf: Preprocessor */ /* nf: Preprocessor */
/* fprintf(stderr," -DVar=Name Persistent definition\n"); */ /* fprintf(stderr," -DVar=Name Persistent definition\n"); */
fprintf(stderr,"\n"); fprintf(stderr, "\n");
} }
static int static int myisblank(int c) {
myisblank(int c)
{
switch (c) { switch (c) {
case ' ': case ' ':
case '\t': case '\t':
@ -127,47 +127,34 @@ myisblank(int c)
} }
} }
static char * static char *add_end_dot(char arg[]) {
add_end_dot(char arg[])
{
int sz = strlen(arg), i; int sz = strlen(arg), i;
i = sz; i = sz;
while (i && myisblank(arg[--i])); while (i && myisblank(arg[--i]))
;
if (i && arg[i] != ',') { if (i && arg[i] != ',') {
char *p = (char *)malloc(sz+2); char *p = (char *)malloc(sz + 2);
if (!p) if (!p)
return NULL; return NULL;
strncpy(p,arg,sz); strncpy(p, arg, sz);
p[sz] = '.'; p[sz] = '.';
p[sz+1] = '\0'; p[sz + 1] = '\0';
return p; return p;
} }
return arg; return arg;
} }
static int static int dump_runtime_variables(void) {
dump_runtime_variables(void) fprintf(stdout, "CC=\"%s\"\n", C_CC);
{ fprintf(stdout, "YAP_ROOTDIR=\"%s\"\n", YAP_ROOTDIR);
fprintf(stdout,"CC=\"%s\"\n",C_CC); fprintf(stdout, "YAP_LIBS=\"%s\"\n", C_LIBS);
fprintf(stdout,"YAP_ROOTDIR=\"%s\"\n",YAP_ROOTDIR); fprintf(stdout, "YAP_SHLIB_SUFFIX=\"%s\"\n", SO_EXT);
fprintf(stdout,"YAP_LIBS=\"%s\"\n",C_LIBS); fprintf(stdout, "YAP_VERSION=%s\n", YAP_NUMERIC_VERSION);
fprintf(stdout,"YAP_SHLIB_SUFFIX=\"%s\"\n",SO_EXT);
fprintf(stdout,"YAP_VERSION=%s\n",YAP_NUMERIC_VERSION);
exit(0); exit(0);
return 1; return 1;
} }
/* X_API int YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap) {
* proccess command line arguments: valid switches are: -b boot -s
* stack area size (K) -h heap area size -a aux stack size -e
* emacs_mode -m -DVar=Value reserved memory for alloc IF DEBUG -p if you
* want to check out startup IF MAC -mpw if we are using the mpw
* shell
*/
int
YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
{
char *p; char *p;
int BootMode = YAP_BOOT_FROM_SAVED_CODE; int BootMode = YAP_BOOT_FROM_SAVED_CODE;
unsigned long int *ssize; unsigned long int *ssize;
@ -204,359 +191,372 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
iap->ErrorCause = NULL; iap->ErrorCause = NULL;
iap->QuietMode = FALSE; iap->QuietMode = FALSE;
while (--argc > 0) while (--argc > 0) {
{ p = *++argv;
p = *++argv; if (*p == '-')
if (*p == '-') switch (*++p) {
switch (*++p) case 'b':
{ BootMode = YAP_BOOT_FROM_PROLOG;
case 'b': iap->YapPrologBootFile = *++argv;
BootMode = YAP_BOOT_FROM_PROLOG; argc--;
iap->YapPrologBootFile = *++argv; break;
argc--; case '?':
break; print_usage();
case '?': exit(EXIT_SUCCESS);
print_usage(); case 'q':
exit(EXIT_SUCCESS); iap->QuietMode = TRUE;
case 'q': break;
iap->QuietMode = TRUE; #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
break; defined(YAPOR_THREADS)
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS) case 'w':
case 'w': ssize = &(iap->NumberWorkers);
ssize = &(iap->NumberWorkers); goto GetSize;
goto GetSize; case 'd':
case 'd': if (!strcmp("dump-runtime-variables", p))
if (!strcmp("dump-runtime-variables",p)) return dump_runtime_variables();
return dump_runtime_variables(); ssize = &(iap->DelayedReleaseLoad);
ssize = &(iap->DelayedReleaseLoad); goto GetSize;
goto GetSize;
#else #else
case 'd': case 'd':
if (!strcmp("dump-runtime-variables",p)) if (!strcmp("dump-runtime-variables", p))
return dump_runtime_variables(); return dump_runtime_variables();
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */ #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */
case 'F': case 'F':
/* just ignore for now */ /* just ignore for now */
argc--; argc--;
argv++; argv++;
break; break;
case 'f': case 'f':
iap->FastBoot = TRUE; iap->FastBoot = TRUE;
if (argc > 1 && argv[1][0] != '-') { if (argc > 1 && argv[1][0] != '-') {
argc--; argc--;
argv++; argv++;
if (strcmp(*argv,"none")) { if (strcmp(*argv, "none")) {
iap->YapPrologRCFile = *argv; iap->YapPrologRCFile = *argv;
} }
break; break;
} }
break; break;
// execution mode // execution mode
case 'J': case 'J':
switch (p[1]) { switch (p[1]) {
case '0': case '0':
iap->ExecutionMode = YAPC_INTERPRETED; iap->ExecutionMode = YAPC_INTERPRETED;
break; break;
case '1': case '1':
iap->ExecutionMode = YAPC_MIXED_MODE_USER; iap->ExecutionMode = YAPC_MIXED_MODE_USER;
break; break;
case '2': case '2':
iap->ExecutionMode = YAPC_MIXED_MODE_ALL; iap->ExecutionMode = YAPC_MIXED_MODE_ALL;
break; break;
case '3': case '3':
iap->ExecutionMode = YAPC_COMPILE_USER; iap->ExecutionMode = YAPC_COMPILE_USER;
break; break;
case '4': case '4':
iap->ExecutionMode = YAPC_COMPILE_ALL; iap->ExecutionMode = YAPC_COMPILE_ALL;
break; break;
default: default:
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c%c ]\n", *p, p[1]); fprintf(stderr, "[ YAP unrecoverable error: unknown switch -%c%c ]\n",
exit(EXIT_FAILURE); *p, p[1]);
} exit(EXIT_FAILURE);
p++; }
break; p++;
case 'G': break;
ssize = &(iap->MaxGlobalSize); case 'G':
goto GetSize; ssize = &(iap->MaxGlobalSize);
break; goto GetSize;
case 's': break;
case 'S': case 's':
ssize = &(iap->StackSize); case 'S':
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS) ssize = &(iap->StackSize);
if (p[1] == 'l') { #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
p++; defined(YAPOR_THREADS)
ssize = &(iap->SchedulerLoop); if (p[1] == 'l') {
} p++;
ssize = &(iap->SchedulerLoop);
}
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */ #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */
goto GetSize; goto GetSize;
case 'a': case 'a':
case 'A': case 'A':
ssize = &(iap->AttsSize); ssize = &(iap->AttsSize);
goto GetSize; goto GetSize;
case 'T': case 'T':
ssize = &(iap->MaxTrailSize); ssize = &(iap->MaxTrailSize);
goto get_trail_size; goto get_trail_size;
case 't': case 't':
ssize = &(iap->TrailSize); ssize = &(iap->TrailSize);
#ifdef TABLING #ifdef TABLING
if (p[1] == 's') { if (p[1] == 's') {
p++; p++;
ssize = &(iap->MaxTableSpaceSize); ssize = &(iap->MaxTableSpaceSize);
} }
#endif /* TABLING */ #endif /* TABLING */
get_trail_size: get_trail_size:
if (*++p == '\0') if (*++p == '\0') {
{ if (argc > 1)
if (argc > 1) --argc, p = *++argv;
--argc, p = *++argv; else {
else fprintf(stderr,
{ "[ YAP unrecoverable error: missing size in flag %s ]",
fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]); argv[0]);
print_usage(); print_usage();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
{ {
unsigned long int i = 0, ch; unsigned long int i = 0, ch;
while ((ch = *p++) >= '0' && ch <= '9') while ((ch = *p++) >= '0' && ch <= '9')
i = i * 10 + ch - '0'; i = i * 10 + ch - '0';
switch(ch) { switch (ch) {
case 'M': case 'M':
case 'm': case 'm':
i *= 1024; i *= 1024;
ch = *p++; ch = *p++;
break;
case 'g':
i *= 1024*1024;
ch = *p++;
break;
case 'k':
case 'K':
ch = *p++;
break;
}
if (ch) {
iap->YapPrologTopLevelGoal = add_end_dot(*argv);
} else {
*ssize = i;
}
}
break;
case 'h':
case 'H':
ssize = &(iap->HeapSize);
GetSize:
if (*++p == '\0')
{
if (argc > 1)
--argc, p = *++argv;
else
{
fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]);
print_usage();
exit(EXIT_FAILURE);
}
}
{
unsigned long int i = 0, ch;
while ((ch = *p++) >= '0' && ch <= '9')
i = i * 10 + ch - '0';
switch(ch) {
case 'M':
case 'm':
i *= 1024;
ch = *p++;
break;
case 'g':
case 'G':
i *= 1024*1024;
ch = *p++;
break;
case 'k':
case 'K':
ch = *p++;
break;
}
if (ch)
{
fprintf(stderr,"[ YAP unrecoverable error: illegal size specification %s ]", argv[-1]);
Yap_exit(1);
}
*ssize = i;
}
break;
#ifdef DEBUG
case 'P':
YAP_SetOutputMessage();
if (p[1] != '\0') {
while (p[1] != '\0') {
int ch = p[1];
if (ch >= 'A' && ch <= 'Z')
ch += ('a'-'A');
if (ch >= 'a' && ch <= 'z')
GLOBAL_Option[ch - 96] = 1;
}
}
break;
#endif
case 'L':
if (p[1] && p[1] >= '0' && p[1] <= '9') /* hack to emulate SWI's L local option */
{
ssize = &(iap->MaxStackSize);
goto GetSize;
}
iap->QuietMode = TRUE;
iap->HaltAfterConsult = TRUE;
case 'l':
p++;
if (!*++argv) {
fprintf(stderr,"%% YAP unrecoverable error: missing load file name\n");
exit(1);
} else if (!strcmp("--",*argv)) {
/* shell script, the next entry should be the file itself */
iap->YapPrologRCFile = argv[1];
argc = 1;
break;
} else {
iap->YapPrologRCFile = *argv;
argc--;
}
if (*p) {
/* we have something, usually, of the form:
-L --
FileName
ExtraArgs
*/
/* being called from a script */
while (*p && (*p == ' ' || *p == '\t'))
p++;
if (p[0] == '-' && p[1] == '-') {
/* ignore what is next */
argc = 1;
}
}
break;
/* run goal before top-level */
case 'g':
if ((*argv)[0] == '\0')
iap->YapPrologGoal = *argv;
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing initialization goal for option 'g' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologGoal = *argv;
}
break;
/* run goal as top-level */
case 'z':
if ((*argv)[0] == '\0')
iap->YapPrologTopLevelGoal = *argv;
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing goal for option 'z' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologTopLevelGoal = add_end_dot(*argv);
}
break;
case 'n':
if (!strcmp("nosignals", p)) {
iap->PrologShouldHandleInterrupts = FALSE;
break;
}
break;
case '-':
if (!strcmp("-nosignals", p)) {
iap->PrologShouldHandleInterrupts = FALSE;
break;
} else if (!strncmp("-home=",p,strlen("-home="))) {
GLOBAL_Home = p+strlen("-home=");
} else if (!strncmp("-cwd=",p,strlen("-cwd="))) {
#if __WINDOWS__
if (_chdir( p+strlen("-cwd=") ) < 0) {
#else
if (chdir( p+strlen("-cwd=") ) < 0) {
#endif
fprintf(stderr," [ YAP unrecoverable error in setting cwd: %s ]\n", strerror(errno));
}
} else if (!strncmp("-stack=",p,strlen("-stack="))) {
ssize = &(iap->StackSize);
p+=strlen("-stack=");
goto GetSize;
} else if (!strncmp("-trail=",p,strlen("-trail="))) {
ssize = &(iap->TrailSize);
p+=strlen("-trail=");
goto GetSize;
} else if (!strncmp("-heap=",p,strlen("-heap="))) {
ssize = &(iap->HeapSize);
p+=strlen("-heap=");
goto GetSize;
} else if (!strncmp("-goal=",p,strlen("-goal="))) {
iap->YapPrologGoal = p+strlen("-goal=");
} else if (!strncmp("-top-level=",p,strlen("-top-level="))) {
iap->YapPrologTopLevelGoal = p+strlen("-top-level=");
} else if (!strncmp("-table=",p,strlen("-table="))) {
ssize = &(iap->MaxTableSpaceSize);
p +=strlen( "-table=");
goto GetSize;
} else if (!strncmp("-",p,strlen("-="))) {
ssize = &(iap->MaxTableSpaceSize);
p +=strlen( "-table=");
/* skip remaining arguments */
argc = 1;
}
break; break;
case 'p': case 'g':
if ((*argv)[0] == '\0') i *= 1024 * 1024;
iap->YapPrologAddPath = *argv; ch = *p++;
else { break;
argc--; case 'k':
if (argc == 0) { case 'K':
fprintf(stderr," [ YAP unrecoverable error: missing paths for option 'p' ]\n"); ch = *p++;
exit(EXIT_FAILURE); break;
} }
argv++; if (ch) {
iap->YapPrologAddPath = *argv; iap->YapPrologTopLevelGoal = add_end_dot(*argv);
} } else {
break; *ssize = i;
/* nf: Begin preprocessor code */ }
case 'D': }
{ break;
char *var, *value; case 'h':
++p; case 'H':
var = p; ssize = &(iap->HeapSize);
if (var == NULL || *var=='\0') GetSize:
break; if (*++p == '\0') {
while(*p!='=' && *p!='\0') ++p; if (argc > 1)
if ( *p=='\0' ) break; --argc, p = *++argv;
*p='\0'; else {
++p; fprintf(stderr,
value=p; "[ YAP unrecoverable error: missing size in flag %s ]",
if ( *value == '\0' ) break; argv[0]);
if (iap->def_c == YAP_MAX_YPP_DEFS) print_usage();
break; exit(EXIT_FAILURE);
iap->def_var[iap->def_c]=var; }
iap->def_value[iap->def_c]=value; }
++(iap->def_c); {
break; unsigned long int i = 0, ch;
} while ((ch = *p++) >= '0' && ch <= '9')
/* End preprocessor code */ i = i * 10 + ch - '0';
default: switch (ch) {
{ case 'M':
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c ]\n", *p); case 'm':
print_usage(); i *= 1024;
exit(EXIT_FAILURE); ch = *p++;
} break;
} case 'g':
else { case 'G':
iap->SavedState = p; i *= 1024 * 1024;
ch = *p++;
break;
case 'k':
case 'K':
ch = *p++;
break;
}
if (ch) {
fprintf(
stderr,
"[ YAP unrecoverable error: illegal size specification %s ]",
argv[-1]);
Yap_exit(1);
}
*ssize = i;
}
break;
#ifdef DEBUG
case 'P':
YAP_SetOutputMessage();
if (p[1] != '\0') {
while (p[1] != '\0') {
int ch = p[1];
if (ch >= 'A' && ch <= 'Z')
ch += ('a' - 'A');
if (ch >= 'a' && ch <= 'z')
GLOBAL_Option[ch - 96] = 1;
}
}
break;
#endif
case 'L':
if (p[1] && p[1] >= '0' &&
p[1] <= '9') /* hack to emulate SWI's L local option */
{
ssize = &(iap->MaxStackSize);
goto GetSize;
}
iap->QuietMode = TRUE;
iap->HaltAfterConsult = TRUE;
case 'l':
p++;
if (!*++argv) {
fprintf(stderr,
"%% YAP unrecoverable error: missing load file name\n");
exit(1);
} else if (!strcmp("--", *argv)) {
/* shell script, the next entry should be the file itself */
iap->YapPrologRCFile = argv[1];
argc = 1;
break;
} else {
iap->YapPrologRCFile = *argv;
argc--;
}
if (*p) {
/* we have something, usually, of the form:
-L --
FileName
ExtraArgs
*/
/* being called from a script */
while (*p && (*p == ' ' || *p == '\t'))
p++;
if (p[0] == '-' && p[1] == '-') {
/* ignore what is next */
argc = 1;
}
}
break;
/* run goal before top-level */
case 'g':
if ((*argv)[0] == '\0')
iap->YapPrologGoal = *argv;
else {
argc--;
if (argc == 0) {
fprintf(stderr, " [ YAP unrecoverable error: missing "
"initialization goal for option 'g' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologGoal = *argv;
}
break;
/* run goal as top-level */
case 'z':
if ((*argv)[0] == '\0')
iap->YapPrologTopLevelGoal = *argv;
else {
argc--;
if (argc == 0) {
fprintf(
stderr,
" [ YAP unrecoverable error: missing goal for option 'z' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologTopLevelGoal = add_end_dot(*argv);
}
break;
case 'n':
if (!strcmp("nosignals", p)) {
iap->PrologShouldHandleInterrupts = FALSE;
break;
}
break;
case '-':
if (!strcmp("-nosignals", p)) {
iap->PrologShouldHandleInterrupts = FALSE;
break;
} else if (!strncmp("-home=", p, strlen("-home="))) {
GLOBAL_Home = p + strlen("-home=");
} else if (!strncmp("-cwd=", p, strlen("-cwd="))) {
#if __WINDOWS__
if (_chdir(p + strlen("-cwd=")) < 0) {
#else
if (chdir(p + strlen("-cwd=")) < 0) {
#endif
fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n",
strerror(errno));
}
} else if (!strncmp("-stack=", p, strlen("-stack="))) {
ssize = &(iap->StackSize);
p += strlen("-stack=");
goto GetSize;
} else if (!strncmp("-trail=", p, strlen("-trail="))) {
ssize = &(iap->TrailSize);
p += strlen("-trail=");
goto GetSize;
} else if (!strncmp("-heap=", p, strlen("-heap="))) {
ssize = &(iap->HeapSize);
p += strlen("-heap=");
goto GetSize;
} else if (!strncmp("-goal=", p, strlen("-goal="))) {
iap->YapPrologGoal = p + strlen("-goal=");
} else if (!strncmp("-top-level=", p, strlen("-top-level="))) {
iap->YapPrologTopLevelGoal = p + strlen("-top-level=");
} else if (!strncmp("-table=", p, strlen("-table="))) {
ssize = &(iap->MaxTableSpaceSize);
p += strlen("-table=");
goto GetSize;
} else if (!strncmp("-", p, strlen("-="))) {
ssize = &(iap->MaxTableSpaceSize);
p += strlen("-table=");
/* skip remaining arguments */
argc = 1;
}
break;
case 'p':
if ((*argv)[0] == '\0')
iap->YapPrologAddPath = *argv;
else {
argc--;
if (argc == 0) {
fprintf(
stderr,
" [ YAP unrecoverable error: missing paths for option 'p' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologAddPath = *argv;
}
break;
/* nf: Begin preprocessor code */
case 'D': {
char *var, *value;
++p;
var = p;
if (var == NULL || *var == '\0')
break;
while (*p != '=' && *p != '\0')
++p;
if (*p == '\0')
break;
*p = '\0';
++p;
value = p;
if (*value == '\0')
break;
if (iap->def_c == YAP_MAX_YPP_DEFS)
break;
iap->def_var[iap->def_c] = var;
iap->def_value[iap->def_c] = value;
++(iap->def_c);
break;
} }
/* End preprocessor code */
default: {
fprintf(stderr, "[ YAP unrecoverable error: unknown switch -%c ]\n",
*p);
print_usage();
exit(EXIT_FAILURE);
}
}
else {
iap->SavedState = p;
} }
//___androidlog_print(ANDROID_LOG_INFO, "YAP ", "boot mode %d", BootMode); }
//___androidlog_print(ANDROID_LOG_INFO, "YAP ", "boot mode %d", BootMode);
return BootMode; return BootMode;
} }