WINDOWS compatibility

This commit is contained in:
U-WIN-U2045GN0RNQ\Vítor Santos Costa
2011-03-08 00:03:50 +00:00
parent 53137a2502
commit a3f79cede9
23 changed files with 105 additions and 86 deletions

2
packages/PLStream/pl-dtoa.c Normal file → Executable file
View File

@@ -30,7 +30,7 @@
#define MALLOC PL_malloc
#define FREE PL_free
#if defined(_REENTRANT)||defined(__YAP_PROLOG__)
#if defined(_REENTRANT)||( defined(__YAP_PROLOG__) && defined(THREADS))
#define Long int /* 32-bits */
#define MULTIPLE_THREADS

View File

@@ -1796,7 +1796,7 @@ error:
return FALSE;
}
#ifdef __WINDOWS__ /* defined in pl-nt.c */
#if defined(__WINDOWS__) && !defined(__MINGW32__) /* defined in pl-nt.c */
extern int ftruncate(int fileno, int64_t length);
#define HAVE_FTRUNCATE
#endif
@@ -4696,7 +4696,7 @@ static const PL_extension foreigns[] = {
struct PL_local_data *Yap_InitThreadIO(int wid)
{
struct PL_local_data *p = (struct PL_local_data *)malloc(sizeof(struct PL_local_data));
struct PL_local_data *p = (struct PL_local_data *)calloc(sizeof(struct PL_local_data), 1);
if (!p) {
Yap_Error(OUT_OF_HEAP_ERROR, 0L, "Creating thread %d\n", wid);
}

View File

@@ -808,6 +808,9 @@ PRED_IMPL("make_directory", 1, make_directory, 0)
if ( !PL_get_file_name(A1, &n, 0) )
return FALSE;
#if __MINGW32__
#define mkdir(A, B) mkdir(A)
#endif
if ( mkdir(n, 0777) == 0 )
return TRUE;
else

8
packages/PLStream/pl-fmt.c Normal file → Executable file
View File

@@ -33,7 +33,7 @@ source should also use format() to produce error messages, etc.
#include <ctype.h>
static char * formatNumber(bool split, int div, int radix,
bool small, Number n, Buffer out);
bool smll, Number n, Buffer out);
static char * formatFloat(int how, int arg, Number f, Buffer out);
#define MAXRUBBER 100
@@ -877,7 +877,7 @@ emit_rubber(format_state *state)
** Fri Aug 19 22:26:41 1988 jan@swivax.UUCP (Jan Wielemaker) */
static char *
formatNumber(bool split, int div, int radix, bool small, Number i,
formatNumber(bool split, int div, int radix, bool smll, Number i,
Buffer out)
{ switch(i->type)
{ case V_INTEGER:
@@ -912,7 +912,7 @@ formatNumber(bool split, int div, int radix, bool small, Number i,
}
if ( split && before && (digits++ % 3) == 0 && digits != 1 )
*--s = ',';
*--s = digitName((int)(n % radix), small);
*--s = digitName((int)(n % radix), smll);
n /= radix;
}
if ( negative )
@@ -937,7 +937,7 @@ formatNumber(bool split, int div, int radix, bool small, Number i,
buf = tmp;
mpz_get_str(buf, radix, i->value.mpz);
if ( !small && radix > 10 )
if ( !smll && radix > 10 )
{ char *s;
for(s=buf; *s; s++)

View File

@@ -138,6 +138,9 @@ typedef enum
#if HAVE_SYS_PARAM_H
#include <sys/param.h> //MAXPATHLEN
#endif
#ifdef __WINDOWS__
#include <windows.h>
#endif
#if __YAP_PROLOG__
#include "pl-yap.h"
#if _WIN32
@@ -590,6 +593,8 @@ typedef double real;
#define XOS_DOWNCASE 0x01 /* _xos_canonical_filename() */
#define statfunc stat
#ifndef __WINDOWS__
#define __WINDOWS__ 1
#endif
@@ -728,17 +733,17 @@ extern void RemoveTemporaryFiles(void);
extern int Pause(real t);
char *findExecutable(const char *av0, char *buffer);
void setOSPrologFlags(void);
void setRandom(unsigned int *seedp);
char *canoniseFileName(char *path);
char *canonisePath(char *path);
void PL_changed_cwd(void);
struct tm *LocalTime(long *t, struct tm *r);
size_t getenv3(const char *name, char *buf, size_t len);
int Setenv(char *name, char *value);
int Unsetenv(char *name);
int System(char *cmd);
bool expandVars(const char *pattern, char *expanded, int maxlen);
extern void setOSPrologFlags(void);
extern void setRandom(unsigned int *seedp);
extern char *canoniseFileName(char *path);
extern char *canonisePath(char *path);
extern void PL_changed_cwd(void);
extern struct tm *LocalTime(long *t, struct tm *r);
extern size_t getenv3(const char *name, char *buf, size_t len);
extern int Setenv(char *name, char *value);
extern int Unsetenv(char *name);
extern int System(char *cmd);
extern bool expandVars(const char *pattern, char *expanded, int maxlen);
/**** SWI stuff (emulated in pl-yap.c) ****/
extern int writeAtomToStream(IOSTREAM *so, atom_t at);
@@ -757,7 +762,7 @@ PL_EXPORT(int) PL_get_file_nameW(term_t n, wchar_t **name, int flags);
COMMON(int) unifyTime(term_t t, time_t time);
COMMON(char) digitName(int n, int small);
COMMON(char) digitName(int n, int sm);
/**** stuff from pl-utf8.c ****/
size_t utf8_strlen(const char *s, size_t len);

2
packages/PLStream/pl-rl.c Normal file → Executable file
View File

@@ -40,7 +40,7 @@ SWI-Prolog.h and SWI-Stream.h
#include "SWI-Stream.h"
#include "SWI-Prolog.h"
#ifdef __WINDOWS__
#if defined(__WINDOWS__) && !defined(__YAP_PROLOG__)
#ifdef WIN64
#include "config/win64.h"
#else

View File

@@ -22,13 +22,15 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef __WINDOWS__
#if defined(__WINDOWS__)||defined(__WIN32)
#include <uxnt.h>
#ifndef _YAP_NOT_INSTALLED_
#ifdef WIN64
#define MD "config/win64.h"
#else
#define MD "config/win32.h"
#endif
#endif
#include <winsock2.h>
#include "windows/mswchar.h"
#define CRLF_MAPPING 1

4
packages/PLStream/pl-string.c Normal file → Executable file
View File

@@ -102,10 +102,10 @@ remove_string(char *s)
** Fri Jun 10 10:45:40 1988 jan@swivax.UUCP (Jan Wielemaker) */
char
digitName(int n, int small)
digitName(int n, int smll)
{ if (n <= 9)
return n + '0';
return n + (small ? 'a' : 'A') - 10;
return n + (smll ? 'a' : 'A') - 10;
}

2
packages/PLStream/pl-string.h Normal file → Executable file
View File

@@ -27,7 +27,7 @@
COMMON(char *) store_string(const char *s);
COMMON(void) remove_string(char *s);
COMMON(char) digitName(int n, int small);
COMMON(char) digitName(int n, int smll);
COMMON(int) digitValue(int b, int c);
COMMON(bool) strprefix(const char *string, const char *prefix);
COMMON(bool) strpostfix(const char *string, const char *postfix);

View File

@@ -0,0 +1,38 @@
/* $Id$
Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: wielemak@science.uva.nl
WWW: http://www.swi-prolog.org
Copyright (C): 1985-2005, University of 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <wchar.h>
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See pl-mswchar.cpp for the motivation for this nonsense. Used in
pl-fli.c and pl-text.c.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#ifdef __WINDOWS__
#define wcrtomb(s, wc, ps) ms_wcrtomb(s, wc, ps)
#define mbrtowc(pwc, s, n, ps) ms_mbrtowc(pwc, s, n, ps)
extern size_t ms_wcrtomb(char *s, wchar_t wc, mbstate_t *ps);
extern size_t ms_mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
#endif

View File

@@ -61,7 +61,7 @@ DWORD RunSilent(const char* strCommand)
char *pEnvCMD = NULL;
char *pDefaultCMD = "CMD.EXE";
ULONG rc;
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
@@ -71,25 +71,25 @@ DWORD RunSilent(const char* strCommand)
pEnvCMD = getenv("COMSPEC");
if(pEnvCMD){
if(pEnvCMD){
strcpy(Args, pEnvCMD);
} else{
strcpy(Args, pDefaultCMD);
}
/* "/c" option - Do the command then terminate the command window */
strcat(Args, " /c ");
strcat(Args, " /c ");
/*the application you would like to run from the command window */
strcat(Args, strCommand);
strcat(Args, strCommand);
if (!CreateProcess( NULL, Args, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE,
NULL,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&StartupInfo,
&ProcessInfo))
{
return GetLastError();
return GetLastError();
}
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
@@ -100,7 +100,7 @@ DWORD RunSilent(const char* strCommand)
CloseHandle(ProcessInfo.hProcess);
return rc;
}
/*------------------------------------------------------------------------------
@@ -271,15 +271,15 @@ pt_popen(const char *cmd, const char *mode)
siStartInfo.dwFlags = STARTF_USESTDHANDLES;
success = CreateProcessW(NULL,
wcmd, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
wcmd, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
CREATE_NO_WINDOW, // creation flags: without window (?)
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
if ( !success )
goto finito;