upgrade to latest SWI
This commit is contained in:
@@ -37,10 +37,24 @@
|
||||
#include <math.h> /* avoid abs() problem with msvc++ */
|
||||
#include <stdio.h> /* rename() and remove() prototypes */
|
||||
|
||||
#if TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#if !O_XOS
|
||||
#ifdef O_XOS
|
||||
#define statstruct struct _stati64
|
||||
#else
|
||||
#define statstruct struct stat
|
||||
#define statfunc stat
|
||||
#endif
|
||||
#if HAVE_PWD_H
|
||||
@@ -99,13 +113,9 @@ long clock_wait_ticks;
|
||||
This module is a contraction of functions that used to be all over the
|
||||
place. together with pl-os.h (included by pl-incl.h) this file
|
||||
should define a basic layer around the OS, on which the rest of
|
||||
SWI-Prolog is based. SWI-Prolog has been developed on SUN, running
|
||||
SunOs 3.4 and later 4.0.
|
||||
SWI-Prolog is based.
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
Unfortunately some OS's simply do not offer an equivalent to SUN os
|
||||
features. In most cases part of the functionality of the system will
|
||||
have to be dropped. See the header of pl-incl.h for details.
|
||||
- - - - - - - - - - - - - - - - */
|
||||
|
||||
/********************************
|
||||
* INITIALISATION *
|
||||
@@ -120,6 +130,9 @@ have to be dropped. See the header of pl-incl.h for details.
|
||||
bool
|
||||
initOs(void)
|
||||
{ GET_LD
|
||||
|
||||
GD->statistics.start_time = WallTime();
|
||||
|
||||
DEBUG(1, Sdprintf("OS:initExpand() ...\n"));
|
||||
initExpand();
|
||||
DEBUG(1, Sdprintf("OS:initEnviron() ...\n"));
|
||||
@@ -432,11 +445,10 @@ UsedMemory(void)
|
||||
|
||||
uintptr_t
|
||||
FreeMemory(void)
|
||||
{
|
||||
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_DATA)
|
||||
uintptr_t used = UsedMemory();
|
||||
{ uintptr_t used = UsedMemory();
|
||||
|
||||
struct rlimit limit;
|
||||
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_DATA)
|
||||
struct rlimit limit;
|
||||
|
||||
if ( getrlimit(RLIMIT_DATA, &limit) == 0 )
|
||||
return limit.rlim_cur - used;
|
||||
@@ -467,9 +479,6 @@ FreeMemory(void)
|
||||
Depreciated according to Linux manpage, suggested by Solaris
|
||||
manpage.
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#ifdef __MINGW32__
|
||||
__stdcall unsigned long GetTickCount(void);
|
||||
#endif
|
||||
|
||||
void
|
||||
setRandom(unsigned int *seedp)
|
||||
@@ -712,34 +721,6 @@ RemoveTemporaryFiles(void)
|
||||
}
|
||||
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Size of a VM page of memory. Most BSD machines have this function. If not,
|
||||
here are several alternatives ...
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef HAVE_GETPAGESIZE
|
||||
#ifdef _SC_PAGESIZE
|
||||
int
|
||||
getpagesize()
|
||||
{ return sysconf(_SC_PAGESIZE);
|
||||
}
|
||||
#else /*_SC_PAGESIZE*/
|
||||
|
||||
#if hpux
|
||||
#include <a.out.h>
|
||||
int
|
||||
getpagesize()
|
||||
{
|
||||
#ifdef EXEC_PAGESIZE
|
||||
return EXEC_PAGESIZE;
|
||||
#else
|
||||
return 4096; /* not that important */
|
||||
#endif
|
||||
}
|
||||
#endif /*hpux*/
|
||||
#endif /*_SC_PAGESIZE*/
|
||||
#endif /*HAVE_GETPAGESIZE*/
|
||||
|
||||
#if O_HPFS
|
||||
|
||||
/* Conversion rules Prolog <-> OS/2 (using HPFS)
|
||||
@@ -791,7 +772,7 @@ OsPath(const char *plpath, char *path)
|
||||
}
|
||||
#endif /* O_HPFS */
|
||||
|
||||
#if defined(__unix__) || defined(__APPLE__)
|
||||
#ifdef __unix__
|
||||
char *
|
||||
PrologPath(const char *p, char *buf, size_t len)
|
||||
{ strncpy(buf, p, len);
|
||||
@@ -929,7 +910,7 @@ registerParentDirs(const char *path)
|
||||
{ char dirname[MAXPATHLEN];
|
||||
char tmp[MAXPATHLEN];
|
||||
CanonicalDir d;
|
||||
struct stat buf;
|
||||
statstruct buf;
|
||||
|
||||
for(e--; *e != '/' && e > path + 1; e-- )
|
||||
;
|
||||
@@ -967,7 +948,7 @@ not it updates the cache and returns FALSE.
|
||||
static int
|
||||
verify_entry(CanonicalDir d)
|
||||
{ char tmp[MAXPATHLEN];
|
||||
struct stat buf;
|
||||
statstruct buf;
|
||||
|
||||
if ( statfunc(OsPath(d->canonical, tmp), &buf) == 0 )
|
||||
{ if ( d->inode == buf.st_ino &&
|
||||
@@ -1008,7 +989,7 @@ verify_entry(CanonicalDir d)
|
||||
static char *
|
||||
canoniseDir(char *path)
|
||||
{ CanonicalDir d, next;
|
||||
struct stat buf;
|
||||
statstruct buf;
|
||||
char tmp[MAXPATHLEN];
|
||||
|
||||
DEBUG(1, Sdprintf("canoniseDir(%s) --> ", path));
|
||||
@@ -1728,6 +1709,40 @@ LocalTime(long *t, struct tm *r)
|
||||
}
|
||||
|
||||
|
||||
/*******************************
|
||||
* TERMINAL *
|
||||
*******************************/
|
||||
|
||||
#ifdef HAVE_TCSETATTR
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#define O_HAVE_TERMIO 1
|
||||
#else /*HAVE_TCSETATTR*/
|
||||
#ifdef HAVE_SYS_TERMIO_H
|
||||
#include <sys/termio.h>
|
||||
#define termios termio
|
||||
#define O_HAVE_TERMIO 1
|
||||
#else
|
||||
#ifdef HAVE_SYS_TERMIOS_H
|
||||
#include <sys/termios.h>
|
||||
#define O_HAVE_TERMIO 1
|
||||
#endif
|
||||
#endif
|
||||
#endif /*HAVE_TCSETATTR*/
|
||||
|
||||
typedef struct tty_state
|
||||
{
|
||||
#if defined(O_HAVE_TERMIO)
|
||||
struct termios tab;
|
||||
#elif defined(HAVE_SGTTYB)
|
||||
struct sgttyb tab;
|
||||
#else
|
||||
int tab; /* empty is not allowed */
|
||||
#endif
|
||||
} tty_state;
|
||||
|
||||
#define TTY_STATE(buf) (((tty_state*)(buf->state))->tab)
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
TERMINAL IO MANIPULATION
|
||||
|
||||
@@ -1744,7 +1759,7 @@ PopTty(IOSTREAM *s, ttybuf *buf)
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
static void
|
||||
ResetStdin(void)
|
||||
ResetStdin()
|
||||
{ Sinput->limitp = Sinput->bufp = Sinput->buffer;
|
||||
if ( !GD->os.org_terminal.read )
|
||||
GD->os.org_terminal = *Sinput->functions;
|
||||
@@ -1757,10 +1772,12 @@ Sread_terminal(void *handle, char *buf, size_t size)
|
||||
int fd = (int)h;
|
||||
source_location oldsrc = LD->read_source;
|
||||
|
||||
if ( LD->prompt.next && ttymode != TTY_RAW )
|
||||
PL_write_prompt(TRUE);
|
||||
else
|
||||
Sflush(Suser_output);
|
||||
if ( Soutput && true(Soutput, SIO_ISATTY) )
|
||||
{ if ( LD->prompt.next && ttymode != TTY_RAW )
|
||||
PL_write_prompt(TRUE);
|
||||
else
|
||||
Sflush(Suser_output);
|
||||
}
|
||||
|
||||
PL_dispatch(fd, PL_DISPATCH_WAIT);
|
||||
size = (*GD->os.org_terminal.read)(handle, buf, size);
|
||||
@@ -1779,7 +1796,7 @@ Sread_terminal(void *handle, char *buf, size_t size)
|
||||
}
|
||||
|
||||
void
|
||||
ResetTty()
|
||||
ResetTty(void)
|
||||
{ GET_LD
|
||||
startCritical;
|
||||
ResetStdin();
|
||||
@@ -1813,29 +1830,32 @@ PushTty(IOSTREAM *s, ttybuf *buf, int mode)
|
||||
struct termios tio;
|
||||
int fd;
|
||||
|
||||
buf->mode = ttymode;
|
||||
ttymode = mode;
|
||||
buf->mode = ttymode;
|
||||
buf->state = NULL;
|
||||
ttymode = mode;
|
||||
|
||||
if ( (fd = Sfileno(s)) < 0 || !isatty(fd) )
|
||||
succeed; /* not a terminal */
|
||||
if ( !truePrologFlag(PLFLAG_TTY_CONTROL) )
|
||||
succeed;
|
||||
|
||||
buf->state = allocHeap(sizeof(tty_state));
|
||||
|
||||
#ifdef HAVE_TCSETATTR
|
||||
if ( tcgetattr(fd, &buf->tab) ) /* save the old one */
|
||||
if ( tcgetattr(fd, &TTY_STATE(buf)) ) /* save the old one */
|
||||
fail;
|
||||
#else
|
||||
if ( ioctl(fd, TIOCGETA, &buf->tab) ) /* save the old one */
|
||||
if ( ioctl(fd, TIOCGETA, &TTY_STATE(buf)) ) /* save the old one */
|
||||
fail;
|
||||
#endif
|
||||
|
||||
tio = buf->tab;
|
||||
tio = TTY_STATE(buf);
|
||||
|
||||
switch( mode )
|
||||
{ case TTY_RAW:
|
||||
#if defined(HAVE_TCSETATTR) && defined(HAVE_CFMAKERAW)
|
||||
cfmakeraw(&tio);
|
||||
tio.c_oflag = buf->tab.c_oflag; /* donot change output modes */
|
||||
tio.c_oflag = TTY_STATE(buf).c_oflag; /* donot change output modes */
|
||||
tio.c_lflag |= ISIG;
|
||||
#else
|
||||
tio.c_lflag &= ~(ECHO|ICANON);
|
||||
@@ -1876,26 +1896,33 @@ PushTty(IOSTREAM *s, ttybuf *buf, int mode)
|
||||
|
||||
|
||||
bool
|
||||
PopTty(IOSTREAM *s, ttybuf *buf)
|
||||
PopTty(IOSTREAM *s, ttybuf *buf, int do_free)
|
||||
{ GET_LD
|
||||
int fd;
|
||||
|
||||
ttymode = buf->mode;
|
||||
|
||||
if ( (fd = Sfileno(s)) < 0 || !isatty(fd) )
|
||||
succeed; /* not a terminal */
|
||||
if ( !truePrologFlag(PLFLAG_TTY_CONTROL) )
|
||||
succeed;
|
||||
if ( buf->state )
|
||||
{ int fd = Sfileno(s);
|
||||
|
||||
if ( fd >= 0 )
|
||||
{
|
||||
#ifdef HAVE_TCSETATTR
|
||||
tcsetattr(fd, TCSANOW, &buf->tab);
|
||||
tcsetattr(fd, TCSANOW, &TTY_STATE(buf));
|
||||
#else
|
||||
#ifdef TIOCSETA
|
||||
ioctl(fd, TIOCSETA, &buf->tab);
|
||||
ioctl(fd, TIOCSETA, &TTY_STATE(buf));
|
||||
#else
|
||||
ioctl(fd, TCSETA, &buf->tab);
|
||||
ioctl(fd, TCXONC, (void *)1);
|
||||
ioctl(fd, TCSETA, &TTY_STATE(buf));
|
||||
ioctl(fd, TCXONC, (void *)1);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( do_free )
|
||||
{ freeHeap(buf->state, sizeof(tty_state));
|
||||
buf->state = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
succeed;
|
||||
}
|
||||
@@ -1910,6 +1937,7 @@ PushTty(IOSTREAM *s, ttybuf *buf, int mode)
|
||||
int fd;
|
||||
|
||||
buf->mode = ttymode;
|
||||
buf->state = NULL;
|
||||
ttymode = mode;
|
||||
|
||||
if ( (fd = Sfileno(s)) < 0 || !isatty(fd) )
|
||||
@@ -1917,25 +1945,26 @@ PushTty(IOSTREAM *s, ttybuf *buf, int mode)
|
||||
if ( !truePrologFlag(PLFLAG_TTY_CONTROL) )
|
||||
succeed;
|
||||
|
||||
if ( ioctl(fd, TIOCGETP, &buf->tab) ) /* save the old one */
|
||||
buf->state = allocHeap(sizeof(tty_state));
|
||||
|
||||
if ( ioctl(fd, TIOCGETP, &TTY_STATE(buf)) ) /* save the old one */
|
||||
fail;
|
||||
tio = buf->tab;
|
||||
tio = TTY_STATE(buf);
|
||||
|
||||
switch( mode )
|
||||
{ case TTY_RAW:
|
||||
tio.sg_flags |= CBREAK;
|
||||
tio.sg_flags &= ~ECHO;
|
||||
break;
|
||||
case TTY_OUTPUT:
|
||||
tio.sg_flags |= (CRMOD);
|
||||
break;
|
||||
case TTY_SAVE:
|
||||
succeed;
|
||||
default:
|
||||
sysError("Unknown PushTty() mode: %d", mode);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
{ case TTY_RAW:
|
||||
tio.sg_flags |= CBREAK;
|
||||
tio.sg_flags &= ~ECHO;
|
||||
break;
|
||||
case TTY_OUTPUT:
|
||||
tio.sg_flags |= (CRMOD);
|
||||
break;
|
||||
case TTY_SAVE:
|
||||
succeed;
|
||||
default:
|
||||
sysError("Unknown PushTty() mode: %d", mode);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
ioctl(fd, TIOCSETP, &tio);
|
||||
ioctl(fd, TIOCSTART, NULL);
|
||||
@@ -1945,17 +1974,22 @@ PushTty(IOSTREAM *s, ttybuf *buf, int mode)
|
||||
|
||||
|
||||
bool
|
||||
PopTty(IOSTREAM *s, ttybuf *buf)
|
||||
PopTty(IOSTREAM *s, ttybuf *buf, int do_free)
|
||||
{ ttymode = buf->mode;
|
||||
int fd;
|
||||
|
||||
if ( (fd = Sfileno(s)) < 0 || !isatty(fd) )
|
||||
succeed; /* not a terminal */
|
||||
if ( !truePrologFlag(PLFLAG_TTY_CONTROL) )
|
||||
succeed;
|
||||
if ( buf->state )
|
||||
{ int fd = Sfileno(s);
|
||||
|
||||
ioctl(fd, TIOCSETP, &buf->tab);
|
||||
ioctl(fd, TIOCSTART, NULL);
|
||||
if ( fd >= 0 )
|
||||
{ ioctl(fd, TIOCSETP, &buf->tab);
|
||||
ioctl(fd, TIOCSTART, NULL);
|
||||
}
|
||||
|
||||
if ( do_free )
|
||||
{ freeHeap(buf->state, sizeof(tty_state));
|
||||
buf->state = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
succeed;
|
||||
}
|
||||
@@ -1972,7 +2006,7 @@ PushTty(IOSTREAM *s, ttybuf *buf, int mode)
|
||||
|
||||
|
||||
bool
|
||||
PopTty(IOSTREAM *s, ttybuf *buf)
|
||||
PopTty(IOSTREAM *s, ttybuf *buf, int do_free)
|
||||
{ GET_LD
|
||||
ttymode = buf->mode;
|
||||
if ( ttymode != TTY_RAW )
|
||||
@@ -2448,7 +2482,7 @@ findExecutable(const char *av0, char *buffer)
|
||||
return NULL;
|
||||
file = Which(buf, tmp);
|
||||
|
||||
#if __unix__ || __APPLE__ /* argv[0] can be an #! script! */
|
||||
#if __unix__ /* argv[0] can be an #! script! */
|
||||
if ( file )
|
||||
{ int n, fd;
|
||||
char buf[MAXPATHLEN];
|
||||
@@ -2483,10 +2517,10 @@ findExecutable(const char *av0, char *buffer)
|
||||
#endif /*__WINDOWS__*/
|
||||
|
||||
|
||||
#if __unix__ || __APPLE__
|
||||
#ifdef __unix__
|
||||
static char *
|
||||
okToExec(const char *s)
|
||||
{ struct stat stbuff;
|
||||
{ statstruct stbuff;
|
||||
|
||||
if (statfunc(s, &stbuff) == 0 && /* stat it */
|
||||
S_ISREG(stbuff.st_mode) && /* check for file */
|
||||
|
Reference in New Issue
Block a user