back to my original patch, providing UTF8_STRING to
ui.c and gui_gtk_x11.c when FEAT_MBYTE is on, I have
gotten vim from cvs and applied the changes such that
they wont break a non- FEAT_MBYTE system.

the latest is at:
http://members.telocity.com/~seer26/UTF8_STRING.patch

I dont know if anybody else besides me has tested it
whatsoever. It works fine for me. if there is
anything else I should do to it, let me know.
Index: src/ui.c
===================================================================
RCS file: /cvsroot/vim/vim/src/ui.c,v
retrieving revision 1.46
diff -u -u -r1.46 ui.c
--- src/ui.c    29 Apr 2002 14:00:38 -0000      1.46
+++ src/ui.c    5 Sep 2002 21:18:19 -0000
@@ -1822,6 +1822,12 @@
 }
 
 static Atom    vim_atom;       /* Vim's own special selection format */
+#ifdef FEAT_MBYTE
+static Atom     utf8_string_atom;
+#define NUM_VIM_CB_ENC_TYPES 5
+#else
+#define NUM_VIM_CB_ENC_TYPES 4
+#endif
 static Atom    compound_text_atom;
 static Atom    text_atom;
 static Atom    targets_atom;
@@ -1831,6 +1837,9 @@
     Display    *dpy;
 {
     vim_atom          = XInternAtom(dpy, VIM_ATOM_NAME,   False);
+#ifdef FEAT_MBYTE
+    utf8_string_atom   = XInternAtom(dpy, "UTF8_STRING",   False);
+#endif
     compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False);
     text_atom         = XInternAtom(dpy, "TEXT",          False);
     targets_atom       = XInternAtom(dpy, "TARGETS",       False);
@@ -1881,6 +1890,32 @@
        motion_type = *p++;
        len--;
     }
+#ifdef FEAT_MBYTE
+    else if (*type == utf8_string_atom)
+    {
+       /*convert "utf-8" to "p_enc"*/
+       vimconv_T cvrt;
+       
+# ifdef USE_ICONV
+       cvrt.vc_fd = (iconv_t)-1;
+# endif
+       convert_setup(&cvrt,"utf-8",p_enc);
+
+       if (cvrt.vc_type != CONV_NONE)
+       {
+           int temp;
+
+           p = string_convert(&cvrt, p, &temp);
+           len = (long_u)temp;
+           if(!p)
+           {
+               *(int *)success = FALSE;
+               return;
+           }
+       }
+       convert_setup(&cvrt, (char_u *)"", (char_u *)"");
+    }
+#endif
     else if (*type == compound_text_atom || (
 #ifdef FEAT_MBYTE
                enc_dbcs != 0 &&
@@ -1927,13 +1962,19 @@
     int                nbytes = 0;
     char_u     *buffer;
 
-    for (i = 0; i < 4; i++)
+    for (i = 0; i < NUM_VIM_CB_ENC_TYPES; i++)
     {
        switch (i)
        {
            case 0:  type = vim_atom;   break;
+#ifdef FEAT_MBYTE
+           case 1:  type = utf8_string_atom;   break;
+           case 2:  type = compound_text_atom; break;
+           case 3:  type = text_atom;  break;
+#else
            case 1:  type = compound_text_atom; break;
            case 2:  type = text_atom;  break;
+#endif
            default: type = XA_STRING;
        }
        XtGetSelectionValue(myShell, cbd->sel_atom, type,
@@ -2007,7 +2048,7 @@
     {
        Atom *array;
 
-       if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 5))) == NULL)
+       if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 
+(NUM_VIM_CB_ENC_TYPES+1)))) == NULL)
            return False;
        *value = (XtPointer)array;
        array[0] = XA_STRING;
@@ -2015,6 +2056,9 @@
        array[2] = vim_atom;
        array[3] = text_atom;
        array[4] = compound_text_atom;
+#ifdef FEAT_MBYTE
+        array[5] = utf8_string_atom;
+#endif
        *type = XA_ATOM;
        /* This used to be: *format = sizeof(Atom) * 8; but that caused
         * crashes on 64 bit machines. (Peter Derr) */
