src/editor/editdraw.c: fix coding style.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2020-02-22 20:41:03 +03:00
parent dff8ee2981
commit 95ed249f6c

View File

@ -119,15 +119,13 @@ status_string (WEdit * edit, char *s, int w)
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
if (edit->utf8) if (edit->utf8)
{ {
unsigned int cur_utf = 0; unsigned int cur_utf;
int char_length = 1; int char_length = 1;
cur_utf = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &char_length); cur_utf = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &char_length);
if (char_length > 0) if (char_length > 0)
{
g_snprintf (byte_str, sizeof (byte_str), "%04u 0x%03X", g_snprintf (byte_str, sizeof (byte_str), "%04u 0x%03X",
(unsigned) cur_utf, (unsigned) cur_utf); (unsigned) cur_utf, (unsigned) cur_utf);
}
else else
{ {
cur_utf = edit_buffer_get_current_byte (&edit->buffer); cur_utf = edit_buffer_get_current_byte (&edit->buffer);
@ -138,7 +136,7 @@ status_string (WEdit * edit, char *s, int w)
else else
#endif #endif
{ {
unsigned char cur_byte = 0; unsigned char cur_byte;
cur_byte = edit_buffer_get_current_byte (&edit->buffer); cur_byte = edit_buffer_get_current_byte (&edit->buffer);
g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X", g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
@ -146,9 +144,7 @@ status_string (WEdit * edit, char *s, int w)
} }
} }
else else
{
strcpy (byte_str, "<EOF> "); strcpy (byte_str, "<EOF> ");
}
/* The field lengths just prevent the status line from shortening too much */ /* The field lengths just prevent the status line from shortening too much */
if (simple_statusbar) if (simple_statusbar)
@ -198,15 +194,17 @@ edit_status_fullscreen (WEdit * edit, int color)
{ {
Widget *h = WIDGET (WIDGET (edit)->owner); Widget *h = WIDGET (WIDGET (edit)->owner);
const int w = h->cols; const int w = h->cols;
const size_t status_size = w + 1;
char *const status = g_malloc (status_size);
int status_len;
const char *fname = "";
int fname_len;
const int gap = 3; /* between the filename and the status */ const int gap = 3; /* between the filename and the status */
const int right_gap = 5; /* at the right end of the screen */ const int right_gap = 5; /* at the right end of the screen */
const int preferred_fname_len = 16; const int preferred_fname_len = 16;
char *status;
size_t status_size;
int status_len;
const char *fname = "";
int fname_len;
status_size = w + 1;
status = g_malloc (status_size);
status_string (edit, status, status_size); status_string (edit, status, status_size);
status_len = (int) str_term_width1 (status); status_len = (int) str_term_width1 (status);
@ -394,17 +392,17 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
long end_col, line_s line[], char *status, int bookmarked) long end_col, line_s line[], char *status, int bookmarked)
{ {
Widget *w = WIDGET (edit); Widget *w = WIDGET (edit);
line_s *p; line_s *p;
int x, x1, y, cols_to_skip;
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 i;
int wrap_start; int wrap_start;
int len; int len;
x = start_col_real;
x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
y = row + EDIT_TEXT_VERTICAL_OFFSET;
cols_to_skip = abs (x);
if (!edit->fullscreen) if (!edit->fullscreen)
{ {
x1++; x1++;
@ -444,6 +442,7 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
if (option_line_state) if (option_line_state)
{ {
tty_setcolor (LINE_STATE_COLOR); tty_setcolor (LINE_STATE_COLOR);
for (i = 0; i < LINE_STATE_WIDTH; i++) for (i = 0; i < LINE_STATE_WIDTH; i++)
{ {
edit_move (x1 + i - option_line_state_width, y); edit_move (x1 + i - option_line_state_width, y);
@ -454,6 +453,7 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
} }
edit_move (x1, y); edit_move (x1, y);
i = 1; i = 1;
for (p = line; p->ch != 0; p++) for (p = line; p->ch != 0; p++)
{ {
@ -471,15 +471,13 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
textchar = p->ch; textchar = p->ch;
color = p->style >> 16; color = p->style >> 16;
if (style & MOD_ABNORMAL) if ((style & MOD_ABNORMAL) != 0)
{
/* Non-printable - use black background */ /* Non-printable - use black background */
color = 0; color = 0;
}
if (style & MOD_WHITESPACE) if ((style & MOD_WHITESPACE) != 0)
{ {
if (style & MOD_MARKED) if ((style & MOD_MARKED) != 0)
{ {
textchar = ' '; textchar = ' ';
tty_setcolor (EDITOR_MARKED_COLOR); tty_setcolor (EDITOR_MARKED_COLOR);
@ -487,9 +485,9 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
else else
tty_setcolor (EDITOR_WHITESPACE_COLOR); tty_setcolor (EDITOR_WHITESPACE_COLOR);
} }
else if (style & MOD_BOLD) else if ((style & MOD_BOLD) != 0)
tty_setcolor (EDITOR_BOLD_COLOR); tty_setcolor (EDITOR_BOLD_COLOR);
else if (style & MOD_MARKED) else if ((style & MOD_MARKED) != 0)
tty_setcolor (EDITOR_MARKED_COLOR); tty_setcolor (EDITOR_MARKED_COLOR);
else else
tty_lowlevel_setcolor (color); tty_lowlevel_setcolor (color);
@ -512,11 +510,9 @@ static void
edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col) edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col)
{ {
Widget *w = WIDGET (edit); Widget *w = WIDGET (edit);
line_s line[MAX_LINE_LEN]; line_s line[MAX_LINE_LEN];
line_s *p = line; line_s *p = line;
off_t q;
off_t m1 = 0, m2 = 0, q;
int col, start_col_real; int col, start_col_real;
int color; int color;
int abn_style; int abn_style;
@ -531,7 +527,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR)) else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
book_mark = BOOK_MARK_FOUND_COLOR; book_mark = BOOK_MARK_FOUND_COLOR;
if (book_mark) if (book_mark != 0)
abn_style = book_mark << 16; abn_style = book_mark << 16;
else else
abn_style = MOD_ABNORMAL; abn_style = MOD_ABNORMAL;
@ -546,7 +542,8 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
color = edit_get_syntax_color (edit, b - 1); color = edit_get_syntax_color (edit, b - 1);
q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0); q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col; col = (int) edit_move_forward3 (edit, b, 0, q);
start_col_real = col + edit->start_col;
if (option_line_state) if (option_line_state)
{ {
@ -554,22 +551,21 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
cur_line = edit->start_line + row; cur_line = edit->start_line + row;
if (cur_line <= edit->buffer.lines) if (cur_line <= edit->buffer.lines)
{
g_snprintf (line_stat, sizeof (line_stat), "%7ld ", cur_line + 1); g_snprintf (line_stat, sizeof (line_stat), "%7ld ", cur_line + 1);
}
else else
{ {
memset (line_stat, ' ', LINE_STATE_WIDTH); memset (line_stat, ' ', LINE_STATE_WIDTH);
line_stat[LINE_STATE_WIDTH] = '\0'; line_stat[LINE_STATE_WIDTH] = '\0';
} }
if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR)) if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
{
g_snprintf (line_stat, 2, "*"); g_snprintf (line_stat, 2, "*");
}
} }
if (col + 16 > -edit->start_col) if (col + 16 > -edit->start_col)
{ {
off_t m1 = 0, m2 = 0;
eval_marks (edit, &m1, &m2); eval_marks (edit, &m1, &m2);
if (row <= edit->buffer.lines - edit->start_line) if (row <= edit->buffer.lines - edit->start_line)
@ -630,20 +626,20 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
c = edit_buffer_get_byte (&edit->buffer, q); c = edit_buffer_get_byte (&edit->buffer, q);
/* we don't use bg for mc - fg contains both */ /* we don't use bg for mc - fg contains both */
if (book_mark) if (book_mark != 0)
{
p->style |= book_mark << 16; p->style |= book_mark << 16;
}
else else
{ {
color = edit_get_syntax_color (edit, q); color = edit_get_syntax_color (edit, q);
p->style |= color << 16; p->style |= color << 16;
} }
switch (c) switch (c)
{ {
case '\n': case '\n':
col = end_col - edit->start_col + 1; /* quit */ col = end_col - edit->start_col + 1; /* quit */
break; break;
case '\t': case '\t':
{ {
int tab_over; int tab_over;
@ -657,9 +653,9 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
if (tty_use_colors () && if (tty_use_colors () &&
((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws)) ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
{ {
if (p->style & MOD_MARKED) if ((p->style & MOD_MARKED) != 0)
c = p->style; c = p->style;
else if (book_mark) else if (book_mark != 0)
c |= book_mark << 16; c |= book_mark << 16;
else else
c = p->style | MOD_WHITESPACE; c = p->style | MOD_WHITESPACE;
@ -701,7 +697,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
p->style |= MOD_WHITESPACE; p->style |= MOD_WHITESPACE;
c = p->style & ~MOD_CURSOR; c = p->style & ~MOD_CURSOR;
p++; p++;
while (--i) while (--i != 0)
{ {
p->ch = ' '; p->ch = ' ';
p->style = c; p->style = c;
@ -713,7 +709,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
p->ch |= ' '; p->ch |= ' ';
c = p->style & ~MOD_CURSOR; c = p->style & ~MOD_CURSOR;
p++; p++;
while (--i) while (--i != 0)
{ {
p->ch = ' '; p->ch = ' ';
p->style = c; p->style = c;
@ -722,6 +718,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
} }
} }
break; break;
case ' ': case ' ':
if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws) if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
{ {
@ -732,21 +729,17 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
break; break;
} }
MC_FALLTHROUGH; MC_FALLTHROUGH;
default: default:
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
if (mc_global.utf8_display) if (mc_global.utf8_display)
{ {
if (!edit->utf8) if (!edit->utf8)
{
c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter); c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
} else if (g_unichar_iswide (c))
else
{ {
if (g_unichar_iswide (c)) wide_width_char = TRUE;
{ col++;
wide_width_char = TRUE;
col++;
}
} }
} }
else if (edit->utf8) else if (edit->utf8)
@ -847,8 +840,9 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
static inline void static inline void
edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column) edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column)
{ {
off_t b = edit_buffer_get_bol (&edit->buffer, curs); off_t b;
b = edit_buffer_get_bol (&edit->buffer, curs);
edit_draw_this_line (edit, b, row, start_column, end_column); edit_draw_this_line (edit, b, row, start_column, end_column);
} }
@ -866,9 +860,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
int force = edit->force; int force = edit->force;
int y1, x1, y2, x2; int y1, x1, y2, x2;
int last_line, last_column;
int last_line;
int last_column;
/* draw only visible region */ /* draw only visible region */
@ -940,10 +932,11 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row) if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)
{ {
long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row; long upto;
row = start_row; row = start_row;
b = edit->start_display; b = edit->start_display;
upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
while (row <= upto) while (row <= upto)
{ {
if (key_pending (edit)) if (key_pending (edit))
@ -1027,7 +1020,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
static inline void static inline void
edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end) edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
{ {
if (page) /* if it was an expose event, 'page' would be set */ if (page != 0) /* if it was an expose event, 'page' would be set */
edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS; edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
render_edit_text (edit, row_start, col_start, row_end, col_end); render_edit_text (edit, row_start, col_start, row_end, col_end);
@ -1037,7 +1030,7 @@ edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end,
* was halted, so next time we must redraw everything in case stuff * was halted, so next time we must redraw everything in case stuff
* was left undrawn from a previous key press. * was left undrawn from a previous key press.
*/ */
if (edit->force) if (edit->force != 0)
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
} }