From deb756d25ba273b87f371aeb28b3867e33b5439d Mon Sep 17 00:00:00 2001 From: Spoike Date: Wed, 20 Nov 2019 07:14:28 +0000 Subject: [PATCH] Fix some problems in my recent commit. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5584 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/Makefile | 2 +- engine/client/sys_sdl.c | 68 +++++++++++++++++++++++++++++++++++++++++ engine/qclib/qccgui.c | 2 +- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/engine/Makefile b/engine/Makefile index 9f5a42fa6..bcf90e583 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -1809,7 +1809,7 @@ $(OUT_DIR)/%.mo $(OUT_DIR)/%.d : %.m #enables use of precompiled headers in gcc 3.4 onwards. $(OUT_DIR)/quakedef.h.gch : quakedef.h - $(CC) -x c $(ALL_CFLAGS) -o $@ -c $< + $(CC) -x c-header $(ALL_CFLAGS) -o $@ -c $< PRECOMPHEADERS ?= $(OUT_DIR)/quakedef.h.gch ifneq ($(OUT_DIR),) diff --git a/engine/client/sys_sdl.c b/engine/client/sys_sdl.c index b39658e03..e42a2d621 100644 --- a/engine/client/sys_sdl.c +++ b/engine/client/sys_sdl.c @@ -317,6 +317,74 @@ void Sys_Quit (void) //SDL provides no file enumeration facilities. #if defined(_WIN32) #include +//outlen is the size of out in _BYTES_. +wchar_t *widen(wchar_t *out, size_t outbytes, const char *utf8) +{ + size_t outlen; + wchar_t *ret = out; + //utf-8 to utf-16, not ucs-2. + unsigned int codepoint; + int error; + outlen = outbytes/sizeof(wchar_t); + if (!outlen) + return L""; + outlen--; + while (*utf8) + { + codepoint = utf8_decode(&error, utf8, (void*)&utf8); + if (error || codepoint > 0x10FFFFu) + codepoint = 0xFFFDu; + if (codepoint > 0xffff) + { + if (outlen < 2) + break; + outlen -= 2; + codepoint -= 0x10000u; + *out++ = 0xD800 | (codepoint>>10); + *out++ = 0xDC00 | (codepoint&0x3ff); + } + else + { + if (outlen < 1) + break; + outlen -= 1; + *out++ = codepoint; + } + } + *out = 0; + return ret; +} +char *narrowen(char *out, size_t outlen, wchar_t *wide) +{ + char *ret = out; + int bytes; + unsigned int codepoint; + if (!outlen) + return ""; + outlen--; + //utf-8 to utf-16, not ucs-2. + while (*wide) + { + codepoint = *wide++; + if (codepoint >= 0xD800u && codepoint <= 0xDBFFu) + { //handle utf-16 surrogates + if (*wide >= 0xDC00u && *wide <= 0xDFFFu) + { + codepoint = (codepoint&0x3ff)<<10; + codepoint |= *wide++ & 0x3ff; + } + else + codepoint = 0xFFFDu; + } + bytes = utf8_encode(out, codepoint, outlen); + if (bytes <= 0) + break; + out += bytes; + outlen -= bytes; + } + *out = 0; + return ret; +} static int Sys_EnumerateFiles2 (const char *match, int matchstart, int neststart, int (QDECL *func)(const char *fname, qofs_t fsize, time_t mtime, void *parm, searchpathfuncs_t *spath), void *parm, searchpathfuncs_t *spath) { qboolean go; diff --git a/engine/qclib/qccgui.c b/engine/qclib/qccgui.c index 8228b34b0..e5d2278ea 100644 --- a/engine/qclib/qccgui.c +++ b/engine/qclib/qccgui.c @@ -1749,7 +1749,7 @@ void GenericMenu(WPARAM wParam) case IDM_ABOUT: #if defined(SVNREVISION) && defined(SVNDATE) - MessageBox(NULL, "FTE QuakeC Compiler "STRINGIFY(SVNREVISION)" ("SVNDATE")\nWritten by Forethought Entertainment, whoever that is.\n\nIf you have problems with wordpad corrupting your qc files, try saving them using utf-16 encoding via notepad.\nDecompiler component derived from frikdec.", "About", 0); + MessageBox(NULL, "FTE QuakeC Compiler "STRINGIFY(SVNREVISION)" ("STRINGIFY(SVNDATE)")\nWritten by Forethought Entertainment, whoever that is.\n\nIf you have problems with wordpad corrupting your qc files, try saving them using utf-16 encoding via notepad.\nDecompiler component derived from frikdec.", "About", 0); #elif defined(SVNREVISION) MessageBox(NULL, "FTE QuakeC Compiler "STRINGIFY(SVNREVISION)" ("__DATE__" "__TIME__")\nWritten by Forethought Entertainment, whoever that is.\n\nIf you have problems with wordpad corrupting your qc files, try saving them using utf-16 encoding via notepad.\nDecompiler component derived from frikdec.", "About", 0); #else