qemacs-commit
[Top][All Lists]
Advanced

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

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


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs hex.c unihex.c
Date: Tue, 22 Apr 2008 09:04:20 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        08/04/22 09:04:20

Modified files:
        .              : hex.c unihex.c 

Log message:
        fixed issues in hex and unihex modes:
        - default to overtype mode
        - fixed "cursor not found" bug at end of file
        - simplified hex dump code
        - display both glyph offset and byte offset in unihex mode

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/qemacs/unihex.c?cvsroot=qemacs&r1=1.15&r2=1.16

Patches:
Index: hex.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/hex.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- hex.c       20 Apr 2008 12:01:34 -0000      1.26
+++ hex.c       22 Apr 2008 09:04:20 -0000      1.27
@@ -49,7 +49,7 @@
 static int hex_display(EditState *s, DisplayState *ds, int offset)
 {
     int j, len, ateof;
-    int offset1;
+    int offset1, offset2;
     unsigned char b;
 
     display_bol(ds);
@@ -57,55 +57,61 @@
     ds->style = QE_STYLE_COMMENT;
     display_printf(ds, -1, -1, "%08x ", offset);
 
-    ds->style = QE_STYLE_FUNCTION;
-
     ateof = 0;
     len = s->b->total_size - offset;
     if (len > s->disp_width)
         len = s->disp_width;
+
     if (s->mode == &hex_mode) {
+
+        ds->style = QE_STYLE_FUNCTION;
+
         for (j = 0; j < s->disp_width; j++) {
             display_char(ds, -1, -1, ' ');
             offset1 = offset + j;
+            offset2 = offset1 + 1;
             if (j < len) {
-                eb_read(s->b, offset + j, &b, 1);
-                display_printhex(ds, offset1, offset1 + 1, b, 2);
+                eb_read(s->b, offset1, &b, 1);
+                display_printhex(ds, offset1, offset2, b, 2);
             } else {
                 if (!ateof) {
                     ateof = 1;
                 } else {
-                    offset1 = -2;
+                    offset1 = offset2 = -1;
                 }
-                display_printf(ds, offset1, offset1 + 1, "  ");
+                ds->cur_hex_mode = s->hex_mode;
+                display_printf(ds, offset1, offset2, "  ");
+                ds->cur_hex_mode = 0;
             }
             if ((j & 7) == 7)
                 display_char(ds, -1, -1, ' ');
         }
         display_char(ds, -1, -1, ' ');
-        display_char(ds, -1, -1, ' ');
     }
     ds->style = 0;
 
+    display_char(ds, -1, -1, ' ');
+
     ateof = 0;
     for (j = 0; j < s->disp_width; j++) {
         offset1 = offset + j;
+        offset2 = offset1 + 1;
         if (j < len) {
-            eb_read(s->b, offset + j, &b, 1);
+            eb_read(s->b, offset1, &b, 1);
         } else {
             b = ' ';
             if (!ateof) {
                 ateof = 1;
             } else {
-                offset1 = -2;
+                offset1 = offset2 = -1;
             }
         }
-        display_char(ds, offset1, offset1 + 1, to_disp(b));
+        display_char(ds, offset1, offset2, to_disp(b));
     }
-    offset += len;
     display_eol(ds, -1, -1);
 
     if (len >= s->disp_width)
-        return offset;
+        return offset + len;
     else
         return -1;
 }
@@ -189,7 +195,7 @@
     s->hex_mode = 1;
     s->unihex_mode = 0;
     s->hex_nibble = 0;
-    //s->insert = 0;
+    s->insert = 0;
     s->wrap = WRAP_TRUNCATE;
     return 0;
 }
@@ -224,7 +230,7 @@
 static void hex_move_eol(EditState *s)
 {
     s->offset = align(s->offset, s->disp_width) + s->disp_width - 1;
-    if (s->offset >= s->b->total_size)
+    if (s->offset > s->b->total_size)
         s->offset = s->b->total_size;
 }
 
@@ -233,7 +239,8 @@
     s->offset += dir;
     if (s->offset < 0)
         s->offset = 0;
-    else if (s->offset > s->b->total_size)
+    else
+    if (s->offset > s->b->total_size)
         s->offset = s->b->total_size;
 }
 
@@ -242,7 +249,8 @@
     s->offset += dir * s->disp_width;
     if (s->offset < 0)
         s->offset = 0;
