fixes + indenting

This commit is contained in:
Vitor Santos Costa 2016-04-12 16:04:33 +01:00
parent 69bb5c4d08
commit e6c2503563
7 changed files with 384 additions and 115 deletions

View File

@ -171,26 +171,26 @@ loop:
static Int access_path(USES_REGS1) {
Term tname = Deref(ARG1);
char *file_name;
if (IsVarTerm(tname)) {
Yap_Error(INSTANTIATION_ERROR, tname, "access");
return FALSE;
return false;
} else if (!IsAtomTerm(tname)) {
Yap_Error(TYPE_ERROR_ATOM, tname, "access");
return FALSE;
return false;
} else {
#if HAVE_STAT
struct SYSTEM_STAT ss;
char *file_name;
file_name = RepAtom(AtomOfTerm(tname))->StrOfAE;
if (SYSTEM_STAT(file_name, &ss) != 0) {
/* ignore errors while checking a file */
return FALSE;
return true;
}
return TRUE;
return true;
#else
return FALSE;
return false;
#endif
}
}

279
os/fmemopen-android.c Normal file
View File

@ -0,0 +1,279 @@
bplist00Ñ_WebMainResourceÕ
_WebResourceTextEncodingName_WebResourceFrameName^WebResourceURL_WebResourceData_WebResourceMIMETypeUUTF-8P_Phttps://raw.githubusercontent.com/j-jorge/android-stdioext/master/src/fmemopen.cO#H<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*
* Modifications for Android written Jul 2009 by Alan Viverette
*/
/*
FUNCTION
&lt;&lt;fmemopen&gt;&gt;---open a stream around a fixed-length string
INDEX
fmemopen
ANSI_SYNOPSIS
#include &lt;stdio.h&gt;
FILE *fmemopen(void *restrict &lt;[buf]&gt;, size_t &lt;[size]&gt;,
const char *restrict &lt;[mode]&gt;);
DESCRIPTION
&lt;&lt;fmemopen&gt;&gt; creates a seekable &lt;&lt;FILE&gt;&gt; stream that wraps a
fixed-length buffer of &lt;[size]&gt; bytes starting at &lt;[buf]&gt;. The stream
is opened with &lt;[mode]&gt; treated as in &lt;&lt;fopen&gt;&gt;, where append mode
starts writing at the first NUL byte. If &lt;[buf]&gt; is NULL, then
&lt;[size]&gt; bytes are automatically provided as if by &lt;&lt;malloc&gt;&gt;, with
the initial size of 0, and &lt;[mode]&gt; must contain &lt;&lt;+&gt;&gt; so that data
can be read after it is written.
The stream maintains a current position, which moves according to
bytes read or written, and which can be one past the end of the array.
The stream also maintains a current file size, which is never greater
than &lt;[size]&gt;. If &lt;[mode]&gt; starts with &lt;&lt;r&gt;&gt;, the position starts at
&lt;&lt;0&gt;&gt;, and file size starts at &lt;[size]&gt; if &lt;[buf]&gt; was provided. If
&lt;[mode]&gt; starts with &lt;&lt;w&gt;&gt;, the position and file size start at &lt;&lt;0&gt;&gt;,
and if &lt;[buf]&gt; was provided, the first byte is set to NUL. If
&lt;[mode]&gt; starts with &lt;&lt;a&gt;&gt;, the position and file size start at the
location of the first NUL byte, or else &lt;[size]&gt; if &lt;[buf]&gt; was
provided.
When reading, NUL bytes have no significance, and reads cannot exceed
the current file size. When writing, the file size can increase up to
&lt;[size]&gt; as needed, and NUL bytes may be embedded in the stream (see
&lt;&lt;open_memstream&gt;&gt; for an alternative that automatically enlarges the
buffer). When the stream is flushed or closed after a write that
changed the file size, a NUL byte is written at the current position
if there is still room; if the stream is not also open for reading, a
NUL byte is additionally written at the last byte of &lt;[buf]&gt; when the
stream has exceeded &lt;[size]&gt;, so that a write-only &lt;[buf]&gt; is always
NUL-terminated when the stream is flushed or closed (and the initial
&lt;[size]&gt; should take this into account). It is not possible to seek
outside the bounds of &lt;[size]&gt;. A NUL byte written during a flush is
restored to its previous value when seeking elsewhere in the string.
RETURNS
The return value is an open FILE pointer on success. On error,
&lt;&lt;NULL&gt;&gt; is returned, and &lt;&lt;errno&gt;&gt; will be set to EINVAL if &lt;[size]&gt;
is zero or &lt;[mode]&gt; is invalid, ENOMEM if &lt;[buf]&gt; was NULL and memory
could not be allocated, or EMFILE if too many streams are already
open.
PORTABILITY
This function is being added to POSIX 200x, but is not in POSIX 2001.
Supporting OS subroutines required: &lt;&lt;sbrk&gt;&gt;.
*/
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;errno.h&gt;
#include &lt;string.h&gt;
#include &lt;malloc.h&gt;
#include "stdioext.h"
/* Describe details of an open memstream. */
typedef struct fmemcookie {
void *storage; /* storage to free on close */
char *buf; /* buffer start */
size_t pos; /* current position */
size_t eof; /* current file size */
size_t max; /* maximum file size */
char append; /* nonzero if appending */
char writeonly; /* 1 if write-only */
char saved; /* saved character that lived at pos before write-only NUL */
} fmemcookie;
/* Read up to non-zero N bytes into BUF from stream described by
COOKIE; return number of bytes read (0 on EOF). */
static int
fmemread(void *cookie, char *buf, int n)
{
fmemcookie *c = (fmemcookie *) cookie;
/* Can't read beyond current size, but EOF condition is not an error. */
if (c-&gt;pos &gt; c-&gt;eof)
return 0;
if (n &gt;= c-&gt;eof - c-&gt;pos)
n = c-&gt;eof - c-&gt;pos;
memcpy (buf, c-&gt;buf + c-&gt;pos, n);
c-&gt;pos += n;
return n;
}
/* Write up to non-zero N bytes of BUF into the stream described by COOKIE,
returning the number of bytes written or EOF on failure. */
static int
fmemwrite(void *cookie, const char *buf, int n)
{
fmemcookie *c = (fmemcookie *) cookie;
int adjust = 0; /* true if at EOF, but still need to write NUL. */
/* Append always seeks to eof; otherwise, if we have previously done
a seek beyond eof, ensure all intermediate bytes are NUL. */
if (c-&gt;append)
c-&gt;pos = c-&gt;eof;
else if (c-&gt;pos &gt; c-&gt;eof)
memset (c-&gt;buf + c-&gt;eof, '\0', c-&gt;pos - c-&gt;eof);
/* Do not write beyond EOF; saving room for NUL on write-only stream. */
if (c-&gt;pos + n &gt; c-&gt;max - c-&gt;writeonly)
{
adjust = c-&gt;writeonly;
n = c-&gt;max - c-&gt;pos;
}
/* Now n is the number of bytes being modified, and adjust is 1 if
the last byte is NUL instead of from buf. Write a NUL if
write-only; or if read-write, eof changed, and there is still
room. When we are within the file contents, remember what we
overwrite so we can restore it if we seek elsewhere later. */
if (c-&gt;pos + n &gt; c-&gt;eof)
{
c-&gt;eof = c-&gt;pos + n;
if (c-&gt;eof - adjust &lt; c-&gt;max)
c-&gt;saved = c-&gt;buf[c-&gt;eof - adjust] = '\0';
}
else if (c-&gt;writeonly)
{
if (n)
{
c-&gt;saved = c-&gt;buf[c-&gt;pos + n - adjust];
c-&gt;buf[c-&gt;pos + n - adjust] = '\0';
}
else
adjust = 0;
}
c-&gt;pos += n;
if (n - adjust)
memcpy (c-&gt;buf + c-&gt;pos - n, buf, n - adjust);
else
{
return EOF;
}
return n;
}
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
static fpos_t
fmemseek(void *cookie, fpos_t pos, int whence)
{
fmemcookie *c = (fmemcookie *) cookie;
off_t offset = (off_t) pos;
if (whence == SEEK_CUR)
offset += c-&gt;pos;
else if (whence == SEEK_END)
offset += c-&gt;eof;
if (offset &lt; 0)
{
offset = -1;
}
else if (offset &gt; c-&gt;max)
{
offset = -1;
}
else
{
if (c-&gt;writeonly &amp;&amp; c-&gt;pos &lt; c-&gt;eof)
{
c-&gt;buf[c-&gt;pos] = c-&gt;saved;
c-&gt;saved = '\0';
}
c-&gt;pos = offset;
if (c-&gt;writeonly &amp;&amp; c-&gt;pos &lt; c-&gt;eof)
{
c-&gt;saved = c-&gt;buf[c-&gt;pos];
c-&gt;buf[c-&gt;pos] = '\0';
}
}
return (fpos_t) offset;
}
/* Reclaim resources used by stream described by COOKIE. */
static int
fmemclose(void *cookie)
{
fmemcookie *c = (fmemcookie *) cookie;
free (c-&gt;storage);
return 0;
}
/* Open a memstream around buffer BUF of SIZE bytes, using MODE.
Return the new stream, or fail with NULL. */
FILE *
fmemopen(void *buf, size_t size, const char *mode)
{
FILE *fp;
fmemcookie *c;
int flags;
int dummy;
if ((flags = __sflags (mode, &amp;dummy)) == 0)
return NULL;
if (!size || !(buf || flags &amp; __SAPP))
{
return NULL;
}
if ((fp = (FILE *) __sfp ()) == NULL)
return NULL;
if ((c = (fmemcookie *) malloc (sizeof *c + (buf ? 0 : size))) == NULL)
{
fp-&gt;_flags = 0; /* release */
return NULL;
}
c-&gt;storage = c;
c-&gt;max = size;
/* 9 modes to worry about. */
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
c-&gt;writeonly = (flags &amp; __SWR) != 0;
c-&gt;saved = '\0';
if (!buf)
{
/* r+/w+/a+, and no buf: file starts empty. */
c-&gt;buf = (char *) (c + 1);
*(char *) buf = '\0';
c-&gt;pos = c-&gt;eof = 0;
c-&gt;append = (flags &amp; __SAPP) != 0;
}
else
{
c-&gt;buf = (char *) buf;
switch (*mode)
{
case 'a':
/* a/a+ and buf: position and size at first NUL. */
buf = memchr (c-&gt;buf, '\0', size);
c-&gt;eof = c-&gt;pos = buf ? (char *) buf - c-&gt;buf : size;
if (!buf &amp;&amp; c-&gt;writeonly)
/* a: guarantee a NUL within size even if no writes. */
c-&gt;buf[size - 1] = '\0';
c-&gt;append = 1;
break;
case 'r':
/* r/r+ and buf: read at beginning, full size available. */
c-&gt;pos = c-&gt;append = 0;
c-&gt;eof = size;
break;
case 'w':
/* w/w+ and buf: write at beginning, truncate to empty. */
c-&gt;pos = c-&gt;append = c-&gt;eof = 0;
*c-&gt;buf = '\0';
break;
default:
abort();
}
}
fp-&gt;_file = -1;
fp-&gt;_flags = flags;
fp-&gt;_cookie = c;
fp-&gt;_read = flags &amp; (__SRD | __SRW) ? fmemread : NULL;
fp-&gt;_write = flags &amp; (__SWR | __SRW) ? fmemwrite : NULL;
fp-&gt;_seek = fmemseek;
fp-&gt;_close = fmemclose;
return fp;
}
</pre></body></html>Ztext/plain (F]l~šî$: $E

