qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs buffer.c hex.c qe.h charset.c qe.c shell.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs buffer.c hex.c qe.h charset.c qe.c shell.c
Date: Tue, 04 Feb 2014 22:47:31 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/02/04 22:47:31

Modified files:
        .              : buffer.c hex.c qe.h charset.c qe.c shell.c 

Log message:
        replace unicode_to_charset with eb_encode_uchar
        
        * prepare support for eol_type support by making char encoding buffer 
specific
        * fix small bugs and unsafe cases.
        * fix bug in eb_goto_pos for EBCDIC charsets

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.69&r2=1.70
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.134&r2=1.135
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.142&r2=1.143
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.82&r2=1.83

Patches:
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -b -r1.69 -r1.70
--- buffer.c    31 Jan 2014 14:50:13 -0000      1.69
+++ buffer.c    4 Feb 2014 22:47:31 -0000       1.70
@@ -1115,6 +1115,8 @@
     b->flags &= ~BF_UTF8;
     if (charset == &charset_utf8)
         b->flags |= BF_UTF8;
+
+    if (charset)
     charset_decode_init(&b->charset_state, charset);
 
     b->char_bytes = 1;
@@ -1266,7 +1268,7 @@
 int eb_goto_pos(EditBuffer *b, int line1, int col1)
 {
     Page *p, *p_end;
-    int line2, col2, line, col, offset, offset1, nl;
+    int line2, col2, line, col, offset, offset1;
 
     line = 0;
     col = 0;
@@ -1293,8 +1295,7 @@
                 line = line1;
                 col = 0;
             }
-            nl = b->charset->eol_char;
-            while (col < col1 && eb_nextc(b, offset, &offset1) != nl) {
+            while (col < col1 && eb_nextc(b, offset, &offset1) != '\n') {
                 col++;
                 offset = offset1;
             }
@@ -1715,6 +1716,24 @@
     eb_set_buffer_name(b, get_basename(filename));
 }
 
+/* Encode unicode character according to buffer charset */
+/* Return number of bytes of conversion */
+/* the function uses '?' to indicate that no match could be found in
+   buffer charset */
+int eb_encode_uchar(EditBuffer *b, char *buf, unsigned int c)
+{
+    QECharset *charset = b->charset;
+    u8 *q = (u8 *)buf;
+
+    q = charset->encode_func(charset, q, c);
+    if (!q) {
+        q = (u8 *)buf;
+        *q++ = '?';
+    }
+    *q = '\0';
+    return q - (u8 *)buf;
+}
+
 /* Insert unicode character according to buffer encoding */
 /* Return number of bytes inserted */
 int eb_insert_uchar(EditBuffer *b, int offset, int c)
@@ -1722,7 +1741,7 @@
     char buf[MAX_CHAR_BYTES];
     int len;
 
-    len = unicode_to_charset(buf, c, b->charset);
+    len = eb_encode_uchar(b, buf, c);
     return eb_insert(b, offset, buf, len);
 }
 
