From 886a3106db6d6a60d2d706d2caad3e883dd70b14 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 1 Feb 2014 22:17:36 +0000 Subject: move utf8 local conversion operations to table --- amiga/clipboard.c | 25 ++++++++++----------- amiga/gui.c | 1 + amiga/utf8.c | 65 +++++++++++++++++++++++++++++++------------------------ amiga/utf8.h | 7 ++++++ 4 files changed, 57 insertions(+), 41 deletions(-) (limited to 'amiga') diff --git a/amiga/clipboard.c b/amiga/clipboard.c index d39e89e4a..6768dde17 100644 --- a/amiga/clipboard.c +++ b/amiga/clipboard.c @@ -16,10 +16,21 @@ * along with this program. If not, see . */ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "utils/nsoption.h" +#include "utils/utf8.h" #include "desktop/gui.h" #include "desktop/plotters.h" #include "desktop/textinput.h" -#include "utils/nsoption.h" #include "amiga/bitmap.h" #include "amiga/clipboard.h" @@ -31,18 +42,6 @@ #include "amiga/menu.h" #include "amiga/utf8.h" -#include "utils/utf8.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - #define ID_UTF8 MAKE_ID('U','T','F','8') struct IFFHandle *iffh = NULL; diff --git a/amiga/gui.c b/amiga/gui.c index 074dfafa6..f186328fe 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5223,6 +5223,7 @@ int main(int argc, char** argv) .clipboard = amiga_clipboard_table, .download = amiga_download_table, .fetch = &amiga_fetch_table, + .utf8 = amiga_utf8_table, }; /* Open popupmenu.library just to check the version. diff --git a/amiga/utf8.c b/amiga/utf8.c index d182492e9..a8e415d45 100755 --- a/amiga/utf8.c +++ b/amiga/utf8.c @@ -18,13 +18,44 @@ #include #include - #include + #include "utils/utf8.h" +#include "desktop/gui.h" #include #include #include +#include "amiga/utf8.h" + +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); +#endif + + return utf8_from_enc(string,encname,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); +#endif + + return utf8_to_enc(string,encname,len,result); +} + void ami_utf8_free(char *ptr) { if(ptr) free(ptr); @@ -58,32 +89,10 @@ char *ami_to_utf8_easy(const char *string) } } -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); -#endif - - return utf8_from_enc(string,encname,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); -#endif - - return utf8_to_enc(string,encname,len,result); -} +static struct gui_utf8_table utf8_table = { + .utf8_to_local = utf8_to_local_encoding, + .local_to_utf8 = utf8_from_local_encoding, +}; +struct gui_utf8_table *amiga_utf8_table = &utf8_table; diff --git a/amiga/utf8.h b/amiga/utf8.h index 7956523ee..065a149f2 100755 --- a/amiga/utf8.h +++ b/amiga/utf8.h @@ -18,7 +18,14 @@ #ifndef AMIGA_UTF8_H #define AMIGA_UTF8_H + +extern struct gui_utf8_table *ami_utf8_table; + char *ami_utf8_easy(const char *string); void ami_utf8_free(char *ptr); char *ami_to_utf8_easy(const char *string); + +nserror utf8_from_local_encoding(const char *string, size_t len, char **result); +nserror utf8_to_local_encoding(const char *string, size_t len, char **result); + #endif -- cgit v1.2.3