diff --git a/src/ppload.c b/src/ppload.c index 0e72039..39af17c 100644 --- a/src/ppload.c +++ b/src/ppload.c @@ -1,6 +1,11 @@ #include "pplib.h" +#ifdef _WIN32 /* --ak */ +extern FILE *ppu8open(const char *filename, const char *mode); +#define fopen ppu8open +#endif /* _WIN32 --ak */ + const char * ppobj_kind[] = { "none", "null", "bool", "integer", "number", "name", "string", "array", "dict", "stream", "ref" }; #define ignored_char(c) (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09 || c == 0x00) diff --git a/src/pptest1.c b/src/pptest1.c index eabb0ea..2389eaf 100644 --- a/src/pptest1.c +++ b/src/pptest1.c @@ -61,6 +61,10 @@ static int usage (const char *argv0) return 0; } +#ifdef _WIN32 /* --ak */ +#include +#endif /* _WIN32 --ak */ + int main (int argc, const char **argv) { const char *filepath; @@ -69,6 +73,10 @@ int main (int argc, const char **argv) const void *data; size_t size; +#ifdef _WIN32 /* --ak */ + _setmode(fileno(stdout), _O_BINARY); +#endif /* _WIN32 --ak */ + if (argc < 2) return usage(argv[0]); for (a = 1; a < argc; ++a) diff --git a/src/pptest2.c b/src/pptest2.c index 766110d..70f0b64 100644 --- a/src/pptest2.c +++ b/src/pptest2.c @@ -36,6 +36,10 @@ static void log_callback (const char *message, void *alien) fprintf((FILE *)alien, "\nooops: %s\n", message); } +#ifdef _WIN32 /* --ak */ +#include +#endif /* _WIN32 --ak */ + int main (int argc, const char **argv) { const char *filepath; @@ -54,6 +58,10 @@ int main (int argc, const char **argv) ppname *op; size_t operators; +#ifdef _WIN32 /* --ak */ + _setmode(fileno(stdout), _O_BINARY); +#endif /* _WIN32 --ak */ + if (argc < 2) return usage(argv[0]); ppstream_init_buffers(); diff --git a/src/pptest3.c b/src/pptest3.c index 815ed51..8822dca 100644 --- a/src/pptest3.c +++ b/src/pptest3.c @@ -76,6 +76,10 @@ static void check_stream_chunks (ppstream *stream) #define USE_BUFFERS_POOL 1 +#ifdef _WIN32 /* --ak */ +#include +#endif /* _WIN32 --ak */ + int main (int argc, const char **argv) { const char *filepath; @@ -87,6 +91,10 @@ int main (int argc, const char **argv) ppuint refnum; ppref *ref; +#ifdef _WIN32 /* --ak */ + _setmode(fileno(stdout), _O_BINARY); +#endif /* _WIN32 --ak */ + if (argc < 2) return usage(argv[0]); if (USE_BUFFERS_POOL) diff --git a/src/util/utiliof.c b/src/util/utiliof.c index 41d6fba..836a60e 100644 --- a/src/util/utiliof.c +++ b/src/util/utiliof.c @@ -8,6 +8,11 @@ #include "utillog.h" #include "utiliof.h" +#ifdef _WIN32 /* --ak */ +FILE *ppu8open(const char *filename, const char *mode); +#define fopen ppu8open +#endif /* _WIN32 --ak */ + /* commons */ void * iof_copy_data (const void *data, size_t size) @@ -2969,25 +2974,88 @@ iof * iof_filter_reader_replacement (iof *P, iof_handler handler, size_t statesi return F; } +#ifdef _WIN32 /* --ak */ +#include +#include +#include +/* + Get wide string from multibyte string. (by T. Tanaka) +*/ +static wchar_t * +get_wstring_from_mbstring(int cp, const char *mbstr, wchar_t *wstr) +{ + int len; + len = MultiByteToWideChar(cp, 0, mbstr, -1, wstr, 0); + if (len==0) { + return NULL; + } + if (wstr==NULL) { + wstr = (wchar_t *)util_malloc(sizeof(wchar_t)*(len+1)); + } + len = MultiByteToWideChar(cp, 0, mbstr, -1, wstr, len+1); + if (len==0) { + return NULL; + } + return wstr; +} +FILE *ppu8open(const char *filename, const char *mode) +{ + wchar_t *wfilename, *wmode; + FILE *ret; + int cp; + unsigned char *fnn; + unsigned char *p; + size_t len = strlen(filename); + fnn = (unsigned char *)util_malloc(len + 10); + p = strstr(filename, ".\\"); + if (!p) { + p = strstr(filename, "./"); + } + if (!p && len > 2) { + p = strstr(filename + 2, "//"); + } + if (!p && len > 2) { + p = strstr(filename + 2, "\\\\"); + } + if (!p && len > 2) { + p = strstr(filename + 2, "\\/"); + } + if (!p && len > 2) { + p = strstr(filename + 2, "/\\"); + } + if (!p && len > 2 && ((filename[0] == '/' && filename[1] == '/') || + (filename[0] == '\\' && filename[1] == '\\' && + filename[2] != '?'))) { + filename += 2; + strcpy (fnn, "\\\\?\\UNC\\"); + strcat (fnn, filename); + } else if (!p && len > 2 && filename[1] == ':') { + strcpy (fnn, "\\\\?\\"); + strcat (fnn, filename); + } else { + strcpy (fnn, filename); + } + for (p = fnn; *p; p++) { + if (*p == '/') + *p = '\\'; + } - - - - - - - - - - - - - - - - - - + cp = CP_UTF8; + wfilename = get_wstring_from_mbstring(cp, fnn, wfilename=NULL); + free(fnn); + if (wfilename == NULL) + return NULL; + wmode = get_wstring_from_mbstring(cp, mode, wmode=NULL); + if (wmode == NULL) { + free(wfilename); + return NULL; + } + ret = _wfopen((const wchar_t *)wfilename, (const wchar_t *)wmode); + free(wfilename); + free(wmode); + return ret; +} +#endif /* _WIN32 --ak */ diff --git a/src/util/utilmd5.c b/src/util/utilmd5.c index 8719842..d21a41b 100644 --- a/src/util/utilmd5.c +++ b/src/util/utilmd5.c @@ -61,6 +61,11 @@ #include "utilmd5.h" +#ifdef _WIN32 /* --ak */ +extern FILE *ppu8open(const char *filename, const char *mode); +#define fopen ppu8open +#endif /* _WIN32 --ak */ + #undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ #ifdef ARCH_IS_BIG_ENDIAN # define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) diff --git a/src/util/utilsha.c b/src/util/utilsha.c index 596bf76..269c69a 100644 --- a/src/util/utilsha.c +++ b/src/util/utilsha.c @@ -38,6 +38,11 @@ //#include /* assert() */ #include "utilsha.h" +#ifdef _WIN32 /* --ak */ +extern FILE *ppu8open(const char *filename, const char *mode); +#define fopen ppu8open +#endif /* _WIN32 --ak */ + /* * UNROLLED TRANSFORM LOOP NOTE: * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform