diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index fd7c53deb..ff701dfdf 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -1228,7 +1228,7 @@ write_reports(faction * f, time_t ltime) report_type * rtype = report_types; errno = 0; - printf("Reports for %s:", factionname(f)); + log_stdio(stdout, "Reports for %s:", factionname(f)); fflush(stdout); for (;rtype!=NULL;rtype=rtype->next) { diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 1e61d0f5c..767fdcff2 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -511,7 +511,7 @@ factionorders(void) if (f!=NULL) { const char * pass = getstrtoken(); if (quiet==0) { - printf(" %4s;", factionid(f)); + log_stdio(stdout, " %4s;", factionid(f)); fflush(stdout); } @@ -1363,7 +1363,7 @@ readfaction(FILE * F, int encoding) xrds(F, &f->name, encoding); xrds(F, &f->banner, encoding); - if (quiet==0) printf(" - Lese Partei %s (%s)\n", f->name, factionid(f)); + if (quiet==0) log_stdio(stdout, " - Lese Partei %s (%s)\n", f->name, factionid(f)); rds(F, &email); if (set_email(&f->email, email)!=0) { diff --git a/src/common/util/log.c b/src/common/util/log.c index 0fa5e6a49..158ea206a 100644 --- a/src/common/util/log.c +++ b/src/common/util/log.c @@ -11,6 +11,7 @@ without prior permission by the authors of Eressea. */ #include #include "log.h" +#include "unicode.h" #include #include @@ -20,8 +21,14 @@ without prior permission by the authors of Eressea. /* TODO: set from external function */ int log_flags = LOG_FLUSH|LOG_CPERROR|LOG_CPWARNING; +#ifdef STDIO_CP +static int stdio_codepage = STDIO_CP; +#else +static int stdio_codepage = 0; +#endif static FILE * logfile; +#define MAXLENGTH 4096 /* because I am lazy, CP437 output is limited to this many chars */ void log_flush(void) { @@ -36,6 +43,32 @@ log_puts(const char * str) fputs(str, logfile); } +static int +cp_convert(const char * format, char * buffer, size_t length, int codepage) +{ + /* when console output on MSDOS, convert to codepage */ + const char * input = format; + char * pos = buffer; + + while (pos+1=0xA0) { + *cp_character = (char)ucs4_character; + } else { + struct { wint_t ucs4; unsigned char cp; } xref[] = { + {0x20ac, 0x80}, {0x0081, 0x81}, {0x201a, 0x82}, {0x0192, 0x83}, + {0x201e, 0x84}, {0x2026, 0x85}, {0x2020, 0x86}, {0x2021, 0x87}, + {0x02c6, 0x88}, {0x2030, 0x89}, {0x0160, 0x8a}, {0x2039, 0x8b}, + {0x0152, 0x8c}, {0x008d, 0x8d}, {0x017d, 0x8e}, {0x008f, 0x8f}, + {0x0090, 0x90}, {0x2018, 0x91}, {0x2019, 0x92}, {0x201c, 0x93}, + {0x201d, 0x94}, {0x2022, 0x95}, {0x2013, 0x96}, {0x2014, 0x97}, + {0x02dc, 0x98}, {0x2122, 0x99}, {0x0161, 0x9a}, {0x203a, 0x9b}, + {0x0153, 0x9c}, {0x009d, 0x9d}, {0x017e, 0x9e}, {0x0178, 0x9f} + }; + int l=0, r=sizeof(xref)/sizeof(xref[0]); + while (l!=r) { + int m = (l+r)/2; + if (xref[m].ucs4==ucs4_character) { + *cp_character = (char)xref[m].cp; + break; + } + else if (xref[m].ucs4 #define USE_UNICODE + extern int unicode_utf8_to_cp437(char *ucs4_character, const char *utf8_string, size_t *length); + extern int unicode_utf8_to_cp1252(char *ucs4_character, const char *utf8_string, size_t *length); extern int unicode_utf8_to_ucs4(wint_t *ucs4_character, const char *utf8_string, size_t *length); extern int unicode_utf8_strcasecmp(const char * a, const char * b); extern int unicode_latin1_to_utf8(unsigned char *out, size_t *outlen, const unsigned char *in, size_t *inlen); diff --git a/src/config.h b/src/config.h index c561de9fe..9e9cc462c 100644 --- a/src/config.h +++ b/src/config.h @@ -23,6 +23,7 @@ #define CONFIG_H #ifdef _MSC_VER +# define STDIO_CP 1252 /* log.c, convert to console character set */ # pragma warning (disable: 4201 4214 4514 4115 4711) # pragma warning(disable: 4056) /* warning C4056: overflow in floating point constant arithmetic */ diff --git a/src/scripts/hse4-run.lua b/src/scripts/hse4-run.lua index bc18868d7..becdcbdb3 100644 --- a/src/scripts/hse4-run.lua +++ b/src/scripts/hse4-run.lua @@ -9,8 +9,8 @@ function run_scripts() "hse/portals.lua", "hse/stats.lua" } - for index in scripts do - local script = scriptpath .. "/" .. scripts[index] + for index, value in pairs(scripts) do + local script = scriptpath .. "/" .. value print("- loading " .. script) if pcall(dofile, script)==0 then print("Could not load " .. script) @@ -30,6 +30,7 @@ function process(orders) print("could not read game") return -1 end + init_summary() -- run the turn: read_orders(orders)