flags & var init work
This commit is contained in:
parent
825bfd11c2
commit
794d04c851
@ -105,7 +105,10 @@ Int Yap_peek(int sno) {
|
||||
Int ch;
|
||||
|
||||
s = GLOBAL_Stream + sno;
|
||||
if (s->status & Readline_Stream_f) {
|
||||
#if USE_READLINE
|
||||
if (s->status & Readline_Stream_f
|
||||
&& trueGlobalPrologFlag(READLINE_FLAG)
|
||||
) {
|
||||
ch = Yap_ReadlinePeekChar(sno);
|
||||
if (ch == EOFCHAR) {
|
||||
s->stream_getc = EOFPeek;
|
||||
@ -114,6 +117,7 @@ Int Yap_peek(int sno) {
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
#endif
|
||||
ocharcount = s->charcount;
|
||||
olinecount = s->linecount;
|
||||
olinepos = s->linepos;
|
||||
@ -155,6 +159,7 @@ Int Yap_peek(int sno) {
|
||||
ungetc(c / 1 << 16, s->file);
|
||||
c %= 1 << 16;
|
||||
}
|
||||
return c;
|
||||
} else if (s->encoding == ENC_UTF16_LE) {
|
||||
/* do the ungetc as if a write .. */
|
||||
unsigned long int c = ch;
|
||||
@ -238,7 +243,9 @@ static Int at_end_of_stream_0(USES_REGS1) { /* at_end_of_stream */
|
||||
}
|
||||
|
||||
static int yap_fflush(int sno) {
|
||||
#if USE_READLINE
|
||||
Yap_ReadlineFlush(sno);
|
||||
#endif
|
||||
if ((GLOBAL_Stream[sno].status & Output_Stream_f) &&
|
||||
!(GLOBAL_Stream[sno].status &
|
||||
(Null_Stream_f | InMemory_Stream_f | Socket_Stream_f | Pipe_Stream_f |
|
||||
|
49
os/console.c
49
os/console.c
@ -34,31 +34,7 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
*/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "yapio.h"
|
||||
#include <stdlib.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#if HAVE_IO_H
|
||||
/* Windows */
|
||||
#include <io.h>
|
||||
#endif
|
||||
#if HAVE_SOCKET
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(x) (((x)&_S_IFDIR)==_S_IFDIR)
|
||||
#endif
|
||||
#endif
|
||||
#include "iopreds.h"
|
||||
#include "sysbits.h"
|
||||
|
||||
static Int prompt( USES_REGS1 );
|
||||
static Int prompt1( USES_REGS1 );
|
||||
@ -94,7 +70,8 @@ is_same_tty(FILE *f1, FILE *f2)
|
||||
#if HAVE_TTYNAME
|
||||
return(ttyname(fileno(f1)) == ttyname(fileno(f2)));
|
||||
#else
|
||||
return;
|
||||
// assume a single console, for now
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -114,14 +91,18 @@ is_same_tty2 (USES_REGS1)
|
||||
void
|
||||
Yap_ConsoleOps( StreamDesc *s )
|
||||
{
|
||||
Yap_DefaultStreamOps( s );
|
||||
/* the putc routine only has to check it is putting out a newline */
|
||||
s->stream_putc = ConsolePutc;
|
||||
#if USE_READLINE
|
||||
/* if a tty have a special routine to call readline */
|
||||
if (!Yap_ReadlineOps( s )) {
|
||||
/* else just PlGet plus checking for prompt */
|
||||
s->stream_getc = ConsoleGetc;
|
||||
if (( s->status & Readline_Stream_f) &&
|
||||
trueGlobalPrologFlag(READLINE_FLAG) ) {
|
||||
if (Yap_ReadlineOps( s ))
|
||||
return;
|
||||
}
|
||||
Yap_DefaultStreamOps( s );
|
||||
#endif
|
||||
s->stream_getc = ConsoleGetc;
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -155,7 +136,7 @@ ConsoleGetc(int sno)
|
||||
/* keep the prompt around, just in case, but don't actually
|
||||
show it in silent mode */
|
||||
if (LOCAL_newline) {
|
||||
if (silentMode()) {
|
||||
if (!silentMode()) {
|
||||
char *cptr = LOCAL_Prompt, ch;
|
||||
|
||||
/* use the default routine */
|
||||
@ -247,7 +228,10 @@ Yap_GetCharForSIGINT(void)
|
||||
{
|
||||
CACHE_REGS
|
||||
int ch;
|
||||
if ((ch = Yap_ReadlineForSIGINT()) == 0)
|
||||
#if USE_READLINE
|
||||
if (trueGlobalPrologFlag(READLINE_FLAG) ||
|
||||
(ch = Yap_ReadlineForSIGINT()) == 0)
|
||||
#endif
|
||||
{ /* ask for a new line */
|
||||
fprintf(stderr, "Action (h for help): ");
|
||||
ch = getc(stdin);
|
||||
@ -261,6 +245,7 @@ Yap_GetCharForSIGINT(void)
|
||||
|
||||
|
||||
void Yap_InitConsole(void) {
|
||||
LOCAL_newline = true;
|
||||
Yap_InitCPred ("prompt", 1, prompt1, SafePredFlag|SyncPredFlag);
|
||||
Yap_InitCPred ("prompt1", 1, prompt1, SafePredFlag|SyncPredFlag);
|
||||
Yap_InitCPred ("$is_same_tty", 2, is_same_tty2, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
|
100
os/files.c
100
os/files.c
@ -24,75 +24,8 @@ static char SccsId[] = "%W% %G%";
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "yapio.h"
|
||||
#include "eval.h"
|
||||
#include "YapText.h"
|
||||
#include <stdlib.h>
|
||||
#if HAVE_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
#if HAVE_CTYPE_H
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
#if HAVE_WCTYPE_H
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
#if HAVE_LIMITS_H
|
||||
#include <limits.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
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#if HAVE_LIBGEN_H
|
||||
#include <libgen.h>
|
||||
#endif
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#if HAVE_FCNTL_H
|
||||
/* for O_BINARY and O_TEXT in WIN32 */
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#if HAVE_IO_H
|
||||
/* Windows */
|
||||
#include <io.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 _MSC_VER || defined(__MINGW32__)
|
||||
#if HAVE_SOCKET
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(x) (((x)&_S_IFDIR)==_S_IFDIR)
|
||||
#endif
|
||||
#endif
|
||||
#include "iopreds.h"
|
||||
#include "sysbits.h"
|
||||
|
||||
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
#define SYSTEM_STAT _stat
|
||||
@ -341,16 +274,35 @@ time_file(USES_REGS1)
|
||||
} else {
|
||||
const char *n = RepAtom(AtomOfTerm(tname))->StrOfAE;
|
||||
#if __WIN32
|
||||
FILETIME ftWrite;
|
||||
if ((hdl = CreateFile( n, 0, 0, NULL, OPEN_EXISTING, NULL)) == 0)
|
||||
FILETIME ft;
|
||||
HANDLE hdl;
|
||||
Term rc;
|
||||
|
||||
if ((hdl = CreateFile( n, 0, 0, NULL, OPEN_EXISTING, 0, 0)) == 0)
|
||||
return false;
|
||||
if (GetFileTime(hdl, NULL,NULL,&ftWrite))
|
||||
if (GetFileTime(hdl, NULL,NULL,&ft))
|
||||
return false;
|
||||
// Convert the last-write time to local time.
|
||||
// FileTimeToSystemTime(&ftWrite, &stUTC);
|
||||
// SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
|
||||
CloseHandle( hdl );
|
||||
return Yap_unify(ARG2, MkIntegerTerm(ftWrite));
|
||||
ULONGLONG qwResult;
|
||||
|
||||
// Copy the time into a quadword.
|
||||
qwResult = (((ULONGLONG) ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
|
||||
#if SIZEOF_INT_P==8
|
||||
rc = MkIntegerTerm(qwResult);
|
||||
#elif USE_GMP
|
||||
char s[64];
|
||||
MP_INT rop;
|
||||
|
||||
snprintf(s, 64, "%I64d", (long long int)n);
|
||||
mpz_init_set_str (&rop, s, 10);
|
||||
rc = Yap_MkBigNumTerm((void *)&rop) PASS_REGS);
|
||||
#else
|
||||
rc = MkIntegerTerm(ft.dwHighDateTime);
|
||||
#endif
|
||||
return Yap_unify(ARG2, rc);
|
||||
#elif HAVE_STAT
|
||||
struct SYSTEM_STAT ss;
|
||||
|
||||
@ -505,7 +457,7 @@ is_absolute_file_name ( USES_REGS1 )
|
||||
at = AtomOfTerm(t);
|
||||
if (IsWideAtom(at)) {
|
||||
#if _WIN32
|
||||
return PathisRelativeW(RepAtom(at)->WStrOfAE[0]);
|
||||
return PathIsRelativeW(RepAtom(at)->WStrOfAE);
|
||||
#else
|
||||
return RepAtom(at)->WStrOfAE[0] == '/';
|
||||
#endif
|
||||
|
@ -14,7 +14,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* @file memopen.c
|
||||
* @defgroup Memory Streams.
|
||||
* @in.
|
||||
* @return Description of returned value.
|
||||
*/
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <stdio.h>
|
||||
|
41
os/iopreds.c
41
os/iopreds.c
@ -27,8 +27,7 @@ static char SccsId[] = "%W% %G%";
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* This file includes the definition of a miscellania of standard predicates
|
||||
* for yap refering to: Files and GLOBAL_Streams, Simple Input/Output,
|
||||
* This file includes the definition of a miscellania of standard predicates * for yap refering to: Files and GLOBAL_Streams, Simple Input/Output,
|
||||
*
|
||||
*/
|
||||
|
||||
@ -178,10 +177,10 @@ static void unix_upd_stream_info(StreamDesc *s) {
|
||||
Yap_socketStream(s);
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
{
|
||||
if (_isatty(_fileno(s->u.file.file))) {
|
||||
if (_isatty(_fileno(s->file))) {
|
||||
s->status |= Tty_Stream_f | Reset_Eof_Stream_f | Promptable_Stream_f;
|
||||
/* make all console descriptors unbuffered */
|
||||
setvbuf(s->u.file.file, NULL, _IONBF, 0);
|
||||
setvbuf(s->file, NULL, _IONBF, 0);
|
||||
return;
|
||||
}
|
||||
#if _MSC_VER
|
||||
@ -1017,11 +1016,7 @@ Int GetStreamFd(int sno) {
|
||||
} else
|
||||
#endif
|
||||
if (GLOBAL_Stream[sno].status & Pipe_Stream_f) {
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
return ((Int)(GLOBAL_Stream[sno].u.pipe.hdl));
|
||||
#else
|
||||
return (GLOBAL_Stream[sno].u.pipe.fd);
|
||||
#endif
|
||||
} else if (GLOBAL_Stream[sno].status & InMemory_Stream_f) {
|
||||
return (-1);
|
||||
}
|
||||
@ -1030,7 +1025,7 @@ Int GetStreamFd(int sno) {
|
||||
|
||||
Int Yap_GetStreamFd(int sno) { return GetStreamFd(sno); }
|
||||
|
||||
static int binary_file(char *file_name) {
|
||||
static int binary_file(const char *file_name) {
|
||||
#if HAVE_STAT
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
struct _stat ss;
|
||||
@ -1269,20 +1264,20 @@ static void check_bom(int sno, StreamDesc *st) {
|
||||
|
||||
|
||||
#define OPEN_DEFS() \
|
||||
PAR("alias", isatom, OPEN_ALIAS), PAR("bom", boolean, OPEN_BOM), \
|
||||
PAR("alias", isatom, OPEN_ALIAS), PAR("bom", booleanFlag, OPEN_BOM), \
|
||||
PAR("buffer", isatom, OPEN_BUFFER), \
|
||||
PAR("close_on_abort", boolean, OPEN_CLOSE_ON_ABORT), \
|
||||
PAR("close_on_abort", booleanFlag, OPEN_CLOSE_ON_ABORT), \
|
||||
PAR("create", isatom, OPEN_CREATE), \
|
||||
PAR("encoding", isatom, OPEN_ENCODING), \
|
||||
PAR("eof_action", isatom, OPEN_EOF_ACTION), \
|
||||
PAR("expand_filename", boolean, OPEN_EXPAND_FILENAME), \
|
||||
PAR("expand_filename", booleanFlag, OPEN_EXPAND_FILENAME), \
|
||||
PAR("file_name", isatom, OPEN_FILE_NAME), PAR("input", ok, OPEN_INPUT), \
|
||||
PAR("locale", isatom, OPEN_LOCALE), PAR("lock", isatom, OPEN_LOCK), \
|
||||
PAR("mode", isatom, OPEN_MODE), PAR("output", ok, OPEN_OUTPUT), \
|
||||
PAR("representation_errors", boolean, OPEN_REPRESENTATION_ERRORS), \
|
||||
PAR("reposition", boolean, OPEN_REPOSITION), \
|
||||
PAR("script", boolean, OPEN_SCRIPT), \
|
||||
PAR("type", isatom, OPEN_TYPE), PAR("wait", boolean, OPEN_WAIT), \
|
||||
PAR("representation_errors", booleanFlag, OPEN_REPRESENTATION_ERRORS), \
|
||||
PAR("reposition", booleanFlag, OPEN_REPOSITION), \
|
||||
PAR("script", booleanFlag, OPEN_SCRIPT), \
|
||||
PAR("type", isatom, OPEN_TYPE), PAR("wait", booleanFlag, OPEN_WAIT), \
|
||||
PAR(NULL, ok, OPEN_END)
|
||||
|
||||
#define PAR(x, y, z) z
|
||||
@ -1307,7 +1302,7 @@ do_open(Term file_name, Term t2,
|
||||
char io_mode[8];
|
||||
StreamDesc *st;
|
||||
bool avoid_bom = false, needs_bom = false;
|
||||
char *fname;
|
||||
const char *fname;
|
||||
stream_flags_t flags;
|
||||
FILE *fd;
|
||||
encoding_t encoding;
|
||||
@ -1439,7 +1434,7 @@ do_open(Term file_name, Term t2,
|
||||
(!(flags & Binary_Stream_f) && binary_file(fname))) {
|
||||
UNLOCK(st->streamlock);
|
||||
if (errno == ENOENT)
|
||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, ARG6, "%s: %s", fname,
|
||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s: %s", fname,
|
||||
strerror(errno)));
|
||||
else {
|
||||
return (PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, file_name, "%s: %s",
|
||||
@ -1799,7 +1794,7 @@ user_output, and user_error can never be closed.
|
||||
}
|
||||
|
||||
#define CLOSE_DEFS() \
|
||||
PAR("force", boolean, CLOSE_FORCE), PAR(NULL, ok, CLOSE_END)
|
||||
PAR("force", booleanFlag, CLOSE_FORCE), PAR(NULL, ok, CLOSE_END)
|
||||
|
||||
#define PAR(x, y, z) z
|
||||
|
||||
@ -1857,14 +1852,14 @@ Term read_line(int sno) {
|
||||
|
||||
#define ABSOLUTE_FILE_NAME_DEFS() \
|
||||
PAR("access", isatom, ABSOLUTE_FILE_NAME_ACCESS), \
|
||||
PAR("expand", boolean, ABSOLUTE_FILE_NAME_EXPAND), \
|
||||
PAR("expand", booleanFlag, ABSOLUTE_FILE_NAME_EXPAND), \
|
||||
PAR("extensions", ok, ABSOLUTE_FILE_NAME_EXTENSIONS), \
|
||||
PAR("file_type", is_file_type, ABSOLUTE_FILE_NAME_FILE_TYPE), \
|
||||
PAR("file_errors", is_file_errors, ABSOLUTE_FILE_NAME_FILE_ERRORS), \
|
||||
PAR("glob", ok, ABSOLUTE_FILE_NAME_GLOB), \
|
||||
PAR("relative_to", isatom, ABSOLUTE_FILE_NAME_RELATIVE_TO), \
|
||||
PAR("solutions", issolutions, ABSOLUTE_FILE_NAME_SOLUTIONS), \
|
||||
PAR("verbose_file_search", boolean, \
|
||||
PAR("verbose_file_search", booleanFlag, \
|
||||
ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH), \
|
||||
PAR(NULL, ok, ABSOLUTE_FILE_NAME_END)
|
||||
|
||||
@ -2010,7 +2005,9 @@ void Yap_InitIOPreds(void) {
|
||||
Yap_InitReadTPreds();
|
||||
Yap_InitFormat();
|
||||
Yap_InitRandomPreds();
|
||||
Yap_InitReadline();
|
||||
#if USE_READLINE
|
||||
Yap_InitReadlinePreds();
|
||||
#endif
|
||||
Yap_InitSockets();
|
||||
Yap_InitSignalPreds();
|
||||
Yap_InitSysPreds();
|
||||
|
Reference in New Issue
Block a user