diff --git a/src/config/opttypes.c b/src/config/opttypes.c index 8ef3ea05..6c02278b 100644 --- a/src/config/opttypes.c +++ b/src/config/opttypes.c @@ -322,7 +322,7 @@ cp_set(struct option *opt, unsigned char *str) static void cp_wr(struct option *o, struct string *s) { - unsigned char *mime_name = get_cp_mime_name(o->value.number); + unsigned char *mime_name = get_cp_config_name(o->value.number); add_optstring_to_string(s, mime_name, strlen(mime_name)); } diff --git a/src/dialogs/options.c b/src/dialogs/options.c index 9475884f..43ce7595 100644 --- a/src/dialogs/options.c +++ b/src/dialogs/options.c @@ -64,7 +64,7 @@ charset_list(struct terminal *term, void *xxx, void *ses_) items++; add_to_menu(&mi, name, NULL, ACT_MAIN_NONE, - display_codepage, get_cp_mime_name(i), 0); + display_codepage, get_cp_config_name(i), 0); } /* Special codepages are not in the menu and it may cause assertion diff --git a/src/intl/charsets.c b/src/intl/charsets.c index 99f0f7e7..719aff33 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -1427,6 +1427,11 @@ free_charsets_lookup(void) #endif } +/* Get the codepage's name for displaying to the user, or NULL if + * @cp_index is one past the end. In the future, we might want to + * localize these with gettext. So it may be best not to use this + * function if the name will have to be converted back to an + * index. */ unsigned char * get_cp_name(int cp_index) { @@ -1436,11 +1441,27 @@ get_cp_name(int cp_index) return codepages[cp_index].name; } +/* Get the codepage's name for saving to a configuration file. These + * names can be converted back to indexes, even in future versions of + * ELinks. */ +unsigned char * +get_cp_config_name(int cp_index) +{ + if (cp_index < 0) return "none"; + if (cp_index & SYSTEM_CHARSET_FLAG) return "System"; + if (!codepages[cp_index].aliases) return NULL; + + return codepages[cp_index].aliases[0]; +} + +/* Get the codepage's name for sending to a library or server that + * understands MIME charset names. This function irreversibly maps + * the "System" codepage to the underlying charset. */ unsigned char * get_cp_mime_name(int cp_index) { if (cp_index < 0) return "none"; - if (cp_index & SYSTEM_CHARSET_FLAG) return "System"; + cp_index &= ~SYSTEM_CHARSET_FLAG; if (!codepages[cp_index].aliases) return NULL; return codepages[cp_index].aliases[0]; diff --git a/src/intl/charsets.h b/src/intl/charsets.h index 69d67ace..02524547 100644 --- a/src/intl/charsets.h +++ b/src/intl/charsets.h @@ -106,6 +106,7 @@ unsigned char *convert_string(struct conv_table *convert_table, int get_cp_index(unsigned char *); unsigned char *get_cp_name(int); +unsigned char *get_cp_config_name(int); unsigned char *get_cp_mime_name(int); int is_cp_utf8(int); void free_conv_table(void); diff --git a/src/scripting/lua/core.c b/src/scripting/lua/core.c index 5ffb414f..830676b5 100644 --- a/src/scripting/lua/core.c +++ b/src/scripting/lua/core.c @@ -579,7 +579,7 @@ l_get_option(LS) { unsigned char *cp_name; - cp_name = get_cp_mime_name(opt->value.number); + cp_name = get_cp_config_name(opt->value.number); lua_pushstring(S, cp_name); break; }