summaryrefslogtreecommitdiffstats
path: root/src/editor
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:11:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:11:49 +0000
commit1b88cd5ee8510e90e69f885bfd730ce57621781c (patch)
treeb6b33bd695258f68c68824029c279d660ee4b85e /src/editor
parentAdding upstream version 3:4.8.30. (diff)
downloadmc-upstream.tar.xz
mc-upstream.zip
Adding upstream version 3:4.8.31.upstream/3%4.8.31upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/editor')
-rw-r--r--src/editor/Makefile.in2
-rw-r--r--src/editor/bookmark.c2
-rw-r--r--src/editor/edit-impl.h4
-rw-r--r--src/editor/edit.c266
-rw-r--r--src/editor/editbuffer.c2
-rw-r--r--src/editor/editcmd.c167
-rw-r--r--src/editor/editcomplete.c2
-rw-r--r--src/editor/editdraw.c14
-rw-r--r--src/editor/editmacros.c2
-rw-r--r--src/editor/editmenu.c2
-rw-r--r--src/editor/editoptions.c2
-rw-r--r--src/editor/editsearch.c19
-rw-r--r--src/editor/editwidget.c12
-rw-r--r--src/editor/etags.c2
-rw-r--r--src/editor/format.c2
-rw-r--r--src/editor/spell.c2
-rw-r--r--src/editor/syntax.c118
17 files changed, 341 insertions, 279 deletions
diff --git a/src/editor/Makefile.in b/src/editor/Makefile.in
index b20d678..ffef1a0 100644
--- a/src/editor/Makefile.in
+++ b/src/editor/Makefile.in
@@ -137,7 +137,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
$(top_srcdir)/m4.include/vfs/mc-vfs-sfs.m4 \
$(top_srcdir)/m4.include/vfs/mc-vfs-ftp.m4 \
$(top_srcdir)/m4.include/vfs/mc-vfs-sftp.m4 \
- $(top_srcdir)/m4.include/vfs/mc-vfs-fish.m4 \
+ $(top_srcdir)/m4.include/vfs/mc-vfs-shell.m4 \
$(top_srcdir)/m4.include/vfs/mc-vfs-undelfs.m4 \
$(top_srcdir)/m4.include/vfs/mc-vfs-tarfs.m4 \
$(top_srcdir)/m4.include/vfs/mc-vfs-cpiofs.m4 \
diff --git a/src/editor/bookmark.c b/src/editor/bookmark.c
index d530660..040a01b 100644
--- a/src/editor/bookmark.c
+++ b/src/editor/bookmark.c
@@ -1,7 +1,7 @@
/*
Editor book mark handling
- Copyright (C) 2001-2023
+ Copyright (C) 2001-2024
Free Software Foundation, Inc.
Written by:
diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h
index 3d00545..98472ee 100644
--- a/src/editor/edit-impl.h
+++ b/src/editor/edit-impl.h
@@ -141,7 +141,7 @@ WEdit *edit_find_editor (const WDialog * h);
gboolean edit_widget_is_editor (const Widget * w);
gboolean edit_drop_hotkey_menu (WDialog * h, int key);
void edit_menu_cmd (WDialog * h);
-void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
+void edit_user_menu (WEdit * edit, const char *menu_file, int selected_entry);
void edit_init_menu (WMenuBar * menubar);
void edit_save_mode_cmd (void);
off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto);
@@ -163,7 +163,7 @@ void edit_set_codeset (WEdit * edit);
void edit_block_copy_cmd (WEdit * edit);
void edit_block_move_cmd (WEdit * edit);
-int edit_block_delete_cmd (WEdit * edit);
+gboolean edit_block_delete_cmd (WEdit * edit);
void edit_delete_line (WEdit * edit);
int edit_delete (WEdit * edit, gboolean byte_delete);
diff --git a/src/editor/edit.c b/src/editor/edit.c
index dc3b322..2eceeed 100644
--- a/src/editor/edit.c
+++ b/src/editor/edit.c
@@ -1,7 +1,7 @@
/*
Editor low level data handling and cursor fundamentals.
- Copyright (C) 1996-2023
+ Copyright (C) 1996-2024
Free Software Foundation, Inc.
Written by:
@@ -142,6 +142,7 @@ static const struct edit_filters
{ "lz4 -cd %s 2>&1", "lz4 > %s", ".lz4" },
{ "lzip -cd %s 2>&1", "lzip > %s", ".lz"},
{ "lzma -cd %s 2>&1", "lzma > %s", ".lzma" },
+ { "lzop -cd %s 2>&1", "lzop > %s", ".lzo"},
{ "bzip2 -cd %s 2>&1", "bzip2 > %s", ".bz2" },
{ "gzip -cd %s 2>&1", "gzip > %s", ".gz" },
{ "gzip -cd %s 2>&1", "gzip > %s", ".Z" }
@@ -262,15 +263,20 @@ static char *
edit_get_filter (const vfs_path_t * filename_vpath)
{
int i;
- char *p, *quoted_name;
+ char *quoted_name;
+ char *p = NULL;
i = edit_find_filter (filename_vpath);
if (i < 0)
return NULL;
quoted_name = name_quote (vfs_path_as_str (filename_vpath), FALSE);
- p = g_strdup_printf (all_filters[i].read, quoted_name);
- g_free (quoted_name);
+ if (quoted_name != NULL)
+ {
+ p = g_strdup_printf (all_filters[i].read, quoted_name);
+ g_free (quoted_name);
+ }
+
return p;
}
@@ -479,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')
@@ -503,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));
}
@@ -637,7 +645,7 @@ edit_modification (WEdit * edit)
edit->caches_valid = FALSE;
/* raise lock when file modified */
- if (!edit->modified && !edit->delete_file)
+ if (edit->modified == 0 && edit->delete_file == 0)
edit->locked = lock_file (edit->filename_vpath);
edit->modified = 1;
}
@@ -679,12 +687,12 @@ is_blank (const edit_buffer_t * buf, off_t offset)
off_t s, f;
s = edit_buffer_get_bol (buf, offset);
- f = edit_buffer_get_eol (buf, offset) - 1;
- while (s <= f)
+ f = edit_buffer_get_eol (buf, offset);
+ for (; s < f; s++)
{
int c;
- c = edit_buffer_get_byte (buf, s++);
+ c = edit_buffer_get_byte (buf, s);
if (!isspace (c))
return FALSE;
}
@@ -697,7 +705,8 @@ is_blank (const edit_buffer_t * buf, off_t offset)
static off_t
edit_find_line (WEdit * edit, long line)
{
- long i, j = 0;
+ long i;
+ long j = 0;
long m = 2000000000; /* what is the magic number? */
if (!edit->caches_valid)
@@ -874,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;
@@ -886,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;
@@ -897,8 +912,8 @@ edit_cursor_to_eol (WEdit * edit)
static unsigned long
my_type_of (int c)
{
- unsigned long x, r = 0;
- const char *p, *q;
+ unsigned long r = 0;
+ const char *q;
const char chars_move_whole_word[] =
"!=&|<>^~ !:;, !'!`!.?!\"!( !) !{ !} !Aa0 !+-*/= |<> ![ !] !\\#! ";
@@ -918,16 +933,21 @@ my_type_of (int c)
else if (isspace (c))
c = ' ';
q = strchr (chars_move_whole_word, c);
- if (!q)
+ if (q == NULL)
return 0xFFFFFFFFUL;
+
do
{
+ unsigned long x;
+ const char *p;
+
for (x = 1, p = chars_move_whole_word; p < q; p++)
if (*p == '!')
x <<= 1;
r |= x;
}
- while ((q = strchr (q + 1, c)));
+ while ((q = strchr (q + 1, c)) != NULL);
+
return r;
}
@@ -949,8 +969,10 @@ edit_left_word_move (WEdit * edit, int s)
if (edit->buffer.curs1 == 0)
break;
c1 = edit_buffer_get_previous_byte (&edit->buffer);
+ if (c1 == '\n')
+ break;
c2 = edit_buffer_get_current_byte (&edit->buffer);
- if (c1 == '\n' || c2 == '\n')
+ if (c2 == '\n')
break;
if ((my_type_of (c1) & my_type_of (c2)) == 0)
break;
@@ -988,8 +1010,10 @@ edit_right_word_move (WEdit * edit, int s)
if (edit->buffer.curs1 >= edit->buffer.size)
break;
c1 = edit_buffer_get_previous_byte (&edit->buffer);
+ if (c1 == '\n')
+ break;
c2 = edit_buffer_get_current_byte (&edit->buffer);
- if (c1 == '\n' || c2 == '\n')
+ if (c2 == '\n')
break;
if ((my_type_of (c1) & my_type_of (c2)) == 0)
break;
@@ -1118,8 +1142,10 @@ edit_right_delete_word (WEdit * edit)
int c1, c2;
c1 = edit_delete (edit, TRUE);
+ if (c1 == '\n')
+ break;
c2 = edit_buffer_get_current_byte (&edit->buffer);
- if (c1 == '\n' || c2 == '\n')
+ if (c2 == '\n')
break;
if ((isspace (c1) == 0) != (isspace (c2) == 0))
break;
@@ -1138,8 +1164,10 @@ edit_left_delete_word (WEdit * edit)
int c1, c2;
c1 = edit_backspace (edit, TRUE);
+ if (c1 == '\n')
+ break;
c2 = edit_buffer_get_previous_byte (&edit->buffer);
- if (c1 == '\n' || c2 == '\n')
+ if (c2 == '\n')
break;
if ((isspace (c1) == 0) != (isspace (c2) == 0))
break;
@@ -1162,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:
@@ -1199,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)
{
@@ -1249,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:
@@ -1284,19 +1316,17 @@ 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++)
+ if (count++ != 0)
edit->force |= REDRAW_PAGE;
}
@@ -1326,6 +1356,7 @@ edit_group_undo (WEdit * edit)
{
long ac = KEY_PRESS;
long cur_ac = KEY_PRESS;
+
while (ac != STACK_BOTTOM && ac == cur_ac)
{
cur_ac = get_prev_undo_action (edit);
@@ -1374,7 +1405,8 @@ is_aligned_on_a_tab (WEdit * edit)
static gboolean
right_of_four_spaces (WEdit * edit)
{
- int i, ch = 0;
+ int i;
+ int ch = 0;
for (i = 1; i <= HALF_TAB_SIZE; i++)
ch |= edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - i);
@@ -1442,14 +1474,8 @@ insert_spaces_tab (WEdit * edit, gboolean half)
if (half)
i /= 2;
if (i != 0)
- {
- i = ((edit->curs_col / i) + 1) * i - edit->curs_col;
- while (i > 0)
- {
+ for (i = ((edit->curs_col / i) + 1) * i - edit->curs_col; i > 0; i -= space_width)
edit_insert (edit, ' ');
- i -= space_width;
- }
- }
}
/* --------------------------------------------------------------------------------------------- */
@@ -1609,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))
{
@@ -1616,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)
@@ -1687,10 +1716,10 @@ edit_move_block_to_left (WEdit * edit)
static size_t
edit_print_string (WEdit * e, const char *s)
{
- size_t i = 0;
+ size_t i;
- while (s[i] != '\0')
- edit_execute_cmd (e, CK_InsertChar, (unsigned char) s[i++]);
+ for (i = 0; s[i] != '\0'; i++)
+ edit_execute_cmd (e, CK_InsertChar, (unsigned char) s[i]);
e->force |= REDRAW_COMPLETELY;
edit_update_screen (e);
return i;
@@ -1772,10 +1801,10 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t *
/** User edit menu, like user menu (F2) but only in editor. */
void
-user_menu (WEdit * edit, const char *menu_file, int selected_entry)
+edit_user_menu (WEdit * edit, const char *menu_file, int selected_entry)
{
char *block_file;
- gboolean nomark;
+ gboolean mark;
off_t curs;
off_t start_mark, end_mark;
struct stat status;
@@ -1784,27 +1813,27 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
block_file = mc_config_get_full_path (EDIT_HOME_BLOCK_FILE);
block_file_vpath = vfs_path_from_str (block_file);
curs = edit->buffer.curs1;
- nomark = !eval_marks (edit, &start_mark, &end_mark);
- if (!nomark)
+ mark = eval_marks (edit, &start_mark, &end_mark);
+ if (mark)
edit_save_block (edit, block_file, start_mark, end_mark);
/* run shell scripts from menu */
if (user_menu_cmd (CONST_WIDGET (edit), menu_file, selected_entry)
&& (mc_stat (block_file_vpath, &status) == 0) && (status.st_size != 0))
{
- int rc = 0;
+ gboolean rc = FALSE;
FILE *fd;
/* i.e. we have marked block */
- if (!nomark)
+ if (mark)
rc = edit_block_delete_cmd (edit);
- if (rc == 0)
+ if (!rc)
{
off_t ins_len;
ins_len = edit_insert_file (edit, block_file_vpath);
- if (!nomark && ins_len > 0)
+ if (mark && ins_len > 0)
edit_set_markers (edit, start_mark, start_mark + ins_len, 0, 0);
}
/* truncate block file */
@@ -1827,7 +1856,8 @@ edit_get_write_filter (const vfs_path_t * write_name_vpath, const vfs_path_t * f
{
int i;
const char *write_name;
- char *p, *write_name_quoted;
+ char *write_name_quoted;
+ char *p = NULL;
i = edit_find_filter (filename_vpath);
if (i < 0)
@@ -1835,8 +1865,11 @@ edit_get_write_filter (const vfs_path_t * write_name_vpath, const vfs_path_t * f
write_name = vfs_path_get_last_path_str (write_name_vpath);
write_name_quoted = name_quote (write_name, FALSE);
- p = g_strdup_printf (all_filters[i].write, write_name_quoted);
- g_free (write_name_quoted);
+ if (write_name_quoted != NULL)
+ {
+ p = g_strdup_printf (all_filters[i].write, write_name_quoted);
+ g_free (write_name_quoted);
+ }
return p;
}
@@ -1950,7 +1983,7 @@ edit_write_stream (WEdit * edit, FILE * f)
gboolean
is_break_char (char c)
{
- return (isspace (c) || strchr ("{}[]()<>=|/\\!?~-+`'\",.;:#$%^&*", c));
+ return (isspace (c) || strchr ("{}[]()<>=|/\\!?~-+`'\",.;:#$%^&*", c) != NULL);
}
/* --------------------------------------------------------------------------------------------- */
@@ -2006,7 +2039,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
{
int file;
off_t blocklen;
- int vertical_insertion = 0;
+ gboolean vertical_insertion = FALSE;
char *buf;
file = mc_open (filename_vpath, O_RDONLY | O_BINARY);
@@ -2019,7 +2052,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
{
/* if contain signature VERTICAL_MAGIC then it vertical block */
if (memcmp (buf, VERTICAL_MAGIC, sizeof (VERTICAL_MAGIC)) == 0)
- vertical_insertion = 1;
+ vertical_insertion = TRUE;
else
mc_lseek (file, 0, SEEK_SET);
}
@@ -2377,6 +2410,7 @@ edit_push_undo_action (WEdit * edit, long c)
&& ((sp - 2) & edit->undo_stack_size_mask) != edit->undo_stack_bottom)
{
long d;
+
if (edit->undo_stack[spm1] < 0)
{
d = edit->undo_stack[(sp - 2) & edit->undo_stack_size_mask];
@@ -2457,6 +2491,7 @@ edit_push_redo_action (WEdit * edit, long c)
&& ((sp - 2) & edit->redo_stack_size_mask) != edit->redo_stack_bottom)
{
long d;
+
if (edit->redo_stack[spm1] < 0)
{
d = edit->redo_stack[(sp - 2) & edit->redo_stack_size_mask];
@@ -2848,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);
}
/* --------------------------------------------------------------------------------------------- */
@@ -2867,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);
}
/* --------------------------------------------------------------------------------------------- */
@@ -2900,7 +2939,6 @@ edit_scroll_upward (WEdit * edit, long i)
edit_update_curs_row (edit);
}
-
/* --------------------------------------------------------------------------------------------- */
void
@@ -2956,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;
@@ -2974,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
@@ -2996,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);
+ }
}
}
}
@@ -3069,6 +3111,71 @@ edit_set_markers (WEdit * edit, off_t m1, off_t m2, long c1, long c2)
edit->column2 = c2;
}
+/* --------------------------------------------------------------------------------------------- */
+/**
+ if mark2 is -1 then marking is from mark1 to the cursor.
+ Otherwise its between the markers. This handles this.
+ Returns FALSE if no text is marked.
+ */
+
+gboolean
+eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark)
+{
+ long end_mark_curs;
+
+ if (edit->mark1 == edit->mark2)
+ {
+ *start_mark = *end_mark = 0;
+ edit->column2 = edit->column1 = 0;
+ return FALSE;
+ }
+
+ if (edit->end_mark_curs < 0)
+ end_mark_curs = edit->buffer.curs1;
+ else
+ end_mark_curs = edit->end_mark_curs;
+
+ if (edit->mark2 >= 0)
+ {
+ *start_mark = MIN (edit->mark1, edit->mark2);
+ *end_mark = MAX (edit->mark1, edit->mark2);
+ }
+ else
+ {
+ *start_mark = MIN (edit->mark1, end_mark_curs);
+ *end_mark = MAX (edit->mark1, end_mark_curs);
+ edit->column2 = edit->curs_col + edit->over_col;
+ }
+
+ if (edit->column_highlight
+ && ((edit->mark1 > end_mark_curs && edit->column1 < edit->column2)
+ || (edit->mark1 < end_mark_curs && edit->column1 > edit->column2)))
+ {
+ off_t start_bol, start_eol;
+ off_t end_bol, end_eol;
+ long col1, col2;
+ off_t diff1, diff2;
+
+ start_bol = edit_buffer_get_bol (&edit->buffer, *start_mark);
+ start_eol = edit_buffer_get_eol (&edit->buffer, start_bol - 1) + 1;
+ end_bol = edit_buffer_get_bol (&edit->buffer, *end_mark);
+ end_eol = edit_buffer_get_eol (&edit->buffer, *end_mark);
+ col1 = MIN (edit->column1, edit->column2);
+ col2 = MAX (edit->column1, edit->column2);
+
+ diff1 = edit_move_forward3 (edit, start_bol, col2, 0) -
+ edit_move_forward3 (edit, start_bol, col1, 0);
+ diff2 = edit_move_forward3 (edit, end_bol, col2, 0) -
+ edit_move_forward3 (edit, end_bol, col1, 0);
+
+ *start_mark -= diff1;
+ *end_mark += diff2;
+ *start_mark = MAX (*start_mark, start_eol);
+ *end_mark = MIN (*end_mark, end_eol);
+ }
+
+ return TRUE;
+}
/* --------------------------------------------------------------------------------------------- */
/** highlight marker toggle */
@@ -3364,7 +3471,6 @@ edit_execute_cmd (WEdit * edit, long command, int char_for_insertion)
if (!mc_global.utf8_display || edit->charpoint == 0)
#endif
if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
-
edit_delete (edit, FALSE);
}
if (edit_options.cursor_beyond_eol && edit->over_col > 0)
@@ -3378,7 +3484,7 @@ edit_execute_cmd (WEdit * edit, long command, int char_for_insertion)
&& !mc_global.utf8_display)
{
unsigned char str[UTF8_CHAR_LEN + 1];
- size_t i = 0;
+ size_t i;
int res;
res = g_unichar_to_utf8 (char_for_insertion, (char *) str);
@@ -3388,14 +3494,12 @@ edit_execute_cmd (WEdit * edit, long command, int char_for_insertion)
str[1] = '\0';
}
else
- {
str[res] = '\0';
- }
- while (i <= UTF8_CHAR_LEN && str[i] != '\0')
+
+ for (i = 0; i <= UTF8_CHAR_LEN && str[i] != '\0'; i++)
{
char_for_insertion = str[i];
edit_insert (edit, char_for_insertion);
- i++;
}
}
else
@@ -3920,7 +4024,7 @@ edit_execute_cmd (WEdit * edit, long command, int char_for_insertion)
edit_goto_matching_bracket (edit);
break;
case CK_UserMenu:
- user_menu (edit, NULL, -1);
+ edit_user_menu (edit, NULL, -1);
break;
case CK_Sort:
edit_sort_cmd (edit);
diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c
index 24bc7ee..acc776a 100644
--- a/src/editor/editbuffer.c
+++ b/src/editor/editbuffer.c
@@ -1,7 +1,7 @@
/*
Editor text keep buffer.
- Copyright (C) 2013-2023
+ Copyright (C) 2013-2024
Free Software Foundation, Inc.
Written by:
diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c
index de624f2..bca9df7 100644
--- a/src/editor/editcmd.c
+++ b/src/editor/editcmd.c
@@ -1,7 +1,7 @@
/*
Editor high level editing commands
- Copyright (C) 1996-2023
+ Copyright (C) 1996-2024
Free Software Foundation, Inc.
Written by:
@@ -460,22 +460,23 @@ edit_save_cmd (WEdit * edit)
/* --------------------------------------------------------------------------------------------- */
static void
-edit_delete_column_of_text (WEdit * edit)
+edit_delete_column_of_text (WEdit * edit, off_t m1, off_t m2)
{
- off_t m1, m2;
off_t n;
+ off_t r;
long b, c, d;
- eval_marks (edit, &m1, &m2);
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);
@@ -490,25 +491,22 @@ edit_delete_column_of_text (WEdit * edit)
/* 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);
+ }
}
}
/* --------------------------------------------------------------------------------------------- */
-/** if success return 0 */
+/** if success return TRUE */
-static int
-edit_block_delete (WEdit * edit)
+static gboolean
+edit_block_delete (WEdit * edit, off_t start_mark, off_t end_mark)
{
- off_t start_mark, end_mark;
off_t curs_pos;
long curs_line, c1, c2;
- if (!eval_marks (edit, &start_mark, &end_mark))
- return 0;
-
if (edit->column_highlight && edit->mark2 < 0)
edit_mark_cmd (edit, FALSE);
@@ -517,7 +515,7 @@ edit_block_delete (WEdit * edit)
edit_query_dialog2 (_("Warning"),
("Block is large, you may not be able to undo this action"),
_("C&ontinue"), _("&Cancel")) != 0)
- return 1;
+ return FALSE;
c1 = MIN (edit->column1, edit->column2);
c2 = MAX (edit->column1, edit->column2);
@@ -538,16 +536,18 @@ edit_block_delete (WEdit * edit)
{
if (edit->column_highlight)
{
+ off_t b, e;
off_t line_width;
if (edit->mark2 < 0)
edit_mark_cmd (edit, FALSE);
- edit_delete_column_of_text (edit);
+ edit_delete_column_of_text (edit, start_mark, 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;
}
@@ -563,7 +563,7 @@ edit_block_delete (WEdit * edit)
edit_set_markers (edit, 0, 0, 0, 0);
edit->force |= REDRAW_PAGE;
- return 0;
+ return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
@@ -586,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')
@@ -631,15 +632,28 @@ static void
pipe_mail (const edit_buffer_t * buf, char *to, char *subject, char *cc)
{
FILE *p = 0;
- char *s;
+ char *s = NULL;
to = name_quote (to, FALSE);
- subject = name_quote (subject, FALSE);
- cc = name_quote (cc, FALSE);
- s = g_strconcat ("mail -s ", subject, *cc ? " -c " : "", cc, " ", to, (char *) NULL);
- g_free (to);
- g_free (subject);
- g_free (cc);
+ if (to != NULL)
+ {
+ subject = name_quote (subject, FALSE);
+ if (subject != NULL)
+ {
+ cc = name_quote (cc, FALSE);
+ if (cc == NULL)
+ s = g_strdup_printf ("mail -s %s %s", subject, to);
+ else
+ {
+ s = g_strdup_printf ("mail -s %s -c %s %s", subject, cc, to);
+ g_free (cc);
+ }
+
+ g_free (subject);
+ }
+
+ g_free (to);
+ }
if (s != NULL)
{
@@ -1256,72 +1270,6 @@ edit_close_cmd (WEdit * edit)
}
/* --------------------------------------------------------------------------------------------- */
-/**
- if mark2 is -1 then marking is from mark1 to the cursor.
- Otherwise its between the markers. This handles this.
- Returns FALSE if no text is marked.
- */
-
-gboolean
-eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark)
-{
- long end_mark_curs;
-
- if (edit->mark1 == edit->mark2)
- {
- *start_mark = *end_mark = 0;
- edit->column2 = edit->column1 = 0;
- return FALSE;
- }
-
- if (edit->end_mark_curs < 0)
- end_mark_curs = edit->buffer.curs1;
- else
- end_mark_curs = edit->end_mark_curs;
-
- if (edit->mark2 >= 0)
- {
- *start_mark = MIN (edit->mark1, edit->mark2);
- *end_mark = MAX (edit->mark1, edit->mark2);
- }
- else
- {
- *start_mark = MIN (edit->mark1, end_mark_curs);
- *end_mark = MAX (edit->mark1, end_mark_curs);
- edit->column2 = edit->curs_col + edit->over_col;
- }
-
- if (edit->column_highlight
- && ((edit->mark1 > end_mark_curs && edit->column1 < edit->column2)
- || (edit->mark1 < end_mark_curs && edit->column1 > edit->column2)))
- {
- off_t start_bol, start_eol;
- off_t end_bol, end_eol;
- long col1, col2;
- off_t diff1, diff2;
-
- start_bol = edit_buffer_get_bol (&edit->buffer, *start_mark);
- start_eol = edit_buffer_get_eol (&edit->buffer, start_bol - 1) + 1;
- end_bol = edit_buffer_get_bol (&edit->buffer, *end_mark);
- end_eol = edit_buffer_get_eol (&edit->buffer, *end_mark);
- col1 = MIN (edit->column1, edit->column2);
- col2 = MAX (edit->column1, edit->column2);
-
- diff1 = edit_move_forward3 (edit, start_bol, col2, 0) -
- edit_move_forward3 (edit, start_bol, col1, 0);
- diff2 = edit_move_forward3 (edit, end_bol, col2, 0) -
- edit_move_forward3 (edit, end_bol, col1, 0);
-
- *start_mark -= diff1;
- *end_mark += diff2;
- *start_mark = MAX (*start_mark, start_eol);
- *end_mark = MIN (*end_mark, end_eol);
- }
-
- return TRUE;
-}
-
-/* --------------------------------------------------------------------------------------------- */
void
edit_block_copy_cmd (WEdit * edit)
@@ -1398,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);
@@ -1409,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
@@ -1429,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);
@@ -1443,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);
@@ -1453,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)
@@ -1475,19 +1426,19 @@ edit_block_move_cmd (WEdit * edit)
}
/* --------------------------------------------------------------------------------------------- */
-/** returns 1 if canceelled by user */
+/** returns FALSE if canceelled by user */
-int
+gboolean
edit_block_delete_cmd (WEdit * edit)
{
off_t start_mark, end_mark;
if (eval_marks (edit, &start_mark, &end_mark))
- return edit_block_delete (edit);
+ return edit_block_delete (edit, start_mark, end_mark);
edit_delete_line (edit);
- return 0;
+ return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
@@ -1859,7 +1810,7 @@ edit_sort_cmd (WEdit * edit)
edit->force |= REDRAW_COMPLETELY;
- if (edit_block_delete_cmd (edit))
+ if (!edit_block_delete_cmd (edit))
return 1;
{
@@ -1934,7 +1885,7 @@ edit_block_process_cmd (WEdit * edit, int macro_number)
fname = g_strdup_printf ("%s.%i.sh", EDIT_HOME_MACRO_FILE, macro_number);
macros_fname = g_build_filename (mc_config_get_data_path (), fname, (char *) NULL);
- user_menu (edit, macros_fname, 0);
+ edit_user_menu (edit, macros_fname, 0);
g_free (fname);
g_free (macros_fname);
edit->force |= REDRAW_COMPLETELY;
diff --git a/src/editor/editcomplete.c b/src/editor/editcomplete.c
index 06f304d..f3ea0e7 100644
--- a/src/editor/editcomplete.c
+++ b/src/editor/editcomplete.c
@@ -1,7 +1,7 @@
/*
Editor word completion engine
- Copyright (C) 2021-2023
+ Copyright (C) 2021-2024
Free Software Foundation, Inc.
Written by:
diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c
index fbd1e09..49be571 100644
--- a/src/editor/editdraw.c
+++ b/src/editor/editdraw.c
@@ -1,7 +1,7 @@
/*
Editor text drawing.
- Copyright (C) 1996-2023
+ Copyright (C) 1996-2024
Free Software Foundation, Inc.
Written by:
@@ -448,7 +448,6 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
{
int style;
unsigned int textchar;
- int color;
if (cols_to_skip != 0)
{
@@ -458,8 +457,6 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
style = p->style & 0xFF00;
textchar = p->ch;
- /* If non-printable - use black background */
- color = (style & MOD_ABNORMAL) != 0 ? 0 : p->style >> 16;
if ((style & MOD_WHITESPACE) != 0)
{
@@ -475,8 +472,10 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
tty_setcolor (EDITOR_BOLD_COLOR);
else if ((style & MOD_MARKED) != 0)
tty_setcolor (EDITOR_MARKED_COLOR);
+ else if ((style & MOD_ABNORMAL) != 0)
+ tty_setcolor (EDITOR_NONPRINTABLE_COLOR);
else
- tty_lowlevel_setcolor (color);
+ tty_lowlevel_setcolor (p->style >> 16);
if (edit_options.show_right_margin)
{
@@ -951,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))
diff --git a/src/editor/editmacros.c b/src/editor/editmacros.c
index 8545d67..6c07139 100644
--- a/src/editor/editmacros.c
+++ b/src/editor/editmacros.c
@@ -1,7 +1,7 @@
/*
Editor macros engine
- Copyright (C) 2001-2023
+ Copyright (C) 2001-2024
Free Software Foundation, Inc.
This file is part of the Midnight Commander.
diff --git a/src/editor/editmenu.c b/src/editor/editmenu.c
index 3509fa2..f83742c 100644
--- a/src/editor/editmenu.c
+++ b/src/editor/editmenu.c
@@ -1,7 +1,7 @@
/*
Editor menu definitions and initialisation
- Copyright (C) 1996-2023
+ Copyright (C) 1996-2024
Free Software Foundation, Inc.
Written by:
diff --git a/src/editor/editoptions.c b/src/editor/editoptions.c
index 9e059f3..c81d9b8 100644
--- a/src/editor/editoptions.c
+++ b/src/editor/editoptions.c
@@ -1,7 +1,7 @@
/*
Editor options dialog box
- Copyright (C) 1996-2023
+ Copyright (C) 1996-2024
Free Software Foundation, Inc.
Written by:
diff --git a/src/editor/editsearch.c b/src/editor/editsearch.c
index 1bdf883..4ed5785 100644
--- a/src/editor/editsearch.c
+++ b/src/editor/editsearch.c
@@ -1,7 +1,7 @@
/*
Search & replace engine of MCEditor.
- Copyright (C) 2021-2023
+ Copyright (C) 2021-2024
Free Software Foundation, Inc.
Written by:
@@ -29,7 +29,7 @@
#include "lib/global.h"
#include "lib/search.h"
-#include "lib/mcconfig.h" /* mc_config_history_get */
+#include "lib/mcconfig.h" /* mc_config_history_get_recent_item() */
#ifdef HAVE_CHARSET
#include "lib/charsets.h" /* cp_source */
#endif
@@ -780,16 +780,12 @@ edit_search_cmd (WEdit * edit, gboolean again)
else
{
/* find last search string in history */
- GList *history;
+ char *s;
- history = mc_config_history_get (MC_HISTORY_SHARED_SEARCH);
- if (history != NULL)
+ s = mc_config_history_get_recent_item (MC_HISTORY_SHARED_SEARCH);
+ if (s != NULL)
{
- /* FIXME: is it possible that history->data == NULL? */
- edit->last_search_string = (char *) history->data;
- history->data = NULL;
- history = g_list_first (history);
- g_list_free_full (history, g_free);
+ edit->last_search_string = s;
if (edit_search_init (edit, edit->last_search_string))
{
@@ -877,7 +873,8 @@ edit_replace_cmd (WEdit * edit, gboolean again)
edit->search = NULL;
}
- input2_str = g_string_new (input2);
+ input2_str = g_string_new_take (input2);
+ input2 = NULL;
if (edit->search == NULL)
{
diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c
index 05f03e8..45be31e 100644
--- a/src/editor/editwidget.c
+++ b/src/editor/editwidget.c
@@ -1,7 +1,7 @@
/*
Editor initialisation and callback handler.
- Copyright (C) 1996-2023
+ Copyright (C) 1996-2024
Free Software Foundation, Inc.
Written by:
@@ -152,7 +152,7 @@ edit_about (void)
QUICK_LABEL (N_("A user friendly text editor\n"
"written for the Midnight Commander."), NULL),
QUICK_SEPARATOR (FALSE),
- QUICK_LABEL (N_("Copyright (C) 1996-2023 the Free Software Foundation"), NULL),
+ QUICK_LABEL (N_("Copyright (C) 1996-2024 the Free Software Foundation"), NULL),
QUICK_START_BUTTONS (TRUE, TRUE),
QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
QUICK_END
@@ -182,9 +182,10 @@ edit_about (void)
*/
static void
-edit_help (void)
+edit_help (const WDialog * h)
{
- ev_help_t event_data = { NULL, "[Internal File Editor]" };
+ ev_help_t event_data = { NULL, h->help_ctx };
+
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
@@ -426,8 +427,7 @@ edit_dialog_command_execute (WDialog * h, long command)
dlg_close (h);
break;
case CK_Help:
- edit_help ();
- /* edit->force |= REDRAW_COMPLETELY; */
+ edit_help (h);
break;
case CK_Menu:
edit_menu_cmd (h);
diff --git a/src/editor/etags.c b/src/editor/etags.c
index 7b570d6..ddc5ca8 100644
--- a/src/editor/etags.c
+++ b/src/editor/etags.c
@@ -6,7 +6,7 @@
or, if etags utility not installed:
$ find . -type f -name "*.[ch]" | ctags --c-kinds=+p --fields=+iaS --extra=+q -e -L-
- Copyright (C) 2009-2023
+ Copyright (C) 2009-2024
Free Software Foundation, Inc.
Written by:
diff --git a/src/editor/format.c b/src/editor/format.c
index 3193067..9dc5d72 100644
--- a/src/editor/format.c
+++ b/src/editor/format.c
@@ -1,7 +1,7 @@
/*
Dynamic paragraph formatting.
- Copyright (C) 2011-2023
+ Copyright (C) 2011-2024
Free Software Foundation, Inc.
Copyright (C) 1996 Paul Sheer
diff --git a/src/editor/spell.c b/src/editor/spell.c
index aeb0884..9d26345 100644
--- a/src/editor/spell.c
+++ b/src/editor/spell.c
@@ -1,7 +1,7 @@
/*
Editor spell checker
- Copyright (C) 2012-2023
+ Copyright (C) 2012-2024
Free Software Foundation, Inc.
Written by:
diff --git a/src/editor/syntax.c b/src/editor/syntax.c
index f95ad2b..4b8116f 100644
--- a/src/editor/syntax.c
+++ b/src/editor/syntax.c
@@ -1,7 +1,7 @@
/*
Editor syntax highlighting.
- Copyright (C) 1996-2023
+ Copyright (C) 1996-2024
Free Software Foundation, Inc.
Written by:
@@ -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;
@@ -801,44 +812,44 @@ get_args (char *l, char **args, int args_size)
/* --------------------------------------------------------------------------------------------- */
static int
-this_try_alloc_color_pair (const char *fg, const char *bg, const char *attrs)
+this_try_alloc_color_pair (tty_color_pair_t * color)
{
char f[80], b[80], a[80], *p;
- if (bg != NULL && *bg == '\0')
- bg = NULL;
- if (fg != NULL && *fg == '\0')
- fg = NULL;
- if (attrs != NULL && *attrs == '\0')
- attrs = NULL;
+ if (color->bg != NULL && *color->bg == '\0')
+ color->bg = NULL;
+ if (color->fg != NULL && *color->fg == '\0')
+ color->fg = NULL;
+ if (color->attrs != NULL && *color->attrs == '\0')
+ color->attrs = NULL;
- if ((fg == NULL) && (bg == NULL))
+ if (color->fg == NULL && color->bg == NULL)
return EDITOR_NORMAL_COLOR;
- if (fg != NULL)
+ if (color->fg != NULL)
{
- g_strlcpy (f, fg, sizeof (f));
+ g_strlcpy (f, color->fg, sizeof (f));
p = strchr (f, '/');
if (p != NULL)
*p = '\0';
- fg = f;
+ color->fg = f;
}
- if (bg != NULL)
+ if (color->bg != NULL)
{
- g_strlcpy (b, bg, sizeof (b));
+ g_strlcpy (b, color->bg, sizeof (b));
p = strchr (b, '/');
if (p != NULL)
*p = '\0';
- bg = b;
+ color->bg = b;
}
- if ((fg == NULL) || (bg == NULL))
+ if (color->fg == NULL || color->bg == NULL)
{
/* get colors from skin */
char *editnormal;
editnormal = mc_skin_get ("editor", "_default_", "default;default");
- if (fg == NULL)
+ if (color->fg == NULL)
{
g_strlcpy (f, editnormal, sizeof (f));
p = strchr (f, ';');
@@ -846,24 +857,24 @@ this_try_alloc_color_pair (const char *fg, const char *bg, const char *attrs)
*p = '\0';
if (f[0] == '\0')
g_strlcpy (f, "default", sizeof (f));
- fg = f;
+ color->fg = f;
}
- if (bg == NULL)
+ if (color->bg == NULL)
{
p = strchr (editnormal, ';');
if ((p != NULL) && (*(++p) != '\0'))
g_strlcpy (b, p, sizeof (b));
else
g_strlcpy (b, "default", sizeof (b));
- bg = b;
+ color->bg = b;
}
g_free (editnormal);
}
- if (attrs != NULL)
+ if (color->attrs != NULL)
{
- g_strlcpy (a, attrs, sizeof (a));
+ g_strlcpy (a, color->attrs, sizeof (a));
p = strchr (a, '/');
if (p != NULL)
*p = '\0';
@@ -871,9 +882,10 @@ this_try_alloc_color_pair (const char *fg, const char *bg, const char *attrs)
p = a;
while ((p = strchr (p, SYNTAX_TOKEN_PLUS)) != NULL)
*p++ = '+';
- attrs = a;
+ color->attrs = a;
}
- return tty_try_alloc_color_pair (fg, bg, attrs);
+
+ return tty_try_alloc_color_pair (color, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
@@ -923,7 +935,7 @@ static int
edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
{
FILE *g = NULL;
- char *fg, *bg, *attrs;
+ tty_color_pair_t color;
char last_fg[32] = "", last_bg[32] = "", last_attrs[64] = "";
char whole_right[512];
char whole_left[512];
@@ -1089,19 +1101,19 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
g_ptr_array_add (c->keyword, k);
no_words = FALSE;
subst_defines (edit->defines, a, &args[ARGS_LEN]);
- fg = *a;
+ color.fg = *a;
if (*a != NULL)
a++;
- bg = *a;
+ color.bg = *a;
if (*a != NULL)
a++;
- attrs = *a;
+ color.attrs = *a;
if (*a != NULL)
a++;
- g_strlcpy (last_fg, fg != NULL ? fg : "", sizeof (last_fg));
- g_strlcpy (last_bg, bg != NULL ? bg : "", sizeof (last_bg));
- g_strlcpy (last_attrs, attrs != NULL ? attrs : "", sizeof (last_attrs));
- k->color = this_try_alloc_color_pair (fg, bg, attrs);
+ g_strlcpy (last_fg, color.fg != NULL ? color.fg : "", sizeof (last_fg));
+ g_strlcpy (last_bg, color.bg != NULL ? color.bg : "", sizeof (last_bg));
+ g_strlcpy (last_attrs, color.attrs != NULL ? color.attrs : "", sizeof (last_attrs));
+ k->color = this_try_alloc_color_pair (&color);
k->keyword = g_string_new (" ");
check_not_a;
}
@@ -1153,22 +1165,22 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
k->keyword = g_string_new (*a++);
subst_defines (edit->defines, a, &args[ARGS_LEN]);
- fg = *a;
+ color.fg = *a;
if (*a != NULL)
a++;
- bg = *a;
+ color.bg = *a;
if (*a != NULL)
a++;
- attrs = *a;
+ color.attrs = *a;
if (*a != NULL)
a++;
- if (fg == NULL)
- fg = last_fg;
- if (bg == NULL)
- bg = last_bg;
- if (attrs == NULL)
- attrs = last_attrs;
- k->color = this_try_alloc_color_pair (fg, bg, attrs);
+ if (color.fg == NULL)
+ color.fg = last_fg;
+ if (color.bg == NULL)
+ color.bg = last_bg;
+ if (color.attrs == NULL)
+ color.attrs = last_attrs;
+ k->color = this_try_alloc_color_pair (&color);
check_not_a;
}
else if (*(args[0]) == '#')
@@ -1481,7 +1493,7 @@ edit_free_syntax_rules (WEdit * edit)
g_ptr_array_free (edit->rules, TRUE);
edit->rules = NULL;
g_clear_slist (&edit->syntax_marker, g_free);
- tty_color_free_all_tmp ();
+ tty_color_free_temp ();
}
/* --------------------------------------------------------------------------------------------- */