[This copy contains the attachment. Also, I forgot to mention that simply 
changing 
the logic of preprocessing in, say, vim.h doesn't solve the problem. Features 
provided by the conflicting code are indeed needed together--you lose X 
functionality or MacRoman encoding functionality depending what is disabled, 
and 
there's no easy way to reconcile it by playing preprocessor games.]

Hi,

I recently had trouble compiling Vim on Mac OS X 10.4.9 with GTK2 GUI. As is
mentioned in the Vim source, the X headers and Mac headers clash horribly. This
means stuff has to be separated carefully into files that have X headers 
available
and those that have Mac headers available, and they weren't quite sorted out
right. The attached patch fixes it by moving code around:

- Moved from os_mac_conv.c to mac_gui.c and made static to that file:

   - mac_utf16_to_enc
   - mac_enc_to_utf16
   - mac_enc_to_cfstring
   - mac_utf16_to_utf8
   - mac_utf8_to_utf16

- A chunk of code from option.c has also been moved to os_mac_conv.c
   as 'mac_lang_init()'.

- And a preprocessor conditional in globals.h was changed so X headers
   aren't expected when they aren't available.

I thought it was the best of a bad bunch of options for fixing the issues.

It now compiles for me, configured with

./configure --with-features=huge --enable-pythoninterp --enable-perlinterp
--enable-rubyinterp --enable-tclinterp --enable-cscope --enable-gui=gtk2

It would be good to have this or a similar fix in the official distribution.

Might this have an effect on MacVim, Bjorn, or vim-coco, Jiang (sorry if names
wrong...memory is hazy)? If so, perhaps you could suggest a better solution?

Cheers,

Ben.





--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Index: src/option.c
===================================================================
--- src/option.c        (revision 728)
+++ src/option.c        (working copy)
@@ -3267,20 +3267,7 @@
     }
 # else
 #  ifdef MACOS_CONVERT
-    if (mch_getenv((char_u *)"LANG") == NULL)
-    {
-       char    buf[20];
-       if (LocaleRefGetPartString(NULL,
-                   kLocaleLanguageMask | kLocaleLanguageVariantMask |
-                   kLocaleRegionMask | kLocaleRegionVariantMask,
-                   sizeof buf, buf) == noErr && *buf)
-       {
-           vim_setenv((char_u *)"LANG", (char_u *)buf);
-#   ifdef HAVE_LOCALE_H
-           setlocale(LC_ALL, "");
-#   endif
-       }
-    }
+    mac_lang_init();
 #  endif
 # endif
 
Index: src/proto/os_mac_conv.pro
===================================================================
--- src/proto/os_mac_conv.pro   (revision 728)
+++ src/proto/os_mac_conv.pro   (working copy)
@@ -4,8 +4,6 @@
 int enc2macroman __ARGS((char_u *from, size_t fromlen, char_u *to, int 
*tolenp, int maxtolen, char_u *rest, int *restlenp));
 void mac_conv_init __ARGS((void));
 void mac_conv_cleanup __ARGS((void));
-char_u *mac_utf16_to_enc __ARGS((UniChar *from, size_t fromLen, size_t 
*actualLen));
-UniChar *mac_enc_to_utf16 __ARGS((char_u *from, size_t fromLen, size_t 
*actualLen));
-CFStringRef mac_enc_to_cfstring __ARGS((char_u *from, size_t fromLen));
 char_u *mac_precompose_path __ARGS((char_u *decompPath, size_t decompLen, 
size_t *precompLen));
+void mac_lang_init __ARGS((void));
 /* vim: set ft=c : */
Index: src/gui_mac.c
===================================================================
--- src/gui_mac.c       (revision 728)
+++ src/gui_mac.c       (working copy)
@@ -60,6 +60,9 @@
 #ifdef MACOS_CONVERT
 # define USE_CARBONKEYHANDLER
 static EventHandlerUPP keyEventHandlerUPP = NULL;
+static char_u *mac_utf16_to_enc __ARGS((UniChar *from, size_t fromLen, size_t 
*actualLen));
+static UniChar *mac_enc_to_utf16 __ARGS((char_u *from, size_t fromLen, size_t 
*actualLen));
+static CFStringRef mac_enc_to_cfstring __ARGS((char_u *from, size_t fromLen));
 #endif
 
 
@@ -6466,5 +6469,213 @@
     RevealDataBrowserItem(dataBrowser, item, kTabsColumn,
                                                      kDataBrowserRevealOnly);
 }
+#endif // FEAT_GUI_TABLINE
 
