vaccinewars

be a doctor and try to vaccinate the world
git clone git://src.adamsgaard.dk/vaccinewars # fast
git clone https://src.adamsgaard.dk/vaccinewars.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit b52aa4f79ec0edf736a7114b22296cf46f62a99a
parent 311dcdb73a679592df474f50244c595464999368
Author: Ben Webb <ben@salilab.org>
Date:   Mon, 26 Aug 2002 12:24:09 +0000

Windows UTF-8 text files are now properly detected as such.


Diffstat:
MTODO | 1-
Msrc/dopewars.c | 29+++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/TODO b/TODO @@ -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 @@ -1800,6 +1800,34 @@ void ScannerErrorHandler(GScanner *scanner, gchar *msg, gint error) 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" */ @@ -1820,6 +1848,7 @@ static gboolean ReadConfigFile(char *FileName, gchar **encoding) 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++;