From f296909c75b3e2c71ce237bd8244151c0352cb43 Mon Sep 17 00:00:00 2001 From: Albert Cahalan Date: Sat, 21 Nov 2009 11:30:19 +0000 Subject: [PATCH] have to reset y_nudge if wiping out lang/locale --- src/compiler.h | 6 ++++++ src/fonts.c | 3 ++- src/fonts.h | 1 + src/i18n.c | 44 +++++++++++++++++++++++--------------------- src/i18n.h | 4 ++-- src/tuxpaint.c | 4 +--- 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/compiler.h b/src/compiler.h index e534c5448..b6878f7cf 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -118,6 +118,12 @@ #define expected(x,y) (x) #endif +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +#define MUST_CHECK __attribute__((warn_unused_result)) +#else +#define MUST_CHECK +#endif + #ifdef __powerpc__ // Ticks at 1/4 the memory bus clock (24.907667 MHz on Albert's Mac Cube) diff --git a/src/fonts.c b/src/fonts.c index dba66434b..45158015e 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -143,6 +143,7 @@ int num_font_styles_max = 0; int text_state = 0; unsigned text_size = 4; // initial text size +int button_label_y_nudge; static void loadfonts_locale_filter(SDL_Surface * screen, const char *const dir, const char *restrict locale); @@ -259,7 +260,7 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size) str, SDL_GetError() ); - smash_i18n(); + button_label_y_nudge = smash_i18n(); } } diff --git a/src/fonts.h b/src/fonts.h index 198c11b4e..9a0e6e94e 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -177,6 +177,7 @@ extern style_info **user_font_styles; extern int num_font_styles; extern int num_font_styles_max; +extern int button_label_y_nudge; int compar_fontgroup(const void *v1, const void *v2); int compar_fontkiller(const void *v1, const void *v2); diff --git a/src/i18n.c b/src/i18n.c index f7bfdb944..3cf4d880f 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -346,15 +346,15 @@ static void ctype_utf8(void) #endif } + /* Determine the current language/locale, and set the language string: */ +static int set_current_language(void) MUST_CHECK; static int set_current_language(void) { char *loc, *baseloc; int i, found; - int y_nudge; - - y_nudge = 0; + int y_nudge = 0; bindtextdomain("tuxpaint", LOCALEDIR); /* Old version of glibc does not have bind_textdomain_codeset() */ @@ -368,18 +368,13 @@ static int set_current_language(void) langint = LANG_EN; -#ifndef WIN32 +#ifndef _WIN32 loc = setlocale(LC_MESSAGES, NULL); // NULL: Used to direct setlocale() to query the current internationalised environment and return the name of the locale(). // FIXME: I'm getting back en_US.UTF-8 even after LC_ALL has been putenv()'d...?? -bjk 2008.02.19 - if (loc != NULL) - { - if (strstr(loc, "LC_MESSAGES") != NULL) - { - loc = getenv("LANG"); - } - } + if (loc && strstr(loc, "LC_MESSAGES")) + loc = getenv("LANG"); #else bind_textdomain_codeset("tuxpaint", "UTF-8"); loc = getenv("LANGUAGE"); @@ -400,10 +395,10 @@ static int set_current_language(void) //debug(loc); - if (loc != NULL) + if (loc) { baseloc = strdup(loc); - if (strchr(baseloc, '.') != NULL) + if (strchr(baseloc, '.')) strcpy(strchr(baseloc, '.'), "\0"); @@ -464,7 +459,7 @@ static int set_current_language(void) fflush(stderr); #endif - return(y_nudge); + return y_nudge; } @@ -665,9 +660,10 @@ static void show_locale_usage(FILE * f, const char *const prg) "\n", prg); } -static void setup_language(const char *const prg, int * y_nudge) +static int setup_language(const char *const prg) MUST_CHECK; +static int setup_language(const char *const prg) { - if (langstr != NULL) + if (langstr) { int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0]; @@ -720,13 +716,18 @@ static void setup_language(const char *const prg, int * y_nudge) langstr = NULL; } - *y_nudge = set_current_language(); + return set_current_language(); } // handle --locale arg static void do_locale_option(const char *const arg) { + if(!strcmp(arg,"help")) + { + show_locale_usage(stdout,"tuxpaint"); + exit(0); + } int len = strlen(arg) + 6; char *str = malloc(len); snprintf(str, len, "LANG=%s", arg); @@ -738,22 +739,23 @@ static void do_locale_option(const char *const arg) ctype_utf8(); } -void setup_i18n(const char *restrict lang, const char *restrict locale, int *button_label_y_nudge) +int setup_i18n(const char *restrict lang, const char *restrict locale) { printf("lang \"%s\", locale \"%s\"\n", lang, locale); if(lang) set_langstr(lang); if(locale) do_locale_option(locale); - setup_language("tuxpaint", button_label_y_nudge); + int y_nudge = setup_language("tuxpaint"); printf("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]); + return y_nudge; } -void smash_i18n(void) +int smash_i18n(void) { putenv((char *) "LANG=C"); putenv((char *) "OUTPUT_CHARSET=C"); setlocale(LC_ALL, "C"); ctype_utf8(); - set_current_language(); + return set_current_language(); } diff --git a/src/i18n.h b/src/i18n.h index 400fdba9d..499bf9ff5 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -147,7 +147,7 @@ extern const char *lang_prefix, *short_lang_prefix; /* Function prototypes: */ int get_current_language(void); -void setup_i18n(const char *restrict lang, const char *restrict locale, int *button_label_y_nudge); -void smash_i18n(void); +int setup_i18n(const char *restrict lang, const char *restrict locale) MUST_CHECK; +int smash_i18n(void) MUST_CHECK; #endif diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 9da3ff5a7..ef06d670c 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -1167,8 +1167,6 @@ static SDL_Surface *img_title_on, *img_title_off, static SDL_Surface *img_title_names[NUM_TITLES]; static SDL_Surface *img_tools[NUM_TOOLS], *img_tool_names[NUM_TOOLS]; -static int button_label_y_nudge; - static SDL_Surface *thumbnail(SDL_Surface * src, int max_x, int max_y, int keep_aspect); static SDL_Surface *thumbnail2(SDL_Surface * src, int max_x, int max_y, @@ -19077,7 +19075,7 @@ static void setup_config(char *argv[]) datadir = tmpcfg.datadir ? tmpcfg.datadir : savedir; - setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale, &button_label_y_nudge); + button_label_y_nudge = setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale); #if 0