sync with 0.8.8cvs2
authorPaul Mangan <paul@claws-mail.org>
Wed, 8 Jan 2003 19:57:10 +0000 (19:57 +0000)
committerPaul Mangan <paul@claws-mail.org>
Wed, 8 Jan 2003 19:57:10 +0000 (19:57 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.in
src/codeconv.c
src/codeconv.h

index 3950fb2..530bc79 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2003-01-08
+
+       * src/codeconv.[ch]: code cleanup and optimization.
+         conv_code_converter_new()
+         conv_convert(): use functions obtained by conv_get_code_conv_func()
+         when using libjconv.
+         conv_codeset_strdup(): code cleanup.
+         conv_get_code_conv_func(): added an argument for destination
+         character set, and generalized.
+
 2003-01-06
 
        * src/codeconv.c: LBREAK_IF_REQUIRED(): break line only if some
index dc6b2b2..85b0b40 100644 (file)
@@ -1,3 +1,8 @@
+2003-01-08 [paul]      0.8.8claws68
+
+       * sync with 0.8.8cvs2
+               see ChangeLog 2002-01-08
+
 2003-01-08 [paul]      0.8.8claws67
 
        * po/it.po
index 1f5e65f..0534b93 100644 (file)
@@ -1,3 +1,13 @@
+2003-01-08
+
+       * src/codeconv.[ch]: ¥³¡¼¥É¤ÎÀ°Íý¤ÈºÇŬ²½¡£
+         conv_code_converter_new()
+         conv_convert(): libjconv »ÈÍÑ»þ¤Ë conv_get_code_conv_func() ¤Ç
+         ÆÀ¤é¤ì¤ë´Ø¿ô¤ò»ÈÍѤ¹¤ë¤è¤¦¤Ë¤·¤¿¡£
+         conv_codeset_strdup(): ¥³¡¼¥É¤ÎÀ°Íý¡£
+         conv_get_code_conv_func(): ÊÑ´¹Àèʸ»ú¥³¡¼¥É¤Î°ú¿ô¤òÄɲä·¡¢°ìÈ̲½
+         ¤·¤¿¡£
+
 2003-01-06
 
        * src/codeconv.c: LBREAK_IF_REQUIRED(): Ê¸»ú¤¬Â³¤¯¾ì¹ç¤Î¤ß²þ¹Ô¤¹¤ë
index 4f761c1..c6506ec 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=8
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws67
+EXTRA_VERSION=claws68
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index c2178fe..1537a09 100644 (file)
 #include <ctype.h>
 #include <stdlib.h>
 
-#if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
-#  include <wchar.h>
-#  include <wctype.h>
-#endif
-
 #if HAVE_LOCALE_H
 #  include <locale.h>
 #endif
@@ -540,9 +535,7 @@ CodeConverter *conv_code_converter_new(const gchar *charset)
        CodeConverter *conv;
 
        conv = g_new0(CodeConverter, 1);
-#if !HAVE_LIBJCONV
-       conv->code_conv_func = conv_get_code_conv_func(charset);
-#endif
+       conv->code_conv_func = conv_get_code_conv_func(charset, NULL);
        conv->charset_str = g_strdup(charset);
        conv->charset = conv_get_charset_from_str(charset);
 
@@ -559,14 +552,18 @@ gint conv_convert(CodeConverter *conv, gchar *outbuf, gint outlen,
                  const gchar *inbuf)
 {
 #if HAVE_LIBJCONV
-       gchar *str;
-
-       str = conv_codeset_strdup(inbuf, conv->charset_str, NULL);
-       if (!str)
-               return -1;
+       if (conv->code_conv_func != conv_noconv)
+               conv->code_conv_func(outbuf, outlen, inbuf);
        else {
-               strncpy2(outbuf, str, outlen);
-               g_free(str);
+               gchar *str;
+
+               str = conv_codeset_strdup(inbuf, conv->charset_str, NULL);
+               if (!str)
+                       return -1;
+               else {
+                       strncpy2(outbuf, str, outlen);
+                       g_free(str);
+               }
        }
 #else /* !HAVE_LIBJCONV */
        conv->code_conv_func(outbuf, outlen, inbuf);
@@ -580,39 +577,31 @@ gchar *conv_codeset_strdup(const gchar *inbuf,
 {
        gchar *buf;
        size_t len;
+       CodeConvFunc conv_func;
 #if HAVE_LIBJCONV
        gint actual_codeset;
        const gchar *const *codesets;
        gint n_codesets;
-#else /* !HAVE_LIBJCONV */
-       CharSet src_charset = C_AUTO, dest_charset = C_AUTO;
 #endif
 
-       if (!dest_codeset) {
-               CodeConvFunc func;
-
-               func = conv_get_code_conv_func(src_codeset);
-               if (func != conv_noconv) {
-                       if (func == conv_jistodisp ||
-                           func == conv_sjistodisp ||
-                           func == conv_anytodisp)
-                               len = strlen(inbuf) * 2 + 1;
-                       else
-                               len = strlen(inbuf) + 1;
-                       buf = g_malloc(len);
-                       if (!buf) return NULL;
-                       func(buf, len, inbuf);
-                       buf = g_realloc(buf, strlen(buf) + 1);
-                       return buf;
-               }
+       conv_func = conv_get_code_conv_func(src_codeset, dest_codeset);
+       if (conv_func != conv_noconv) {
+               len = (strlen(inbuf) + 1) * 3;
+               buf = g_malloc(len);
+               if (!buf) return NULL;
+
+               conv_func(buf, len, inbuf);
+               return g_realloc(buf, strlen(buf) + 1);
        }
 
+#if !HAVE_LIBJCONV
+       return g_strdup(inbuf);
+#else
        /* don't convert if src and dest codeset are identical */
        if (src_codeset && dest_codeset &&
            !strcasecmp(src_codeset, dest_codeset))
                return g_strdup(inbuf);
 
-#if HAVE_LIBJCONV
        if (src_codeset) {
                codesets = &src_codeset;
                n_codesets = 1;
@@ -638,71 +627,74 @@ gchar *conv_codeset_strdup(const gchar *inbuf,
 #endif /* 0 */
                return NULL;
        }
-#else /* !HAVE_LIBJCONV */
-       if (src_codeset) {
-               if (!strcasecmp(src_codeset, CS_EUC_JP) ||
-                   !strcasecmp(src_codeset, CS_EUCJP))
-                       src_charset = C_EUC_JP;
-               else if (!strcasecmp(src_codeset, CS_SHIFT_JIS) ||
-                        !strcasecmp(src_codeset, "SHIFT-JIS") ||
-                        !strcasecmp(src_codeset, "SJIS"))
-                       src_charset = C_SHIFT_JIS;
-               if (dest_codeset && !strcasecmp(dest_codeset, CS_ISO_2022_JP))
-                       dest_charset = C_ISO_2022_JP;
-       }
-
-       if ((src_charset == C_EUC_JP || src_charset == C_SHIFT_JIS) &&
-           dest_charset == C_ISO_2022_JP) {
-               len = (strlen(inbuf) + 1) * 3;
-               buf = g_malloc(len);
-               if (buf) {
-                       if (src_charset == C_EUC_JP)
-                               conv_euctojis(buf, len, inbuf);
-                       else
-                               conv_anytojis(buf, len, inbuf);
-                       buf = g_realloc(buf, strlen(buf) + 1);
-               }
-       } else
-               buf = g_strdup(inbuf);
-
-       return buf;
-#endif /* !HAVE_LIBJCONV */
+#endif /* HAVE_LIBJCONV */
 }
 
-CodeConvFunc conv_get_code_conv_func(const gchar *charset)
+CodeConvFunc conv_get_code_conv_func(const gchar *src_charset_str,
+                                    const gchar *dest_charset_str)
 {
-       CodeConvFunc code_conv;
-       CharSet cur_charset;
+       CodeConvFunc code_conv = conv_noconv;
+       CharSet src_charset;
+       CharSet dest_charset;
 
-       if (!charset) {
-               cur_charset = conv_get_current_charset();
-               if (cur_charset == C_EUC_JP || cur_charset == C_SHIFT_JIS)
+       if (!src_charset_str)
+               src_charset = conv_get_current_charset();
+       else
+               src_charset = conv_get_charset_from_str(src_charset_str);
+
+       /* auto detection mode */
+       if (!src_charset_str && !dest_charset_str) {
+               if (src_charset == C_EUC_JP || src_charset == C_SHIFT_JIS)
                        return conv_anytodisp;
                else
                        return conv_noconv;
        }
 
-       if (!strcasecmp(charset, CS_ISO_2022_JP) ||
-           !strcasecmp(charset, CS_ISO_2022_JP_2))
-               code_conv = conv_jistodisp;
-       else if (!strcasecmp(charset, CS_US_ASCII))
-               code_conv = conv_ustodisp;
-       else if (!strncasecmp(charset, CS_ISO_8859_1, 10))
-               code_conv = conv_latintodisp;
+       dest_charset = conv_get_charset_from_str(dest_charset_str);
+
+       switch (src_charset) {
+       case C_ISO_2022_JP:
+       case C_ISO_2022_JP_2:
+               if (dest_charset == C_AUTO)
+                       code_conv = conv_jistodisp;
+               else if (dest_charset == C_EUC_JP)
+                       code_conv = conv_jistoeuc;
+               break;
+       case C_US_ASCII:
+               if (dest_charset == C_AUTO)
+                       code_conv = conv_ustodisp;
+               break;
+       case C_ISO_8859_1:
 #if !HAVE_LIBJCONV
-       else if (!strncasecmp(charset, "ISO-8859-", 9))
-               code_conv = conv_latintodisp;
+       case C_ISO_8859_2:
+       case C_ISO_8859_4:
+       case C_ISO_8859_5:
+       case C_ISO_8859_7:
+       case C_ISO_8859_8:
+       case C_ISO_8859_9:
+       case C_ISO_8859_11:
+       case C_ISO_8859_13:
+       case C_ISO_8859_15:
 #endif
-       else if (!strcasecmp(charset, CS_SHIFT_JIS) ||
-                !strcasecmp(charset, "SHIFT-JIS")  ||
-                !strcasecmp(charset, "SJIS")       ||
-                !strcasecmp(charset, "X-SJIS"))
-               code_conv = conv_sjistodisp;
-       else if (!strcasecmp(charset, CS_EUC_JP) ||
-                !strcasecmp(charset, CS_EUCJP))
-               code_conv = conv_euctodisp;
-       else
-               code_conv = conv_noconv;
+               if (dest_charset == C_AUTO)
+                       code_conv = conv_latintodisp;
+               break;
+       case C_SHIFT_JIS:
+               if (dest_charset == C_AUTO)
+                       code_conv = conv_sjistodisp;
+               else if (dest_charset == C_EUC_JP)
+                       code_conv = conv_sjistoeuc;
+               break;
+       case C_EUC_JP:
+               if (dest_charset == C_AUTO)
+                       code_conv = conv_euctodisp;
+               else if (dest_charset == C_ISO_2022_JP ||
+                        dest_charset == C_ISO_2022_JP_2)
+                       code_conv = conv_euctojis;
+               break;
+       default:
+               break;
+       }
 
        return code_conv;
 }
@@ -734,6 +726,8 @@ static const struct {
        {C_EUC_JP,              CS_EUC_JP},
        {C_EUC_JP,              CS_EUCJP},
        {C_SHIFT_JIS,           CS_SHIFT_JIS},
+       {C_SHIFT_JIS,           CS_SHIFT__JIS},
+       {C_SHIFT_JIS,           CS_SJIS},
        {C_ISO_2022_KR,         CS_ISO_2022_KR},
        {C_EUC_KR,              CS_EUC_KR},
        {C_ISO_2022_CN,         CS_ISO_2022_CN},
index bc40db3..53aa967 100644 (file)
 
 #include <glib.h>
 
-#if HAVE_LIBJCONV
-#  include <jconv.h>
-#endif
-
 typedef struct _CodeConverter  CodeConverter;
 
 typedef enum
@@ -71,9 +67,7 @@ typedef void (*CodeConvFunc) (gchar *outbuf, gint outlen, const gchar *inbuf);
 
 struct _CodeConverter
 {
-#if !HAVE_LIBJCONV
        CodeConvFunc code_conv_func;
-#endif
        gchar *charset_str;
        CharSet charset;
 };
@@ -102,6 +96,9 @@ struct _CodeConverter
 #define CS_EUC_JP              "EUC-JP"
 #define CS_EUCJP               "EUCJP"
 #define CS_SHIFT_JIS           "Shift_JIS"
+#define CS_SHIFT__JIS          "SHIFT-JIS"
+#define CS_SJIS                        "SJIS"
+#define CS_X_SJIS              "X-SJIS"
 #define CS_ISO_2022_KR         "ISO-2022-KR"
 #define CS_EUC_KR              "EUC-KR"
 #define CS_ISO_2022_CN         "ISO-2022-CN"
@@ -138,11 +135,12 @@ gint conv_convert                 (CodeConverter  *conv,
                                         gint            outlen,
                                         const gchar    *inbuf);
 
-gchar *conv_codeset_strdup(const gchar *inbuf,
-                          const gchar *src_codeset,
-                          const gchar *dest_codeset);
+gchar *conv_codeset_strdup             (const gchar    *inbuf,
+                                        const gchar    *src_codeset,
+                                        const gchar    *dest_codeset);
 
-CodeConvFunc conv_get_code_conv_func(const gchar *charset);
+CodeConvFunc conv_get_code_conv_func   (const gchar    *src_charset_str,
+                                        const gchar    *dest_charset_str);
 
 const gchar *conv_get_charset_str              (CharSet         charset);
 CharSet conv_get_charset_from_str              (const gchar    *charset);