Enlightenment CVS committal Author : stffrdhrn Project : e17 Module : apps/e
Dir : e17/apps/e/src/bin Modified Files: e_intl.c e_path.c Log Message: - Clean up the best match function and make it work - In e_path the user list should be before the default list - Add a function to list all available locales wrapping "locale -a" =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_intl.c,v retrieving revision 1.55 retrieving revision 1.56 diff -u -3 -r1.55 -r1.56 --- e_intl.c 25 Nov 2005 04:10:54 -0000 1.55 +++ e_intl.c 26 Nov 2005 11:44:02 -0000 1.56 @@ -33,6 +33,7 @@ static void _e_intl_language_hash_free(Evas_Hash *language_hash); static char *_e_intl_language_hash_find(Evas_Hash *language_hash, char *language); static int _e_intl_language_list_find(Evas_List *language_list, char *language); +static Evas_List *_e_intl_language_system_locales_get(void); Evas_Bool _e_intl_cb_free_language_hash(Evas_Hash *hash, const char *key, void *data, void *fdata); static Evas_List *_e_intl_language_dir_scan(const char *dir); static int _e_intl_cb_exit(void *data, int type, void *event); @@ -483,53 +484,57 @@ static char * _e_intl_language_hash_find(Evas_Hash *language_hash, char *language) { - Evas_List *l; - Evas_List *all_languages; - char *best_language; - char *directory; - int state; + Evas_List *l; + Evas_List *all_languages; + char *best_language; + int best_chars; + char *directory; if (!language_hash) return NULL; if (!language) return NULL; best_language = NULL; + best_chars = 0; all_languages = e_intl_language_list(); /* Do a best match: * If language is ja_JP.UTF-8 we should match ja - * If language is zh we should match the first in the list, of zh_CN and zh_TW + * If language is zh we should match the first in the list of zh_CN and zh_TW */ for ( l = all_languages ; l ; l = l->next ) { - char *lang; - int comp_len; - int lang_len; - int language_len; - - lang = l->data; - lang_len = strlen(lang); - language_len = strlen(language); - /* return shorter */ - comp_len = lang_len > language_len ? language_len : lang_len; + char *list_lang; + int cmp_ret; - if ( !strncmp(lang, language, comp_len) ) + list_lang = l->data; + cmp_ret = strncmp(list_lang, language, 2); + if ( cmp_ret == 0 ) { - if ( best_language == NULL ) + int list_lang_len; + int language_len; + int compare_len; + + if (best_language == NULL) { - best_language = lang; - if ( lang_len > language_len ) - state = 1; /* looking for shorter */ - else - state = 0; /* looking for longer */ + best_language = list_lang; + best_chars = 2; + continue; } - else if ( (state == 1 && lang_len > language_len) || - (state == 0 && lang_len < language_len) ) - best_language = lang; - if ( strlen(best_language) == language_len ) break; + list_lang_len = strlen(list_lang); + language_len = strlen(language); + compare_len = list_lang_len < language_len ? list_lang_len : + language_len; + if ( (compare_len > best_chars ) && + !strncmp(list_lang, language, compare_len) + ) + { + best_language = list_lang; + best_chars = compare_len; + } } } - + directory = evas_hash_find(language_hash, best_language); while (all_languages) @@ -620,6 +625,27 @@ } static Evas_List * +_e_intl_language_system_locales_get(void) +{ + Evas_List *locales; + FILE *output; + + locales = NULL; + output = popen("locale -a", "r"); + if ( output ) + { + char line[32]; + while ( fscanf(output, "%[^\n]\n", line) == 1) + { + locales = evas_list_append(locales, strdup(line)); + } + + pclose(output); + } + return locales; +} + +static Evas_List * _e_intl_imc_path_scan(E_Path *path) { =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_path.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -3 -r1.14 -r1.15 --- e_path.c 11 Jun 2005 13:32:29 -0000 1.14 +++ e_path.c 26 Nov 2005 11:44:02 -0000 1.15 @@ -334,7 +334,7 @@ if (dir_list) evas_list_free(dir_list); } -/* compine default_list and and user_list int and easy to use list */ +/* combine default_list and and user_list in and easy to use list */ Evas_List * e_path_dir_list_get(E_Path *ep) { @@ -345,14 +345,6 @@ dir_list = NULL; - for (l = ep->default_dir_list; l; l = l->next) - { - epd = l->data; - new_epd = malloc(sizeof(E_Path_Dir)); - new_epd->dir = strdup(epd->dir); - dir_list = evas_list_append(dir_list, new_epd); - } - if (ep->user_dir_list) { for (l = *(ep->user_dir_list); l; l = l->next) @@ -364,6 +356,14 @@ } } + for (l = ep->default_dir_list; l; l = l->next) + { + epd = l->data; + new_epd = malloc(sizeof(E_Path_Dir)); + new_epd->dir = strdup(epd->dir); + dir_list = evas_list_append(dir_list, new_epd); + } + return dir_list; } ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs