win32
This commit is contained in:
parent
8c873350c9
commit
5073ff9b43
322
os/sysbits.c
322
os/sysbits.c
@ -55,7 +55,7 @@ static int chdir(char *);
|
|||||||
|
|
||||||
void exit(int);
|
void exit(int);
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef _WIN32
|
||||||
void
|
void
|
||||||
Yap_WinError(char *yap_error)
|
Yap_WinError(char *yap_error)
|
||||||
{
|
{
|
||||||
@ -452,7 +452,7 @@ PrologPath(const char *Y, char *X) {
|
|||||||
|
|
||||||
static bool ChDir(const char *path) {
|
static bool ChDir(const char *path) {
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
char *qpath = Yap_AbsoluteFile(path, NULL, true);
|
const char *qpath = Yap_AbsoluteFile(path, NULL, true);
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
if (GLOBAL_AssetsWD) {
|
if (GLOBAL_AssetsWD) {
|
||||||
@ -487,7 +487,7 @@ static bool ChDir(const char *path) {
|
|||||||
#else
|
#else
|
||||||
rc = (chdir(qpath) == 0);
|
rc = (chdir(qpath) == 0);
|
||||||
#endif
|
#endif
|
||||||
free( qpath );
|
free( (void *)qpath );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
@ -501,7 +501,8 @@ BaseName(const char *X) {
|
|||||||
return qpath;
|
return qpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
|
||||||
|
const har *
|
||||||
DirName(const char *X) {
|
DirName(const char *X) {
|
||||||
char dir[YAP_FILENAME_MAX];
|
char dir[YAP_FILENAME_MAX];
|
||||||
char drive[YAP_FILENAME_MAX];
|
char drive[YAP_FILENAME_MAX];
|
||||||
@ -520,7 +521,7 @@ DirName(const char *X) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *myrealpath( const char *path, char *out)
|
static const char *myrealpath( const char *path, char *out)
|
||||||
{
|
{
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
DWORD retval=0;
|
DWORD retval=0;
|
||||||
@ -539,21 +540,28 @@ static char *myrealpath( const char *path, char *out)
|
|||||||
return out;
|
return out;
|
||||||
#elif HAVE_REALPATH
|
#elif HAVE_REALPATH
|
||||||
{
|
{
|
||||||
char *rc = realpath(path,out);
|
const char *rc;
|
||||||
char *s0;
|
rc = ( const char *)realpath(path,out);
|
||||||
|
const char *s0, *s;
|
||||||
|
|
||||||
if (rc == NULL && (errno == ENOENT|| errno == EACCES)) {
|
if (rc == NULL && (errno == ENOENT|| errno == EACCES)) {
|
||||||
char *s = basename((char *)path);
|
|
||||||
|
if ( is_directory(rc)) {
|
||||||
|
s = (const char *)path;
|
||||||
|
} else {
|
||||||
|
s = basename((char *)path);
|
||||||
|
path = dirname((char *)path);
|
||||||
|
}
|
||||||
s0 = malloc(strlen(s)+1);
|
s0 = malloc(strlen(s)+1);
|
||||||
strcpy(s0, s);
|
strcpy((char *)s0, s);
|
||||||
if ((rc = myrealpath(dirname((char *)path), out))==NULL) {
|
if ((rc = myrealpath(path, out))==NULL) {
|
||||||
Yap_FileError(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "could not find file %s: %s", path, strerror(errno));
|
Yap_FileError(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "could not find file %s: %s", path, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(rc[strlen(rc)-1] != '/' )
|
if(rc[strlen(rc)-1] != '/' )
|
||||||
strcat(rc, "/");
|
strcat((char *)rc, "/");
|
||||||
strcat(rc, s0);
|
strcat((char *)rc, s0);
|
||||||
free(s0);
|
free((void *)s0);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -599,21 +607,20 @@ PrologExpandVars(const char *spec, char *tmp0, bool ok_to)
|
|||||||
/**
|
/**
|
||||||
* generate absolute path, if ok first expand SICStus Prolog style
|
* generate absolute path, if ok first expand SICStus Prolog style
|
||||||
*
|
*
|
||||||
* @param spec the file path, including ~ and $
|
* @param[in] spec the file path, including `~` and `$`.
|
||||||
* @param tmp where to store the file
|
* @param[out] tmp where to store the file.
|
||||||
* @param ok where to process ~and $
|
* @param[in] ok where to process `~` and `$`.
|
||||||
*
|
*
|
||||||
* @return tmp, or NULL
|
* @return tmp, or NULL
|
||||||
*/
|
*/
|
||||||
char *
|
const char *
|
||||||
Yap_AbsoluteFile(const char *spec, char *tmp, bool ok)
|
Yap_AbsoluteFile(const char *spec, char *tmp, bool ok)
|
||||||
{
|
{
|
||||||
char *t1 = NULL;
|
char *t1 = NULL;
|
||||||
t1 = PrologExpandVars(spec, t1, ok);
|
t1 = PrologExpandVars(spec, t1, ok);
|
||||||
if (!t1)
|
if (!t1)
|
||||||
return NULL;
|
return NULL;
|
||||||
char *rc = myrealpath(t1, tmp);
|
return myrealpath(t1, tmp);
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -645,32 +652,31 @@ prolog_expanded_file_system_path( USES_REGS1 )
|
|||||||
} else if (IsStringTerm(t1)) {
|
} else if (IsStringTerm(t1)) {
|
||||||
cmd = StringOfTerm(t1);
|
cmd = StringOfTerm(t1);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if (t2 == TermTrue)
|
|
||||||
flag = true;
|
|
||||||
else if (t2 == TermFalse)
|
|
||||||
flag = false;
|
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (t2 == TermTrue) {
|
||||||
|
flag = true;
|
||||||
|
} else if (t2 == TermFalse) {
|
||||||
|
flag = false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (IsAtomTerm(t3)) {
|
if (IsAtomTerm(t3)) {
|
||||||
p0 = RepAtom(AtomOfTerm(t3))->StrOfAE;
|
p0 = RepAtom(AtomOfTerm(t3))->StrOfAE;
|
||||||
} else if (IsStringTerm(t3)) {
|
} else if (IsStringTerm(t3)) {
|
||||||
p0 = StringOfTerm(t3);
|
p0 = StringOfTerm(t3);
|
||||||
} else {
|
} else {
|
||||||
|
return false;
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
const char *out = PrologExpandVars(cmd,o,flag);
|
const char *out = PrologExpandVars(cmd,o,flag);
|
||||||
if (Yap_IsAbsolutePath(out)) {
|
if (Yap_IsAbsolutePath(out)) {
|
||||||
return Yap_unify(MkAtomTerm(Yap_LookupAtom(out)), ARG4);
|
return Yap_unify(MkAtomTerm(Yap_LookupAtom(out)), ARG4);
|
||||||
} else if (p0[0] == '\0') {
|
} else if (p0[0] == '\0') {
|
||||||
char *rc = myrealpath(out, LOCAL_FileNameBuf2 );
|
const char *rc = myrealpath(out, LOCAL_FileNameBuf2 );
|
||||||
return Yap_unify(MkAtomTerm(Yap_LookupAtom(rc)), ARG4);
|
return Yap_unify(MkAtomTerm(Yap_LookupAtom(rc)), ARG4);
|
||||||
} else {
|
} else {
|
||||||
strncpy( LOCAL_FileNameBuf2, p0, YAP_FILENAME_MAX );
|
char *pt =stpncpy( LOCAL_FileNameBuf2, p0, YAP_FILENAME_MAX );
|
||||||
char *pt = LOCAL_FileNameBuf2 + strlen( LOCAL_FileNameBuf );
|
printf("%s\n", LOCAL_FileNameBuf2);
|
||||||
if ( !dir_separator( pt[-1] )) {
|
if ( !dir_separator( pt[-1] )) {
|
||||||
#if ATARI || _MSC_VER || defined(__MINGW32__)
|
#if ATARI || _MSC_VER || defined(__MINGW32__)
|
||||||
pt[0] = '\\';
|
pt[0] = '\\';
|
||||||
@ -678,16 +684,17 @@ prolog_expanded_file_system_path( USES_REGS1 )
|
|||||||
pt[0] = '/';
|
pt[0] = '/';
|
||||||
#endif
|
#endif
|
||||||
pt++;
|
pt++;
|
||||||
|
pt[0] = '\n';
|
||||||
}
|
}
|
||||||
out = strncpy( pt, out, YAP_FILENAME_MAX -(pt -LOCAL_FileNameBuf2) );
|
out = strncpy( pt, out, YAP_FILENAME_MAX -(pt -LOCAL_FileNameBuf2) );
|
||||||
char *rc = myrealpath(out, LOCAL_FileNameBuf );
|
const char *rc = myrealpath(LOCAL_FileNameBuf2, LOCAL_FileNameBuf );
|
||||||
return Yap_unify(MkAtomTerm(Yap_LookupAtom(rc)), ARG4);
|
return Yap_unify(MkAtomTerm(Yap_LookupAtom(rc)), ARG4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXPAND_FILENAME_DEFS() \
|
#define EXPAND_FILENAME_DEFS() \
|
||||||
PAR("parameter_expansion", isatom, EXPAND_FILENAME_PARAMETER_EXPANSION), \
|
PAR("parameter_expansion", isatom, EXPAND_FILENAME_PARAMETER_EXPANSION), \
|
||||||
PAR("commands", boolean, EXPAND_FILENAME_COMMANDS), \
|
PAR("commands", booleanFlag, EXPAND_FILENAME_COMMANDS), \
|
||||||
PAR(NULL, ok, EXPAND_FILENAME_END)
|
PAR(NULL, ok, EXPAND_FILENAME_END)
|
||||||
|
|
||||||
#define PAR(x, y, z) z
|
#define PAR(x, y, z) z
|
||||||
@ -710,19 +717,21 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
|||||||
{
|
{
|
||||||
xarg *args;
|
xarg *args;
|
||||||
expand_filename_enum_choices_t i;
|
expand_filename_enum_choices_t i;
|
||||||
bool use_glob = false;
|
bool use_system_expansion = true, glob_vs_wordexp = true;
|
||||||
char **ss = NULL;
|
const char *tmp = NULL;
|
||||||
char *tmp = NULL;
|
|
||||||
const char *spec;
|
|
||||||
char *tmpe = NULL;
|
char *tmpe = NULL;
|
||||||
size_t j, pathcount;
|
const char *spec;
|
||||||
int flags = 0;
|
|
||||||
#if HAVE_WORDEXP
|
|
||||||
wordexp_t wresult;
|
|
||||||
#endif
|
|
||||||
#if HAVE_GLOB
|
#if HAVE_GLOB
|
||||||
glob_t gresult;
|
glob_t gresult;
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_GLOB || HAVE_WORDEXP
|
||||||
|
char **ss = NULL;
|
||||||
|
int flags = 0, j;
|
||||||
|
#endif
|
||||||
|
#if HAVE_WORDEXP
|
||||||
|
wordexp_t wresult;
|
||||||
|
#endif
|
||||||
|
Term tf;
|
||||||
|
|
||||||
if (IsVarTerm(t1)) {
|
if (IsVarTerm(t1)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, t1, NULL);
|
Yap_Error(INSTANTIATION_ERROR, t1, NULL);
|
||||||
@ -739,14 +748,14 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
|||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
return TermNil;
|
return TermNil;
|
||||||
}
|
}
|
||||||
|
tmpe = malloc(YAP_FILENAME_MAX+1);
|
||||||
|
|
||||||
for (i = 0; i < EXPAND_FILENAME_END; i++) {
|
for (i = 0; i < EXPAND_FILENAME_END; i++) {
|
||||||
if (args[i].used) {
|
if (args[i].used) {
|
||||||
Term t = args[i].tvalue;
|
Term t = args[i].tvalue;
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case EXPAND_FILENAME_PARAMETER_EXPANSION:
|
case EXPAND_FILENAME_PARAMETER_EXPANSION:
|
||||||
if (t == TermProlog) {
|
if (t == TermProlog) {
|
||||||
use_glob = true;
|
|
||||||
tmpe = malloc(YAP_FILENAME_MAX+1);
|
|
||||||
if (tmpe == NULL) {
|
if (tmpe == NULL) {
|
||||||
return TermNil;
|
return TermNil;
|
||||||
}
|
}
|
||||||
@ -754,19 +763,24 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
|||||||
#ifdef GLOB_BRACE
|
#ifdef GLOB_BRACE
|
||||||
flags = GLOB_BRACE|GLOB_TILDE;
|
flags = GLOB_BRACE|GLOB_TILDE;
|
||||||
#endif
|
#endif
|
||||||
flags |= GLOB_NOCHECK;
|
//#ifdef GLOB_NOCHECK
|
||||||
|
// flags |= GLOB_NOCHECK;
|
||||||
|
//#endif
|
||||||
spec = tmpe;
|
spec = tmpe;
|
||||||
} else if (t == TermTrue) {
|
} else if (t == TermTrue) {
|
||||||
use_glob = false;
|
use_system_expansion = true;
|
||||||
} else if (t == TermFalse) {
|
} else if (t == TermFalse) {
|
||||||
use_glob = true;
|
use_system_expansion = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EXPAND_FILENAME_COMMANDS:
|
case EXPAND_FILENAME_COMMANDS:
|
||||||
if (!use_glob) {
|
if (!use_system_expansion) {
|
||||||
|
use_system_expansion = true;
|
||||||
|
#ifdef WRDE_NOCMD
|
||||||
if (t == TermFalse) {
|
if (t == TermFalse) {
|
||||||
flags = WRDE_NOCMD;
|
flags = WRDE_NOCMD;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
case EXPAND_FILENAME_END:
|
case EXPAND_FILENAME_END:
|
||||||
break;
|
break;
|
||||||
@ -775,38 +789,53 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
|
{
|
||||||
char u[YAP_FILENAME_MAX+1];
|
char u[YAP_FILENAME_MAX+1];
|
||||||
|
WIN32_FIND_DATA find;
|
||||||
|
HANDLE hFind;
|
||||||
|
CELL *dest;
|
||||||
|
|
||||||
// first pass, remove Unix style stuff
|
// first pass, remove Unix style stuff
|
||||||
if (unix2win(spec, u, YAP_FILENAME_MAX) == NULL)
|
if (unix2win(spec, u, YAP_FILENAME_MAX) == NULL)
|
||||||
return NULL;
|
return TermNil;
|
||||||
spec = (const char *)u;
|
spec = (const char *)u;
|
||||||
#endif
|
|
||||||
if (tmp == NULL) {
|
if (!use_system_expansion) {
|
||||||
tmp = malloc(YAP_FILENAME_MAX+1);
|
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(spec)), TermNil);
|
||||||
if (tmp == NULL) {
|
}
|
||||||
|
hFind = FindFirstFile(spec, &find);
|
||||||
|
|
||||||
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
return TermNil;
|
return TermNil;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
#if ( __WIN32 || __MINGW32__ )
|
|
||||||
DWORD retval=0;
|
|
||||||
// notice that the file does not need to exist
|
|
||||||
if (ini == NULL) {
|
|
||||||
ini = malloc(strlen(w)+1);
|
|
||||||
}
|
|
||||||
retval = ExpandEnvironmentStrings(pattern,
|
|
||||||
expanded,
|
|
||||||
maxlen);
|
|
||||||
|
|
||||||
if (retval == 0)
|
|
||||||
{
|
{
|
||||||
Yap_WinError("Generating a full path name for a file" );
|
tf = AbsPair(HR);
|
||||||
return NULL;
|
HR[0] = MkAtomTerm(Yap_LookupAtom(find.cFileName));
|
||||||
|
HR[1] = TermNil;
|
||||||
|
dest = HR+1;
|
||||||
|
HR += 2;
|
||||||
|
while (FindNextFile(hFind, &find)) {
|
||||||
|
*dest = AbsPair(HR);
|
||||||
|
HR[0] = MkAtomTerm(Yap_LookupAtom(find.cFileName));
|
||||||
|
HR[1] = TermNil;
|
||||||
|
dest = HR+1;
|
||||||
|
HR += 2;
|
||||||
|
}
|
||||||
|
FindClose(hFind);
|
||||||
|
}
|
||||||
|
return tf;
|
||||||
}
|
}
|
||||||
return expanded;
|
|
||||||
#elif HAVE_WORDEXP || HAVE_GLOB
|
#elif HAVE_WORDEXP || HAVE_GLOB
|
||||||
|
if (!use_system_expansion) {
|
||||||
|
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(spec)), TermNil);
|
||||||
|
}
|
||||||
/* Expand the string for the program to run. */
|
/* Expand the string for the program to run. */
|
||||||
if (use_glob) {
|
size_t pathcount;
|
||||||
|
if ( glob_vs_wordexp ) {
|
||||||
#if HAVE_GLOB
|
#if HAVE_GLOB
|
||||||
|
memset( &gresult,0,sizeof(gresult) );
|
||||||
switch (glob (spec, flags, NULL, &gresult))
|
switch (glob (spec, flags, NULL, &gresult))
|
||||||
{
|
{
|
||||||
case 0: /* Successful. */
|
case 0: /* Successful. */
|
||||||
@ -837,6 +866,7 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
|||||||
} else {
|
} else {
|
||||||
#if HAVE_WORDEXP
|
#if HAVE_WORDEXP
|
||||||
int rc;
|
int rc;
|
||||||
|
memset( &wresult,0,sizeof(wresult) );
|
||||||
switch ((rc = wordexp (spec, &wresult, flags)))
|
switch ((rc = wordexp (spec, &wresult, flags)))
|
||||||
{
|
{
|
||||||
case 0: /* Successful. */
|
case 0: /* Successful. */
|
||||||
@ -864,35 +894,34 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
Term tf = TermNil;
|
tf = TermNil;
|
||||||
for (j = 0; j < pathcount; j++) {
|
for (j = 0; j < pathcount; j++) {
|
||||||
const char *s = ss[pathcount-(j+1)];
|
const char *s = ss[pathcount-(j+1)];
|
||||||
#if HAVE_REALPATH
|
#if HAVE_REALPATH
|
||||||
s = myrealpath(s, tmp);
|
tmp = myrealpath(s,(char *) tmp);
|
||||||
|
#else
|
||||||
|
tmp = s;
|
||||||
#endif
|
#endif
|
||||||
//if (!exists(s))
|
//if (!exists(s))
|
||||||
// continue;
|
// continue;
|
||||||
Atom a = Yap_LookupAtom(s);
|
Atom a = Yap_LookupAtom(s);
|
||||||
tf = MkPairTerm(MkAtomTerm( a ),tf);
|
tf = MkPairTerm(MkAtomTerm( a ),tf);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// just use basic
|
|
||||||
if (expanded == NULL) {
|
|
||||||
expanded = malloc(strlen(pattern)+1);
|
|
||||||
}
|
|
||||||
strcpy(expanded, pattern);
|
|
||||||
#endif
|
|
||||||
if (tmp)
|
|
||||||
free( tmp );
|
|
||||||
if (tmpe)
|
|
||||||
free( tmpe );
|
|
||||||
#if HAVE_GLOB
|
#if HAVE_GLOB
|
||||||
if (use_glob)
|
if (use_system_expansion && glob_vs_wordexp)
|
||||||
globfree( &gresult );
|
globfree( &gresult );
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_WORDEXP
|
#if HAVE_WORDEXP
|
||||||
if (!use_glob)
|
if (use_system_expansion && !glob_vs_wordexp)
|
||||||
wordfree( &wresult );
|
wordfree( &wresult );
|
||||||
|
#endif
|
||||||
|
if (tmp)
|
||||||
|
free( (void *)tmp );
|
||||||
|
if (tmpe)
|
||||||
|
free( tmpe );
|
||||||
|
#else
|
||||||
|
// just use basic
|
||||||
|
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(spec)), TermNil);
|
||||||
#endif
|
#endif
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
@ -1291,7 +1320,7 @@ Yap_InitPageSize(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static const char *
|
||||||
expandWithPrefix(const char *source, const char *root, char *result)
|
expandWithPrefix(const char *source, const char *root, char *result)
|
||||||
{
|
{
|
||||||
char *work;
|
char *work;
|
||||||
@ -1428,7 +1457,7 @@ Yap_InitPageSize(void)
|
|||||||
root = expandWithPrefix( root, NULL, save_buffer );
|
root = expandWithPrefix( root, NULL, save_buffer );
|
||||||
}
|
}
|
||||||
// { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "root= %s %s ", root, source) ; }
|
// { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "root= %s %s ", root, source) ; }
|
||||||
char *work = expandWithPrefix( source, root, result );
|
const char *work = expandWithPrefix( source, root, (char *)result );
|
||||||
|
|
||||||
// expand names in case you have
|
// expand names in case you have
|
||||||
// to add a prefix
|
// to add a prefix
|
||||||
@ -1557,34 +1586,31 @@ Yap_InitPageSize(void)
|
|||||||
static Int
|
static Int
|
||||||
p_shell ( USES_REGS1 )
|
p_shell ( USES_REGS1 )
|
||||||
{ /* '$shell'(+SystCommand) */
|
{ /* '$shell'(+SystCommand) */
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
|
||||||
char *cmd;
|
|
||||||
term_t A1 = Yap_InitSlot(ARG1);
|
|
||||||
if ( PL_get_chars(A1, &cmd, CVT_ALL|REP_FN|CVT_EXCEPTION) )
|
|
||||||
{ int rval = System(cmd);
|
|
||||||
|
|
||||||
return rval == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
#else
|
|
||||||
#if HAVE_SYSTEM
|
|
||||||
char *shell;
|
|
||||||
register int bourne = FALSE;
|
|
||||||
Term t1 = Deref (ARG1);
|
|
||||||
const char *cmd;
|
const char *cmd;
|
||||||
|
Term t1 = Deref (ARG1);
|
||||||
shell = (char *) getenv ("SHELL");
|
|
||||||
if (!strcmp (shell, "/bin/sh"))
|
|
||||||
bourne = TRUE;
|
|
||||||
if (shell == NIL)
|
|
||||||
bourne = TRUE;
|
|
||||||
if (IsAtomTerm(t1))
|
if (IsAtomTerm(t1))
|
||||||
cmd = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
cmd = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||||
else if (IsStringTerm(t1))
|
else if (IsStringTerm(t1))
|
||||||
cmd = StringOfTerm(t1);
|
cmd = StringOfTerm(t1);
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
#if _MSC_VER || defined(__MINGW32__)
|
||||||
|
{ int rval = system(cmd);
|
||||||
|
|
||||||
|
return rval == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
#if HAVE_SYSTEM
|
||||||
|
char *shell;
|
||||||
|
register int bourne = FALSE;
|
||||||
|
|
||||||
|
shell = (char *) getenv ("SHELL");
|
||||||
|
if (!strcmp (shell, "/bin/sh"))
|
||||||
|
bourne = TRUE;
|
||||||
|
if (shell == NIL)
|
||||||
|
bourne = TRUE;
|
||||||
/* Yap_CloseStreams(TRUE); */
|
/* Yap_CloseStreams(TRUE); */
|
||||||
if (bourne)
|
if (bourne)
|
||||||
return system( cmd ) == 0;
|
return system( cmd ) == 0;
|
||||||
@ -1636,10 +1662,26 @@ Yap_InitPageSize(void)
|
|||||||
static Int
|
static Int
|
||||||
p_system ( USES_REGS1 )
|
p_system ( USES_REGS1 )
|
||||||
{ /* '$system'(+SystCommand) */
|
{ /* '$system'(+SystCommand) */
|
||||||
|
const char *cmd;
|
||||||
|
Term t1 = Deref (ARG1);
|
||||||
|
|
||||||
|
if (IsVarTerm(t1)) {
|
||||||
|
Yap_Error(INSTANTIATION_ERROR,t1,"argument to system/1 unbound");
|
||||||
|
return FALSE;
|
||||||
|
} else if (IsAtomTerm(t1)) {
|
||||||
|
cmd = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||||
|
} else if (IsStringTerm(t1)) {
|
||||||
|
cmd = StringOfTerm(t1);
|
||||||
|
} else {
|
||||||
|
if (!Yap_GetName (LOCAL_FileNameBuf, YAP_FILENAME_MAX, t1)) {
|
||||||
|
Yap_Error(TYPE_ERROR_ATOM,t1,"argument to system/1");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cmd = LOCAL_FileNameBuf;
|
||||||
|
}
|
||||||
|
/* Yap_CloseStreams(TRUE); */
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
#if _MSC_VER || defined(__MINGW32__)
|
||||||
char *cmd;
|
|
||||||
term_t A1 = Yap_InitSlot(ARG1);
|
|
||||||
if ( PL_get_chars(A1, &cmd, CVT_ALL|REP_FN|CVT_EXCEPTION) )
|
|
||||||
{ STARTUPINFO si;
|
{ STARTUPINFO si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
|
|
||||||
@ -1649,7 +1691,7 @@ Yap_InitPageSize(void)
|
|||||||
|
|
||||||
// Start the child process.
|
// Start the child process.
|
||||||
if( !CreateProcess( NULL, // No module name (use command line)
|
if( !CreateProcess( NULL, // No module name (use command line)
|
||||||
cmd, // Command line
|
(LPSTR)cmd, // Command line
|
||||||
NULL, // Process handle not inheritable
|
NULL, // Process handle not inheritable
|
||||||
NULL, // Thread handle not inheritable
|
NULL, // Thread handle not inheritable
|
||||||
FALSE, // Set handle inheritance to FALSE
|
FALSE, // Set handle inheritance to FALSE
|
||||||
@ -1675,32 +1717,14 @@ Yap_InitPageSize(void)
|
|||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
#elif HAVE_SYSTEM
|
#elif HAVE_SYSTEM
|
||||||
Term t1 = Deref (ARG1);
|
|
||||||
const char *s;
|
|
||||||
|
|
||||||
if (IsVarTerm(t1)) {
|
|
||||||
Yap_Error(INSTANTIATION_ERROR,t1,"argument to system/1 unbound");
|
|
||||||
return FALSE;
|
|
||||||
} else if (IsAtomTerm(t1)) {
|
|
||||||
s = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
|
||||||
} else if (IsStringTerm(t1)) {
|
|
||||||
s = StringOfTerm(t1);
|
|
||||||
} else {
|
|
||||||
if (!Yap_GetName (LOCAL_FileNameBuf, YAP_FILENAME_MAX, t1)) {
|
|
||||||
Yap_Error(TYPE_ERROR_ATOM,t1,"argument to system/1");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
s = LOCAL_FileNameBuf;
|
|
||||||
}
|
|
||||||
/* Yap_CloseStreams(TRUE); */
|
|
||||||
#if _MSC_VER
|
#if _MSC_VER
|
||||||
_flushall();
|
_flushall();
|
||||||
#endif
|
#endif
|
||||||
if (system (s)) {
|
if (system (cmd)) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM,t1,"%s in system(%s)", strerror(errno), s);
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM,t1,"%s in system(%s)", strerror(errno), cmd);
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM,t1,"in system(%s)", s);
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM,t1,"in system(%s)", cmd);
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -1874,38 +1898,6 @@ Yap_InitPageSize(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wrapper for alarm system call */
|
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
|
||||||
|
|
||||||
static DWORD WINAPI
|
|
||||||
DoTimerThread(LPVOID targ)
|
|
||||||
{
|
|
||||||
Int *time = (Int *)targ;
|
|
||||||
HANDLE htimer;
|
|
||||||
LARGE_INTEGER liDueTime;
|
|
||||||
|
|
||||||
htimer = CreateWaitableTimer(NULL, FALSE, NULL);
|
|
||||||
liDueTime.QuadPart = -10000000;
|
|
||||||
liDueTime.QuadPart *= time[0];
|
|
||||||
/* add time in usecs */
|
|
||||||
liDueTime.QuadPart -= time[1]*10;
|
|
||||||
/* Copy the relative time into a LARGE_INTEGER. */
|
|
||||||
if (SetWaitableTimer(htimer, &liDueTime,0,NULL,NULL,0) == 0) {
|
|
||||||
return(FALSE);
|
|
||||||
}
|
|
||||||
if (WaitForSingleObject(htimer, INFINITE) != WAIT_OBJECT_0)
|
|
||||||
fprintf(stderr,"WaitForSingleObject failed (%ld)\n", GetLastError());
|
|
||||||
Yap_signal (YAP_WINTIMER_SIGNAL);
|
|
||||||
/* now, say what is going on */
|
|
||||||
Yap_PutValue(AtomAlarm, MkAtomTerm(AtomTrue));
|
|
||||||
ExitThread(1);
|
|
||||||
#if _MSC_VER
|
|
||||||
return(0L);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
p_host_type( USES_REGS1 ) {
|
p_host_type( USES_REGS1 ) {
|
||||||
Term out = MkAtomTerm(Yap_LookupAtom(HOST_ALIAS));
|
Term out = MkAtomTerm(Yap_LookupAtom(HOST_ALIAS));
|
||||||
|
127
os/sysbits.h
127
os/sysbits.h
@ -13,22 +13,98 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
|
#if !defined(MINGW_HAS_SECURE_API)
|
||||||
|
#define MINGW_HAS_SECURE_API 1
|
||||||
|
#endif
|
||||||
|
//#undef _POSIX_
|
||||||
|
#endif
|
||||||
|
#include "Yap.h"
|
||||||
|
#include "Yatom.h"
|
||||||
|
#include "YapHeap.h"
|
||||||
|
#include "yapio.h"
|
||||||
|
#include "eval.h"
|
||||||
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
|
#include <winsock2.h>
|
||||||
|
/* Windows */
|
||||||
|
#include <io.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <direct.h>
|
||||||
|
#include "Shlwapi.h"
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_STDARG_H
|
||||||
|
#include <stdarg.h>
|
||||||
|
#endif
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#if HAVE_SYS_PARAM_H
|
||||||
|
#include <sys/param.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FENV_H
|
||||||
|
#include <fenv.h>
|
||||||
|
#endif
|
||||||
|
#define S_ISDIR(x) (((x)&_S_IFDIR)==_S_IFDIR)
|
||||||
|
#if HAVE_STDARG_H
|
||||||
|
#include <stdarg.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_CTYPE_H
|
||||||
|
#include <ctype.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_SYS_PARAMS_H
|
||||||
|
#include <sys/params.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_SYS_TYPES_H
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_STAT_H
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_SYS_SELECT_H && !_MSC_VER && !defined(__MINGW32__)
|
||||||
|
#include <sys/select.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_STRING_H
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_LIBGEN_H
|
||||||
|
#include <libgen.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_WCTYPE_H
|
||||||
|
#include <wctype.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_LIMITS_H
|
||||||
|
#include <limits.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_ERRNO_H
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_FCNTL_H
|
||||||
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
#if !HAVE_STRNCAT
|
||||||
|
#define strncat(X,Y,Z) strcat(X,Y)
|
||||||
|
#endif
|
||||||
|
#if !HAVE_STRNCPY
|
||||||
|
#define strncpy(X,Y,Z) strcpy(X,Y)
|
||||||
|
#endif
|
||||||
|
#include "iopreds.h"
|
||||||
|
|
||||||
|
#if HAVE_SIGNAL_H
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#ifdef MPW
|
||||||
|
#define signal sigset
|
||||||
|
#endif
|
||||||
|
|
||||||
/* windows.h does not like absmi.h, this
|
/* windows.h does not like absmi.h, this
|
||||||
should fix it for now */
|
should fix it for now */
|
||||||
#if _WIN32 || __MINGW32__
|
|
||||||
#include <winsock2.h>
|
|
||||||
#endif
|
|
||||||
#include "absmi.h"
|
|
||||||
#include "yapio.h"
|
|
||||||
#include "iopreds.h"
|
|
||||||
#include "alloc.h"
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#if STDC_HEADERS
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_WINDOWS_H
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_SYS_TIME_H && !_MSC_VER
|
#if HAVE_SYS_TIME_H && !_MSC_VER
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
@ -41,12 +117,6 @@
|
|||||||
#if HAVE_STRING_H
|
#if HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
#if !HAVE_STRNCAT
|
|
||||||
#define strncat(X,Y,Z) strcat(X,Y)
|
|
||||||
#endif
|
|
||||||
#if !HAVE_STRNCPY
|
|
||||||
#define strncpy(X,Y,Z) strcpy(X,Y)
|
|
||||||
#endif
|
|
||||||
#if HAVE_GETPWNAM
|
#if HAVE_GETPWNAM
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
@ -61,17 +131,6 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
#if _MSC_VER || defined(__MINGW32__)
|
||||||
#include <windows.h>
|
|
||||||
/* required for DLL compatibility */
|
|
||||||
#if HAVE_DIRECT_H
|
|
||||||
#include <direct.h>
|
|
||||||
#endif
|
|
||||||
#include <io.h>
|
|
||||||
#include <shlwapi.h>
|
|
||||||
#else
|
|
||||||
#if HAVE_SYS_PARAM_H
|
|
||||||
#include <sys/param.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
/* CYGWIN seems to include this automatically */
|
/* CYGWIN seems to include this automatically */
|
||||||
#if HAVE_FENV_H && !defined(__CYGWIN__)
|
#if HAVE_FENV_H && !defined(__CYGWIN__)
|
||||||
@ -86,13 +145,7 @@
|
|||||||
#if HAVE_LIBGEN_H
|
#if HAVE_LIBGEN_H
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_STDARG_H
|
#if defined(HAVE_READLINE_READLINE_H)
|
||||||
#include <stdarg.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_ERRNO_H
|
|
||||||
#include <errno.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_READLINE_READLINE_H
|
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
|||||||
|
|
||||||
bool Yap_IsAbsolutePath(const char *p);
|
bool Yap_IsAbsolutePath(const char *p);
|
||||||
Atom Yap_TemporaryFile(const char *prefix, int *fd);
|
Atom Yap_TemporaryFile(const char *prefix, int *fd);
|
||||||
char *Yap_AbsoluteFile(const char *spec, char *tmp, bool expand);
|
const char *Yap_AbsoluteFile(const char *spec, char *tmp, bool expand);
|
||||||
|
|
||||||
typedef enum mem_buf_source {
|
typedef enum mem_buf_source {
|
||||||
MEM_BUF_CODE = 1,
|
MEM_BUF_CODE = 1,
|
||||||
|
Reference in New Issue
Block a user