From 14bf4b47a5ea36ba329e5910f3aa1d26cc452be9 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 25 Jun 2016 17:52:32 +0100 Subject: Use charset from default Locale and store it in an option so we can (a) override and (b) get it without constantly looking it up --- frontends/amiga/gui.c | 32 +++++++++++++++++++++----------- frontends/amiga/gui.h | 2 +- frontends/amiga/gui_options.c | 2 +- frontends/amiga/options.h | 2 +- frontends/amiga/utf8.c | 43 ++++++------------------------------------- 5 files changed, 30 insertions(+), 51 deletions(-) (limited to 'frontends/amiga') diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c index ac173eb1e..8d7c69ddb 100644 --- a/frontends/amiga/gui.c +++ b/frontends/amiga/gui.c @@ -28,6 +28,7 @@ #endif #include #include +#include #include #include #include @@ -44,6 +45,7 @@ #include #include #ifdef __amigaos4__ +#include #include #include #include @@ -247,7 +249,7 @@ static void gui_window_place_caret(struct gui_window *g, int x, int y, int heigh -STRPTR ami_locale_langs(void) +STRPTR ami_locale_langs(int *codeset) { struct Locale *locale; STRPTR acceptlangs = NULL; @@ -255,6 +257,8 @@ STRPTR ami_locale_langs(void) if((locale = OpenLocale(NULL))) { + if(codeset != NULL) *codeset = locale->loc_CodeSet; + for(int i = 0; i < 10; i++) { if(locale->loc_PrefLanguages[i]) @@ -562,6 +566,7 @@ static nserror ami_set_options(struct nsoption_s *defaults) { STRPTR tempacceptlangs; char temp[1024]; + int codeset = 0; /* The following line disables the popupmenu.class select menu. ** It's not recommended to use it! @@ -572,20 +577,11 @@ static nserror ami_set_options(struct nsoption_s *defaults) if(ClickTabBase->lib_Version < 53) nsoption_set_bool(tab_always_show, true); - /* Some AmigaOS3 overrides */ -#ifndef __amigaos4__ - nsoption_set_bool(download_notify, false); - nsoption_set_bool(font_antialiasing, false); - nsoption_set_bool(truecolour_mouse_pointers, false); - nsoption_set_bool(use_openurl_lib, true); - nsoption_set_bool(bitmap_fonts, true); -#endif - if((!nsoption_charp(accept_language)) || (nsoption_charp(accept_language)[0] == '\0') || (nsoption_bool(accept_lang_locale) == true)) { - if((tempacceptlangs = ami_locale_langs())) + if((tempacceptlangs = ami_locale_langs(&codeset))) { nsoption_set_charp(accept_language, (char *)strdup(tempacceptlangs)); @@ -593,6 +589,20 @@ static nserror ami_set_options(struct nsoption_s *defaults) } } + /* Some OS-specific overrides */ +#ifdef __amigaos4__ + if(codeset == 0) codeset = 4; /* ISO-8859-1 */ + const char *encname = (const char *)ObtainCharsetInfo(DFCS_NUMBER, codeset, + DFCS_MIMENAME); + nsoption_set_charp(local_charset, strdup(encname)); +#else + nsoption_set_bool(download_notify, false); + nsoption_set_bool(font_antialiasing, false); + nsoption_set_bool(truecolour_mouse_pointers, false); + nsoption_set_bool(use_openurl_lib, true); + nsoption_set_bool(bitmap_fonts, true); +#endif + sprintf(temp, "%s/Cookies", current_user_dir); nsoption_setnull_charp(cookie_file, (char *)strdup(temp)); diff --git a/frontends/amiga/gui.h b/frontends/amiga/gui.h index 4e36cb63f..8b0e22386 100644 --- a/frontends/amiga/gui.h +++ b/frontends/amiga/gui.h @@ -179,7 +179,7 @@ void ami_get_msg(void); void ami_try_quit(void); void ami_quit_netsurf(void); void ami_schedule_redraw(struct gui_window_2 *gwin, bool full_redraw); -STRPTR ami_locale_langs(void); +STRPTR ami_locale_langs(int *codeset); int ami_key_to_nskey(ULONG keycode, struct InputEvent *ie); bool ami_text_box_at_point(struct gui_window_2 *gwin, ULONG *x, ULONG *y); bool ami_mouse_to_ns_coords(struct gui_window_2 *gwin, int *x, int *y, diff --git a/frontends/amiga/gui_options.c b/frontends/amiga/gui_options.c index 4e6914c6a..344d82309 100755 --- a/frontends/amiga/gui_options.c +++ b/frontends/amiga/gui_options.c @@ -2140,7 +2140,7 @@ BOOL ami_gui_opts_event(void) RefreshSetGadgetAttrs((struct Gadget *)gow->objects[GID_OPTS_CONTENTLANG], gow->win, NULL, GA_Disabled, code, TAG_DONE); - if(code && (text = ami_locale_langs())) + if(code && (text = ami_locale_langs(NULL))) { RefreshSetGadgetAttrs((struct Gadget *)gow->objects[GID_OPTS_CONTENTLANG], gow->win, NULL, STRINGA_TextVal, text, TAG_DONE); diff --git a/frontends/amiga/options.h b/frontends/amiga/options.h index 39e62dc10..6f5c91906 100644 --- a/frontends/amiga/options.h +++ b/frontends/amiga/options.h @@ -87,9 +87,9 @@ NSOPTION_INTEGER(redraw_tile_size_y, 0) NSOPTION_INTEGER(monitor_aspect_x, 0) NSOPTION_INTEGER(monitor_aspect_y, 0) NSOPTION_BOOL(accept_lang_locale, true) +NSOPTION_STRING(local_charset, "ISO-8859-1") /* Options relevant for OS3 only */ #ifndef __amigaos4__ NSOPTION_BOOL(friend_bitmap, false) -NSOPTION_STRING(local_charset, "ISO-8859-1") #endif diff --git a/frontends/amiga/utf8.c b/frontends/amiga/utf8.c index 24af8c8b9..d48e073fd 100755 --- a/frontends/amiga/utf8.c +++ b/frontends/amiga/utf8.c @@ -19,9 +19,6 @@ #include #include #include -#include -#include -#include #include "utils/nsoption.h" #include "utils/utf8.h" @@ -31,34 +28,12 @@ nserror utf8_from_local_encoding(const char *string, size_t len, char **result) { - const char *encname = "ISO-8859-1"; - -#ifdef __amigaos4__ - LONG charset; - - charset = GetDiskFontCtrl(DFCTRL_CHARSET); - encname = (const char *) ObtainCharsetInfo(DFCS_NUMBER, charset, DFCS_MIMENAME); -#else - encname = nsoption_charp(local_charset); -#endif - - return utf8_from_enc(string,encname,len,result,NULL); + return utf8_from_enc(string, nsoption_charp(local_charset), len, result, NULL); } nserror utf8_to_local_encoding(const char *string, size_t len, char **result) { - const char *encname = "ISO-8859-1"; - -#ifdef __amigaos4__ - LONG charset; - - charset = GetDiskFontCtrl(DFCTRL_CHARSET); - encname = (const char *) ObtainCharsetInfo(DFCS_NUMBER, charset, DFCS_MIMENAME); -#else - encname = nsoption_charp(local_charset); -#endif - - return utf8_to_enc(string,encname,len,result); + return utf8_to_enc(string, nsoption_charp(local_charset), len, result); } void ami_utf8_free(char *ptr) @@ -70,12 +45,9 @@ char *ami_utf8_easy(const char *string) { char *localtext; - if(utf8_to_local_encoding(string,strlen(string),&localtext) == NSERROR_OK) - { + if(utf8_to_local_encoding(string, strlen(string), &localtext) == NSERROR_OK) { return localtext; - } - else - { + } else { return strdup(string); } } @@ -84,12 +56,9 @@ char *ami_to_utf8_easy(const char *string) { char *localtext; - if(utf8_from_local_encoding(string,strlen(string),&localtext) == NSERROR_OK) - { + if(utf8_from_local_encoding(string, strlen(string), &localtext) == NSERROR_OK) { return localtext; - } - else - { + } else { return strdup(string); } } -- cgit v1.2.3