From 926580879633d54a831d460b7f8d768ef81d3090 Mon Sep 17 00:00:00 2001 From: fedor Date: Fri, 21 Sep 2001 16:13:11 +0000 Subject: [PATCH] Improve unicode handling git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@10947 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++ Headers/gnustep/base/NSGeometry.h | 6 +-- Source/NSConnection.m | 90 ------------------------------- Source/Unicode.m | 34 +++++++++++- configure | 4 +- configure.in | 4 +- 6 files changed, 46 insertions(+), 99 deletions(-) diff --git a/ChangeLog b/ChangeLog index c64e4f692..f7c7714c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-09-21 Adam Fedor + + * configure.in: Typo in iconv cached value. + * Headers/gnustep/base/NSGeometry.h: Make const values static also. + * Source/NSConnection.m: Remove obsolete BROKEN_NESTED code. + * Source/Unicode.m: Dynamically determine best Unicode encoding. + 2001-09-21 Richard Frith-Macdonald * Headers/gnustep/base/DistributedObjects.h: diff --git a/Headers/gnustep/base/NSGeometry.h b/Headers/gnustep/base/NSGeometry.h index 240355eec..dd4794c69 100644 --- a/Headers/gnustep/base/NSGeometry.h +++ b/Headers/gnustep/base/NSGeometry.h @@ -80,9 +80,9 @@ enum _NSRectEdge NSMaxYEdge }; -const NSPoint NSZeroPoint; /* A zero point. */ -const NSRect NSZeroRect; /* A zero origin rectangle. */ -const NSSize NSZeroSize; /* A zero size rectangle. */ +static const NSPoint NSZeroPoint; /* A zero point. */ +static const NSRect NSZeroRect; /* A zero origin rectangle. */ +static const NSSize NSZeroSize; /* A zero size rectangle. */ /**** Function Prototypes ****************************************************/ diff --git a/Source/NSConnection.m b/Source/NSConnection.m index a73c62248..c07c38bcd 100644 --- a/Source/NSConnection.m +++ b/Source/NSConnection.m @@ -1413,96 +1413,6 @@ static BOOL multi_threaded = NO; RELEASE(arp); } -#ifdef BROKEN_NESTED_FUNCTIONS -typedef struct _NSConnection_t { - @defs(NSConnection) -} NSConnection_t; -static NSConnection_t *c_self_t; -static NSPortCoder *op = nil; -static NSPortCoder *ip = nil; -static NSConnection *c_self; -static BOOL is_exception = NO; -static BOOL second_decode = NO; -static int seq_num; - - void encoder (int argnum, void *datum, const char *type, int flags) - { -#define ENCODED_ARGNAME @"argument value" - switch (*type) - { - case _C_ID: - if (flags & _F_BYCOPY) - [op encodeBycopyObject: *(id*)datum]; -#ifdef _F_BYREF - else if (flags & _F_BYREF) - [op encodeByrefObject: *(id*)datum]; -#endif - else - [op encodeObject: *(id*)datum]; - break; - default: - [op encodeValueOfObjCType: type at: datum]; - } - } - - void decoder(int argnum, void *datum, const char *type, int flags) - { - c_self_t = (NSConnection_t *)c_self; - if (type == 0) - { - if (ip != nil) - { - [c_self _doneInRmc: ip]; - /* this must be here to avoid trashing alloca'ed retframe */ - ip = (id)-1; - c_self_t->_repInCount++; /* received a reply */ - } - return; - } - /* If we didn't get the reply packet yet, get it now. */ - if (ip == nil) - { - if (c_self_t->_isValid == NO) - { - [NSException raise: NSGenericException - format: @"connection waiting for request was shut down"]; - } - ip = [c_self _getReplyRmc: seq_num]; - /* - * Find out if the server is returning an exception instead - * of the return values. - */ - [ip decodeValueOfObjCType: @encode(BOOL) at: &is_exception]; - if (is_exception == YES) - { - /* Decode the exception object, and raise it. */ - id exc; - [ip decodeValueOfObjCType: @encode(id) at: &exc]; - [c_self _doneInRmc: ip]; - ip = (id)-1; - /* xxx Is there anything else to clean up in - dissect_method_return()? */ - [exc raise]; - } - } - if (*type == _C_PTR) - else - [ip decodeValueOfObjCType: type+1 at: datum]; - [ip decodeValueOfObjCType: type at: datum]; - /* -decodeValueOfObjCType:at: malloc's new memory - for pointers. We need to make sure it gets freed eventually - so we don't have a memory leak. Request here that it be - autorelease'ed. Also autorelease created objects. */ - if (second_decode == NO) - { - if ((*type == _C_CHARPTR || *type == _C_PTR) && *(void**)datum != 0) - [NSData dataWithBytesNoCopy: *(void**)datum length: 1]; - } - else if (*type == _C_ID) - AUTORELEASE(*(id*)datum); - } -#endif - static void retDecoder(DOContext *ctxt) { NSPortCoder *coder = ctxt->decoder; diff --git a/Source/Unicode.m b/Source/Unicode.m index 601ae072d..61cfd172f 100644 --- a/Source/Unicode.m +++ b/Source/Unicode.m @@ -52,11 +52,15 @@ struct _ucc_ {unichar from; char to;}; // The rest of the GNUstep code stores UNICODE in internal byte order, // so we do the same. This should be UCS-2-INTERNAL for libiconv #ifdef WORDS_BIGENDIAN -#define UNICODE_ENC "UNICODEBIG" +#define UNICODE_INT "UNICODEBIGL" #else -#define UNICODE_ENC "UNICODELITTLE" +#define UNICODE_INT "UNICODELITTLE" #endif +#define UNICODE_ENC ((unicode_enc) ? unicode_enc : internal_unicode_enc()) + +static const char *unicode_enc = NULL; + #endif @@ -174,6 +178,8 @@ const struct _strenc_ str_encoding_table[]= {0, "Unknown encoding"} }; + + NSStringEncoding *GetAvailableEncodings() { // FIXME: This should check which iconv definitions are available and @@ -279,6 +285,30 @@ GetEncodingName(NSStringEncoding encoding) #ifdef HAVE_ICONV +/* Check to see what type of internal unicode format the library supports */ +static const char * +internal_unicode_enc() +{ + iconv_t conv; + unicode_enc = UNICODE_INT; + conv = iconv_open(unicode_enc, "ASCII"); + if (conv != (iconv_t)-1) + { + iconv_close(conv); + return unicode_enc; + } + unicode_enc = "UCS-2-INTERNAL"; + conv = iconv_open(unicode_enc, "ASCII"); + if (conv != (iconv_t)-1) + { + iconv_close(conv); + return unicode_enc; + } + unicode_enc = "UCS-2"; + /* This had better work */ + return unicode_enc; +} + static char * iconv_stringforencoding(NSStringEncoding enc) { diff --git a/configure b/configure index 10294addf..1f1b76ee6 100755 --- a/configure +++ b/configure @@ -5463,7 +5463,7 @@ else echo "$ac_t""no" 1>&6 fi - if test x"$av_cv_lib_giconv_main" = xyes; then + if test x"$ac_cv_lib_giconv_main" = xyes; then cat >> confdefs.h <<\EOF #define HAVE_ICONV 1 EOF @@ -5516,7 +5516,7 @@ else echo "$ac_t""no" 1>&6 fi - if test x"$av_cv_lib_iconv_main" = xyes; then + if test x"$ac_cv_lib_iconv_main" = xyes; then cat >> confdefs.h <<\EOF #define HAVE_ICONV 1 EOF diff --git a/configure.in b/configure.in index 261e6eab5..c232ecb06 100644 --- a/configure.in +++ b/configure.in @@ -916,12 +916,12 @@ if test $ac_cv_func_iconv = no; then # BSDs install this lib as libgiconv AC_CHECK_LIB(giconv, main) - if test x"$av_cv_lib_giconv_main" = xyes; then + if test x"$ac_cv_lib_giconv_main" = xyes; then AC_DEFINE(HAVE_ICONV) AC_DEFINE(HAVE_GICONV_H) else AC_CHECK_LIB(iconv, main) - if test x"$av_cv_lib_iconv_main" = xyes; then + if test x"$ac_cv_lib_iconv_main" = xyes; then AC_DEFINE(HAVE_ICONV) fi fi