]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - utf8lib.h
Fix inability to access non-ascii path under Windows with WTF-8
[xonotic/darkplaces.git] / utf8lib.h
index 275366e64a2c418f7f1420956e66f67f10e70e3d..cb7041b961108b877c8a2206237470b9bae18d21 100644 (file)
--- a/utf8lib.h
+++ b/utf8lib.h
@@ -1,9 +1,30 @@
+/*
+Copyright (C) 2009-2020 DarkPlaces contributors
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
 /*
  * UTF-8 utility functions for DarkPlaces
  */
 #ifndef UTF8LIB_H__
 #define UTF8LIB_H__
 
+#include <stddef.h>
 #include "qtypes.h"
 
 // types for unicode strings
@@ -19,7 +40,7 @@ typedef int32_t Uchar;
 // a non-utf8 version to work: u8_strlen() will wrap to strlen()
 // u8_byteofs() and u8_charidx() will simply return whatever is passed as index parameter
 // u8_getchar() will will just return the next byte, u8_fromchar will write one byte, ...
-extern cvar_t    utf8_enable;
+extern struct cvar_s utf8_enable;
 void   u8_Init(void);
 
 size_t u8_strlen(const char*);
@@ -57,4 +78,17 @@ extern Uchar u8_quake2utf8map[256];
 Uchar u8_toupper(Uchar ch);
 Uchar u8_tolower(Uchar ch);
 
+#ifdef WIN32
+
+// WTF-8 encoding to circumvent Windows encodings, be it UTF-16 or random codepages
+// https://simonsapin.github.io/wtf-8/
+#define U32 0
+#define CHECKS 1
+typedef wchar_t wchar;
+
+int towtf8(const wchar* wstr, int wlen, char* cstr, int maxclen);
+int fromwtf8(const char* cstr, int clen, wchar* wstr, int maxwlen);
+
+#endif // WIN32
+
 #endif // UTF8LIB_H__