From 95fdf497384b481c46f1cd795293db70b527dbab Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 14 Jun 2012 06:56:56 +0000 Subject: [PATCH] formatting SVN revision: 72103 --- src/bin/e_intl.c | 792 ++++++++++++++++++++++++----------------------- 1 file changed, 400 insertions(+), 392 deletions(-) diff --git a/src/bin/e_intl.c b/src/bin/e_intl.c index d8eecfe03..e9985e1ed 100644 --- a/src/bin/e_intl.c +++ b/src/bin/e_intl.c @@ -17,37 +17,37 @@ static char *_e_intl_orig_ecore_imf_module = NULL; static const char *_e_intl_imc_personal_path = NULL; static const char *_e_intl_imc_system_path = NULL; -#define E_EXE_STOP(EXE) if (EXE) { ecore_exe_terminate(EXE); ecore_exe_free(EXE); EXE = NULL; } +#define E_EXE_STOP(EXE) if (EXE) { ecore_exe_terminate(EXE); ecore_exe_free(EXE); EXE = NULL; } #define E_EXE_IS_VALID(EXE) (!((!EXE) || (EXE[0] == 0))) /* All locale parts */ -#define E_INTL_LOC_ALL E_INTL_LOC_LANG | \ - E_INTL_LOC_REGION | \ - E_INTL_LOC_CODESET | \ - E_INTL_LOC_MODIFIER +#define E_INTL_LOC_ALL E_INTL_LOC_LANG | \ + E_INTL_LOC_REGION | \ + E_INTL_LOC_CODESET | \ + E_INTL_LOC_MODIFIER /* Locale parts which are significant when Validating */ -#define E_INTL_LOC_SIGNIFICANT E_INTL_LOC_LANG | \ - E_INTL_LOC_REGION | \ - E_INTL_LOC_CODESET +#define E_INTL_LOC_SIGNIFICANT E_INTL_LOC_LANG | \ + E_INTL_LOC_REGION | \ + E_INTL_LOC_CODESET /* Language Setting and Listing */ -static char *_e_intl_language_path_find(char *language); -static Eina_List *_e_intl_language_dir_scan(const char *dir); -static int _e_intl_language_list_find(Eina_List *language_list, char *language); +static char *_e_intl_language_path_find(char *language); +static Eina_List *_e_intl_language_dir_scan(const char *dir); +static int _e_intl_language_list_find(Eina_List *language_list, char *language); /* Locale Validation and Discovery */ -static Eina_Hash *_e_intl_locale_alias_hash_get(void); -static char *_e_intl_locale_alias_get(const char *language); -static Eina_List *_e_intl_locale_system_locales_get(void); -static Eina_List *_e_intl_locale_search_order_get(const char *locale); -static int _e_intl_locale_validate(const char *locale); -static void _e_intl_locale_hash_free(Eina_Hash *language_hash); -static Eina_Bool _e_intl_locale_hash_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata); +static Eina_Hash *_e_intl_locale_alias_hash_get(void); +static char *_e_intl_locale_alias_get(const char *language); +static Eina_List *_e_intl_locale_system_locales_get(void); +static Eina_List *_e_intl_locale_search_order_get(const char *locale); +static int _e_intl_locale_validate(const char *locale); +static void _e_intl_locale_hash_free(Eina_Hash *language_hash); +static Eina_Bool _e_intl_locale_hash_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata); /* Input Method Configuration and Management */ -static Eina_Bool _e_intl_cb_exit(void *data, int type, void *event); -static Eina_List *_e_intl_imc_dir_scan(const char *dir); +static Eina_Bool _e_intl_cb_exit(void *data, int type, void *event); +static Eina_List *_e_intl_imc_dir_scan(const char *dir); EINTERN int e_intl_init(void) @@ -101,8 +101,8 @@ e_intl_post_init(void) if ((e_config->input_method) && (e_config->input_method[0] != 0)) e_intl_input_method_set(e_config->input_method); - _e_intl_exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, - _e_intl_cb_exit, NULL); + _e_intl_exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, + _e_intl_cb_exit, NULL); return 1; } @@ -111,8 +111,8 @@ e_intl_post_shutdown(void) { if (_e_intl_exit_handler) { - ecore_event_handler_del(_e_intl_exit_handler); - _e_intl_exit_handler = NULL; + ecore_event_handler_del(_e_intl_exit_handler); + _e_intl_exit_handler = NULL; } e_intl_input_method_set(NULL); @@ -145,12 +145,12 @@ e_intl_language_set(const char *lang) */ if (!lang) { - e_util_env_set("LANG", _e_intl_orig_lang); + e_util_env_set("LANG", _e_intl_orig_lang); - if (!lang) lang = getenv("LC_ALL"); - if (!lang) lang = getenv("LANG"); + if (!lang) lang = getenv("LC_ALL"); + if (!lang) lang = getenv("LANG"); - set_envars = 0; + set_envars = 0; } E_FREE(_e_intl_language_alias); @@ -165,88 +165,88 @@ e_intl_language_set(const char *lang) ok = 1; if (strcmp(_e_intl_language_alias, "C")) { - ok = _e_intl_locale_validate(_e_intl_language_alias); - if (!ok) - { - char *p, *new_lang; - - new_lang = _e_intl_language_alias; - p = strchr(new_lang, '.'); - if (p) *p = 0; - _e_intl_language_alias = strdup(new_lang); - E_FREE(new_lang); - ok = _e_intl_locale_validate(_e_intl_language_alias); - } + ok = _e_intl_locale_validate(_e_intl_language_alias); + if (!ok) + { + char *p, *new_lang; + + new_lang = _e_intl_language_alias; + p = strchr(new_lang, '.'); + if (p) *p = 0; + _e_intl_language_alias = strdup(new_lang); + E_FREE(new_lang); + ok = _e_intl_locale_validate(_e_intl_language_alias); + } } if (!ok) { - fprintf(stderr, "The locale '%s' cannot be found on your " - "system. Please install this locale or try " - "something else.", _e_intl_language_alias); + fprintf(stderr, "The locale '%s' cannot be found on your " + "system. Please install this locale or try " + "something else.", _e_intl_language_alias); } else { - /* Only set env vars is a non NULL locale was passed */ - if (set_envars) - { + /* Only set env vars is a non NULL locale was passed */ + if (set_envars) + { e_util_env_set("LANG", lang); /* Unset LANGUAGE, apparently causes issues if set */ e_util_env_set("LANGUAGE", NULL); - } + } - setlocale(LC_ALL, lang); + setlocale(LC_ALL, lang); if (_e_intl_language) - { + { char *locale_path; locale_path = _e_intl_language_path_find(_e_intl_language_alias); if (!locale_path) - { - E_Locale_Parts *locale_parts; + { + E_Locale_Parts *locale_parts; - locale_parts = e_intl_locale_parts_get(_e_intl_language_alias); + locale_parts = e_intl_locale_parts_get(_e_intl_language_alias); - /* If locale is C or some form of en don't report an error */ - if ((!locale_parts) && - (strcmp(_e_intl_language_alias, "C"))) - { - fprintf(stderr, - "An error occurred setting your locale. \n\n" + /* If locale is C or some form of en don't report an error */ + if ((!locale_parts) && + (strcmp(_e_intl_language_alias, "C"))) + { + fprintf(stderr, + "An error occurred setting your locale. \n\n" - "The locale you have chosen '%s' appears to \n" - "be an alias, however, it can not be resloved.\n" - "Please make sure you have a 'locale.alias' \n" - "file in your 'messages' path which can resolve\n" - "this alias.\n\n" + "The locale you have chosen '%s' appears to \n" + "be an alias, however, it can not be resloved.\n" + "Please make sure you have a 'locale.alias' \n" + "file in your 'messages' path which can resolve\n" + "this alias.\n\n" - "Enlightenment will not be translated.\n", - _e_intl_language_alias); - } - else if ((locale_parts) && (locale_parts->lang) && - (strcmp(locale_parts->lang, "en"))) - { - fprintf(stderr, - "An error occurred setting your locale. \n\n" + "Enlightenment will not be translated.\n", + _e_intl_language_alias); + } + else if ((locale_parts) && (locale_parts->lang) && + (strcmp(locale_parts->lang, "en"))) + { + fprintf(stderr, + "An error occurred setting your locale. \n\n" - "The translation files for the locale you \n" - "have chosen (%s) cannot be found in your \n" - "'messages' path. \n\n" + "The translation files for the locale you \n" + "have chosen (%s) cannot be found in your \n" + "'messages' path. \n\n" - "Enlightenment will not be translated.\n", - _e_intl_language_alias); - } - e_intl_locale_parts_free(locale_parts); - } - else - { -#ifdef HAVE_GETTEXT - bindtextdomain(PACKAGE, locale_path); - textdomain(PACKAGE); - bind_textdomain_codeset(PACKAGE, "UTF-8"); -#endif - free(locale_path); + "Enlightenment will not be translated.\n", + _e_intl_language_alias); + } + e_intl_locale_parts_free(locale_parts); } - } + else + { +#ifdef HAVE_GETTEXT + bindtextdomain(PACKAGE, locale_path); + textdomain(PACKAGE); + bind_textdomain_codeset(PACKAGE, "UTF-8"); +#endif + free(locale_path); + } + } } } @@ -256,7 +256,7 @@ e_intl_language_get(void) return _e_intl_language; } -EAPI const char * +EAPI const char * e_intl_language_alias_get(void) { return _e_intl_language_alias; @@ -274,20 +274,20 @@ e_intl_language_list(void) dir_list = e_path_dir_list_get(path_messages); EINA_LIST_FOREACH(dir_list, next, epd) { - Eina_List *dir_languages; - char *language; + Eina_List *dir_languages; + char *language; - dir_languages = _e_intl_language_dir_scan(epd->dir); + dir_languages = _e_intl_language_dir_scan(epd->dir); - EINA_LIST_FREE(dir_languages, language) - if ((_e_intl_language_list_find(all_languages, language)) || - ((strlen(language) > 2) && (!_e_intl_locale_validate(language)))) - { - free(language); - } - else - all_languages = eina_list_append(all_languages, language); - } + EINA_LIST_FREE(dir_languages, language) + if ((_e_intl_language_list_find(all_languages, language)) || + ((strlen(language) > 2) && (!_e_intl_locale_validate(language)))) + { + free(language); + } + else + all_languages = eina_list_append(all_languages, language); + } e_path_dir_list_free(dir_list); @@ -313,52 +313,52 @@ e_intl_input_method_set(const char *imc_path) { if (!imc_path) { - E_EXE_STOP(_e_intl_input_method_exec); - e_util_env_set("GTK_IM_MODULE", _e_intl_orig_gtk_im_module); + E_EXE_STOP(_e_intl_input_method_exec); + e_util_env_set("GTK_IM_MODULE", _e_intl_orig_gtk_im_module); e_util_env_set("QT_IM_MODULE", _e_intl_orig_qt_im_module); e_util_env_set("XMODIFIERS", _e_intl_orig_xmodifiers); - e_util_env_set("ECORE_IMF_MODULE", _e_intl_orig_ecore_imf_module); + e_util_env_set("ECORE_IMF_MODULE", _e_intl_orig_ecore_imf_module); } if (imc_path) { - Eet_File *imc_ef; - E_Input_Method_Config *imc; + Eet_File *imc_ef; + E_Input_Method_Config *imc; - imc_ef = eet_open(imc_path, EET_FILE_MODE_READ); - if (imc_ef) - { - imc = e_intl_input_method_config_read(imc_ef); - eet_close(imc_ef); + imc_ef = eet_open(imc_path, EET_FILE_MODE_READ); + if (imc_ef) + { + imc = e_intl_input_method_config_read(imc_ef); + eet_close(imc_ef); - if (imc) - { - e_util_env_set("GTK_IM_MODULE", imc->gtk_im_module); - e_util_env_set("QT_IM_MODULE", imc->qt_im_module); - e_util_env_set("XMODIFIERS", imc->xmodifiers); - e_util_env_set("ECORE_IMF_MODULE", imc->ecore_imf_module); + if (imc) + { + e_util_env_set("GTK_IM_MODULE", imc->gtk_im_module); + e_util_env_set("QT_IM_MODULE", imc->qt_im_module); + e_util_env_set("XMODIFIERS", imc->xmodifiers); + e_util_env_set("ECORE_IMF_MODULE", imc->ecore_imf_module); - E_EXE_STOP(_e_intl_input_method_exec); + E_EXE_STOP(_e_intl_input_method_exec); - if (E_EXE_IS_VALID(imc->e_im_exec)) - { - e_util_library_path_strip(); - _e_intl_input_method_exec = ecore_exe_run(imc->e_im_exec, NULL); - e_util_library_path_restore(); - ecore_exe_tag_set(_e_intl_input_method_exec,"E/im_exec"); + if (E_EXE_IS_VALID(imc->e_im_exec)) + { + e_util_library_path_strip(); + _e_intl_input_method_exec = ecore_exe_run(imc->e_im_exec, NULL); + e_util_library_path_restore(); + ecore_exe_tag_set(_e_intl_input_method_exec, "E/im_exec"); - if ((!_e_intl_input_method_exec) || - (!ecore_exe_pid_get(_e_intl_input_method_exec))) - e_util_dialog_show(_("Input Method Error"), - _( "Error starting the input method executable