@@ -2026,7 +2070,11 @@
     if (       *target != XA_STRING
            && *target != vim_atom
            && *target != text_atom
-           && *target != compound_text_atom)
+           && *target != compound_text_atom
+#ifdef FEAT_MBYTE
+            && *target != utf8_string_atom
+#endif
+           )
        return False;
 
     clip_get_selection(cbd);
@@ -2034,46 +2082,80 @@
     if (motion_type < 0)
        return False;
 
-    /* For our own format, the first byte contains the motion type */
-    if (*target == vim_atom)
-       (*length)++;
-
-    *value = XtMalloc((Cardinal)*length);
-    result = (char_u *)*value;
-    if (result == NULL)
+#ifdef FEAT_MBYTE
+    if (*target == utf8_string_atom)
     {
-       vim_free(string);
-       return False;
-    }
+       /*convert "p_enc" to "utf-8" */
+       vimconv_T cvrt;
+       
+# ifdef USE_ICONV
+       cvrt.vc_fd = (iconv_t)-1;
+# endif
+       convert_setup(&cvrt,p_enc,"utf-8");
 
-    if (*target == XA_STRING)
-    {
-       mch_memmove(result, string, (size_t)(*length));
-       *type = XA_STRING;
-    }
-    else if (*target == compound_text_atom
-           || *target == text_atom)
-    {
-       XTextProperty   text_prop;
-       char            *string_nt = (char *)alloc((unsigned)*length + 1);
+       if (cvrt.vc_type == CONV_NONE)
+       {
+           *value=(XtPointer)string;
+           string=NULL;
+       }
+       else
+       {
+           int temp = (int)length;
+           *value = (XtPointer)string_convert(&cvrt, string, &temp);
+           *length = (long_u)temp;
+       }
+
+       *type = utf8_string_atom;
+       convert_setup(&cvrt, (char_u *)"", (char_u *)"");
 
-       /* create NUL terminated string which XmbTextListToTextProperty wants */
-       mch_memmove(string_nt, string, (size_t)*length);
-       string_nt[*length] = NUL;
-       XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, 1,
-                                             XCompoundTextStyle, &text_prop);
-       vim_free(string_nt);
-       XtFree(*value);                 /* replace with COMPOUND text */
-       *value = (XtPointer)(text_prop.value);  /*    from plain text */
-       *length = text_prop.nitems;
-       *type = compound_text_atom;
+       if(!*value)
+           return False;
     }
     else
+#endif
     {
-       result[0] = motion_type;
-       mch_memmove(result + 1, string, (size_t)(*length - 1));
-       *type = vim_atom;
+       /* For our own format, the first byte contains the motion type */
+       if (*target == vim_atom)
+           (*length)++;
+
+       *value = XtMalloc((Cardinal)*length);
+       result = (char_u *)*value;
+       if (result == NULL)
+       {
+           vim_free(string);
+           return False;
+       }
+
+       if (*target == XA_STRING)
+       {
+           mch_memmove(result, string, (size_t)(*length));
+           *type = XA_STRING;
+       }
+       else if (*target == compound_text_atom
+               || *target == text_atom)
+       {
+           XTextProperty       text_prop;
+           char                *string_nt = (char *)alloc((unsigned)*length + 1);
+
+           /* create NUL terminated string which XmbTextListToTextProperty wants */
+           mch_memmove(string_nt, string, (size_t)*length);
+           string_nt[*length] = NUL;
+           XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, 1,
+                                                 XCompoundTextStyle, &text_prop);
+           vim_free(string_nt);
+           XtFree(*value);                     /* replace with COMPOUND text */
+           *value = (XtPointer)(text_prop.value);      /*    from plain text */
+           *length = text_prop.nitems;
+           *type = compound_text_atom;
+       }
+       else
+       {
+           result[0] = motion_type;
+           mch_memmove(result + 1, string, (size_t)(*length - 1));
+           *type = vim_atom;
+       }
     }
