Re: [f16-branch 2/2] Handle strange lang boot argument values.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please, see comments below

On Wed, 2011-10-05 at 14:09 +0200, Ales Kozumplik wrote:
> First, internally translate '.utf8' to '.UTF-8' so it matches the
> lang-table.
> 
> Second, if a language missing from the lang-table is used with lang=,
> fallback on en_US.
> 
> Resolves: rhbz#731356
> ---
>  loader/lang.c   |   39 +++++++++++++++++++++++++++++++++++++--
>  loader/lang.h   |    1 +
>  loader/loader.c |    2 +-
>  3 files changed, 39 insertions(+), 3 deletions(-)
> 
> diff --git a/loader/lang.c b/loader/lang.c
> index 6b1fa8e..3dda676 100644
> --- a/loader/lang.c
> +++ b/loader/lang.c
> @@ -36,6 +36,7 @@
>  #include <sys/wait.h>
>  #include <unistd.h>
>  #include <wchar.h>
> +#include <glib.h>
>  
>  #include "loader.h"
>  #include "lang.h"
> @@ -103,6 +104,14 @@ char * translateString(char * str) {
>  static struct langInfo * languages = NULL;
>  static int numLanguages = 0;
>  
> +static int defaultLanguageIndex(void) {
> +    int i;
> +    for (i = 0; i < numLanguages; ++i)
> +        if (!strcmp(languages[i].lc_all, LANG_DEFAULT))
> +            return i;
> +    return -1;
> +}
> +
>  static void loadLanguageList(void) {
>      char * file = "/etc/lang-table";
>      FILE * f;
> @@ -144,6 +153,31 @@ int getLangInfo(struct langInfo ** langs) {
>      return numLanguages;
>  }
>  
> +/**
> + * Normalize the value of lang= boot argument.
> + *
> + * Currently only replaces the trailing .utf8 with .UTF-8.
> + *
> + * Returns a heap-allocated string.
> + */
> +char *normalizeLang(const char *s) {
> +    char *ending = g_strrstr(s, ".utf8");
> +    /* check this is at the end */
> +    if (!ending || strlen(ending) > strlen(".utf8"))
> +        goto dup;
> +    int basic_length = strlen(s) - strlen(".utf8"); /* length before .utf8 */
> +    char *result = g_malloc(strlen(s) + 2);
> +    if (!result)
> +        goto dup;
> +    strncpy(result, s, basic_length);
> +    strcpy(result + basic_length, ".UTF-8");
> +    return result;
> +
> + dup:
> +    /* if normalization fails simply return a dup of the original */
> +    return strdup(s);
> +}

glib has a g_str_has_suffix () function you could maybe use here.

And why the goto, when it executes just one return statement?

> +
>  void loadLanguage(void)
>  {
>      char *filename;
> @@ -395,8 +429,9 @@ int setLanguage (const char * key, int forced) {
>          }
>      }
>  
> -    logMessage(ERROR, "unable to set to requested language %s", key);
> -    return -1;
> +    logMessage(ERROR, "unable to set the requested language '%s', "
> +               "setting the default '%s'", key, LANG_DEFAULT);
> +    return setupLanguage(defaultLanguageIndex(), forced | !FL_KICKSTART(flags));
>  }
>  
>  int chooseLanguage(char ** lang) {
> diff --git a/loader/lang.h b/loader/lang.h
> index 168ffa3..c8590a9 100644
> --- a/loader/lang.h
> +++ b/loader/lang.h
> @@ -34,6 +34,7 @@ int chooseLanguage(char ** lang);
>  char * translateString(char * str);
>  int setLanguage (const char * key, int forced);
>  int getLangInfo(struct langInfo **langs);
> +char *normalizeLang(const char *s);

Not very consistent * placement. Not sure which one is our coding style.

>  
>  extern const char *LANG_DEFAULT;
>  
> diff --git a/loader/loader.c b/loader/loader.c
> index eedf439..cb8b7ab 100644
> --- a/loader/loader.c
> +++ b/loader/loader.c
> @@ -992,7 +992,7 @@ static void parseCmdLineFlags(struct loaderData_s * loaderData) {
>              } else if (!strcasecmp(k, "display")) {
>                  setenv("DISPLAY", v, 1);
>              } else if (!strcasecmp(k, "lang")) {
> -                loaderData->lang = g_strdup(v);
> +                loaderData->lang = normalizeLang(v);
>                  loaderData->lang_set = 1;
>              } else if (!strcasecmp(k, "keymap")) {
>                  loaderData->kbd = g_strdup(v);

-- 
Martin Gracik <mgracik@xxxxxxxxxx>

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux