win32 support, especially win does not allow file streaming in memory

This commit is contained in:
Vítor Santos Costa 2016-02-24 02:07:46 +00:00
parent 3af377d610
commit e4e59dedf7
4 changed files with 39 additions and 36 deletions

View File

@ -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));

View File

@ -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

View File

@ -1,4 +1,4 @@
/*************************************************************************
/*************************************************************************post/////85
* *
* YAP Prolog *
* *
@ -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
@ -446,4 +446,3 @@ Yap_InitMems( void )
Yap_InitCPred ("peek_mem_write_stream", 3, peek_mem_write_stream, SyncPredFlag);
CurrentModule = cm;
}

View File

@ -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
@ -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;
@ -672,7 +674,7 @@ Yap_AbsoluteFileInBuffer(const char *spec, char *out, size_t sz, bool ok)
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;
@ -2297,4 +2299,3 @@ Yap_InitSysPreds(void)
Yap_InitCPred ("rmdir", 2, p_rmdir, SyncPredFlag);
Yap_InitCPred ("make_directory", 1, make_directory, SyncPredFlag);
}