improve code in getting restore file.
This commit is contained in:
parent
ace9025c10
commit
ca3177889c
69
C/save.c
69
C/save.c
@ -1386,7 +1386,7 @@ commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *A
|
|||||||
*/
|
*/
|
||||||
errout = Yap_stderr;
|
errout = Yap_stderr;
|
||||||
#endif
|
#endif
|
||||||
return(mode);
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1401,10 +1401,27 @@ cat_file_name(char *s, char *prefix, char *name, unsigned int max_length)
|
|||||||
strncat(s, name, max_length-1);
|
strncat(s, name, max_length-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, char *buf) {
|
||||||
|
int mode;
|
||||||
|
|
||||||
|
|
||||||
|
if ((splfild = open_file(inpf, O_RDONLY)) < 0) {
|
||||||
|
return FAIL_RESTORE;
|
||||||
|
}
|
||||||
|
if (buf[0] == '\0')
|
||||||
|
strncpy(buf, inpf, YAP_FILENAME_MAX);
|
||||||
|
if ((mode = commit_to_saved_state(inpf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
|
||||||
|
Yap_ErrorMessage = NULL;
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
||||||
{
|
{
|
||||||
int mode = FAIL_RESTORE;
|
int mode = FAIL_RESTORE;
|
||||||
|
char save_buffer[YAP_FILENAME_MAX+1];
|
||||||
|
|
||||||
// Yap_ErrorMessage = NULL;
|
// Yap_ErrorMessage = NULL;
|
||||||
if (inpf == NULL) {
|
if (inpf == NULL) {
|
||||||
@ -1413,6 +1430,8 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
|||||||
#endif
|
#endif
|
||||||
inpf = StartUpFile;
|
inpf = StartUpFile;
|
||||||
}
|
}
|
||||||
|
/* careful it starts from the root */
|
||||||
|
if (inpf[0] != '/') {
|
||||||
#if __simplescalar__
|
#if __simplescalar__
|
||||||
/* does not implement getcwd */
|
/* does not implement getcwd */
|
||||||
strncpy(Yap_FileNameBuf,yap_pwd,YAP_FILENAME_MAX);
|
strncpy(Yap_FileNameBuf,yap_pwd,YAP_FILENAME_MAX);
|
||||||
@ -1425,9 +1444,11 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
|||||||
#endif
|
#endif
|
||||||
strncat(Yap_FileNameBuf, "/", YAP_FILENAME_MAX-1);
|
strncat(Yap_FileNameBuf, "/", YAP_FILENAME_MAX-1);
|
||||||
strncat(Yap_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
strncat(Yap_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
||||||
|
} else {
|
||||||
|
strncat(Yap_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
||||||
|
}
|
||||||
if (inpf != NULL && (splfild = open_file(inpf, O_RDONLY)) > 0) {
|
if (inpf != NULL && (splfild = open_file(inpf, O_RDONLY)) > 0) {
|
||||||
if ((mode = commit_to_saved_state(inpf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
|
if ((mode = try_open(inpf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||||
Yap_ErrorMessage = NULL;
|
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1438,11 +1459,12 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
|||||||
*/
|
*/
|
||||||
if (YapLibDir != NULL) {
|
if (YapLibDir != NULL) {
|
||||||
cat_file_name(Yap_FileNameBuf, Yap_LibDir, inpf, YAP_FILENAME_MAX);
|
cat_file_name(Yap_FileNameBuf, Yap_LibDir, inpf, YAP_FILENAME_MAX);
|
||||||
if ((splfild = open_file(Yap_FileNameBuf, O_RDONLY)) > 0) {
|
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||||
if ((mode = commit_to_saved_state(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
|
|
||||||
Yap_ErrorMessage = NULL;
|
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||||
|
return mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if HAVE_GETENV
|
#if HAVE_GETENV
|
||||||
@ -1450,21 +1472,17 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
|||||||
char *yap_env = getenv("YAPLIBDIR");
|
char *yap_env = getenv("YAPLIBDIR");
|
||||||
if (yap_env != NULL) {
|
if (yap_env != NULL) {
|
||||||
cat_file_name(Yap_FileNameBuf, yap_env, inpf, YAP_FILENAME_MAX);
|
cat_file_name(Yap_FileNameBuf, yap_env, inpf, YAP_FILENAME_MAX);
|
||||||
if ((splfild = open_file(Yap_FileNameBuf, O_RDONLY)) > 0) {
|
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||||
if ((mode = commit_to_saved_state(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
|
|
||||||
Yap_ErrorMessage = NULL;
|
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (YAP_LIBDIR != NULL) {
|
if (YAP_LIBDIR != NULL) {
|
||||||
cat_file_name(Yap_FileNameBuf, YAP_LIBDIR, inpf, YAP_FILENAME_MAX);
|
cat_file_name(Yap_FileNameBuf, YAP_LIBDIR, inpf, YAP_FILENAME_MAX);
|
||||||
if ((splfild = open_file(Yap_FileNameBuf, O_RDONLY)) > 0) {
|
if ((splfild = open_file(Yap_FileNameBuf, O_RDONLY)) > 0) {
|
||||||
if ((mode = commit_to_saved_state(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
|
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||||
Yap_ErrorMessage = NULL;
|
return mode;
|
||||||
return(mode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1503,11 +1521,8 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
|||||||
pt[1] = '\0';
|
pt[1] = '\0';
|
||||||
strncat(Yap_FileNameBuf,"lib/Yap/startup.yss",YAP_FILENAME_MAX);
|
strncat(Yap_FileNameBuf,"lib/Yap/startup.yss",YAP_FILENAME_MAX);
|
||||||
}
|
}
|
||||||
if ((splfild = open_file(Yap_FileNameBuf, O_RDONLY)) > 0) {
|
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||||
if ((mode = commit_to_saved_state(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
|
return mode;
|
||||||
Yap_ErrorMessage = NULL;
|
|
||||||
return(mode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
@ -1515,20 +1530,14 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
|||||||
/* try to open from current directory */
|
/* try to open from current directory */
|
||||||
/* could not open file */
|
/* could not open file */
|
||||||
if (Yap_ErrorMessage == NULL) {
|
if (Yap_ErrorMessage == NULL) {
|
||||||
#if __simplescalar__
|
if (save_buffer[0]) {
|
||||||
/* does not implement getcwd */
|
strncpy(Yap_FileNameBuf, save_buffer, YAP_FILENAME_MAX-1);
|
||||||
strncpy(Yap_FileNameBuf,yap_pwd,YAP_FILENAME_MAX);
|
do_system_error(PERMISSION_ERROR_OPEN_SOURCE_SINK,"incorrect saved state");
|
||||||
#elif HAVE_GETCWD
|
} else {
|
||||||
if (getcwd (Yap_FileNameBuf, YAP_FILENAME_MAX) == NULL)
|
strncpy(Yap_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
||||||
Yap_FileNameBuf[0] = '\0';
|
|
||||||
#else
|
|
||||||
if (getwd (Yap_FileNameBuf) == NULL)
|
|
||||||
Yap_FileNameBuf[0] = '\0';
|
|
||||||
#endif
|
|
||||||
strncat(Yap_FileNameBuf, "/", YAP_FILENAME_MAX-1);
|
|
||||||
strncat(Yap_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
|
||||||
do_system_error(PERMISSION_ERROR_OPEN_SOURCE_SINK,"could not open saved state");
|
do_system_error(PERMISSION_ERROR_OPEN_SOURCE_SINK,"could not open saved state");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
<h2>Yap-6.0.7:</h2>
|
<h2>Yap-6.0.7:</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li> FIXED: restore from / file should just try that file. </li>
|
||||||
|
<li> FIXED: bad things can happen to P when user code is called (obs
|
||||||
|
from Ingo Thon). </li>
|
||||||
<li> NEW: coinduction.yap. </li>
|
<li> NEW: coinduction.yap. </li>
|
||||||
<li> FIXED: remove leftover files including two lib*.a (obs from
|
<li> FIXED: remove leftover files including two lib*.a (obs from
|
||||||
Bernd Gutmann).</li>
|
Bernd Gutmann).</li>
|
||||||
|
Reference in New Issue
Block a user