Refactoring editor buffer API of bytes/symbols get.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
e056726606
Коммит
cd9a56109d
@ -153,8 +153,6 @@ void edit_menu_cmd (WDialog * h);
|
||||
void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
|
||||
void edit_init_menu (struct WMenuBar *menubar);
|
||||
void edit_save_mode_cmd (void);
|
||||
int edit_get_byte (const WEdit * edit, off_t byte_index);
|
||||
int edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width);
|
||||
long edit_count_lines (const WEdit * edit, off_t current, off_t upto);
|
||||
off_t edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto);
|
||||
off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto);
|
||||
|
@ -573,74 +573,6 @@ edit_modification (WEdit * edit)
|
||||
edit->modified = 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
edit_get_byte_ptr (const WEdit * edit, off_t byte_index)
|
||||
{
|
||||
if (byte_index >= (edit->buffer.curs1 + edit->buffer.curs2) || byte_index < 0)
|
||||
return NULL;
|
||||
|
||||
if (byte_index >= edit->buffer.curs1)
|
||||
{
|
||||
off_t p;
|
||||
|
||||
p = edit->buffer.curs1 + edit->buffer.curs2 - byte_index - 1;
|
||||
return (char *) (edit->buffer.buffers2[p >> S_EDIT_BUF_SIZE] +
|
||||
(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
|
||||
}
|
||||
|
||||
return (char *) (edit->buffer.buffers1[byte_index >> S_EDIT_BUF_SIZE] +
|
||||
(byte_index & M_EDIT_BUF_SIZE));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
static int
|
||||
edit_get_prev_utf (const WEdit * edit, off_t byte_index, int *char_width)
|
||||
{
|
||||
int i, res;
|
||||
gchar utf8_buf[3 * UTF8_CHAR_LEN + 1];
|
||||
gchar *str;
|
||||
gchar *cursor_buf_ptr;
|
||||
|
||||
if (byte_index > (edit->buffer.curs1 + edit->buffer.curs2) || byte_index <= 0)
|
||||
{
|
||||
*char_width = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < (3 * UTF8_CHAR_LEN); i++)
|
||||
utf8_buf[i] = edit_get_byte (edit, byte_index + i - (2 * UTF8_CHAR_LEN));
|
||||
utf8_buf[3 * UTF8_CHAR_LEN] = '\0';
|
||||
|
||||
cursor_buf_ptr = utf8_buf + (2 * UTF8_CHAR_LEN);
|
||||
str = g_utf8_find_prev_char (utf8_buf, cursor_buf_ptr);
|
||||
|
||||
if (str == NULL || g_utf8_next_char (str) != cursor_buf_ptr)
|
||||
{
|
||||
*char_width = 1;
|
||||
return *(cursor_buf_ptr - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if (res < 0)
|
||||
{
|
||||
*char_width = 1;
|
||||
return *(cursor_buf_ptr - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
*char_width = cursor_buf_ptr - str;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* high level cursor movement commands */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -657,7 +589,7 @@ is_in_indent (const WEdit * edit)
|
||||
off_t p;
|
||||
|
||||
for (p = edit_bol (edit, edit->buffer.curs1); p < edit->buffer.curs1; p++)
|
||||
if (strchr (" \t", edit_get_byte (edit, p)) == NULL)
|
||||
if (strchr (" \t", edit_buffer_get_byte (&edit->buffer, p)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
@ -682,7 +614,7 @@ is_blank (const WEdit * edit, off_t offset)
|
||||
f = edit_eol (edit, offset) - 1;
|
||||
while (s <= f)
|
||||
{
|
||||
c = edit_get_byte (edit, s++);
|
||||
c = edit_buffer_get_byte (&edit->buffer, s++);
|
||||
if (!isspace (c))
|
||||
return FALSE;
|
||||
}
|
||||
@ -947,8 +879,8 @@ edit_left_word_move (WEdit * edit, int s)
|
||||
edit_cursor_move (edit, -1);
|
||||
if (edit->buffer.curs1 == 0)
|
||||
break;
|
||||
c1 = edit_get_byte (edit, edit->buffer.curs1 - 1);
|
||||
c2 = edit_get_byte (edit, edit->buffer.curs1);
|
||||
c1 = edit_buffer_get_previous_byte (&edit->buffer);
|
||||
c2 = edit_buffer_get_current_byte (&edit->buffer);
|
||||
if (c1 == '\n' || c2 == '\n')
|
||||
break;
|
||||
if ((my_type_of (c1) & my_type_of (c2)) == 0)
|
||||
@ -985,8 +917,8 @@ edit_right_word_move (WEdit * edit, int s)
|
||||
edit_cursor_move (edit, 1);
|
||||
if (edit->buffer.curs1 >= edit->last_byte)
|
||||
break;
|
||||
c1 = edit_get_byte (edit, edit->buffer.curs1 - 1);
|
||||
c2 = edit_get_byte (edit, edit->buffer.curs1);
|
||||
c1 = edit_buffer_get_previous_byte (&edit->buffer);
|
||||
c2 = edit_buffer_get_current_byte (&edit->buffer);
|
||||
if (c1 == '\n' || c2 == '\n')
|
||||
break;
|
||||
if ((my_type_of (c1) & my_type_of (c2)) == 0)
|
||||
@ -1013,27 +945,23 @@ static void
|
||||
edit_right_char_move_cmd (WEdit * edit)
|
||||
{
|
||||
int cw = 1;
|
||||
int c = 0;
|
||||
int c;
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
{
|
||||
c = edit_get_utf (edit, edit->buffer.curs1, &cw);
|
||||
c = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &cw);
|
||||
if (cw < 1)
|
||||
cw = 1;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
c = edit_get_byte (edit, edit->buffer.curs1);
|
||||
}
|
||||
c = edit_buffer_get_current_byte (&edit->buffer);
|
||||
|
||||
if (option_cursor_beyond_eol && c == '\n')
|
||||
{
|
||||
edit->over_col++;
|
||||
}
|
||||
else
|
||||
{
|
||||
edit_cursor_move (edit, cw);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1042,6 +970,7 @@ static void
|
||||
edit_left_char_move_cmd (WEdit * edit)
|
||||
{
|
||||
int cw = 1;
|
||||
|
||||
if (edit->column_highlight
|
||||
&& option_cursor_beyond_eol
|
||||
&& edit->mark1 != edit->mark2
|
||||
@ -1050,7 +979,7 @@ edit_left_char_move_cmd (WEdit * edit)
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
{
|
||||
edit_get_prev_utf (edit, edit->buffer.curs1, &cw);
|
||||
edit_buffer_get_prev_utf (&edit->buffer, edit->buffer.curs1, &cw);
|
||||
if (cw < 1)
|
||||
cw = 1;
|
||||
}
|
||||
@ -1103,7 +1032,7 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi
|
||||
#ifdef HAVE_CHARSET
|
||||
/* search start of current multibyte char (like CJK) */
|
||||
if (edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->last_byte
|
||||
&& edit_get_byte (edit, edit->buffer.curs1) >= 256 )
|
||||
&& edit_buffer_get_current_byte (&edit->buffer) >= 256)
|
||||
{
|
||||
edit_right_char_move_cmd (edit);
|
||||
edit_left_char_move_cmd (edit);
|
||||
@ -1124,7 +1053,7 @@ edit_right_delete_word (WEdit * edit)
|
||||
int c1, c2;
|
||||
|
||||
c1 = edit_delete (edit, TRUE);
|
||||
c2 = edit_get_byte (edit, edit->buffer.curs1);
|
||||
c2 = edit_buffer_get_current_byte (&edit->buffer);
|
||||
if (c1 == '\n' || c2 == '\n')
|
||||
break;
|
||||
if ((isspace (c1) == 0) != (isspace (c2) == 0))
|
||||
@ -1144,7 +1073,7 @@ edit_left_delete_word (WEdit * edit)
|
||||
int c1, c2;
|
||||
|
||||
c1 = edit_backspace (edit, TRUE);
|
||||
c2 = edit_get_byte (edit, edit->buffer.curs1 - 1);
|
||||
c2 = edit_buffer_get_previous_byte (&edit->buffer);
|
||||
if (c1 == '\n' || c2 == '\n')
|
||||
break;
|
||||
if ((isspace (c1) == 0) != (isspace (c2) == 0))
|
||||
@ -1338,7 +1267,7 @@ edit_group_undo (WEdit * edit)
|
||||
static void
|
||||
edit_delete_to_line_end (WEdit * edit)
|
||||
{
|
||||
while (edit_get_byte (edit, edit->buffer.curs1) != '\n' && edit->buffer.curs2 != 0)
|
||||
while (edit_buffer_get_current_byte (&edit->buffer) != '\n' && edit->buffer.curs2 != 0)
|
||||
edit_delete (edit, TRUE);
|
||||
}
|
||||
|
||||
@ -1347,7 +1276,7 @@ edit_delete_to_line_end (WEdit * edit)
|
||||
static void
|
||||
edit_delete_to_line_begin (WEdit * edit)
|
||||
{
|
||||
while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n' && edit->buffer.curs1 != 0)
|
||||
while (edit_buffer_get_previous_byte (&edit->buffer) != '\n' && edit->buffer.curs1 != 0)
|
||||
edit_backspace (edit, TRUE);
|
||||
}
|
||||
|
||||
@ -1371,7 +1300,7 @@ right_of_four_spaces (WEdit * edit)
|
||||
int i, ch = 0;
|
||||
|
||||
for (i = 1; i <= HALF_TAB_SIZE; i++)
|
||||
ch |= edit_get_byte (edit, edit->buffer.curs1 - i);
|
||||
ch |= edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - i);
|
||||
|
||||
return (ch == ' ' && is_aligned_on_a_tab (edit));
|
||||
}
|
||||
@ -1384,7 +1313,7 @@ left_of_four_spaces (WEdit * edit)
|
||||
int i, ch = 0;
|
||||
|
||||
for (i = 0; i < HALF_TAB_SIZE; i++)
|
||||
ch |= edit_get_byte (edit, edit->buffer.curs1 + i);
|
||||
ch |= edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 + i);
|
||||
|
||||
return (ch == ' ' && is_aligned_on_a_tab (edit));
|
||||
}
|
||||
@ -1403,7 +1332,7 @@ edit_auto_indent (WEdit * edit)
|
||||
/* copy the leading whitespace of the line */
|
||||
while (TRUE)
|
||||
{ /* no range check - the line _is_ \n-terminated */
|
||||
c = edit_get_byte (edit, p++);
|
||||
c = edit_buffer_get_byte (&edit->buffer, p++);
|
||||
if (c != ' ' && c != '\t')
|
||||
break;
|
||||
edit_insert (edit, c);
|
||||
@ -1416,7 +1345,8 @@ static inline void
|
||||
edit_double_newline (WEdit * edit)
|
||||
{
|
||||
edit_insert (edit, '\n');
|
||||
if (edit_get_byte (edit, edit->buffer.curs1) == '\n' || edit_get_byte (edit, edit->buffer.curs1 - 2) == '\n')
|
||||
if (edit_buffer_get_current_byte (&edit->buffer) == '\n'
|
||||
|| edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - 2) == '\n')
|
||||
return;
|
||||
edit->force |= REDRAW_PAGE;
|
||||
edit_insert (edit, '\n');
|
||||
@ -1488,7 +1418,7 @@ check_and_wrap_line (WEdit * edit)
|
||||
while (TRUE)
|
||||
{
|
||||
curs--;
|
||||
c = edit_get_byte (edit, curs);
|
||||
c = edit_buffer_get_byte (&edit->buffer, curs);
|
||||
if (c == '\n' || curs <= 0)
|
||||
{
|
||||
edit_insert (edit, '\n');
|
||||
@ -1522,8 +1452,9 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack
|
||||
int i = 1, a, inc = -1, c, d, n = 0;
|
||||
unsigned long j = 0;
|
||||
off_t q;
|
||||
|
||||
edit_update_curs_row (edit);
|
||||
c = edit_get_byte (edit, edit->buffer.curs1);
|
||||
c = edit_buffer_get_current_byte (&edit->buffer);
|
||||
p = strchr (b, c);
|
||||
/* no limit */
|
||||
if (!furthest_bracket_search)
|
||||
@ -1541,7 +1472,7 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack
|
||||
/* out of buffer? */
|
||||
if (q >= edit->last_byte || q < 0)
|
||||
break;
|
||||
a = edit_get_byte (edit, q);
|
||||
a = edit_buffer_get_byte (&edit->buffer, q);
|
||||
/* don't want to eat CPU */
|
||||
if (j++ > furthest_bracket_search)
|
||||
break;
|
||||
@ -1644,7 +1575,7 @@ edit_move_block_to_left (WEdit * edit)
|
||||
else
|
||||
del_tab_width = option_tab_spacing;
|
||||
|
||||
next_char = edit_get_byte (edit, edit->buffer.curs1);
|
||||
next_char = edit_buffer_get_current_byte (&edit->buffer);
|
||||
if (next_char == '\t')
|
||||
edit_delete (edit, TRUE);
|
||||
else if (next_char == ' ')
|
||||
@ -1652,7 +1583,7 @@ edit_move_block_to_left (WEdit * edit)
|
||||
{
|
||||
if (next_char == ' ')
|
||||
edit_delete (edit, TRUE);
|
||||
next_char = edit_get_byte (edit, edit->buffer.curs1);
|
||||
next_char = edit_buffer_get_current_byte (&edit->buffer);
|
||||
}
|
||||
|
||||
if (cur_bol == 0)
|
||||
@ -1715,7 +1646,7 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t *
|
||||
long l;
|
||||
off_t p;
|
||||
|
||||
if (edit_get_byte (edit, edit->buffer.curs1) != '\n')
|
||||
if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
|
||||
for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width)
|
||||
edit_insert (edit, ' ');
|
||||
|
||||
@ -1728,7 +1659,7 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t *
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
if (edit_get_byte (edit, p) == '\n')
|
||||
if (edit_buffer_get_byte (&edit->buffer, p) == '\n')
|
||||
{
|
||||
p++;
|
||||
break;
|
||||
@ -1809,83 +1740,6 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
edit_get_byte (const WEdit * edit, off_t byte_index)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = edit_get_byte_ptr (edit, byte_index);
|
||||
|
||||
return (p != NULL) ? *(unsigned char *) p : '\n';
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
int
|
||||
edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
int res = -1;
|
||||
gunichar ch;
|
||||
gchar *next_ch = NULL;
|
||||
int width = 0;
|
||||
gchar utf8_buf[UTF8_CHAR_LEN + 1];
|
||||
|
||||
if (byte_index >= (edit->buffer.curs1 + edit->buffer.curs2) || byte_index < 0)
|
||||
{
|
||||
*char_width = 0;
|
||||
return '\n';
|
||||
}
|
||||
|
||||
str = edit_get_byte_ptr (edit, byte_index);
|
||||
|
||||
if (str == NULL)
|
||||
{
|
||||
*char_width = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if (res < 0)
|
||||
{
|
||||
/* Retry with explicit bytes to make sure it's not a buffer boundary */
|
||||
int i;
|
||||
for (i = 0; i < UTF8_CHAR_LEN; i++)
|
||||
utf8_buf[i] = edit_get_byte (edit, byte_index + i);
|
||||
utf8_buf[UTF8_CHAR_LEN] = '\0';
|
||||
str = utf8_buf;
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
}
|
||||
|
||||
if (res < 0)
|
||||
{
|
||||
ch = *str;
|
||||
width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = res;
|
||||
/* Calculate UTF-8 char width */
|
||||
next_ch = g_utf8_next_char (str);
|
||||
if (next_ch)
|
||||
{
|
||||
width = next_ch - str;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = 0;
|
||||
width = 0;
|
||||
}
|
||||
}
|
||||
*char_width = width;
|
||||
return ch;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
edit_get_write_filter (const vfs_path_t * write_name_vpath, const vfs_path_t * filename_vpath)
|
||||
{
|
||||
@ -1919,7 +1773,7 @@ edit_write_stream (WEdit * edit, FILE * f)
|
||||
if (edit->lb == LB_ASIS)
|
||||
{
|
||||
for (i = 0; i < edit->last_byte; i++)
|
||||
if (fputc (edit_get_byte (edit, i), f) < 0)
|
||||
if (fputc (edit_buffer_get_byte (&edit->buffer, i), f) < 0)
|
||||
break;
|
||||
return i;
|
||||
}
|
||||
@ -1927,8 +1781,9 @@ edit_write_stream (WEdit * edit, FILE * f)
|
||||
/* change line breaks */
|
||||
for (i = 0; i < edit->last_byte; i++)
|
||||
{
|
||||
unsigned char c = edit_get_byte (edit, i);
|
||||
unsigned char c;
|
||||
|
||||
c = edit_buffer_get_byte (&edit->buffer, i);
|
||||
if (!(c == '\n' || c == '\r'))
|
||||
{
|
||||
/* not line break */
|
||||
@ -1937,7 +1792,9 @@ edit_write_stream (WEdit * edit, FILE * f)
|
||||
}
|
||||
else
|
||||
{ /* (c == '\n' || c == '\r') */
|
||||
unsigned char c1 = edit_get_byte (edit, i + 1); /* next char */
|
||||
unsigned char c1;
|
||||
|
||||
c1 = edit_buffer_get_byte (&edit->buffer, i + 1); /* next char */
|
||||
|
||||
switch (edit->lb)
|
||||
{
|
||||
@ -2026,8 +1883,8 @@ edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsiz
|
||||
|
||||
for (word_start = start_pos; word_start != 0; word_start--, cut_len++)
|
||||
{
|
||||
c1 = edit_get_byte (edit, word_start);
|
||||
c2 = edit_get_byte (edit, word_start - 1);
|
||||
c1 = edit_buffer_get_byte (&edit->buffer, word_start);
|
||||
c2 = edit_buffer_get_byte (&edit->buffer, word_start - 1);
|
||||
|
||||
if (is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n')
|
||||
break;
|
||||
@ -2037,8 +1894,8 @@ edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsiz
|
||||
|
||||
do
|
||||
{
|
||||
c1 = edit_get_byte (edit, word_start + match_expr->len);
|
||||
c2 = edit_get_byte (edit, word_start + match_expr->len + 1);
|
||||
c1 = edit_buffer_get_byte (&edit->buffer, word_start + match_expr->len);
|
||||
c2 = edit_buffer_get_byte (&edit->buffer, word_start + match_expr->len + 1);
|
||||
g_string_append_c (match_expr, c1);
|
||||
}
|
||||
while (!(is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n'));
|
||||
@ -2733,7 +2590,7 @@ edit_delete (WEdit * edit, gboolean byte_delete)
|
||||
/* if byte_delete == TRUE then delete only one byte not multibyte char */
|
||||
if (edit->utf8 && !byte_delete)
|
||||
{
|
||||
edit_get_utf (edit, edit->buffer.curs1, &cw);
|
||||
edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &cw);
|
||||
if (cw < 1)
|
||||
cw = 1;
|
||||
}
|
||||
@ -2805,7 +2662,7 @@ edit_backspace (WEdit * edit, gboolean byte_delete)
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8 && !byte_delete)
|
||||
{
|
||||
edit_get_prev_utf (edit, edit->buffer.curs1, &cw);
|
||||
edit_buffer_get_prev_utf (&edit->buffer, edit->buffer.curs1, &cw);
|
||||
if (cw < 1)
|
||||
cw = 1;
|
||||
}
|
||||
@ -2873,7 +2730,7 @@ edit_cursor_move (WEdit * edit, off_t increment)
|
||||
|
||||
edit_push_undo_action (edit, CURS_RIGHT);
|
||||
|
||||
c = edit_get_byte (edit, edit->buffer.curs1 - 1);
|
||||
c = edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - 1);
|
||||
if (!((edit->buffer.curs2 + 1) & M_EDIT_BUF_SIZE))
|
||||
edit->buffer.buffers2[(edit->buffer.curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
|
||||
edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE -
|
||||
@ -2904,7 +2761,7 @@ edit_cursor_move (WEdit * edit, off_t increment)
|
||||
|
||||
edit_push_undo_action (edit, CURS_LEFT);
|
||||
|
||||
c = edit_get_byte (edit, edit->buffer.curs1);
|
||||
c = edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1);
|
||||
if (!(edit->buffer.curs1 & M_EDIT_BUF_SIZE))
|
||||
edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
|
||||
edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE][edit->buffer.curs1 & M_EDIT_BUF_SIZE] = c;
|
||||
@ -2938,7 +2795,7 @@ edit_eol (const WEdit * edit, off_t current)
|
||||
if (current >= edit->last_byte)
|
||||
return edit->last_byte;
|
||||
|
||||
for (; edit_get_byte (edit, current) != '\n'; current++)
|
||||
for (; edit_buffer_get_byte (&edit->buffer, current) != '\n'; current++)
|
||||
;
|
||||
|
||||
return current;
|
||||
@ -2953,7 +2810,7 @@ edit_bol (const WEdit * edit, off_t current)
|
||||
if (current <= 0)
|
||||
return 0;
|
||||
|
||||
for (; edit_get_byte (edit, current - 1) != '\n'; current--)
|
||||
for (; edit_buffer_get_byte (&edit->buffer, current - 1) != '\n'; current--)
|
||||
;
|
||||
|
||||
return current;
|
||||
@ -2971,7 +2828,7 @@ edit_count_lines (const WEdit * edit, off_t current, off_t upto)
|
||||
if (current < 0)
|
||||
current = 0;
|
||||
while (current < upto)
|
||||
if (edit_get_byte (edit, current++) == '\n')
|
||||
if (edit_buffer_get_byte (&edit->buffer, current++) == '\n')
|
||||
lines++;
|
||||
return lines;
|
||||
}
|
||||
@ -3048,7 +2905,7 @@ edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto)
|
||||
return p - 1;
|
||||
}
|
||||
|
||||
orig_c = c = edit_get_byte (edit, p);
|
||||
orig_c = c = edit_buffer_get_byte (&edit->buffer, p);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
@ -3056,7 +2913,7 @@ edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto)
|
||||
int utf_ch;
|
||||
int cw = 1;
|
||||
|
||||
utf_ch = edit_get_utf (edit, p, &cw);
|
||||
utf_ch = edit_buffer_get_utf (&edit->buffer, p, &cw);
|
||||
if (mc_global.utf8_display)
|
||||
{
|
||||
if (cw > 1)
|
||||
@ -3349,8 +3206,8 @@ edit_mark_current_word_cmd (WEdit * edit)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
c1 = edit_get_byte (edit, pos);
|
||||
c2 = edit_get_byte (edit, pos - 1);
|
||||
c1 = edit_buffer_get_byte (&edit->buffer, pos);
|
||||
c2 = edit_buffer_get_byte (&edit->buffer, pos - 1);
|
||||
if (!isspace (c1) && isspace (c2))
|
||||
break;
|
||||
if ((my_type_of (c1) & my_type_of (c2)) == 0)
|
||||
@ -3362,8 +3219,8 @@ edit_mark_current_word_cmd (WEdit * edit)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
c1 = edit_get_byte (edit, pos);
|
||||
c2 = edit_get_byte (edit, pos + 1);
|
||||
c1 = edit_buffer_get_byte (&edit->buffer, pos);
|
||||
c2 = edit_buffer_get_byte (&edit->buffer, pos + 1);
|
||||
if (!isspace (c1) && isspace (c2))
|
||||
break;
|
||||
if ((my_type_of (c1) & my_type_of (c2)) == 0)
|
||||
@ -3394,10 +3251,10 @@ edit_delete_line (WEdit * edit)
|
||||
{
|
||||
/*
|
||||
* Delete right part of the line.
|
||||
* Note that edit_get_byte() returns '\n' when byte position is
|
||||
* Note that edit_buffer_get_byte() returns '\n' when byte position is
|
||||
* beyond EOF.
|
||||
*/
|
||||
while (edit_get_byte (edit, edit->buffer.curs1) != '\n')
|
||||
while (edit_buffer_get_current_byte (&edit->buffer) != '\n')
|
||||
(void) edit_delete (edit, TRUE);
|
||||
|
||||
/*
|
||||
@ -3409,9 +3266,9 @@ edit_delete_line (WEdit * edit)
|
||||
|
||||
/*
|
||||
* Delete left part of the line.
|
||||
* Note, that edit_get_byte() returns '\n' when byte position is < 0.
|
||||
* Note, that edit_buffer_get_byte() returns '\n' when byte position is < 0.
|
||||
*/
|
||||
while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n')
|
||||
while (edit_buffer_get_previous_byte (&edit->buffer) != '\n')
|
||||
(void) edit_backspace (edit, TRUE);
|
||||
}
|
||||
|
||||
@ -3423,7 +3280,7 @@ edit_indent_width (const WEdit * edit, off_t p)
|
||||
off_t q = p;
|
||||
|
||||
/* move to the end of the leading whitespace of the line */
|
||||
while (strchr ("\t ", edit_get_byte (edit, q)) && q < edit->last_byte - 1)
|
||||
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, q)) && q < edit->last_byte - 1)
|
||||
q++;
|
||||
/* count the number of columns of indentation */
|
||||
return (long) edit_move_forward3 (edit, p, 0, q);
|
||||
@ -3636,7 +3493,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
||||
#ifdef HAVE_CHARSET
|
||||
if (!mc_global.utf8_display || edit->charpoint == 0)
|
||||
#endif
|
||||
if (edit_get_byte (edit, edit->buffer.curs1) != '\n')
|
||||
if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
|
||||
|
||||
edit_delete (edit, FALSE);
|
||||
}
|
||||
@ -3745,7 +3602,8 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
||||
edit->over_col--;
|
||||
else if (option_backspace_through_tabs && is_in_indent (edit))
|
||||
{
|
||||
while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n' && edit->buffer.curs1 > 0)
|
||||
while (edit_buffer_get_previous_byte (&edit->buffer) != '\n'
|
||||
&& edit->buffer.curs1 > 0)
|
||||
edit_backspace (edit, TRUE);
|
||||
}
|
||||
else if (option_fake_half_tabs && is_in_indent (edit) && right_of_four_spaces (edit))
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
@ -84,6 +85,35 @@
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Get pointer to byte at specified index
|
||||
*
|
||||
* @param buf pointer to editor buffer
|
||||
* @param byte_index byte index
|
||||
*
|
||||
* @return NULL if byte_index is negative or larger than file size; pointer to byte otherwise.
|
||||
*/
|
||||
|
||||
static char *
|
||||
edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index)
|
||||
{
|
||||
unsigned char *b;
|
||||
|
||||
if (byte_index >= (buf->curs1 + buf->curs2) || byte_index < 0)
|
||||
return NULL;
|
||||
|
||||
if (byte_index >= buf->curs1)
|
||||
{
|
||||
off_t p;
|
||||
|
||||
p = buf->curs1 + buf->curs2 - byte_index - 1;
|
||||
b = buf->buffers2[p >> S_EDIT_BUF_SIZE];
|
||||
return (char *) &b[EDIT_BUF_SIZE - 1 - (p & M_EDIT_BUF_SIZE)];
|
||||
}
|
||||
|
||||
b = buf->buffers1[byte_index >> S_EDIT_BUF_SIZE];
|
||||
return (char *) &b[byte_index & M_EDIT_BUF_SIZE];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
@ -124,3 +154,147 @@ edit_buffer_clean (edit_buffer_t * buf)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Get byte at specified index
|
||||
*
|
||||
* @param buf pointer to editor buffer
|
||||
* @param byte_index byte index
|
||||
*
|
||||
* @return '\n' if byte_index is negative or larger than file size; byte at byte_index otherwise.
|
||||
*/
|
||||
|
||||
int
|
||||
edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = edit_buffer_get_byte_ptr (buf, byte_index);
|
||||
|
||||
return (p != NULL) ? *(unsigned char *) p : '\n';
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
/**
|
||||
* Get utf-8 symbol at specified index
|
||||
*
|
||||
* @param buf pointer to editor buffer
|
||||
* @param byte_index byte index
|
||||
* @param char_width width of returned symbol
|
||||
*
|
||||
* @return '\n' if byte_index is negative or larger than file size;
|
||||
* 0 if utf-8 symbol at specified index is invalid;
|
||||
* utf-8 symbol otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
gunichar res;
|
||||
gunichar ch;
|
||||
gchar *next_ch = NULL;
|
||||
|
||||
if (byte_index >= (buf->curs1 + buf->curs2) || byte_index < 0)
|
||||
{
|
||||
*char_width = 0;
|
||||
return '\n';
|
||||
}
|
||||
|
||||
str = edit_buffer_get_byte_ptr (buf, byte_index);
|
||||
if (str == NULL)
|
||||
{
|
||||
*char_width = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
if (res == (gunichar) (-2) || res == (gunichar) (-1))
|
||||
{
|
||||
/* Retry with explicit bytes to make sure it's not a buffer boundary */
|
||||
size_t i;
|
||||
gchar utf8_buf[UTF8_CHAR_LEN + 1];
|
||||
|
||||
for (i = 0; i < UTF8_CHAR_LEN; i++)
|
||||
utf8_buf[i] = edit_buffer_get_byte (buf, byte_index + i);
|
||||
utf8_buf[i] = '\0';
|
||||
res = g_utf8_get_char_validated (utf8_buf, -1);
|
||||
}
|
||||
|
||||
if (res == (gunichar) (-2) || res == (gunichar) (-1))
|
||||
{
|
||||
ch = *str;
|
||||
*char_width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = res;
|
||||
/* Calculate UTF-8 char width */
|
||||
next_ch = g_utf8_next_char (str);
|
||||
if (next_ch != NULL)
|
||||
*char_width = next_ch - str;
|
||||
else
|
||||
{
|
||||
ch = 0;
|
||||
*char_width = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) ch;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Get utf-8 symbol before specified index
|
||||
*
|
||||
* @param buf pointer to editor buffer
|
||||
* @param byte_index byte index
|
||||
* @param char_width width of returned symbol
|
||||
*
|
||||
* @return 0 if byte_index is negative or larger than file size;
|
||||
* 1-byte value before specified index if utf-8 symbol before specified index is invalid;
|
||||
* utf-8 symbol otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width)
|
||||
{
|
||||
size_t i;
|
||||
gchar utf8_buf[3 * UTF8_CHAR_LEN + 1];
|
||||
gchar *str;
|
||||
gchar *cursor_buf_ptr;
|
||||
gunichar res;
|
||||
|
||||
if (byte_index > (buf->curs1 + buf->curs2) || byte_index <= 0)
|
||||
{
|
||||
*char_width = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < (3 * UTF8_CHAR_LEN); i++)
|
||||
utf8_buf[i] = edit_buffer_get_byte (buf, byte_index + i - (2 * UTF8_CHAR_LEN));
|
||||
utf8_buf[i] = '\0';
|
||||
|
||||
cursor_buf_ptr = utf8_buf + (2 * UTF8_CHAR_LEN);
|
||||
str = g_utf8_find_prev_char (utf8_buf, cursor_buf_ptr);
|
||||
|
||||
if (str == NULL || g_utf8_next_char (str) != cursor_buf_ptr)
|
||||
{
|
||||
*char_width = 1;
|
||||
return *(cursor_buf_ptr - 1);
|
||||
}
|
||||
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
if (res == (gunichar) (-2) || res == (gunichar) (-1))
|
||||
{
|
||||
*char_width = 1;
|
||||
return *(cursor_buf_ptr - 1);
|
||||
}
|
||||
|
||||
*char_width = cursor_buf_ptr - str;
|
||||
return (int) res;
|
||||
}
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -52,6 +52,28 @@ typedef struct edit_buffer_struct {
|
||||
void edit_buffer_init (edit_buffer_t * buf);
|
||||
void edit_buffer_clean (edit_buffer_t * buf);
|
||||
|
||||
int edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index);
|
||||
#ifdef HAVE_CHARSET
|
||||
int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width);
|
||||
int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width);
|
||||
#endif
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
static inline int
|
||||
edit_buffer_get_current_byte (const edit_buffer_t * buf)
|
||||
{
|
||||
return edit_buffer_get_byte (buf, buf->curs1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline int
|
||||
edit_buffer_get_previous_byte (const edit_buffer_t * buf)
|
||||
{
|
||||
return edit_buffer_get_byte (buf, buf->curs1 - 1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* MC__EDIT_BUFFER_H */
|
||||
|
@ -433,7 +433,7 @@ static gboolean
|
||||
edit_check_newline (WEdit * edit)
|
||||
{
|
||||
return !(option_check_nl_at_eof && edit->last_byte > 0
|
||||
&& edit_get_byte (edit, edit->last_byte - 1) != '\n'
|
||||
&& edit_buffer_get_byte (&edit->buffer, edit->last_byte - 1) != '\n'
|
||||
&& edit_query_dialog2 (_("Warning"),
|
||||
_("The file you are saving is not finished with a newline"),
|
||||
_("C&ontinue"), _("&Cancel")));
|
||||
@ -567,7 +567,7 @@ edit_delete_column_of_text (WEdit * edit)
|
||||
while (q > p)
|
||||
{
|
||||
/* delete line between margins */
|
||||
if (edit_get_byte (edit, edit->buffer.curs1) != '\n')
|
||||
if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
|
||||
edit_delete (edit, TRUE);
|
||||
q--;
|
||||
}
|
||||
@ -712,7 +712,7 @@ edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_po
|
||||
for (i = current_pos; i < max_pos; i++)
|
||||
{
|
||||
current_pos++;
|
||||
if (edit_get_byte (edit, i) == end_string_symbol)
|
||||
if (edit_buffer_get_byte (&edit->buffer, i) == end_string_symbol)
|
||||
break;
|
||||
}
|
||||
|
||||
@ -735,7 +735,7 @@ edit_calculate_end_of_previous_line (WEdit * edit, off_t current_pos, char end_s
|
||||
off_t i;
|
||||
|
||||
for (i = current_pos - 1; i >= 0; i--)
|
||||
if (edit_get_byte (edit, i) == end_string_symbol)
|
||||
if (edit_buffer_get_byte (&edit->buffer, i) == end_string_symbol)
|
||||
break;
|
||||
|
||||
return i;
|
||||
@ -836,7 +836,7 @@ editcmd_find (WEdit * edit, gsize * len)
|
||||
|
||||
/* fix the start and the end of search block positions */
|
||||
if ((edit->search_line_type & AT_START_LINE) != 0
|
||||
&& (start_mark != 0 || edit_get_byte (edit, start_mark - 1) != end_string_symbol))
|
||||
&& (start_mark != 0 || edit_buffer_get_byte (&edit->buffer, start_mark - 1) != end_string_symbol))
|
||||
{
|
||||
start_mark =
|
||||
edit_calculate_start_of_next_line (edit, start_mark, edit->last_byte,
|
||||
@ -844,7 +844,7 @@ editcmd_find (WEdit * edit, gsize * len)
|
||||
}
|
||||
if ((edit->search_line_type & AT_END_LINE) != 0
|
||||
&& (end_mark - 1 != edit->last_byte
|
||||
|| edit_get_byte (edit, end_mark) != end_string_symbol))
|
||||
|| edit_buffer_get_byte (&edit->buffer, end_mark) != end_string_symbol))
|
||||
{
|
||||
end_mark = edit_calculate_end_of_previous_line (edit, end_mark, end_string_symbol);
|
||||
}
|
||||
@ -1049,7 +1049,7 @@ edit_get_block (WEdit * edit, off_t start, off_t finish, off_t * l)
|
||||
off_t x;
|
||||
|
||||
x = edit_move_forward3 (edit, edit_bol (edit, start), 0, start);
|
||||
c = edit_get_byte (edit, start);
|
||||
c = edit_buffer_get_byte (&edit->buffer, start);
|
||||
if ((x >= edit->column1 && x < edit->column2)
|
||||
|| (x >= edit->column2 && x < edit->column1) || c == '\n')
|
||||
{
|
||||
@ -1063,7 +1063,7 @@ edit_get_block (WEdit * edit, off_t start, off_t finish, off_t * l)
|
||||
{
|
||||
*l = finish - start;
|
||||
while (start < finish)
|
||||
*s++ = edit_get_byte (edit, start++);
|
||||
*s++ = edit_buffer_get_byte (&edit->buffer, start++);
|
||||
}
|
||||
*s = '\0';
|
||||
return r;
|
||||
@ -1110,7 +1110,7 @@ pipe_mail (WEdit * edit, char *to, char *subject, char *cc)
|
||||
{
|
||||
off_t i;
|
||||
for (i = 0; i < edit->last_byte; i++)
|
||||
fputc (edit_get_byte (edit, i), p);
|
||||
fputc (edit_buffer_get_byte (&edit->buffer, i), p);
|
||||
pclose (p);
|
||||
}
|
||||
}
|
||||
@ -1128,7 +1128,7 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
|
||||
if (edit->buffer.curs1 <= 0)
|
||||
return FALSE;
|
||||
|
||||
c = edit_get_byte (edit, edit->buffer.curs1 - 1);
|
||||
c = edit_buffer_get_previous_byte (&edit->buffer);
|
||||
/* return if not at end or in word */
|
||||
if (is_break_char (c))
|
||||
return FALSE;
|
||||
@ -1141,7 +1141,7 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
|
||||
return FALSE;
|
||||
|
||||
last = c;
|
||||
c = edit_get_byte (edit, edit->buffer.curs1 - i);
|
||||
c = edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - i);
|
||||
|
||||
if (is_break_char (c))
|
||||
{
|
||||
@ -1185,7 +1185,7 @@ edit_collect_completions_get_current_word (WEdit * edit, mc_search_t * srch, off
|
||||
{
|
||||
int chr;
|
||||
|
||||
chr = edit_get_byte (edit, word_start + i);
|
||||
chr = edit_buffer_get_byte (&edit->buffer, word_start + i);
|
||||
if (!isspace (chr))
|
||||
g_string_append_c (temp, chr);
|
||||
}
|
||||
@ -1240,7 +1240,7 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
|
||||
/* add matched completion if not yet added */
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
skip = edit_get_byte (edit, start + i);
|
||||
skip = edit_buffer_get_byte (&edit->buffer, start + i);
|
||||
if (isspace (skip))
|
||||
continue;
|
||||
|
||||
@ -1330,7 +1330,7 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
|
||||
long l;
|
||||
off_t p;
|
||||
|
||||
if (edit_get_byte (edit, edit->buffer.curs1) != '\n')
|
||||
if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
|
||||
{
|
||||
for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width)
|
||||
edit_insert (edit, ' ');
|
||||
@ -1344,7 +1344,7 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
if (edit_get_byte (edit, p) == '\n')
|
||||
if (edit_buffer_get_byte (&edit->buffer, p) == '\n')
|
||||
{
|
||||
p++;
|
||||
break;
|
||||
@ -2705,7 +2705,7 @@ edit_replace_cmd (WEdit * edit, int again)
|
||||
mc_search_cbret_t
|
||||
edit_search_cmd_callback (const void *user_data, gsize char_offset, int *current_char)
|
||||
{
|
||||
*current_char = edit_get_byte ((WEdit *) user_data, (off_t) char_offset);
|
||||
*current_char = edit_buffer_get_byte (&((WEdit *) user_data)->buffer, (off_t) char_offset);
|
||||
return MC_SEARCH_CB_OK;
|
||||
}
|
||||
|
||||
@ -2888,7 +2888,7 @@ edit_save_block (WEdit * edit, const char *filename, off_t start, off_t finish)
|
||||
{
|
||||
end = min (finish, start + TEMP_BUF_LEN);
|
||||
for (; i < end; i++)
|
||||
buf[i - start] = edit_get_byte (edit, i);
|
||||
buf[i - start] = edit_buffer_get_byte (&edit->buffer, i);
|
||||
len -= mc_write (file, (char *) buf, end - start);
|
||||
start = end;
|
||||
}
|
||||
@ -3296,7 +3296,7 @@ edit_complete_word_cmd (WEdit * edit)
|
||||
/* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */
|
||||
match_expr = g_string_new ("(^|\\s+|\\b)");
|
||||
for (i = 0; i < word_len; i++)
|
||||
g_string_append_c (match_expr, edit_get_byte (edit, word_start + i));
|
||||
g_string_append_c (match_expr, edit_buffer_get_byte (&edit->buffer, word_start + i));
|
||||
g_string_append (match_expr,
|
||||
"[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+");
|
||||
|
||||
@ -3475,7 +3475,7 @@ edit_get_match_keyword_cmd (WEdit * edit)
|
||||
/* prepare match expression */
|
||||
match_expr = g_string_sized_new (word_len);
|
||||
for (i = 0; i < word_len; i++)
|
||||
g_string_append_c (match_expr, edit_get_byte (edit, word_start + i));
|
||||
g_string_append_c (match_expr, edit_buffer_get_byte (&edit->buffer, word_start + i));
|
||||
|
||||
ptr = g_get_current_dir ();
|
||||
path = g_strconcat (ptr, G_DIR_SEPARATOR_S, (char *) NULL);
|
||||
@ -3609,7 +3609,7 @@ edit_spellcheck_file (WEdit * edit)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
c2 = edit_get_byte (edit, edit->buffer.curs1);
|
||||
c2 = edit_buffer_get_current_byte (&edit->buffer);
|
||||
|
||||
do
|
||||
{
|
||||
@ -3618,7 +3618,7 @@ edit_spellcheck_file (WEdit * edit)
|
||||
|
||||
c1 = c2;
|
||||
edit_cursor_move (edit, 1);
|
||||
c2 = edit_get_byte (edit, edit->buffer.curs1);
|
||||
c2 = edit_buffer_get_current_byte (&edit->buffer);
|
||||
}
|
||||
while (is_break_char (c1) || is_break_char (c2));
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ status_string (WEdit * edit, char *s, int w)
|
||||
unsigned int cur_utf = 0;
|
||||
int cw = 1;
|
||||
|
||||
cur_utf = edit_get_utf (edit, edit->buffer.curs1, &cw);
|
||||
cur_utf = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &cw);
|
||||
if (cw > 0)
|
||||
{
|
||||
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
|
||||
@ -130,7 +130,7 @@ status_string (WEdit * edit, char *s, int w)
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_utf = edit_get_byte (edit, edit->buffer.curs1);
|
||||
cur_utf = edit_buffer_get_current_byte (&edit->buffer);
|
||||
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
|
||||
(int) cur_utf, (unsigned) cur_utf);
|
||||
}
|
||||
@ -140,7 +140,7 @@ status_string (WEdit * edit, char *s, int w)
|
||||
{
|
||||
unsigned char cur_byte = 0;
|
||||
|
||||
cur_byte = edit_get_byte (edit, edit->buffer.curs1);
|
||||
cur_byte = edit_buffer_get_current_byte (&edit->buffer);
|
||||
g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
|
||||
(int) cur_byte, (unsigned) cur_byte);
|
||||
}
|
||||
@ -311,9 +311,9 @@ edit_status_window (WEdit * edit)
|
||||
unsigned int cur_utf;
|
||||
int cw = 1;
|
||||
|
||||
cur_utf = edit_get_utf (edit, edit->buffer.curs1, &cw);
|
||||
cur_utf = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &cw);
|
||||
if (cw <= 0)
|
||||
cur_utf = edit_get_byte (edit, edit->buffer.curs1);
|
||||
cur_utf = edit_buffer_get_current_byte (&edit->buffer);
|
||||
tty_printf ("[%05d 0x%04X]", cur_utf, cur_utf);
|
||||
}
|
||||
#endif
|
||||
@ -321,7 +321,7 @@ edit_status_window (WEdit * edit)
|
||||
{
|
||||
unsigned char cur_byte;
|
||||
|
||||
cur_byte = edit_get_byte (edit, edit->buffer.curs1);
|
||||
cur_byte = edit_buffer_get_current_byte (&edit->buffer);
|
||||
tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte);
|
||||
}
|
||||
}
|
||||
@ -570,7 +570,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
|
||||
if (tty_use_colors () && visible_tws)
|
||||
{
|
||||
tws = edit_eol (edit, b);
|
||||
while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t'))
|
||||
while (tws > b && ((c = edit_buffer_get_byte (&edit->buffer, tws - 1)) == ' ' || c == '\t'))
|
||||
tws--;
|
||||
}
|
||||
|
||||
@ -607,14 +607,11 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
{
|
||||
c = edit_get_utf (edit, q, &cw);
|
||||
}
|
||||
c = edit_buffer_get_utf (&edit->buffer, q, &cw);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
c = edit_get_byte (edit, q);
|
||||
}
|
||||
c = edit_buffer_get_byte (&edit->buffer, q);
|
||||
|
||||
/* we don't use bg for mc - fg contains both */
|
||||
if (book_mark)
|
||||
{
|
||||
|
@ -9,6 +9,7 @@
|
||||
Paul Sheer, 1998
|
||||
Egmont Koblinger <egmont@gmail.com>, 2010
|
||||
Slava Zanko <slavazanko@gmail.com>, 2013
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2013
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -221,7 +222,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
|
||||
if (*text == '\0')
|
||||
return -1;
|
||||
|
||||
c = xx_tolower (edit, edit_get_byte (edit, i - 1));
|
||||
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i - 1));
|
||||
if ((line_start != 0 && c != '\n') || (whole_left != NULL && strchr (whole_left, c) != NULL))
|
||||
return -1;
|
||||
|
||||
@ -234,7 +235,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
|
||||
return -1;
|
||||
while (TRUE)
|
||||
{
|
||||
c = xx_tolower (edit, edit_get_byte (edit, i));
|
||||
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
|
||||
if (*p == '\0' && whole_right != NULL && strchr (whole_right, c) == NULL)
|
||||
break;
|
||||
if (c == *p)
|
||||
@ -250,7 +251,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
|
||||
j = 0;
|
||||
while (TRUE)
|
||||
{
|
||||
c = xx_tolower (edit, edit_get_byte (edit, i));
|
||||
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
|
||||
if (c == *p)
|
||||
{
|
||||
j = i;
|
||||
@ -282,7 +283,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
|
||||
while (TRUE)
|
||||
{
|
||||
d = c;
|
||||
c = xx_tolower (edit, edit_get_byte (edit, i));
|
||||
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
|
||||
for (j = 0; p[j] != SYNTAX_TOKEN_BRACKET && p[j]; j++)
|
||||
if (c == p[j])
|
||||
goto found_char2;
|
||||
@ -301,7 +302,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
|
||||
case SYNTAX_TOKEN_BRACE:
|
||||
if (++p > q)
|
||||
return -1;
|
||||
c = xx_tolower (edit, edit_get_byte (edit, i));
|
||||
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
|
||||
for (; *p != SYNTAX_TOKEN_BRACE && *p; p++)
|
||||
if (c == *p)
|
||||
goto found_char3;
|
||||
@ -311,12 +312,12 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
|
||||
p++;
|
||||
break;
|
||||
default:
|
||||
if (*p != xx_tolower (edit, edit_get_byte (edit, i)))
|
||||
if (*p != xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i)))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return (whole_right != NULL &&
|
||||
strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL) ? -1 : i;
|
||||
strchr (whole_right, xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i))) != NULL) ? -1 : i;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -344,7 +345,7 @@ 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_get_byte (edit, i));
|
||||
c = xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i));
|
||||
if (c == 0)
|
||||
return;
|
||||
|
||||
@ -353,7 +354,7 @@ apply_rules_going_right (WEdit * edit, off_t i)
|
||||
/* check to turn off a keyword */
|
||||
if (_rule.keyword != 0)
|
||||
{
|
||||
if (edit_get_byte (edit, i - 1) == '\n')
|
||||
if (edit_buffer_get_byte (&edit->buffer, i - 1) == '\n')
|
||||
_rule.keyword = 0;
|
||||
if (is_end)
|
||||
{
|
||||
@ -1374,7 +1375,7 @@ get_first_editor_line (WEdit * edit)
|
||||
|
||||
for (i = 0; i < sizeof (s) - 1; i++)
|
||||
{
|
||||
s[i] = edit_get_byte (edit, i);
|
||||
s[i] = edit_buffer_get_byte (&edit->buffer, i);
|
||||
if (s[i] == '\n')
|
||||
{
|
||||
s[i] = '\0';
|
||||
|
@ -86,7 +86,7 @@ line_start (WEdit * edit, long line)
|
||||
p = edit_move_forward (edit, p, line - l, 0);
|
||||
|
||||
p = edit_bol (edit, p);
|
||||
while (strchr ("\t ", edit_get_byte (edit, p)))
|
||||
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)))
|
||||
p++;
|
||||
return p;
|
||||
}
|
||||
@ -97,19 +97,20 @@ static int
|
||||
bad_line_start (WEdit * edit, off_t p)
|
||||
{
|
||||
int c;
|
||||
c = edit_get_byte (edit, p);
|
||||
|
||||
c = edit_buffer_get_byte (&edit->buffer, p);
|
||||
if (c == '.')
|
||||
{ /* '...' is acceptable */
|
||||
if (edit_get_byte (edit, p + 1) == '.')
|
||||
if (edit_get_byte (edit, p + 2) == '.')
|
||||
return 0;
|
||||
{ /* `...' is acceptable */
|
||||
if (edit_buffer_get_byte (&edit->buffer, p + 1) == '.'
|
||||
&& edit_buffer_get_byte (&edit->buffer, p + 2) == '.')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
if (c == '-')
|
||||
{
|
||||
if (edit_get_byte (edit, p + 1) == '-')
|
||||
if (edit_get_byte (edit, p + 2) == '-')
|
||||
return 0; /* '---' is acceptable */
|
||||
if (edit_buffer_get_byte (&edit->buffer, p + 1) == '-'
|
||||
&& edit_buffer_get_byte (&edit->buffer, p + 2) == '-')
|
||||
return 0; /* `---' is acceptable */
|
||||
return 1;
|
||||
}
|
||||
if (strchr (NO_FORMAT_CHARS_START, c))
|
||||
@ -190,11 +191,10 @@ get_paragraph (WEdit * edit, off_t p, off_t q, int indent, int *size)
|
||||
return NULL;
|
||||
for (s = t; p < q; p++, s++)
|
||||
{
|
||||
if (indent)
|
||||
if (edit_get_byte (edit, p - 1) == '\n')
|
||||
while (strchr ("\t ", edit_get_byte (edit, p)))
|
||||
p++;
|
||||
*s = edit_get_byte (edit, p);
|
||||
if (indent && edit_buffer_get_byte (&edit->buffer, p - 1) == '\n')
|
||||
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)))
|
||||
p++;
|
||||
*s = edit_buffer_get_byte (&edit->buffer, p);
|
||||
}
|
||||
*size = (unsigned long) (s - t);
|
||||
/* FIXME: all variables related to 'size' should be fixed */
|
||||
@ -365,7 +365,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
|
||||
|
||||
cursor = edit->buffer.curs1;
|
||||
if (indent)
|
||||
while (strchr ("\t ", edit_get_byte (edit, p)))
|
||||
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)))
|
||||
p++;
|
||||
for (i = 0; i < size; i++, p++)
|
||||
{
|
||||
@ -373,7 +373,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
|
||||
{
|
||||
if (t[i - 1] == '\n' && c == '\n')
|
||||
{
|
||||
while (strchr ("\t ", edit_get_byte (edit, p)))
|
||||
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)))
|
||||
p++;
|
||||
}
|
||||
else if (t[i - 1] == '\n')
|
||||
@ -389,7 +389,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
|
||||
else if (c == '\n')
|
||||
{
|
||||
edit_cursor_move (edit, p - edit->buffer.curs1);
|
||||
while (strchr ("\t ", edit_get_byte (edit, p)))
|
||||
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)))
|
||||
{
|
||||
edit_delete (edit, TRUE);
|
||||
if (cursor > edit->buffer.curs1)
|
||||
@ -398,7 +398,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
|
||||
p = edit->buffer.curs1;
|
||||
}
|
||||
}
|
||||
c = edit_get_byte (edit, p);
|
||||
c = edit_buffer_get_byte (&edit->buffer, p);
|
||||
if (c != t[i])
|
||||
replace_at (edit, p, t[i]);
|
||||
}
|
||||
@ -417,9 +417,9 @@ test_indent (const WEdit * edit, off_t p, off_t q)
|
||||
return 0;
|
||||
|
||||
for (; p < q; p++)
|
||||
if (edit_get_byte (edit, p - 1) == '\n')
|
||||
if (indent != edit_indent_width (edit, p))
|
||||
return 0;
|
||||
if (edit_buffer_get_byte (&edit->buffer, p - 1) == '\n'
|
||||
&& indent != edit_indent_width (edit, p))
|
||||
return 0;
|
||||
return indent;
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,9 @@ START_PARAMETRIZED_TEST (test_autocomplete, test_autocomplete_ds)
|
||||
{
|
||||
int chr;
|
||||
|
||||
chr = edit_get_byte (test_edit, data->input_completed_word_start_pos + i++);
|
||||
chr =
|
||||
edit_buffer_get_byte (&test_edit->buffer,
|
||||
data->input_completed_word_start_pos + i++);
|
||||
if (isspace (chr))
|
||||
break;
|
||||
g_string_append_c (actual_completed_str, chr);
|
||||
@ -336,7 +338,9 @@ START_PARAMETRIZED_TEST (test_autocomplete_single, test_autocomplete_single_ds)
|
||||
{
|
||||
int chr;
|
||||
|
||||
chr = edit_get_byte (test_edit, data->input_completed_word_start_pos + i++);
|
||||
chr =
|
||||
edit_buffer_get_byte (&test_edit->buffer,
|
||||
data->input_completed_word_start_pos + i++);
|
||||
if (isspace (chr))
|
||||
break;
|
||||
g_string_append_c (actual_completed_str, chr);
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user