old swi library: replace by original yap code
This commit is contained in:
parent
eabf145052
commit
c652f79f26
@ -1,402 +1,353 @@
|
||||
|
||||
#ifndef _PL_STREAM_H
|
||||
#define _PL_STREAM_H
|
||||
|
||||
#ifndef _PL_EXPORT_DONE
|
||||
#define _PL_EXPORT_DONE
|
||||
|
||||
#if (defined(__WINDOWS__) || defined(__CYGWIN__)) && !defined(__LCC__)
|
||||
#define HAVE_DECLSPEC
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DECLSPEC
|
||||
# ifdef PL_KERNEL
|
||||
#define PL_EXPORT(type) __declspec(dllexport) type
|
||||
#define PL_EXPORT_DATA(type) __declspec(dllexport) type
|
||||
#define install_t void
|
||||
# else
|
||||
# ifdef __BORLANDC__
|
||||
#define PL_EXPORT(type) type _stdcall
|
||||
#define PL_EXPORT_DATA(type) extern type
|
||||
# else
|
||||
#define PL_EXPORT(type) extern type
|
||||
#define PL_EXPORT_DATA(type) __declspec(dllimport) type
|
||||
# endif
|
||||
#define install_t __declspec(dllexport) void
|
||||
# endif
|
||||
#else /*HAVE_DECLSPEC*/
|
||||
#define PL_EXPORT(type) extern type
|
||||
#define PL_EXPORT_DATA(type) extern type
|
||||
#define install_t void
|
||||
#endif /*HAVE_DECLSPEC*/
|
||||
#endif /*_PL_EXPORT_DONE*/
|
||||
|
||||
/* This appears to make the wide-character support compile and work
|
||||
on HPUX 11.23. There really should be a cleaner way ...
|
||||
*/
|
||||
#if defined(__hpux)
|
||||
#include <sys/_mbstate_t.h>
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__WINDOWS__)
|
||||
#define __WINDOWS__ 1
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include <stddef.h>
|
||||
#ifdef __WINDOWS__
|
||||
#include <stdint.h>
|
||||
#ifndef INT64_T_DEFINED
|
||||
#define INT64_T_DEFINED 1
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#endif
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h> /* more portable than stdint.h */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef PL_HAVE_TERM_T
|
||||
#define PL_HAVE_TERM_T
|
||||
typedef intptr_t term_t;
|
||||
#endif
|
||||
/*******************************
|
||||
* CONSTANTS *
|
||||
*******************************/
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#if defined(__WINDOWS__) && !defined(EWOULDBLOCK)
|
||||
#define EWOULDBLOCK 1000 /* Needed for socket handling */
|
||||
#endif
|
||||
#define EPLEXCEPTION 1001 /* errno: pending Prolog exception */
|
||||
|
||||
#define SIO_BUFSIZE (4096) /* buffering buffer-size */
|
||||
#define SIO_LINESIZE (1024) /* Sgets() default buffer size */
|
||||
#define SIO_MAGIC (7212676) /* magic number */
|
||||
#define SIO_CMAGIC (42) /* we are close (and thus illegal!) */
|
||||
|
||||
typedef ssize_t (*Sread_function)(void *handle, char *buf, size_t bufsize);
|
||||
typedef ssize_t (*Swrite_function)(void *handle, char*buf, size_t bufsize);
|
||||
typedef long (*Sseek_function)(void *handle, long pos, int whence);
|
||||
typedef int64_t (*Sseek64_function)(void *handle, int64_t pos, int whence);
|
||||
typedef int (*Sclose_function)(void *handle);
|
||||
typedef int (*Scontrol_function)(void *handle, int action, void *arg);
|
||||
|
||||
#include "pl-thread.h"
|
||||
|
||||
typedef struct io_functions
|
||||
{ Sread_function read; /* fill the buffer */
|
||||
Swrite_function write; /* empty the buffer */
|
||||
Sseek_function seek; /* seek to position */
|
||||
Sclose_function close; /* close stream */
|
||||
Scontrol_function control; /* Info/control */
|
||||
Sseek64_function seek64; /* seek to position (intptr_t files) */
|
||||
} IOFUNCTIONS;
|
||||
|
||||
typedef struct io_position
|
||||
{ int64_t byteno; /* byte-position in file */
|
||||
int64_t charno; /* character position in file */
|
||||
long int lineno; /* lineno in file */
|
||||
long int linepos; /* position in line */
|
||||
intptr_t reserved[2]; /* future extensions */
|
||||
} IOPOS;
|
||||
|
||||
/* NOTE: check with encoding_names */
|
||||
/* in pl-file.c */
|
||||
typedef enum
|
||||
{ ENC_UNKNOWN = 0, /* invalid/unknown */
|
||||
ENC_OCTET, /* raw 8 bit input */
|
||||
ENC_ASCII, /* US-ASCII (0..127) */
|
||||
ENC_ISO_LATIN_1, /* ISO Latin-1 (0..256) */
|
||||
ENC_ANSI, /* default (multibyte) codepage */
|
||||
ENC_UTF8,
|
||||
ENC_UNICODE_BE, /* big endian unicode file */
|
||||
ENC_UNICODE_LE, /* little endian unicode file */
|
||||
ENC_WCHAR /* pl_wchar_t */
|
||||
} IOENC;
|
||||
|
||||
#define SIO_NL_POSIX 0 /* newline as \n */
|
||||
#define SIO_NL_DOS 1 /* newline as \r\n */
|
||||
#define SIO_NL_DETECT 3 /* detect processing mode */
|
||||
|
||||
typedef struct io_stream
|
||||
{ char *bufp; /* `here' */
|
||||
char *limitp; /* read/write limit */
|
||||
char *buffer; /* the buffer */
|
||||
char *unbuffer; /* Sungetc buffer */
|
||||
int lastc; /* last character written */
|
||||
int magic; /* magic number SIO_MAGIC */
|
||||
int bufsize; /* size of the buffer */
|
||||
int flags; /* Status flags */
|
||||
IOPOS posbuf; /* location in file */
|
||||
IOPOS * position; /* pointer to above */
|
||||
void *handle; /* function's handle */
|
||||
IOFUNCTIONS *functions; /* open/close/read/write/seek */
|
||||
int locks; /* lock/unlock count */
|
||||
IOLOCK * mutex; /* stream mutex */
|
||||
/* SWI-Prolog 4.0.7 */
|
||||
void (*close_hook)(void* closure);
|
||||
void * closure;
|
||||
/* SWI-Prolog 5.1.3 */
|
||||
int timeout; /* timeout (milliseconds) */
|
||||
/* SWI-Prolog 5.4.4 */
|
||||
char * message; /* error/warning message */
|
||||
IOENC encoding; /* character encoding used */
|
||||
struct io_stream * tee; /* copy data to this stream */
|
||||
mbstate_t * mbstate; /* ENC_ANSI decoding */
|
||||
struct io_stream * upstream; /* stream providing our input */
|
||||
struct io_stream * downstream; /* stream providing our output */
|
||||
unsigned newline : 2; /* Newline mode */
|
||||
unsigned erased : 1; /* Stream was erased */
|
||||
unsigned references : 4; /* Reference-count */
|
||||
int io_errno; /* Save errno value */
|
||||
void * exception; /* pending exception (record_t) */
|
||||
void * context; /* getStreamContext() */
|
||||
intptr_t reserved[0]; /* reserved for extension */
|
||||
struct PL_locale * locale; /* Locale associated to stream */
|
||||
#if 0 /* We used them all :-( */
|
||||
intptr_t reserved[0]; /* reserved for extension */
|
||||
#endif
|
||||
} IOSTREAM;
|
||||
|
||||
#define SmakeFlag(n) (1<<(n-1))
|
||||
|
||||
#define SIO_FBUF SmakeFlag(1) /* full buffering */
|
||||
#define SIO_LBUF SmakeFlag(2) /* line buffering */
|
||||
#define SIO_NBUF SmakeFlag(3) /* no buffering */
|
||||
#define SIO_FEOF SmakeFlag(4) /* end-of-file */
|
||||
#define SIO_FERR SmakeFlag(5) /* error ocurred */
|
||||
#define SIO_USERBUF SmakeFlag(6) /* buffer is from user */
|
||||
#define SIO_INPUT SmakeFlag(7) /* input stream */
|
||||
#define SIO_OUTPUT SmakeFlag(8) /* output stream */
|
||||
#define SIO_NOLINENO SmakeFlag(9) /* line no. info is void */
|
||||
#define SIO_NOLINEPOS SmakeFlag(10) /* line pos is void */
|
||||
#define SIO_STATIC SmakeFlag(11) /* Stream in static memory */
|
||||
#define SIO_RECORDPOS SmakeFlag(12) /* Maintain position */
|
||||
#define SIO_FILE SmakeFlag(13) /* Stream refers to an OS file */
|
||||
#define SIO_PIPE SmakeFlag(14) /* Stream refers to an OS pipe */
|
||||
#define SIO_NOFEOF SmakeFlag(15) /* don't set SIO_FEOF flag */
|
||||
#define SIO_TEXT SmakeFlag(16) /* text-mode operation */
|
||||
#define SIO_FEOF2 SmakeFlag(17) /* attempt to read past eof */
|
||||
#define SIO_FEOF2ERR SmakeFlag(18) /* Sfpasteof() */
|
||||
#define SIO_NOCLOSE SmakeFlag(19) /* Do not close on abort */
|
||||
#define SIO_APPEND SmakeFlag(20) /* opened in append-mode */
|
||||
#define SIO_UPDATE SmakeFlag(21) /* opened in update-mode */
|
||||
#define SIO_ISATTY SmakeFlag(22) /* Stream is a tty */
|
||||
#define SIO_CLOSING SmakeFlag(23) /* We are closing the stream */
|
||||
#define SIO_TIMEOUT SmakeFlag(24) /* We had a timeout */
|
||||
#define SIO_NOMUTEX SmakeFlag(25) /* Do not allow multi-thread access */
|
||||
#define SIO_ADVLOCK SmakeFlag(26) /* File locked with advisory lock */
|
||||
#define SIO_WARN SmakeFlag(27) /* Pending warning */
|
||||
#define SIO_CLEARERR SmakeFlag(28) /* Clear error after reporting */
|
||||
#define SIO_REPXML SmakeFlag(29) /* Bad char --> XML entity */
|
||||
#define SIO_REPPL SmakeFlag(30) /* Bad char --> Prolog \hex\ */
|
||||
#define SIO_BOM SmakeFlag(31) /* BOM was detected/written */
|
||||
|
||||
#define SIO_SEEK_SET 0 /* From beginning of file. */
|
||||
#define SIO_SEEK_CUR 1 /* From current position. */
|
||||
#define SIO_SEEK_END 2 /* From end of file. */
|
||||
|
||||
PL_EXPORT(IOSTREAM *) S__getiob(void); /* get DLL's __iob[] address */
|
||||
|
||||
PL_EXPORT_DATA(IOFUNCTIONS) Sfilefunctions; /* OS file functions */
|
||||
PL_EXPORT_DATA(int) Slinesize; /* Sgets() linesize */
|
||||
#if (defined(__CYGWIN__) || defined(__MINGW32__)) && !defined(PL_KERNEL)
|
||||
#define S__iob S__getiob()
|
||||
#else
|
||||
PL_EXPORT_DATA(IOSTREAM) S__iob[3]; /* Libs standard streams */
|
||||
#endif
|
||||
|
||||
#define Sinput (&S__iob[0]) /* Stream Sinput */
|
||||
#define Soutput (&S__iob[1]) /* Stream Soutput */
|
||||
#define Serror (&S__iob[2]) /* Stream Serror */
|
||||
|
||||
#define Sgetchar() Sgetc(Sinput)
|
||||
#define Sputchar(c) Sputc((c), Soutput)
|
||||
|
||||
static inline void
|
||||
S__checkpasteeof(IOSTREAM *s, int c)
|
||||
{
|
||||
if ( (c)==-1 && ((s)->flags & (SIO_FEOF|SIO_FERR)) )
|
||||
((s)->flags |= SIO_FEOF2);
|
||||
}
|
||||
|
||||
#define S__updatefilepos_getc(s, c) \
|
||||
((s)->position ? S__fupdatefilepos_getc((s), (c)) \
|
||||
: S__fcheckpasteeof((s), (c)))
|
||||
|
||||
#define Snpgetc(s) ((s)->bufp < (s)->limitp ? (int)(*(s)->bufp++)&0xff \
|
||||
: S__fillbuf(s))
|
||||
#define Sgetc(s) S__updatefilepos_getc((s), Snpgetc(s))
|
||||
|
||||
PL_EXPORT(int) Speekcode(IOSTREAM *s);
|
||||
|
||||
/* Control-operations */
|
||||
#define SIO_GETSIZE (1) /* get size of underlying object */
|
||||
#define SIO_GETFILENO (2) /* get underlying file (if any) */
|
||||
#define SIO_SETENCODING (3) /* modify encoding of stream */
|
||||
#define SIO_FLUSHOUTPUT (4) /* flush output */
|
||||
#define SIO_LASTERROR (5) /* string holding last error */
|
||||
#ifdef __WINDOWS__
|
||||
#define SIO_GETWINSOCK (6) /* get underlying SOCKET object */
|
||||
#endif
|
||||
|
||||
/* Sread_pending() */
|
||||
#define SIO_RP_BLOCK 0x1 /* wait for new input */
|
||||
|
||||
#if IOSTREAM_REPLACES_STDIO
|
||||
|
||||
#undef FILE
|
||||
#undef stdin
|
||||
#undef stdout
|
||||
#undef stderr
|
||||
#undef putc
|
||||
#undef getc
|
||||
#undef putchar
|
||||
#undef getchar
|
||||
#undef feof
|
||||
#undef ferror
|
||||
#undef fileno
|
||||
#undef clearerr
|
||||
|
||||
#define FILE IOSTREAM
|
||||
#define stdin Sinput
|
||||
#define stdout Soutput
|
||||
#define stderr Serror
|
||||
|
||||
#define putc Sputc
|
||||
#define getc Sgetc
|
||||
#define fputc Sputc
|
||||
#define fgetc Sgetc
|
||||
#define getw Sgetw
|
||||
#define putw Sputw
|
||||
#define fread Sfread
|
||||
#define fwrite Sfwrite
|
||||
#define ungetc Sungetc
|
||||
#define putchar Sputchar
|
||||
#define getchar Sgetchar
|
||||
#define feof Sfeof
|
||||
#define ferror Sferror
|
||||
#define clearerr Sclearerr
|
||||
#define fflush Sflush
|
||||
#define fseek Sseek
|
||||
#define ftell Stell
|
||||
#define fclose Sclose
|
||||
#define fgets Sfgets
|
||||
#define gets Sgets
|
||||
#define fputs Sfputs
|
||||
#define puts Sputs
|
||||
#define fprintf Sfprintf
|
||||
#define printf Sprintf
|
||||
#define vprintf Svprintf
|
||||
#define vfprintf Svfprintf
|
||||
#define sprintf Ssprintf
|
||||
#define vsprintf Svsprintf
|
||||
#define fopen Sopen_file
|
||||
#define fdopen Sfdopen
|
||||
#define fileno Sfileno
|
||||
#define popen Sopen_pipe
|
||||
|
||||
#endif /*IOSTREAM_REPLACES_STDIO*/
|
||||
|
||||
/*******************************
|
||||
* PROTOTYPES *
|
||||
*******************************/
|
||||
|
||||
PL_EXPORT(void) SinitStreams(void);
|
||||
PL_EXPORT(void) Scleanup(void);
|
||||
PL_EXPORT(void) Sreset(void);
|
||||
PL_EXPORT(int) S__fupdatefilepos_getc(IOSTREAM *s, int c);
|
||||
PL_EXPORT(int) S__fcheckpasteeof(IOSTREAM *s, int c);
|
||||
PL_EXPORT(int) S__fillbuf(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sunit_size(IOSTREAM *s);
|
||||
/* byte I/O */
|
||||
PL_EXPORT(int) Sputc(int c, IOSTREAM *s);
|
||||
PL_EXPORT(int) Sfgetc(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sungetc(int c, IOSTREAM *s);
|
||||
/* multibyte I/O */
|
||||
PL_EXPORT(int) Scanrepresent(int c, IOSTREAM *s);
|
||||
PL_EXPORT(int) Sputcode(int c, IOSTREAM *s);
|
||||
PL_EXPORT(int) Sgetcode(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sungetcode(int c, IOSTREAM *s);
|
||||
/* word I/O */
|
||||
PL_EXPORT(int) Sputw(int w, IOSTREAM *s);
|
||||
PL_EXPORT(int) Sgetw(IOSTREAM *s);
|
||||
PL_EXPORT(size_t) Sfread(void *data, size_t size, size_t elems,
|
||||
IOSTREAM *s);
|
||||
PL_EXPORT(size_t) Sfwrite(const void *data, size_t size, size_t elems,
|
||||
IOSTREAM *s);
|
||||
PL_EXPORT(int) Sfeof(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sfpasteof(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sferror(IOSTREAM *s);
|
||||
PL_EXPORT(void) Sclearerr(IOSTREAM *s);
|
||||
PL_EXPORT(void) Sseterr(IOSTREAM *s, int which, const char *message);
|
||||
PL_EXPORT(void) Sset_exception(IOSTREAM *s, term_t ex);
|
||||
PL_EXPORT(int) Ssetenc(IOSTREAM *s, IOENC new_enc, IOENC *old_enc);
|
||||
PL_EXPORT(int) Sflush(IOSTREAM *s);
|
||||
PL_EXPORT(int64_t) Ssize(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sseek(IOSTREAM *s, long pos, int whence);
|
||||
PL_EXPORT(long) Stell(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sclose(IOSTREAM *s);
|
||||
PL_EXPORT(char *) Sfgets(char *buf, int n, IOSTREAM *s);
|
||||
PL_EXPORT(char *) Sgets(char *buf);
|
||||
PL_EXPORT(ssize_t) Sread_pending(IOSTREAM *s,
|
||||
char *buf, size_t limit, int flags);
|
||||
PL_EXPORT(int) Sfputs(const char *q, IOSTREAM *s);
|
||||
PL_EXPORT(int) Sputs(const char *q);
|
||||
PL_EXPORT(int) Sfprintf(IOSTREAM *s, const char *fm, ...);
|
||||
PL_EXPORT(int) Sprintf(const char *fm, ...);
|
||||
PL_EXPORT(int) Svprintf(const char *fm, va_list args);
|
||||
PL_EXPORT(int) Svfprintf(IOSTREAM *s, const char *fm, va_list args);
|
||||
PL_EXPORT(int) Ssprintf(char *buf, const char *fm, ...);
|
||||
PL_EXPORT(int) Svsprintf(char *buf, const char *fm, va_list args);
|
||||
PL_EXPORT(int) Svdprintf(const char *fm, va_list args);
|
||||
PL_EXPORT(int) Sdprintf(const char *fm, ...);
|
||||
PL_EXPORT(int) Slock(IOSTREAM *s);
|
||||
PL_EXPORT(int) StryLock(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sunlock(IOSTREAM *s);
|
||||
PL_EXPORT(IOSTREAM *) Snew(void *handle, int flags, IOFUNCTIONS *functions);
|
||||
PL_EXPORT(IOSTREAM *) Sopen_file(const char *path, const char *how);
|
||||
PL_EXPORT(IOSTREAM *) Sfdopen(int fd, const char *type);
|
||||
PL_EXPORT(int) Sfileno(IOSTREAM *s);
|
||||
PL_EXPORT(IOSTREAM *) Sopen_pipe(const char *command, const char *type);
|
||||
PL_EXPORT(IOSTREAM *) Sopenmem(char **buffer, size_t *sizep, const char *mode);
|
||||
PL_EXPORT(IOSTREAM *) Sopen_string(IOSTREAM *s, char *buf, size_t sz, const char *m);
|
||||
PL_EXPORT(int) Sclosehook(void (*hook)(IOSTREAM *s));
|
||||
PL_EXPORT(void) Sfree(void *ptr);
|
||||
PL_EXPORT(int) Sset_filter(IOSTREAM *parent, IOSTREAM *filter);
|
||||
PL_EXPORT(void) Ssetbuffer(IOSTREAM *s, char *buf, size_t size);
|
||||
|
||||
PL_EXPORT(int64_t) Stell64(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sseek64(IOSTREAM *s, int64_t pos, int whence);
|
||||
|
||||
PL_EXPORT(int) Ssetlocale(IOSTREAM *s, struct PL_locale *n, struct PL_locale **old);
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#if defined(_WINSOCKAPI_) || defined(NEEDS_SWINSOCK)
|
||||
PL_EXPORT(SOCKET) Swinsock(IOSTREAM *s);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
PL_EXPORT(int) ScheckBOM(IOSTREAM *s);
|
||||
PL_EXPORT(int) SwriteBOM(IOSTREAM *s);
|
||||
PL_EXPORT(ssize_t) Sread_user(void *handle, char *buf, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_PL_STREAM_H*/
|
||||
|
||||
#ifndef _PL_STREAM_H
|
||||
#define _PL_STREAM_H
|
||||
|
||||
#ifndef _PL_EXPORT_DONE
|
||||
#define _PL_EXPORT_DONE
|
||||
|
||||
#if (defined(__WINDOWS__) || defined(__CYGWIN__)) && !defined(__LCC__)
|
||||
#define HAVE_DECLSPEC
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DECLSPEC
|
||||
# ifdef PL_KERNEL
|
||||
#define PL_EXPORT(type) __declspec(dllexport) type
|
||||
#define PL_EXPORT_DATA(type) __declspec(dllexport) type
|
||||
#define install_t void
|
||||
# else
|
||||
# ifdef __BORLANDC__
|
||||
#define PL_EXPORT(type) type _stdcall
|
||||
#define PL_EXPORT_DATA(type) extern type
|
||||
# else
|
||||
#define PL_EXPORT(type) extern type
|
||||
#define PL_EXPORT_DATA(type) __declspec(dllimport) type
|
||||
# endif
|
||||
#define install_t __declspec(dllexport) void
|
||||
# endif
|
||||
#else /*HAVE_DECLSPEC*/
|
||||
#define PL_EXPORT(type) extern type
|
||||
#define PL_EXPORT_DATA(type) extern type
|
||||
#define install_t void
|
||||
#endif /*HAVE_DECLSPEC*/
|
||||
#endif /*_PL_EXPORT_DONE*/
|
||||
|
||||
/* This appears to make the wide-character support compile and work
|
||||
on HPUX 11.23. There really should be a cleaner way ...
|
||||
*/
|
||||
#if defined(__hpux)
|
||||
#include <sys/_mbstate_t.h>
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__WINDOWS__)
|
||||
#define __WINDOWS__ 1
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include <stddef.h>
|
||||
#ifdef __WINDOWS__
|
||||
#include <stdint.h>
|
||||
#ifndef INT64_T_DEFINED
|
||||
#define INT64_T_DEFINED 1
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#endif
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h> /* more portable than stdint.h */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef PL_HAVE_TERM_T
|
||||
#define PL_HAVE_TERM_T
|
||||
typedef intptr_t term_t;
|
||||
#endif
|
||||
/*******************************
|
||||
* CONSTANTS *
|
||||
*******************************/
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#if defined(__WINDOWS__) && !defined(EWOULDBLOCK)
|
||||
#define EWOULDBLOCK 1000 /* Needed for socket handling */
|
||||
#endif
|
||||
#define EPLEXCEPTION 1001 /* errno: pending Prolog exception */
|
||||
|
||||
#define SIO_BUFSIZE (4096) /* buffering buffer-size */
|
||||
#define SIO_LINESIZE (1024) /* Sgets() default buffer size */
|
||||
#define SIO_MAGIC (7212676) /* magic number */
|
||||
#define SIO_CMAGIC (42) /* we are close (and thus illegal!) */
|
||||
|
||||
typedef ssize_t (*Sread_function)(void *handle, char *buf, size_t bufsize);
|
||||
typedef ssize_t (*Swrite_function)(void *handle, char*buf, size_t bufsize);
|
||||
typedef long (*Sseek_function)(void *handle, long pos, int whence);
|
||||
typedef int64_t (*Sseek64_function)(void *handle, int64_t pos, int whence);
|
||||
typedef int (*Sclose_function)(void *handle);
|
||||
typedef int (*Scontrol_function)(void *handle, int action, void *arg);
|
||||
|
||||
#include "pl-thread.h"
|
||||
|
||||
typedef struct io_functions
|
||||
{ Sread_function read; /* fill the buffer */
|
||||
Swrite_function write; /* empty the buffer */
|
||||
Sseek_function seek; /* seek to position */
|
||||
Sclose_function close; /* close stream */
|
||||
Scontrol_function control; /* Info/control */
|
||||
Sseek64_function seek64; /* seek to position (intptr_t files) */
|
||||
} IOFUNCTIONS;
|
||||
|
||||
typedef struct io_position
|
||||
{ int64_t byteno; /* byte-position in file */
|
||||
int64_t charno; /* character position in file */
|
||||
long int lineno; /* lineno in file */
|
||||
long int linepos; /* position in line */
|
||||
intptr_t reserved[2]; /* future extensions */
|
||||
} IOPOS;
|
||||
|
||||
#if defined(YAP_H)
|
||||
typedef encoding_t IOENC;
|
||||
#else
|
||||
/* NOTE: check with encoding_names */
|
||||
/* in pl-file.c */
|
||||
typedef enum
|
||||
{ ENC_UNKNOWN = 0, /* invalid/unknown */
|
||||
ENC_OCTET, /* raw 8 bit input */
|
||||
ENC_ASCII, /* US-ASCII (0..127) */
|
||||
ENC_ISO_LATIN_1, /* ISO Latin-1 (0..256) */
|
||||
ENC_ANSI, /* default (multibyte) codepage */
|
||||
ENC_UTF8,
|
||||
ENC_UNICODE_BE, /* big endian unicode file */
|
||||
ENC_UNICODE_LE, /* little endian unicode file */
|
||||
ENC_WCHAR /* pl_wchar_t */
|
||||
} IOENC;
|
||||
#endif
|
||||
|
||||
#define SIO_NL_POSIX 0 /* newline as \n */
|
||||
#define SIO_NL_DOS 1 /* newline as \r\n */
|
||||
#define SIO_NL_DETECT 3 /* detect processing mode */
|
||||
|
||||
typedef struct io_stream
|
||||
{ char *bufp; /* `here' */
|
||||
char *limitp; /* read/write limit */
|
||||
char *buffer; /* the buffer */
|
||||
char *unbuffer; /* Sungetc buffer */
|
||||
int lastc; /* last character written */
|
||||
int magic; /* magic number SIO_MAGIC */
|
||||
int bufsize; /* size of the buffer */
|
||||
int flags; /* Status flags */
|
||||
IOPOS posbuf; /* location in file */
|
||||
IOPOS * position; /* pointer to above */
|
||||
void *handle; /* function's handle */
|
||||
IOFUNCTIONS *functions; /* open/close/read/write/seek */
|
||||
int locks; /* lock/unlock count */
|
||||
IOLOCK * mutex; /* stream mutex */
|
||||
/* SWI-Prolog 4.0.7 */
|
||||
void (*close_hook)(void* closure);
|
||||
void * closure;
|
||||
/* SWI-Prolog 5.1.3 */
|
||||
int timeout; /* timeout (milliseconds) */
|
||||
/* SWI-Prolog 5.4.4 */
|
||||
char * message; /* error/warning message */
|
||||
IOENC encoding; /* character encoding used */
|
||||
struct io_stream * tee; /* copy data to this stream */
|
||||
mbstate_t * mbstate; /* ENC_ANSI decoding */
|
||||
struct io_stream * upstream; /* stream providing our input */
|
||||
struct io_stream * downstream; /* stream providing our output */
|
||||
unsigned newline : 2; /* Newline mode */
|
||||
unsigned erased : 1; /* Stream was erased */
|
||||
unsigned references : 4; /* Reference-count */
|
||||
int io_errno; /* Save errno value */
|
||||
void * exception; /* pending exception (record_t) */
|
||||
void * context; /* getStreamContext() */
|
||||
intptr_t reserved[0]; /* reserved for extension */
|
||||
struct PL_locale * locale; /* Locale associated to stream */
|
||||
#if 0 /* We used them all :-( */
|
||||
intptr_t reserved[0]; /* reserved for extension */
|
||||
#endif
|
||||
} IOSTREAM;
|
||||
|
||||
#define SmakeFlag(n) (1<<(n-1))
|
||||
|
||||
#define SIO_FBUF SmakeFlag(1) /* full buffering */
|
||||
#define SIO_LBUF SmakeFlag(2) /* line buffering */
|
||||
#define SIO_NBUF SmakeFlag(3) /* no buffering */
|
||||
#define SIO_FEOF SmakeFlag(4) /* end-of-file */
|
||||
#define SIO_FERR SmakeFlag(5) /* error ocurred */
|
||||
#define SIO_USERBUF SmakeFlag(6) /* buffer is from user */
|
||||
#define SIO_INPUT SmakeFlag(7) /* input stream */
|
||||
#define SIO_OUTPUT SmakeFlag(8) /* output stream */
|
||||
#define SIO_NOLINENO SmakeFlag(9) /* line no. info is void */
|
||||
#define SIO_NOLINEPOS SmakeFlag(10) /* line pos is void */
|
||||
#define SIO_STATIC SmakeFlag(11) /* Stream in static memory */
|
||||
#define SIO_RECORDPOS SmakeFlag(12) /* Maintain position */
|
||||
#define SIO_FILE SmakeFlag(13) /* Stream refers to an OS file */
|
||||
#define SIO_PIPE SmakeFlag(14) /* Stream refers to an OS pipe */
|
||||
#define SIO_NOFEOF SmakeFlag(15) /* don't set SIO_FEOF flag */
|
||||
#define SIO_TEXT SmakeFlag(16) /* text-mode operation */
|
||||
#define SIO_FEOF2 SmakeFlag(17) /* attempt to read past eof */
|
||||
#define SIO_FEOF2ERR SmakeFlag(18) /* Sfpasteof() */
|
||||
#define SIO_NOCLOSE SmakeFlag(19) /* Do not close on abort */
|
||||
#define SIO_APPEND SmakeFlag(20) /* opened in append-mode */
|
||||
#define SIO_UPDATE SmakeFlag(21) /* opened in update-mode */
|
||||
#define SIO_ISATTY SmakeFlag(22) /* Stream is a tty */
|
||||
#define SIO_CLOSING SmakeFlag(23) /* We are closing the stream */
|
||||
#define SIO_TIMEOUT SmakeFlag(24) /* We had a timeout */
|
||||
#define SIO_NOMUTEX SmakeFlag(25) /* Do not allow multi-thread access */
|
||||
#define SIO_ADVLOCK SmakeFlag(26) /* File locked with advisory lock */
|
||||
#define SIO_WARN SmakeFlag(27) /* Pending warning */
|
||||
#define SIO_CLEARERR SmakeFlag(28) /* Clear error after reporting */
|
||||
#define SIO_REPXML SmakeFlag(29) /* Bad char --> XML entity */
|
||||
#define SIO_REPPL SmakeFlag(30) /* Bad char --> Prolog \hex\ */
|
||||
#define SIO_BOM SmakeFlag(31) /* BOM was detected/written */
|
||||
|
||||
#define SIO_SEEK_SET 0 /* From beginning of file. */
|
||||
#define SIO_SEEK_CUR 1 /* From current position. */
|
||||
#define SIO_SEEK_END 2 /* From end of file. */
|
||||
|
||||
PL_EXPORT(IOSTREAM *) S__getiob(void); /* get DLL's __iob[] address */
|
||||
|
||||
PL_EXPORT_DATA(IOFUNCTIONS) Sfilefunctions; /* OS file functions */
|
||||
PL_EXPORT_DATA(int) Slinesize; /* Sgets() linesize */
|
||||
#if (defined(__CYGWIN__) || defined(__MINGW32__)) && !defined(PL_KERNEL)
|
||||
#define S__iob S__getiob()
|
||||
#else
|
||||
PL_EXPORT_DATA(IOSTREAM) S__iob[3]; /* Libs standard streams */
|
||||
#endif
|
||||
|
||||
#define Sinput (&S__iob[0]) /* Stream Sinput */
|
||||
#define Soutput (&S__iob[1]) /* Stream Soutput */
|
||||
#define Serror (&S__iob[2]) /* Stream Serror */
|
||||
|
||||
#define Sgetchar() Sgetc(Sinput)
|
||||
#define Sputchar(c) Sputc((c), Soutput)
|
||||
|
||||
static inline void
|
||||
S__checkpasteeof(IOSTREAM *s, int c)
|
||||
{
|
||||
if ( (c)==-1 && ((s)->flags & (SIO_FEOF|SIO_FERR)) )
|
||||
((s)->flags |= SIO_FEOF2);
|
||||
}
|
||||
|
||||
#define S__updatefilepos_getc(s, c) \
|
||||
((s)->position ? S__fupdatefilepos_getc((s), (c)) \
|
||||
: S__fcheckpasteeof((s), (c)))
|
||||
|
||||
#define Snpgetc(s) ((s)->bufp < (s)->limitp ? (int)(*(s)->bufp++)&0xff \
|
||||
: S__fillbuf(s))
|
||||
#define Sgetc(s) S__updatefilepos_getc((s), Snpgetc(s))
|
||||
|
||||
PL_EXPORT(int) Speekcode(IOSTREAM *s);
|
||||
|
||||
/* Control-operations */
|
||||
#define SIO_GETSIZE (1) /* get size of underlying object */
|
||||
#define SIO_GETFILENO (2) /* get underlying file (if any) */
|
||||
#define SIO_SETENCODING (3) /* modify encoding of stream */
|
||||
#define SIO_FLUSHOUTPUT (4) /* flush output */
|
||||
#define SIO_LASTERROR (5) /* string holding last error */
|
||||
#ifdef __WINDOWS__
|
||||
#define SIO_GETWINSOCK (6) /* get underlying SOCKET object */
|
||||
#endif
|
||||
|
||||
/* Sread_pending() */
|
||||
#define SIO_RP_BLOCK 0x1 /* wait for new input */
|
||||
|
||||
#if IOSTREAM_REPLACES_STDIO
|
||||
|
||||
#undef FILE
|
||||
#undef stdin
|
||||
#undef stdout
|
||||
#undef stderr
|
||||
#undef putc
|
||||
#undef getc
|
||||
#undef putchar
|
||||
#undef getchar
|
||||
#undef feof
|
||||
#undef ferror
|
||||
#undef fileno
|
||||
#undef clearerr
|
||||
|
||||
#define FILE IOSTREAM
|
||||
#define stdin Sinput
|
||||
#define stdout Soutput
|
||||
#define stderr Serror
|
||||
|
||||
#define putc Sputc
|
||||
#define getc Sgetc
|
||||
#define fputc Sputc
|
||||
#define fgetc Sgetc
|
||||
#define getw Sgetw
|
||||
#define putw Sputw
|
||||
#define fread Sfread
|
||||
#define fwrite Sfwrite
|
||||
#define ungetc Sungetc
|
||||
#define putchar Sputchar
|
||||
#define getchar Sgetchar
|
||||
#define feof Sfeof
|
||||
#define ferror Sferror
|
||||
#define clearerr Sclearerr
|
||||
#define fflush Sflush
|
||||
#define fseek Sseek
|
||||
#define ftell Stell
|
||||
#define fclose Sclose
|
||||
#define fgets Sfgets
|
||||
#define gets Sgets
|
||||
#define fputs Sfputs
|
||||
#define puts Sputs
|
||||
#define fprintf Sfprintf
|
||||
#define printf Sprintf
|
||||
#define vprintf Svprintf
|
||||
#define vfprintf Svfprintf
|
||||
#define sprintf Ssprintf
|
||||
#define vsprintf Svsprintf
|
||||
#define fopen Sopen_file
|
||||
#define fdopen Sfdopen
|
||||
#define fileno Sfileno
|
||||
Svdprintf(const char *fm, va_list args);
|
||||
PL_EXPORT(int) Sdprintf(const char *fm, ...);
|
||||
PL_EXPORT(int) Slock(IOSTREAM *s);
|
||||
PL_EXPORT(int) StryLock(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sunlock(IOSTREAM *s);
|
||||
PL_EXPORT(IOSTREAM *) Snew(void *handle, int flags, IOFUNCTIONS *functions);
|
||||
PL_EXPORT(IOSTREAM *) Sopen_file(const char *path, const char *how);
|
||||
PL_EXPORT(IOSTREAM *) Sfdopen(int fd, const char *type);
|
||||
PL_EXPORT(int) Sfileno(IOSTREAM *s);
|
||||
PL_EXPORT(IOSTREAM *) Sopen_pipe(const char *command, const char *type);
|
||||
PL_EXPORT(IOSTREAM *) Sopenmem(char **buffer, size_t *sizep, const char *mode);
|
||||
PL_EXPORT(IOSTREAM *) Sopen_string(IOSTREAM *s, char *buf, size_t sz, const char *m);
|
||||
PL_EXPORT(int) Sclosehook(void (*hook)(IOSTREAM *s));
|
||||
PL_EXPORT(void) Sfree(void *ptr);
|
||||
PL_EXPORT(int) Sset_filter(IOSTREAM *parent, IOSTREAM *filter);
|
||||
PL_EXPORT(void) Ssetbuffer(IOSTREAM *s, char *buf, size_t size);
|
||||
|
||||
PL_EXPORT(int64_t) Stell64(IOSTREAM *s);
|
||||
PL_EXPORT(int) Sseek64(IOSTREAM *s, int64_t pos, int whence);
|
||||
|
||||
PL_EXPORT(int) Ssetlocale(IOSTREAM *s, struct PL_locale *n, struct PL_locale **old);
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#if defined(_WINSOCKAPI_) || defined(NEEDS_SWINSOCK)
|
||||
PL_EXPORT(SOCKET) Swinsock(IOSTREAM *s);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
PL_EXPORT(int) ScheckBOM(IOSTREAM *s);
|
||||
PL_EXPORT(int) SwriteBOM(IOSTREAM *s);
|
||||
PL_EXPORT(ssize_t) Sread_user(void *handle, char *buf, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /*_PL_STREAM_H*/
|
@ -445,7 +445,7 @@ error:
|
||||
|
||||
|
||||
|
||||
/** @pred char_type(? _Char_, ? _Type_)
|
||||
/** @pred char_type(? _Char_, ? _Type_)
|
||||
|
||||
|
||||
Like code_type/2, tests or generates alternative _Types_ or
|
||||
@ -461,7 +461,7 @@ PRED_IMPL("char_type", 2, char_type, PL_FA_NONDETERMINISTIC)
|
||||
}
|
||||
|
||||
|
||||
/** @pred code_type(? _Char_, ? _Type_)
|
||||
/** @pred code_type(? _Char_, ? _Type_)
|
||||
|
||||
|
||||
Tests or generates alternative _Types_ or _Chars_. The
|
||||
@ -488,7 +488,7 @@ character-types are inspired by the standard `C`
|
||||
|
||||
+ `cntrl`
|
||||
_Char_ is an ASCII control-character (0..31).
|
||||
|
||||
|
||||
+ `digit`
|
||||
_Char_ is a digit.
|
||||
|
||||
@ -541,7 +541,7 @@ character-types are inspired by the standard `C`
|
||||
_Char_ is a quote-character.
|
||||
|
||||
+ `paren(Close)`
|
||||
_Char_ is an open-parenthesis and Close is the corresponding close-parenthesis.
|
||||
_Char_ is an open-parenthesis and Close is the corresponding close-parenthesis.
|
||||
|
||||
|
||||
+ `code_type(? _Code_, ? _Type_)`
|
||||
@ -552,7 +552,7 @@ one-character atoms. Please note that both predicates are as
|
||||
flexible as possible. They handle either representation if the
|
||||
argument is instantiated and only will instantiate with an integer
|
||||
code or one-character atom depending of the version used. See also
|
||||
the prolog-flag double_quotes and the built-in predicates
|
||||
the prolog-flag double_quotes and the built-in predicates
|
||||
atom_chars/2 and atom_codes/2.
|
||||
|
||||
|
||||
@ -718,7 +718,7 @@ modify_case_atom(term_t in, term_t out, int down)
|
||||
}
|
||||
|
||||
|
||||
/** @pred downcase_atom(+ _Word_, - _LowerCaseWord_)
|
||||
/** @pred downcase_atom(+ _Word_, - _LowerCaseWord_)
|
||||
|
||||
If the first argument is bound to an atom _Word_, the
|
||||
second argument shoud unify with an atom such that all alphabetic cdes
|
||||
@ -733,7 +733,7 @@ PRED_IMPL("downcase_atom", 2, downcase_atom, 0)
|
||||
{ return modify_case_atom(A1, A2, TRUE);
|
||||
}
|
||||
|
||||
/** @pred upcase_atom(+ _Word_, - _UpCaseWord_)
|
||||
/** @pred upcase_atom(+ _Word_, - _UpCaseWord_)
|
||||
|
||||
If the first argument is bound to an atom _Word_, the
|
||||
second argument shoud unify with an atom such that all alphabetic cdes
|
||||
@ -787,7 +787,7 @@ write_normalize_space(IOSTREAM *out, term_t in)
|
||||
}
|
||||
|
||||
|
||||
/** @pred normalize_space(- _Out_, + _In_)
|
||||
/** @pred normalize_space(- _Out_, + _In_)
|
||||
|
||||
Remove white space at the beginning an end of the word _In_, and replace
|
||||
sequences of white space in the middle of _In_ by a single white
|
||||
@ -881,7 +881,7 @@ static lccat lccats[] =
|
||||
|
||||
/// @}
|
||||
|
||||
/** @pred setlocale( + _In_, - _Old_, -_New_)
|
||||
/** @pred setlocale( + _In_, - _Old_, -_New_)
|
||||
|
||||
*/
|
||||
|
@ -158,7 +158,7 @@ PL_unify_list_ex(term_t l, term_t h, term_t t)
|
||||
|
||||
if ( PL_get_nil(l) )
|
||||
fail;
|
||||
|
||||
|
||||
return PL_error(NULL, 0, NULL, ERR_TYPE, ATOM_list, l);
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ PL_get_list_ex(term_t l, term_t h, term_t t)
|
||||
|
||||
if ( PL_get_nil(l) )
|
||||
fail;
|
||||
|
||||
|
||||
return PL_error(NULL, 0, NULL, ERR_TYPE, ATOM_list, l);
|
||||
}
|
||||
|
||||
@ -405,7 +405,7 @@ int PL_error(const char *pred, int arity, const char *msg, PL_error_code id, ...
|
||||
case ERR_TYPE: /* ERR_INSTANTIATION if var(actual) */
|
||||
{ atom_t expected = va_arg(args, atom_t);
|
||||
term_t actual = va_arg(args, term_t);
|
||||
|
||||
|
||||
if ( PL_is_variable(actual) && expected != ATOM_variable )
|
||||
goto err_instantiation;
|
||||
|
@ -22,6 +22,9 @@
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PL_ERROR_H
|
||||
#define PL_ERROR_H 1
|
||||
|
||||
#ifndef COMMON
|
||||
#define COMMON(type) extern type
|
||||
#endif
|
||||
@ -88,3 +91,4 @@ COMMON(int) PL_get_module_ex(term_t name, module_t *m);
|
||||
COMMON(int) PL_get_arg_ex(int n, term_t term, term_t arg);
|
||||
COMMON(int) check_float(double f);
|
||||
|
||||
#endif
|
@ -5784,70 +5784,6 @@ EndPredDefs
|
||||
|
||||
#if __YAP_PROLOG__
|
||||
|
||||
void Yap_flush(void)
|
||||
{
|
||||
GET_LD
|
||||
flush_output(0 PASS_LD);
|
||||
}
|
||||
|
||||
void *
|
||||
Yap_GetStreamHandle(Atom at)
|
||||
{ GET_LD
|
||||
atom_t a;
|
||||
IOSTREAM *s;
|
||||
|
||||
a = YAP_SWIAtomFromAtom(at);
|
||||
if (!get_stream_handle(a, &s, SH_ERRORS|SH_ALIAS))
|
||||
return NULL;
|
||||
return s;
|
||||
}
|
||||
|
||||
void *Yap_GetInputStream(Atom at)
|
||||
{ GET_LD
|
||||
atom_t a;
|
||||
IOSTREAM *s;
|
||||
if ( at == AtomUser ) {
|
||||
if ( (s = getStream(Suser_input)) )
|
||||
return s;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
a = YAP_SWIAtomFromAtom(at);
|
||||
if ( !get_stream_handle(a, &s, SH_ERRORS|SH_ALIAS|SH_INPUT) )
|
||||
return NULL;
|
||||
|
||||
if ( !(s->flags &SIO_INPUT) )
|
||||
{ releaseStream(s);
|
||||
return Yap_Error(PERMISSION_ERROR_INPUT_STREAM, MkAtomTerm(at),
|
||||
"read or ql");
|
||||
return NULL;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void *Yap_GetOutputStream(Atom at)
|
||||
{ GET_LD
|
||||
atom_t a;
|
||||
IOSTREAM *s;
|
||||
if ( at == AtomUser ) {
|
||||
if ( (s = getStream(Suser_output)) )
|
||||
return s;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
a = YAP_SWIAtomFromAtom(at);
|
||||
if ( !get_stream_handle(a, &s, SH_ERRORS|SH_ALIAS|SH_OUTPUT) )
|
||||
return NULL;
|
||||
|
||||
if ( !(s->flags &SIO_OUTPUT) )
|
||||
{ releaseStream(s);
|
||||
return Yap_Error(PERMISSION_ERROR_OUTPUT_STREAM, MkAtomTerm(at),
|
||||
"write or ql");
|
||||
return NULL;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static int
|
||||
pl_get_time(term_t t)
|
||||
{ return PL_unify_float(t, WallTime());
|
@ -580,10 +580,10 @@ sort_expand(GlobInfo info)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@addgroup
|
||||
|
||||
\pred expand_file_name(+ _WildCard_,- _List_)
|
||||
@addgroup
|
||||
|
||||
\pred expand_file_name(+ _WildCard_,- _List_)
|
||||
|
||||
|
||||
This is an SWI-Prolog built-in that unifies _List_ with a sorted list of
|
@ -22,7 +22,7 @@
|
||||
|
||||
/** @defgroup SetLocale Localization Support
|
||||
* @ingroup InputOutput
|
||||
* @{
|
||||
* @{
|
||||
*
|
||||
* This code includes support for localization, that is, the ability to support
|
||||
* different languages and representation formats.
|
||||
@ -62,7 +62,7 @@ static struct lconv defl =
|
||||
|
||||
struct lconv *
|
||||
localeconv(void)
|
||||
{
|
||||
{
|
||||
return &defl;
|
||||
}
|
||||
#endif
|
@ -874,7 +874,7 @@ static folderid *folderids;
|
||||
|
||||
// do nothing the first step
|
||||
static void
|
||||
in(REFKNOWNFOLDERID idp, char *name, int i)
|
||||
in(REFKNOWNFOLDERID idp, char *name, int i)
|
||||
{
|
||||
if (folderids) {
|
||||
folderids[i].csidl = (KNOWNFOLDERID *)idp;
|
||||
@ -885,7 +885,7 @@ in(REFKNOWNFOLDERID idp, char *name, int i)
|
||||
// initialize twice: first, just count, second
|
||||
// incrementing i to point to the next free entry
|
||||
static int
|
||||
j(int i)
|
||||
j(int i)
|
||||
{
|
||||
in( &FOLDERID_AccountPictures, "AccountPictures" , i++);
|
||||
in( &FOLDERID_AddNewPrograms, "AddNewPrograms" , i++);
|
||||
@ -1083,10 +1083,10 @@ static int
|
||||
unify_csidl_path(term_t t, int csidl)
|
||||
{ wchar_t buf[MAX_PATH];
|
||||
|
||||
if ( SUCCEEDED(SHGetFolderPathW(NULL,
|
||||
CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
|
||||
NULL,
|
||||
0,
|
||||
if ( SUCCEEDED(SHGetFolderPathW(NULL,
|
||||
CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
|
||||
NULL,
|
||||
0,
|
||||
buf)) )
|
||||
{ wchar_t *p;
|
||||
|
||||
@ -1105,11 +1105,11 @@ unify_csidl_path(term_t t, int csidl)
|
||||
|
||||
/** @pred win_folder(?_KnowFolder_, -_Path_)
|
||||
*
|
||||
* This SWI Windows Built-in relates a Windows `known folder` with its
|
||||
* This SWI Windows Built-in relates a Windows `known folder` with its
|
||||
* corresponding file system _Path_. It can also be used to enumerate folderids/
|
||||
*
|
||||
* It is an interface to [SHGetKnownFolderPath](http://msdn.microsoft.com/en-us/library/windows/desktop/bb762204(v=vs.85).aspx).
|
||||
* Note that in order to follow Microsoft
|
||||
* It is an interface to [SHGetKnownFolderPath](http://msdn.microsoft.com/en-us/library/windows/desktop/bb762204(v=vs.85).aspx).
|
||||
* Note that in order to follow Microsoft
|
||||
* documentation, YAP supports `Known Folderids` instead of special folderids,
|
||||
* as used in SWI-Prolog. Also, names in YAP are obtained by removing
|
||||
* the prefix `FOLDERID_`: no further processing is made to convert to lower caps.
|
||||
@ -1290,7 +1290,7 @@ PRED_IMPL("win_registry_get_value", 3, win_registry_get_value, 0)
|
||||
* This non-deterministic Windows Built-in consults the Windows registry for all
|
||||
* subkeys _Name_ of attribute _Key_. It can be used to enumerate and rebuild
|
||||
* the registry.
|
||||
*
|
||||
*
|
||||
* This built-in is an interface to [RegEnumKeyEx](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724862(v=vs.85).aspx)
|
||||
*/
|
||||
static
|
@ -59,7 +59,7 @@ avoid using term-references to address the list.
|
||||
#if __YAP_PROLOG__
|
||||
|
||||
typedef struct list_ctx
|
||||
{
|
||||
{
|
||||
Term gstore;
|
||||
Term start;
|
||||
} list_ctx;
|
1640
library/dialect/swi/os/pl-read.c
Normal file
1640
library/dialect/swi/os/pl-read.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -84,7 +84,7 @@ COMMON(int) get_string_text(atom_t atom, PL_chars_t *text ARG_LD);
|
||||
static inline int
|
||||
text_get_char(const PL_chars_t *t, size_t i)
|
||||
{ assert(t->canonical);
|
||||
return t->encoding == ENC_ISO_LATIN_1 ? t->text.t[i]&0xff
|
||||
return t->encoding == ENC_ISO_LATIN1 ? t->text.t[i]&0xff
|
||||
: t->text.w[i];
|
||||
}
|
||||
|
@ -1,156 +1,156 @@
|
||||
/* Part of SWI-Prolog
|
||||
|
||||
Author: Jan Wielemaker
|
||||
E-mail: J.Wielemaker@cs.vu.nl
|
||||
WWW: http://www.swi-prolog.org
|
||||
Copyright (C): 1985-2012, University of Amsterdam
|
||||
VU University Amsterdam
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PL_THREAD_H_DEFINED
|
||||
#define PL_THREAD_H_DEFINED
|
||||
|
||||
#ifdef THREADS
|
||||
#include <pthread.h>
|
||||
|
||||
typedef pthread_mutex_t simpleMutex;
|
||||
|
||||
#define simpleMutexInit(p) pthread_mutex_init(p, NULL)
|
||||
#define simpleMutexDelete(p) pthread_mutex_destroy(p)
|
||||
#define simpleMutexLock(p) pthread_mutex_lock(p)
|
||||
#define simpleMutexUnlock(p) pthread_mutex_unlock(p)
|
||||
|
||||
typedef pthread_mutex_t recursiveMutex;
|
||||
|
||||
#define NEED_RECURSIVE_MUTEX_INIT 1
|
||||
extern int recursiveMutexInit(recursiveMutex *m);
|
||||
#define recursiveMutexDelete(p) pthread_mutex_destroy(p)
|
||||
#define recursiveMutexLock(p) pthread_mutex_lock(p)
|
||||
#define recursiveMutexTryLock(p) pthread_mutex_trylock(p)
|
||||
#define recursiveMutexUnlock(p) pthread_mutex_unlock(p)
|
||||
|
||||
|
||||
typedef struct counting_mutex
|
||||
{ simpleMutex mutex; /* mutex itself */
|
||||
const char *name; /* name of the mutex */
|
||||
long count; /* # times locked */
|
||||
long unlocked; /* # times unlocked */
|
||||
#ifdef O_CONTENTION_STATISTICS
|
||||
long collisions; /* # contentions */
|
||||
#endif
|
||||
struct counting_mutex *next; /* next of allocated chain */
|
||||
} counting_mutex;
|
||||
|
||||
extern counting_mutex *allocSimpleMutex(const char *name);
|
||||
extern void freeSimpleMutex(counting_mutex *m);
|
||||
|
||||
extern counting_mutex _PL_mutexes[]; /* Prolog mutexes */
|
||||
|
||||
#define L_MISC 0
|
||||
#define L_ALLOC 1
|
||||
#define L_ATOM 2
|
||||
#define L_FLAG 3
|
||||
#define L_FUNCTOR 4
|
||||
#define L_RECORD 5
|
||||
#define L_THREAD 6
|
||||
#define L_PREDICATE 7
|
||||
#define L_MODULE 8
|
||||
#define L_TABLE 9
|
||||
#define L_BREAK 10
|
||||
#define L_FILE 11
|
||||
#define L_SEETELL 12
|
||||
#define L_PLFLAG 13
|
||||
#define L_OP 14
|
||||
#define L_INIT 15
|
||||
#define L_TERM 16
|
||||
#define L_GC 17
|
||||
#define L_AGC 18
|
||||
#define L_STOPTHEWORLD 19
|
||||
#define L_FOREIGN 20
|
||||
#define L_OS 21
|
||||
#define L_LOCALE 23
|
||||
#ifdef __WINDOWS__
|
||||
#define L_DDE 24
|
||||
#define L_CSTACK 25
|
||||
#endif
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
The IF_MT(id, g) macro is used to bypass mutexes if threading is
|
||||
disabled. We cannot do this for the L_THREAD mutex however as we need to
|
||||
control when threads can be created.
|
||||
|
||||
We assume id == L_THREAD is optimized away if id is known at
|
||||
compile-time
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#define IF_MT(id,g) g
|
||||
//#define IF_MT(id, g) if ( id == L_THREAD ) g
|
||||
|
||||
#ifdef O_CONTENTION_STATISTICS
|
||||
#define countingMutexLock(cm) \
|
||||
do \
|
||||
{ if ( pthread_mutex_trylock(&(cm)->mutex) == EBUSY ) \
|
||||
{ (cm)->collisions++; \
|
||||
pthread_mutex_lock(&(cm)->mutex); \
|
||||
} \
|
||||
(cm)->count++; \
|
||||
} while(0)
|
||||
#else
|
||||
#define countingMutexLock(cm) \
|
||||
do \
|
||||
{ simpleMutexLock(&(cm)->mutex); \
|
||||
(cm)->count++; \
|
||||
} while(0)
|
||||
#endif
|
||||
#define countingMutexUnlock(cm) \
|
||||
do \
|
||||
{ (cm)->unlocked++; \
|
||||
assert((cm)->unlocked <= (cm)->count); \
|
||||
simpleMutexUnlock(&(cm)->mutex); \
|
||||
} while(0)
|
||||
|
||||
//#define O_DEBUG_MT
|
||||
#ifdef O_DEBUG_MT
|
||||
#define PL_LOCK(id) \
|
||||
do { Sdprintf("[%d] %s:%d: LOCK(%s)\n", \
|
||||
pthread_self(), \
|
||||
__BASE_FILE__, __LINE__, #id); \
|
||||
countingMutexLock(&_PL_mutexes[id]); \
|
||||
} while(0)
|
||||
#define PL_UNLOCK(id) \
|
||||
do { Sdprintf("[%d] %s:%d: UNLOCK(%s)\n", \
|
||||
pthread_self(), \
|
||||
__BASE_FILE__, __LINE__, #id); \
|
||||
countingMutexUnlock(&_PL_mutexes[id]); \
|
||||
} while(0)
|
||||
#else
|
||||
#define PL_LOCK(id) IF_MT(id, countingMutexLock(&_PL_mutexes[id]))
|
||||
#define PL_UNLOCK(id) IF_MT(id, countingMutexUnlock(&_PL_mutexes[id]))
|
||||
#endif
|
||||
#undef O_DEBUG_MT
|
||||
|
||||
#define IOLOCK recursiveMutex
|
||||
|
||||
#else
|
||||
#define PL_LOCK(X)
|
||||
#define PL_UNLOCK(X)
|
||||
|
||||
typedef void * IOLOCK;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Part of SWI-Prolog
|
||||
|
||||
Author: Jan Wielemaker
|
||||
E-mail: J.Wielemaker@cs.vu.nl
|
||||
WWW: http://www.swi-prolog.org
|
||||
Copyright (C): 1985-2012, University of Amsterdam
|
||||
VU University Amsterdam
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PL_THREAD_H_DEFINED
|
||||
#define PL_THREAD_H_DEFINED
|
||||
|
||||
#ifdef THREADS
|
||||
#include <pthread.h>
|
||||
|
||||
typedef pthread_mutex_t simpleMutex;
|
||||
|
||||
#define simpleMutexInit(p) pthread_mutex_init(p, NULL)
|
||||
#define simpleMutexDelete(p) pthread_mutex_destroy(p)
|
||||
#define simpleMutexLock(p) pthread_mutex_lock(p)
|
||||
#define simpleMutexUnlock(p) pthread_mutex_unlock(p)
|
||||
|
||||
typedef pthread_mutex_t recursiveMutex;
|
||||
|
||||
#define NEED_RECURSIVE_MUTEX_INIT 1
|
||||
extern int recursiveMutexInit(recursiveMutex *m);
|
||||
#define recursiveMutexDelete(p) pthread_mutex_destroy(p)
|
||||
#define recursiveMutexLock(p) pthread_mutex_lock(p)
|
||||
#define recursiveMutexTryLock(p) pthread_mutex_trylock(p)
|
||||
#define recursiveMutexUnlock(p) pthread_mutex_unlock(p)
|
||||
|
||||
|
||||
typedef struct counting_mutex
|
||||
{ simpleMutex mutex; /* mutex itself */
|
||||
const char *name; /* name of the mutex */
|
||||
long count; /* # times locked */
|
||||
long unlocked; /* # times unlocked */
|
||||
#ifdef O_CONTENTION_STATISTICS
|
||||
long collisions; /* # contentions */
|
||||
#endif
|
||||
struct counting_mutex *next; /* next of allocated chain */
|
||||
} counting_mutex;
|
||||
|
||||
extern counting_mutex *allocSimpleMutex(const char *name);
|
||||
extern void freeSimpleMutex(counting_mutex *m);
|
||||
|
||||
extern counting_mutex _PL_mutexes[]; /* Prolog mutexes */
|
||||
|
||||
#define L_MISC 0
|
||||
#define L_ALLOC 1
|
||||
#define L_ATOM 2
|
||||
#define L_FLAG 3
|
||||
#define L_FUNCTOR 4
|
||||
#define L_RECORD 5
|
||||
#define L_THREAD 6
|
||||
#define L_PREDICATE 7
|
||||
#define L_MODULE 8
|
||||
#define L_TABLE 9
|
||||
#define L_BREAK 10
|
||||
#define L_FILE 11
|
||||
#define L_SEETELL 12
|
||||
#define L_PLFLAG 13
|
||||
#define L_OP 14
|
||||
#define L_INIT 15
|
||||
#define L_TERM 16
|
||||
#define L_GC 17
|
||||
#define L_AGC 18
|
||||
#define L_STOPTHEWORLD 19
|
||||
#define L_FOREIGN 20
|
||||
#define L_OS 21
|
||||
#define L_LOCALE 23
|
||||
#ifdef __WINDOWS__
|
||||
#define L_DDE 24
|
||||
#define L_CSTACK 25
|
||||
#endif
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
The IF_MT(id, g) macro is used to bypass mutexes if threading is
|
||||
disabled. We cannot do this for the L_THREAD mutex however as we need to
|
||||
control when threads can be created.
|
||||
|
||||
We assume id == L_THREAD is optimized away if id is known at
|
||||
compile-time
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#define IF_MT(id,g) g
|
||||
//#define IF_MT(id, g) if ( id == L_THREAD ) g
|
||||
|
||||
#ifdef O_CONTENTION_STATISTICS
|
||||
#define countingMutexLock(cm) \
|
||||
do \
|
||||
{ if ( pthread_mutex_trylock(&(cm)->mutex) == EBUSY ) \
|
||||
{ (cm)->collisions++; \
|
||||
pthread_mutex_lock(&(cm)->mutex); \
|
||||
} \
|
||||
(cm)->count++; \
|
||||
} while(0)
|
||||
#else
|
||||
#define countingMutexLock(cm) \
|
||||
do \
|
||||
{ simpleMutexLock(&(cm)->mutex); \
|
||||
(cm)->count++; \
|
||||
} while(0)
|
||||
#endif
|
||||
#define countingMutexUnlock(cm) \
|
||||
do \
|
||||
{ (cm)->unlocked++; \
|
||||
assert((cm)->unlocked <= (cm)->count); \
|
||||
simpleMutexUnlock(&(cm)->mutex); \
|
||||
} while(0)
|
||||
|
||||
//#define O_DEBUG_MT
|
||||
#ifdef O_DEBUG_MT
|
||||
#define PL_LOCK(id) \
|
||||
do { Sdprintf("[%d] %s:%d: LOCK(%s)\n", \
|
||||
pthread_self(), \
|
||||
__BASE_FILE__, __LINE__, #id); \
|
||||
countingMutexLock(&_PL_mutexes[id]); \
|
||||
} while(0)
|
||||
#define PL_UNLOCK(id) \
|
||||
do { Sdprintf("[%d] %s:%d: UNLOCK(%s)\n", \
|
||||
pthread_self(), \
|
||||
__BASE_FILE__, __LINE__, #id); \
|
||||
countingMutexUnlock(&_PL_mutexes[id]); \
|
||||
} while(0)
|
||||
#else
|
||||
#define PL_LOCK(id) IF_MT(id, countingMutexLock(&_PL_mutexes[id]))
|
||||
#define PL_UNLOCK(id) IF_MT(id, countingMutexUnlock(&_PL_mutexes[id]))
|
||||
#endif
|
||||
#undef O_DEBUG_MT
|
||||
|
||||
#define IOLOCK recursiveMutex
|
||||
|
||||
#else
|
||||
#define PL_LOCK(X)
|
||||
#define PL_UNLOCK(X)
|
||||
|
||||
typedef void * IOLOCK;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -271,7 +271,7 @@ _xos_os_filenameW(const char *cname, wchar_t *osname, size_t len)
|
||||
|
||||
#if __MINGW32__
|
||||
if ( q == cname && q[0] == '/' ) /* deal with /host/share in mingw32 */
|
||||
{
|
||||
{
|
||||
UINT is_drive;
|
||||
|
||||
q++;
|
||||
@ -527,7 +527,7 @@ _xos_absolute_filename(const char *local, char *absolute, size_t len)
|
||||
|
||||
int
|
||||
_xos_same_file(const char *p1, const char *p2)
|
||||
{
|
||||
{
|
||||
TCHAR buf1[PATH_MAX];
|
||||
TCHAR buf2[PATH_MAX];
|
||||
int rc = FALSE, found = FALSE;
|
||||
@ -538,13 +538,13 @@ _xos_same_file(const char *p1, const char *p2)
|
||||
|
||||
HANDLE hFile1 = CreateFile(buf1, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
HANDLE hFile2 = CreateFile(buf2, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
|
||||
if (hFile1 != INVALID_HANDLE_VALUE &&
|
||||
hFile2 != INVALID_HANDLE_VALUE) {
|
||||
BY_HANDLE_FILE_INFORMATION f1, f2;
|
||||
if (GetFileInformationByHandle(hFile1, &f1) &&
|
||||
GetFileInformationByHandle(hFile2, &f2) ) {
|
||||
rc =
|
||||
rc =
|
||||
f1.dwVolumeSerialNumber == f2.dwVolumeSerialNumber &&
|
||||
f1.nFileIndexLow == f2.nFileIndexLow &&
|
||||
f1.nFileIndexLow == f2.nFileIndexLow;
|
1640
os/pl-read.c
1640
os/pl-read.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user