-    else if (s->offset > s->b->total_size)
+    else
+    if (s->offset > s->b->total_size)
         s->offset = s->b->total_size;
 }
 

Index: unihex.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/unihex.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- unihex.c    5 Apr 2008 18:16:30 -0000       1.15
+++ unihex.c    22 Apr 2008 09:04:20 -0000      1.16
@@ -33,11 +33,24 @@
     s->hex_mode = 1;
     s->unihex_mode = 1;
     s->hex_nibble = 0;
-    //s->insert = 0;
+    s->insert = 0;
     s->wrap = WRAP_TRUNCATE;
     return 0;
 }
 
+static int to_disp(int c)
+{
+#if 1
+    /* Do not allow characters in range 160-255 to show as graphics */
+    if ((c & 127) < ' ' || c == 127)
+        c = '.';
+#else
+    if (c < ' ' || c >= 127)
+        c = '.';
+#endif
+    return c;
+}
+
 static int unihex_backward_offset(EditState *s, int offset)
 {
     int pos;
@@ -50,25 +63,27 @@
 static int unihex_display(EditState *s, DisplayState *ds, int offset)
 {
     int j, len, ateof;
-    int offset1;
+    int offset1, offset2, charpos;
     unsigned int b;
+    /* CG: array size is incorrect, should be smaller and should clip
+     * disp_width too.
+     */
     unsigned int buf[LINE_MAX_SIZE];
     unsigned int pos[LINE_MAX_SIZE];
 
-    ateof = 0;
     display_bol(ds);
 
     ds->style = QE_STYLE_COMMENT;
-    display_printf(ds, -1, -1, "%08x ", offset);
+    charpos = eb_get_char_offset(s->b, offset);
+    display_printf(ds, -1, -1, "%08x %08x ", charpos, offset);
 
+    ateof = 0;
     len = 0;
     for (j = 0; j < s->disp_width; j++) {
         if (offset < s->b->total_size) {
-            b = eb_nextc(s->b, offset, &offset1);
             pos[len] = offset;
-            buf[len] = b;
+            buf[len] = eb_nextc(s->b, offset, &offset);
             len++;
-            offset = offset1;
         }
     }
     pos[len] = offset;
@@ -77,41 +92,49 @@
 
     for (j = 0; j < s->disp_width; j++) {
         display_char(ds, -1, -1, ' ');
+        offset1 = pos[j];
+        offset2 = pos[j + 1];
         if (j < len) {
-            display_printhex(ds, pos[j], pos[j+1], buf[j], 4);
+            display_printhex(ds, offset1, offset2, buf[j], 4);
         } else {
             if (!ateof) {
                 ateof = 1;
-                display_printf(ds, pos[j], pos[j] + 1, "    ");
+                offset2 = offset1 + 1;
             } else {
-                display_printf(ds, -1, -1, "    ");
+                offset2 = offset1 = -1;
             }
+            ds->cur_hex_mode = s->hex_mode;
+            display_printf(ds, offset1, offset2, "    ");
+            ds->cur_hex_mode = 0;
         }
         if ((j & 7) == 7)
             display_char(ds, -1, -1, ' ');
     }
+    display_char(ds, -1, -1, ' ');
+
     ds->style = 0;
 
     display_char(ds, -1, -1, ' ');
-    display_char(ds, -1, -1, ' ');
 
+    ateof = 0;
     for (j = 0; j < s->disp_width; j++) {
+        offset1 = pos[j];
+        offset2 = pos[j + 1];
         if (j < len) {
             b = buf[j];
-            if (b < ' ' || b == 127)
-                b = '.';
-            display_char(ds, pos[j], pos[j+1], b);
+            /* CG: should handle double width glyphs */
+            b = to_disp(b);
         } else {
             b = ' ';
             if (!ateof) {
                 ateof = 1;
-                display_char(ds, pos[j], pos[j] + 1, b);
+                offset2 = offset1 + 1;
             } else {
-                display_char(ds, -1, -1, b);
+                offset2 = offset1 = -1;
             }
         }
+        display_char(ds, offset1, offset2, b);
     }
-    ds->style = 0;
     display_eol(ds, -1, -1);
 
     if (len >= s->disp_width)
@@ -120,7 +143,6 @@
         return -1;
 }
 
-
 static void unihex_move_bol(EditState *s)
 {
     int pos;




reply via email to

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