mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-11 05:49:18 +03:00
* view.c (view_display_hex): Completely rewritten. Now the code
distinguishes several phases (state selection, color selection, printing) and does not mix them wildly, as the previous code did.
This commit is contained in:
parent
ba8ba542f0
commit
b7cba56d21
@ -10,6 +10,10 @@
|
|||||||
of the hex editor out of this function. Whoever wrote that
|
of the hex editor out of this function. Whoever wrote that
|
||||||
should be blamed for it, but the code has been there since the
|
should be blamed for it, but the code has been there since the
|
||||||
beginning.
|
beginning.
|
||||||
|
* view.c (view_display_hex): Completely rewritten. Now the code
|
||||||
|
distinguishes several phases (state selection, color selection,
|
||||||
|
printing) and does not mix them wildly, as the previous code
|
||||||
|
did.
|
||||||
|
|
||||||
2005-08-16 Roland Illig <roland.illig@gmx.de>
|
2005-08-16 Roland Illig <roland.illig@gmx.de>
|
||||||
|
|
||||||
|
166
src/view.c
166
src/view.c
@ -1596,10 +1596,10 @@ view_display_clean (WView *view)
|
|||||||
#define view_gotoyx(v,r,c) widget_move (v,r,c)
|
#define view_gotoyx(v,r,c) widget_move (v,r,c)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MARK_NORMAL = 0,
|
MARK_NORMAL,
|
||||||
MARK_SELECTED = 1,
|
MARK_SELECTED,
|
||||||
MARK_CURSOR = 2,
|
MARK_CURSOR,
|
||||||
MARK_CHANGED = 3
|
MARK_CHANGED
|
||||||
} mark_t;
|
} mark_t;
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
@ -1677,7 +1677,6 @@ view_display_hex (WView *view)
|
|||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
attrset (NORMAL_COLOR);
|
|
||||||
for (row = 0; get_byte (view, from) != -1 && row < height; row++) {
|
for (row = 0; get_byte (view, from) != -1 && row < height; row++) {
|
||||||
/* Print the hex offset */
|
/* Print the hex offset */
|
||||||
attrset (MARKED_COLOR);
|
attrset (MARKED_COLOR);
|
||||||
@ -1687,112 +1686,99 @@ view_display_hex (WView *view)
|
|||||||
attrset (NORMAL_COLOR);
|
attrset (NORMAL_COLOR);
|
||||||
|
|
||||||
col = hex_start;
|
col = hex_start;
|
||||||
/* Each hex number is two digits */
|
for (bytes = 0; bytes < view->bytes_per_line; bytes++, from++) {
|
||||||
hex_buff[2] = '\0';
|
|
||||||
for (bytes = 0;
|
if ((c = get_byte (view, from)) == -1)
|
||||||
bytes < view->bytes_per_line
|
break;
|
||||||
&& (c = get_byte (view, from)) != -1;
|
|
||||||
bytes++, from++) {
|
/* Save the cursor position for view_place_cursor() */
|
||||||
/* Display and mark changed bytes */
|
if (from == view->hex_cursor && !view->hexview_in_text) {
|
||||||
if (curr && from == curr->offset) {
|
view->cursor_row = row;
|
||||||
|
view->cursor_col = col;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determine the state of the current byte */
|
||||||
|
|
||||||
|
/* The current cursor position */
|
||||||
|
if (from == view->hex_cursor) {
|
||||||
|
boldflag = MARK_CURSOR;
|
||||||
|
|
||||||
|
/* Changed bytes from the hex editor */
|
||||||
|
} else if (curr && from == curr->offset) {
|
||||||
c = curr->value;
|
c = curr->value;
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
boldflag = MARK_CHANGED;
|
boldflag = MARK_CHANGED;
|
||||||
attrset (VIEW_UNDERLINED_COLOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (view->found_len && from >= view->search_start
|
/* Marked bytes from the search functions */
|
||||||
&& from < view->search_start + view->found_len) {
|
} else if (view->search_start <= from
|
||||||
|
&& from < view->search_start + view->found_len) {
|
||||||
boldflag = MARK_SELECTED;
|
boldflag = MARK_SELECTED;
|
||||||
attrset (MARKED_COLOR);
|
|
||||||
}
|
} else {
|
||||||
/* Display the navigation cursor */
|
boldflag = MARK_NORMAL;
|
||||||
if (from == view->hex_cursor) {
|
|
||||||
if (!view->hexview_in_text) {
|
|
||||||
view->cursor_row = row;
|
|
||||||
view->cursor_col = col;
|
|
||||||
}
|
|
||||||
boldflag = MARK_CURSOR;
|
|
||||||
attrset (view->hexview_in_text
|
|
||||||
? MARKED_SELECTED_COLOR
|
|
||||||
: VIEW_UNDERLINED_COLOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print a hex number (sprintf is too slow) */
|
/* Select the color for the hex number */
|
||||||
hex_buff[0] = hex_char[(c >> 4)];
|
attrset (
|
||||||
hex_buff[1] = hex_char[c & 15];
|
boldflag == MARK_NORMAL ? NORMAL_COLOR :
|
||||||
|
boldflag == MARK_SELECTED ? MARKED_COLOR :
|
||||||
|
boldflag == MARK_CHANGED ? VIEW_UNDERLINED_COLOR :
|
||||||
|
/* boldflag == MARK_CURSOR */
|
||||||
|
view->hexview_in_text ? MARKED_SELECTED_COLOR :
|
||||||
|
VIEW_UNDERLINED_COLOR);
|
||||||
|
|
||||||
|
/* Print the hex number */
|
||||||
view_gotoyx (view, top + row, left + col);
|
view_gotoyx (view, top + row, left + col);
|
||||||
view_add_string (view, hex_buff);
|
view_add_character (view, hex_char[c / 16]);
|
||||||
col += 3;
|
view_add_character (view, hex_char[c % 16]);
|
||||||
/* Turn off the cursor or changed byte highlighting here */
|
col += 2;
|
||||||
if (boldflag == MARK_CURSOR || boldflag == MARK_CHANGED)
|
|
||||||
attrset (NORMAL_COLOR);
|
|
||||||
if ((bytes & 3) == 3 && bytes + 1 < view->bytes_per_line) {
|
|
||||||
/* Turn off the search highlighting */
|
|
||||||
if (boldflag == MARK_SELECTED
|
|
||||||
&& from == view->search_start + view->found_len - 1)
|
|
||||||
attrset (NORMAL_COLOR);
|
|
||||||
|
|
||||||
/* Hex numbers are printed in the groups of four */
|
/* Print the separator */
|
||||||
/* Groups are separated by a vline */
|
attrset (NORMAL_COLOR);
|
||||||
|
if (bytes != view->bytes_per_line - 1) {
|
||||||
view_gotoyx (view, top + row, left + col - 1);
|
|
||||||
view_add_character (view, ' ');
|
view_add_character (view, ' ');
|
||||||
view_gotoyx (view, top + row, left + col);
|
col += 1;
|
||||||
if (view->data_area.width < 80)
|
|
||||||
|
/* After every four bytes, print a group separator */
|
||||||
|
if (bytes % 4 == 3) {
|
||||||
|
if (view->data_area.width >= 80) {
|
||||||
|
view_add_one_vline ();
|
||||||
|
col += 1;
|
||||||
|
}
|
||||||
|
view_add_character (view, ' ');
|
||||||
col += 1;
|
col += 1;
|
||||||
else {
|
|
||||||
view_add_one_vline ();
|
|
||||||
col += 2;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (boldflag != MARK_NORMAL
|
/* Select the color for the character; this differs from the
|
||||||
&& from == view->search_start + view->found_len - 1)
|
* hex color when boldflag == MARK_CURSOR */
|
||||||
attrset (MARKED_COLOR);
|
attrset (
|
||||||
}
|
boldflag == MARK_NORMAL ? NORMAL_COLOR :
|
||||||
if (boldflag != MARK_NORMAL
|
boldflag == MARK_SELECTED ? MARKED_COLOR :
|
||||||
&& from < view->search_start + view->found_len - 1
|
boldflag == MARK_CHANGED ? VIEW_UNDERLINED_COLOR :
|
||||||
&& bytes != view->bytes_per_line - 1) {
|
/* boldflag == MARK_CURSOR */
|
||||||
view_gotoyx (view, top + row, left + col);
|
view->hexview_in_text ? VIEW_UNDERLINED_COLOR :
|
||||||
view_add_character (view, ' ');
|
MARKED_SELECTED_COLOR);
|
||||||
}
|
|
||||||
|
c = convert_to_display_c (c);
|
||||||
|
if (!is_printable (c))
|
||||||
|
c = '.';
|
||||||
|
|
||||||
/* Print corresponding character on the text side */
|
/* Print corresponding character on the text side */
|
||||||
view_gotoyx (view, top + row, left + text_start + bytes);
|
view_gotoyx (view, top + row, left + text_start + bytes);
|
||||||
|
|
||||||
c = convert_to_display_c (c);
|
|
||||||
|
|
||||||
if (!is_printable (c))
|
|
||||||
c = '.';
|
|
||||||
switch (boldflag) {
|
|
||||||
case MARK_NORMAL:
|
|
||||||
break;
|
|
||||||
case MARK_SELECTED:
|
|
||||||
attrset (MARKED_COLOR);
|
|
||||||
break;
|
|
||||||
case MARK_CURSOR:
|
|
||||||
if (view->hexview_in_text) {
|
|
||||||
/* Our side is active */
|
|
||||||
view->cursor_col = text_start + bytes;
|
|
||||||
view->cursor_row = row;
|
|
||||||
attrset (VIEW_UNDERLINED_COLOR);
|
|
||||||
} else {
|
|
||||||
/* Other side is active */
|
|
||||||
attrset (MARKED_SELECTED_COLOR);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MARK_CHANGED:
|
|
||||||
attrset (VIEW_UNDERLINED_COLOR);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
view_add_character (view, c);
|
view_add_character (view, c);
|
||||||
|
|
||||||
if (boldflag != MARK_NORMAL) {
|
/* Save the cursor position for view_place_cursor() */
|
||||||
boldflag = MARK_NORMAL;
|
if (from == view->hex_cursor && view->hexview_in_text) {
|
||||||
attrset (NORMAL_COLOR);
|
view->cursor_row = row;
|
||||||
|
view->cursor_col = text_start + bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Be polite to the other functions */
|
||||||
|
attrset (NORMAL_COLOR);
|
||||||
|
|
||||||
view_place_cursor (view);
|
view_place_cursor (view);
|
||||||
view->dpy_complete = (get_byte (view, from) == -1);
|
view->dpy_complete = (get_byte (view, from) == -1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user