diff --git a/src/common/attributes/object.c b/src/common/attributes/object.c index 64ebcf20c..3164ebcf0 100644 --- a/src/common/attributes/object.c +++ b/src/common/attributes/object.c @@ -17,11 +17,12 @@ #include "object.h" /* kernel includes */ -#include +#include #include #include +#include #include -#include +#include /* util includes */ #include diff --git a/src/common/attributes/variable.c b/src/common/attributes/variable.c index 393aa9333..14cd49db2 100644 --- a/src/common/attributes/variable.c +++ b/src/common/attributes/variable.c @@ -15,6 +15,8 @@ #include #include "variable.h" +#include + /* libc includes */ #include #include diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index e7dd40584..e608e71ff 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -372,7 +372,7 @@ cr_skill(variant var, char * buffer, const void * userdata) const faction * report = (const faction*)userdata; skill_t sk = (skill_t)var.i; if (sk!=NOSKILL) sprintf(buffer, "\"%s\"", - add_translation(skillnames[sk], skillname(sk, report->locale))); + add_translation(mkname("skill", skillnames[sk]), skillname(sk, report->locale))); else strcpy(buffer, "\"\""); return 0; } @@ -850,7 +850,7 @@ cr_output_unit(FILE * F, const region * r, fprintf(F, "TALENTE\n"); } fprintf(F, "%d %d;%s\n", u->number*level_days(sv->level), esk, - add_translation(skillnames[sk], skillname(sk, f->locale))); + add_translation(mkname("skill", skillnames[sk]), skillname(sk, f->locale))); } } /* spells */ diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 6625b928f..bc54629f4 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -1258,11 +1258,11 @@ init_prefixnames(void) int key; for (key=0;race_prefixes[key];++key) { variant var; - const char * pname = locale_string(lang, race_prefixes[key]); + const char * pname = locale_string(lang, mkname("prefix", race_prefixes[key])); if (findtoken(&in->names, pname, &var)==E_TOK_NOMATCH || var.i!=key) { var.i = key; addtoken(&in->names, pname, var); - addtoken(&in->names, locale_string(lang, race_prefixes[key]), var); + addtoken(&in->names, locale_string(lang, mkname("prefix", race_prefixes[key])), var); } } } @@ -1883,7 +1883,7 @@ mail_cmd(unit * u, struct order * ord) default: /* possibly filler token? */ s = getstrtoken(); - cont = 1; + if (s && *s) cont = 1; break; } } while (cont); diff --git a/src/common/gamecode/monster.c b/src/common/gamecode/monster.c index 72cbd01dd..7baacdb1d 100644 --- a/src/common/gamecode/monster.c +++ b/src/common/gamecode/monster.c @@ -155,7 +155,7 @@ get_money_for_dragon(region * r, unit * u, int wanted) if (rmoney(r) >= wanted) { /* 5% chance, dass der drache aus einer laune raus attackiert */ if (chance(1.0-u->race->aggression)) { - return create_order(K_TAX, default_locale, ""); + return create_order(K_TAX, default_locale, NULL); } } @@ -178,7 +178,7 @@ get_money_for_dragon(region * r, unit * u, int wanted) /* falls die einnahmen erreicht werden, bleibt das monster noch eine * runde hier. */ if (n + rmoney(r) >= wanted) { - return create_order(K_TAX, default_locale, ""); + return create_order(K_TAX, default_locale, NULL); } /* wenn wir NULL zurückliefern, macht der drache was anderes, z.b. weggehen */ @@ -965,7 +965,7 @@ plan_monsters(void) /* All monsters guard the region: */ if (!is_waiting(u) && r->land) { - addlist(&u->orders, create_order(K_GUARD, u->faction->locale, "")); + addlist(&u->orders, create_order(K_GUARD, u->faction->locale, NULL)); } /* Einheiten mit Bewegungsplan kriegen ein NACH: */ @@ -997,7 +997,7 @@ plan_monsters(void) switch (old_race(u->race)) { case RC_SEASERPENT: - long_order = create_order(K_PIRACY, f->locale, ""); + long_order = create_order(K_PIRACY, f->locale, NULL); break; case RC_ALP: long_order = monster_seeks_target(r, u); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 64dbb6183..9c8368c3c 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -38,7 +38,6 @@ /* kernel includes */ #include -#include #include #include #include @@ -48,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -77,7 +75,6 @@ #include #include #include -#include /* libc includes */ #include @@ -621,34 +618,6 @@ rp_battles(FILE * F, faction * f) } } -size_t -f_regionid(const region * r, const faction * f, char * buffer, size_t size) -{ - - if (!r) { - strncpy(buffer, "(Chaos)", size); - } else { - plane * pl = r->planep; - strncpy(buffer, rname(r, f->locale), size); - buffer[size-1]=0; - if (pl==NULL || !fval(pl, PFL_NOCOORDS)) { - sprintf(buffer+strlen(buffer), " (%d,%d%s%s)", region_x(r,f), region_y(r,f), pl?",":"", pl?pl->name:""); - } - } - return strlen(buffer); -} - -static char * -f_regionid_s(const region * r, const faction * f) -{ - static int i = 0; - static char bufs[4][NAMESIZE + 20]; - char * buf = bufs[(++i)%4]; - - f_regionid(r, f, buf, NAMESIZE + 20); - return buf; -} - static void prices(FILE * F, const region * r, const faction * f) { @@ -720,46 +689,6 @@ see_border(const border * b, const faction * f, const region * r) return cs; } -const char * -trailinto(const region * r, const struct locale * lang) -{ - char ref[32]; - const char * s; - if (r) { - const char * tname = terrain_name(r); - strcat(strcpy(ref, tname), "_trail"); - s = locale_string(lang, ref); - if (s && *s) { - if (strstr(s, "%s")) return s; - } - } - return "%s"; -} - -static void -eval_localize(struct opstack ** stack, const void * userdata) /* (string, locale) -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct locale * lang = f?f->locale:default_locale; - const char *c = (const char *)opop_v(stack); - c = locale_string(lang, c); - opush_v(stack, strcpy(balloc(strlen(c)+1), c)); -} - -static void -eval_trail(struct opstack ** stack, const void * userdata) /* (int, int) -> int */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct locale * lang = f?f->locale:default_locale; - const struct region * r = (const struct region*)opop(stack).v; - const char * trail = trailinto(r, lang); - const char * rn = f_regionid_s(r, f); - variant var; - char * x = var.v = balloc(strlen(trail)+strlen(rn)); - sprintf(x, trail, rn); - opush(stack, var); -} - static void describe(FILE * F, const region * r, int partial, faction * f) { @@ -949,6 +878,7 @@ describe(FILE * F, const region * r, int partial, faction * f) if(!r2) continue; nrd--; if (dh) { + char regname[4096]; if (nrd == 0) { strcpy(bufp++, " "); bufp += strxcpy(bufp, LOC(f->locale, "nr_nb_final")); @@ -958,7 +888,7 @@ describe(FILE * F, const region * r, int partial, faction * f) bufp += strxcpy(bufp, LOC(f->locale, directions[d])); strcpy(bufp++, " "); bufp += sprintf(bufp, trailinto(r2, f->locale), - f_regionid_s(r2, f)); + f_regionid(r2, f, regname, sizeof(regname))); } else { strcpy(bufp++, " "); @@ -2326,374 +2256,9 @@ writemonument(void) /******* end summary ******/ -static void -eval_unit(struct opstack ** stack, const void * userdata) /* unit -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct unit * u = (const struct unit *)opop(stack).v; - const char * c = u?unitname(u):LOC(f->locale, "an_unknown_unit"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_unit_dative(struct opstack ** stack, const void * userdata) /* unit -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct unit * u = (const struct unit *)opop(stack).v; - const char * c = u?unitname(u):LOC(f->locale, "unknown_unit_dative"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_spell(struct opstack ** stack, const void * userdata) /* unit -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct spell * sp = (const struct spell *)opop(stack).v; - const char * c = sp?spell_name(sp, f->locale):LOC(f->locale, "an_unknown_spell"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_curse(struct opstack ** stack, const void * userdata) /* unit -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct curse_type * sp = (const struct curse_type *)opop(stack).v; - const char * c = sp?curse_name(sp, f->locale):LOC(f->locale, "an_unknown_curse"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_unitname(struct opstack ** stack, const void * userdata) /* unit -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct unit * u = (const struct unit *)opop(stack).v; - const char * c = u?u->name:LOC(f->locale, "an_unknown_unit"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - - -static void -eval_unitid(struct opstack ** stack, const void * userdata) /* unit -> int */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct unit * u = (const struct unit *)opop(stack).v; - const char * c = u?u->name:LOC(f->locale, "an_unknown_unit"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_unitsize(struct opstack ** stack, const void * userdata) /* unit -> int */ -{ - const struct unit * u = (const struct unit *)opop(stack).v; - variant var; - - var.i = u->number; - opush(stack, var); -} - -static void -eval_faction(struct opstack ** stack, const void * userdata) /* faction -> string */ -{ - const struct faction * f = (const struct faction *)opop(stack).v; - const char * c = factionname(f); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_alliance(struct opstack ** stack, const void * userdata) /* faction -> string */ -{ - const struct alliance * al = (const struct alliance *)opop(stack).v; - const char * c = alliancename(al); - variant var; - if (c!=NULL) { - size_t len = strlen(c); - var.v = strcpy(balloc(len+1), c); - } - else var.v = NULL; - opush(stack, var); -} - -static void -eval_region(struct opstack ** stack, const void * userdata) /* region -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct region * r = (const struct region *)opop(stack).v; - const char * c = regionname(r, f); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_terrain(struct opstack ** stack, const void * userdata) /* region -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct region * r = (const struct region *)opop(stack).v; - const char * c = LOC(f->locale, terrain_name(r)); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_ship(struct opstack ** stack, const void * userdata) /* ship -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct ship * u = (const struct ship *)opop(stack).v; - const char * c = u?shipname(u):LOC(f->locale, "an_unknown_ship"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_building(struct opstack ** stack, const void * userdata) /* building -> string */ -{ - const struct faction * f = (const struct faction *)userdata; - const struct building * u = (const struct building *)opop(stack).v; - const char * c = u?buildingname(u):LOC(f->locale, "an_unknown_building"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_weight(struct opstack ** stack, const void * userdata) /* region -> string */ -{ - char buffer[32]; - const struct faction * f = (const struct faction *)userdata; - const struct locale * lang = f->locale; - int weight = opop_i(stack); - variant var; - - if (weight % SCALEWEIGHT == 0) { - if (weight==SCALEWEIGHT) { - sprintf(buffer, "1 %s", LOC(lang, "weight_unit")); - } else { - sprintf(buffer, "%u %s", weight/SCALEWEIGHT, LOC(lang, "weight_unit_p")); - } - } else { - if (weight==1) { - sprintf(buffer, "1 %s %u", LOC(lang, "weight_per"), SCALEWEIGHT); - } else { - sprintf(buffer, "%u %s %u", weight, LOC(lang, "weight_per_p"), SCALEWEIGHT); - } - } - - var.v = strcpy(balloc(strlen(buffer)+1), buffer); - opush(stack, var); -} - -static void -eval_resource(struct opstack ** stack, const void * userdata) -{ - const faction * report = (const faction*)userdata; - int j = opop(stack).i; - const struct resource_type * res = (const struct resource_type *)opop(stack).v; - const char * c = LOC(report->locale, resourcename(res, j!=1)); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_race(struct opstack ** stack, const void * userdata) -{ - const faction * report = (const faction*)userdata; - int j = opop(stack).i; - const race * r = (const race *)opop(stack).v; - const char * c = LOC(report->locale, rc_name(r, j!=1)); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_order(struct opstack ** stack, const void * userdata) /* order -> string */ -{ - const faction * report = (const faction*)userdata; - const struct order * ord = (const struct order *)opop(stack).v; - static char buf[256]; - size_t len; - variant var; - - write_order(ord, report->locale, buf, sizeof(buf)); - len = strlen(buf); - var.v = strcpy(balloc(len+1), buf); - opush(stack, var); -} - -static void -eval_resources(struct opstack ** stack, const void * userdata) /* order -> string */ -{ - const faction * report = (const faction*)userdata; - const struct resource * res = (const struct resource *)opop(stack).v; - static char buf[256]; - size_t len = sizeof(buf); - variant var; - - char * edit = buf; - while (res!=NULL && len > 4) { - const char * rname = resourcename(res->type, (res->number!=1)?NMF_PLURAL:0); - int written = snprintf(edit, len, "%d %s", res->number, LOC(report->locale, rname)); - len -= written; - edit += written; - - res = res->next; - if (res!=NULL && len>2) { - strcat(edit, ", "); - edit += 2; - len -= 2; - } - } - *edit = 0; - var.v = strcpy(balloc(edit-buf+1), buf); - opush(stack, var); -} - -static void -eval_regions(struct opstack ** stack, const void * userdata) /* order -> string */ -{ - const faction * report = (const faction*)userdata; - int i = opop(stack).i; - int end, begin = opop(stack).i; - const arg_regions * regions = (const arg_regions *)opop(stack).v; - static char buf[256]; - size_t len = sizeof(buf); - variant var; - char * edit = buf; - - if (regions==NULL) { - end = begin; - } else { - if (i>=0) end = begin+i; - else end = regions->nregions+i; - } - for (i=begin;iregions[i], report); - size_t written = strlcpy(edit, rname, len); - len -= written; - edit += written; - - if (i+12) { - strcat(edit, ", "); - edit += 2; - len -= 2; - } - } - *edit = 0; - var.v = strcpy(balloc(edit-buf+1), buf); - opush(stack, var); -} - -static void -eval_direction(struct opstack ** stack, const void * userdata) -{ - const faction * report = (const faction*)userdata; - int i = opop(stack).i; - const char * c = LOC(report->locale, (i>=0)?directions[i]:"unknown_direction"); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_skill(struct opstack ** stack, const void * userdata) -{ - const faction * report = (const faction*)userdata; - skill_t sk = (skill_t)opop(stack).i; - const char * c = skillname(sk, report->locale); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); -} - -static void -eval_int36(struct opstack ** stack, const void * userdata) -{ - int i = opop(stack).i; - const char * c = itoa36(i); - size_t len = strlen(c); - variant var; - - var.v = strcpy(balloc(len+1), c); - opush(stack, var); - unused(userdata); -} - void report_init(void) { - /* register functions that turn message contents to readable strings */ - add_function("alliance", &eval_alliance); - add_function("region", &eval_region); - add_function("terrain", &eval_terrain); - add_function("weight", &eval_weight); - add_function("resource", &eval_resource); - add_function("race", &eval_race); - add_function("faction", &eval_faction); - add_function("ship", &eval_ship); - add_function("unit", &eval_unit); - add_function("unit.dative", &eval_unit_dative); - add_function("unit.name", &eval_unitname); - add_function("unit.id", &eval_unitid); - add_function("unit.size", &eval_unitsize); - add_function("building", &eval_building); - add_function("skill", &eval_skill); - add_function("order", &eval_order); - add_function("direction", &eval_direction); - add_function("int36", &eval_int36); - add_function("trail", &eval_trail); - add_function("localize", &eval_localize); - add_function("spell", &eval_spell); - add_function("curse", &eval_curse); - add_function("resources", &eval_resources); - add_function("regions", &eval_regions); - register_reporttype("nr", &report_plaintext, 1<no == 1) { - return LOC(u->faction->locale, u->race->_name[0]); + return LOC(u->faction->locale, mkname("race", u->race->_name[0])); } - return LOC(u->faction->locale, u->race->_name[1]); + return LOC(u->faction->locale, mkname("race", u->race->_name[1])); } const char * diff --git a/src/common/kernel/order.c b/src/common/kernel/order.c index fd12cd812..636ef10ad 100644 --- a/src/common/kernel/order.c +++ b/src/common/kernel/order.c @@ -265,37 +265,43 @@ create_order_i(keyword_t kwd, const char * sptr, int persistent, const struct lo order * create_order(keyword_t kwd, const struct locale * lang, const char * params, ...) { - va_list marker; char zBuffer[DISPLAYSIZE]; - char * sptr = zBuffer; + if (params) { + char * sptr = zBuffer; + va_list marker; - va_start(marker, params); - while (*params) { - switch (*params) { - case '%': - /* ignore these, they are syntactical sugar */ - break; - case '"': - case '\'': - case ' ': + va_start(marker, params); + while (*params) { + if (*params=='%') { + int i; + const char * s; + ++params; + switch (*params) { + case 's': + s = va_arg(marker, const char *); + sptr += strlcpy(sptr, s, sizeof(zBuffer)-(sptr-zBuffer)); + break; + case 'd': + i = va_arg(marker, int); + sptr += strlcpy(sptr, itoa10(i), sizeof(zBuffer)-(sptr-zBuffer)); + break; + case 'i': + i = va_arg(marker, int); + sptr += strlcpy(sptr, itoa36(i), sizeof(zBuffer)-(sptr-zBuffer)); + break; + default: + assert(!"unknown format-character in create_order"); + } + } else { *sptr++ = *params; - break; - case 's': - sptr += strlcpy(sptr, va_arg(marker, const char *), sizeof(zBuffer)-(sptr-zBuffer)); - break; - case 'd': - sptr += strlcpy(sptr, itoa10(va_arg(marker, int)), sizeof(zBuffer)-(sptr-zBuffer)); - break; - case 'i': - sptr += strlcpy(sptr, itoa36(va_arg(marker, int)), sizeof(zBuffer)-(sptr-zBuffer)); - break; - default: - assert(!"unknown format-character in create_order"); + } + ++params; } - ++params; + va_end(marker); + *sptr = 0; + } else { + zBuffer[0] = 0; } - va_end(marker); - return create_order_i(kwd, zBuffer, 0, lang); } diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 528d26c98..be7067cc8 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -128,7 +128,7 @@ write_regionname(const region * r, const faction * f, char * buffer, size_t size const char * regionname(const region * r, const faction * f) { - static char buf[65]; + static char buf[NAMESIZE]; return write_regionname(r, f, buf, sizeof(buf)); } @@ -758,7 +758,8 @@ r_setdemand(region * r, const luxury_type * ltype, int value) while (*dp && (*dp)->type != ltype) dp = &(*dp)->next; d = *dp; if (!d) { - d = *dp = calloc(sizeof(struct demand), 1); + d = *dp = malloc(sizeof(struct demand)); + d->next = NULL; d->type = ltype; } d->value = value; @@ -945,9 +946,10 @@ setluxuries(region * r, const luxury_type * sale) if(r->land->demands) freelist(r->land->demands); for (ltype=luxurytypes; ltype; ltype=ltype->next) { - struct demand * dmd = calloc(sizeof(struct demand), 1); + struct demand * dmd = malloc(sizeof(struct demand)); dmd->type = ltype; if (ltype!=sale) dmd->value = 1 + rng_int() % 5; + else dmd->value = 0; dmd->next = r->land->demands; r->land->demands = dmd; } diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index 0b8d0c0e1..a8eac9d87 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -22,6 +22,7 @@ #include "reports.h" /* kernel includes */ +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -1553,6 +1556,416 @@ var_free_regions(variant x) free(x.v); } +const char * +trailinto(const region * r, const struct locale * lang) +{ + char ref[32]; + const char * s; + if (r) { + const char * tname = terrain_name(r); + strcat(strcpy(ref, tname), "_trail"); + s = locale_string(lang, ref); + if (s && *s) { + if (strstr(s, "%s")) return s; + } + } + return "%s"; +} + +size_t +f_regionid(const region * r, const faction * f, char * buffer, size_t size) +{ + + if (!r) { + strncpy(buffer, "(Chaos)", size); + } else { + plane * pl = r->planep; + strncpy(buffer, rname(r, f->locale), size); + buffer[size-1]=0; + if (pl==NULL || !fval(pl, PFL_NOCOORDS)) { + sprintf(buffer+strlen(buffer), " (%d,%d%s%s)", region_x(r,f), region_y(r,f), pl?",":"", pl?pl->name:""); + } + } + return strlen(buffer); +} + +static char * +f_regionid_s(const region * r, const faction * f) +{ + static int i = 0; + static char bufs[4][NAMESIZE + 20]; + char * buf = bufs[(++i)%4]; + + f_regionid(r, f, buf, NAMESIZE + 20); + return buf; +} + +/*** BEGIN MESSAGE RENDERING ***/ +static void +eval_localize(struct opstack ** stack, const void * userdata) /* (string, locale) -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct locale * lang = f?f->locale:default_locale; + const char *c = (const char *)opop_v(stack); + c = locale_string(lang, c); + opush_v(stack, strcpy(balloc(strlen(c)+1), c)); +} + +static void +eval_trail(struct opstack ** stack, const void * userdata) /* (int, int) -> int */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct locale * lang = f?f->locale:default_locale; + const struct region * r = (const struct region*)opop(stack).v; + const char * trail = trailinto(r, lang); + const char * rn = f_regionid_s(r, f); + variant var; + char * x = var.v = balloc(strlen(trail)+strlen(rn)); + sprintf(x, trail, rn); + opush(stack, var); +} + +static void +eval_unit(struct opstack ** stack, const void * userdata) /* unit -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct unit * u = (const struct unit *)opop(stack).v; + const char * c = u?unitname(u):LOC(f->locale, "an_unknown_unit"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_unit_dative(struct opstack ** stack, const void * userdata) /* unit -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct unit * u = (const struct unit *)opop(stack).v; + const char * c = u?unitname(u):LOC(f->locale, "unknown_unit_dative"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_spell(struct opstack ** stack, const void * userdata) /* unit -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct spell * sp = (const struct spell *)opop(stack).v; + const char * c = sp?spell_name(sp, f->locale):LOC(f->locale, "an_unknown_spell"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_curse(struct opstack ** stack, const void * userdata) /* unit -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct curse_type * sp = (const struct curse_type *)opop(stack).v; + const char * c = sp?curse_name(sp, f->locale):LOC(f->locale, "an_unknown_curse"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_unitname(struct opstack ** stack, const void * userdata) /* unit -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct unit * u = (const struct unit *)opop(stack).v; + const char * c = u?u->name:LOC(f->locale, "an_unknown_unit"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + + +static void +eval_unitid(struct opstack ** stack, const void * userdata) /* unit -> int */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct unit * u = (const struct unit *)opop(stack).v; + const char * c = u?u->name:LOC(f->locale, "an_unknown_unit"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_unitsize(struct opstack ** stack, const void * userdata) /* unit -> int */ +{ + const struct unit * u = (const struct unit *)opop(stack).v; + variant var; + + var.i = u->number; + opush(stack, var); +} + +static void +eval_faction(struct opstack ** stack, const void * userdata) /* faction -> string */ +{ + const struct faction * f = (const struct faction *)opop(stack).v; + const char * c = factionname(f); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_alliance(struct opstack ** stack, const void * userdata) /* faction -> string */ +{ + const struct alliance * al = (const struct alliance *)opop(stack).v; + const char * c = alliancename(al); + variant var; + if (c!=NULL) { + size_t len = strlen(c); + var.v = strcpy(balloc(len+1), c); + } + else var.v = NULL; + opush(stack, var); +} + +static void +eval_region(struct opstack ** stack, const void * userdata) /* region -> string */ +{ + char name[NAMESIZE+32]; + const struct faction * f = (const struct faction *)userdata; + const struct region * r = (const struct region *)opop(stack).v; + const char * c = write_regionname(r, f, name, sizeof(name)); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_terrain(struct opstack ** stack, const void * userdata) /* region -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct region * r = (const struct region *)opop(stack).v; + const char * c = LOC(f->locale, terrain_name(r)); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_ship(struct opstack ** stack, const void * userdata) /* ship -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct ship * u = (const struct ship *)opop(stack).v; + const char * c = u?shipname(u):LOC(f->locale, "an_unknown_ship"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_building(struct opstack ** stack, const void * userdata) /* building -> string */ +{ + const struct faction * f = (const struct faction *)userdata; + const struct building * u = (const struct building *)opop(stack).v; + const char * c = u?buildingname(u):LOC(f->locale, "an_unknown_building"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_weight(struct opstack ** stack, const void * userdata) /* region -> string */ +{ + char buffer[32]; + const struct faction * f = (const struct faction *)userdata; + const struct locale * lang = f->locale; + int weight = opop_i(stack); + variant var; + + if (weight % SCALEWEIGHT == 0) { + if (weight==SCALEWEIGHT) { + sprintf(buffer, "1 %s", LOC(lang, "weight_unit")); + } else { + sprintf(buffer, "%u %s", weight/SCALEWEIGHT, LOC(lang, "weight_unit_p")); + } + } else { + if (weight==1) { + sprintf(buffer, "1 %s %u", LOC(lang, "weight_per"), SCALEWEIGHT); + } else { + sprintf(buffer, "%u %s %u", weight, LOC(lang, "weight_per_p"), SCALEWEIGHT); + } + } + + var.v = strcpy(balloc(strlen(buffer)+1), buffer); + opush(stack, var); +} + +static void +eval_resource(struct opstack ** stack, const void * userdata) +{ + const faction * report = (const faction*)userdata; + int j = opop(stack).i; + const struct resource_type * res = (const struct resource_type *)opop(stack).v; + const char * c = LOC(report->locale, resourcename(res, j!=1)); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_race(struct opstack ** stack, const void * userdata) +{ + const faction * report = (const faction*)userdata; + int j = opop(stack).i; + const race * r = (const race *)opop(stack).v; + const char * c = LOC(report->locale, rc_name(r, j!=1)); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_order(struct opstack ** stack, const void * userdata) /* order -> string */ +{ + const faction * report = (const faction*)userdata; + const struct order * ord = (const struct order *)opop(stack).v; + static char buf[256]; + size_t len; + variant var; + + write_order(ord, report->locale, buf, sizeof(buf)); + len = strlen(buf); + var.v = strcpy(balloc(len+1), buf); + opush(stack, var); +} + +static void +eval_resources(struct opstack ** stack, const void * userdata) /* order -> string */ +{ + const faction * report = (const faction*)userdata; + const struct resource * res = (const struct resource *)opop(stack).v; + static char buf[256]; + size_t len = sizeof(buf); + variant var; + + char * edit = buf; + while (res!=NULL && len > 4) { + const char * rname = resourcename(res->type, (res->number!=1)?NMF_PLURAL:0); + int written = snprintf(edit, len, "%d %s", res->number, LOC(report->locale, rname)); + len -= written; + edit += written; + + res = res->next; + if (res!=NULL && len>2) { + strcat(edit, ", "); + edit += 2; + len -= 2; + } + } + *edit = 0; + var.v = strcpy(balloc(edit-buf+1), buf); + opush(stack, var); +} + +static void +eval_regions(struct opstack ** stack, const void * userdata) /* order -> string */ +{ + const faction * report = (const faction*)userdata; + int i = opop(stack).i; + int end, begin = opop(stack).i; + const arg_regions * regions = (const arg_regions *)opop(stack).v; + static char buf[256]; + size_t len = sizeof(buf); + variant var; + char * edit = buf; + + if (regions==NULL) { + end = begin; + } else { + if (i>=0) end = begin+i; + else end = regions->nregions+i; + } + for (i=begin;iregions[i], report); + size_t written = strlcpy(edit, rname, len); + len -= written; + edit += written; + + if (i+12) { + strcat(edit, ", "); + edit += 2; + len -= 2; + } + } + *edit = 0; + var.v = strcpy(balloc(edit-buf+1), buf); + opush(stack, var); +} + +static void +eval_direction(struct opstack ** stack, const void * userdata) +{ + const faction * report = (const faction*)userdata; + int i = opop(stack).i; + const char * c = LOC(report->locale, (i>=0)?directions[i]:"unknown_direction"); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_skill(struct opstack ** stack, const void * userdata) +{ + const faction * report = (const faction*)userdata; + skill_t sk = (skill_t)opop(stack).i; + const char * c = skillname(sk, report->locale); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); +} + +static void +eval_int36(struct opstack ** stack, const void * userdata) +{ + int i = opop(stack).i; + const char * c = itoa36(i); + size_t len = strlen(c); + variant var; + + var.v = strcpy(balloc(len+1), c); + opush(stack, var); + unused(userdata); +} +/*** END MESSAGE RENDERING ***/ + void reports_init(void) { @@ -1576,6 +1989,32 @@ reports_init(void) register_argtype("items", var_free_resources, var_copy_items, VAR_VOIDPTR); register_argtype("regions", var_free_regions, var_copy_regions, VAR_VOIDPTR); + /* register functions that turn message contents to readable strings */ + add_function("alliance", &eval_alliance); + add_function("region", &eval_region); + add_function("terrain", &eval_terrain); + add_function("weight", &eval_weight); + add_function("resource", &eval_resource); + add_function("race", &eval_race); + add_function("faction", &eval_faction); + add_function("ship", &eval_ship); + add_function("unit", &eval_unit); + add_function("unit.dative", &eval_unit_dative); + add_function("unit.name", &eval_unitname); + add_function("unit.id", &eval_unitid); + add_function("unit.size", &eval_unitsize); + add_function("building", &eval_building); + add_function("skill", &eval_skill); + add_function("order", &eval_order); + add_function("direction", &eval_direction); + add_function("int36", &eval_int36); + add_function("trail", &eval_trail); + add_function("localize", &eval_localize); + add_function("spell", &eval_spell); + add_function("curse", &eval_curse); + add_function("resources", &eval_resources); + add_function("regions", &eval_regions); + /* register alternative visibility functions */ register_function((pf_generic)view_neighbours, "view_neighbours"); register_function((pf_generic)view_regatta, "view_regatta"); diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index 647b3bbd6..22859f828 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -116,6 +116,7 @@ extern const char * report_kampfstatus(const struct unit * u, const struct local struct region ** regions; } arg_regions; + extern size_t f_regionid(const struct region * r, const struct faction * f, char * buffer, size_t size); #ifdef __cplusplus } diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 75ceef2fe..e3a7ee895 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -87,8 +87,8 @@ const char * xmlfile = "eressea.xml"; const char * g_datadir; int firstx = 0, firsty = 0; -const char * enc_gamedata = NULL; -const char * enc_orderfile = NULL; +int enc_gamedata = 0; +int enc_orderfile = 0; /* local symbols */ static region * current_region; @@ -246,6 +246,109 @@ convertunique(faction * f) } #endif +int +freadstr(FILE * F, int encoding, char * start, size_t size) +{ + char * str = start; + boolean quote = false; + for (;;) { + int c = fgetc(F); + + if (isspace(c)) { + if (str==start) { + continue; + } + if (!quote) { + *str = 0; + return (int)(str-start); + } + } + switch (c) { + case EOF: + return EOF; + case '"': + if (!quote && str!=start) { + log_error(("datafile contains a \" that isn't at the start of a string.\n")); + assert(!"datafile contains a \" that isn't at the start of a string.\n"); + } + if (quote) { + *str = 0; + return (int)(str-start); + } + quote = true; + break; + case '\\': + c = fgetc(F); + switch (c) { + case EOF: + return EOF; + case 'n': + if ((size_t)(str-start+1)0) str+=ret; + } else { + *str++ = (char)c; + } + } + } + break; + default: + if ((size_t)(str-start+1)0) str+=ret; + } else { + *str++ = (char)c; + } + } + } + } +} + +/** writes a quoted string to the file +* no trailing space, since this is used to make the creport. +*/ +int +fwritestr(FILE * F, const char * str) +{ + int nwrite = 0; + fputc('\"', F); + while (*str) { + int c = (int)(unsigned char)*str++; + switch (c) { + case '"': + case '\\': + fputc('\\', F); + fputc(c, F); + nwrite+=2; + break; + case '\n': + fputc('\\', F); + fputc('n', F); + nwrite+=2; + break; + default: + fputc(c, F); + ++nwrite; + } + } + fputc('\"', F); + return nwrite + 2; +} + + static void rds(FILE * F, void **ds) { @@ -283,61 +386,12 @@ rds(FILE * F, void **ds) } } -static int -xrs(FILE * F, char *dest, size_t size, int encoding) -{ - char buffer[4096]; - char * begin = dest; - char * s = begin; - boolean quote = false; - size_t maxs = size; - - for (;;) { - int c = getc(F); - - if (c=='"') { - if (quote) { - c = getc(F); - if (isspace(c)) break; - } else if (s==begin) { - quote = true; - continue; - } - } else if (isspace(c) && !quote) { - break; - } - - if ((c & 0x80) && encoding!=XML_CHAR_ENCODING_NONE && encoding!=XML_CHAR_ENCODING_UTF8) { - if (begin!=buffer) { - size_t cp = s-begin; - maxs = min(sizeof(buffer), maxs); - if (cp>maxs) cp = maxs; - memcpy(buffer, begin, cp); - begin = buffer; - s = begin + cp; - } - } - *s++ = (char)c; - } - *s = 0; - if (begin==buffer) { - // convert - const char * inbuf = begin; - char * outbuf = dest; - int inbytes = (int)(s-begin)+1; - int outbytes = (int)size; - - assert(encoding==XML_CHAR_ENCODING_8859_1); - return isolat1ToUTF8((xmlChar *)outbuf, &outbytes, (const xmlChar *)inbuf, &inbytes); - } - return (int)(s-begin); -} static void xrds(FILE * F, void **ds, int encoding) { static char buffer[DISPLAYSIZE + 1]; /*Platz für null-char nicht vergessen!*/ - int len = xrs(F, buffer, sizeof(buffer), encoding); + int len = freadstr(F, encoding, buffer, sizeof(buffer)); if (len>=0) { if (ds) { @@ -1314,7 +1368,7 @@ readregion(FILE * F, int encoding, short x, short y) rawmaterial * res; rss(F, token, sizeof(token)); if (strcmp(token, "end")==0) break; - res = calloc(sizeof(rawmaterial), 1); + res = malloc(sizeof(rawmaterial)); res->type = rmt_find(token); if (res->type==NULL) { log_error(("invalid resourcetype %s in data.\n", token)); @@ -1322,6 +1376,7 @@ readregion(FILE * F, int encoding, short x, short y) assert(res->type!=NULL); res->level = ri(F); res->amount = ri(F); + res->flags = 0; if(global.data_version >= RANDOMIZED_RESOURCES_VERSION) { res->startlevel = ri(F); @@ -1341,6 +1396,7 @@ readregion(FILE * F, int encoding, short x, short y) *pres = res; pres=&res->next; } + *pres = NULL; } rss(F, token, sizeof(token)); if (strcmp(token, "noherb") != 0) { @@ -1672,7 +1728,7 @@ writefaction(FILE * F, const faction * f) } int -readgame(const char * filename, int backup, const char * encoding) +readgame(const char * filename, int backup, int encoding) { int i, n, p; faction *f, **fp; @@ -1684,7 +1740,6 @@ readgame(const char * filename, int backup, const char * encoding) int rmax = maxregions; char path[MAX_PATH]; char token[32]; - int enc = xmlParseCharEncoding(encoding); sprintf(path, "%s/%s", datapath(), filename); log_printf("- reading game data from %s\n", filename); @@ -1732,7 +1787,7 @@ readgame(const char * filename, int backup, const char * encoding) while(--n >= 0) { plane *pl = calloc(1, sizeof(plane)); pl->id = ri(F); - xrds(F, &pl->name, enc); + xrds(F, &pl->name, encoding); pl->minx = (short)ri(F); pl->maxx = (short)ri(F); pl->miny = (short)ri(F); @@ -1767,7 +1822,7 @@ readgame(const char * filename, int backup, const char * encoding) /* fflush (stdout); */ while (--n >= 0) { - faction * f = readfaction(F, enc); + faction * f = readfaction(F, encoding); *fp = f; fp = &f->next; @@ -1825,7 +1880,7 @@ readgame(const char * filename, int backup, const char * encoding) } --rmax; - r = readregion(F, enc, x, y); + r = readregion(F, encoding, x, y); /* Burgen */ p = ri(F); @@ -1838,9 +1893,9 @@ readgame(const char * filename, int backup, const char * encoding) *bp = b; bp = &b->next; bhash(b); - xrds(F, &b->name, enc); + xrds(F, &b->name, encoding); if (lomem) rds(F, 0); - else xrds(F, &b->display, enc); + else xrds(F, &b->display, encoding); b->size = ri(F); if (global.data_version < TYPES_VERSION) { assert(!"data format is no longer supported"); @@ -1865,9 +1920,9 @@ readgame(const char * filename, int backup, const char * encoding) *shp = sh; shp = &sh->next; shash(sh); - xrds(F, &sh->name, enc); + xrds(F, &sh->name, encoding); if (lomem) rds(F, NULL); - else xrds(F, &sh->display, enc); + else xrds(F, &sh->display, encoding); rss(F, token, sizeof(token)); sh->type = st_find(token); @@ -1893,7 +1948,7 @@ readgame(const char * filename, int backup, const char * encoding) up = &r->units; while (--p >= 0) { - unit * u = readunit(F, enc); + unit * u = readunit(F, encoding); sc_mage * mage; assert(u->region==NULL); diff --git a/src/common/kernel/save.h b/src/common/kernel/save.h index 883e113f1..321e2b05f 100644 --- a/src/common/kernel/save.h +++ b/src/common/kernel/save.h @@ -36,7 +36,7 @@ double version(void); FILE * cfopen(const char *filename, const char *mode); int readorders(const char *filename, const char * encoding); int creategame(void); -extern int readgame(const char * filename, int backup, const char * encoding); +extern int readgame(const char * filename, int backup, int encoding); int writegame(const char *filename, int quiet); extern void rsf(FILE * F, char *s, size_t len); @@ -47,8 +47,8 @@ extern int data_version; extern int maxregions; extern int firstx, firsty; extern const char *xmlfile; -extern const char * enc_gamedata; -extern const char * enc_orderfile; +extern int enc_gamedata; +extern int enc_orderfile; extern void init_locales(void); extern int lastturn(void); @@ -81,6 +81,9 @@ extern int a_readstring(struct attrib * a, FILE * F); extern void a_writestring(const struct attrib * a, FILE * F); extern void a_finalizestring(struct attrib * a); +extern int freadstr(FILE * F, int encoding, char * str, size_t size); +extern int fwritestr(FILE * F, const char * str); + extern void create_backup(char *file); #ifdef __cplusplus diff --git a/src/common/spells/spells.c b/src/common/spells/spells.c index 091170c98..ebdeef15c 100644 --- a/src/common/spells/spells.c +++ b/src/common/spells/spells.c @@ -2404,7 +2404,7 @@ patzer_peasantmob(castorder *co) u = create_unit(r, f, n, new_race[RC_PEASANT], 0, LOC(f->locale, "angry_mob"), NULL); fset(u, UFL_ISNEW); /* guard(u, GUARD_ALL); hier zu früh! Befehl BEWACHE setzten */ - addlist(&u->orders, create_order(K_GUARD, lang, "")); + addlist(&u->orders, create_order(K_GUARD, lang, NULL)); set_order(&u->thisorder, default_order(lang)); a = a_new(&at_unitdissolve); a->data.ca[0] = 1; /* An rpeasants(r). */ diff --git a/src/common/util/filereader.c b/src/common/util/filereader.c index 278581d07..834f6d312 100644 --- a/src/common/util/filereader.c +++ b/src/common/util/filereader.c @@ -4,6 +4,11 @@ #include #include +#include + +#include +#include + #define COMMENT_CHAR ';' #define CONTINUE_CHAR '\\' #define MAXLINE 4096*16 @@ -22,7 +27,6 @@ eatwhite(const char * ptr, size_t * total_size) int ret = 0; *total_size = 0; -#ifdef USE_UNICODE while (*ptr) { wint_t ucs; @@ -33,15 +37,128 @@ eatwhite(const char * ptr, size_t * total_size) *total_size += size; ptr += size; } -#else - *total_size = 0; - while (ptr[*total_size] && isspace(*(unsigned char*)ptr[*total_size])) ++*total_size; -#endif return ret; } -const char * -getbuf(FILE * F, int encoding) +static const char * +getbuf_latin1(FILE * F) +{ + boolean cont = false; + char quote = 0; + boolean comment = false; + char * cp = fbuf; + char * tail = lbuf+MAXLINE-2; + + tail[1] = '@'; /* if this gets overwritten by fgets then the line was very long. */ + do { + const char * bp = fgets(lbuf, MAXLINE, F); + + if (bp==NULL) return NULL; + while (*bp && isspace(*(unsigned char*)bp)) ++bp; /* eatwhite */ + + comment = (boolean)(comment && cont); + + if (tail[1]==0) { + /* we read he maximum number of bytes! */ + if (tail[0]!='\n') { + /* it wasn't enough space to finish the line, eat the rest */ + for (;;) { + tail[1] = '@'; + bp = fgets(lbuf, MAXLINE, F); + if (bp==NULL) return NULL; + if (tail[1]) { + /* read enough this time to end the line */ + break; + } + } + comment = false; + cont = false; + bp = NULL; + continue; + } else { + tail[1] = '@'; + } + } + cont = false; + while (*bp && cp0) cp+=ret; + ++bp; + continue; + } + } + if (cp==fbuf+MAXLINE) { + --cp; + } + *cp=0; + } while (cont || cp==fbuf); + return fbuf; +} + +static const char * +getbuf_utf8(FILE * F) { boolean cont = false; char quote = 0; @@ -74,7 +191,9 @@ getbuf(FILE * F, int encoding) } } comment = false; + cont = false; bp = NULL; + continue; } else { tail[1] = '@'; } @@ -161,3 +280,10 @@ getbuf(FILE * F, int encoding) } while (cont || cp==fbuf); return fbuf; } + +const char * +getbuf(FILE * F, int encoding) +{ + if (encoding==XML_CHAR_ENCODING_UTF8) return getbuf_utf8(F); + return getbuf_latin1(F); +} diff --git a/src/common/util/nrmessage.c b/src/common/util/nrmessage.c index 1a2543f43..a7f620955 100644 --- a/src/common/util/nrmessage.c +++ b/src/common/util/nrmessage.c @@ -54,7 +54,7 @@ nrt_find(const struct locale * lang, const struct message_type * mtype) } type = type->next; } - if (lang && found->lang!=lang) { + if (lang && found && found->lang!=lang) { log_warning(("could not find nr-type %s for locale %s, substituting with %s\n", mtype->name, locale_name(lang), locale_name(found->lang))); } diff --git a/src/common/util/umlaut.c b/src/common/util/umlaut.c index 70a4019b2..3ff200c0b 100644 --- a/src/common/util/umlaut.c +++ b/src/common/util/umlaut.c @@ -47,13 +47,13 @@ addtoken(tnode * root, const char * str, variant id) const char str[3]; } replace[] = { /* match lower-case (!) umlauts and others to transcriptions */ - { 228, "AE"}, - { 246, "OE"}, - { 252, "UE"}, - { 223, "SS"}, - { 230, "AE"}, - { 248, "OE"}, - { 229, "AA"}, + { 228, "AE"}, /* auml */ + { 246, "OE"}, /* ouml */ + { 252, "UE"}, /* uuml */ + { 223, "SS"}, /* szlig */ + { 230, "AE"}, /* norsk */ + { 248, "OE"}, /* norsk */ + { 229, "AA"}, /* norsk */ { 0, "" } }; diff --git a/src/config.h b/src/config.h index dcef564ff..a9ae3fe68 100644 --- a/src/config.h +++ b/src/config.h @@ -169,7 +169,7 @@ typedef struct _stat stat_type; # define strdup _strdup # define HAVE_STRDUP -# define sleep _sleep +# define sleep(sec) _sleep(sec*1000000) # define HAVE_SLEEP # define stricmp(a, b) _stricmp(a, b) diff --git a/src/eressea/gmtool.c b/src/eressea/gmtool.c index c0c4c97c2..c5b492724 100644 --- a/src/eressea/gmtool.c +++ b/src/eressea/gmtool.c @@ -62,6 +62,8 @@ #include +#include + #include #include @@ -1299,10 +1301,13 @@ load_inifile(const char * filename) { dictionary * d = iniparser_new(filename); if (d) { + const char * str; g_basedir = iniparser_getstring(d, "common:base", g_basedir); g_resourcedir = iniparser_getstring(d, "common:res", g_resourcedir); xmlfile = iniparser_getstring(d, "common:xml", xmlfile); - enc_gamedata = iniparser_getstring(d, "common:gamedata_encoding", enc_gamedata); + + str = iniparser_getstring(d, "common:gamedata_encoding", NULL); + if (str) enc_gamedata = xmlParseCharEncoding(str); } inifile = d; } diff --git a/src/eressea/lua/gamecode.cpp b/src/eressea/lua/gamecode.cpp index 591ea4293..3b7748ca5 100644 --- a/src/eressea/lua/gamecode.cpp +++ b/src/eressea/lua/gamecode.cpp @@ -46,6 +46,8 @@ #include #include +#include + #include #include @@ -108,7 +110,8 @@ message_region(unit& sender, const char * str) static int read_game(const char * filename, const char * encoding) { - int rv = readgame(filename, false, encoding); + int enc = xmlParseCharEncoding(encoding); + int rv = readgame(filename, false, enc); printf(" - Korrekturen Runde %d\n", turn); korrektur(); return rv; diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index fbc3f4974..5db3247a0 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -110,6 +110,8 @@ #include #include +#include + /* stdc++ includes */ #include #include @@ -386,18 +388,17 @@ game_done(void) #include "magic.h" +#define CRTDBG + #ifdef CRTDBG void init_crtdbg(void) { #if (defined(_MSC_VER)) -# if MALLOCDBG == 2 -# define CHECKON() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF) -# elif MALLOCDBG == 3 -# define CHECKON() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & 0) -# elif MALLOCDBG == 1 -# define CHECKON() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF) -# endif + int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + // flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_1024_DF; + // flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */ + _CrtSetDbgFlag(flags); #endif } #endif @@ -601,14 +602,17 @@ load_inifile(const char * filename) { dictionary * d = iniparser_new(filename); if (d) { + const char * str; g_basedir = iniparser_getstring(d, "common:base", g_basedir); g_resourcedir = iniparser_getstring(d, "common:res", g_resourcedir); xmlfile = iniparser_getstring(d, "common:xml", xmlfile); script_path = iniparser_getstring(d, "common:scripts", script_path); lomem = iniparser_getint(d, "common:lomem", lomem)?1:0; - enc_gamedata = iniparser_getstring(d, "common:gamedata_encoding", enc_gamedata); - enc_orderfile = iniparser_getstring(d, "common:orderfile_encoding", enc_orderfile); + str = iniparser_getstring(d, "common:gamedata_encoding", NULL); + if (str) enc_gamedata = xmlParseCharEncoding(str); + str = iniparser_getstring(d, "common:orderfile_encoding", NULL); + if (str) enc_orderfile = xmlParseCharEncoding(str); quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1; battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0; diff --git a/src/res/de/strings.xml b/src/res/de/strings.xml index a79a9db0d..d8ab23ca5 100644 --- a/src/res/de/strings.xml +++ b/src/res/de/strings.xml @@ -8,7 +8,8 @@ --> Wirbel - Vortex + vortex + remous Ein Wirbel aus reinem Chaos zieht über die Region diff --git a/src/res/en/strings.xml b/src/res/en/strings.xml index 638eab4cc..b65b6dfc6 100644 --- a/src/res/en/strings.xml +++ b/src/res/en/strings.xml @@ -173,6 +173,9 @@ the glacier of %s + + Wall + the %s diff --git a/src/scripts/eressea.lua b/src/scripts/eressea.lua index 5d3c1d13c..a9ab87224 100644 --- a/src/scripts/eressea.lua +++ b/src/scripts/eressea.lua @@ -1,6 +1,6 @@ -- the locales that this gameworld supports. local locales = { "de", "en" } -enc_orders = "UTF-8" +enc_orders = "ISO-8859-1" enc_game = "ISO-8859-1" function loadscript(name)