@@ -1740,7 +1759,7 @@
         size = size1 = 0;
         while (buf < bufend) {
             int c = utf8_decode(&buf);
-            int clen = unicode_to_charset(buf1 + size1, c, b->charset);
+            int clen = eb_encode_uchar(b, buf1 + size1, c);
             size1 += clen;
             if (size1 > ssizeof(buf) - MAX_CHAR_BYTES || buf >= bufend) {
                 size += eb_insert(b, offset + size, buf1, size1);
@@ -1904,7 +1923,7 @@
         for (offset = src_offset; offset < offset_max;) {
             char buf[MAX_CHAR_BYTES];
             int c = eb_nextc(src, offset, &offset);
-            int len = unicode_to_charset(buf, c, b->charset);
+            int len = eb_encode_uchar(b, buf, c);
             b->cur_style = src->cur_style;
             size += eb_insert(b, offset1 + size, buf, len);
         }

Index: hex.c
===================================================================
RCS file: /sources/qemacs/qemacs/hex.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- hex.c       31 Jan 2014 14:50:56 -0000      1.36
+++ hex.c       4 Feb 2014 22:47:31 -0000       1.37
@@ -259,7 +259,7 @@
         if ((s->insert || offset >= s->b->total_size) && s->hex_nibble == 0) {
             ch = h << ((hsize - 1) * 4);
             if (s->unihex_mode || s->b->charset->char_size > 1) {
-                len = unicode_to_charset(buf, ch, s->b->charset);
+                len = eb_encode_uchar(s->b, buf, ch);
             } else {
                 len = 1;
                 buf[0] = ch;
@@ -279,7 +279,7 @@
             ch = (cur_ch & ~(0xf << shift)) | (h << shift);
 
             if (s->unihex_mode) {
-                len = unicode_to_charset(buf, ch, s->b->charset);
+                len = eb_encode_uchar(s->b, buf, ch);
             } else {
                 len = 1;
                 buf[0] = ch;

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -b -r1.134 -r1.135
--- qe.h        3 Feb 2014 20:03:07 -0000       1.134
+++ qe.h        4 Feb 2014 22:47:31 -0000       1.135
@@ -553,7 +553,6 @@
 u8 *encode_8bit(QECharset *charset, u8 *q, int c);
 
 int unicode_glyph_tty_width(unsigned int ucs);
-int unicode_to_charset(char *buf, unsigned int c, QECharset *charset);
 
 /* arabic.c */
 int arab_join(unsigned int *line, unsigned int *ctog, int len);
@@ -903,6 +902,7 @@
 void eb_style_callback(EditBuffer *b, void *opaque, int arg,
                        enum LogOperation op, int offset, int size);
 int eb_delete_uchar(EditBuffer *b, int offset);
+int eb_encode_uchar(EditBuffer *b, char *buf, unsigned int c);
 int eb_insert_uchar(EditBuffer *b, int offset, int c);
 int eb_insert_utf8_buf(EditBuffer *b, int offset, const char *buf, int len);
 int eb_insert_str(EditBuffer *b, int offset, const char *str);

Index: charset.c
===================================================================
RCS file: /sources/qemacs/qemacs/charset.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- charset.c   11 Jan 2014 18:58:08 -0000      1.28
+++ charset.c   4 Feb 2014 22:47:31 -0000       1.29
@@ -793,21 +793,6 @@
     return &charset_8859_1;
 }
 
-/* the function uses '?' to indicate that no match could be found in
-   current charset */
-int unicode_to_charset(char *buf, unsigned int c, QECharset *charset)
-{
-    char *q;
-
-    q = (char *)charset->encode_func(charset, (u8 *)buf, c);
-    if (!q) {
-        q = buf;
-        *q++ = '?';
-    }
-    *q = '\0';
-    return q - buf;
-}
-
 /********************************************************/
 /* 8 bit charsets */
 

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.142
retrieving revision 1.143
diff -u -b -r1.142 -r1.143
--- qe.c        3 Feb 2014 20:03:07 -0000       1.142
+++ qe.c        4 Feb 2014 22:47:31 -0000       1.143
@@ -682,8 +682,9 @@
         ch1 = qe_tolower(ch);
 
     if (ch != ch1) {
-        len = unicode_to_charset(buf, ch1, b->charset);
+        len = eb_encode_uchar(b, buf, ch1);
         eb_replace(b, offset0, *offsetp - offset0, buf, len);
+        *offsetp = offset0 + len;
     }
     return 1;
 }
@@ -713,6 +714,7 @@
 
     /* WARNING: during case change, the region offsets can change, so
        it is not so simple ! */
+    /* XXX: if last char of region changes width, offset will move */
     offset = min(s->offset, s->b->mark);
     for (;;) {
         if (offset >= max(s->offset, s->b->mark))
@@ -1279,7 +1281,8 @@
     } else
     if (((expand_ligature(g, c) && g[1] == accent)
     ||   (c != '\n' && combine_accent(g, c, accent)))
-    &&  (len = unicode_to_charset(buf, g[0], s->b->charset)) > 0) {
+    &&  (len = eb_encode_uchar(s->b, buf, g[0])) > 0) {
+        /* XXX: should bypass eb_encode_uchar to detect encoding failure */
         eb_replace(s->b, offset0, s->offset - offset0, buf, len);
         s->offset = offset0 + len;
     } else {
@@ -1303,7 +1306,7 @@
 
     cur_ch = eb_nextc(s->b, s->offset, &offset1);
     cur_len = offset1 - s->offset;
-    len = unicode_to_charset(buf, key, s->b->charset);
+    len = eb_encode_uchar(s->b, buf, key);
     insert = (s->insert || cur_ch == '\n');
 
     if (insert) {
@@ -1354,7 +1357,7 @@
                 /* then insert match */
                 for (i = 0; i < ret; i++) {
                     key = match_buf[i];
-                    len = unicode_to_charset(buf, key, s->b->charset);
+                    len = eb_encode_uchar(s->b, buf, key);
                     eb_insert(s->b, s->compose_start_offset, buf, len);
                     s->compose_start_offset += len;
                     /* should only bump s->offset if at insert point */
@@ -1875,9 +1878,9 @@
     /* slow, but simple iterative method */
     for (offset = 0; offset < b->total_size;) {
         c = eb_nextc(b, offset, &offset);
-        len = unicode_to_charset(buf, c, charset);
         b1->cur_style = b->cur_style;
-        eb_write(b1, b1->total_size, buf, len);
+        len = eb_encode_uchar(b1, buf, c);
+        eb_insert(b1, b1->total_size, buf, len);
     }
 
     /* replace current buffer with conversion */

Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -b -r1.82 -r1.83
--- shell.c     24 Jan 2014 00:46:27 -0000      1.82
+++ shell.c     4 Feb 2014 22:47:31 -0000       1.83
@@ -874,7 +874,7 @@
                             break;
                         }
                     }
-                    //len = unicode_to_charset(buf1, c, s->b->charset);
+                    //len = eb_encode_uchar(s->b, buf1, c);
                     buf1[0] = c;
                     len = 1;
                 }
@@ -1567,7 +1567,7 @@
             buf[1] = c - KEY_META(0);
             len = 2;
         } else {
-            len = unicode_to_charset(buf, c, e->b->charset);
+            len = eb_encode_uchar(e->b, buf, c);
         }
         tty_write(s, buf, len);
     } else {



reply via email to

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