qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs hex.c unicode_width.h unihex.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs hex.c unicode_width.h unihex.c
Date: Sun, 19 Mar 2017 11:39:25 -0400 (EDT)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        17/03/19 11:39:25

Modified files:
        .              : hex.c unicode_width.h unihex.c 

Log message:
        unihex: fix display problems
        - fix invalid widths in unicode_width.h
        - avoid setting s->offset to invalid values in hex.c
        - update s->unihex_mode on the fly if larger code-points are displayed
        - display code-points with at least 4 hex digits
        - compute default s->dump_width more accurately

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.50&r2=1.51
http://cvs.savannah.gnu.org/viewcvs/qemacs/unicode_width.h?cvsroot=qemacs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/qemacs/unihex.c?cvsroot=qemacs&r1=1.37&r2=1.38

Patches:
Index: hex.c
===================================================================
RCS file: /sources/qemacs/qemacs/hex.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- hex.c       15 Mar 2017 23:17:58 -0000      1.50
+++ hex.c       19 Mar 2017 15:39:25 -0000      1.51
@@ -221,9 +221,10 @@
 
 static void hex_move_eol(EditState *s)
 {
-    s->offset = align(s->offset, s->dump_width) + s->dump_width - 1;
-    if (s->offset > s->b->total_size)
-        s->offset = s->b->total_size;
+    int offset = align(s->offset, s->dump_width) + s->dump_width - 1;
+    if (offset > s->b->total_size)
+        offset = s->b->total_size;
+    s->offset = offset;
 }
 
 static void hex_move_left_right(EditState *s, int dir)

Index: unicode_width.h
===================================================================
RCS file: /sources/qemacs/qemacs/unicode_width.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- unicode_width.h     19 Mar 2017 13:24:06 -0000      1.2
+++ unicode_width.h     19 Mar 2017 15:39:25 -0000      1.3
@@ -742,6 +742,6 @@
                  /* E0080-E00FF  unassigned */
                  /* E0100-E01EF  Variation Selectors Supplement */
     0xE01EF, 0,  /* E01F0-EFFFF  unassigned */
-    0x10FFFF, 2, /* F0000-FFFFF  Supplementary Private Use Area-A */
+    0xFFFFFFFF, 1, /* F0000-FFFFF  Supplementary Private Use Area-A */
                  /* 100000-10FFFF  Supplementary Private Use Area-B */
-    0xFFFFFFFF, 1, /* catch all */
+                 /* catch all */

Index: unihex.c
===================================================================
RCS file: /sources/qemacs/qemacs/unihex.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- unihex.c    16 Mar 2017 09:16:31 -0000      1.37
+++ unihex.c    19 Mar 2017 15:39:25 -0000      1.38
@@ -29,13 +29,13 @@
 static int unihex_mode_init(EditState *s, EditBuffer *b, int flags)
 {
     if (s) {
-        int c, maxc, offset, max_offset;
+        int c, maxc, offset, max_offset, w;
 
         /* unihex mode is incompatible with EOL_DOS eol type */
         eb_set_charset(s->b, s->b->charset, EOL_UNIX);
 
         /* Compute max width of character in hex dump (limit to first 64K) */
-        maxc = 0xFF;
+        maxc = 0xFFFF;
         max_offset = min(65536, s->b->total_size);
         for (offset = 0; offset < max_offset;) {
             c = eb_nextc(s->b, offset, &offset);
@@ -44,8 +44,8 @@
 
         s->hex_mode = 1;
         s->hex_nibble = 0;
-        s->unihex_mode = snprintf(NULL, 0, "%x", maxc);
-        s->dump_width = 32 / s->unihex_mode;
+        s->unihex_mode = w = snprintf(NULL, 0, "%x", maxc);
+        s->dump_width = clamp((s->width - 8 - 2 - 2 - 1) / (w + 3), 8, 16);
         s->insert = 0;
         s->wrap = WRAP_TRUNCATE;
     }
@@ -54,7 +54,7 @@
 
 static int unihex_to_disp(int c)
 {
-    /* Prevent display of C1 control codes and invalid code points */
+    /* Prevent display of C0 and C1 control codes and invalid code points */
     if (c < ' ' || c == 127 || (c >= 128 && c < 160)
     ||  (c >= 0xD800 && c <= 0xDFFF) || c > 0x10FFFF)
         c = '.';
@@ -75,6 +75,7 @@
 {
     int j, len, ateof, dump_width;
     int offset1, offset2;
+    int c, maxc;
     unsigned int b;
     /* CG: array size is incorrect, should be smaller */
     unsigned int buf[LINE_MAX_SIZE];
@@ -91,13 +92,20 @@
     dump_width = min(LINE_MAX_SIZE - 1, s->dump_width);
     ateof = 0;
     len = 0;
+    maxc = 0;
     for (j = 0; j < dump_width && offset < s->b->total_size; j++) {
         pos[len] = offset;
-        buf[len] = eb_nextc(s->b, offset, &offset);
+        buf[len] = c = eb_nextc(s->b, offset, &offset);
+        if (maxc < c)
+            maxc = c;
         len++;
     }
     pos[len] = offset;
 
+    /* adjust s->unihex_mode if a larger character has been found */
+    while (s->unihex_mode < 8 && maxc >> (s->unihex_mode * 4) != 0)
+        s->unihex_mode++;
+
     ds->style = UNIHEX_STYLE_DUMP;
 
     for (j = 0; j < dump_width; j++) {
@@ -218,6 +226,7 @@
 static int unihex_mode_probe(ModeDef *mode, ModeProbeData *p)
 {
     /* XXX: should check for non 8 bit characters */
+    /* XXX: should auto-detect if content has non ASCII utf8 contents */
     return 1;
 }
 



reply via email to

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