mcedit: add intermediate variables to make code more readable and debuggable.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2023-12-17 17:32:15 +03:00
parent d8a93bcc86
commit 49bc0ddebf
4 changed files with 99 additions and 58 deletions

View File

@ -485,6 +485,7 @@ edit_load_position (WEdit * edit, gboolean load_position)
{
long line, column;
off_t offset;
off_t b;
if (edit->filename_vpath == NULL
|| *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) == '\0')
@ -509,7 +510,8 @@ edit_load_position (WEdit * edit, gboolean load_position)
edit->search_start = edit->buffer.curs1;
}
edit_move_to_prev_col (edit, edit_buffer_get_current_bol (&edit->buffer));
b = edit_buffer_get_current_bol (&edit->buffer);
edit_move_to_prev_col (edit, b);
edit_move_display (edit, line - (WIDGET (edit)->rect.lines / 2));
}
@ -881,7 +883,10 @@ edit_move_to_bottom (WEdit * edit)
static void
edit_cursor_to_bol (WEdit * edit)
{
edit_cursor_move (edit, edit_buffer_get_current_bol (&edit->buffer) - edit->buffer.curs1);
off_t b;
b = edit_buffer_get_current_bol (&edit->buffer);
edit_cursor_move (edit, b - edit->buffer.curs1);
edit->search_start = edit->buffer.curs1;
edit->prev_col = edit_get_col (edit);
edit->over_col = 0;
@ -893,7 +898,10 @@ edit_cursor_to_bol (WEdit * edit)
static void
edit_cursor_to_eol (WEdit * edit)
{
edit_cursor_move (edit, edit_buffer_get_current_eol (&edit->buffer) - edit->buffer.curs1);
off_t b;
b = edit_buffer_get_current_eol (&edit->buffer);
edit_cursor_move (edit, b - edit->buffer.curs1);
edit->search_start = edit->buffer.curs1;
edit->prev_col = edit_get_col (edit);
edit->over_col = 0;
@ -1182,8 +1190,11 @@ edit_do_undo (WEdit * edit)
edit->undo_stack_disable = 1; /* don't record undo's onto undo stack! */
edit->over_col = 0;
while ((ac = edit_pop_undo_action (edit)) < KEY_PRESS)
{
off_t b;
switch ((int) ac)
{
case STACK_BOTTOM:
@ -1219,16 +1230,14 @@ edit_do_undo (WEdit * edit)
if (ac >= MARK_1 - 2 && ac < MARK_2 - 2)
{
edit->mark1 = ac - MARK_1;
edit->column1 =
(long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1),
0, edit->mark1);
b = edit_buffer_get_bol (&edit->buffer, edit->mark1);
edit->column1 = (long) edit_move_forward3 (edit, b, 0, edit->mark1);
}
if (ac >= MARK_2 - 2 && ac < MARK_CURS - 2)
{
edit->mark2 = ac - MARK_2;
edit->column2 =
(long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2),
0, edit->mark2);
b = edit_buffer_get_bol (&edit->buffer, edit->mark2);
edit->column2 = (long) edit_move_forward3 (edit, b, 0, edit->mark2);
}
else if (ac >= MARK_CURS - 2 && ac < KEY_PRESS)
{
@ -1269,8 +1278,11 @@ edit_do_redo (WEdit * edit)
return;
edit->over_col = 0;
while ((ac = edit_pop_redo_action (edit)) < KEY_PRESS)
{
off_t b;
switch ((int) ac)
{
case STACK_BOTTOM:
@ -1304,16 +1316,14 @@ edit_do_redo (WEdit * edit)
if (ac >= MARK_1 - 2 && ac < MARK_2 - 2)
{
edit->mark1 = ac - MARK_1;
edit->column1 =
(long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1),
0, edit->mark1);
b = edit_buffer_get_bol (&edit->buffer, edit->mark1);
edit->column1 = (long) edit_move_forward3 (edit, b, 0, edit->mark1);
}
else if (ac >= MARK_2 - 2 && ac < KEY_PRESS)
{
edit->mark2 = ac - MARK_2;
edit->column2 =
(long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2),
0, edit->mark2);
b = edit_buffer_get_bol (&edit->buffer, edit->mark2);
edit->column2 = (long) edit_move_forward3 (edit, b, 0, edit->mark2);
}
/* more than one pop usually means something big */
if (count++ != 0)
@ -1625,6 +1635,8 @@ edit_move_block_to_right (WEdit * edit)
do
{
off_t b;
edit_cursor_move (edit, cur_bol - edit->buffer.curs1);
if (!edit_line_is_blank (edit, edit->buffer.curs_line))
{
@ -1632,8 +1644,9 @@ edit_move_block_to_right (WEdit * edit)
insert_spaces_tab (edit, edit_options.fake_half_tabs);
else
edit_insert (edit, '\t');
edit_cursor_move (edit,
edit_buffer_get_bol (&edit->buffer, cur_bol) - edit->buffer.curs1);
b = edit_buffer_get_bol (&edit->buffer, cur_bol);
edit_cursor_move (edit, b - edit->buffer.curs1);
}
if (cur_bol == 0)
@ -2870,8 +2883,10 @@ edit_get_cursor_offset (const WEdit * edit)
long
edit_get_col (const WEdit * edit)
{
return (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0,
edit->buffer.curs1);
off_t b;
b = edit_buffer_get_current_bol (&edit->buffer);
return (long) edit_move_forward3 (edit, b, 0, edit->buffer.curs1);
}
/* --------------------------------------------------------------------------------------------- */
@ -2889,8 +2904,10 @@ edit_update_curs_row (WEdit * edit)
void
edit_update_curs_col (WEdit * edit)
{
edit->curs_col = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer),
0, edit->buffer.curs1);
off_t b;
b = edit_buffer_get_current_bol (&edit->buffer);
edit->curs_col = (long) edit_move_forward3 (edit, b, 0, edit->buffer.curs1);
}
/* --------------------------------------------------------------------------------------------- */
@ -2977,16 +2994,19 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
{
long prev = edit->prev_col;
long over = edit->over_col;
off_t b;
edit_cursor_move (edit,
edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->buffer.curs1);
if (edit_options.cursor_beyond_eol)
{
off_t e;
long line_len;
line_len = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0,
edit_buffer_get_current_eol (&edit->buffer));
b = edit_buffer_get_current_bol (&edit->buffer);
e = edit_buffer_get_current_eol (&edit->buffer);
line_len = (long) edit_move_forward3 (edit, b, 0, e);
if (line_len < prev + edit->over_col)
{
edit->over_col = prev + over - line_len;
@ -2995,9 +3015,9 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
}
else
{
edit->curs_col = prev + over;
edit->prev_col = edit->curs_col;
edit->over_col = 0;
edit->prev_col = edit->curs_col;
edit->curs_col = prev + over;
}
}
else
@ -3017,12 +3037,13 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
q = edit->curs_col;
edit->curs_col -= (edit->curs_col % fake_half_tabs);
p = edit_buffer_get_current_bol (&edit->buffer);
edit_cursor_move (edit,
edit_move_forward3 (edit, p, edit->curs_col,
0) - edit->buffer.curs1);
b = edit_move_forward3 (edit, p, edit->curs_col, 0);
edit_cursor_move (edit, b - edit->buffer.curs1);
if (!left_of_four_spaces (edit))
edit_cursor_move (edit,
edit_move_forward3 (edit, p, q, 0) - edit->buffer.curs1);
{
b = edit_move_forward3 (edit, p, q, 0);
edit_cursor_move (edit, b - edit->buffer.curs1);
}
}
}
}