-#endif // FEAT_GUI_TABLINE
+#if defined(MACOS_CONVERT)
+/*
+ * Conversion from UTF-16 UniChars to 'encoding'
+ */
+    static char_u *
+mac_utf16_to_enc(from, fromLen, actualLen)
+    UniChar *from;
+    size_t fromLen;
+    size_t *actualLen;
+{
+    /* Following code borrows somewhat from os_mswin.c */
+    vimconv_T  conv;
+    size_t      utf8_len;
+    char_u      *utf8_str;
+    char_u      *result = NULL;
+
+    /* Convert to utf-8 first, works better with iconv */
+    utf8_len = 0;
+    utf8_str = mac_utf16_to_utf8(from, fromLen, &utf8_len);
+
+    if (utf8_str)
+    {
+       /* We might be called before we have p_enc set up. */
+       conv.vc_type = CONV_NONE;
+
+       /* If encoding (p_enc) is any unicode, it is actually in utf-8 (vim
+        * internal unicode is always utf-8) so don't convert in such cases */
+
+       if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0)
+           convert_setup(&conv, (char_u *)"utf-8",
+                   p_enc? p_enc: (char_u *)"macroman");
+       if (conv.vc_type == CONV_NONE)
+       {
+           /* p_enc is utf-8, so we're done. */
+           result = utf8_str;
+       }
+       else
+       {
+           result = string_convert(&conv, utf8_str, (int *)&utf8_len);
+           vim_free(utf8_str);
+       }
+
+       convert_setup(&conv, NULL, NULL);
+
+       if (actualLen)
+           *actualLen = utf8_len;
+    }
+    else if (actualLen)
+       *actualLen = 0;
+
+    return result;
+}
+
+/*
+ * Conversion from 'encoding' to UTF-16 UniChars
+ */
+    static UniChar *
+mac_enc_to_utf16(from, fromLen, actualLen)
+    char_u *from;
+    size_t fromLen;
+    size_t *actualLen;
+{
+    /* Following code borrows somewhat from os_mswin.c */
+    vimconv_T  conv;
+    size_t      utf8_len;
+    char_u      *utf8_str;
+    UniChar     *result = NULL;
+    Boolean     should_free_utf8 = FALSE;
+
+    do
+    {
+       /* Use MacRoman by default, we might be called before we have p_enc
+        * set up.  Convert to utf-8 first, works better with iconv().  Does
+        * nothing if 'encoding' is "utf-8". */
+       conv.vc_type = CONV_NONE;
+       if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0 &&
+               convert_setup(&conv, p_enc ? p_enc : (char_u *)"macroman",
+                   (char_u *)"utf-8") == FAIL)
+           break;
+
+       if (conv.vc_type != CONV_NONE)
+       {
+           utf8_len = fromLen;
+           utf8_str = string_convert(&conv, from, (int *)&utf8_len);
+           should_free_utf8 = TRUE;
+       }
+       else
+       {
+           utf8_str = from;
+           utf8_len = fromLen;
+       }
+
+       if (utf8_str == NULL)
+           break;
+
+       convert_setup(&conv, NULL, NULL);
+
+       result = mac_utf8_to_utf16(utf8_str, utf8_len, actualLen);
+
+       if (should_free_utf8)
+           vim_free(utf8_str);
+       return result;
+    }
+    while (0);
+
+    if (actualLen)
+       *actualLen = 0;
+
+    return result;
+}
+
+/*
+ * Converts from UTF-16 UniChars to CFString
+ */
+    static CFStringRef
+mac_enc_to_cfstring(from, fromLen)
+    char_u  *from;
+    size_t  fromLen;
+{
+    UniChar    *utf16_str;
+    size_t     utf16_len;
+    CFStringRef        result = NULL;
+
+    utf16_str = mac_enc_to_utf16(from, fromLen, &utf16_len);
+    if (utf16_str)
+    {
+       result = CFStringCreateWithCharacters(NULL, utf16_str, 
utf16_len/sizeof(UniChar));
+       vim_free(utf16_str);
+    }
+
+    return result;
+}
+
+/*
+ * Converts from UTF-16 UniChars to precomposed UTF-8
+ */
+    static char_u *
+mac_utf16_to_utf8(from, fromLen, actualLen)
+    UniChar *from;
+    size_t fromLen;
+    size_t *actualLen;
+{
+    ByteCount          utf8_len;
+    ByteCount          inputRead;
+    char_u             *result;
+
+    if (gUTF16ToUTF8Converter)
+    {
+       result = alloc(fromLen * 6 + 1);
+       if (result && TECConvertText(gUTF16ToUTF8Converter, (ConstTextPtr)from,
+                   fromLen, &inputRead, result,
+                   (fromLen*6+1)*sizeof(char_u), &utf8_len) == noErr)
+       {
+           TECFlushText(gUTF16ToUTF8Converter, result, 
(fromLen*6+1)*sizeof(char_u), &inputRead);
+           utf8_len += inputRead;
+       }
+       else
+       {
+           vim_free(result);
+           result = NULL;
+       }
+    }
+    else
+    {
+       result = NULL;
+    }
+
+    if (actualLen)
+       *actualLen = result ? utf8_len : 0;
+
+    return result;
+}
+
+/*
+ * Converts from UTF-8 to UTF-16 UniChars
+ */
+    static UniChar *
+mac_utf8_to_utf16(from, fromLen, actualLen)
+    char_u *from;
+    size_t fromLen;
+    size_t *actualLen;
+{
+    CFStringRef  utf8_str;
+    CFRange      convertRange;
+    UniChar      *result = NULL;
+
+    utf8_str = CFStringCreateWithBytes(NULL, from, fromLen,
+           kCFStringEncodingUTF8, FALSE);
+
+    if (utf8_str == NULL) {
+       if (actualLen)
+           *actualLen = 0;
+       return NULL;
+    }
+
+    convertRange = CFRangeMake(0, CFStringGetLength(utf8_str));
+    result = (UniChar *)alloc(convertRange.length * sizeof(UniChar));
+
+    CFStringGetCharacters(utf8_str, convertRange, result);
+
+    CFRelease(utf8_str);
+
+    if (actualLen)
+       *actualLen = convertRange.length * sizeof(UniChar);
+
+    return result;
+}
+#endif // MACOS_CONVERT
Index: src/os_mac_conv.c
===================================================================
--- src/os_mac_conv.c   (revision 728)
+++ src/os_mac_conv.c   (working copy)
@@ -12,7 +12,6 @@
  * This code has been put in a separate file to avoid the conflicts that are
  * caused by including both the X11 and Carbon header files.
  */
