Skip to content

Commit

Permalink
patch for Windows MSVC from W32TeX
Browse files Browse the repository at this point in the history
  • Loading branch information
t-tk committed Jul 24, 2021
1 parent da8c7b5 commit 66cecb8
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/ppload.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/pptest1.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ static int usage (const char *argv0)
return 0;
}

#ifdef _WIN32 /* --ak */
#include <fcntl.h>
#endif /* _WIN32 --ak */

int main (int argc, const char **argv)
{
const char *filepath;
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/pptest2.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ static void log_callback (const char *message, void *alien)
fprintf((FILE *)alien, "\nooops: %s\n", message);
}

#ifdef _WIN32 /* --ak */
#include <fcntl.h>
#endif /* _WIN32 --ak */

int main (int argc, const char **argv)
{
const char *filepath;
Expand All @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/pptest3.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static void check_stream_chunks (ppstream *stream)

#define USE_BUFFERS_POOL 1

#ifdef _WIN32 /* --ak */
#include <fcntl.h>
#endif /* _WIN32 --ak */

int main (int argc, const char **argv)
{
const char *filepath;
Expand All @@ -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)
Expand Down
103 changes: 85 additions & 18 deletions src/util/utiliof.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2969,25 +2974,87 @@ iof * iof_filter_reader_replacement (iof *P, iof_handler handler, size_t statesi
return F;
}

#ifdef _WIN32 /* --ak */
#include <malloc.h>
#include <sys/stat.h>
#include <wchar.h>
#include <windows.h>
/*
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 = 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 = 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)
return NULL;
ret = _wfopen((const wchar_t *)wfilename, (const wchar_t *)wmode);
free(wfilename);
free(wmode);
return ret;
}
#endif /* _WIN32 --ak */
5 changes: 5 additions & 0 deletions src/util/utilmd5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/util/utilsha.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
//#include <assert.h> /* 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
Expand Down

0 comments on commit 66cecb8

Please sign in to comment.