static inline void print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, long end_col, struct line_s line[], char *status, int bookmarked) { struct line_s *p; int x = start_col_real; int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; int y = row + EDIT_TEXT_VERTICAL_OFFSET; int cols_to_skip = abs (x); int i; int wrap_start; int len; tty_setcolor (EDITOR_NORMAL_COLOR); if (bookmarked != 0) tty_setcolor (bookmarked); len = end_col + 1 - start_col; wrap_start = option_word_wrap_line_length + edit->start_col; if (len > 0 && edit->widget.y + y >= 0) { if (!show_right_margin || wrap_start > end_col) tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len); else if (wrap_start < 0) { tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len); } else { if (wrap_start > 0) tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start); len -= wrap_start; if (len > 0) { tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len); } } } if (option_line_state) { tty_setcolor (LINE_STATE_COLOR); for (i = 0; i < LINE_STATE_WIDTH; i++) { edit_move (x1 + i - option_line_state_width, y); if (status[i] == '\0') status[i] = ' '; tty_print_char (status[i]); } } edit_move (x1, y); p = line; i = 1; while (p->ch) { int style; unsigned int textchar; int color; if (cols_to_skip) { p++; cols_to_skip--; continue; } style = p->style & 0xFF00; textchar = p->ch; color = p->style >> 16; if (style & MOD_ABNORMAL) { /* Non-printable - use black background */ color = 0; } if (style & MOD_WHITESPACE) { if (style & MOD_MARKED) { textchar = ' '; tty_setcolor (EDITOR_MARKED_COLOR); } else { #if 0 if (color != EDITOR_NORMAL_COLOR) { textchar = ' '; tty_lowlevel_setcolor (color); } else #endif tty_setcolor (EDITOR_WHITESPACE_COLOR); } } else { if (style & MOD_BOLD) { tty_setcolor (EDITOR_BOLD_COLOR); } else if (style & MOD_MARKED) { tty_setcolor (EDITOR_MARKED_COLOR); } else { tty_lowlevel_setcolor (color); } } if (show_right_margin) { if (i > option_word_wrap_line_length + edit->start_col) tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); i++; } tty_print_anychar (textchar); p++; } }
/** * Parse, format and possibly display one visual line of text. * * Formatting starts at the given "state" (which encodes the file offset and parser and formatter's * internal state). In unwrap mode, this should point to the beginning of the paragraph with the * default state, the additional horizontal scrolling is added here. In wrap mode, this should * point to the beginning of the line, with the proper state at that point. * * In wrap mode, if a line ends in a newline, it is consumed, even if it's exactly at the right * edge. In unwrap mode, the whole remaining line, including the newline is consumed. Displaying * the next line should start at "state"'s new value, or if we displayed the bottom line then * state->offset tells the file offset to be shown in the top bar. * * If "row" is offscreen, don't actually display the line but still update "state" and return the * proper value. This is used by mcview_wrap_move_down to advance in the file. * * @param view ... * @param state the parser-formatter state machine's state, updated * @param row print to this row * @param paragraph_ended store TRUE if paragraph ended by newline or EOF, FALSE if wraps to next * line * @param linewidth store the width of the line here * @return the number of rows, that is, 0 if we were already at EOF, otherwise 1 */ static int mcview_display_line (WView * view, mcview_state_machine_t * state, int row, gboolean * paragraph_ended, off_t * linewidth) { const screen_dimen left = view->data_area.left; const screen_dimen top = view->data_area.top; const screen_dimen width = view->data_area.width; const screen_dimen height = view->data_area.height; off_t dpy_text_column = view->text_wrap_mode ? 0 : view->dpy_text_column; screen_dimen col = 0; int cs[1 + MAX_COMBINING_CHARS]; char str[(1 + MAX_COMBINING_CHARS) * UTF8_CHAR_LEN + 1]; int i, j; if (paragraph_ended != NULL) *paragraph_ended = TRUE; if (!view->text_wrap_mode && (row < 0 || row >= (int) height) && linewidth == NULL) { /* Optimization: Fast forward to the end of the line, rather than carefully * parsing and then not actually displaying it. */ off_t eol; int retval; eol = mcview_eol (view, state->offset, mcview_get_filesize (view)); retval = (eol > state->offset) ? 1 : 0; mcview_state_machine_init (state, eol); return retval; } while (TRUE) { int charwidth = 0; mcview_state_machine_t state_saved; int n; int color; state_saved = *state; n = mcview_next_combining_char_sequence (view, state, cs, 1 + MAX_COMBINING_CHARS, &color); if (n == 0) { if (linewidth != NULL) *linewidth = col; return (col > 0) ? 1 : 0; } if (view->search_start <= state->offset && state->offset < view->search_end) color = VIEW_SELECTED_COLOR; if (cs[0] == '\n') { /* New line: reset all formatting state for the next paragraph. */ mcview_state_machine_init (state, state->offset); if (linewidth != NULL) *linewidth = col; return 1; } if (mcview_is_non_spacing_mark (view, cs[0])) { /* Lonely combining character. Probably leftover after too many combining chars. Just ignore. */ continue; } /* Nonprintable, or lonely spacing mark */ if ((!mcview_isprint (view, cs[0]) || mcview_ismark (view, cs[0])) && cs[0] != '\t') cs[0] = '.'; for (i = 0; i < n; i++) charwidth += mcview_wcwidth (view, cs[i]); /* Adjust the width for TAB. It's handled below along with the normal characters, * so that it's wrapped consistently with them, and is painted with the proper * attributes (although currently it can't have a special color). */ if (cs[0] == '\t') { charwidth = option_tab_spacing - state->unwrapped_column % option_tab_spacing; state->print_lonely_combining = TRUE; } else state->print_lonely_combining = FALSE; /* In wrap mode only: We're done with this row if the character sequence wouldn't fit. * Except if at the first column, because then it wouldn't fit in the next row either. * In this extreme case let the unwrapped code below do its best to display it. */ if (view->text_wrap_mode && (off_t) col + charwidth > dpy_text_column + (off_t) width && col > 0) { *state = state_saved; if (paragraph_ended != NULL) *paragraph_ended = FALSE; if (linewidth != NULL) *linewidth = col; return 1; } /* Display, unless outside of the viewport. */ if (row >= 0 && row < (int) height) { if ((off_t) col >= dpy_text_column && (off_t) col + charwidth <= dpy_text_column + (off_t) width) { /* The combining character sequence fits entirely in the viewport. Print it. */ tty_setcolor (color); widget_move (view, top + row, left + ((off_t) col - dpy_text_column)); if (cs[0] == '\t') { for (i = 0; i < charwidth; i++) tty_print_char (' '); } else { j = 0; for (i = 0; i < n; i++) j += mcview_char_display (view, cs[i], str + j); str[j] = '\0'; /* This is probably a bug in our tty layer, but tty_print_string * normalizes the string, whereas tty_printf doesn't. Don't normalize, * since we handle combining characters ourselves correctly, it's * better if they are copy-pasted correctly. Ticket 3255. */ tty_printf ("%s", str); } } else if ((off_t) col < dpy_text_column && (off_t) col + charwidth > dpy_text_column) { /* The combining character sequence would cross the left edge of the viewport. * This cannot happen with wrap mode. Print replacement character(s), * or spaces with the correct attributes for partial Tabs. */ tty_setcolor (color); for (i = dpy_text_column; i < (off_t) col + charwidth && i < dpy_text_column + (off_t) width; i++) { widget_move (view, top + row, left + (i - dpy_text_column)); tty_print_anychar ((cs[0] == '\t') ? ' ' : PARTIAL_CJK_AT_LEFT_MARGIN); } } else if ((off_t) col < dpy_text_column + (off_t) width && (off_t) col + charwidth > dpy_text_column + (off_t) width) { /* The combining character sequence would cross the right edge of the viewport * and we're not wrapping. Print replacement character(s), * or spaces with the correct attributes for partial Tabs. */ tty_setcolor (color); for (i = col; i < dpy_text_column + (off_t) width; i++) { widget_move (view, top + row, left + (i - dpy_text_column)); tty_print_anychar ((cs[0] == '\t') ? ' ' : PARTIAL_CJK_AT_RIGHT_MARGIN); } } } col += charwidth; state->unwrapped_column += charwidth; if (!view->text_wrap_mode && (off_t) col >= dpy_text_column + (off_t) width && linewidth == NULL) { /* Optimization: Fast forward to the end of the line, rather than carefully * parsing and then not actually displaying it. */ off_t eol; eol = mcview_eol (view, state->offset, mcview_get_filesize (view)); mcview_state_machine_init (state, eol); return 1; } } }
void mcview_display_hex (mcview_t * view) { const screen_dimen top = view->data_area.top; const screen_dimen left = view->data_area.left; const screen_dimen height = view->data_area.height; const screen_dimen width = view->data_area.width; const int ngroups = view->bytes_per_line / 4; const screen_dimen text_start = 8 + 13 * ngroups + ((width < 80) ? 0 : (ngroups - 1 + 1)); /* 8 characters are used for the file offset, and every hex group * takes 13 characters. On "big" screens, the groups are separated * by an extra vertical line, and there is an extra space before the * text column. */ screen_dimen row; off_t from; int c; mark_t boldflag = MARK_NORMAL; struct hexedit_change_node *curr = view->change_list; #ifdef HAVE_CHARSET int ch = 0; #endif /* HAVE_CHARSET */ char hex_buff[10]; /* A temporary buffer for sprintf and mvwaddstr */ int bytes; /* Number of bytes already printed on the line */ mcview_display_clean (view); /* Find the first displayable changed byte */ from = view->dpy_start; while (curr && (curr->offset < from)) { curr = curr->next; } for (row = 0; mcview_get_byte (view, from, NULL) == TRUE && row < height; row++) { screen_dimen col = 0; size_t i; col = 0; /* Print the hex offset */ g_snprintf (hex_buff, sizeof (hex_buff), "%08" PRIXMAX " ", (uintmax_t) from); widget_move (view, top + row, left); tty_setcolor (VIEW_BOLD_COLOR); for (i = 0; col < width && hex_buff[i] != '\0'; i++) { tty_print_char (hex_buff[i]); /* tty_print_char(hex_buff[i]); */ col += 1; } tty_setcolor (VIEW_NORMAL_COLOR); for (bytes = 0; bytes < view->bytes_per_line; bytes++, from++) { #ifdef HAVE_CHARSET if (view->utf8) { int cw = 1; gboolean read_res = TRUE; ch = mcview_get_utf (view, from, &cw, &read_res); if (!read_res) break; /* char width is greater 0 bytes */ if (cw != 0) { int cnt; char corr_buf[UTF8_CHAR_LEN + 1]; struct hexedit_change_node *corr = curr; int res; res = g_unichar_to_utf8 (ch, (char *) corr_buf); for (cnt = 0; cnt < cw; cnt++) { if (curr != NULL && from + cnt == curr->offset) { /* replace only changed bytes in array of multibyte char */ corr_buf[cnt] = curr->value; curr = curr->next; } } corr_buf[res] = '\0'; /* Determine the state of the current multibyte char */ ch = utf8_to_int ((char *) corr_buf, &cw, &read_res); curr = corr; } } #endif /* HAVE_CHARSET */ if (!mcview_get_byte (view, from, &c)) break; /* Save the cursor position for mcview_place_cursor() */ if (from == view->hex_cursor && !view->hexview_in_text) { view->cursor_row = row; view->cursor_col = col; } /* Determine the state of the current byte */ boldflag = mcview_hex_calculate_boldflag (view, from, curr); /* Determine the value of the current byte */ if (curr != NULL && from == curr->offset) { c = curr->value; curr = curr->next; } /* Select the color for the hex number */ tty_setcolor (boldflag == MARK_NORMAL ? VIEW_NORMAL_COLOR : boldflag == MARK_SELECTED ? VIEW_BOLD_COLOR : boldflag == MARK_CHANGED ? VIEW_UNDERLINED_COLOR : /* boldflag == MARK_CURSOR */ view->hexview_in_text ? VIEW_SELECTED_COLOR : VIEW_UNDERLINED_COLOR); /* Print the hex number */ widget_move (view, top + row, left + col); if (col < width) { tty_print_char (hex_char[c / 16]); col += 1; } if (col < width) { tty_print_char (hex_char[c % 16]); col += 1; } /* Print the separator */ tty_setcolor (VIEW_NORMAL_COLOR); if (bytes != view->bytes_per_line - 1) { if (col < width) { tty_print_char (' '); col += 1; } /* After every four bytes, print a group separator */ if (bytes % 4 == 3) { if (view->data_area.width >= 80 && col < width) { tty_print_one_vline (TRUE); col += 1; } if (col < width) { tty_print_char (' '); col += 1; } } } /* Select the color for the character; this differs from the * hex color when boldflag == MARK_CURSOR */ tty_setcolor (boldflag == MARK_NORMAL ? VIEW_NORMAL_COLOR : boldflag == MARK_SELECTED ? VIEW_BOLD_COLOR : boldflag == MARK_CHANGED ? VIEW_UNDERLINED_COLOR : /* boldflag == MARK_CURSOR */ view->hexview_in_text ? VIEW_SELECTED_COLOR : MARKED_SELECTED_COLOR); #ifdef HAVE_CHARSET if (mc_global.utf8_display) { if (!view->utf8) { c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter); } if (!g_unichar_isprint (c)) c = '.'; } else if (view->utf8) ch = convert_from_utf_to_current_c (ch, view->converter); else #endif { #ifdef HAVE_CHARSET c = convert_to_display_c (c); #endif if (!is_printable (c)) c = '.'; } /* Print corresponding character on the text side */ if (text_start + bytes < width) { widget_move (view, top + row, left + text_start + bytes); #ifdef HAVE_CHARSET if (view->utf8) tty_print_anychar (ch); else #endif tty_print_char (c); } /* Save the cursor position for mcview_place_cursor() */ if (from == view->hex_cursor && view->hexview_in_text) { view->cursor_row = row; view->cursor_col = text_start + bytes; } } } /* Be polite to the other functions */ tty_setcolor (VIEW_NORMAL_COLOR); mcview_place_cursor (view); view->dpy_end = from; }
void mcview_display_nroff (mcview_t * view) { const screen_dimen left = view->data_area.left; const screen_dimen top = view->data_area.top; const screen_dimen width = view->data_area.width; const screen_dimen height = view->data_area.height; screen_dimen row, col; off_t from; int cw = 1; int c; int c_prev = 0; int c_next = 0; struct hexedit_change_node *curr = view->change_list; mcview_display_clean (view); mcview_display_ruler (view); /* Find the first displayable changed byte */ from = view->dpy_start; while (curr && (curr->offset < from)) { curr = curr->next; } tty_setcolor (NORMAL_COLOR); for (row = 0, col = 0; row < height;) { #ifdef HAVE_CHARSET if (view->utf8) { gboolean read_res = TRUE; c = mcview_get_utf (view, from, &cw, &read_res); if (!read_res) break; } else #endif { if (!mcview_get_byte (view, from, &c)) break; } from++; if (cw > 1) from += cw - 1; if (c == '\b') { if (from > 1) { #ifdef HAVE_CHARSET if (view->utf8) { gboolean read_res; c_next = mcview_get_utf (view, from, &cw, &read_res); } else #endif mcview_get_byte (view, from, &c_next); } if (g_unichar_isprint (c_prev) && g_unichar_isprint (c_next) && (c_prev == c_next || c_prev == '_' || (c_prev == '+' && c_next == 'o'))) { if (col == 0) { if (row == 0) { /* We're inside an nroff character sequence at the * beginning of the screen -- just skip the * backspace and continue with the next character. */ continue; } row--; col = width; } col--; if (c_prev == '_' && (c_next != '_' || mcview_count_backspaces (view, from + 1) == 1)) tty_setcolor (VIEW_UNDERLINED_COLOR); else tty_setcolor (VIEW_BOLD_COLOR); continue; } } if ((c == '\n') || (col >= width && view->text_wrap_mode)) { col = 0; row++; if (c == '\n' || row >= height) continue; } if (c == '\r') { mcview_get_byte_indexed (view, from, 1, &c); if (c == '\r' || c == '\n') continue; col = 0; row++; continue; } if (c == '\t') { off_t line, column; mcview_offset_to_coord (view, &line, &column, from); col += (option_tab_spacing - col % option_tab_spacing); if (view->text_wrap_mode && col >= width && width != 0) { row += col / width; col %= width; } continue; } if (view->search_start <= from && from < view->search_end) { tty_setcolor (SELECTED_COLOR); } c_prev = c; if ((off_t) col >= view->dpy_text_column && (off_t) col - view->dpy_text_column < (off_t) width) { widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column)); #ifdef HAVE_CHARSET if (mc_global.utf8_display) { if (!view->utf8) { c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter); } if (!g_unichar_isprint (c)) c = '.'; } else if (view->utf8) c = convert_from_utf_to_current_c (c, view->converter); else c = convert_to_display_c (c); #endif tty_print_anychar (c); } col++; #ifdef HAVE_CHARSET if (view->utf8) { if (g_unichar_iswide (c)) col++; else if (g_unichar_iszerowidth (c)) col--; } #endif tty_setcolor (NORMAL_COLOR); } view->dpy_end = from; }
void mcview_display_text (mcview_t * view) { const screen_dimen left = view->data_area.left; const screen_dimen top = view->data_area.top; const screen_dimen width = view->data_area.width; const screen_dimen height = view->data_area.height; screen_dimen row = 0, col = 0; off_t from; int cw = 1; int c, prev_ch = 0; gboolean last_row = TRUE; struct hexedit_change_node *curr = view->change_list; mcview_display_clean (view); mcview_display_ruler (view); /* Find the first displayable changed byte */ from = view->dpy_start; while ((curr != NULL) && (curr->offset < from)) curr = curr->next; while (TRUE) { tty_setcolor (NORMAL_COLOR); if (row >= height) break; #ifdef HAVE_CHARSET if (view->utf8) { gboolean read_res = TRUE; c = mcview_get_utf (view, from, &cw, &read_res); if (!read_res) break; } else #endif if (!mcview_get_byte (view, from, &c)) break; last_row = FALSE; from++; if (cw > 1) from += cw - 1; if (c != '\n' && prev_ch == '\r') { if (++row >= height) break; col = 0; /* tty_print_anychar ('\n'); */ } prev_ch = c; if (c == '\r') continue; if (c == '\n') { col = 0; row++; continue; } if (col >= width && view->text_wrap_mode) { col = 0; if (++row >= height) break; } if (c == '\t') { col += (option_tab_spacing - col % option_tab_spacing); if (view->text_wrap_mode && col >= width && width != 0) { row += col / width; col %= width; } continue; } if (view->search_start <= from && from < view->search_end) tty_setcolor (SELECTED_COLOR); if (((off_t) col >= view->dpy_text_column) && ((off_t) col - view->dpy_text_column < (off_t) width)) { widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column)); #ifdef HAVE_CHARSET if (mc_global.utf8_display) { if (!view->utf8) c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter); if (!g_unichar_isprint (c)) c = '.'; } else if (view->utf8) c = convert_from_utf_to_current_c (c, view->converter); else #endif { #ifdef HAVE_CHARSET c = convert_to_display_c (c); #endif if (!is_printable (c)) c = '.'; } tty_print_anychar (c); } col++; #ifdef HAVE_CHARSET if (view->utf8) { if (g_unichar_iswide (c)) col++; else if (g_unichar_iszerowidth (c)) col--; } #endif } view->dpy_end = from; if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0') { if (last_row && mcview_get_byte (view, from - 1, &c)) if (c != '\n') row--; while (++row < height) { widget_move (view, top + row, left); tty_print_string (mcview_show_eof); } } }
void mcview_display_hex (WView * view) { const screen_dimen top = view->data_area.top; const screen_dimen left = view->data_area.left; const screen_dimen height = view->data_area.height; const screen_dimen width = view->data_area.width; const int ngroups = view->bytes_per_line / 4; /* 8 characters are used for the file offset, and every hex group * takes 13 characters. Starting at width of 80 columns, the groups * are separated by an extra vertical line. Starting at width of 81, * there is an extra space before the text column. There is always a * mostly empty column on the right, to allow overflowing CJKs. */ const screen_dimen text_start = 8 + 13 * ngroups + ((width < 80) ? 0 : (width == 80) ? (ngroups - 1) : (ngroups - 1 + 1)); int row; off_t from; mark_t boldflag_byte = MARK_NORMAL; mark_t boldflag_char = MARK_NORMAL; struct hexedit_change_node *curr = view->change_list; #ifdef HAVE_CHARSET int cont_bytes = 0; /* number of continuation bytes remanining from current UTF-8 */ gboolean cjk_right = FALSE; /* whether the second byte of a CJK is to be processed */ #endif /* HAVE_CHARSET */ gboolean utf8_changed = FALSE; /* whether any of the bytes in the UTF-8 were changed */ char hex_buff[10]; /* A temporary buffer for sprintf and mvwaddstr */ mcview_display_clean (view); /* Find the first displayable changed byte */ /* In UTF-8 mode, go back by 1 or maybe 2 lines to handle continuation bytes properly. */ from = view->dpy_start; row = 0; #ifdef HAVE_CHARSET if (view->utf8) { if (from >= view->bytes_per_line) { row--; from -= view->bytes_per_line; } if (view->bytes_per_line == 4 && from >= view->bytes_per_line) { row--; from -= view->bytes_per_line; } } #endif /* HAVE_CHARSET */ while (curr && (curr->offset < from)) { curr = curr->next; } for (; mcview_get_byte (view, from, NULL) && row < (int) height; row++) { screen_dimen col = 0; size_t i; int bytes; /* Number of bytes already printed on the line */ /* Print the hex offset */ if (row >= 0) { g_snprintf (hex_buff, sizeof (hex_buff), "%08" PRIXMAX " ", (uintmax_t) from); widget_move (view, top + row, left); tty_setcolor (VIEW_BOLD_COLOR); for (i = 0; col < width && hex_buff[i] != '\0'; col++, i++) tty_print_char (hex_buff[i]); tty_setcolor (VIEW_NORMAL_COLOR); } for (bytes = 0; bytes < view->bytes_per_line; bytes++, from++) { int c; #ifdef HAVE_CHARSET int ch = 0; if (view->utf8) { struct hexedit_change_node *corr = curr; if (cont_bytes != 0) { /* UTF-8 continuation bytes, print a space (with proper attributes)... */ cont_bytes--; ch = ' '; if (cjk_right) { /* ... except when it'd wipe out the right half of a CJK, then print nothing */ cjk_right = FALSE; ch = -1; } } else { int j; gchar utf8buf[UTF8_CHAR_LEN + 1]; int res; int first_changed = -1; for (j = 0; j < UTF8_CHAR_LEN; j++) { if (mcview_get_byte (view, from + j, &res)) utf8buf[j] = res; else { utf8buf[j] = '\0'; break; } if (curr != NULL && from + j == curr->offset) { utf8buf[j] = curr->value; if (first_changed == -1) first_changed = j; } if (curr != NULL && from + j >= curr->offset) curr = curr->next; } utf8buf[UTF8_CHAR_LEN] = '\0'; /* Determine the state of the current multibyte char */ ch = g_utf8_get_char_validated (utf8buf, -1); if (ch == -1 || ch == -2) { ch = '.'; } else { gchar *next_ch; next_ch = g_utf8_next_char (utf8buf); cont_bytes = next_ch - utf8buf - 1; if (g_unichar_iswide (ch)) cjk_right = TRUE; } utf8_changed = (first_changed >= 0 && first_changed <= cont_bytes); curr = corr; } } #endif /* HAVE_CHARSET */ /* For negative rows, the only thing we care about is overflowing * UTF-8 continuation bytes which were handled above. */ if (row < 0) { if (curr != NULL && from == curr->offset) curr = curr->next; continue; } if (!mcview_get_byte (view, from, &c)) break; /* Save the cursor position for mcview_place_cursor() */ if (from == view->hex_cursor && !view->hexview_in_text) { view->cursor_row = row; view->cursor_col = col; } /* Determine the state of the current byte */ boldflag_byte = mcview_hex_calculate_boldflag (view, from, curr, FALSE); boldflag_char = mcview_hex_calculate_boldflag (view, from, curr, utf8_changed); /* Determine the value of the current byte */ if (curr != NULL && from == curr->offset) { c = curr->value; curr = curr->next; } /* Select the color for the hex number */ tty_setcolor (boldflag_byte == MARK_NORMAL ? VIEW_NORMAL_COLOR : boldflag_byte == MARK_SELECTED ? VIEW_BOLD_COLOR : boldflag_byte == MARK_CHANGED ? VIEW_UNDERLINED_COLOR : /* boldflag_byte == MARK_CURSOR */ view->hexview_in_text ? VIEW_SELECTED_COLOR : VIEW_UNDERLINED_COLOR); /* Print the hex number */ widget_move (view, top + row, left + col); if (col < width) { tty_print_char (hex_char[c / 16]); col += 1; } if (col < width) { tty_print_char (hex_char[c % 16]); col += 1; } /* Print the separator */ tty_setcolor (VIEW_NORMAL_COLOR); if (bytes != view->bytes_per_line - 1) { if (col < width) { tty_print_char (' '); col += 1; } /* After every four bytes, print a group separator */ if (bytes % 4 == 3) { if (view->data_area.width >= 80 && col < width) { tty_print_one_vline (TRUE); col += 1; } if (col < width) { tty_print_char (' '); col += 1; } } } /* Select the color for the character; this differs from the * hex color when boldflag == MARK_CURSOR */ tty_setcolor (boldflag_char == MARK_NORMAL ? VIEW_NORMAL_COLOR : boldflag_char == MARK_SELECTED ? VIEW_BOLD_COLOR : boldflag_char == MARK_CHANGED ? VIEW_UNDERLINED_COLOR : /* boldflag_char == MARK_CURSOR */ view->hexview_in_text ? VIEW_SELECTED_COLOR : MARKED_SELECTED_COLOR); #ifdef HAVE_CHARSET if (mc_global.utf8_display) { if (!view->utf8) { c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter); } if (!g_unichar_isprint (c)) c = '.'; } else if (view->utf8) ch = convert_from_utf_to_current_c (ch, view->converter); else #endif { #ifdef HAVE_CHARSET c = convert_to_display_c (c); #endif if (!is_printable (c)) c = '.'; } /* Print corresponding character on the text side */ if (text_start + bytes < width) { widget_move (view, top + row, left + text_start + bytes); #ifdef HAVE_CHARSET if (view->utf8) tty_print_anychar (ch); else #endif tty_print_char (c); } /* Save the cursor position for mcview_place_cursor() */ if (from == view->hex_cursor && view->hexview_in_text) { view->cursor_row = row; view->cursor_col = text_start + bytes; } } } /* Be polite to the other functions */ tty_setcolor (VIEW_NORMAL_COLOR); mcview_place_cursor (view); view->dpy_end = from; }