+
     *format = 8;           /* 8 bits per char */
     vim_free(string);
     return True;
Index: src/gui_gtk_x11.c
===================================================================
RCS file: /cvsroot/vim/vim/src/gui_gtk_x11.c,v
retrieving revision 1.63
diff -u -u -r1.63 gui_gtk_x11.c
--- src/gui_gtk_x11.c   3 Aug 2002 17:15:15 -0000       1.63
+++ src/gui_gtk_x11.c   5 Sep 2002 21:18:31 -0000
@@ -84,6 +84,9 @@
     SELECTION_TEXT,
     SELECTION_COMPOUND_TEXT,
     SELECTION_VIM
+#ifdef FEAT_MBYTE
+    ,SELECTION_UTF8_STRING
+#endif
 };
 
 /*
@@ -133,6 +136,9 @@
 static GdkAtom compound_text_atom = GDK_NONE;
 static GdkAtom text_atom = GDK_NONE;
 static GdkAtom vim_atom = GDK_NONE;    /* Vim's own special selection format */
+#ifdef FEAT_MBYTE
+static GdkAtom utf8_string_atom = GDK_NONE;
+#endif
 
 /*
  * Keycodes recognized by vim.
@@ -941,6 +947,40 @@
        g_string_free(str, FALSE);
        free_p = TRUE;
     }
+#ifdef FEAT_MBYTE
+    else if (data->type == utf8_string_atom)
+    {
+       /*convert "utf-8" to "p_enc"*/
+       vimconv_T cvrt;
+       
+# ifdef USE_ICONV
+       cvrt.vc_fd = (iconv_t)-1;
+# endif
+       convert_setup(&cvrt,"utf-8",p_enc);
+
+       if (cvrt.vc_type == CONV_NONE)
+       {
+           p = (char_u *)data->data;
+           len = data->length;
+       }
+       else
+       {
+           int temp;
+
+           p = string_convert(&cvrt, (char_u *)data->data, &temp);
+           len = (long_u)temp;
+           if(!p)
+           {
+               received_selection = RS_FAIL;
+               if (gtk_main_level() > 0)
+                   gtk_main_quit();
+               return;
+           }
+           free_p = TRUE;
+       }
+       convert_setup(&cvrt, (char_u *)"", (char_u *)"");
+    }
+#endif
     else
     {
        p = (char_u *)data->data;
@@ -990,6 +1030,9 @@
 
     if (info != (guint)SELECTION_STRING
            && info != (guint)SELECTION_VIM
+#ifdef FEAT_MBYTE
+           && info != (guint)SELECTION_UTF8_STRING
+#endif
            && info != (guint)SELECTION_COMPOUND_TEXT
            && info != (guint)SELECTION_TEXT)
        return;
@@ -1000,47 +1043,81 @@
     if (motion_type < 0)
        return;
 
-    /* For our own format, the first byte contains the motion type */
-    if (info == (guint)SELECTION_VIM)
-       length++;
-
-    result = lalloc((long_u)(2 * length), FALSE);
-    if (result == NULL)
+#ifdef FEAT_MBYTE
+    if( info == (guint)SELECTION_UTF8_STRING)
     {
-       vim_free(string);
-       return;
-    }
+       /*convert "p_enc" to "utf-8" */
+       vimconv_T cvrt;
+       
+# ifdef USE_ICONV
+       cvrt.vc_fd = (iconv_t)-1;
+# endif
+       convert_setup(&cvrt,p_enc,"utf-8");
 
-    if (info == (guint)SELECTION_VIM)
-    {
-       result[0] = motion_type;
-       mch_memmove(result + 1, string, (size_t)(length - 1));
-       type = vim_atom;
-    }
-    else if (info == (guint)SELECTION_COMPOUND_TEXT
-                                            || info == (guint)SELECTION_TEXT)
-    {
-       char *str;
-       gint format, new_len;
-
-       vim_free(result);
-       str = g_new(char, length + 1);
-       mch_memmove(str, string, (size_t) length);
-       vim_free(string);
-       str[length] = '\0';
-       gdk_string_to_compound_text(str, &type, &format, &result, &new_len);
-       g_free(str);
-       selection_data->type = type;
-       selection_data->format = format;
-       gtk_selection_data_set(selection_data, type, format, result, new_len);
-       gdk_free_compound_text(result);
-       return;
+       if (cvrt.vc_type == CONV_NONE)
+       {
+           result=string;
+           string=NULL;
+       }
+       else
+       {
+           int temp = (int)length;
+           result = string_convert(&cvrt, string, &temp);
+           length = (long_u)temp;
+       }
+
+       type = utf8_string_atom;
+       convert_setup(&cvrt, (char_u *)"", (char_u *)"");
+
+       if(!result)
+           return;
     }
     else
+#endif
     {
-       mch_memmove(result, string, (size_t)length);
-       type = GDK_TARGET_STRING;
+       /* For our own format, the first byte contains the motion type */
+       if (info == (guint)SELECTION_VIM)
+           length++;
+
+       result = lalloc((long_u)(2 * length), FALSE);
+       if (result == NULL)
+       {
+           vim_free(string);
+           return;
+       }
+
+       if (info == (guint)SELECTION_VIM)
+       {
+           result[0] = motion_type;
+           mch_memmove(result + 1, string, (size_t)(length - 1));
+           type = vim_atom;
+       }
+       else if (info == (guint)SELECTION_COMPOUND_TEXT
+                                                || info == (guint)SELECTION_TEXT)
+       {
+           char *str;
+           gint format, new_len;
+
+           vim_free(result);
+           str = g_new(char, length + 1);
+           mch_memmove(str, string, (size_t) length);
+           vim_free(string);
+           str[length] = '\0';
+           gdk_string_to_compound_text(str, &type, &format, &result, &new_len);
+           g_free(str);
+           selection_data->type = type;
+           selection_data->format = format;
+           gtk_selection_data_set(selection_data, type, format, result, new_len);
+           gdk_free_compound_text(result);
+           return;
+       }
+       else
+       {
+           mch_memmove(result, string, (size_t)length);
+           type = GDK_TARGET_STRING;
+       }
     }
+
     selection_data->type = selection_data->target;
     selection_data->format = 8;        /* 8 bits per char */
 
@@ -1787,6 +1864,9 @@
 
 static const GtkTargetEntry primary_targets[] = {
     {VIM_ATOM_NAME,   0, SELECTION_VIM},
+#ifdef FEAT_MBYTE
+    {"UTF8_STRING", 0, SELECTION_UTF8_STRING},
+#endif
     {"COMPOUND_TEXT", 0, SELECTION_COMPOUND_TEXT},
     {"TEXT",         0, SELECTION_TEXT},
     {"STRING",       0, SELECTION_STRING}
@@ -1812,6 +1892,9 @@
     /* Initialise atoms */
     compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);
     text_atom = gdk_atom_intern("TEXT", FALSE);
+#ifdef FEAT_MBYTE
+    utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);
+#endif
 
     /* Set default foreground and background colors. */
     gui.norm_pixel = gui.def_norm_pixel;
@@ -3525,6 +3608,19 @@
     while (received_selection == RS_NONE)
        gtk_main();             /* wait for selection_received_event */
 
+#ifdef FEAT_MBYTE
+    //Lets use UTF8_STRING if available!!
+    if (received_selection == RS_FAIL)
+    {
+       /* Now try to get it out of the usual string selection. */
+       received_selection = RS_NONE;
+       (void)gtk_selection_convert(gui.drawarea, cbd->gtk_sel_atom,
+                                   gdk_atom_intern("UTF8_STRING", FALSE),
+                                   (guint32)GDK_CURRENT_TIME);
+       while (received_selection == RS_NONE)
+           gtk_main();         /* wait for selection_received_event */
+    }
+#endif
     if (received_selection == RS_FAIL)
     {
        /* Now try to get it out of the usual string selection. */

Reply via email to