qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs buffer.c qe.h x11.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs buffer.c qe.h x11.c
Date: Fri, 07 Feb 2014 15:56:23 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/02/07 15:56:23

Modified files:
        .              : buffer.c qe.h x11.c 

Log message:
        improve x11 clipboard support
        
        * add eb_get_content_size() to compute size of buffer contents encoded 
in utf8
        * simplify selection_send()

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.71&r2=1.72
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.137&r2=1.138
http://cvs.savannah.gnu.org/viewcvs/qemacs/x11.c?cvsroot=qemacs&r1=1.33&r2=1.34

Patches:
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -b -r1.71 -r1.72
--- buffer.c    5 Feb 2014 00:56:48 -0000       1.71
+++ buffer.c    7 Feb 2014 15:56:15 -0000       1.72
@@ -1912,13 +1912,29 @@
         out = buf_init(&outbuf, buf, buf_size);
         for (offset = 0; offset < b->total_size;) {
             c = eb_nextc(b, offset, &offset);
-            if (!buf_putc_utf8(out, c))
-                break;
+            buf_putc_utf8(out, c);
         }
         return out->len;
     }
 }
 
+/* Compute the size of the contents of a buffer encoded in utf8 */
+int eb_get_content_size(EditBuffer *b)
+{
+    if (b->charset == &charset_utf8 && b->eol_type == EOL_UNIX) {
+        return b->total_size;
+    } else {
+        int c, offset, size;
+        char buf[MAX_CHAR_BYTES];
+
+        for (offset = size = 0; offset < b->total_size;) {
+            c = eb_nextc(b, offset, &offset);
+            size += utf8_encode(buf, c);
+        }
+        return size;
+    }
+}
+
 /* Insert 'size' bytes of 'src' buffer from position 'src_offset' into
  * buffer 'dest' at offset 'dest_offset'. 'src' MUST BE DIFFERENT from
  * 'dest'. Charset converson between source and destination buffer is

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.137
retrieving revision 1.138
diff -u -b -r1.137 -r1.138
--- qe.h        7 Feb 2014 07:38:30 -0000       1.137
+++ qe.h        7 Feb 2014 15:56:17 -0000       1.138
@@ -922,6 +922,7 @@
 int eb_match_istr(EditBuffer *b, int offset, const char *str, int *offsetp);
 int eb_printf(EditBuffer *b, const char *fmt, ...) __attr_printf(2,3);
 void eb_line_pad(EditBuffer *b, int n);
+int eb_get_content_size(EditBuffer *b);
 int eb_get_contents(EditBuffer *b, char *buf, int buf_size);
 int eb_insert_buffer_convert(EditBuffer *dest, int dest_offset,
                              EditBuffer *src, int src_offset,

Index: x11.c
===================================================================
RCS file: /sources/qemacs/qemacs/x11.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- x11.c       7 Feb 2014 07:54:27 -0000       1.33
+++ x11.c       7 Feb 2014 15:56:20 -0000       1.34
@@ -1171,9 +1171,11 @@
                         xa_targets, 8*sizeof(target_list[0]), PropModeReplace,
                         (unsigned char *)target_list,
                         countof(target_list));
-    } else if (rq->target == XA_STRING) {
-        /* get qemacs yank buffer */
+    } else
+    if (rq->target == XA_STRING) {
+        /* XXX: charset is ignored! */
 
+        /* get qemacs yank buffer */
         b = qs->yank_buffers[qs->yank_current];
         if (!b)
             return;
@@ -1190,43 +1192,19 @@
     if (rq->target == xa_formats[0]
     ||  rq->target == xa_formats[1]
     ||  rq->target == xa_formats[2]) {
-        int len;
-        /* get qemacs yank buffer */
+        int len, size;
 
+        /* get qemacs yank buffer */
         b = qs->yank_buffers[qs->yank_current];
         if (!b)
             return;
-        buf = qe_malloc_array(unsigned char, b->total_size);
-        if (!buf)
-            return;
-        eb_read(b, 0, buf, b->total_size);
-        len = b->total_size;
-
-        /* if not UTF-8 we must convert to it */
-        if (!(b->flags & BF_UTF8)) {
-            struct CharsetDecodeState st;
-            unsigned char *utf_buf, *p;
 
-            utf_buf = qe_malloc_array(unsigned char, b->total_size * 6);
-            if (!utf_buf) {
-                qe_free(&buf);
+        /* Get buffer contents encoded in utf-8-unix */
+        size = eb_get_content_size(b) + 1;
+        buf = qe_malloc_array(unsigned char, size);
+        if (!buf)
                 return;
-            }
-
-            charset_decode_init(&st, b->charset, b->eol_type);
-            st.p = buf;
-            p = utf_buf;
-            for (;;) {
-                int c = st.decode_func(&st);
-                if (c == 0)
-                    break;
-                p += utf8_encode((char *)p, c);
-            }
-
-            qe_free(&buf);
-            len = p - utf_buf;
-            buf = utf_buf;
-        }
+        len = eb_get_contents(b, (char *)buf, size);
 
         XChangeProperty(display, rq->requestor, rq->property,
                         rq->target, 8, PropModeReplace,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]