eressea-pbem.de no longer exists

improve default_order generation, save memory.
This commit is contained in:
Enno Rehling 2012-05-16 13:07:28 -07:00
parent 7b6a719a62
commit 9065334677
8 changed files with 32 additions and 31 deletions

View File

@ -137,7 +137,6 @@ static void game_init(void)
register_cr(); register_cr();
register_xr(); register_xr();
debug_language("locales.log");
register_names(); register_names();
register_resources(); register_resources();
register_buildings(); register_buildings();

View File

@ -3238,9 +3238,21 @@ void kernel_init(void)
} }
} }
static order * defaults[MAXLOCALES];
order *default_order(const struct locale *lang) order *default_order(const struct locale *lang)
{ {
return parse_order(locale_string(lang, "defaultorder"), lang); int i = locale_index(lang);
order *result = 0;
assert(i<MAXLOCALES);
result = defaults[i];
if (!result) {
const char * str = locale_string(lang, "defaultorder");
if (str) {
result = defaults[i] = parse_order(str, lang);
}
}
return result ? copy_order(result) : 0;
} }
int entertainmoney(const region * r) int entertainmoney(const region * r)
@ -3284,10 +3296,17 @@ int markets_module(void)
*/ */
void free_gamedata(void) void free_gamedata(void)
{ {
int i;
free_units(); free_units();
free_regions(); free_regions();
free_borders(); free_borders();
for (i=0;i!=MAXLOCALES;++i) {
if (defaults[i]) {
free_order(defaults[i]);
defaults[i] = 0;
}
}
while (alliances) { while (alliances) {
alliance *al = alliances; alliance *al = alliances;
alliances = al->next; alliances = al->next;

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea-pbem.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de> | (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>

View File

@ -34,10 +34,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
locale *default_locale; locale *default_locale;
locale *locales; locale *locales;
unsigned int locale_hashkey(const locale * lang) unsigned int locale_index(const locale * lang)
{ {
assert(lang); assert(lang);
return lang->hashkey; return lang->index;
} }
locale *find_locale(const char *name) locale *find_locale(const char *name)
@ -49,7 +49,7 @@ locale *find_locale(const char *name)
return l; return l;
} }
static int nextlocaleindex = 0; static unsigned int nextlocaleindex = 0;
locale *make_locale(const char *name) locale *make_locale(const char *name)
{ {
@ -95,14 +95,6 @@ void make_locales(const char *str)
} }
} }
static FILE *s_debug = NULL;
static char *s_logfile = NULL;
void debug_language(const char *log)
{
s_logfile = strdup(log);
}
const char *locale_getstring(const locale * lang, const char *key) const char *locale_getstring(const locale * lang, const char *key)
{ {
unsigned int hkey = hashstring(key); unsigned int hkey = hashstring(key);
@ -156,21 +148,12 @@ const char *locale_string(const locale * lang, const char *key)
find = find->nexthash; find = find->nexthash;
} }
if (!find) { if (!find) {
const char *s = key;
log_warning(("missing translation for \"%s\" in locale %s\n", key, log_warning(("missing translation for \"%s\" in locale %s\n", key,
lang->name)); lang->name));
if (lang != default_locale) { if (lang != default_locale) {
s = locale_string(default_locale, key); return locale_string(default_locale, key);
} }
if (s_logfile) { return 0;
s_debug = s_debug ? s_debug : fopen(s_logfile, "w");
if (s_debug) {
fprintf(s_debug, "%s;%s;%s\n", key, lang->name, s);
fflush(s_debug);
locale_setstring((struct locale *)lang, key, s);
}
}
return s;
} }
return find->str; return find->str;
} }

View File

@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
#define MAXLOCALES 3
struct locale; struct locale;
/** managing multiple locales: **/ /** managing multiple locales: **/
@ -34,13 +36,12 @@ extern "C" {
extern const char *locale_getstring(const struct locale *lang, extern const char *locale_getstring(const struct locale *lang,
const char *key); const char *key);
extern const char *locale_string(const struct locale *lang, const char *key); /* does fallback */ extern const char *locale_string(const struct locale *lang, const char *key); /* does fallback */
extern unsigned int locale_hashkey(const struct locale *lang); extern unsigned int locale_index(const struct locale *lang);
extern const char *locale_name(const struct locale *lang); extern const char *locale_name(const struct locale *lang);
extern const char *mkname(const char *namespc, const char *key); extern const char *mkname(const char *namespc, const char *key);
extern char *mkname_buf(const char *namespc, const char *key, char *buffer); extern char *mkname_buf(const char *namespc, const char *key, char *buffer);
extern void debug_language(const char *log);
extern void make_locales(const char *str); extern void make_locales(const char *str);
#define LOC(lang, s) (lang?locale_string(lang, s):s) #define LOC(lang, s) (lang?locale_string(lang, s):s)

View File

@ -5,7 +5,6 @@
* feel that you need to include it, it's a sure sign that you're trying to * feel that you need to include it, it's a sure sign that you're trying to
* do something BAD. */ * do something BAD. */
#define MAXLOCALES 3
#define SMAXHASH 2048 #define SMAXHASH 2048
typedef struct locale_str { typedef struct locale_str {
unsigned int hashkey; unsigned int hashkey;
@ -15,7 +14,7 @@ typedef struct locale_str {
} locale_str; } locale_str;
typedef struct locale { typedef struct locale {
int index; unsigned int index;
struct locale *next; struct locale *next;
unsigned int hashkey; unsigned int hashkey;
const char *name; const char *name;

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea-pbem.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2001 | Henning Peters <faroul@beyond.kn-bremen.de> | (c) 1998 - 2001 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea-pbem.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2001 | Henning Peters <faroul@beyond.kn-bremen.de> | (c) 1998 - 2001 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>