View File

@ -233,9 +233,9 @@ static void unix_upd_stream_info(StreamDesc *s) {
filedes = fileno(s->file);
if (isatty(filedes)) {
#if HAVE_TTYNAME
char *ttys = ttyname_r(filedes, LOCAL_FileNameBuf, YAP_FILENAME_MAX - 1);
if (ttys == NULL)
s->name = AtomTty;
int rc = ttyname_r(filedes, LOCAL_FileNameBuf, YAP_FILENAME_MAX - 1);
if (rc == 0)
s->name = Yap_LookupAtom(LOCAL_FileNameBuf);
else
s->name = AtomTtys;
#else
@ -251,24 +251,21 @@ static void unix_upd_stream_info(StreamDesc *s) {
s->status |= Seekable_Stream_f;
}
void Yap_DefaultStreamOps(StreamDesc *st) {
CACHE_REGS
st->stream_wputc = put_wchar;
st->stream_wgetc = get_wchar;
st->stream_putc = FilePutc;
st->stream_getc = PlGetc;
st->stream_putc = FilePutc;
st->stream_getc = PlGetc;
if (st->status & (Promptable_Stream_f)) {
Yap_ConsoleOps(st);
Yap_ConsoleOps(st);
}
#ifndef _WIN32
#ifndef _WIN32
else if (st->file != NULL) {
if (st->encoding == LOCAL_encoding) {
st->stream_wgetc = get_wchar_from_file;
}
else
st->stream_wgetc = get_wchar_from_FILE;
if (st->encoding == LOCAL_encoding) {
st->stream_wgetc = get_wchar_from_file;
} else
st->stream_wgetc = get_wchar_from_FILE;
}
#endif
if (GLOBAL_CharConversionTable != NULL)
@ -288,7 +285,7 @@ void Yap_DefaultStreamOps(StreamDesc *st) {
static void InitFileIO(StreamDesc *s) {
CACHE_REGS
Yap_DefaultStreamOps(s);
Yap_DefaultStreamOps(s);
}
static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file) {
@ -557,7 +554,7 @@ int ResetEOF(StreamDesc *s) {
/* reset the eof indicator on file */
if (feof(s->file))
clearerr(s->file);
/* reset our function for reading input */
/* reset our function for reading input */
Yap_DefaultStreamOps(s);
/* next, reset our own error indicator */
s->status &= ~Eof_Stream_f;
@ -1276,8 +1273,9 @@ do_open(Term file_name, Term t2,
if ((fd = fopen(fname, io_mode)) == NULL ||
(!(flags & Binary_Stream_f) && binary_file(fname))) {
strncpy(LOCAL_FileNameBuf, fname, MAXPATHLEN);
if (fname != fbuf && fname != LOCAL_FileNameBuf && fname != LOCAL_FileNameBuf2)
free((void *)fname);
if (fname != fbuf && fname != LOCAL_FileNameBuf &&
fname != LOCAL_FileNameBuf2)
free((void *)fname);
fname = LOCAL_FileNameBuf;
UNLOCK(st->streamlock);
if (errno == ENOENT)

View File

@ -217,10 +217,6 @@ int Yap_open_buf_write_stream(char *buf, size_t nchars, encoding_t *encp,
buf = malloc(nchars);
st->status |= FreeOnClose_Stream_f;
}
st->nbuf = buf;
if (!st->nbuf) {
return -1;
}
st->nsize = nchars;
st->linepos = 0;
st->charcount = 0;
@ -231,9 +227,17 @@ int Yap_open_buf_write_stream(char *buf, size_t nchars, encoding_t *encp,
st->encoding = LOCAL_encoding;
Yap_DefaultStreamOps(st);
#if MAY_WRITE
st->file = open_memstream(&st->nbuf, &st->nsize);
st->status |= Seekable_Stream_f;
#if HAVE_FMEMOPEN
st->file = fmemopen((void *)buf, nchars, "w");
#else
st->file = open_memstream(buf, &st->nsize);
st->status |= Seekable_Stream_f;
#endif
st->nsize = nchars;
st->nbuf = buf;
if (!st->nbuf) {
return -1;
}
st->u.mem_string.pos = 0;
st->u.mem_string.buf = st->nbuf;
st->u.mem_string.max_size = nchars;

View File

@ -25,12 +25,12 @@ static char SccsId[] = "%W% %G%";
*/
#include "Yap.h"
#include "Yatom.h"
#include "YapHeap.h"
#include "YapFlags.h"
#include "yapio.h"
#include "eval.h"
#include "YapHeap.h"
#include "YapText.h"
#include "Yatom.h"
#include "eval.h"
#include "yapio.h"
#include <stdlib.h>
#if HAVE_STDARG_H
#include <stdarg.h>
@ -183,8 +183,8 @@ static int parse_quasi_quotations(ReadData _PL_rd ARG_LD) {
#endif /*O_QUASIQUOTATIONS*/
#define READ_DEFS() \
PAR("comments", list_filler, READ_COMMENTS), \
PAR("module", isatom, READ_MODULE), PAR("priority", nat, READ_PRIORITY), \
PAR("comments", list_filler, READ_COMMENTS) \
, PAR("module", isatom, READ_MODULE), PAR("priority", nat, READ_PRIORITY), \
PAR("quasi_quotations", filler, READ_QUASI_QUOTATIONS), \
PAR("term_position", filler, READ_TERM_POSITION), \
PAR("syntax_errors", isatom, READ_SYNTAX_ERRORS), \
@ -217,7 +217,7 @@ static const param_t read_defs[] = {READ_DEFS()};
* +
*/
static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
CACHE_REGS
CACHE_REGS
Term info;
Term startline, errline, endline;
Term tf[4];
@ -288,8 +288,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
} break;
case String_tok: {
Term t0 =
Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
Term t0 = Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
if (!t0) {
return 0;
}
@ -302,8 +301,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} break;
case BQString_tok: {
Term t0 =
Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
Term t0 = Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} break;
case WBQString_tok: {
@ -364,9 +362,9 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
}
Term Yap_syntax_error(TokEntry *errtok, int sno) {
return syntax_error(errtok, sno, CurrentModule);
}
return syntax_error(errtok, sno, CurrentModule);
}
typedef struct FEnv {
Term qq, tp, sp, np, vp, ce;
Term tpos; /// initial position of the term to be read.
@ -400,7 +398,7 @@ typedef struct renv {
static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
int inp_stream);
static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
CACHE_REGS
CACHE_REGS
LOCAL_VarTable = NULL;
LOCAL_AnonVarTable = NULL;
fe->enc = GLOBAL_Stream[inp_stream].encoding;
@ -415,11 +413,11 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
if (args[READ_MODULE].used) {
fe->cmod = args[READ_MODULE].tvalue;
} else {
fe->cmod = CurrentModule;
fe->cmod = CurrentModule;
}
if (fe->cmod == TermProlog)
fe->cmod = PROLOG_MODULE;
if (args[READ_BACKQUOTED_STRING].used) {
if (fe->cmod == TermProlog)
fe->cmod = PROLOG_MODULE;
if (args[READ_BACKQUOTED_STRING].used) {
if (!setBackQuotesFlag(args[READ_BACKQUOTED_STRING].tvalue))
return false;
}
@ -430,7 +428,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
}
if (args[READ_COMMENTS].used) {
fe->tcomms = args[READ_COMMENTS].tvalue;
} else {
} else {
fe->tcomms = 0;
}
if (args[READ_TERM_POSITION].used) {
@ -458,8 +456,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
} else {
fe->np = 0;
}
if (args[READ_CHARACTER_ESCAPES].used ||
Yap_CharacterEscapes(fe->cmod)) {
if (args[READ_CHARACTER_ESCAPES].used || Yap_CharacterEscapes(fe->cmod)) {
fe->ce = true;
} else {
fe->ce = false;
@ -496,7 +493,7 @@ typedef enum {
} parser_state_t;
Int Yap_FirstLineInParse(void) {
CACHE_REGS
CACHE_REGS
return LOCAL_StartLineCount;
}
@ -504,7 +501,7 @@ Int Yap_FirstLineInParse(void) {
#define POPFET(X) fe->X = *--HR
static void reset_regs(TokEntry *tokstart, FEnv *fe) {
CACHE_REGS
CACHE_REGS
restore_machine_regs();
@ -572,7 +569,7 @@ static Term get_varnames(FEnv *fe, TokEntry *tokstart) {
}
static Term get_singletons(FEnv *fe, TokEntry *tokstart) {
CACHE_REGS
CACHE_REGS
Term v;
if (fe->sp) {
while (TRUE) {
@ -590,7 +587,7 @@ static Term get_singletons(FEnv *fe, TokEntry *tokstart) {
}
static void warn_singletons(FEnv *fe, TokEntry *tokstart) {
CACHE_REGS
CACHE_REGS
Term v;
fe->sp = TermNil;
v = get_singletons(fe, tokstart);
@ -612,8 +609,8 @@ static void warn_singletons(FEnv *fe, TokEntry *tokstart) {
}
static Term get_stream_position(FEnv *fe, TokEntry *tokstart) {
CACHE_REGS
Term v;
CACHE_REGS
Term v;
if (fe->tp) {
while (true) {
fe->old_H = HR;
@ -630,7 +627,7 @@ static Term get_stream_position(FEnv *fe, TokEntry *tokstart) {
}
static bool complete_processing(FEnv *fe, TokEntry *tokstart) {
CACHE_REGS
CACHE_REGS
Term v1, v2, v3, vc, tp;
if (fe->t && fe->vp)
@ -665,7 +662,7 @@ static bool complete_processing(FEnv *fe, TokEntry *tokstart) {
}
static bool complete_clause_processing(FEnv *fe, TokEntry *tokstart) {
CACHE_REGS
CACHE_REGS
Term v_vp, v_vnames, v_comments, v_pos;
if (fe->t && fe->vp)
@ -711,7 +708,7 @@ static parser_state_t scanEOF(FEnv *fe, int inp_stream);
static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream);
static parser_state_t scanEOF(FEnv *fe, int inp_stream) {
CACHE_REGS
CACHE_REGS
// bool store_comments = false;
TokEntry *tokstart = LOCAL_tokptr;
// check for an user abort
@ -752,7 +749,7 @@ static parser_state_t scanEOF(FEnv *fe, int inp_stream) {
static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
int nargs) {
CACHE_REGS
CACHE_REGS
LOCAL_ErrorMessage = NULL;
fe->old_TR = TR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
@ -789,7 +786,7 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
}
static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
CACHE_REGS
CACHE_REGS
/* preserve value of H after scanning: otherwise we may lose strings
and floats */
LOCAL_tokptr = LOCAL_toktide =
@ -802,9 +799,9 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
return YAP_PARSING;
}
if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) {
size_t len = strlen("Empty clause");
size_t len = strlen("Empty clause");
char *out = malloc(len + 1);
strncpy(out, "Empty clause",len);
strncpy(out, "Empty clause", len);
LOCAL_ErrorMessage = out;
LOCAL_Error_TYPE = SYNTAX_ERROR;
LOCAL_Error_Term = TermEof;
@ -814,7 +811,7 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
}
static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) {
CACHE_REGS
CACHE_REGS
fe->t = 0;
// running out of memory
if (LOCAL_Error_TYPE == RESOURCE_ERROR_TRAIL) {
@ -854,7 +851,7 @@ static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) {
}
static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) {
CACHE_REGS
CACHE_REGS
fe->t = 0;
if (LOCAL_Error_TYPE == RESOURCE_ERROR_TRAIL ||
LOCAL_Error_TYPE == RESOURCE_ERROR_AUXILIARY_STACK ||
@ -873,18 +870,18 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) {
LOCAL_ErrorMessage = NULL;
LOCAL_Error_TYPE = SYNTAX_ERROR;
return YAP_PARSING_FINISHED;
// dec-10
// dec-10
} else if (Yap_PrintWarning(terr)) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
return YAP_SCANNING;
}
}
}
LOCAL_Error_TYPE = YAP_NO_ERROR;
return YAP_PARSING_FINISHED;
}
static parser_state_t parse(REnv *re, FEnv *fe, int inp_stream) {
CACHE_REGS
CACHE_REGS
TokEntry *tokstart = LOCAL_tokptr;
fe->t = Yap_Parse(re->prio, fe->enc, fe->cmod);
fe->toklast = LOCAL_tokptr;
@ -941,7 +938,7 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) {
state = parseError(&re, &fe, inp_stream);
break;
case YAP_PARSING_FINISHED: {
CACHE_REGS
CACHE_REGS
bool done;
if (fe.reading_clause)
done = complete_clause_processing(&fe, LOCAL_tokptr);
@ -953,7 +950,7 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) {
break;
}
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
Yap_Error(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage);
}
#if EMACS
first_char = tokstart->TokPos;
@ -994,8 +991,8 @@ static Int read_term(
}
#define READ_CLAUSE_DEFS() \
PAR("comments", list_filler, READ_CLAUSE_COMMENTS), \
PAR("module", isatom, READ_CLAUSE_MODULE), \
PAR("comments", list_filler, READ_CLAUSE_COMMENTS) \
, PAR("module", isatom, READ_CLAUSE_MODULE), \
PAR("variable_names", filler, READ_CLAUSE_VARIABLE_NAMES), \
PAR("variables", filler, READ_CLAUSE_VARIABLES), \
PAR("term_position", filler, READ_CLAUSE_TERM_POSITION), \
@ -1018,7 +1015,7 @@ static const param_t read_clause_defs[] = {READ_CLAUSE_DEFS()};
static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
int inp_stream) {
CACHE_REGS
CACHE_REGS
xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END);
if (args == NULL) {
@ -1030,8 +1027,8 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
fe->cmod = args[READ_CLAUSE_MODULE].tvalue;
} else {
fe->cmod = LOCAL_SourceModule;
if (fe->cmod == TermProlog)
fe->cmod = PROLOG_MODULE;
if (fe->cmod == TermProlog)
fe->cmod = PROLOG_MODULE;
}
re->bq = getBackQuotesFlag();
fe->enc = GLOBAL_Stream[inp_stream].encoding;
@ -1258,17 +1255,14 @@ static Int style_checker(USES_REGS1) {
return TRUE;
}
X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, int prio,
Term *bindings) {
CACHE_REGS
X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp,
int prio, Term *bindings) {
CACHE_REGS
Term bvar = MkVarTerm(), ctl;
yhandle_t sl;
if (bindings) {
Term enc = MkAtomTerm(Yap_LookupAtom(enc_name(*encp)));
Term encc = Yap_MkApplTerm(Yap_MkFunctor(AtomEncoding, 1), 1, &enc);
ctl = Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &bvar);
ctl = MkPairTerm(ctl, MkPairTerm(encc, TermNil));
sl = Yap_PushHandle(bvar);
} else {
ctl = TermNil;

View File

@ -463,9 +463,8 @@ static bool ChDir(const char *path) {
#else
rc = (chdir(qpath) == 0);
#endif
if (qpath != qp && qpath != LOCAL_FileNameBuf &&
qpath != LOCAL_FileNameBuf2)
free((char *)qpath);
if (qpath != qp && qpath != LOCAL_FileNameBuf && qpath != LOCAL_FileNameBuf2)
free((char *)qpath);
return rc;
}
#if _WIN32 || defined(__MINGW32__)
@ -582,20 +581,19 @@ static const char *expandVars(const char *spec, char *u) {
*/
const char *Yap_AbsoluteFile(const char *spec, char *rc0, bool ok) {
const char *p;
char *rc;
const char *rc;
rc = PlExpandVars(spec, NULL, rc0);
if (!rc)
rc = spec;
if ((p = myrealpath(rc, rc0))) {
if (rc != rc0 && rc != spec && rc != p)
freeBuffer(rc);
return p;
if (rc != rc0 && rc != spec && rc != p)
freeBuffer(rc);
return p;
} else {
if (rc != rc0 && rc != spec)
freeBuffer(rc);
if (rc != rc0 && rc != spec)
freeBuffer(rc);
return NULL;
}
}
/**
@ -1424,7 +1422,7 @@ static Int p_expand_file_name(USES_REGS1) {
if (!(text2 = PlExpandVars(text, NULL, NULL)))
return false;
freeBuffer(text);
bool rc = Yap_unify(ARG2, Yap_MkTextTerm(text2, LOCAL_encoding, t));
bool rc = Yap_unify(ARG2, Yap_MkTextTerm(text2, LOCAL_encoding, t));
freeBuffer(text2);
return rc;
}
@ -2006,8 +2004,8 @@ static wchar_t *WideStringFromAtom(Atom KeyAt USES_REGS) {
"generating key in win_registry_get_value/3");
return false;
}
k = (wchar_t *)Yap_AllocCodeSpace(sz);
}
k = (wchar_t *)Yap_AllocCodeSpace(sz);
}
kptr = k;
while ((*kptr++ = *chp++))
;

View File

@ -22,18 +22,18 @@
//#undef _POSIX_
#endif
#include "Yap.h"
#include "Yatom.h"
#include "YapHeap.h"
#include "yapio.h"
#include "eval.h"
#include "YapText.h"
#include "Yatom.h"
#include "eval.h"
#include "yapio.h"
#if _WIN32 || defined(__MINGW32__)
#include <winsock2.h>
/* Windows */
#include "Shlwapi.h"
#include <direct.h>
#include <io.h>
#include <windows.h>
#include <direct.h>
#include "Shlwapi.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@ -45,13 +45,12 @@
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#endif
#ifdef FENV_H
#include <fenv.h>
#endif
#define S_ISDIR(x) (((x)&_S_IFDIR)==_S_IFDIR)
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
#if HAVE_STDARG_H
#include <stdarg.h>
#endif
@ -67,7 +66,7 @@
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SYS_SELECT_H && !_MSC_VER && !defined(__MINGW32__)
#if HAVE_SYS_SELECT_H && !_MSC_VER && !defined(__MINGW32__)
#include <sys/select.h>
#endif
#if HAVE_STRING_H
@ -89,10 +88,10 @@
#include <fcntl.h>
#endif
#if !HAVE_STRNCAT
#define strncat(X,Y,Z) strcat(X,Y)
#define strncat(X, Y, Z) strcat(X, Y)
#endif
#if !HAVE_STRNCPY
#define strncpy(X,Y,Z) strcpy(X,Y)
#define strncpy(X, Y, Z) strcpy(X, Y)
#endif
#include "iopreds.h"
@ -102,7 +101,7 @@
#endif
#ifdef MPW
#define signal sigset
#define signal sigset
#endif
/* windows.h does not like absmi.h, this
@ -133,7 +132,7 @@
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if _MSC_VER || defined(__MINGW32__)
#if _MSC_VER || defined(__MINGW32__)
#endif
/* CYGWIN seems to include this automatically */
#if HAVE_FENV_H && !defined(__CYGWIN__)
@ -152,10 +151,7 @@
#include <readline/readline.h>
#endif
void Yap_InitRandom (void);
void Yap_InitTime (int wid);
void Yap_InitOSSignals (int wid);
void Yap_InitRandom(void);
void Yap_InitTime(int wid);
void Yap_InitOSSignals(int wid);
void Yap_InitWTime(void);