-
 #define NO_X11_INCLUDES
 #include "vim.h"
 
@@ -317,138 +316,6 @@
 }
 
 /*
- * Conversion from UTF-16 UniChars to 'encoding'
- */
-    char_u *
-mac_utf16_to_enc(from, fromLen, actualLen)
-    UniChar *from;
-    size_t fromLen;
-    size_t *actualLen;
-{
-    /* Following code borrows somewhat from os_mswin.c */
-    vimconv_T  conv;
-    size_t      utf8_len;
-    char_u      *utf8_str;
-    char_u      *result = NULL;
-
-    /* Convert to utf-8 first, works better with iconv */
-    utf8_len = 0;
-    utf8_str = mac_utf16_to_utf8(from, fromLen, &utf8_len);
-
-    if (utf8_str)
-    {
-       /* We might be called before we have p_enc set up. */
-       conv.vc_type = CONV_NONE;
-
-       /* If encoding (p_enc) is any unicode, it is actually in utf-8 (vim
-        * internal unicode is always utf-8) so don't convert in such cases */
-
-       if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0)
-           convert_setup(&conv, (char_u *)"utf-8",
-                   p_enc? p_enc: (char_u *)"macroman");
-       if (conv.vc_type == CONV_NONE)
-       {
-           /* p_enc is utf-8, so we're done. */
-           result = utf8_str;
-       }
-       else
-       {
-           result = string_convert(&conv, utf8_str, (int *)&utf8_len);
-           vim_free(utf8_str);
-       }
-
-       convert_setup(&conv, NULL, NULL);
-
-       if (actualLen)
-           *actualLen = utf8_len;
-    }
-    else if (actualLen)
-       *actualLen = 0;
-
-    return result;
-}
-
-/*
- * Conversion from 'encoding' to UTF-16 UniChars
- */
-    UniChar *
-mac_enc_to_utf16(from, fromLen, actualLen)
-    char_u *from;
-    size_t fromLen;
-    size_t *actualLen;
-{
-    /* Following code borrows somewhat from os_mswin.c */
-    vimconv_T  conv;
-    size_t      utf8_len;
-    char_u      *utf8_str;
-    UniChar     *result = NULL;
-    Boolean     should_free_utf8 = FALSE;
-
-    do
-    {
-       /* Use MacRoman by default, we might be called before we have p_enc
-        * set up.  Convert to utf-8 first, works better with iconv().  Does
-        * nothing if 'encoding' is "utf-8". */
-       conv.vc_type = CONV_NONE;
-       if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0 &&
-               convert_setup(&conv, p_enc ? p_enc : (char_u *)"macroman",
-                   (char_u *)"utf-8") == FAIL)
-           break;
-
-       if (conv.vc_type != CONV_NONE)
-       {
-           utf8_len = fromLen;
-           utf8_str = string_convert(&conv, from, (int *)&utf8_len);
-           should_free_utf8 = TRUE;
-       }
-       else
-       {
-           utf8_str = from;
-           utf8_len = fromLen;
-       }
-
-       if (utf8_str == NULL)
-           break;
-
-       convert_setup(&conv, NULL, NULL);
-
-       result = mac_utf8_to_utf16(utf8_str, utf8_len, actualLen);
-
-       if (should_free_utf8)
-           vim_free(utf8_str);
-       return result;
-    }
-    while (0);
-
-    if (actualLen)
-       *actualLen = 0;
-
-    return result;
-}
-
-/*
- * Converts from UTF-16 UniChars to CFString
- */
-    CFStringRef
-mac_enc_to_cfstring(from, fromLen)
-    char_u  *from;
-    size_t  fromLen;
-{
-    UniChar    *utf16_str;
-    size_t     utf16_len;
-    CFStringRef        result = NULL;
-
-    utf16_str = mac_enc_to_utf16(from, fromLen, &utf16_len);
-    if (utf16_str)
-    {
-       result = CFStringCreateWithCharacters(NULL, utf16_str, 
utf16_len/sizeof(UniChar));
-       vim_free(utf16_str);
-    }
-
-    return result;
-}
-
-/*
  * Converts a decomposed HFS+ UTF-8 path to precomposed UTF-8
  */
     char_u *
