Remove attempt to emulate SWI I/O

add YAP_getcwd and PL_cwd to interface
This commit is contained in:
Vítor Santos Costa 2008-12-13 16:07:55 +00:00
parent e0531d0743
commit 2b0c27deb6
8 changed files with 86 additions and 1137 deletions

View File

@ -356,6 +356,9 @@
#include "cut_c.h"
#endif /* CUT_C */
#if !HAVE_STRNCPY
#define strncpy(X,Y,Z) strcpy(X,Y)
#endif
#define YAP_BOOT_FROM_PROLOG 0
#define YAP_BOOT_FROM_SAVED_CODE 1
@ -2382,3 +2385,17 @@ YAP_AGCRegisterHook(Agc_hook hook)
return old;
}
X_API char *
YAP_cwd(void)
{
char *buf;
int len;
if (!Yap_getcwd(Yap_FileNameBuf, YAP_FILENAME_MAX))
return FALSE;
len = strlen(Yap_FileNameBuf);
buf = malloc(+1);
if (!buf)
return NULL;
strncpy(buf, Yap_FileNameBuf, len);
return buf;
}

View File

@ -871,11 +871,17 @@ c_eq(Term t1, Term t2, compiler_struct *cglobs)
}
}
/* first argument is an unbound var */
c_var(t1, 0, 0, 0, cglobs);
cglobs->onhead = TRUE;
if (IsNewVar(t1)) {
c_var(t1, 0, 0, 0, cglobs);
} else {
c_var(t1, 0, 0, 0, cglobs);
cglobs->onhead = TRUE;
}
if (IsVarTerm(t2)) {
cglobs->onhead = TRUE;
c_var(t2, 0, 0, 0, cglobs);
} else {
cglobs->onhead = TRUE;
c_arg(0, t2, 0, 0, cglobs);
}
cglobs->onhead = FALSE;

View File

@ -672,7 +672,7 @@ Yap_DebugGetc()
curfile = NULL;
}
if (curfile == NULL)
YP_fgets(my_line, 200, stdin);
(void)YP_fgets(my_line, 200, stdin);
eolflg = 0;
lp = my_line;
}

View File

@ -1608,6 +1608,34 @@ Yap_volume_header(char *file)
return volume_header(file);
}
int Yap_getcwd(const char *buf, int len)
{
#if __simplescalar__
/* does not implement getcwd */
strncpy(Yap_buf,yap_pwd,len);
#elif HAVE_GETCWD
if (getcwd ((char *)buf, len) == NULL) {
#if HAVE_STRERROR
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in getcwd/1", strerror(errno));
#else
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "error %d in getcwd/1", errno);
#endif
return FALSE;
}
#else
if (getwd (buf) == NULL) {
#if HAVE_STRERROR
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in getcwd/1", strerror(errno));
#else
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "in getcwd/1");
#endif
return FALSE;
}
#endif
return TRUE;
}
/******
TODO: rewrite to use wordexp
****/
@ -1698,16 +1726,8 @@ TrueFileName (char *source, char *root, char *result, int in_lib)
#endif
/* step 3: get the full file name */
if (!dir_separator(result[0]) && !volume_header(result)) {
#if __simplescalar__
/* does not implement getcwd */
strncpy(ares1,yap_pwd,YAP_FILENAME_MAX);
#elif HAVE_GETCWD
if (getcwd (ares1, YAP_FILENAME_MAX) == NULL)
if (!Yap_getcwd(ares1, YAP_FILENAME_MAX))
return FALSE;
#else
if (getwd (ares1) == NULL)
return FALSE;
#endif
#if _MSC_VER || defined(__MINGW32__)
strncat (ares1, "\\", YAP_FILENAME_MAX);
#else
@ -1858,32 +1878,11 @@ p_true_file_name3 (void)
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)));
}
static Int
p_getcwd(void)
{
#if __simplescalar__
/* does not implement getcwd */
strncpy(Yap_FileNameBuf,yap_pwd,YAP_FILENAME_MAX);
#elif HAVE_GETCWD
if (getcwd (Yap_FileNameBuf, YAP_FILENAME_MAX) == NULL) {
#if HAVE_STRERROR
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in getcwd/1", strerror(errno));
#else
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "error %d in getcwd/1", errno);
#endif
if (!Yap_getcwd(Yap_FileNameBuf, YAP_FILENAME_MAX))
return FALSE;
}
#else
if (getwd (Yap_FileNameBuf) == NULL) {
#if HAVE_STRERROR
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in getcwd/1", strerror(errno));
#else
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "in getcwd/1");
#endif
return FALSE;
}
#endif
return Yap_unify(ARG1,MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)));
}

View File

@ -314,6 +314,7 @@ void STD_PROTO(Yap_InitSysPath,(void));
void STD_PROTO(Yap_SetTextFile,(char *));
#endif
void STD_PROTO(Yap_cputime_interval,(Int *,Int *));
int STD_PROTO(Yap_getcwd,(const char *, int));
void STD_PROTO(Yap_walltime_interval,(Int *,Int *));
void STD_PROTO(Yap_InitSysbits,(void));
void STD_PROTO(Yap_InitSysPreds,(void));

View File

@ -307,8 +307,27 @@ extern X_API void PL_free(void *);
#define PL_register_foreign(name, arity, function, flags) PL_register_foreign_in_module(NULL, (name), (arity), (function), (flags))
extern X_API int Sprintf(char *,...);
extern X_API int Sdprintf(char *,...);
extern X_API int Sprintf(const char * fm,...);
extern X_API int Sdprintf(const char *,...);
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Output representation for PL_get_chars() and friends. The
prepresentation type REP_FN is for PL_get_file_name() and friends. On
Windows we use UTF-8 which is translated by the `XOS' layer to Windows
UNICODE file functions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#define REP_ISO_LATIN_1 0x0000 /* output representation */
#define REP_UTF8 0x1000
#define REP_MB 0x2000
#ifdef __WINDOWS__
#define REP_FN REP_UTF8
#else
#define REP_FN REP_MB
#endif
#define PL_DIFF_LIST 0x20000 /* PL_unify_chars() */
#ifdef SIO_MAGIC /* defined from <SWI-Stream.h> */
extern X_API int PL_unify_stream(term_t t, IOSTREAM *s);
@ -316,6 +335,8 @@ extern X_API int PL_open_stream(term_t t, IOSTREAM *s); /* compat */
extern X_API int PL_get_stream_handle(term_t t, IOSTREAM **s);
#endif
extern X_API char *PL_cwd(void);
void swi_install(void);
#endif /* _FLI_H_INCLUDED */

View File

@ -451,6 +451,9 @@ extern X_API int PROTO(YAP_AtomReleaseHold,(YAP_Atom));
/* void YAP_AtomReleaseHold(YAP_Atom) */
extern X_API YAP_agc_hook PROTO(YAP_AGCRegisterHook,(YAP_agc_hook));
/* char *YAP_cwd(void) */
extern X_API char * PROTO(YAP_cwd,(void));
/* thread stuff */
extern X_API int PROTO(YAP_ThreadSelf,(void));
extern X_API YAP_CELL PROTO(YAP_ThreadCreateEngine,(YAP_thread_attr *));

File diff suppressed because it is too large Load Diff