win32 support, especially win does not allow file streaming in memory
This commit is contained in:
parent
3af377d610
commit
e4e59dedf7
@ -24,7 +24,7 @@ static int GETW(int sno) {
|
||||
case ENC_ISO_ANSI: {
|
||||
char buf[8];
|
||||
int out;
|
||||
int wch;
|
||||
wchar_t wch;
|
||||
mbstate_t mbstate;
|
||||
|
||||
memset((void *)&(mbstate), 0, sizeof(mbstate_t));
|
||||
|
@ -196,6 +196,9 @@ void Yap_DefaultStreamOps(StreamDesc *st) {
|
||||
if (st->status & (Promptable_Stream_f)) {
|
||||
st->stream_wgetc = get_wchar;
|
||||
Yap_ConsoleOps(st, true);
|
||||
} else if (st->status & (InMemory_Stream_f)) {
|
||||
st->stream_wgetc = get_wchar;
|
||||
Yap_ConsoleOps(st, true);
|
||||
} else if (st->encoding == LOCAL_encoding) {
|
||||
st->stream_wgetc = get_wchar_from_file;
|
||||
} else
|
||||
|
29
os/mem.c
29
os/mem.c
@ -1,4 +1,4 @@
|
||||
/*************************************************************************
|
||||
/*************************************************************************post/////85
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
@ -38,7 +38,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#if HAVE_IO_H
|
||||
/* Windows */
|
||||
#include <io.h>
|
||||
#endif
|
||||
#endif
|
||||
#if HAVE_SOCKET
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
@ -55,11 +55,11 @@ static char SccsId[] = "%W% %G%";
|
||||
FILE * open_memstream (char **buf, size_t *len);
|
||||
#endif
|
||||
|
||||
#if HAVE_FMEMOPEN
|
||||
#if HAVE_FMEMOPEN
|
||||
#define MAY_READ 1
|
||||
#endif
|
||||
|
||||
#if HAVE_OPEN_MEMSTREAM
|
||||
#if HAVE_OPEN_MEMSTREAM
|
||||
#define MAY_READ 1
|
||||
#define MAY_WRITE 1
|
||||
#endif
|
||||
@ -82,12 +82,12 @@ MemGetc (int sno)
|
||||
|
||||
spos = s->u.mem_string.pos;
|
||||
if (spos == s->u.mem_string.max_size) {
|
||||
return post_process_eof(s);
|
||||
return EOF;
|
||||
} else {
|
||||
ch = s->u.mem_string.buf[spos];
|
||||
s->u.mem_string.pos = ++spos;
|
||||
}
|
||||
return post_process_read_char(ch, s);
|
||||
return ch;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -166,7 +166,7 @@ MemPutc(int sno, int ch)
|
||||
FILE *f;
|
||||
encoding_t encoding;
|
||||
stream_flags_t flags;
|
||||
|
||||
|
||||
sno = GetFreeStreamD();
|
||||
if (sno < 0)
|
||||
return (PlIOError (RESOURCE_ERROR_MAX_STREAMS,TermNil, "new stream not available for open_mem_read_stream/1"));
|
||||
@ -254,7 +254,7 @@ Yap_open_buf_write_stream(char *buf, size_t nchars, encoding_t *encp, memBufSou
|
||||
int sno;
|
||||
StreamDesc *st;
|
||||
|
||||
|
||||
|
||||
sno = GetFreeStreamD();
|
||||
if (sno < 0)
|
||||
return -1;
|
||||
@ -322,11 +322,11 @@ open_mem_write_stream (USES_REGS1) /* $open_mem_write_stream(-Stream) */
|
||||
return (Yap_unify (ARG1, t));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Yap_PeekMemwriteStream() shows the current buffer for a memory stream.
|
||||
*
|
||||
*
|
||||
* @param sno, the in-memory stream
|
||||
*
|
||||
*
|
||||
* @return temporary buffer, discarded by close and may be moved away
|
||||
* by other writes..
|
||||
*/
|
||||
@ -413,13 +413,13 @@ bool Yap_CloseMemoryStream( int sno )
|
||||
fclose(GLOBAL_Stream[sno].file);
|
||||
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
||||
free( GLOBAL_Stream[sno].nbuf );
|
||||
#else
|
||||
#else
|
||||
if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_CODE)
|
||||
Yap_FreeAtomSpace(GLOBAL_Stream[sno].u.mem_string.buf);
|
||||
else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) {
|
||||
free(GLOBAL_Stream[sno].u.mem_string.buf);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
} else {
|
||||
#if MAY_READ
|
||||
fclose(GLOBAL_Stream[sno].file);
|
||||
@ -430,7 +430,7 @@ bool Yap_CloseMemoryStream( int sno )
|
||||
else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) {
|
||||
free(GLOBAL_Stream[sno].u.mem_string.buf);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -446,4 +446,3 @@ Yap_InitMems( void )
|
||||
Yap_InitCPred ("peek_mem_write_stream", 3, peek_mem_write_stream, SyncPredFlag);
|
||||
CurrentModule = cm;
|
||||
}
|
||||
|
||||
|
41
os/sysbits.c
41
os/sysbits.c
@ -541,14 +541,14 @@ DirName(const char *X) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static const char *myrealpath( const char *path)
|
||||
static const char *myrealpath( const char *path, char *out)
|
||||
{
|
||||
#if _WIN32 || defined(__MINGW32__)
|
||||
DWORD retval=0;
|
||||
|
||||
// notice that the file does not need to exist
|
||||
retval = GetFullPathName(path,
|
||||
YAP_FILENAME_MAX,
|
||||
MAX_PATH-1,
|
||||
out,
|
||||
NULL);
|
||||
|
||||
@ -594,9 +594,10 @@ static const char *myrealpath( const char *path)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
char *out = malloc(strlen(path)+1);
|
||||
strcpy( out, path);
|
||||
return out;
|
||||
char *rc = malloc(strlen(path)+1);
|
||||
strcpy( rc, path);
|
||||
const char * f = rc;
|
||||
return f;
|
||||
}
|
||||
|
||||
static const char *
|
||||
@ -605,9 +606,10 @@ expandVars(const char *spec)
|
||||
CACHE_REGS
|
||||
#if _WIN32 || defined(__MINGW32__)
|
||||
char u[YAP_FILENAME_MAX+1];
|
||||
char *out;
|
||||
|
||||
// first pass, remove Unix style stuff
|
||||
if ((ou=unix2win(spec, YAP_FILENAME_MAX)) == NULL)
|
||||
if ((out=unix2win(spec, u, YAP_FILENAME_MAX)) == NULL)
|
||||
return NULL;
|
||||
spec = u;
|
||||
#endif
|
||||
@ -619,7 +621,7 @@ expandVars(const char *spec)
|
||||
if (IsPairTerm(t))
|
||||
return RepAtom(AtomOfTerm(HeadOfTerm(t)))->StrOfAE;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
@ -639,7 +641,7 @@ Yap_AbsoluteFile(const char *spec, bool ok)
|
||||
rc = PlExpandVars(spec, NULL, NULL);
|
||||
if (!rc)
|
||||
rc = spec;
|
||||
if ((p = myrealpath(rc) ) ) {
|
||||
if ((p = myrealpath(rc, NULL )) ) {
|
||||
return p;
|
||||
} else {
|
||||
return NULL;
|
||||
@ -648,7 +650,7 @@ Yap_AbsoluteFile(const char *spec, bool ok)
|
||||
}
|
||||
|
||||
/**
|
||||
* generate absolute path and stores path in an user given buffer. If
|
||||
* generate absolute path and stores path in an user given buffer. If
|
||||
* NULL, uses a temporary buffer that must be quickly released.
|
||||
*
|
||||
* if ok first expand variable names and do globbing
|
||||
@ -671,8 +673,8 @@ Yap_AbsoluteFileInBuffer(const char *spec, char *out, size_t sz, bool ok)
|
||||
} else {
|
||||
rc = spec;
|
||||
}
|
||||
|
||||
if ((p = myrealpath(rc) ) ) {
|
||||
|
||||
if ((p = myrealpath(rc, out) ) ) {
|
||||
if (!out) {
|
||||
out = LOCAL_FileNameBuf;
|
||||
sz = YAP_FILENAME_MAX-1;
|
||||
@ -702,15 +704,14 @@ do_glob(const char *spec, bool glob_vs_wordexp)
|
||||
WIN32_FIND_DATA find;
|
||||
HANDLE hFind;
|
||||
CELL *dest;
|
||||
char *espec;
|
||||
Term tf;
|
||||
|
||||
// first pass, remove Unix style stuff
|
||||
if (unix2win(espec, u, YAP_FILENAME_MAX) == NULL)
|
||||
if ((espec =unix2win(spec, u, YAP_FILENAME_MAX)) == NULL)
|
||||
return TermNil;
|
||||
espec = (const char *)u;
|
||||
|
||||
if (!use_system_expansion) {
|
||||
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(espec)), TermNil);
|
||||
}
|
||||
hFind = FindFirstFile(espec, &find);
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
@ -860,6 +861,7 @@ prolog_realpath( USES_REGS1 )
|
||||
{
|
||||
Term t1 = Deref(ARG1);
|
||||
const char *cmd;
|
||||
char out[YAP_FILENAME_MAX];
|
||||
|
||||
if (IsAtomTerm(t1)) {
|
||||
cmd = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||
@ -868,7 +870,7 @@ prolog_realpath( USES_REGS1 )
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
const char *rc = myrealpath( cmd );
|
||||
const char *rc = myrealpath( cmd , out);
|
||||
if (!rc) {
|
||||
PlIOError( SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, strerror(errno));
|
||||
return false;
|
||||
@ -901,7 +903,7 @@ static const param_t expand_filename_defs[] = {EXPAND_FILENAME_DEFS()};
|
||||
|
||||
static Term
|
||||
do_expand_file_name(Term t1, Term opts USES_REGS)
|
||||
{
|
||||
{
|
||||
xarg *args;
|
||||
expand_filename_enum_choices_t i;
|
||||
bool use_system_expansion = true;
|
||||
@ -969,7 +971,7 @@ do_expand_file_name(Term t1, Term opts USES_REGS)
|
||||
/* @pred expand_file_name( +Pattern, -ListOfPaths) is det
|
||||
|
||||
This builtin receives a pattern and expands it into a list of files.
|
||||
In Unix-like systems, YAP applies glob to expand patterns such as '*', '.', and '?'. Further variable expansion
|
||||
In Unix-like systems, YAP applies glob to expand patterns such as '*', '.', and '?'. Further variable expansion
|
||||
may also happen. glob is shell-dependent: som Yap_InitCPred ("absolute_file_system_path", 2, absolute_file_system_path, 0);
|
||||
Yap_InitCPred ("real_path", 2, prolog_realpath, 0);
|
||||
Yap_InitCPred ("true_file_name", 2,
|
||||
@ -1786,7 +1788,7 @@ p_mv ( USES_REGS1 )
|
||||
Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom");
|
||||
} else {
|
||||
oldname = (RepAtom(AtomOfTerm(t1)))->StrOfAE;
|
||||
newname = (RepAtom(AtomOfTerm(t2)))->StrOfAE;
|
||||
newname = (RepAtom(AtomOfTerm(t2)))->StrOfAE;
|
||||
if ((r = link (oldname, newname)) == 0 && (r = unlink (oldname)) != 0)
|
||||
unlink (newname);
|
||||
if (r != 0) {
|
||||
@ -2297,4 +2299,3 @@ Yap_InitSysPreds(void)
|
||||
Yap_InitCPred ("rmdir", 2, p_rmdir, SyncPredFlag);
|
||||
Yap_InitCPred ("make_directory", 1, make_directory, SyncPredFlag);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user