View File

@ -463,17 +463,20 @@ static void
edit_delete_column_of_text (WEdit * edit, off_t m1, off_t m2)
{
off_t n;
off_t r;
long b, c, d;
n = edit_buffer_get_forward_offset (&edit->buffer, m1, 0, m2) + 1;
c = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m1), 0, m1);
d = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m2), 0, m2);
r = edit_buffer_get_bol (&edit->buffer, m1);
c = (long) edit_move_forward3 (edit, r, 0, m1);
r = edit_buffer_get_bol (&edit->buffer, m2);
d = (long) edit_move_forward3 (edit, r, 0, m2);
b = MAX (MIN (c, d), MIN (edit->column1, edit->column2));
c = MAX (c, MAX (edit->column1, edit->column2));
while (n-- != 0)
{
off_t r, p, q;
off_t p, q;
r = edit_buffer_get_current_bol (&edit->buffer);
p = edit_move_forward3 (edit, r, b, 0);
@ -488,9 +491,10 @@ edit_delete_column_of_text (WEdit * edit, off_t m1, off_t m2)
/* move to next line except on the last delete */
if (n != 0)
edit_cursor_move (edit,
edit_buffer_get_forward_offset (&edit->buffer, edit->buffer.curs1, 1,
0) - edit->buffer.curs1);
{
r = edit_buffer_get_forward_offset (&edit->buffer, edit->buffer.curs1, 1, 0);
edit_cursor_move (edit, r - edit->buffer.curs1);
}
}
}
@ -532,6 +536,7 @@ edit_block_delete (WEdit * edit, off_t start_mark, off_t end_mark)
{
if (edit->column_highlight)
{
off_t b, e;
off_t line_width;
if (edit->mark2 < 0)
@ -540,8 +545,9 @@ edit_block_delete (WEdit * edit, off_t start_mark, off_t end_mark)
/* move cursor to the saved position */
edit_move_to_line (edit, curs_line);
/* calculate line width and cursor position before cut */
line_width = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0,
edit_buffer_get_current_eol (&edit->buffer));
b = edit_buffer_get_current_bol (&edit->buffer);
e = edit_buffer_get_current_eol (&edit->buffer);
line_width = edit_move_forward3 (edit, b, 0, e);
if (edit_options.cursor_beyond_eol && curs_pos > line_width)
edit->over_col = curs_pos - line_width;
}
@ -580,7 +586,8 @@ edit_get_block (WEdit * edit, off_t start, off_t finish, off_t * l)
int c;
off_t x;
x = edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, start), 0, start);
x = edit_buffer_get_bol (&edit->buffer, start);
x = edit_move_forward3 (edit, x, 0, start);
c = edit_buffer_get_byte (&edit->buffer, start);
if ((x >= edit->column1 && x < edit->column2)
|| (x >= edit->column2 && x < edit->column1) || c == '\n')
@ -1339,6 +1346,7 @@ edit_block_move_cmd (WEdit * edit)
off_t size;
long c1, c2, b_width;
long x, x2;
off_t b1, b2;
c1 = MIN (edit->column1, edit->column2);
c2 = MAX (edit->column1, edit->column2);
@ -1350,8 +1358,9 @@ edit_block_move_cmd (WEdit * edit)
x2 = x + edit->over_col;
/* do nothing when cursor inside first line of selected area */
if ((edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1) ==
edit_buffer_get_eol (&edit->buffer, start_mark)) && x2 > c1 && x2 <= c2)
b1 = edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1);
b2 = edit_buffer_get_eol (&edit->buffer, start_mark);
if (b1 == b2 && x2 > c1 && x2 <= c2)
return;
if (edit->buffer.curs1 > start_mark
@ -1370,7 +1379,8 @@ edit_block_move_cmd (WEdit * edit)
edit->over_col = MAX (0, edit->over_col - b_width);
/* calculate the cursor pos after delete block */
current = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), x, 0);
b1 = edit_buffer_get_current_bol (&edit->buffer);
current = edit_move_forward3 (edit, b1, x, 0);
edit_cursor_move (edit, current - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit);
@ -1384,6 +1394,7 @@ edit_block_move_cmd (WEdit * edit)
else
{
off_t count, count_orig;
off_t x;
current = edit->buffer.curs1;
copy_buf = g_malloc0 (end_mark - start_mark);
@ -1394,9 +1405,8 @@ edit_block_move_cmd (WEdit * edit)
copy_buf[end_mark - count - 1] = edit_delete (edit, TRUE);
edit_scroll_screen_over_cursor (edit);
edit_cursor_move (edit,
current - edit->buffer.curs1 -
(((current - edit->buffer.curs1) > 0) ? end_mark - start_mark : 0));
x = current > edit->buffer.curs1 ? end_mark - start_mark : 0;
edit_cursor_move (edit, current - edit->buffer.curs1 - x);
edit_scroll_screen_over_cursor (edit);
count_orig = count;
while (count-- > start_mark)

View File

@ -950,9 +950,8 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
{
row = curs_row - 1;
b = edit_buffer_get_backward_offset (&edit->buffer,
edit_buffer_get_current_bol (&edit->buffer),
1);
b = edit_buffer_get_current_bol (&edit->buffer);
b = edit_buffer_get_backward_offset (&edit->buffer, b, 1);
if (row >= start_row && row <= end_row)
{
if (key_pending (edit))

View File

@ -248,7 +248,8 @@ compare_word_to_right (const WEdit * edit, off_t i, const GString * text,
const unsigned char *p, *q;
int c, d, j;
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i - 1));
c = edit_buffer_get_byte (&edit->buffer, i - 1);
c = xx_tolower (edit, c);
if ((line_start && c != '\n') || (whole_left != NULL && strchr (whole_left, c) != NULL))
return -1;
@ -261,7 +262,8 @@ compare_word_to_right (const WEdit * edit, off_t i, const GString * text,
return -1;
while (TRUE)
{
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
c = edit_buffer_get_byte (&edit->buffer, i);
c = xx_tolower (edit, c);
if (*p == '\0' && whole_right != NULL && strchr (whole_right, c) == NULL)
break;
if (c == *p)
@ -277,7 +279,8 @@ compare_word_to_right (const WEdit * edit, off_t i, const GString * text,
j = 0;
while (TRUE)
{
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
c = edit_buffer_get_byte (&edit->buffer, i);
c = xx_tolower (edit, c);
if (c == *p)
{
j = i;
@ -308,7 +311,8 @@ compare_word_to_right (const WEdit * edit, off_t i, const GString * text,
while (TRUE)
{
d = c;
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
c = edit_buffer_get_byte (&edit->buffer, i);
c = xx_tolower (edit, c);
for (j = 0; p[j] != SYNTAX_TOKEN_BRACKET && p[j] != '\0'; j++)
if (c == p[j])
goto found_char2;
@ -327,7 +331,8 @@ compare_word_to_right (const WEdit * edit, off_t i, const GString * text,
case SYNTAX_TOKEN_BRACE:
if (++p > q)
return -1;
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
c = edit_buffer_get_byte (&edit->buffer, i);
c = xx_tolower (edit, c);
for (; *p != SYNTAX_TOKEN_BRACE && *p != '\0'; p++)
if (c == *p)
goto found_char3;
@ -337,13 +342,18 @@ compare_word_to_right (const WEdit * edit, off_t i, const GString * text,
p++;
break;
default:
if (*p != xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i)))
c = edit_buffer_get_byte (&edit->buffer, i);
if (*p != xx_tolower (edit, c))
return -1;
}
}
return (whole_right != NULL &&
strchr (whole_right,
xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i))) != NULL) ? -1 : i;
if (whole_right == NULL)
return i;
c = edit_buffer_get_byte (&edit->buffer, i);
c = xx_tolower (edit, c);
return strchr (whole_right, c) != NULL ? -1 : i;
}
/* --------------------------------------------------------------------------------------------- */
@ -371,7 +381,8 @@ apply_rules_going_right (WEdit * edit, off_t i)
off_t end = 0;
edit_syntax_rule_t _rule = edit->rule;
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
c = edit_buffer_get_byte (&edit->buffer, i);
c = xx_tolower (edit, c);
if (c == 0)
return;