Mageia Bugzilla – Attachment 4176 Details for
Bug 5749
hunspell doesn't have locale fallback mechanism to find dictionnaries
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
[patch]
adds fallback mechanisms to find default dictionnary
hunspell-1.3.2-mga-fallback-to-language.patch (text/plain), 2.48 KB, created by
Pablo Saratxaga
on 2013-06-30 00:40:12 CEST
(
hide
)
Description:
adds fallback mechanisms to find default dictionnary
Filename:
MIME Type:
Creator:
Pablo Saratxaga
Created:
2013-06-30 00:40:12 CEST
Size:
2.48 KB
patch
obsolete
>--- hunspell-1.3.2_bak/src/tools/hunspell.cxx 2013-06-29 15:59:48.458556502 +0200 >+++ hunspell-1.3.2/src/tools/hunspell.cxx 2013-06-30 00:29:11.748249991 +0200 >@@ -151,6 +151,8 @@ > int wordchars_utf16_free = 0; > int wordchars_utf16_len; > char * dicname = NULL; >+char * colon = NULL; >+char * underscore = NULL; > char * privdicname = NULL; > const char * currentfilename = NULL; > >@@ -1634,17 +1636,20 @@ > if (! dicname) { > if (! (dicname=getenv("DICTIONARY"))) { > /* >- * Search in order of LC_ALL, LC_MESSAGES & >+ * Search in order of LANGUAGE, LC_ALL, LC_MESSAGES & > * LANG > */ >- const char *tests[] = { "LC_ALL", "LC_MESSAGES", "LANG" }; >+ const char *tests[] = { "LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG" }; > for (size_t i = 0; i < sizeof(tests) / sizeof(const char*); ++i) { > if ((dicname=getenv(tests[i])) && strcmp(dicname, "") != 0) { > dicname = mystrdup(dicname); >+ colon = strchr(dicname, ':'); >+ if (colon) *colon++ = '\0'; > char * dot = strchr(dicname, '.'); >- if (dot) *dot = '\0'; > char * at = strchr(dicname, '@'); >+ if (dot) *dot = '\0'; > if (at) *at = '\0'; >+ underscore = strchr(dicname, '_'); > break; > } > } >@@ -1678,8 +1683,47 @@ > > char * dicplus = strchr(dicname, ','); > if (dicplus) *dicplus = '\0'; >+ >+ /* .aff and .dic files share the same path and basename, >+ * so we test all possibilities with .aff and once found >+ * the .dic one uses the same parameters; no need to test >+ * all cases for both >+ */ > char * aff = search(path, dicname, ".aff"); >+ >+ /* if xx_YY not found, try fallback to xx */ >+ if (!aff && underscore) { >+ *underscore = '\0'; >+ aff = search(path, dicname, ".aff"); >+ } >+ >+ /* if there was a ':', then it is a colon separated >+ * list of locales, test again with each of them */ >+ while (!aff && colon) { >+ char *s = mystrdup(colon); >+ if (dicname) free(dicname); >+ dicname = s; >+ >+ colon = strchr(dicname, ':'); >+ if (colon) *colon++ = '\0'; >+ char * dot = strchr(dicname, '.'); >+ char * at = strchr(dicname, '@'); >+ if (dot) *dot = '\0'; >+ if (at) *at = '\0'; >+ underscore = strchr(dicname, '_'); >+ >+ aff = search(path, dicname, ".aff"); >+ >+ /* if xx_YY not found, try fallback to xx */ >+ if (!aff && underscore) { >+ *underscore = '\0'; >+ aff = search(path, dicname, ".aff"); >+ } >+ } >+ >+ /* look for .dic */ > char * dic = search(path, dicname, ".dic"); >+ > if (aff && dic) { > if (showpath) { > fprintf(stderr, gettext("LOADED DICTIONARY:\n%s\n%s\n"), aff, dic);
--- hunspell-1.3.2_bak/src/tools/hunspell.cxx 2013-06-29 15:59:48.458556502 +0200 +++ hunspell-1.3.2/src/tools/hunspell.cxx 2013-06-30 00:29:11.748249991 +0200 @@ -151,6 +151,8 @@ int wordchars_utf16_free = 0; int wordchars_utf16_len; char * dicname = NULL; +char * colon = NULL; +char * underscore = NULL; char * privdicname = NULL; const char * currentfilename = NULL; @@ -1634,17 +1636,20 @@ if (! dicname) { if (! (dicname=getenv("DICTIONARY"))) { /* - * Search in order of LC_ALL, LC_MESSAGES & + * Search in order of LANGUAGE, LC_ALL, LC_MESSAGES & * LANG */ - const char *tests[] = { "LC_ALL", "LC_MESSAGES", "LANG" }; + const char *tests[] = { "LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG" }; for (size_t i = 0; i < sizeof(tests) / sizeof(const char*); ++i) { if ((dicname=getenv(tests[i])) && strcmp(dicname, "") != 0) { dicname = mystrdup(dicname); + colon = strchr(dicname, ':'); + if (colon) *colon++ = '\0'; char * dot = strchr(dicname, '.'); - if (dot) *dot = '\0'; char * at = strchr(dicname, '@'); + if (dot) *dot = '\0'; if (at) *at = '\0'; + underscore = strchr(dicname, '_'); break; } } @@ -1678,8 +1683,47 @@ char * dicplus = strchr(dicname, ','); if (dicplus) *dicplus = '\0'; + + /* .aff and .dic files share the same path and basename, + * so we test all possibilities with .aff and once found + * the .dic one uses the same parameters; no need to test + * all cases for both + */ char * aff = search(path, dicname, ".aff"); + + /* if xx_YY not found, try fallback to xx */ + if (!aff && underscore) { + *underscore = '\0'; + aff = search(path, dicname, ".aff"); + } + + /* if there was a ':', then it is a colon separated + * list of locales, test again with each of them */ + while (!aff && colon) { + char *s = mystrdup(colon); + if (dicname) free(dicname); + dicname = s; + + colon = strchr(dicname, ':'); + if (colon) *colon++ = '\0'; + char * dot = strchr(dicname, '.'); + char * at = strchr(dicname, '@'); + if (dot) *dot = '\0'; + if (at) *at = '\0'; + underscore = strchr(dicname, '_'); + + aff = search(path, dicname, ".aff"); + + /* if xx_YY not found, try fallback to xx */ + if (!aff && underscore) { + *underscore = '\0'; + aff = search(path, dicname, ".aff"); + } + } + + /* look for .dic */ char * dic = search(path, dicname, ".dic"); + if (aff && dic) { if (showpath) { fprintf(stderr, gettext("LOADED DICTIONARY:\n%s\n%s\n"), aff, dic);
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 5749
: 4176