" - "please make sure that your input
" - "method configuration is correct and
" - "that your configuration's
" - "executable is in your PATH
")); - } - e_intl_input_method_config_free(imc); - } - } + if ((!_e_intl_input_method_exec) || + (!ecore_exe_pid_get(_e_intl_input_method_exec))) + e_util_dialog_show(_("Input Method Error"), + _("Error starting the input method executable

" + "please make sure that your input
" + "method configuration is correct and
" + "that your configuration's
" + "executable is in your PATH
")); + } + e_intl_input_method_config_free(imc); + } + } } } @@ -385,10 +385,10 @@ e_intl_imc_personal_path_get(void) { if (!_e_intl_imc_personal_path) { - char buf[4096]; + char buf[4096]; - e_user_dir_concat_static(buf, "input_methods"); - _e_intl_imc_personal_path = eina_stringshare_add(buf); + e_user_dir_concat_static(buf, "input_methods"); + _e_intl_imc_personal_path = eina_stringshare_add(buf); } return _e_intl_imc_personal_path; } @@ -398,10 +398,10 @@ e_intl_imc_system_path_get(void) { if (!_e_intl_imc_system_path) { - char buf[4096]; + char buf[4096]; - e_prefix_data_concat_static(buf, "data/input_methods"); - _e_intl_imc_system_path = eina_stringshare_add(buf); + e_prefix_data_concat_static(buf, "data/input_methods"); + _e_intl_imc_system_path = eina_stringshare_add(buf); } return _e_intl_imc_system_path; } @@ -415,7 +415,7 @@ _e_intl_cb_exit(void *data __UNUSED__, int type __UNUSED__, void *event) if (!ev->exe) return ECORE_CALLBACK_PASS_ON; if (!(ecore_exe_tag_get(ev->exe) && - (!strcmp(ecore_exe_tag_get(ev->exe), "E/im_exec")))) return 1; + (!strcmp(ecore_exe_tag_get(ev->exe), "E/im_exec")))) return 1; _e_intl_input_method_exec = NULL; return ECORE_CALLBACK_PASS_ON; @@ -436,7 +436,6 @@ _e_intl_locale_hash_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __ return 1; } - /* * get the directory associated with the language. Language Must be valid alias * i.e. Already validated and already de-aliased. @@ -450,15 +449,15 @@ _e_intl_locale_hash_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __ static char * _e_intl_language_path_find(char *language) { - char *directory; - char *data; - Eina_List *dir_list; - Eina_List *search_list; - Eina_List *next_dir; - Eina_List *next_search; - E_Path_Dir *epd; - char *search_locale; - int found; + char *directory; + char *data; + Eina_List *dir_list; + Eina_List *search_list; + Eina_List *next_dir; + Eina_List *next_search; + E_Path_Dir *epd; + char *search_locale; + int found; search_list = _e_intl_locale_search_order_get(language); @@ -471,21 +470,21 @@ _e_intl_language_path_find(char *language) /* For each directory in the path */ EINA_LIST_FOREACH(dir_list, next_dir, epd) { - if (found) break; + if (found) break; - /* Match canonicalized locale against each possible search */ - EINA_LIST_FOREACH(search_list, next_search, search_locale) - { - char message_path[PATH_MAX]; + /* Match canonicalized locale against each possible search */ + EINA_LIST_FOREACH(search_list, next_search, search_locale) + { + char message_path[PATH_MAX]; - snprintf(message_path, sizeof(message_path), "%s/%s/LC_MESSAGES/%s.mo", epd->dir, search_locale, PACKAGE); + snprintf(message_path, sizeof(message_path), "%s/%s/LC_MESSAGES/%s.mo", epd->dir, search_locale, PACKAGE); - if ((ecore_file_exists(message_path)) && (!ecore_file_is_dir(message_path))) - { - directory = strdup(epd->dir); - found = 1; - } - } + if ((ecore_file_exists(message_path)) && (!ecore_file_is_dir(message_path))) + { + directory = strdup(epd->dir); + found = 1; + } + } } e_path_dir_list_free(dir_list); @@ -510,17 +509,17 @@ _e_intl_language_dir_scan(const char *dir) if (files) { - EINA_LIST_FREE(files, file) - { - char file_path[PATH_MAX]; + EINA_LIST_FREE(files, file) + { + char file_path[PATH_MAX]; - snprintf(file_path, sizeof(file_path),"%s/%s/LC_MESSAGES/%s.mo", - dir, file, PACKAGE); - if (ecore_file_exists(file_path) && !ecore_file_is_dir(file_path)) - languages = eina_list_append(languages, file); - else - free(file); - } + snprintf(file_path, sizeof(file_path), "%s/%s/LC_MESSAGES/%s.mo", + dir, file, PACKAGE); + if (ecore_file_exists(file_path) && !ecore_file_is_dir(file_path)) + languages = eina_list_append(languages, file); + else + free(file); + } } return languages; } @@ -577,31 +576,31 @@ _e_intl_locale_alias_hash_get(void) EINA_LIST_FOREACH(dir_list, next, epd) { - char buf[4096]; - FILE *f; + char buf[4096]; + FILE *f; - snprintf(buf, sizeof(buf), "%s/locale.alias", epd->dir); - f = fopen(buf, "r"); - if (f) - { - char alias[4096], locale[4096]; + snprintf(buf, sizeof(buf), "%s/locale.alias", epd->dir); + f = fopen(buf, "r"); + if (f) + { + char alias[4096], locale[4096]; - /* read locale alias lines */ - while (fscanf(f, "%4090s %[^\n]\n", alias, locale) == 2) - { - /* skip comments */ - if ((alias[0] == '!') || (alias[0] == '#')) - continue; + /* read locale alias lines */ + while (fscanf(f, "%4090s %[^\n]\n", alias, locale) == 2) + { + /* skip comments */ + if ((alias[0] == '!') || (alias[0] == '#')) + continue; - /* skip dupes */ - if (eina_hash_find(alias_hash, alias)) - continue; + /* skip dupes */ + if (eina_hash_find(alias_hash, alias)) + continue; - if (!alias_hash) alias_hash = eina_hash_string_superfast_new(NULL); - eina_hash_add(alias_hash, alias, strdup(locale)); - } - fclose (f); - } + if (!alias_hash) alias_hash = eina_hash_string_superfast_new(NULL); + eina_hash_add(alias_hash, alias, strdup(locale)); + } + fclose(f); + } } e_path_dir_list_free(dir_list); @@ -622,81 +621,85 @@ e_intl_locale_parts_get(const char *locale) { /* Parse Results */ E_Locale_Parts *locale_parts; - char language[4]; - char territory[4]; - char codeset[32]; - char modifier[32]; + char language[4]; + char territory[4]; + char codeset[32]; + char modifier[32]; /* Parse State */ - int state = 0; /* start out looking for the language */ + int state = 0; /* start out looking for the language */ unsigned int locale_idx; - int tmp_idx = 0; + int tmp_idx = 0; /* Parse Loop - Seperators are _ . @ */ for (locale_idx = 0; locale_idx < strlen(locale); locale_idx++) { - char locale_char; - locale_char = locale[locale_idx]; + char locale_char; + locale_char = locale[locale_idx]; - /* we have finished scanning the locale string */ - if (!locale_char) - break; + /* we have finished scanning the locale string */ + if (!locale_char) + break; - /* scan this character based on the current start */ - switch (state) - { - case 0: /* Gathering Language */ - if (tmp_idx == 2 && locale_char == '_') - { - state++; - language[tmp_idx] = 0; - tmp_idx = 0; - } - else if ((tmp_idx < 2) && (islower(locale_char))) - language[tmp_idx++] = locale_char; - else - return NULL; - break; - case 1: /* Gathering Territory */ - if (tmp_idx == 2 && locale_char == '.') - { - state++; - territory[tmp_idx] = 0; - tmp_idx = 0; - } - else if ((tmp_idx == 2) && (locale_char == '@')) - { - state += 2; - territory[tmp_idx] = 0; - codeset[0] = 0; - tmp_idx = 0; - } - else if ((tmp_idx < 2) && isupper(locale_char)) - territory[tmp_idx++] = locale_char; - else - return NULL; - break; - case 2: /* Gathering Codeset */ - if (locale_char == '@') - { - state++; - codeset[tmp_idx] = 0; - tmp_idx = 0; - } - else if (tmp_idx < 32) - codeset[tmp_idx++] = locale_char; - else - return NULL; - break; - case 3: /* Gathering modifier */ - if (tmp_idx < 32) - modifier[tmp_idx++] = locale_char; - else - return NULL; - break; - default: - break; - } + /* scan this character based on the current start */ + switch (state) + { + case 0: /* Gathering Language */ + if (tmp_idx == 2 && locale_char == '_') + { + state++; + language[tmp_idx] = 0; + tmp_idx = 0; + } + else if ((tmp_idx < 2) && (islower(locale_char))) + language[tmp_idx++] = locale_char; + else + return NULL; + break; + + case 1: /* Gathering Territory */ + if (tmp_idx == 2 && locale_char == '.') + { + state++; + territory[tmp_idx] = 0; + tmp_idx = 0; + } + else if ((tmp_idx == 2) && (locale_char == '@')) + { + state += 2; + territory[tmp_idx] = 0; + codeset[0] = 0; + tmp_idx = 0; + } + else if ((tmp_idx < 2) && isupper(locale_char)) + territory[tmp_idx++] = locale_char; + else + return NULL; + break; + + case 2: /* Gathering Codeset */ + if (locale_char == '@') + { + state++; + codeset[tmp_idx] = 0; + tmp_idx = 0; + } + else if (tmp_idx < 32) + codeset[tmp_idx++] = locale_char; + else + return NULL; + break; + + case 3: /* Gathering modifier */ + if (tmp_idx < 32) + modifier[tmp_idx++] = locale_char; + else + return NULL; + break; + + default: + break; + } } /* set end-of-string \0 */ @@ -704,18 +707,22 @@ e_intl_locale_parts_get(const char *locale) switch (state) { case 0: - language[tmp_idx] = 0; - tmp_idx = 0; + language[tmp_idx] = 0; + tmp_idx = 0; + case 1: - territory[tmp_idx] = 0; - tmp_idx = 0; + territory[tmp_idx] = 0; + tmp_idx = 0; + case 2: - codeset[tmp_idx] = 0; - tmp_idx = 0; + codeset[tmp_idx] = 0; + tmp_idx = 0; + case 3: - modifier[tmp_idx] = 0; + modifier[tmp_idx] = 0; + default: - break; + break; } locale_parts = E_NEW(E_Locale_Parts, 1); @@ -723,23 +730,23 @@ e_intl_locale_parts_get(const char *locale) /* Put the parts of the string together */ if (language[0] != 0) { - locale_parts->mask |= E_INTL_LOC_LANG; - locale_parts->lang = eina_stringshare_add(language); + locale_parts->mask |= E_INTL_LOC_LANG; + locale_parts->lang = eina_stringshare_add(language); } if (territory[0] != 0) { - locale_parts->mask |= E_INTL_LOC_REGION; - locale_parts->region = eina_stringshare_add(territory); + locale_parts->mask |= E_INTL_LOC_REGION; + locale_parts->region = eina_stringshare_add(territory); } if (codeset[0] != 0) { - locale_parts->mask |= E_INTL_LOC_CODESET; - locale_parts->codeset = eina_stringshare_add(codeset); + locale_parts->mask |= E_INTL_LOC_CODESET; + locale_parts->codeset = eina_stringshare_add(codeset); } if (modifier[0] != 0) { - locale_parts->mask |= E_INTL_LOC_MODIFIER; - locale_parts->modifier = eina_stringshare_add(modifier); + locale_parts->mask |= E_INTL_LOC_MODIFIER; + locale_parts->modifier = eina_stringshare_add(modifier); } return locale_parts; @@ -750,11 +757,11 @@ e_intl_locale_parts_free(E_Locale_Parts *locale_parts) { if (locale_parts) { - if (locale_parts->lang) eina_stringshare_del(locale_parts->lang); - if (locale_parts->region) eina_stringshare_del(locale_parts->region); - if (locale_parts->codeset) eina_stringshare_del(locale_parts->codeset); - if (locale_parts->modifier) eina_stringshare_del(locale_parts->modifier); - E_FREE(locale_parts); + if (locale_parts->lang) eina_stringshare_del(locale_parts->lang); + if (locale_parts->region) eina_stringshare_del(locale_parts->region); + if (locale_parts->codeset) eina_stringshare_del(locale_parts->codeset); + if (locale_parts->modifier) eina_stringshare_del(locale_parts->modifier); + E_FREE(locale_parts); } } @@ -773,7 +780,7 @@ e_intl_locale_parts_combine(E_Locale_Parts *locale_parts, int mask) /* determine the size */ if (mask & E_INTL_LOC_LANG) - locale_size = strlen(locale_parts->lang) + 1; + locale_size = strlen(locale_parts->lang) + 1; if (mask & E_INTL_LOC_REGION) locale_size += strlen(locale_parts->region) + 1; @@ -787,7 +794,7 @@ e_intl_locale_parts_combine(E_Locale_Parts *locale_parts, int mask) if (!locale_size) return NULL; /* Allocate memory */ - locale = (char *) malloc(locale_size); + locale = (char *)malloc(locale_size); locale[0] = 0; if (mask & E_INTL_LOC_LANG) @@ -795,20 +802,20 @@ e_intl_locale_parts_combine(E_Locale_Parts *locale_parts, int mask) if (mask & E_INTL_LOC_REGION) { - if (locale[0] != 0) strcat(locale, "_"); - strcat(locale, locale_parts->region); - } + if (locale[0] != 0) strcat(locale, "_"); + strcat(locale, locale_parts->region); + } if (mask & E_INTL_LOC_CODESET) - { - if (locale[0] != 0) strcat(locale, "."); - strcat(locale, locale_parts->codeset); - } + { + if (locale[0] != 0) strcat(locale, "."); + strcat(locale, locale_parts->codeset); + } if (mask & E_INTL_LOC_MODIFIER) { - if (locale[0] != 0) strcat(locale, "@"); - strcat(locale, locale_parts->modifier); + if (locale[0] != 0) strcat(locale, "@"); + strcat(locale, locale_parts->modifier); } return locale; @@ -825,8 +832,8 @@ e_intl_locale_charset_canonic_get(const char *charset) i_tmp = 0; while ((c = charset[i++]) != 0) { - if (isalnum(c)) - charset_canonic[i_tmp++] = tolower(c); + if (isalnum(c)) + charset_canonic[i_tmp++] = tolower(c); } charset_canonic[i_tmp] = 0; @@ -839,18 +846,18 @@ e_intl_locale_charset_canonic_get(const char *charset) static Eina_List * _e_intl_locale_system_locales_get(void) { - Eina_List *locales; - FILE *output; + Eina_List *locales; + FILE *output; locales = NULL; output = popen("locale -a", "r"); if (output) { - char line[32]; - while (fscanf(output, "%[^\n]\n", line) == 1) - locales = eina_list_append(locales, strdup(line)); + char line[32]; + while (fscanf(output, "%[^\n]\n", line) == 1) + locales = eina_list_append(locales, strdup(line)); - pclose(output); + pclose(output); } return locales; } @@ -866,28 +873,28 @@ _e_intl_locale_validate(const char *locale) char *locale_next; char *locale_lr; char *locale_cs_canonic; - int found; + int found; found = 0; locale_parts = e_intl_locale_parts_get(locale); /* Gather the search information */ - locale_lr = - e_intl_locale_parts_combine(locale_parts, - E_INTL_LOC_LANG | E_INTL_LOC_REGION); + locale_lr = + e_intl_locale_parts_combine(locale_parts, + E_INTL_LOC_LANG | E_INTL_LOC_REGION); if (!locale_lr) { - /* Not valid locale, maybe its an alias */ - locale_lr = strdup(locale); - locale_cs_canonic = NULL; + /* Not valid locale, maybe its an alias */ + locale_lr = strdup(locale); + locale_cs_canonic = NULL; } else { - if (locale_parts && locale_parts->codeset) - locale_cs_canonic = e_intl_locale_charset_canonic_get(locale_parts->codeset); - else - locale_cs_canonic = NULL; + if (locale_parts && locale_parts->codeset) + locale_cs_canonic = e_intl_locale_charset_canonic_get(locale_parts->codeset); + else + locale_cs_canonic = NULL; } /* Get list of all available locales and aliases */ @@ -896,76 +903,76 @@ _e_intl_locale_validate(const char *locale) /* Match locale with one from the list */ EINA_LIST_FREE(all_locales, locale_next) { - if (found == 0) - { - E_Locale_Parts *locale_parts_next; - char * locale_lr_next; + if (found == 0) + { + E_Locale_Parts *locale_parts_next; + char *locale_lr_next; - locale_parts_next = e_intl_locale_parts_get(locale_next); - locale_lr_next = e_intl_locale_parts_combine(locale_parts_next, - E_INTL_LOC_LANG | E_INTL_LOC_REGION); + locale_parts_next = e_intl_locale_parts_get(locale_next); + locale_lr_next = e_intl_locale_parts_combine(locale_parts_next, + E_INTL_LOC_LANG | E_INTL_LOC_REGION); - if ((locale_parts) && (locale_lr_next) && - (!strcmp(locale_lr, locale_lr_next))) - { - /* Matched lang/region part, now if CS matches */ - if ((!locale_parts->codeset) && (!locale_parts_next->codeset)) - { - /* Lang/Region parts match and no charsets, - * we have a match - */ - found = 1; - } - else if (locale_parts->codeset && locale_parts_next->codeset) - { - if (!strcmp(locale_parts->codeset, locale_parts_next->codeset)) - { - /* Lang/Region and charsets match */ - found = 1; - } - else if (locale_cs_canonic) - { - char *locale_cs_canonic_next; - /* try to match charsets in canonic form */ + if ((locale_parts) && (locale_lr_next) && + (!strcmp(locale_lr, locale_lr_next))) + { + /* Matched lang/region part, now if CS matches */ + if ((!locale_parts->codeset) && (!locale_parts_next->codeset)) + { + /* Lang/Region parts match and no charsets, + * we have a match + */ + found = 1; + } + else if (locale_parts->codeset && locale_parts_next->codeset) + { + if (!strcmp(locale_parts->codeset, locale_parts_next->codeset)) + { + /* Lang/Region and charsets match */ + found = 1; + } + else if (locale_cs_canonic) + { + char *locale_cs_canonic_next; + /* try to match charsets in canonic form */ - locale_cs_canonic_next = - e_intl_locale_charset_canonic_get(locale_parts_next->codeset); + locale_cs_canonic_next = + e_intl_locale_charset_canonic_get(locale_parts_next->codeset); - if (locale_cs_canonic_next) - { - if (!strcmp(locale_cs_canonic, locale_cs_canonic_next)) - { - /* Lang/Resion and charsets in canonic - * form match - */ - found = 1; - } - free(locale_cs_canonic_next); - } - else - { - if (!strcmp(locale_cs_canonic, locale_parts_next->codeset)) - { - /* Lang/Resion and charsets in canonic - * form match - */ - found = 1; - } - } - } - } - } - else - { - /* Its an alias */ - if (!strcmp(locale_lr, locale_next)) found = 1; - } - e_intl_locale_parts_free(locale_parts_next); - E_FREE(locale_lr_next); - } - free (locale_next); + if (locale_cs_canonic_next) + { + if (!strcmp(locale_cs_canonic, locale_cs_canonic_next)) + { + /* Lang/Resion and charsets in canonic + * form match + */ + found = 1; + } + free(locale_cs_canonic_next); + } + else + { + if (!strcmp(locale_cs_canonic, locale_parts_next->codeset)) + { + /* Lang/Resion and charsets in canonic + * form match + */ + found = 1; + } + } + } + } + } + else + { + /* Its an alias */ + if (!strcmp(locale_lr, locale_next)) found = 1; + } + e_intl_locale_parts_free(locale_parts_next); + E_FREE(locale_lr_next); + } + free(locale_next); } - + e_intl_locale_parts_free(locale_parts); free(locale_lr); E_FREE(locale_cs_canonic); @@ -995,12 +1002,12 @@ _e_intl_locale_search_order_get(const char *locale) search_list = NULL; for (mask = E_INTL_LOC_ALL; mask >= E_INTL_LOC_LANG; mask--) { - if ((mask & locale_parts->mask) == mask) - { - /* Only append if the mask we need is available */ - masked_locale = e_intl_locale_parts_combine(locale_parts, mask); - search_list = eina_list_append(search_list, masked_locale); - } + if ((mask & locale_parts->mask) == mask) + { + /* Only append if the mask we need is available */ + masked_locale = e_intl_locale_parts_combine(locale_parts, mask); + search_list = eina_list_append(search_list, masked_locale); + } } e_intl_locale_parts_free(locale_parts); return search_list; @@ -1017,14 +1024,15 @@ _e_intl_imc_dir_scan(const char *dir) EINA_LIST_FREE(files, file) { - if (strstr(file, ".imc")) - { - char buf[PATH_MAX]; - - snprintf(buf, sizeof(buf), "%s/%s", dir, file); - imcs = eina_list_append(imcs, strdup(buf)); - } - free(file); + if (strstr(file, ".imc")) + { + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s/%s", dir, file); + imcs = eina_list_append(imcs, strdup(buf)); + } + free(file); } return imcs; } +