tWindows UTF-8 text files are now properly detected as such. - vaccinewars - be… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit b52aa4f79ec0edf736a7114b22296cf46f62a99a | |
parent 311dcdb73a679592df474f50244c595464999368 | |
Author: Ben Webb <[email protected]> | |
Date: Mon, 26 Aug 2002 12:24:09 +0000 | |
Windows UTF-8 text files are now properly detected as such. | |
Diffstat: | |
M TODO | 1 - | |
M src/dopewars.c | 29 +++++++++++++++++++++++++++++ | |
2 files changed, 29 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/TODO b/TODO | |
t@@ -1,4 +1,3 @@ | |
-- Read mangled "Windows UTF-8" config files properly | |
- Option to let the cops search/fine you rather than shooting at them | |
- Limit rate of server connections to combat DOS attacks / players trying | |
to get a good starting day? | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -1800,6 +1800,34 @@ void ScannerErrorHandler(GScanner *scanner, gchar *msg,… | |
g_print("%s\n", msg); | |
} | |
+/* | |
+ * On Windows systems, check the current config file referenced by "scanner" | |
+ * for a UTF-8 header. If one is found, "conv" and "encoding" are set | |
+ * for UTF-8 encoding. | |
+ */ | |
+static void CheckConfigHeader(GScanner *scanner, Converter *conv, | |
+ gchar **encoding) | |
+{ | |
+#ifdef CYGWIN | |
+ GTokenType token; | |
+ | |
+ token = g_scanner_peek_next_token(scanner); | |
+ if (token == (guchar)'\357') { | |
+ /* OK; assume this is a Windows-style \357 \273 \277 UTF-8 header */ | |
+ if (g_scanner_get_next_token(scanner) != (guchar)'\357' | |
+ || g_scanner_get_next_token(scanner) != (guchar)'\273' | |
+ || g_scanner_get_next_token(scanner) != (guchar)'\277') { | |
+ return; | |
+ } | |
+ Conv_SetCodeset(conv, "UTF-8"); | |
+ if (encoding) { | |
+ g_free(*encoding); | |
+ *encoding = g_strdup("UTF-8"); | |
+ } | |
+ } | |
+#endif | |
+} | |
+ | |
/* | |
* Read a configuration file given by "FileName" | |
*/ | |
t@@ -1820,6 +1848,7 @@ static gboolean ReadConfigFile(char *FileName, gchar **e… | |
scanner->input_name = FileName; | |
scanner->msg_handler = ScannerErrorHandler; | |
g_scanner_input_file(scanner, fileno(fp)); | |
+ CheckConfigHeader(scanner, conv, encoding); | |
while (!g_scanner_eof(scanner)) { | |
if (!ParseNextConfig(scanner, conv, encoding, FALSE)) { | |
ConfigErrors++; |