# HG changeset patch # User ali # Date 1382893307 0 # Node ID c25e023cb9fe6043c22a0628857381685153ed96 # Parent f1d85b36e188308646fd62129e71fc5954455f89 Bugs #13+14: charsets in configuration files diff -r f1d85b36e188 -r c25e023cb9fe bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Sun Oct 27 16:58:50 2013 +0000 +++ b/bookloupe/bookloupe.c Sun Oct 27 17:01:47 2013 +0000 @@ -202,6 +202,8 @@ { "no-verbose", 0, G_OPTION_FLAG_HIDDEN|G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, pswit+VERBOSE_SWITCH, "Switch off verbose mode", NULL }, + { "charset", 0, 0, G_OPTION_ARG_STRING, &opt_charset, + "Set of characters valid for this ebook", "NAME" }, { NULL } }; @@ -215,8 +217,6 @@ "Defaults for use on www upload", NULL }, { "dump-config", 0, 0, G_OPTION_ARG_NONE, pswit+DUMP_CONFIG_SWITCH, "Dump current config settings", NULL }, - { "charset", 0, 0, G_OPTION_ARG_STRING, &opt_charset, - "Set of characters valid for this ebook", "NAME" }, { NULL } }; @@ -268,11 +268,55 @@ UINT saved_cp; #endif +gboolean set_charset(const char *name,GError **err) +{ + /* The various UNICODE encodings all share the same character set. */ + const char *unicode_aliases[]={ "UCS-2", "UCS-2BE", "UCS-2LE", "UCS-4", + "UCS-4BE", "UCS-4LE", "UCS2", "UCS4", "UNICODE", "UNICODEBIG", + "UNICODELITTLE", "UTF-7", "UTF-8", "UTF-16", "UTF-16BE", "UTF-16LE", + "UTF-32", "UTF-32BE", "UTF-32LE", "UTF7", "UTF8", "UTF16", "UTF16BE", + "UTF16LE", "UTF32", "UTF32BE", "UTF32LE" }; + int i; + if (charset) + g_free(charset); + if (charset_validator!=(GIConv)-1) + g_iconv_close(charset_validator); + if (!name || !g_strcasecmp(name,"auto")) + { + charset=NULL; + charset_validator=(GIConv)-1; + return TRUE; + } + else + charset=g_strdup(name); + for(i=0;imessage); g_clear_error(&err); } - if (options[j].flags&G_OPTION_FLAG_REVERSE) - sw=!sw; - *(gboolean *)options[j].arg_data=sw; + else + { + if (options[j].flags&G_OPTION_FLAG_REVERSE) + sw=!sw; + *(gboolean *)options[j].arg_data=sw; + } + break; + } + else if (options[j].arg==G_OPTION_ARG_STRING) + { + s=g_key_file_get_string(config,"options",keys[i], + &err); + if (err) + { + g_printerr("Bookloupe: %s: options.%s: %s\n", + path,keys[i],err->message); + g_clear_error(&err); + } + else + { + g_free(*(gchar **)options[j].arg_data); + if (!g_strcmp0(s,"auto")) + { + *(gchar **)options[j].arg_data=NULL; + g_free(s); + } + else + *(gchar **)options[j].arg_data=s; + } break; } else @@ -429,49 +506,6 @@ g_free(path); } -gboolean set_charset(const char *name,GError **err) -{ - /* The various UNICODE encodings all share the same character set. */ - const char *unicode_aliases[]={ "UCS-2", "UCS-2BE", "UCS-2LE", "UCS-4", - "UCS-4BE", "UCS-4LE", "UCS2", "UCS4", "UNICODE", "UNICODEBIG", - "UNICODELITTLE", "UTF-7", "UTF-8", "UTF-16", "UTF-16BE", "UTF-16LE", - "UTF-32", "UTF-32BE", "UTF-32LE", "UTF7", "UTF8", "UTF16", "UTF16BE", - "UTF16LE", "UTF32", "UTF32BE", "UTF32LE" }; - int i; - if (charset) - g_free(charset); - if (charset_validator!=(GIConv)-1) - g_iconv_close(charset_validator); - if (!name || !g_strcasecmp(name,"auto")) - { - charset=NULL; - charset_validator=(GIConv)-1; - return TRUE; - } - else - charset=g_strdup(name); - for(i=0;i