cleanup restore: use same code for check_saved_state and for actual
restore, tell exact path of file, try several files even if first one is corrupt. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@664 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
6d8c592775
commit
8ac94c1d88
@ -847,13 +847,14 @@ X_API Int
|
||||
YAP_Init(YAP_init_args *yap_init)
|
||||
{
|
||||
int restore_result;
|
||||
int Trail = 0, Stack = 0, Heap = 0;
|
||||
CELL Trail = 0, Stack = 0, Heap = 0;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
yap_args = yap_init->Argv;
|
||||
yap_argc = yap_init->Argc;
|
||||
if (yap_init->SavedState != NULL) {
|
||||
if (SavedInfo (yap_init->SavedState, &Trail, &Stack, &Heap, yap_init->YapLibDir) != 1) {
|
||||
if (yap_init->SavedState != NULL ||
|
||||
yap_init->YapPrologBootFile == NULL) {
|
||||
if (SavedInfo (yap_init->SavedState, yap_init->YapLibDir, &Trail, &Stack, &Heap) != 1) {
|
||||
return(YAP_BOOT_FROM_SAVED_ERROR);
|
||||
}
|
||||
}
|
||||
@ -889,15 +890,16 @@ YAP_Init(YAP_init_args *yap_init)
|
||||
InitMPE ();
|
||||
#endif
|
||||
|
||||
if (yap_init->YapPrologBootFile != NULL) {
|
||||
if (yap_init->YapPrologRCFile != NULL) {
|
||||
/*
|
||||
This must be done before restore, otherwise
|
||||
restore will print out messages ....
|
||||
*/
|
||||
yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult;
|
||||
}
|
||||
if (yap_init->SavedState != NULL) {
|
||||
restore_result = Restore(yap_init->SavedState);
|
||||
if (yap_init->SavedState != NULL ||
|
||||
yap_init->YapPrologBootFile == NULL) {
|
||||
restore_result = Restore(yap_init->SavedState, yap_init->YapLibDir);
|
||||
} else {
|
||||
restore_result = FAIL_RESTORE;
|
||||
}
|
||||
@ -927,7 +929,7 @@ YAP_Init(YAP_init_args *yap_init)
|
||||
#endif /* YAPOR || TABLING */
|
||||
RECOVER_MACHINE_REGS();
|
||||
|
||||
if (yap_init->YapPrologBootFile != NULL) {
|
||||
if (yap_init->YapPrologRCFile != NULL) {
|
||||
PutValue(FullLookupAtom("$consult_on_boot"), MkAtomTerm(LookupAtom(yap_init->YapPrologBootFile)));
|
||||
/*
|
||||
This must be done again after restore, as yap_flags
|
||||
@ -935,8 +937,8 @@ YAP_Init(YAP_init_args *yap_init)
|
||||
*/
|
||||
yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult;
|
||||
}
|
||||
if (yap_init->SavedState != NULL) {
|
||||
|
||||
if (yap_init->SavedState != NULL ||
|
||||
yap_init->YapPrologBootFile == NULL) {
|
||||
if (restore_result == FAIL_RESTORE)
|
||||
return(YAP_BOOT_FROM_SAVED_ERROR);
|
||||
if (restore_result == DO_ONLY_CODE) {
|
||||
@ -959,6 +961,7 @@ YAP_FastInit(char saved_state[])
|
||||
init_args.TrailSize = 0;
|
||||
init_args.YapLibDir = NULL;
|
||||
init_args.YapPrologBootFile = NULL;
|
||||
init_args.YapPrologRCFile = NULL;
|
||||
init_args.HaltAfterConsult = FALSE;
|
||||
init_args.FastBoot = FALSE;
|
||||
init_args.NumberWorkers = 1;
|
||||
|
29
C/errors.c
29
C/errors.c
@ -311,18 +311,22 @@ dump_stack(void)
|
||||
} else if (HeapTop > (ADDR)GlobalBase) {
|
||||
fprintf(stderr,"[ YAP ERROR: Code Space Collided against Global ]\n");
|
||||
} else {
|
||||
fprintf(stderr," [ Goals with alternatives open:\n");
|
||||
while (b_ptr != NULL) {
|
||||
cl_position(b_ptr->cp_ap);
|
||||
b_ptr = b_ptr->cp_b;
|
||||
if (b_ptr != NULL) {
|
||||
fprintf(stderr," [ Goals with alternatives open:\n");
|
||||
while (b_ptr != NULL) {
|
||||
cl_position(b_ptr->cp_ap);
|
||||
b_ptr = b_ptr->cp_b;
|
||||
}
|
||||
fprintf(stderr," ]\n");
|
||||
}
|
||||
fprintf(stderr," ]\n");
|
||||
fprintf(stderr," [ Goals left to continue:\n");
|
||||
while (env_ptr != NULL) {
|
||||
cl_position((yamop *)(env_ptr[E_CP]));
|
||||
env_ptr = (CELL *)(env_ptr[E_E]);
|
||||
if (env_ptr != NULL) {
|
||||
fprintf(stderr," [ Goals left to continue:\n");
|
||||
while (env_ptr != NULL) {
|
||||
cl_position((yamop *)(env_ptr[E_CP]));
|
||||
env_ptr = (CELL *)(env_ptr[E_E]);
|
||||
}
|
||||
fprintf(stderr," ]\n");
|
||||
}
|
||||
fprintf(stderr," ]\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,7 +334,8 @@ dump_stack(void)
|
||||
static void
|
||||
error_exit_yap (int value)
|
||||
{
|
||||
dump_stack();
|
||||
if (!PrologMode & BootMode)
|
||||
dump_stack();
|
||||
exit_yap(value);
|
||||
}
|
||||
|
||||
@ -387,7 +392,7 @@ Error (yap_error_number type, Term where, char *format,...)
|
||||
exit(1);
|
||||
}
|
||||
/* must do this here */
|
||||
if (type == FATAL_ERROR) {
|
||||
if (type == FATAL_ERROR || HeapBase == NULL) {
|
||||
va_start (ap, format);
|
||||
/* now build the error string */
|
||||
if (format != NULL) {
|
||||
|
350
C/save.c
350
C/save.c
@ -54,7 +54,7 @@ static char SccsId[] = "@(#)save.c 1.3 3/15/90";
|
||||
|
||||
/********* hack for accesing several kinds of terms. Should be cleaned **/
|
||||
|
||||
extern char StartUpFile[];
|
||||
static char StartUpFile[] = "startup";
|
||||
|
||||
static char end_msg[256] ="*** End of YAP saved state *****";
|
||||
|
||||
@ -97,7 +97,7 @@ STATIC_PROTO(void save_crc, (void));
|
||||
STATIC_PROTO(Int do_save, (int));
|
||||
STATIC_PROTO(Int p_save, (void));
|
||||
STATIC_PROTO(Int p_save_program, (void));
|
||||
STATIC_PROTO(int check_header, (void));
|
||||
STATIC_PROTO(int check_header, (CELL *, CELL *, CELL *, CELL *));
|
||||
STATIC_PROTO(void get_heap_info, (void));
|
||||
STATIC_PROTO(void get_regs, (int));
|
||||
STATIC_PROTO(void get_insts, (OPCODE []));
|
||||
@ -121,7 +121,7 @@ STATIC_PROTO(void restore_heap, (void));
|
||||
STATIC_PROTO(void ShowAtoms, (void));
|
||||
STATIC_PROTO(void ShowEntries, (PropEntry *));
|
||||
#endif
|
||||
STATIC_PROTO(int OpenRestore, (char *));
|
||||
STATIC_PROTO(int OpenRestore, (char *, char *, CELL *, CELL *, CELL *, CELL *));
|
||||
STATIC_PROTO(void CloseRestore, (void));
|
||||
STATIC_PROTO(int check_opcodes, (OPCODE []));
|
||||
STATIC_PROTO(void RestoreHeap, (OPCODE [], int));
|
||||
@ -276,6 +276,8 @@ open_file(char *ss, int flag)
|
||||
static void
|
||||
close_file(void)
|
||||
{
|
||||
if (splfild == 0)
|
||||
return;
|
||||
close(splfild);
|
||||
splfild = 0;
|
||||
}
|
||||
@ -284,32 +286,49 @@ close_file(void)
|
||||
static void
|
||||
putout(CELL l)
|
||||
{
|
||||
mywrite(splfild, (char *) &l, sizeof(CELL));
|
||||
mywrite(splfild, (char *) &l, sizeof(CELL));
|
||||
}
|
||||
|
||||
/* stores a pointer to a cell in a file */
|
||||
static void
|
||||
putcellptr(CELL *l)
|
||||
{
|
||||
mywrite(splfild, (char *) &l, sizeof(CELLPOINTER));
|
||||
mywrite(splfild, (char *) &l, sizeof(CELLPOINTER));
|
||||
}
|
||||
|
||||
/* gets a cell from a file */
|
||||
static CELL
|
||||
get_cell(void)
|
||||
{
|
||||
CELL l;
|
||||
myread(splfild, (char *) &l, Unsigned(sizeof(CELL)));
|
||||
return (l);
|
||||
CELL l;
|
||||
myread(splfild, (char *) &l, Unsigned(sizeof(CELL)));
|
||||
return (l);
|
||||
}
|
||||
|
||||
/* gets a cell from a file */
|
||||
static CELL
|
||||
get_header_cell(void)
|
||||
{
|
||||
CELL l;
|
||||
int count = 0, n;
|
||||
while (count < sizeof(CELL)) {
|
||||
if ((n = read(splfild, &l, sizeof(CELL)-count)) < 0) {
|
||||
ErrorMessage = "corrupt saved state";
|
||||
return(0L);
|
||||
}
|
||||
count += n;
|
||||
}
|
||||
return(l);
|
||||
}
|
||||
|
||||
/* gets a pointer to cell from a file */
|
||||
static CELL *
|
||||
get_cellptr(void)
|
||||
{
|
||||
CELL *l;
|
||||
myread(splfild, (char *) &l, Unsigned(sizeof(CELLPOINTER)));
|
||||
return (l);
|
||||
CELL *l;
|
||||
|
||||
myread(splfild, (char *) &l, Unsigned(sizeof(CELLPOINTER)));
|
||||
return (l);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -326,6 +345,10 @@ put_info(int info, int mode)
|
||||
putout(Unsigned(info));
|
||||
/* say whether we just saved the heap or everything */
|
||||
putout(mode);
|
||||
/* c-predicates in system */
|
||||
putout(NUMBER_OF_CPREDS);
|
||||
/* comparison predicates in system */
|
||||
putout(NUMBER_OF_CMPFUNCS);
|
||||
/* current state of stacks, to be used by SavedInfo */
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
/* space available in heap area */
|
||||
@ -589,58 +612,110 @@ p_save_program(void)
|
||||
|
||||
/* First check out if we are dealing with a valid file */
|
||||
static int
|
||||
check_header(void)
|
||||
check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
||||
{
|
||||
char pp[80];
|
||||
char msg[256];
|
||||
CELL hp_size, gb_size, lc_size, tr_size, mode;
|
||||
CELL hp_size, gb_size, lc_size, tr_size, mode, c_preds, cmp_funcs;
|
||||
|
||||
/* make sure we always check if there are enough bytes */
|
||||
/* skip the first line */
|
||||
do {
|
||||
myread(splfild, pp, 1);
|
||||
if (read(splfild, pp, 1) < 0) {
|
||||
ErrorMessage = "corrupt saved state";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
} while (pp[0] != 1);
|
||||
/* now check the version */
|
||||
sprintf(msg, "YAPV%s", version_number);
|
||||
myread(splfild, pp, Unsigned(strlen(msg) + 1));
|
||||
{
|
||||
int count = 0, n, to_read = Unsigned(strlen(msg) + 1);
|
||||
while (count < to_read) {
|
||||
if ((n = read(splfild, pp, to_read-count)) < 0) {
|
||||
ErrorMessage = "corrupt saved state";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
count += n;
|
||||
}
|
||||
}
|
||||
if (pp[0] != 'Y' && pp[1] != 'A' && pp[0] != 'P') {
|
||||
ErrorMessage = "corrupt saved state";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
if (strcmp(pp, msg) != 0) {
|
||||
Error(SYSTEM_ERROR,TermNil,"not a saved Prolog state");
|
||||
ErrorMessage = "saved state for different version of YAP";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
/* check info on header */
|
||||
/* ignore info on saved state */
|
||||
get_cell();
|
||||
*info = get_header_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
/* check the restore mode */
|
||||
if ((mode = get_cell()) != DO_EVERYTHING && mode != DO_ONLY_CODE) {
|
||||
Error(SYSTEM_ERROR,TermNil,"corrupted saved state");
|
||||
mode = get_header_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
/* check the number of c-predicates */
|
||||
c_preds = get_header_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
if (HeapBase != NULL && c_preds != NUMBER_OF_CPREDS) {
|
||||
ErrorMessage = "saved state with different built-ins";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
cmp_funcs = get_header_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
if (HeapBase != NULL && cmp_funcs != NUMBER_OF_CMPFUNCS) {
|
||||
ErrorMessage = "saved state with different built-ins";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
if (mode != DO_EVERYTHING && mode != DO_ONLY_CODE) {
|
||||
ErrorMessage = "corrupt saved state";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
/* ignore info on stacks size */
|
||||
get_cell();
|
||||
get_cell();
|
||||
get_cell();
|
||||
*AHeap = get_header_cell();
|
||||
*AStack = get_header_cell();
|
||||
*ATrail = get_header_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
/* now, check whether we got enough enough space to load the
|
||||
saved space */
|
||||
hp_size = get_cell();
|
||||
while (hp_size > Unsigned(AuxTop) - Unsigned(HeapBase)) {
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
while (HeapBase != NULL && hp_size > Unsigned(AuxTop) - Unsigned(HeapBase)) {
|
||||
if(!growheap(FALSE)) {
|
||||
Error(SYSTEM_ERROR,TermNil,ErrorMessage);
|
||||
return(FALSE);
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
}
|
||||
if (mode == DO_EVERYTHING) {
|
||||
if ((lc_size = get_cell())+(gb_size=get_cell()) > Unsigned(LocalBase) - Unsigned(GlobalBase)) {
|
||||
Error(SYSTEM_ERROR,TermNil,"out of stack space, Yap needs %d", lc_size+gb_size);
|
||||
return(FALSE);
|
||||
lc_size = get_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
gb_size=get_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
if (HeapBase != NULL && lc_size+gb_size > Unsigned(LocalBase) - Unsigned(GlobalBase)) {
|
||||
ErrorMessage = "not enough stack space for restore";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
if ((tr_size = get_cell()) > Unsigned(TrailTop) - Unsigned(TrailBase)) {
|
||||
Error(SYSTEM_ERROR,TermNil,"out of trail space, Yap needs %d", tr_size);
|
||||
if (HeapBase != NULL && (tr_size = get_cell()) > Unsigned(TrailTop) - Unsigned(TrailBase)) {
|
||||
ErrorMessage = "not enough trail space for restore";
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
} else {
|
||||
/* skip cell size */
|
||||
get_cell();
|
||||
get_cell();
|
||||
get_cell();
|
||||
get_header_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
get_header_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
get_header_cell();
|
||||
if (ErrorMessage)
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
return(mode);
|
||||
}
|
||||
@ -1225,57 +1300,19 @@ ShowAtoms()
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static int
|
||||
OpenRestore(char *s)
|
||||
{
|
||||
static int
|
||||
commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap) {
|
||||
int mode;
|
||||
|
||||
/* if (strcmp(s, StartUpFile) == 0)
|
||||
YP_fprintf(YP_stderr, "[ YAP version %s ]\n\n", version_number);*/
|
||||
CloseStreams(TRUE);
|
||||
if ((splfild = open_file(s, O_RDONLY)) < 0) {
|
||||
if (!dir_separator(s[0]) && !volume_header(s)) {
|
||||
|
||||
/*
|
||||
we have a relative path for the file, try to do somewhat better
|
||||
using YAPLIBDIR or friends.
|
||||
*/
|
||||
if (Yap_LibDir != NULL) {
|
||||
strncpy(FileNameBuf, Yap_LibDir, YAP_FILENAME_MAX);
|
||||
#if HAVE_GETENV
|
||||
} else {
|
||||
char *yap_env = getenv("YAPLIBDIR");
|
||||
if (yap_env != NULL) {
|
||||
strncpy(FileNameBuf, yap_env, YAP_FILENAME_MAX);
|
||||
#endif
|
||||
} else {
|
||||
strncpy(FileNameBuf, LIB_DIR, YAP_FILENAME_MAX);
|
||||
}
|
||||
#if HAVE_GETENV
|
||||
}
|
||||
#endif
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
strncat(FileNameBuf,"\\", YAP_FILENAME_MAX);
|
||||
#else
|
||||
strncat(FileNameBuf,"/", YAP_FILENAME_MAX);
|
||||
#endif
|
||||
strncat(FileNameBuf,s, YAP_FILENAME_MAX);
|
||||
if ((splfild = open_file(FileNameBuf, O_RDONLY)) < 0) {
|
||||
if (PrologMode != BootMode) {
|
||||
Error(SYSTEM_ERROR,MkAtomTerm(LookupAtom(s)),
|
||||
"save/1, open(%s)", strerror(errno));
|
||||
}
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
} else {
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
}
|
||||
PrologMode = BootMode;
|
||||
if ((mode = check_header()) == FAIL_RESTORE)
|
||||
if ((mode = check_header(Astate,ATrail,AStack,AHeap)) == FAIL_RESTORE)
|
||||
return(FAIL_RESTORE);
|
||||
if (!yap_flags[HALT_AFTER_CONSULT_FLAG]) {
|
||||
YP_fprintf(YP_stderr, "[ Restoring file %s ]\n", s);
|
||||
PrologMode = BootMode;
|
||||
if (HeapBase) {
|
||||
if (!yap_flags[HALT_AFTER_CONSULT_FLAG]) {
|
||||
TrueFileName(s,FileNameBuf2, YAP_FILENAME_MAX);
|
||||
YP_fprintf(YP_stderr, "[ Restoring file %s ]\n", FileNameBuf2);
|
||||
}
|
||||
CloseStreams(TRUE);
|
||||
}
|
||||
#ifdef DEBUG_RESTORE4
|
||||
/*
|
||||
@ -1286,6 +1323,67 @@ OpenRestore(char *s)
|
||||
return(mode);
|
||||
}
|
||||
|
||||
static void
|
||||
cat_file_name(char *s, char *prefix, char *name, unsigned int max_length)
|
||||
{
|
||||
strncpy(s, prefix, max_length);
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
strncat(s,"\\", max_length);
|
||||
#else
|
||||
strncat(s,"/", max_length);
|
||||
#endif
|
||||
strncat(s, name, max_length);
|
||||
}
|
||||
|
||||
static int
|
||||
OpenRestore(char *s, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
||||
{
|
||||
int mode = FAIL_RESTORE;
|
||||
|
||||
ErrorMessage = NULL;
|
||||
if (s == NULL)
|
||||
s = StartUpFile;
|
||||
if (s != NULL && (splfild = open_file(s, O_RDONLY)) > 0) {
|
||||
if ((mode = commit_to_saved_state(s,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE)
|
||||
return(mode);
|
||||
}
|
||||
if (!dir_separator(s[0]) && !volume_header(s)) {
|
||||
/*
|
||||
we have a relative path for the file, try to do somewhat better
|
||||
using YAPLIBDIR or friends.
|
||||
*/
|
||||
if (YapLibDir != NULL) {
|
||||
cat_file_name(FileNameBuf, Yap_LibDir, s, YAP_FILENAME_MAX);
|
||||
if ((splfild = open_file(FileNameBuf, O_RDONLY)) > 0) {
|
||||
if ((mode = commit_to_saved_state(FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE)
|
||||
return(mode);
|
||||
}
|
||||
}
|
||||
#if HAVE_GETENV
|
||||
{
|
||||
char *yap_env = getenv("YAPLIBDIR");
|
||||
if (yap_env != NULL) {
|
||||
cat_file_name(FileNameBuf, yap_env, s, YAP_FILENAME_MAX);
|
||||
if ((splfild = open_file(FileNameBuf, O_RDONLY)) > 0) {
|
||||
if ((mode = commit_to_saved_state(FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE)
|
||||
return(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (LIB_DIR != NULL) {
|
||||
cat_file_name(FileNameBuf, LIB_DIR, s, YAP_FILENAME_MAX);
|
||||
if ((splfild = open_file(FileNameBuf, O_RDONLY)) > 0) {
|
||||
if ((mode = commit_to_saved_state(FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE)
|
||||
return(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Error(SYSTEM_ERROR, TermNil, ErrorMessage);
|
||||
ErrorMessage = NULL;
|
||||
return(FAIL_RESTORE);
|
||||
}
|
||||
|
||||
static void
|
||||
CloseRestore(void)
|
||||
{
|
||||
@ -1341,77 +1439,24 @@ RestoreHeap(OPCODE old_ops[], int functions_moved)
|
||||
* state
|
||||
*/
|
||||
int
|
||||
SavedInfo(char *FileName, int *ATrail, int *AStack, int *AHeap, char *YapLibDir)
|
||||
SavedInfo(char *FileName, char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
||||
{
|
||||
char pp[80];
|
||||
char msg[256];
|
||||
char NameBuf[YAP_FILENAME_MAX];
|
||||
int result, mode;
|
||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||
int mode;
|
||||
|
||||
if ((splfild = open_file(FileName, O_RDONLY)) < 0) {
|
||||
if (!dir_separator(FileName[0]) && !volume_header(FileName)) {
|
||||
|
||||
/* we have a relative path for the file, try to do somewhat better */
|
||||
if (YapLibDir != NULL) {
|
||||
strncpy(FileNameBuf, YapLibDir, YAP_FILENAME_MAX);
|
||||
#if HAVE_GETENV
|
||||
} else {
|
||||
char* my_env=getenv("YAPLIBDIR");
|
||||
if (my_env != NULL) {
|
||||
strncpy(NameBuf, my_env, YAP_FILENAME_MAX);
|
||||
#endif
|
||||
} else {
|
||||
strncpy(NameBuf, LIB_DIR, YAP_FILENAME_MAX);
|
||||
}
|
||||
#if HAVE_GETENV
|
||||
}
|
||||
#endif
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
strncat(NameBuf,"\\", YAP_FILENAME_MAX);
|
||||
#else
|
||||
strncat(NameBuf,"/", YAP_FILENAME_MAX);
|
||||
#endif
|
||||
strncat(NameBuf,FileName, YAP_FILENAME_MAX);
|
||||
if ((splfild = open_file(NameBuf, O_RDONLY)) < 0) {
|
||||
return(FALSE);
|
||||
}
|
||||
} else {
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
/* skip the first line */
|
||||
do {
|
||||
myread(splfild, pp, 1);
|
||||
} while (pp[0] != 1);
|
||||
sprintf(msg, "YAPV%s", version_number);
|
||||
myread(splfild, pp, Unsigned(strlen(msg) + 1));
|
||||
if (strcmp(pp, msg) != 0) {
|
||||
if (PrologMode != BootMode)
|
||||
Error(SYSTEM_ERROR, TermNil,
|
||||
"file %s is not a saved Prolog state", FileName);
|
||||
return(0);
|
||||
}
|
||||
result = get_cell();
|
||||
mode = get_cell();
|
||||
if (mode != DO_ONLY_CODE && mode != DO_EVERYTHING) {
|
||||
Error(SYSTEM_ERROR, TermNil,
|
||||
"file %s is not a saved Prolog state", FileName);
|
||||
return(0);
|
||||
}
|
||||
if (*AHeap)
|
||||
get_cell();
|
||||
else
|
||||
*AHeap = get_cell() / 1024;
|
||||
if (mode == DO_ONLY_CODE || *AStack)
|
||||
get_cell();
|
||||
else
|
||||
*AStack = get_cell() / 1024;
|
||||
if (mode == DO_ONLY_CODE || *ATrail)
|
||||
get_cell();
|
||||
else
|
||||
*ATrail = get_cell() / 1024;
|
||||
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap);
|
||||
close_file();
|
||||
return (result);
|
||||
if (mode == FAIL_RESTORE) {
|
||||
ErrorMessage = NULL;
|
||||
return(0);
|
||||
}
|
||||
if (! *AHeap)
|
||||
*AHeap = MyHeap / 1024;
|
||||
if (mode != DO_ONLY_CODE && *AStack)
|
||||
*AStack = MyStack / 1024;
|
||||
if (mode != DO_ONLY_CODE && *ATrail)
|
||||
*ATrail = MyTrail / 1024;
|
||||
return (MyState);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1455,14 +1500,15 @@ int in_limbo = FALSE;
|
||||
* associated registers
|
||||
*/
|
||||
int
|
||||
Restore(char *s)
|
||||
Restore(char *s, char *lib_dir)
|
||||
{
|
||||
int restore_mode;
|
||||
int funcs_moved;
|
||||
|
||||
OPCODE old_ops[_std_top+1];
|
||||
|
||||
if ((restore_mode = OpenRestore(s)) == FAIL_RESTORE)
|
||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack, &MyHeap)) == FAIL_RESTORE)
|
||||
return(FALSE);
|
||||
ShutdownLoadForeign();
|
||||
in_limbo = TRUE;
|
||||
@ -1521,7 +1567,7 @@ p_restore(void)
|
||||
Error(TYPE_ERROR_LIST,t1,"restore/1");
|
||||
return(FALSE);
|
||||
}
|
||||
if ((mode = Restore(FileNameBuf)) == DO_ONLY_CODE) {
|
||||
if ((mode = Restore(FileNameBuf, NULL)) == DO_ONLY_CODE) {
|
||||
#if PUSH_REGS
|
||||
restore_absmi_regs(&standard_regs);
|
||||
#endif
|
||||
|
@ -10,7 +10,7 @@
|
||||
* File: Yap.proto *
|
||||
* mods: *
|
||||
* comments: Function declarations for YAP *
|
||||
* version: $Id: Yapproto.h,v 1.26 2002-10-29 17:23:32 vsc Exp $ *
|
||||
* version: $Id: Yapproto.h,v 1.27 2002-10-30 17:27:17 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
/* prototype file for Yap */
|
||||
@ -243,8 +243,8 @@ int STD_PROTO(IsPosfixOp,(Prop,int *,int *));
|
||||
Term STD_PROTO(Parse,(void));
|
||||
|
||||
/* save.c */
|
||||
int STD_PROTO(SavedInfo,(char *,int *,int *,int *,char *));
|
||||
int STD_PROTO(Restore,(char *));
|
||||
int STD_PROTO(SavedInfo,(char *,char *,CELL *,CELL *,CELL *));
|
||||
int STD_PROTO(Restore,(char *, char *));
|
||||
void STD_PROTO(InitSavePreds,(void));
|
||||
|
||||
/* scanner.c */
|
||||
|
106
console/yap.c
106
console/yap.c
@ -67,7 +67,7 @@
|
||||
static int PROTO(mygetc, (void));
|
||||
static void PROTO(do_bootfile, (char *));
|
||||
static void PROTO(do_top_goal,(YAP_Term));
|
||||
static void PROTO(exec_top_level,(int, char *));
|
||||
static void PROTO(exec_top_level,(int, YAP_init_args *));
|
||||
|
||||
#ifndef LIGHT
|
||||
void PROTO (exit, (int));
|
||||
@ -86,7 +86,6 @@ static int output_msg;
|
||||
#endif
|
||||
|
||||
static char BootFile[] = "boot.yap";
|
||||
static char StartUpFile[] = "startup";
|
||||
|
||||
#ifdef lint
|
||||
/* VARARGS1 */
|
||||
@ -211,15 +210,12 @@ do_bootfile (char *bootfilename)
|
||||
#endif
|
||||
}
|
||||
|
||||
static char *filename;
|
||||
|
||||
|
||||
static void
|
||||
print_usage(const YAP_init_args *init_args)
|
||||
{
|
||||
fprintf(stderr,"\n[ Valid switches for command line arguments: ]\n");
|
||||
fprintf(stderr," -? Shows this screen\n");
|
||||
fprintf(stderr," -b Boot file (%s)\n", StartUpFile);
|
||||
fprintf(stderr," -b Boot file \n");
|
||||
fprintf(stderr," -l Prolog file\n");
|
||||
fprintf(stderr," -h Heap area in Kbytes (default: %d, minimum: %d)\n",
|
||||
DefHeapSpace, MinHeapSpace);
|
||||
@ -246,7 +242,7 @@ print_usage(const YAP_init_args *init_args)
|
||||
*/
|
||||
|
||||
static int
|
||||
parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
|
||||
parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
|
||||
{
|
||||
char *p;
|
||||
int BootMode = YAP_BOOT_FROM_SAVED_CODE;
|
||||
@ -260,15 +256,17 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
|
||||
{
|
||||
case 'b':
|
||||
BootMode = YAP_BOOT_FROM_PROLOG;
|
||||
iap->YapPrologBootFile = *++argv;
|
||||
argc--;
|
||||
break;
|
||||
case '?':
|
||||
print_usage(init_args);
|
||||
print_usage(iap);
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'w':
|
||||
ssize = &(init_args->NumberWorkers);
|
||||
ssize = &(iap->NumberWorkers);
|
||||
goto GetSize;
|
||||
case 'd':
|
||||
ssize = &(init_args->DelayedReleaseLoad);
|
||||
ssize = &(iap->DelayedReleaseLoad);
|
||||
goto GetSize;
|
||||
#ifdef USE_SOCKET
|
||||
case 'c': /* running as client */
|
||||
@ -313,7 +311,7 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
|
||||
break;
|
||||
#endif /* EMACS */
|
||||
case 'f':
|
||||
init_args->FastBoot = TRUE;
|
||||
iap->FastBoot = TRUE;
|
||||
break;
|
||||
#ifdef MPWSHELL
|
||||
case 'm':
|
||||
@ -323,19 +321,19 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
|
||||
#endif
|
||||
case 's':
|
||||
case 'S':
|
||||
ssize = &(init_args->StackSize);
|
||||
ssize = &(iap->StackSize);
|
||||
if (p[1] == 'l') {
|
||||
p++;
|
||||
ssize = &(init_args->SchedulerLoop);
|
||||
ssize = &(iap->SchedulerLoop);
|
||||
}
|
||||
goto GetSize;
|
||||
case 'h':
|
||||
case 'H':
|
||||
ssize = &(init_args->HeapSize);
|
||||
ssize = &(iap->HeapSize);
|
||||
goto GetSize;
|
||||
case 't':
|
||||
case 'T':
|
||||
ssize = &(init_args->TrailSize);
|
||||
ssize = &(iap->TrailSize);
|
||||
GetSize:
|
||||
if (*++p == '\0')
|
||||
{
|
||||
@ -344,7 +342,7 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]);
|
||||
print_usage(init_args);
|
||||
print_usage(iap);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -381,13 +379,13 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
|
||||
/* we're done here */
|
||||
argc = 1;
|
||||
}
|
||||
init_args->YapPrologBootFile = *argv;
|
||||
iap->YapPrologRCFile = *argv;
|
||||
argv++;
|
||||
init_args->HaltAfterConsult = TRUE;
|
||||
iap->HaltAfterConsult = TRUE;
|
||||
break;
|
||||
case 'l':
|
||||
if ((*argv)[0] == '\0')
|
||||
init_args->YapPrologBootFile = *argv;
|
||||
iap->YapPrologRCFile = *argv;
|
||||
else {
|
||||
argc--;
|
||||
if (argc == 0) {
|
||||
@ -395,7 +393,7 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
argv++;
|
||||
init_args->YapPrologBootFile = *argv;
|
||||
iap->YapPrologRCFile = *argv;
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
@ -405,64 +403,51 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
|
||||
default:
|
||||
{
|
||||
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c ]\n", *p);
|
||||
print_usage(init_args);
|
||||
print_usage(iap);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
filename = p;
|
||||
iap->SavedState = p;
|
||||
}
|
||||
}
|
||||
return(BootMode);
|
||||
}
|
||||
|
||||
static int
|
||||
init_standard_system(int argc, char *argv[])
|
||||
init_standard_system(int argc, char *argv[], YAP_init_args *iap)
|
||||
{
|
||||
int BootMode;
|
||||
YAP_init_args init_args;
|
||||
|
||||
init_args.SavedState = NULL;
|
||||
init_args.HeapSize = 0;
|
||||
init_args.StackSize = 0;
|
||||
init_args.TrailSize = 0;
|
||||
init_args.YapLibDir = NULL;
|
||||
init_args.YapPrologBootFile = NULL;
|
||||
init_args.HaltAfterConsult = FALSE;
|
||||
init_args.FastBoot = FALSE;
|
||||
init_args.NumberWorkers = 1;
|
||||
init_args.SchedulerLoop = 10;
|
||||
init_args.DelayedReleaseLoad = 3;
|
||||
init_args.Argc = argc;
|
||||
init_args.Argv = argv;
|
||||
iap->SavedState = NULL;
|
||||
iap->HeapSize = 0;
|
||||
iap->StackSize = 0;
|
||||
iap->TrailSize = 0;
|
||||
iap->YapLibDir = NULL;
|
||||
iap->YapPrologBootFile = NULL;
|
||||
iap->YapPrologRCFile = NULL;
|
||||
iap->HaltAfterConsult = FALSE;
|
||||
iap->FastBoot = FALSE;
|
||||
iap->NumberWorkers = 1;
|
||||
iap->SchedulerLoop = 10;
|
||||
iap->DelayedReleaseLoad = 3;
|
||||
iap->Argc = argc;
|
||||
iap->Argv = argv;
|
||||
|
||||
BootMode = parse_yap_arguments(argc,argv,&init_args);
|
||||
BootMode = parse_yap_arguments(argc,argv,iap);
|
||||
|
||||
/* init memory */
|
||||
if (BootMode == YAP_BOOT_FROM_PROLOG)
|
||||
{
|
||||
|
||||
YAP_Init(&init_args);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (filename == NULL)
|
||||
init_args.SavedState = StartUpFile;
|
||||
else
|
||||
init_args.SavedState = filename;
|
||||
|
||||
BootMode = YAP_Init(&init_args);
|
||||
|
||||
}
|
||||
|
||||
if (BootMode == YAP_BOOT_FROM_PROLOG) {
|
||||
YAP_Init(iap);
|
||||
} else {
|
||||
BootMode = YAP_Init(iap);
|
||||
}
|
||||
return(BootMode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
exec_top_level(int BootMode, char *filename)
|
||||
exec_top_level(int BootMode, YAP_init_args *iap)
|
||||
{
|
||||
YAP_Term atomfalse;
|
||||
YAP_Atom livegoal;
|
||||
@ -476,7 +461,7 @@ exec_top_level(int BootMode, char *filename)
|
||||
{
|
||||
YAP_Atom livegoal;
|
||||
/* read the bootfile */
|
||||
do_bootfile (filename ? filename : BootFile);
|
||||
do_bootfile (iap->YapPrologBootFile ? iap->YapPrologBootFile : BootFile);
|
||||
livegoal = YAP_FullLookupAtom("$live");
|
||||
/* initialise the top-level */
|
||||
YAP_PutValue(livegoal, YAP_MkAtomTerm (YAP_LookupAtom("true")));
|
||||
@ -504,11 +489,12 @@ main (int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
int BootMode;
|
||||
YAP_init_args init_args;
|
||||
|
||||
#ifdef SIMICS
|
||||
fprintf(stdout,"Entering YAP\n");
|
||||
#endif /* SIMICS */
|
||||
BootMode = init_standard_system(argc, argv);
|
||||
BootMode = init_standard_system(argc, argv, &init_args);
|
||||
if (BootMode == YAP_BOOT_FROM_SAVED_ERROR) {
|
||||
fprintf(stderr,"[ FATAL ERROR: could not find saved state ]\n");
|
||||
exit(1);
|
||||
@ -516,7 +502,7 @@ main (int argc, char **argv)
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
start_workers();
|
||||
#endif /* YAPOR || TABLING */
|
||||
exec_top_level(BootMode, filename);
|
||||
exec_top_level(BootMode, &init_args);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
@ -70,8 +70,10 @@ typedef struct {
|
||||
int TrailSize;
|
||||
/* if NON-NULL, value for YAPLIBDIR */
|
||||
char *YapLibDir;
|
||||
/* if NON-NULL, name for a Prolog file to consult before entering top-level */
|
||||
/* if NON-NULL, name for a Prolog file to use when booting */
|
||||
char *YapPrologBootFile;
|
||||
/* if NON-NULL, name for a Prolog file to consult before entering top-level */
|
||||
char *YapPrologRCFile;
|
||||
/* if previous NON-NULL and TRUE, halt after consulting that file */
|
||||
int HaltAfterConsult;
|
||||
/* ignore .yaprc, .prolog.ini, etc. files. */
|
||||
|
@ -21,7 +21,7 @@
|
||||
% throws an exception if called outside of any cleanup-context.
|
||||
%
|
||||
% cleanup_all.
|
||||
% calls all pending CleanUpGoals and resets the cleanup-system to an initial state.
|
||||
% calls all pending CleanUpGoals and resets the cleanup-system to an initial state.
|
||||
% should only be used as one of the last calls in the main program.
|
||||
%
|
||||
% hidden predicates:
|
||||
|
Reference in New Issue
Block a user