@@ -482,77 +349,24 @@
 }
 
 /*
- * Converts from UTF-16 UniChars to precomposed UTF-8
+ * Sets LANG environment variable in Vim from Mac locale
  */
-    static char_u *
-mac_utf16_to_utf8(from, fromLen, actualLen)
-    UniChar *from;
-    size_t fromLen;
-    size_t *actualLen;
-{
-    ByteCount          utf8_len;
-    ByteCount          inputRead;
-    char_u             *result;
-
-    if (gUTF16ToUTF8Converter)
+    void
+mac_lang_init() {
+    if (mch_getenv((char_u *)"LANG") == NULL)
     {
-       result = alloc(fromLen * 6 + 1);
-       if (result && TECConvertText(gUTF16ToUTF8Converter, (ConstTextPtr)from,
-                   fromLen, &inputRead, result,
-                   (fromLen*6+1)*sizeof(char_u), &utf8_len) == noErr)
+       char    buf[20];
+       if (LocaleRefGetPartString(NULL,
+                   kLocaleLanguageMask | kLocaleLanguageVariantMask |
+                   kLocaleRegionMask | kLocaleRegionVariantMask,
+                   sizeof buf, buf) == noErr && *buf)
        {
-           TECFlushText(gUTF16ToUTF8Converter, result, 
(fromLen*6+1)*sizeof(char_u), &inputRead);
-           utf8_len += inputRead;
+           vim_setenv((char_u *)"LANG", (char_u *)buf);
+#   ifdef HAVE_LOCALE_H
+           setlocale(LC_ALL, "");
+#   endif
        }
-       else
-       {
-           vim_free(result);
-           result = NULL;
-       }
     }
-    else
-    {
-       result = NULL;
-    }
-
-    if (actualLen)
-       *actualLen = result ? utf8_len : 0;
-
-    return result;
 }
 
-/*
- * Converts from UTF-8 to UTF-16 UniChars
- */
-    static UniChar *
-mac_utf8_to_utf16(from, fromLen, actualLen)
-    char_u *from;
-    size_t fromLen;
-    size_t *actualLen;
-{
-    CFStringRef  utf8_str;
-    CFRange      convertRange;
-    UniChar      *result = NULL;
-
-    utf8_str = CFStringCreateWithBytes(NULL, from, fromLen,
-           kCFStringEncodingUTF8, FALSE);
-
-    if (utf8_str == NULL) {
-       if (actualLen)
-           *actualLen = 0;
-       return NULL;
-    }
-
-    convertRange = CFRangeMake(0, CFStringGetLength(utf8_str));
-    result = (UniChar *)alloc(convertRange.length * sizeof(UniChar));
-
-    CFStringGetCharacters(utf8_str, convertRange, result);
-
-    CFRelease(utf8_str);
-
-    if (actualLen)
-       *actualLen = convertRange.length * sizeof(UniChar);
-
-    return result;
-}
 #endif /* MACOS_CONVERT */
Index: src/globals.h
===================================================================
--- src/globals.h       (revision 728)
+++ src/globals.h       (working copy)
@@ -1172,7 +1172,7 @@
 EXTERN int     no_hlsearch INIT(= FALSE);
 #endif
 
-#ifdef FEAT_BEVAL
+#if defined(FEAT_BEVAL) && defined(FEAT_X11)
 EXTERN BalloonEval     *balloonEval INIT(= NULL);
 # if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
 EXTERN int bevalServers INIT(= 0);

Raspunde prin e-mail lui