From: Sean E. <sea...@us...> - 2002-08-22 03:25:04
|
Update of /cvsroot/gaim/gaim/src In directory usw-pr-cvs1:/tmp/cvs-serv22857/src Modified Files: Tag: gtk1-stable core.h gaim.h util.c Log Message: Now I'm going to bed. Index: core.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/core.h,v retrieving revision 1.18 retrieving revision 1.18.2.1 diff -u -d -r1.18 -r1.18.2.1 --- core.h 4 May 2002 08:21:31 -0000 1.18 +++ core.h 22 Aug 2002 03:25:00 -0000 1.18.2.1 @@ -26,6 +26,14 @@ #include <config.h> #endif +#ifdef HAVE_ICONV +#include <iconv.h> +#endif + +#ifdef HAVE_LANGINFO_CODESET +#include <langinfo.h> +#endif + #include <stdio.h> #include <time.h> #include <glib.h> @@ -47,6 +55,7 @@ char password[32]; char user_info[2048]; int options; + int protocol; /* prpls can use this to save information about the user, * like which server to connect to, etc */ Index: gaim.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/gaim.h,v retrieving revision 1.326 retrieving revision 1.326.2.1 diff -u -d -r1.326 -r1.326.2.1 --- gaim.h 18 Jun 2002 00:49:55 -0000 1.326 +++ gaim.h 22 Aug 2002 03:25:00 -0000 1.326.2.1 @@ -439,6 +439,14 @@ extern time_t get_time(int, int, int, int, int, int); extern FILE *gaim_mkstemp(gchar **); +#ifdef HAVE_LANGINFO_CODESET +#define utf8_to_str(in) convert_string(in, nl_langinfo(CODESET), "UTF-8"); +#define str_to_utf8(in) convert_string(in, "UTF-8", nl_langinfo(CODESET)); +#else +#define utf8_to_str(in) convert_string(in, "ISO-8859-1", "UTF-8"); +#define str_to_utf8(in) convert_string(in, "UTF-8", "ISO-8859-1"); +#endif + /*------------------------------------------------------------------------*/ /* Multi-Entry dialog and vCard dialog support */ /*------------------------------------------------------------------------*/ Index: util.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/util.c,v retrieving revision 1.123 retrieving revision 1.123.2.1 diff -u -d -r1.123 -r1.123.2.1 --- util.c 22 Jun 2002 02:07:48 -0000 1.123 +++ util.c 22 Aug 2002 03:25:00 -0000 1.123.2.1 @@ -32,6 +32,7 @@ #include <string.h> #include <sys/wait.h> #include <ctype.h> +#include <iconv.h> #include <math.h> #include "gaim.h" #include "prpl.h" @@ -1118,92 +1119,49 @@ fclose(fd); } -unsigned char *utf8_to_str(unsigned char *in) +char *convert_string(char *str, const char *destset, const char *srcset) { - int n = 0, i = 0; - int inlen; - unsigned char *result; - - if (!in) - return NULL; - - inlen = strlen(in); +#ifdef HAVE_ICONV + char *buf; + iconv_t cd; + size_t insize = 0; + size_t outsize = 0; + size_t nconv = 0; + char *inptr; + char *outptr; + char *ret; - result = g_malloc(inlen + 1); + if (!str) + return NULL; + buf = g_malloc(strlen(str)*4); + insize = strlen(str); + inptr = str; + outsize = strlen(str)*4; + outptr = buf; - while (n <= inlen - 1) { - long c = (long)in[n]; - if (c < 0x80) - result[i++] = (char)c; - else { - if ((c & 0xC0) == 0xC0) - result[i++] = - (char)(((c & 0x03) << 6) | (((unsigned char)in[++n]) & 0x3F)); - else if ((c & 0xE0) == 0xE0) { - if (n + 2 <= inlen) { - result[i] = - (char)(((c & 0xF) << 4) | (((unsigned char)in[++n]) & 0x3F)); - result[i] = - (char)(((unsigned char)result[i]) | - (((unsigned char)in[++n]) & 0x3F)); - i++; - } else - n += 2; - } else if ((c & 0xF0) == 0xF0) - n += 3; - else if ((c & 0xF8) == 0xF8) - n += 4; - else if ((c & 0xFC) == 0xFC) - n += 5; - } - n++; + cd = iconv_open(destset, srcset); + if (cd == (iconv_t) -1) { + g_free(buf); + debug_printf("iconv_open(%s, %s) Error\n",destset, srcset); + return g_strdup(str); } - result[i] = '\0'; - - return result; -} -char *str_to_utf8(unsigned char *in) -{ - int n = 0, i = 0; - int inlen; - char *result = NULL; - - if (!in) - return NULL; - - inlen = strlen(in); - - result = g_malloc(inlen * 2 + 1); - - while (n < inlen) { - long c = (long)in[n]; - if (c == 27) { - n += 2; - if (in[n] == 'x') - n++; - if (in[n] == '3') - n++; - n += 2; - continue; - } - /* why are we removing newlines and carriage returns? - if ((c == 0x0D) || (c == 0x0A)) { - n++; - continue; - } - */ - if (c < 128) - result[i++] = (char)c; - else { - result[i++] = (char)((c >> 6) | 192); - result[i++] = (char)((c & 63) | 128); - } - n++; + nconv = iconv(cd, &inptr, &insize, &outptr, &outsize); + if (nconv == (size_t) -1) { + debug_printf("iconv Error\n"); + g_free(buf); + return g_strdup(str); } - result[i] = '\0'; + *outptr = '\0'; + iconv_close(cd); - return result; + ret = g_strdup(buf); + g_free(buf); + + return ret; +#else + return g_strdup(str); +#endif } void strip_linefeed(gchar *text) |