[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs hex.c qe.c qe.h unihex.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs hex.c qe.c qe.h unihex.c |
Date: |
Sun, 12 Jan 2014 01:39:10 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 14/01/12 01:39:10
Modified files:
. : hex.c qe.c qe.h unihex.c
Log message:
improve unihex-mode
* determine hex dump width from max char value in buffer
* display byte offset in margin instead of char offset
* accept 0x1f in text-mode
* no longer output octal char value if not ASCII
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.116&r2=1.117
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.116&r2=1.117
http://cvs.savannah.gnu.org/viewcvs/qemacs/unihex.c?cvsroot=qemacs&r1=1.17&r2=1.18
Patches:
Index: hex.c
===================================================================
RCS file: /sources/qemacs/qemacs/hex.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- hex.c 6 Jan 2014 09:40:20 -0000 1.32
+++ hex.c 12 Jan 2014 01:39:10 -0000 1.33
@@ -197,7 +197,7 @@
{
static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
(1 << '\n') | (1 << '\r') | (1 << '\033') |
- (1 << 0x0e) | (1 << 0x0f);
+ (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
int i, c;
for (i = 0; i < size; i++) {
@@ -256,7 +256,7 @@
if (s->hex_mode) {
if (s->unihex_mode)
- hsize = 4;
+ hsize = s->unihex_mode;
else
hsize = 2;
h = to_hex(key);
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -b -r1.116 -r1.117
--- qe.c 12 Jan 2014 01:18:45 -0000 1.116
+++ qe.c 12 Jan 2014 01:39:10 -0000 1.117
@@ -1995,7 +1995,9 @@
buf_put_byte(&out, '\'');
buf_put_byte(&out, ' ');
}
- buf_printf(&out, "\\%03o %d 0x%02x ", c, c, c);
+ if (c < 0x100)
+ buf_printf(&out, "\\%03o ", c);
+ buf_printf(&out, "%d 0x%02x ", c, c);
/* Display buffer bytes if char is encoded */
off = s->offset;
@@ -2012,7 +2014,7 @@
buf_put_byte(&out, ' ');
}
eb_get_pos(s->b, &line_num, &col_num, s->offset);
- put_status(s, "%spoint=%d column=%d mark=%d size=%d region=%d",
+ put_status(s, "%spoint=%d col=%d mark=%d size=%d region=%d",
out.buf, s->offset, col_num, s->b->mark, s->b->total_size,
abs(s->offset - s->b->mark));
}
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -b -r1.116 -r1.117
--- qe.h 12 Jan 2014 01:18:45 -0000 1.116
+++ qe.h 12 Jan 2014 01:39:10 -0000 1.117
@@ -969,7 +969,7 @@
int minibuf; /* true if single line editing */
int disp_width; /* width in binary, hex and unihex modes */
int hex_mode; /* true if we are currently editing hexa */
- int unihex_mode; /* true if unihex editing (hex_mode must be true too) */
+ int unihex_mode; /* true if unihex editing (width of hex char dump) */
int hex_nibble; /* current hexa nibble */
int insert; /* insert/overtype mode */
int bidir;
Index: unihex.c
===================================================================
RCS file: /sources/qemacs/qemacs/unihex.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- unihex.c 4 Jan 2014 15:54:48 -0000 1.17
+++ unihex.c 12 Jan 2014 01:39:10 -0000 1.18
@@ -23,15 +23,24 @@
static int unihex_mode_init(EditState *s, ModeSavedData *saved_data)
{
- int ret;
+ int ret, c, maxc, offset, max_offset;
ret = text_mode_init(s, saved_data);
if (ret)
return ret;
- s->disp_width = 8;
+ /* Compute max width of character in hex dump (limit to first 64K) */
+ maxc = 0xFF;
+ max_offset = min(65536, s->b->total_size);
+ for (offset = 0; offset < max_offset;) {
+ c = eb_nextc(s->b, offset, &offset);
+ maxc = max(maxc, c);
+ }
+
+ s->unihex_mode = snprintf(NULL, 0, "%x", maxc);
+
+ s->disp_width = 32 / s->unihex_mode;
s->hex_mode = 1;
- s->unihex_mode = 1;
s->hex_nibble = 0;
s->insert = 0;
s->wrap = WRAP_TRUNCATE;
@@ -61,7 +70,7 @@
static int unihex_display(EditState *s, DisplayState *ds, int offset)
{
int j, len, ateof, disp_width;
- int offset1, offset2, charpos;
+ int offset1, offset2;
unsigned int b;
/* CG: array size is incorrect, should be smaller */
unsigned int buf[LINE_MAX_SIZE];
@@ -70,8 +79,9 @@
display_bol(ds);
ds->style = QE_STYLE_COMMENT;
- charpos = eb_get_char_offset(s->b, offset);
- display_printf(ds, -1, -1, "%08x ", charpos);
+ display_printf(ds, -1, -1, "%08x ", offset);
+ //int charpos = eb_get_char_offset(s->b, offset);
+ //display_printf(ds, -1, -1, "%08x ", charpos);
//display_printf(ds, -1, -1, "%08x %08x ", charpos, offset);
disp_width = min(LINE_MAX_SIZE - 1, s->disp_width);
@@ -91,13 +101,10 @@
offset1 = pos[j];
offset2 = pos[j + 1];
if (j < len) {
- if (buf[j] < 0x10000) {
- display_printhex(ds, offset1, offset2, buf[j], 4);
- } else {
- ds->cur_hex_mode = 1;
- display_printf(ds, offset1, offset2, "%x", buf[j]);
- ds->cur_hex_mode = 0;
- }
+ display_printhex(ds, offset1, offset2, buf[j], s->unihex_mode);
+ //ds->cur_hex_mode = 1;
+ //display_printf(ds, offset1, offset2, "%0*x", s->unihex_mode,
buf[j]);
+ //ds->cur_hex_mode = 0;
} else {
if (!ateof) {
ateof = 1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs hex.c qe.c qe.h unihex.c,
Charlie Gordon <=