-
Notifications
You must be signed in to change notification settings - Fork 5
patch for Windows MSVC from W32TeX #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <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 = (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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sanity, if wmode is NULL, wfilename should be freed before return. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is fixed by d315123 |
||
} | ||
ret = _wfopen((const wchar_t *)wfilename, (const wchar_t *)wmode); | ||
free(wfilename); | ||
free(wmode); | ||
return ret; | ||
} | ||
#endif /* _WIN32 --ak */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,11 @@ | |
|
||
#include "utilmd5.h" | ||
|
||
#ifdef _WIN32 /* --ak */ | ||
extern FILE *ppu8open(const char *filename, const char *mode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO would be perfect if such redefinitions were in some dedicated place, like utildecl.h, utilplat.h or a new one, containing only platform-dependent code. |
||
#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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps there should be util_fopen() function explicitly called in other places, instead of hiding fopen() by a macro?