From f3dc8142e8b8c0508bd8b2bb998c0b540160e328 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 6 Feb 2013 10:07:05 +0400 Subject: [PATCH 01/25] Ticket #1743: remove limit of file size in mcedit. Initial commit: refactoring: * (edit_load_file_fast): always load whole file. * (edit_load_file): don't ignore result of edit_load_file_fast(). Signed-off-by: Andrew Borodin --- src/editor/edit.c | 48 ++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index a8364a130..e713c4e5e 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -202,9 +202,6 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) int file = -1; gboolean ret = FALSE; - edit->curs2 = edit->last_byte; - buf2 = edit->curs2 >> S_EDIT_BUF_SIZE; - file = mc_open (filename_vpath, O_RDONLY | O_BINARY); if (file == -1) { @@ -217,28 +214,31 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) return FALSE; } - if (!edit->buffers2[buf2]) + edit->curs2 = edit->last_byte; + buf2 = edit->curs2 >> S_EDIT_BUF_SIZE; + + if (edit->buffers2[buf2] == NULL) edit->buffers2[buf2] = g_malloc0 (EDIT_BUF_SIZE); - do + if (mc_read (file, + (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - + (edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE) < 0) + goto done; + + for (buf = buf2 - 1; buf >= 0; buf--) { - if (mc_read (file, - (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - - (edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE) < 0) - break; - - for (buf = buf2 - 1; buf >= 0; buf--) - { - /* edit->buffers2[0] is already allocated */ - if (!edit->buffers2[buf]) - edit->buffers2[buf] = g_malloc0 (EDIT_BUF_SIZE); - if (mc_read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) < 0) - break; - } - ret = TRUE; + /* edit->buffers2[0] is already allocated */ + if (edit->buffers2[buf] == NULL) + edit->buffers2[buf] = g_malloc0 (EDIT_BUF_SIZE); + if (mc_read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) < 0) + goto done; } - while (FALSE); + edit->total_lines = edit_count_lines (edit, 0, edit->last_byte); + + ret = TRUE; + + done: if (!ret) { gchar *errmsg; @@ -435,9 +435,11 @@ edit_load_file (WEdit * edit) if (fast_load) { edit->last_byte = edit->stat1.st_size; - edit_load_file_fast (edit, edit->filename_vpath); - /* If fast load was used, the number of lines wasn't calculated */ - edit->total_lines = edit_count_lines (edit, 0, edit->last_byte); + if (!edit_load_file_fast (edit, edit->filename_vpath)) + { + edit_clean (edit); + return FALSE; + } } else { From 23c2df198cacc1182518501b44f5910873262e75 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 7 Feb 2013 15:05:34 +0400 Subject: [PATCH 02/25] (edit_move_updown): avoid extra search of multi-byte character start. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index e713c4e5e..78cb6a965 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -1151,12 +1151,15 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi edit_move_to_prev_col (edit, p); +#ifdef HAVE_CHARSET /* search start of current multibyte char (like CJK) */ - if (edit->curs1 + 1 < edit->last_byte) + if (edit->curs1 > 0 && edit->curs1 + 1 < edit->last_byte + && edit_get_byte (edit, edit->curs1) >= 256 ) { edit_right_char_move_cmd (edit); edit_left_char_move_cmd (edit); } +#endif edit->search_start = edit->curs1; edit->found_len = 0; From f56de22de5cdb1133d77981896633a7465b53844 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 15 Feb 2013 13:02:00 +0400 Subject: [PATCH 03/25] Start of edit buffers refactoring. Move buffers to separate class. Signed-off-by: Andrew Borodin --- src/editor/Makefile.am | 3 +- src/editor/edit-impl.h | 27 --- src/editor/edit.c | 381 +++++++++++++++++++--------------------- src/editor/editbuffer.c | 87 +++++++++ src/editor/editbuffer.h | 54 ++++++ src/editor/editcmd.c | 114 ++++++------ src/editor/editdraw.c | 38 ++-- src/editor/editwidget.c | 6 +- src/editor/editwidget.h | 6 +- src/editor/wordproc.c | 31 ++-- 10 files changed, 417 insertions(+), 330 deletions(-) create mode 100644 src/editor/editbuffer.c create mode 100644 src/editor/editbuffer.h diff --git a/src/editor/Makefile.am b/src/editor/Makefile.am index 0f03de1de..0ca0fc5c5 100644 --- a/src/editor/Makefile.am +++ b/src/editor/Makefile.am @@ -9,8 +9,9 @@ endif libedit_la_SOURCES = \ bookmark.c \ choosesyntax.c \ - edit.c edit.h \ edit-impl.h \ + edit.c edit.h \ + editbuffer.c editbuffer.h \ editcmd.c \ editcmd_dialogs.c editcmd_dialogs.h \ editdraw.c \ diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index a2f5a9308..ae6aa555c 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -39,33 +39,6 @@ #define EDIT_TOP_EXTREME option_edit_top_extreme #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme -/* - * The editor keeps data in two arrays of buffers. - * All buffers have the same size, which must be a power of 2. - */ - -/* Configurable: log2 of the buffer size in bytes */ -#ifndef S_EDIT_BUF_SIZE -#define S_EDIT_BUF_SIZE 16 -#endif - -/* Size of the buffer */ -#define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE) - -/* Buffer mask (used to find cursor position relative to the buffer) */ -#define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1) - -/* - * Configurable: Maximal allowed number of buffers in each buffer array. - * This number can be increased for systems with enough physical memory. - */ -#ifndef MAXBUFF -#define MAXBUFF 1024 -#endif - -/* Maximal length of file that can be opened */ -#define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2)) - /* Initial size of the undo stack, in bytes */ #define START_STACK_SIZE 32 diff --git a/src/editor/edit.c b/src/editor/edit.c index 78cb6a965..d5d0403fe 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -135,37 +135,8 @@ static const struct edit_filters /* *INDENT-ON* */ }; -/*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ - -/*- - * - * here's a quick sketch of the layout: (don't run this through indent.) - * - * (b1 is buffers1 and b2 is buffers2) - * - * | - * \0\0\0\0\0m e _ f i l e . \nf i n . \n|T h i s _ i s _ s o\0\0\0\0\0\0\0\0\0 - * ______________________________________|______________________________________ - * | - * ... | b2[2] | b2[1] | b2[0] | b1[0] | b1[1] | b1[2] | ... - * |-> |-> |-> |-> |-> |-> | - * | - * _<------------------------->|<----------------->_ - * WEdit->curs2 | WEdit->curs1 - * ^ | ^ - * | ^|^ | - * cursor ||| cursor - * ||| - * file end|||file beginning - * | - * | - * - * _ - * This_is_some_file - * fin. - */ - +/*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ /** * Initialize the buffers for an empty files. @@ -178,13 +149,13 @@ edit_init_buffers (WEdit * edit) for (j = 0; j <= MAXBUFF; j++) { - edit->buffers1[j] = NULL; - edit->buffers2[j] = NULL; + edit->buffer.buffers1[j] = NULL; + edit->buffer.buffers2[j] = NULL; } - edit->curs1 = 0; - edit->curs2 = 0; - edit->buffers2[0] = g_malloc0 (EDIT_BUF_SIZE); + edit->buffer.curs1 = 0; + edit->buffer.curs2 = 0; + edit->buffer.buffers2[0] = g_malloc0 (EDIT_BUF_SIZE); } /* --------------------------------------------------------------------------------------------- */ @@ -214,23 +185,23 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) return FALSE; } - edit->curs2 = edit->last_byte; - buf2 = edit->curs2 >> S_EDIT_BUF_SIZE; + edit->buffer.curs2 = edit->last_byte; + buf2 = edit->buffer.curs2 >> S_EDIT_BUF_SIZE; - if (edit->buffers2[buf2] == NULL) - edit->buffers2[buf2] = g_malloc0 (EDIT_BUF_SIZE); + if (edit->buffer.buffers2[buf2] == NULL) + edit->buffer.buffers2[buf2] = g_malloc0 (EDIT_BUF_SIZE); if (mc_read (file, - (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - - (edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE) < 0) + (char *) edit->buffer.buffers2[buf2] + EDIT_BUF_SIZE - + (edit->buffer.curs2 & M_EDIT_BUF_SIZE), edit->buffer.curs2 & M_EDIT_BUF_SIZE) < 0) goto done; for (buf = buf2 - 1; buf >= 0; buf--) { - /* edit->buffers2[0] is already allocated */ - if (edit->buffers2[buf] == NULL) - edit->buffers2[buf] = g_malloc0 (EDIT_BUF_SIZE); - if (mc_read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) < 0) + /* edit->buffer.buffers2[0] is already allocated */ + if (edit->buffer.buffers2[buf] == NULL) + edit->buffer.buffers2[buf] = g_malloc0 (EDIT_BUF_SIZE); + if (mc_read (file, (char *) edit->buffer.buffers2[buf], EDIT_BUF_SIZE) < 0) goto done; } @@ -484,12 +455,12 @@ edit_load_position (WEdit * edit) { edit_cursor_move (edit, offset); line = edit->curs_line; - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; } book_mark_restore (edit, BOOK_MARK_COLOR); - edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1)); + edit_move_to_prev_col (edit, edit_bol (edit, edit->buffer.curs1)); edit_move_display (edit, line - (WIDGET (edit)->lines / 2)); } @@ -504,7 +475,7 @@ edit_save_position (WEdit * edit) return; book_mark_serialize (edit, BOOK_MARK_COLOR); - save_file_position (edit->filename_vpath, edit->curs_line + 1, edit->curs_col, edit->curs1, + save_file_position (edit->filename_vpath, edit->curs_line + 1, edit->curs_col, edit->buffer.curs1, edit->serialized_bookmarks); edit->serialized_bookmarks = NULL; } @@ -629,19 +600,19 @@ edit_modification (WEdit * edit) static char * edit_get_byte_ptr (const WEdit * edit, off_t byte_index) { - if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) + if (byte_index >= (edit->buffer.curs1 + edit->buffer.curs2) || byte_index < 0) return NULL; - if (byte_index >= edit->curs1) + if (byte_index >= edit->buffer.curs1) { off_t p; - p = edit->curs1 + edit->curs2 - byte_index - 1; - return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] + + 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->buffers1[byte_index >> S_EDIT_BUF_SIZE] + + return (char *) (edit->buffer.buffers1[byte_index >> S_EDIT_BUF_SIZE] + (byte_index & M_EDIT_BUF_SIZE)); } @@ -656,7 +627,7 @@ edit_get_prev_utf (const WEdit * edit, off_t byte_index, int *char_width) gchar *str; gchar *cursor_buf_ptr; - if (byte_index > (edit->curs1 + edit->curs2) || byte_index <= 0) + if (byte_index > (edit->buffer.curs1 + edit->buffer.curs2) || byte_index <= 0) { *char_width = 0; return 0; @@ -707,7 +678,7 @@ is_in_indent (const WEdit * edit) { off_t p; - for (p = edit_bol (edit, edit->curs1); p < edit->curs1; p++) + for (p = edit_bol (edit, edit->buffer.curs1); p < edit->buffer.curs1; p++) if (strchr (" \t", edit_get_byte (edit, p)) == NULL) return FALSE; @@ -755,7 +726,7 @@ edit_find_line (WEdit * edit, long line) memset (edit->line_offsets, 0, sizeof (edit->line_offsets)); /* three offsets that we *know* are line 0 at 0 and these two: */ edit->line_numbers[1] = edit->curs_line; - edit->line_offsets[1] = edit_bol (edit, edit->curs1); + edit->line_offsets[1] = edit_bol (edit, edit->buffer.curs1); edit->line_numbers[2] = edit->total_lines; edit->line_offsets[2] = edit_bol (edit, edit->last_byte); edit->caches_valid = TRUE; @@ -891,7 +862,7 @@ edit_move_to_top (WEdit * edit) { if (edit->curs_line) { - edit_cursor_move (edit, -edit->curs1); + edit_cursor_move (edit, -edit->buffer.curs1); edit_move_to_prev_col (edit, 0); edit->force |= REDRAW_PAGE; edit->search_start = 0; @@ -922,8 +893,8 @@ edit_move_to_bottom (WEdit * edit) static void edit_cursor_to_bol (WEdit * edit) { - edit_cursor_move (edit, edit_bol (edit, edit->curs1) - edit->curs1); - edit->search_start = edit->curs1; + edit_cursor_move (edit, edit_bol (edit, edit->buffer.curs1) - edit->buffer.curs1); + edit->search_start = edit->buffer.curs1; edit->prev_col = edit_get_col (edit); edit->over_col = 0; } @@ -934,8 +905,8 @@ edit_cursor_to_bol (WEdit * edit) static void edit_cursor_to_eol (WEdit * edit) { - edit_cursor_move (edit, edit_eol (edit, edit->curs1) - edit->curs1); - edit->search_start = edit->curs1; + edit_cursor_move (edit, edit_eol (edit, edit->buffer.curs1) - edit->buffer.curs1); + edit->search_start = edit->buffer.curs1; edit->prev_col = edit_get_col (edit); edit->over_col = 0; } @@ -993,13 +964,13 @@ edit_left_word_move (WEdit * edit, int s) if (edit->column_highlight && edit->mark1 != edit->mark2 - && edit->over_col == 0 && edit->curs1 == edit_bol (edit, edit->curs1)) + && edit->over_col == 0 && edit->buffer.curs1 == edit_bol (edit, edit->buffer.curs1)) break; edit_cursor_move (edit, -1); - if (edit->curs1 == 0) + if (edit->buffer.curs1 == 0) break; - c1 = edit_get_byte (edit, edit->curs1 - 1); - c2 = edit_get_byte (edit, edit->curs1); + c1 = edit_get_byte (edit, edit->buffer.curs1 - 1); + c2 = edit_get_byte (edit, edit->buffer.curs1); if (c1 == '\n' || c2 == '\n') break; if ((my_type_of (c1) & my_type_of (c2)) == 0) @@ -1031,13 +1002,13 @@ edit_right_word_move (WEdit * edit, int s) if (edit->column_highlight && edit->mark1 != edit->mark2 - && edit->over_col == 0 && edit->curs1 == edit_eol (edit, edit->curs1)) + && edit->over_col == 0 && edit->buffer.curs1 == edit_eol (edit, edit->buffer.curs1)) break; edit_cursor_move (edit, 1); - if (edit->curs1 >= edit->last_byte) + if (edit->buffer.curs1 >= edit->last_byte) break; - c1 = edit_get_byte (edit, edit->curs1 - 1); - c2 = edit_get_byte (edit, edit->curs1); + c1 = edit_get_byte (edit, edit->buffer.curs1 - 1); + c2 = edit_get_byte (edit, edit->buffer.curs1); if (c1 == '\n' || c2 == '\n') break; if ((my_type_of (c1) & my_type_of (c2)) == 0) @@ -1068,14 +1039,14 @@ edit_right_char_move_cmd (WEdit * edit) #ifdef HAVE_CHARSET if (edit->utf8) { - c = edit_get_utf (edit, edit->curs1, &cw); + c = edit_get_utf (edit, edit->buffer.curs1, &cw); if (cw < 1) cw = 1; } else #endif { - c = edit_get_byte (edit, edit->curs1); + c = edit_get_byte (edit, edit->buffer.curs1); } if (option_cursor_beyond_eol && c == '\n') { @@ -1096,12 +1067,12 @@ edit_left_char_move_cmd (WEdit * edit) if (edit->column_highlight && option_cursor_beyond_eol && edit->mark1 != edit->mark2 - && edit->over_col == 0 && edit->curs1 == edit_bol (edit, edit->curs1)) + && edit->over_col == 0 && edit->buffer.curs1 == edit_bol (edit, edit->buffer.curs1)) return; #ifdef HAVE_CHARSET if (edit->utf8) { - edit_get_prev_utf (edit, edit->curs1, &cw); + edit_get_prev_utf (edit, edit->buffer.curs1, &cw); if (cw < 1) cw = 1; } @@ -1143,25 +1114,25 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi else edit_scroll_downward (edit, lines); } - p = edit_bol (edit, edit->curs1); + p = edit_bol (edit, edit->buffer.curs1); p = direction ? edit_move_backward (edit, p, lines) : edit_move_forward (edit, p, lines, 0); - edit_cursor_move (edit, p - edit->curs1); + edit_cursor_move (edit, p - edit->buffer.curs1); edit_move_to_prev_col (edit, p); #ifdef HAVE_CHARSET /* search start of current multibyte char (like CJK) */ - if (edit->curs1 > 0 && edit->curs1 + 1 < edit->last_byte - && edit_get_byte (edit, edit->curs1) >= 256 ) + if (edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->last_byte + && edit_get_byte (edit, edit->buffer.curs1) >= 256 ) { edit_right_char_move_cmd (edit); edit_left_char_move_cmd (edit); } #endif - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; edit->found_len = 0; } @@ -1170,12 +1141,12 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi static void edit_right_delete_word (WEdit * edit) { - while (edit->curs1 < edit->last_byte) + while (edit->buffer.curs1 < edit->last_byte) { int c1, c2; c1 = edit_delete (edit, TRUE); - c2 = edit_get_byte (edit, edit->curs1); + c2 = edit_get_byte (edit, edit->buffer.curs1); if (c1 == '\n' || c2 == '\n') break; if ((isspace (c1) == 0) != (isspace (c2) == 0)) @@ -1190,12 +1161,12 @@ edit_right_delete_word (WEdit * edit) static void edit_left_delete_word (WEdit * edit) { - while (edit->curs1 > 0) + while (edit->buffer.curs1 > 0) { int c1, c2; c1 = edit_backspace (edit, TRUE); - c2 = edit_get_byte (edit, edit->curs1 - 1); + c2 = edit_get_byte (edit, edit->buffer.curs1 - 1); if (c1 == '\n' || c2 == '\n') break; if ((isspace (c1) == 0) != (isspace (c2) == 0)) @@ -1389,7 +1360,7 @@ edit_group_undo (WEdit * edit) static void edit_delete_to_line_end (WEdit * edit) { - while (edit_get_byte (edit, edit->curs1) != '\n' && edit->curs2 != 0) + while (edit_get_byte (edit, edit->buffer.curs1) != '\n' && edit->buffer.curs2 != 0) edit_delete (edit, TRUE); } @@ -1398,7 +1369,7 @@ edit_delete_to_line_end (WEdit * edit) static void edit_delete_to_line_begin (WEdit * edit) { - while (edit_get_byte (edit, edit->curs1 - 1) != '\n' && edit->curs1 != 0) + while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n' && edit->buffer.curs1 != 0) edit_backspace (edit, TRUE); } @@ -1422,7 +1393,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->curs1 - i); + ch |= edit_get_byte (edit, edit->buffer.curs1 - i); return (ch == ' ' && is_aligned_on_a_tab (edit)); } @@ -1435,7 +1406,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->curs1 + i); + ch |= edit_get_byte (edit, edit->buffer.curs1 + i); return (ch == ' ' && is_aligned_on_a_tab (edit)); } @@ -1448,7 +1419,7 @@ edit_auto_indent (WEdit * edit) off_t p; char c; - p = edit->curs1; + p = edit->buffer.curs1; /* use the previous line as a template */ p = edit_move_backward (edit, p, 1); /* copy the leading whitespace of the line */ @@ -1467,7 +1438,7 @@ static inline void edit_double_newline (WEdit * edit) { edit_insert (edit, '\n'); - if (edit_get_byte (edit, edit->curs1) == '\n' || edit_get_byte (edit, edit->curs1 - 2) == '\n') + if (edit_get_byte (edit, edit->buffer.curs1) == '\n' || edit_get_byte (edit, edit->buffer.curs1 - 2) == '\n') return; edit->force |= REDRAW_PAGE; edit_insert (edit, '\n'); @@ -1535,7 +1506,7 @@ check_and_wrap_line (WEdit * edit) edit_update_curs_col (edit); if (edit->curs_col < option_word_wrap_line_length) return; - curs = edit->curs1; + curs = edit->buffer.curs1; while (TRUE) { curs--; @@ -1547,10 +1518,10 @@ check_and_wrap_line (WEdit * edit) } if (c == ' ' || c == '\t') { - off_t current = edit->curs1; - edit_cursor_move (edit, curs - edit->curs1 + 1); + off_t current = edit->buffer.curs1; + edit_cursor_move (edit, curs - edit->buffer.curs1 + 1); edit_insert (edit, '\n'); - edit_cursor_move (edit, current - edit->curs1 + 1); + edit_cursor_move (edit, current - edit->buffer.curs1 + 1); return; } } @@ -1574,7 +1545,7 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack unsigned long j = 0; off_t q; edit_update_curs_row (edit); - c = edit_get_byte (edit, edit->curs1); + c = edit_get_byte (edit, edit->buffer.curs1); p = strchr (b, c); /* no limit */ if (!furthest_bracket_search) @@ -1587,7 +1558,7 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack /* going left or right? */ if (strchr ("{[(", c)) inc = 1; - for (q = edit->curs1 + inc;; q += inc) + for (q = edit->buffer.curs1 + inc;; q += inc) { /* out of buffer? */ if (q >= edit->last_byte || q < 0) @@ -1626,9 +1597,9 @@ edit_goto_matching_bracket (WEdit * edit) q = edit_get_bracket (edit, 0, 0); if (q >= 0) { - edit->bracket = edit->curs1; + edit->bracket = edit->buffer.curs1; edit->force |= REDRAW_PAGE; - edit_cursor_move (edit, q - edit->curs1); + edit_cursor_move (edit, q - edit->buffer.curs1); } } @@ -1648,14 +1619,14 @@ edit_move_block_to_right (WEdit * edit) do { - edit_cursor_move (edit, cur_bol - edit->curs1); + edit_cursor_move (edit, cur_bol - edit->buffer.curs1); if (!edit_line_is_blank (edit, edit->curs_line)) { if (option_fill_tabs_with_spaces) insert_spaces_tab (edit, option_fake_half_tabs); else edit_insert (edit, '\t'); - edit_cursor_move (edit, edit_bol (edit, cur_bol) - edit->curs1); + edit_cursor_move (edit, edit_bol (edit, cur_bol) - edit->buffer.curs1); } if (cur_bol == 0) @@ -1688,14 +1659,14 @@ edit_move_block_to_left (WEdit * edit) int del_tab_width; int next_char; - edit_cursor_move (edit, cur_bol - edit->curs1); + edit_cursor_move (edit, cur_bol - edit->buffer.curs1); if (option_fake_half_tabs) del_tab_width = HALF_TAB_SIZE; else del_tab_width = option_tab_spacing; - next_char = edit_get_byte (edit, edit->curs1); + next_char = edit_get_byte (edit, edit->buffer.curs1); if (next_char == '\t') edit_delete (edit, TRUE); else if (next_char == ' ') @@ -1703,7 +1674,7 @@ edit_move_block_to_left (WEdit * edit) { if (next_char == ' ') edit_delete (edit, TRUE); - next_char = edit_get_byte (edit, edit->curs1); + next_char = edit_get_byte (edit, edit->buffer.curs1); } if (cur_bol == 0) @@ -1745,7 +1716,7 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * off_t blocklen = -1, width = 0; unsigned char *data; - cursor = edit->curs1; + cursor = edit->buffer.curs1; col = edit_get_col (edit); data = g_malloc0 (TEMP_BUF_LEN); @@ -1766,15 +1737,15 @@ 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->curs1) != '\n') + if (edit_get_byte (edit, edit->buffer.curs1) != '\n') for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width) edit_insert (edit, ' '); - for (p = edit->curs1;; p++) + for (p = edit->buffer.curs1;; p++) { if (p == edit->last_byte) { - edit_cursor_move (edit, edit->last_byte - edit->curs1); + edit_cursor_move (edit, edit->last_byte - edit->buffer.curs1); edit_insert_ahead (edit, '\n'); p++; break; @@ -1786,7 +1757,7 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * } } - edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1); + edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1); for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) edit_insert (edit, ' '); @@ -1796,8 +1767,8 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * *col1 = col; *col2 = col + width; *start_pos = cursor; - *end_pos = edit->curs1; - edit_cursor_move (edit, cursor - edit->curs1); + *end_pos = edit->buffer.curs1; + edit_cursor_move (edit, cursor - edit->buffer.curs1); g_free (data); return blocklen; @@ -1821,7 +1792,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry) block_file = mc_config_get_full_path (EDIT_BLOCK_FILE); block_file_vpath = vfs_path_from_str (block_file); - curs = edit->curs1; + curs = edit->buffer.curs1; nomark = eval_marks (edit, &start_mark, &end_mark); if (nomark == 0) edit_save_block (edit, block_file, start_mark, end_mark); @@ -1853,7 +1824,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry) g_free (block_file); vfs_path_free (block_file_vpath); - edit_cursor_move (edit, curs - edit->curs1); + edit_cursor_move (edit, curs - edit->buffer.curs1); edit->force |= REDRAW_PAGE; widget_redraw (WIDGET (edit)); } @@ -1883,7 +1854,7 @@ edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width) int width = 0; gchar utf8_buf[UTF8_CHAR_LEN + 1]; - if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) + if (byte_index >= (edit->buffer.curs1 + edit->buffer.curs2) || byte_index < 0) { *char_width = 0; return '\n'; @@ -2112,7 +2083,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath) off_t ins_len = 0; p = edit_get_filter (filename_vpath); - current = edit->curs1; + current = edit->buffer.curs1; if (p != NULL) { @@ -2126,7 +2097,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath) /* Place cursor at the end of text selection */ if (!option_cursor_after_inserted_block) { - ins_len = edit->curs1 - current; + ins_len = edit->buffer.curs1 - current; edit_cursor_move (edit, -ins_len); } if (pclose (f) > 0) @@ -2178,7 +2149,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath) long c1, c2; blocklen = edit_insert_column_from_file (edit, file, &mark1, &mark2, &c1, &c2); - edit_set_markers (edit, edit->curs1, mark2, c1, c2); + edit_set_markers (edit, edit->buffer.curs1, mark2, c1, c2); /* highlight inserted text then not persistent blocks */ if (!option_persistent_selections && edit->modified) @@ -2200,7 +2171,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath) /* highlight inserted text then not persistent blocks */ if (!option_persistent_selections && edit->modified) { - edit_set_markers (edit, edit->curs1, current, 0, 0); + edit_set_markers (edit, edit->buffer.curs1, current, 0, 0); if (edit->column_highlight) edit_push_undo_action (edit, COLUMN_ON); edit->column_highlight = 0; @@ -2209,7 +2180,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath) /* Place cursor at the end of text selection */ if (!option_cursor_after_inserted_block) { - ins_len = edit->curs1 - current; + ins_len = edit->buffer.curs1 - current; edit_cursor_move (edit, -ins_len); } } @@ -2358,8 +2329,8 @@ edit_clean (WEdit * edit) book_mark_flush (edit, -1); for (; j <= MAXBUFF; j++) { - g_free (edit->buffers1[j]); - g_free (edit->buffers2[j]); + g_free (edit->buffer.buffers1[j]); + g_free (edit->buffer.buffers2[j]); } g_free (edit->undo_stack); @@ -2673,7 +2644,7 @@ edit_insert (WEdit * edit, int c) return; /* first we must update the position of the display window */ - if (edit->curs1 < edit->start_display) + if (edit->buffer.curs1 < edit->start_display) { edit->start_display++; if (c == '\n') @@ -2700,23 +2671,23 @@ edit_insert (WEdit * edit, int c) else edit_push_undo_action (edit, BACKSPACE_BR); /* update markers */ - edit->mark1 += (edit->mark1 > edit->curs1); - edit->mark2 += (edit->mark2 > edit->curs1); - edit->last_get_rule += (edit->last_get_rule > edit->curs1); + edit->mark1 += (edit->mark1 > edit->buffer.curs1); + edit->mark2 += (edit->mark2 > edit->buffer.curs1); + edit->last_get_rule += (edit->last_get_rule > edit->buffer.curs1); /* add a new buffer if we've reached the end of the last one */ - if (!(edit->curs1 & M_EDIT_BUF_SIZE)) - edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); + if (!(edit->buffer.curs1 & M_EDIT_BUF_SIZE)) + edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); /* perform the insertion */ - edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] + edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE][edit->buffer.curs1 & M_EDIT_BUF_SIZE] = (unsigned char) c; /* update file length */ edit->last_byte++; /* update cursor position */ - edit->curs1++; + edit->buffer.curs1++; } /* --------------------------------------------------------------------------------------------- */ @@ -2728,7 +2699,7 @@ edit_insert_ahead (WEdit * edit, int c) if (edit->last_byte >= SIZE_LIMIT) return; - if (edit->curs1 < edit->start_display) + if (edit->buffer.curs1 < edit->start_display) { edit->start_display++; if (c == '\n') @@ -2747,17 +2718,17 @@ edit_insert_ahead (WEdit * edit, int c) else edit_push_undo_action (edit, DELCHAR_BR); - edit->mark1 += (edit->mark1 >= edit->curs1); - edit->mark2 += (edit->mark2 >= edit->curs1); - edit->last_get_rule += (edit->last_get_rule >= edit->curs1); + edit->mark1 += (edit->mark1 >= edit->buffer.curs1); + edit->mark2 += (edit->mark2 >= edit->buffer.curs1); + edit->last_get_rule += (edit->last_get_rule >= edit->buffer.curs1); - if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE)) - edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); - edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] - [EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c; + 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 - (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1] = c; edit->last_byte++; - edit->curs2++; + edit->buffer.curs2++; } /* --------------------------------------------------------------------------------------------- */ @@ -2782,14 +2753,14 @@ edit_delete (WEdit * edit, gboolean byte_delete) int cw = 1; int i; - if (edit->curs2 == 0) + if (edit->buffer.curs2 == 0) return 0; #ifdef HAVE_CHARSET /* if byte_delete == TRUE then delete only one byte not multibyte char */ if (edit->utf8 && !byte_delete) { - edit_get_utf (edit, edit->curs1, &cw); + edit_get_utf (edit, edit->buffer.curs1, &cw); if (cw < 1) cw = 1; } @@ -2802,27 +2773,27 @@ edit_delete (WEdit * edit, gboolean byte_delete) for (i = 1; i <= cw; i++) { - if (edit->mark1 > edit->curs1) + if (edit->mark1 > edit->buffer.curs1) { edit->mark1--; edit->end_mark_curs--; } - if (edit->mark2 > edit->curs1) + if (edit->mark2 > edit->buffer.curs1) edit->mark2--; - if (edit->last_get_rule > edit->curs1) + if (edit->last_get_rule > edit->buffer.curs1) edit->last_get_rule--; - p = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - - ((edit->curs2 - + p = edit->buffer.buffers2[(edit->buffer.curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - + ((edit->buffer.curs2 - 1) & M_EDIT_BUF_SIZE) - 1]; - if (!(edit->curs2 & M_EDIT_BUF_SIZE)) + if (!(edit->buffer.curs2 & M_EDIT_BUF_SIZE)) { - g_free (edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE]); - edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = NULL; + g_free (edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE]); + edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE] = NULL; } edit->last_byte--; - edit->curs2--; + edit->buffer.curs2--; edit_push_undo_action (edit, p + 256); } @@ -2833,7 +2804,7 @@ edit_delete (WEdit * edit, gboolean byte_delete) edit->total_lines--; edit->force |= REDRAW_AFTER_CURSOR; } - if (edit->curs1 < edit->start_display) + if (edit->buffer.curs1 < edit->start_display) { edit->start_display--; if (p == '\n') @@ -2852,7 +2823,7 @@ edit_backspace (WEdit * edit, gboolean byte_delete) int cw = 1; int i; - if (edit->curs1 == 0) + if (edit->buffer.curs1 == 0) return 0; if (edit->mark2 != edit->mark1) @@ -2861,7 +2832,7 @@ edit_backspace (WEdit * edit, gboolean byte_delete) #ifdef HAVE_CHARSET if (edit->utf8 && !byte_delete) { - edit_get_prev_utf (edit, edit->curs1, &cw); + edit_get_prev_utf (edit, edit->buffer.curs1, &cw); if (cw < 1) cw = 1; } @@ -2871,25 +2842,25 @@ edit_backspace (WEdit * edit, gboolean byte_delete) for (i = 1; i <= cw; i++) { - if (edit->mark1 >= edit->curs1) + if (edit->mark1 >= edit->buffer.curs1) { edit->mark1--; edit->end_mark_curs--; } - if (edit->mark2 >= edit->curs1) + if (edit->mark2 >= edit->buffer.curs1) edit->mark2--; - if (edit->last_get_rule >= edit->curs1) + if (edit->last_get_rule >= edit->buffer.curs1) edit->last_get_rule--; - p = *(edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE] + - ((edit->curs1 - 1) & M_EDIT_BUF_SIZE)); - if (((edit->curs1 - 1) & M_EDIT_BUF_SIZE) == 0) + p = *(edit->buffer.buffers1[(edit->buffer.curs1 - 1) >> S_EDIT_BUF_SIZE] + + ((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE)); + if (((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE) == 0) { - g_free (edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]); - edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = NULL; + g_free (edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE]); + edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = NULL; } edit->last_byte--; - edit->curs1--; + edit->buffer.curs1--; edit_push_undo_action (edit, p); } edit_modification (edit); @@ -2901,7 +2872,7 @@ edit_backspace (WEdit * edit, gboolean byte_delete) edit->force |= REDRAW_AFTER_CURSOR; } - if (edit->curs1 < edit->start_display) + if (edit->buffer.curs1 < edit->start_display) { edit->start_display--; if (p == '\n') @@ -2924,25 +2895,25 @@ edit_cursor_move (WEdit * edit, off_t increment) { for (; increment < 0; increment++) { - if (edit->curs1 == 0) + if (edit->buffer.curs1 == 0) return; edit_push_undo_action (edit, CURS_RIGHT); - c = edit_get_byte (edit, edit->curs1 - 1); - if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE)) - edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); - edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c; - edit->curs2++; - c = edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->curs1 - + c = edit_get_byte (edit, 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 - + (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1] = c; + edit->buffer.curs2++; + c = edit->buffer.buffers1[(edit->buffer.curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE]; - if (!((edit->curs1 - 1) & M_EDIT_BUF_SIZE)) + if (!((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE)) { - g_free (edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]); - edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = NULL; + g_free (edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE]); + edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = NULL; } - edit->curs1--; + edit->buffer.curs1--; if (c == '\n') { edit->curs_line--; @@ -2955,25 +2926,25 @@ edit_cursor_move (WEdit * edit, off_t increment) { for (; increment > 0; increment--) { - if (edit->curs2 == 0) + if (edit->buffer.curs2 == 0) return; edit_push_undo_action (edit, CURS_LEFT); - c = edit_get_byte (edit, edit->curs1); - if (!(edit->curs1 & M_EDIT_BUF_SIZE)) - edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); - edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] = c; - edit->curs1++; - c = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - - ((edit->curs2 - + c = edit_get_byte (edit, 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; + edit->buffer.curs1++; + c = edit->buffer.buffers2[(edit->buffer.curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - + ((edit->buffer.curs2 - 1) & M_EDIT_BUF_SIZE) - 1]; - if (!(edit->curs2 & M_EDIT_BUF_SIZE)) + if (!(edit->buffer.curs2 & M_EDIT_BUF_SIZE)) { - g_free (edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE]); - edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = 0; + g_free (edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE]); + edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE] = 0; } - edit->curs2--; + edit->buffer.curs2--; if (c == '\n') { edit->curs_line++; @@ -3151,7 +3122,7 @@ edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) long edit_get_col (const WEdit * edit) { - return (long) edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit->curs1); + return (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, edit->buffer.curs1); } /* --------------------------------------------------------------------------------------------- */ @@ -3169,7 +3140,7 @@ edit_update_curs_row (WEdit * edit) void edit_update_curs_col (WEdit * edit) { - edit->curs_col = (long) edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit->curs1); + edit->curs_col = (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, edit->buffer.curs1); } /* --------------------------------------------------------------------------------------------- */ @@ -3256,14 +3227,14 @@ edit_move_to_prev_col (WEdit * edit, off_t p) long prev = edit->prev_col; long over = edit->over_col; - edit_cursor_move (edit, edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->curs1); + edit_cursor_move (edit, edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->buffer.curs1); if (option_cursor_beyond_eol) { long line_len; - line_len = (long) edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, - edit_eol (edit, edit->curs1)); + line_len = (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, + edit_eol (edit, edit->buffer.curs1)); if (line_len < prev + edit->over_col) { edit->over_col = prev + over - line_len; @@ -3293,11 +3264,11 @@ 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_bol (edit, edit->curs1); + p = edit_bol (edit, edit->buffer.curs1); edit_cursor_move (edit, - edit_move_forward3 (edit, p, edit->curs_col, 0) - edit->curs1); + edit_move_forward3 (edit, p, edit->curs_col, 0) - edit->buffer.curs1); if (!left_of_four_spaces (edit)) - edit_cursor_move (edit, edit_move_forward3 (edit, p, q, 0) - edit->curs1); + edit_cursor_move (edit, edit_move_forward3 (edit, p, q, 0) - edit->buffer.curs1); } } } @@ -3381,14 +3352,14 @@ edit_mark_cmd (WEdit * edit, gboolean unmark) else if (edit->mark2 >= 0) { edit->end_mark_curs = -1; - edit_set_markers (edit, edit->curs1, -1, edit->curs_col + edit->over_col, + edit_set_markers (edit, edit->buffer.curs1, -1, edit->curs_col + edit->over_col, edit->curs_col + edit->over_col); edit->force |= REDRAW_PAGE; } else { - edit->end_mark_curs = edit->curs1; - edit_set_markers (edit, edit->mark1, edit->curs1, edit->column1, + edit->end_mark_curs = edit->buffer.curs1; + edit_set_markers (edit, edit->mark1, edit->buffer.curs1, edit->column1, edit->curs_col + edit->over_col); } } @@ -3401,7 +3372,7 @@ edit_mark_current_word_cmd (WEdit * edit) { long pos; - for (pos = edit->curs1; pos != 0; pos--) + for (pos = edit->buffer.curs1; pos != 0; pos--) { int c1, c2; @@ -3435,7 +3406,7 @@ edit_mark_current_word_cmd (WEdit * edit) void edit_mark_current_line_cmd (WEdit * edit) { - long pos = edit->curs1; + long pos = edit->buffer.curs1; edit->mark1 = edit_bol (edit, pos); edit->mark2 = edit_eol (edit, pos); @@ -3453,7 +3424,7 @@ edit_delete_line (WEdit * edit) * Note that edit_get_byte() returns '\n' when byte position is * beyond EOF. */ - while (edit_get_byte (edit, edit->curs1) != '\n') + while (edit_get_byte (edit, edit->buffer.curs1) != '\n') (void) edit_delete (edit, TRUE); /* @@ -3467,7 +3438,7 @@ edit_delete_line (WEdit * edit) * Delete left part of the line. * Note, that edit_get_byte() returns '\n' when byte position is < 0. */ - while (edit_get_byte (edit, edit->curs1 - 1) != '\n') + while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n') (void) edit_backspace (edit, TRUE); } @@ -3663,7 +3634,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit_group_undo (edit); edit->found_len = 0; edit->prev_col = edit_get_col (edit); - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; return; } /* check for redo */ @@ -3673,7 +3644,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit_do_redo (edit); edit->found_len = 0; edit->prev_col = edit_get_col (edit); - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; return; } @@ -3692,7 +3663,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->curs1) != '\n') + if (edit_get_byte (edit, edit->buffer.curs1) != '\n') edit_delete (edit, FALSE); } @@ -3735,7 +3706,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) check_and_wrap_line (edit); edit->found_len = 0; edit->prev_col = edit_get_col (edit); - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; edit_find_bracket (edit); return; } @@ -3801,7 +3772,7 @@ 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->curs1 - 1) != '\n' && edit->curs1 > 0) + while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n' && edit->buffer.curs1 > 0) edit_backspace (edit, TRUE); } else if (option_fake_half_tabs && is_in_indent (edit) && right_of_four_spaces (edit)) @@ -4297,13 +4268,13 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) case CK_ScrollDown: case CK_MarkScrollDown: case CK_MarkColumnScrollDown: - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; edit->found_len = 0; break; default: edit->found_len = 0; edit->prev_col = edit_get_col (edit); - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; } edit_find_bracket (edit); diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c new file mode 100644 index 000000000..0a6c7b553 --- /dev/null +++ b/src/editor/editbuffer.c @@ -0,0 +1,87 @@ +/* + Editor text keep buffer. + + Copyright (C) 2013 + The Free Software Foundation, Inc. + + Written by: + Andrew Borodin 2013 + + This file is part of the Midnight Commander. + + The Midnight Commander is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +/** \file + * \brief Source: editor text keep buffer. + * \author Andrew Borodin + * \date 2013 + */ + +#include + +#include "lib/global.h" + +#include "editbuffer.h" + +/* --------------------------------------------------------------------------------------------- */ +/*- + * + * here's a quick sketch of the layout: (don't run this through indent.) + * + * (b1 is buffers1 and b2 is buffers2) + * + * | + * \0\0\0\0\0m e _ f i l e . \nf i n . \n|T h i s _ i s _ s o\0\0\0\0\0\0\0\0\0 + * ______________________________________|______________________________________ + * | + * ... | b2[2] | b2[1] | b2[0] | b1[0] | b1[1] | b1[2] | ... + * |-> |-> |-> |-> |-> |-> | + * | + * _<------------------------->|<----------------->_ + * curs2 | curs1 + * ^ | ^ + * | ^|^ | + * cursor ||| cursor + * ||| + * file end|||file beginning + * | + * | + * + * _ + * This_is_some_file + * fin. + * + * + * This is called a "gab buffer". + * See also: + * http://en.wikipedia.org/wiki/Gap_buffer + * http://stackoverflow.com/questions/4199694/data-structure-for-text-editor + */ + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h new file mode 100644 index 000000000..168092654 --- /dev/null +++ b/src/editor/editbuffer.h @@ -0,0 +1,54 @@ +/** \file + * \brief Header: text keep buffer for WEdit + */ + +#ifndef MC__EDIT_BUFFER_H +#define MC__EDIT_BUFFER_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/* + * The editor keeps data in two arrays of buffers. + * All buffers have the same size, which must be a power of 2. + */ + +/* Configurable: log2 of the buffer size in bytes */ +#ifndef S_EDIT_BUF_SIZE +#define S_EDIT_BUF_SIZE 16 +#endif + +/* Size of the buffer */ +#define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE) + +/* Buffer mask (used to find cursor position relative to the buffer) */ +#define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1) + +/* + * Configurable: Maximal allowed number of buffers in each buffer array. + * This number can be increased for systems with enough physical memory. + */ +#ifndef MAXBUFF +#define MAXBUFF 1024 +#endif + +/* Maximal length of file that can be opened */ +#define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2)) + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +typedef struct edit_buffer_struct { + off_t curs1; /* position of the cursor from the beginning of the file. */ + off_t curs2; /* position from the end of the file */ + unsigned char *buffers1[MAXBUFF + 1]; /* all data up to curs1 */ + unsigned char *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */ +} edit_buffer_t; + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +/*** inline functions ****************************************************************************/ + +#endif /* MC__EDIT_BUFFER_H */ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 31920bc3b..c6c103bc4 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -312,9 +312,9 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) off_t buf; buf = 0; filelen = edit->last_byte; - while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) + while (buf <= (edit->buffer.curs1 >> S_EDIT_BUF_SIZE) - 1) { - if (mc_write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) + if (mc_write (fd, (char *) edit->buffer.buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) { mc_close (fd); goto error_save; @@ -322,20 +322,20 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) buf++; } if (mc_write - (fd, (char *) edit->buffers1[buf], - edit->curs1 & M_EDIT_BUF_SIZE) != (edit->curs1 & M_EDIT_BUF_SIZE)) + (fd, (char *) edit->buffer.buffers1[buf], + edit->buffer.curs1 & M_EDIT_BUF_SIZE) != (edit->buffer.curs1 & M_EDIT_BUF_SIZE)) { filelen = -1; } - else if (edit->curs2) + else if (edit->buffer.curs2 != 0) { - edit->curs2--; - buf = (edit->curs2 >> S_EDIT_BUF_SIZE); + edit->buffer.curs2--; + buf = (edit->buffer.curs2 >> S_EDIT_BUF_SIZE); if (mc_write (fd, - (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, - 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) + (char *) edit->buffer.buffers2[buf] + EDIT_BUF_SIZE - + (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1, + 1 + (edit->buffer.curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->buffer.curs2 & M_EDIT_BUF_SIZE)) { filelen = -1; } @@ -343,14 +343,14 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) { while (--buf >= 0) { - if (mc_write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) + if (mc_write (fd, (char *) edit->buffer.buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) { filelen = -1; break; } } } - edit->curs2++; + edit->buffer.curs2++; } if (mc_close (fd)) goto error_save; @@ -556,24 +556,24 @@ edit_delete_column_of_text (WEdit * edit) while (n--) { - r = edit_bol (edit, edit->curs1); + r = edit_bol (edit, edit->buffer.curs1); p = edit_move_forward3 (edit, r, b, 0); q = edit_move_forward3 (edit, r, c, 0); if (p < m1) p = m1; if (q > m2) q = m2; - edit_cursor_move (edit, p - edit->curs1); + edit_cursor_move (edit, p - edit->buffer.curs1); while (q > p) { /* delete line between margins */ - if (edit_get_byte (edit, edit->curs1) != '\n') + if (edit_get_byte (edit, edit->buffer.curs1) != '\n') edit_delete (edit, TRUE); q--; } if (n) /* move to next line except on the last delete */ - edit_cursor_move (edit, edit_move_forward (edit, edit->curs1, 1, 0) - edit->curs1); + edit_cursor_move (edit, edit_move_forward (edit, edit->buffer.curs1, 1, 0) - edit->buffer.curs1); } } @@ -615,7 +615,7 @@ edit_block_delete (WEdit * edit) curs_pos = edit->curs_col + edit->over_col; /* move cursor to start of selection */ - edit_cursor_move (edit, start_mark - edit->curs1); + edit_cursor_move (edit, start_mark - edit->buffer.curs1); edit_scroll_screen_over_cursor (edit); if (start_mark < end_mark) @@ -630,8 +630,8 @@ edit_block_delete (WEdit * edit) /* 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_bol (edit, edit->curs1), 0, - edit_eol (edit, edit->curs1)); + line_width = edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, + edit_eol (edit, edit->buffer.curs1)); if (option_cursor_beyond_eol && curs_pos > line_width) edit->over_col = curs_pos - line_width; } @@ -858,7 +858,7 @@ editcmd_find (WEdit * edit, gsize * len) else { if (edit_search_options.backwards) - end_mark = max (1, edit->curs1) - 1; + end_mark = max (1, edit->buffer.curs1) - 1; } /* search */ @@ -950,7 +950,7 @@ edit_do_search (WEdit * edit) gsize len = 0; if (edit->search == NULL) - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; edit_push_undo_action (edit, KEY_PRESS + edit->start_display); @@ -981,7 +981,7 @@ edit_do_search (WEdit * edit) if (found == 0) edit_error_dialog (_("Search"), _("Search string not found")); else - edit_cursor_move (edit, edit->search_start - edit->curs1); + edit_cursor_move (edit, edit->search_start - edit->buffer.curs1); } else { @@ -998,7 +998,7 @@ edit_do_search (WEdit * edit) edit->found_start = edit->search_start = edit->search->normal_offset; edit->found_len = len; edit->over_col = 0; - edit_cursor_move (edit, edit->search_start - edit->curs1); + edit_cursor_move (edit, edit->search_start - edit->buffer.curs1); edit_scroll_screen_over_cursor (edit); if (edit_search_options.backwards) edit->search_start--; @@ -1007,7 +1007,7 @@ edit_do_search (WEdit * edit) } else { - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; if (edit->search->error_str != NULL) edit_error_dialog (_("Search"), edit->search->error_str); } @@ -1125,10 +1125,10 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len) off_t i; /* return if at begin of file */ - if (edit->curs1 <= 0) + if (edit->buffer.curs1 <= 0) return FALSE; - c = edit_get_byte (edit, edit->curs1 - 1); + c = edit_get_byte (edit, edit->buffer.curs1 - 1); /* return if not at end or in word */ if (is_break_char (c)) return FALSE; @@ -1137,11 +1137,11 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len) for (i = 2;; i++) { /* return if at begin of file */ - if (edit->curs1 < i) + if (edit->buffer.curs1 < i) return FALSE; last = c; - c = edit_get_byte (edit, edit->curs1 - i); + c = edit_get_byte (edit, edit->buffer.curs1 - i); if (is_break_char (c)) { @@ -1149,7 +1149,7 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len) if (isdigit (last)) return FALSE; - *word_start = edit->curs1 - (i - 1); /* start found */ + *word_start = edit->buffer.curs1 - (i - 1); /* start found */ *word_len = (gsize) (i - 1); break; } @@ -1318,7 +1318,7 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long off_t i, cursor; long col; - cursor = edit->curs1; + cursor = edit->buffer.curs1; col = edit_get_col (edit); for (i = 0; i < size; i++) @@ -1330,16 +1330,16 @@ 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->curs1) != '\n') + if (edit_get_byte (edit, edit->buffer.curs1) != '\n') { for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width) edit_insert (edit, ' '); } - for (p = edit->curs1;; p++) + for (p = edit->buffer.curs1;; p++) { if (p == edit->last_byte) { - edit_cursor_move (edit, edit->last_byte - edit->curs1); + edit_cursor_move (edit, edit->last_byte - edit->buffer.curs1); edit_insert_ahead (edit, '\n'); p++; break; @@ -1350,7 +1350,7 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long break; } } - edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1); + edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1); for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) edit_insert (edit, ' '); @@ -1360,8 +1360,8 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long *col1 = col; *col2 = col + width; *start_pos = cursor; - *end_pos = edit->curs1; - edit_cursor_move (edit, cursor - edit->curs1); + *end_pos = edit->buffer.curs1; + edit_cursor_move (edit, cursor - edit->buffer.curs1); } /* --------------------------------------------------------------------------------------------- */ @@ -2259,7 +2259,7 @@ eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark) long end_mark_curs; if (edit->end_mark_curs < 0) - end_mark_curs = edit->curs1; + end_mark_curs = edit->buffer.curs1; else end_mark_curs = edit->end_mark_curs; @@ -2311,7 +2311,7 @@ eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark) void edit_block_copy_cmd (WEdit * edit) { - off_t start_mark, end_mark, current = edit->curs1; + off_t start_mark, end_mark, current = edit->buffer.curs1; long col_delta = 0; off_t mark1, mark2; long c1, c2; @@ -2349,7 +2349,7 @@ edit_block_copy_cmd (WEdit * edit) edit_scroll_screen_over_cursor (edit); if (edit->column_highlight) - edit_set_markers (edit, edit->curs1, mark2, c1, c2); + edit_set_markers (edit, edit->buffer.curs1, mark2, c1, c2); else if (start_mark < current && end_mark > current) edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0); @@ -2369,7 +2369,7 @@ edit_block_move_cmd (WEdit * edit) if (eval_marks (edit, &start_mark, &end_mark)) return; - if (!edit->column_highlight && edit->curs1 > start_mark && edit->curs1 < end_mark) + if (!edit->column_highlight && edit->buffer.curs1 > start_mark && edit->buffer.curs1 < end_mark) return; if (edit->mark2 < 0) @@ -2393,10 +2393,10 @@ edit_block_move_cmd (WEdit * edit) x2 = x + edit->over_col; /* do nothing when cursor inside first line of selected area */ - if ((edit_eol (edit, edit->curs1) == edit_eol (edit, start_mark)) && x2 > c1 && x2 <= c2) + if ((edit_eol (edit, edit->buffer.curs1) == edit_eol (edit, start_mark)) && x2 > c1 && x2 <= c2) return; - if (edit->curs1 > start_mark && edit->curs1 < edit_eol (edit, end_mark)) + if (edit->buffer.curs1 > start_mark && edit->buffer.curs1 < edit_eol (edit, end_mark)) { if (x > c2) x -= b_width; @@ -2411,8 +2411,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_bol (edit, edit->curs1), x, 0); - edit_cursor_move (edit, current - edit->curs1); + current = edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), x, 0); + edit_cursor_move (edit, current - edit->buffer.curs1); edit_scroll_screen_over_cursor (edit); /* add TWS if need before block insertion */ @@ -2426,9 +2426,9 @@ edit_block_move_cmd (WEdit * edit) { off_t count, count_orig; - current = edit->curs1; + current = edit->buffer.curs1; copy_buf = g_malloc0 (end_mark - start_mark); - edit_cursor_move (edit, start_mark - edit->curs1); + edit_cursor_move (edit, start_mark - edit->buffer.curs1); edit_scroll_screen_over_cursor (edit); for (count = start_mark; count < end_mark; count++) @@ -2436,14 +2436,14 @@ edit_block_move_cmd (WEdit * edit) edit_scroll_screen_over_cursor (edit); edit_cursor_move (edit, - current - edit->curs1 - - (((current - edit->curs1) > 0) ? end_mark - start_mark : 0)); + current - edit->buffer.curs1 - + (((current - edit->buffer.curs1) > 0) ? end_mark - start_mark : 0)); edit_scroll_screen_over_cursor (edit); count_orig = count; while (count-- > start_mark) edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); - edit_set_markers (edit, edit->curs1, edit->curs1 + end_mark - start_mark, 0, 0); + edit_set_markers (edit, edit->buffer.curs1, edit->buffer.curs1 + end_mark - start_mark, 0, 0); /* Place cursor at the end of text selection */ if (option_cursor_after_inserted_block) @@ -2545,7 +2545,7 @@ edit_replace_cmd (WEdit * edit, int again) edit->search = mc_search_new (input1, -1); if (edit->search == NULL) { - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; goto cleanup; } edit->search->search_type = edit_search_options.type; @@ -2591,7 +2591,7 @@ edit_replace_cmd (WEdit * edit, int again) edit->found_start = edit->search_start; i = edit->found_len = len; - edit_cursor_move (edit, edit->search_start - edit->curs1); + edit_cursor_move (edit, edit->search_start - edit->buffer.curs1); edit_scroll_screen_over_cursor (edit); if (edit->replace_mode == 0) @@ -2673,7 +2673,7 @@ edit_replace_cmd (WEdit * edit, int again) else { /* try and find from right here for next search */ - edit->search_start = edit->curs1; + edit->search_start = edit->buffer.curs1; edit_update_curs_col (edit); edit->force |= REDRAW_PAGE; @@ -3525,7 +3525,7 @@ edit_suggest_current_word (WEdit * edit) char *match_word; /* search start of word to spell check */ - match_word = edit_get_word_from_pos (edit, edit->curs1, &word_start, &word_len, &cut_len); + match_word = edit_get_word_from_pos (edit, edit->buffer.curs1, &word_start, &word_len, &cut_len); #ifdef HAVE_CHARSET if (mc_global.source_codepage >= 0 && (mc_global.source_codepage != mc_global.display_codepage)) @@ -3600,7 +3600,7 @@ edit_spellcheck_file (WEdit * edit) { if (edit->curs_line > 0) { - edit_cursor_move (edit, -edit->curs1); + edit_cursor_move (edit, -edit->buffer.curs1); edit_move_to_prev_col (edit, 0); edit_update_curs_row (edit); } @@ -3609,16 +3609,16 @@ edit_spellcheck_file (WEdit * edit) { int c1, c2; - c2 = edit_get_byte (edit, edit->curs1); + c2 = edit_get_byte (edit, edit->buffer.curs1); do { - if (edit->curs1 >= edit->last_byte) + if (edit->buffer.curs1 >= edit->last_byte) return; c1 = c2; edit_cursor_move (edit, 1); - c2 = edit_get_byte (edit, edit->curs1); + c2 = edit_get_byte (edit, edit->buffer.curs1); } while (is_break_char (c1) || is_break_char (c2)); } diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 30439c8f7..b89fa0668 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -7,7 +7,7 @@ Written by: Paul Sheer, 1996, 1997 - Andrew Borodin 2012 + Andrew Borodin 2012, 2013 Slava Zanko , 2013 This file is part of the Midnight Commander. @@ -114,7 +114,7 @@ status_string (WEdit * edit, char *s, int w) * otherwise print the current character as is (if printable), * as decimal and as hex. */ - if (edit->curs1 < edit->last_byte) + if (edit->buffer.curs1 < edit->last_byte) { #ifdef HAVE_CHARSET if (edit->utf8) @@ -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->curs1, &cw); + cur_utf = edit_get_utf (edit, 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->curs1); + cur_utf = edit_get_byte (edit, edit->buffer.curs1); 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->curs1); + cur_byte = edit_get_byte (edit, edit->buffer.curs1); g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X", (int) cur_byte, (unsigned) cur_byte); } @@ -160,7 +160,7 @@ status_string (WEdit * edit, char *s, int w) edit->overwrite == 0 ? '-' : 'O', edit->curs_col + edit->over_col, edit->curs_line + 1, - edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str, + edit->total_lines + 1, (long) edit->buffer.curs1, (long) edit->last_byte, byte_str, #ifdef HAVE_CHARSET mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : #endif @@ -176,7 +176,7 @@ status_string (WEdit * edit, char *s, int w) edit->start_line + 1, edit->curs_row, edit->curs_line + 1, - edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str, + edit->total_lines + 1, (long) edit->buffer.curs1, (long) edit->last_byte, byte_str, #ifdef HAVE_CHARSET mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : #endif @@ -292,7 +292,7 @@ edit_status_window (WEdit * edit) edit_move (2, w->lines - 1); tty_printf ("%3ld %5ld/%ld %6ld/%ld", edit->curs_col + edit->over_col, - edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte); + edit->curs_line + 1, edit->total_lines + 1, edit->buffer.curs1, edit->last_byte); } /* @@ -303,7 +303,7 @@ edit_status_window (WEdit * edit) if (cols > 46) { edit_move (32, w->lines - 1); - if (edit->curs1 >= edit->last_byte) + if (edit->buffer.curs1 >= edit->last_byte) tty_print_string ("[ ]"); #ifdef HAVE_CHARSET else if (edit->utf8) @@ -311,9 +311,9 @@ edit_status_window (WEdit * edit) unsigned int cur_utf; int cw = 1; - cur_utf = edit_get_utf (edit, edit->curs1, &cw); + cur_utf = edit_get_utf (edit, edit->buffer.curs1, &cw); if (cw <= 0) - cur_utf = edit_get_byte (edit, edit->curs1); + cur_utf = edit_get_byte (edit, edit->buffer.curs1); 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->curs1); + cur_byte = edit_get_byte (edit, edit->buffer.curs1); tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte); } } @@ -583,7 +583,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c p->ch = 0; p->style = 0; - if (q == edit->curs1) + if (q == edit->buffer.curs1) p->style |= MOD_CURSOR; if (q >= m1 && q < m2) { @@ -935,7 +935,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, } /* if (force & REDRAW_LINE) ---> default */ - b = edit_bol (edit, edit->curs1); + b = edit_bol (edit, edit->buffer.curs1); if (curs_row >= start_row && curs_row <= end_row) { if (key_pending (edit)) @@ -960,7 +960,7 @@ 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_move_backward (edit, edit_bol (edit, edit->curs1), 1); + b = edit_move_backward (edit, edit_bol (edit, edit->buffer.curs1), 1); if (row >= start_row && row <= end_row) { if (key_pending (edit)) @@ -972,7 +972,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1) { row = curs_row + 1; - b = edit_bol (edit, edit->curs1); + b = edit_bol (edit, edit->buffer.curs1); b = edit_move_forward (edit, b, 1, 0); if (row >= start_row && row <= end_row) { @@ -987,18 +987,18 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, { /* with the new text highlighting, we must draw from the top down */ edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column); - edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column); + edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column); } else { - edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column); + edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column); edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column); } edit->force = 0; prev_curs_row = edit->curs_row; - prev_curs = edit->curs1; + prev_curs = edit->buffer.curs1; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 46b79aa1c..7197fbc08 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -529,8 +529,8 @@ edit_event (Gpm_Event * event, void *data) edit->prev_col = local.x - edit->start_col - option_line_state_width - 1; else { - long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, - edit_eol (edit, edit->curs1)); + long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, + edit_eol (edit, edit->buffer.curs1)); if (local.x > line_len) { @@ -552,7 +552,7 @@ edit_event (Gpm_Event * event, void *data) else if (local.y < (edit->curs_row + 1)) edit_move_up (edit, (edit->curs_row + 1) - local.y, 0); else - edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1)); + edit_move_to_prev_col (edit, edit_bol (edit, edit->buffer.curs1)); if ((local.type & GPM_DOWN) != 0) { diff --git a/src/editor/editwidget.h b/src/editor/editwidget.h index 39017a268..1f62827a6 100644 --- a/src/editor/editwidget.h +++ b/src/editor/editwidget.h @@ -9,6 +9,7 @@ #include "lib/widget.h" /* Widget */ #include "edit-impl.h" +#include "editbuffer.h" /*** typedefs(not structures) and defined constants **********************************************/ @@ -74,10 +75,7 @@ struct WEdit vfs_path_t *dir_vpath; /* NULL if filename is absolute */ /* dynamic buffers and cursor position for editor: */ - off_t curs1; /* position of the cursor from the beginning of the file. */ - off_t curs2; /* position from the end of the file */ - unsigned char *buffers1[MAXBUFF + 1]; /* all data up to curs1 */ - unsigned char *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */ + edit_buffer_t buffer; #ifdef HAVE_CHARSET /* multibyte support */ diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index aa36d2850..0dfcc98cf 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -2,13 +2,14 @@ Word-processor mode for the editor: does dynamic paragraph formatting. - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Copyright (C) 1996 Paul Sheer Writen by: Paul Sheer, 1996 + Andrew Borodin , 2013 This file is part of the Midnight Commander. @@ -30,6 +31,8 @@ * \brief Source: word-processor mode for the editor: does dynamic paragraph formatting * \author Paul Sheer * \date 1996 + * \author Andrew Borodin + * \date 2013 */ #include @@ -75,7 +78,7 @@ line_start (WEdit * edit, long line) long l; l = edit->curs_line; - p = edit->curs1; + p = edit->buffer.curs1; if (line < l) p = edit_move_backward (edit, p, l - line); @@ -140,7 +143,7 @@ begin_paragraph (WEdit * edit, int force) } } } - return edit_move_backward (edit, edit_bol (edit, edit->curs1), edit->curs_line - i); + return edit_move_backward (edit, edit_bol (edit, edit->buffer.curs1), edit->curs_line - i); } /* --------------------------------------------------------------------------------------------- */ @@ -168,7 +171,7 @@ end_paragraph (WEdit * edit, int force) } } return edit_eol (edit, - edit_move_forward (edit, edit_bol (edit, edit->curs1), + edit_move_forward (edit, edit_bol (edit, edit->buffer.curs1), i - edit->curs_line, 0)); } @@ -346,7 +349,7 @@ format_this (unsigned char *t, int size, int indent) static inline void replace_at (WEdit * edit, long q, int c) { - edit_cursor_move (edit, q - edit->curs1); + edit_cursor_move (edit, q - edit->buffer.curs1); edit_delete (edit, TRUE); edit_insert_ahead (edit, c); } @@ -360,7 +363,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size) long cursor; int i, c = 0; - cursor = edit->curs1; + cursor = edit->buffer.curs1; if (indent) while (strchr ("\t ", edit_get_byte (edit, p))) p++; @@ -376,30 +379,30 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size) else if (t[i - 1] == '\n') { off_t curs; - edit_cursor_move (edit, p - edit->curs1); - curs = edit->curs1; + edit_cursor_move (edit, p - edit->buffer.curs1); + curs = edit->buffer.curs1; edit_insert_indent (edit, indent); if (cursor >= curs) - cursor += edit->curs1 - p; - p = edit->curs1; + cursor += edit->buffer.curs1 - p; + p = edit->buffer.curs1; } else if (c == '\n') { - edit_cursor_move (edit, p - edit->curs1); + edit_cursor_move (edit, p - edit->buffer.curs1); while (strchr ("\t ", edit_get_byte (edit, p))) { edit_delete (edit, TRUE); - if (cursor > edit->curs1) + if (cursor > edit->buffer.curs1) cursor--; } - p = edit->curs1; + p = edit->buffer.curs1; } } c = edit_get_byte (edit, p); if (c != t[i]) replace_at (edit, p, t[i]); } - edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */ + edit_cursor_move (edit, cursor - edit->buffer.curs1); /* restore cursor position */ } /* --------------------------------------------------------------------------------------------- */ From e05672660688108dd99c14e6fd57d9894419be71 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 15 Feb 2013 13:22:20 +0400 Subject: [PATCH 04/25] Refactoring of init/clean editor buffer. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 33 +++------------------------------ src/editor/editbuffer.c | 39 +++++++++++++++++++++++++++++++++++++++ src/editor/editbuffer.h | 3 +++ 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index d5d0403fe..aff66c8d8 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -138,28 +138,6 @@ static const struct edit_filters /* --------------------------------------------------------------------------------------------- */ /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -/** - * Initialize the buffers for an empty files. - */ - -static void -edit_init_buffers (WEdit * edit) -{ - int j; - - for (j = 0; j <= MAXBUFF; j++) - { - edit->buffer.buffers1[j] = NULL; - edit->buffer.buffers2[j] = NULL; - } - - edit->buffer.curs1 = 0; - edit->buffer.curs2 = 0; - edit->buffer.buffers2[0] = g_malloc0 (EDIT_BUF_SIZE); -} - -/* --------------------------------------------------------------------------------------------- */ - /** * Load file OR text into buffers. Set cursor to the beginning of file. * @@ -401,7 +379,7 @@ edit_load_file (WEdit * edit) fast_load = FALSE; } - edit_init_buffers (edit); + edit_buffer_init (&edit->buffer); if (fast_load) { @@ -2306,8 +2284,6 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f gboolean edit_clean (WEdit * edit) { - int j = 0; - if (edit == NULL) return FALSE; @@ -2327,11 +2303,8 @@ edit_clean (WEdit * edit) edit_free_syntax_rules (edit); book_mark_flush (edit, -1); - for (; j <= MAXBUFF; j++) - { - g_free (edit->buffer.buffers1[j]); - g_free (edit->buffer.buffers2[j]); - } + + edit_buffer_clean (&edit->buffer); g_free (edit->undo_stack); g_free (edit->redo_stack); diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 0a6c7b553..6be0cd0dd 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -31,6 +31,9 @@ #include +#include +#include + #include "lib/global.h" #include "editbuffer.h" @@ -85,3 +88,39 @@ /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ +/** + * Initialize editor buffers. + * + * @param buf pointer to editor buffer + */ + +void +edit_buffer_init (edit_buffer_t * buf) +{ + memset (buf->buffers1, 0, sizeof (buf->buffers1)); + memset (buf->buffers2, 0, sizeof (buf->buffers2)); + buf->curs1 = 0; + buf->curs2 = 0; + buf->buffers2[0] = g_malloc0 (EDIT_BUF_SIZE); +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Clean editor buffers. + * + * @param buf pointer to editor buffer + */ + +void +edit_buffer_clean (edit_buffer_t * buf) +{ + size_t j; + + for (j = 0; j <= MAXBUFF; j++) + { + g_free (buf->buffers1[j]); + g_free (buf->buffers2[j]); + } +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index 168092654..ef25782ab 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -49,6 +49,9 @@ typedef struct edit_buffer_struct { /*** declarations of public functions ************************************************************/ +void edit_buffer_init (edit_buffer_t * buf); +void edit_buffer_clean (edit_buffer_t * buf); + /*** inline functions ****************************************************************************/ #endif /* MC__EDIT_BUFFER_H */ From cd9a56109d68e170ccdc2083208f511b2d67fcb0 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 15 Feb 2013 13:55:57 +0400 Subject: [PATCH 05/25] Refactoring editor buffer API of bytes/symbols get. Signed-off-by: Andrew Borodin --- src/editor/edit-impl.h | 2 - src/editor/edit.c | 266 ++++-------------- src/editor/editbuffer.c | 174 ++++++++++++ src/editor/editbuffer.h | 22 ++ src/editor/editcmd.c | 42 +-- src/editor/editdraw.c | 23 +- src/editor/syntax.c | 21 +- src/editor/wordproc.c | 42 +-- .../editor/editcmd__edit_complete_word_cmd.c | 8 +- 9 files changed, 327 insertions(+), 273 deletions(-) diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index ae6aa555c..806044569 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -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); diff --git a/src/editor/edit.c b/src/editor/edit.c index aff66c8d8..e7561143a 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -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)) diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 6be0cd0dd..f63187f53 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -33,6 +33,7 @@ #include #include +#include #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 */ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index ef25782ab..9364dc8ae 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -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 */ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index c6c103bc4..a427d5ea7 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -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)); } diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index b89fa0668..434ddd877 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -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) { diff --git a/src/editor/syntax.c b/src/editor/syntax.c index 971e04326..4097b1d0b 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -9,6 +9,7 @@ Paul Sheer, 1998 Egmont Koblinger , 2010 Slava Zanko , 2013 + Andrew Borodin , 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'; diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index 0dfcc98cf..3ade9aab3 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -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; } diff --git a/tests/src/editor/editcmd__edit_complete_word_cmd.c b/tests/src/editor/editcmd__edit_complete_word_cmd.c index 2efbf7565..57dd64cb8 100644 --- a/tests/src/editor/editcmd__edit_complete_word_cmd.c +++ b/tests/src/editor/editcmd__edit_complete_word_cmd.c @@ -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); From fc8044e178c4c31a94e361a5a9815d00ef1fcd5f Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 15 Feb 2013 14:10:34 +0400 Subject: [PATCH 06/25] (edit_buffer_read_file): new editor buffer API. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 38 ++++++++--------------------------- src/editor/editbuffer.c | 44 +++++++++++++++++++++++++++++++++++++++++ src/editor/editbuffer.h | 2 ++ 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index e7561143a..9610013b4 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -147,12 +147,11 @@ static const struct edit_filters static gboolean edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) { - off_t buf, buf2; - int file = -1; - gboolean ret = FALSE; + int file; + gboolean ret; file = mc_open (filename_vpath, O_RDONLY | O_BINARY); - if (file == -1) + if (file < 0) { gchar *errmsg; @@ -163,32 +162,10 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) return FALSE; } - edit->buffer.curs2 = edit->last_byte; - buf2 = edit->buffer.curs2 >> S_EDIT_BUF_SIZE; - - if (edit->buffer.buffers2[buf2] == NULL) - edit->buffer.buffers2[buf2] = g_malloc0 (EDIT_BUF_SIZE); - - if (mc_read (file, - (char *) edit->buffer.buffers2[buf2] + EDIT_BUF_SIZE - - (edit->buffer.curs2 & M_EDIT_BUF_SIZE), edit->buffer.curs2 & M_EDIT_BUF_SIZE) < 0) - goto done; - - for (buf = buf2 - 1; buf >= 0; buf--) - { - /* edit->buffer.buffers2[0] is already allocated */ - if (edit->buffer.buffers2[buf] == NULL) - edit->buffer.buffers2[buf] = g_malloc0 (EDIT_BUF_SIZE); - if (mc_read (file, (char *) edit->buffer.buffers2[buf], EDIT_BUF_SIZE) < 0) - goto done; - } - - edit->total_lines = edit_count_lines (edit, 0, edit->last_byte); - - ret = TRUE; - - done: - if (!ret) + ret = edit_buffer_read_file (&edit->buffer, file, edit->last_byte); + if (ret) + edit->total_lines = edit_count_lines (edit, 0, edit->last_byte); + else { gchar *errmsg; @@ -196,6 +173,7 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) edit_error_dialog (_("Error"), errmsg); g_free (errmsg); } + mc_close (file); return ret; } diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index f63187f53..81b1a0595 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -37,6 +37,8 @@ #include "lib/global.h" +#include "lib/vfs/vfs.h" + #include "editbuffer.h" /* --------------------------------------------------------------------------------------------- */ @@ -298,3 +300,45 @@ edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char #endif /* HAVE_CHARSET */ /* --------------------------------------------------------------------------------------------- */ +/** + * Load file into editor buffer + * + * @param buf pointer to editor buffer + * @param fd file descriptor + * @param size file size + * + * @return TRUE if file was readed successfully, FALSE otherwise + */ + +gboolean +edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) +{ + off_t i; + off_t data_size; + + buf->curs2 = size; + i = buf->curs2 >> S_EDIT_BUF_SIZE; + + if (buf->buffers2[i] == NULL) + buf->buffers2[i] = g_malloc0 (EDIT_BUF_SIZE); + + /* fill last part of buffers2 */ + data_size = buf->curs2 & M_EDIT_BUF_SIZE; + if (mc_read (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size) < 0) + return FALSE; + + /* fullfill other parts of buffers2 from end to begin */ + data_size = EDIT_BUF_SIZE; + for (--i; i >= 0; i--) + { + /* edit->buffers2[0] is already allocated */ + if (buf->buffers2[i] == NULL) + buf->buffers2[i] = g_malloc0 (data_size); + if (mc_read (fd, (char *) buf->buffers2[i], data_size) < 0) + return FALSE; + } + + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index 9364dc8ae..d5e461d4e 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -58,6 +58,8 @@ int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width); #endif +gboolean edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size); + /*** inline functions ****************************************************************************/ static inline int From e6ff98d239f1ca5fb81fefc84ef22b2872a32ac5 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 19 Feb 2013 10:06:33 +0400 Subject: [PATCH 07/25] (edit_buffer_read_file): refactoring: return number of read bytes. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 2 +- src/editor/editbuffer.c | 21 ++++++++++++++------- src/editor/editbuffer.h | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index 9610013b4..b3cb016c3 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -162,7 +162,7 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) return FALSE; } - ret = edit_buffer_read_file (&edit->buffer, file, edit->last_byte); + ret = (edit_buffer_read_file (&edit->buffer, file, edit->last_byte) == edit->last_byte); if (ret) edit->total_lines = edit_count_lines (edit, 0, edit->last_byte); else diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 81b1a0595..5df17050c 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -307,12 +307,13 @@ edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char * @param fd file descriptor * @param size file size * - * @return TRUE if file was readed successfully, FALSE otherwise + * @return number of read bytes */ -gboolean +off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) { + off_t ret; off_t i; off_t data_size; @@ -324,21 +325,27 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) /* fill last part of buffers2 */ data_size = buf->curs2 & M_EDIT_BUF_SIZE; - if (mc_read (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size) < 0) - return FALSE; + ret = mc_read (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size); + if (ret < 0 || ret != data_size) + return ret; /* fullfill other parts of buffers2 from end to begin */ data_size = EDIT_BUF_SIZE; for (--i; i >= 0; i--) { + off_t sz; + /* edit->buffers2[0] is already allocated */ if (buf->buffers2[i] == NULL) buf->buffers2[i] = g_malloc0 (data_size); - if (mc_read (fd, (char *) buf->buffers2[i], data_size) < 0) - return FALSE; + sz = mc_read (fd, (char *) buf->buffers2[i], data_size); + if (sz >= 0) + ret += sz; + if (sz != data_size) + break; } - return TRUE; + return ret; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index d5e461d4e..c9b5b2b5b 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -58,7 +58,7 @@ int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width); #endif -gboolean edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size); +off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size); /*** inline functions ****************************************************************************/ From 64760b56c50bd851c9130aa5ed76a3b954c51f5c Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 15 Feb 2013 14:47:59 +0400 Subject: [PATCH 08/25] (edit_buffer_write_file): new editor buffer API. Signed-off-by: Andrew Borodin --- src/editor/editbuffer.c | 57 +++++++++++++++++++++++++++++++++++++++++ src/editor/editbuffer.h | 1 + src/editor/editcmd.c | 54 ++++++++------------------------------ 3 files changed, 68 insertions(+), 44 deletions(-) diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 5df17050c..a2708ed02 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -349,3 +349,60 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) } /* --------------------------------------------------------------------------------------------- */ +/** + * Write editor buffer content to file + * + * @param buf pointer to editor buffer + * @param fd file descriptor + * + * @return TRUE if file was written successfullly, FALSE otherswise + */ + +gboolean +edit_buffer_write_file (edit_buffer_t * buf, int fd) +{ + gboolean ret = TRUE; + off_t i; + off_t data_size, sz; + + /* write all fullfilled parts of buffers1 from begin to end */ + data_size = EDIT_BUF_SIZE; + for (i = 0; i < buf->curs1 >> S_EDIT_BUF_SIZE; i++) + if (mc_write (fd, (char *) buf->buffers1[i], data_size) != data_size) + return FALSE; + + /* write last partially filled part of buffers1 */ + data_size = buf->curs1 & M_EDIT_BUF_SIZE; + if (mc_write (fd, (char *) buf->buffers1[i], data_size) != data_size) + return FALSE; + + /* write buffers2 from end to begin, if buffers2 contains some data */ + if (buf->curs2 != 0) + { + buf->curs2--; + + /* write last partially filled part of buffers2 */ + i = buf->curs2 >> S_EDIT_BUF_SIZE; + data_size = (buf->curs2 & M_EDIT_BUF_SIZE) + 1; + if (mc_write (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size) != data_size) + ret = FALSE; + else + { + data_size = EDIT_BUF_SIZE; + + /* write other fullfilled parts of buffers2 from end to begin */ + while (--i >= 0) + if (mc_write (fd, (char *) buf->buffers2[i], data_size) != data_size) + { + ret = FALSE; + break; + } + } + + buf->curs2++; + } + + return ret; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index c9b5b2b5b..6d5ab7095 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -59,6 +59,7 @@ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int * #endif off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size); +gboolean edit_buffer_write_file (edit_buffer_t * buf, int fd); /*** inline functions ****************************************************************************/ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index a427d5ea7..72779a7d7 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -309,52 +309,18 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) } else if (edit->lb == LB_ASIS) { /* do not change line breaks */ - off_t buf; - buf = 0; filelen = edit->last_byte; - while (buf <= (edit->buffer.curs1 >> S_EDIT_BUF_SIZE) - 1) - { - if (mc_write (fd, (char *) edit->buffer.buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) - { - mc_close (fd); - goto error_save; - } - buf++; - } - if (mc_write - (fd, (char *) edit->buffer.buffers1[buf], - edit->buffer.curs1 & M_EDIT_BUF_SIZE) != (edit->buffer.curs1 & M_EDIT_BUF_SIZE)) - { - filelen = -1; - } - else if (edit->buffer.curs2 != 0) - { - edit->buffer.curs2--; - buf = (edit->buffer.curs2 >> S_EDIT_BUF_SIZE); - if (mc_write - (fd, - (char *) edit->buffer.buffers2[buf] + EDIT_BUF_SIZE - - (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1, - 1 + (edit->buffer.curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->buffer.curs2 & M_EDIT_BUF_SIZE)) - { - filelen = -1; - } - else - { - while (--buf >= 0) - { - if (mc_write (fd, (char *) edit->buffer.buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) - { - filelen = -1; - break; - } - } - } - edit->buffer.curs2++; - } - if (mc_close (fd)) - goto error_save; + if (!edit_buffer_write_file (&edit->buffer, fd)) + filelen = -1; + + if (filelen != edit->last_byte) + { + mc_close (fd); + goto error_save; + } + if (mc_close (fd) != 0) + goto error_save; /* Update the file information, especially the mtime. */ if (mc_stat (savename_vpath, &edit->stat1) == -1) goto error_save; From 706257a47d350dac81ac653d8bdf82984b6d58b8 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 19 Feb 2013 10:35:54 +0400 Subject: [PATCH 09/25] (edit_buffer_write_file): refactoring: return number of written bytes. Signed-off-by: Andrew Borodin --- src/editor/editbuffer.c | 48 +++++++++++++++++++++++++++++------------ src/editor/editbuffer.h | 2 +- src/editor/editcmd.c | 5 +---- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index a2708ed02..075b84d64 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -355,26 +355,41 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) * @param buf pointer to editor buffer * @param fd file descriptor * - * @return TRUE if file was written successfullly, FALSE otherswise + * @return number of written bytes */ -gboolean +off_t edit_buffer_write_file (edit_buffer_t * buf, int fd) { - gboolean ret = TRUE; + off_t ret = 0; off_t i; off_t data_size, sz; /* write all fullfilled parts of buffers1 from begin to end */ data_size = EDIT_BUF_SIZE; for (i = 0; i < buf->curs1 >> S_EDIT_BUF_SIZE; i++) - if (mc_write (fd, (char *) buf->buffers1[i], data_size) != data_size) - return FALSE; + { + sz = mc_write (fd, (char *) buf->buffers1[i], data_size); + if (sz >= 0) + ret += sz; + else if (i == 0) + ret = sz; + + if (sz != data_size) + return ret; + } /* write last partially filled part of buffers1 */ data_size = buf->curs1 & M_EDIT_BUF_SIZE; - if (mc_write (fd, (char *) buf->buffers1[i], data_size) != data_size) - return FALSE; + if (data_size != 0) + { + sz = mc_write (fd, (char *) buf->buffers1[i], data_size); + if (sz >= 0) + ret += sz; + + if (sz != data_size) + return ret; + } /* write buffers2 from end to begin, if buffers2 contains some data */ if (buf->curs2 != 0) @@ -384,19 +399,24 @@ edit_buffer_write_file (edit_buffer_t * buf, int fd) /* write last partially filled part of buffers2 */ i = buf->curs2 >> S_EDIT_BUF_SIZE; data_size = (buf->curs2 & M_EDIT_BUF_SIZE) + 1; - if (mc_write (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size) != data_size) - ret = FALSE; - else + sz = mc_write (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size); + if (sz >= 0) + ret += sz; + + if (sz == data_size) { data_size = EDIT_BUF_SIZE; /* write other fullfilled parts of buffers2 from end to begin */ while (--i >= 0) - if (mc_write (fd, (char *) buf->buffers2[i], data_size) != data_size) - { - ret = FALSE; + { + sz = mc_write (fd, (char *) buf->buffers2[i], data_size); + if (sz >= 0) + ret += sz; + + if (sz != data_size) break; - } + } } buf->curs2++; diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index 6d5ab7095..cf4cf0943 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -59,7 +59,7 @@ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int * #endif off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size); -gboolean edit_buffer_write_file (edit_buffer_t * buf, int fd); +off_t edit_buffer_write_file (edit_buffer_t * buf, int fd); /*** inline functions ****************************************************************************/ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 72779a7d7..6bc47edc9 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -309,10 +309,7 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) } else if (edit->lb == LB_ASIS) { /* do not change line breaks */ - filelen = edit->last_byte; - - if (!edit_buffer_write_file (&edit->buffer, fd)) - filelen = -1; + filelen = edit_buffer_write_file (&edit->buffer, fd); if (filelen != edit->last_byte) { From e335bba08c8eb990ba26365200d725e0025ca28d Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 18 Feb 2013 12:01:51 +0400 Subject: [PATCH 10/25] New editor buffer API to insert character at cursor position. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 30 ++++++----------------- src/editor/editbuffer.c | 54 +++++++++++++++++++++++++++++++++++++++++ src/editor/editbuffer.h | 3 +++ 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index b3cb016c3..a661e78d4 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -2441,7 +2441,6 @@ edit_push_redo_action (WEdit * edit, long c) /* --------------------------------------------------------------------------------------------- */ /** Basic low level single character buffer alterations and movements at the cursor. - Returns char passed over, inserted or removed. */ void @@ -2479,23 +2478,14 @@ edit_insert (WEdit * edit, int c) else edit_push_undo_action (edit, BACKSPACE_BR); /* update markers */ - edit->mark1 += (edit->mark1 > edit->buffer.curs1); - edit->mark2 += (edit->mark2 > edit->buffer.curs1); - edit->last_get_rule += (edit->last_get_rule > edit->buffer.curs1); + edit->mark1 += (edit->mark1 > edit->buffer.curs1) ? 1 : 0; + edit->mark2 += (edit->mark2 > edit->buffer.curs1) ? 1 : 0; + edit->last_get_rule += (edit->last_get_rule > edit->buffer.curs1) ? 1 : 0; - /* add a new buffer if we've reached the end of the last one */ - if (!(edit->buffer.curs1 & M_EDIT_BUF_SIZE)) - edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); - - /* perform the insertion */ - edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE][edit->buffer.curs1 & M_EDIT_BUF_SIZE] - = (unsigned char) c; + edit_buffer_insert (&edit->buffer, c); /* update file length */ edit->last_byte++; - - /* update cursor position */ - edit->buffer.curs1++; } /* --------------------------------------------------------------------------------------------- */ @@ -2526,17 +2516,13 @@ edit_insert_ahead (WEdit * edit, int c) else edit_push_undo_action (edit, DELCHAR_BR); - edit->mark1 += (edit->mark1 >= edit->buffer.curs1); - edit->mark2 += (edit->mark2 >= edit->buffer.curs1); - edit->last_get_rule += (edit->last_get_rule >= edit->buffer.curs1); + edit->mark1 += (edit->mark1 >= edit->buffer.curs1) ? 1 : 0; + edit->mark2 += (edit->mark2 >= edit->buffer.curs1) ? 1 : 0; + edit->last_get_rule += (edit->last_get_rule >= edit->buffer.curs1) ? 1 : 0; - 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 - (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1] = c; + edit_buffer_insert_ahead (&edit->buffer, c); edit->last_byte++; - edit->buffer.curs2++; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 075b84d64..f061ebc3a 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -299,6 +299,60 @@ edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char } #endif /* HAVE_CHARSET */ +/* --------------------------------------------------------------------------------------------- */ +/** + * Basic low level single character buffer alterations and movements at the cursor: insert character + * at the cursor position and move right. + * + * @param buf pointer to editor buffer + * @param c character to insert + */ + +void +edit_buffer_insert (edit_buffer_t * buf, int c) +{ + off_t i; + + i = buf->curs1 & M_EDIT_BUF_SIZE; + + /* add a new buffer if we've reached the end of the last one */ + if (i == 0) + buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); + + /* perform the insertion */ + buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE][i] = (unsigned char) c; + + /* update cursor position */ + buf->curs1++; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Basic low level single character buffer alterations and movements at the cursor: insert character + * at the cursor position and move left. + * + * @param buf pointer to editor buffer + * @param c character to insert + */ + +void +edit_buffer_insert_ahead (edit_buffer_t * buf, int c) +{ + off_t i; + + i = buf->curs2 & M_EDIT_BUF_SIZE; + + /* add a new buffer if we've reached the end of the last one */ + if (((buf->curs2 + 1) & M_EDIT_BUF_SIZE) == 0) + buf->buffers2[(buf->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); + + /* perform the insertion */ + buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - 1 - i] = (unsigned char) c; + + /* update cursor position */ + buf->curs2++; +} + /* --------------------------------------------------------------------------------------------- */ /** * Load file into editor buffer diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index cf4cf0943..4f83672c9 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -58,6 +58,9 @@ int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width); #endif +void edit_buffer_insert (edit_buffer_t * buf, int c); +void edit_buffer_insert_ahead (edit_buffer_t * buf, int c); + off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size); off_t edit_buffer_write_file (edit_buffer_t * buf, int fd); From ed8c80f48d3fe2d8772b566dca3d997ecb750147 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 18 Feb 2013 12:13:05 +0400 Subject: [PATCH 11/25] New editor buffer API to delete character at cursor position. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 20 ++----------- src/editor/editbuffer.c | 64 +++++++++++++++++++++++++++++++++++++++++ src/editor/editbuffer.h | 2 ++ 3 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index a661e78d4..c4d231d33 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -2577,17 +2577,9 @@ edit_delete (WEdit * edit, gboolean byte_delete) if (edit->last_get_rule > edit->buffer.curs1) edit->last_get_rule--; - p = edit->buffer.buffers2[(edit->buffer.curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - - ((edit->buffer.curs2 - - 1) & M_EDIT_BUF_SIZE) - 1]; + p = edit_buffer_delete (&edit->buffer); - if (!(edit->buffer.curs2 & M_EDIT_BUF_SIZE)) - { - g_free (edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE]); - edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE] = NULL; - } edit->last_byte--; - edit->buffer.curs2--; edit_push_undo_action (edit, p + 256); } @@ -2646,15 +2638,9 @@ edit_backspace (WEdit * edit, gboolean byte_delete) if (edit->last_get_rule >= edit->buffer.curs1) edit->last_get_rule--; - p = *(edit->buffer.buffers1[(edit->buffer.curs1 - 1) >> S_EDIT_BUF_SIZE] + - ((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE)); - if (((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE) == 0) - { - g_free (edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE]); - edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = NULL; - } + p = edit_buffer_backspace (&edit->buffer); + edit->last_byte--; - edit->buffer.curs1--; edit_push_undo_action (edit, p); } edit_modification (edit); diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index f061ebc3a..f76204ba2 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -353,6 +353,70 @@ edit_buffer_insert_ahead (edit_buffer_t * buf, int c) buf->curs2++; } +/* --------------------------------------------------------------------------------------------- */ +/** + * Basic low level single character buffer alterations and movements at the cursor: delete character + * at the cursor position. + * + * @param buf pointer to editor buffer + * @param c character to insert + */ + +int +edit_buffer_delete (edit_buffer_t * buf) +{ + unsigned char c; + off_t prev; + off_t i; + + prev = buf->curs2 - 1; + + i = prev & M_EDIT_BUF_SIZE; + c = buf->buffers2[prev >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - 1 - i]; + + if ((buf->curs2 & M_EDIT_BUF_SIZE) == 0) + { + g_free (buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE]); + buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE] = NULL; + } + + buf->curs2 = prev; + + return c; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Basic low level single character buffer alterations and movements at the cursor: delete character + * before the cursor position and move left. + * + * @param buf pointer to editor buffer + * @param c character to insert + */ + +int +edit_buffer_backspace (edit_buffer_t * buf) +{ + unsigned char c; + off_t prev; + off_t i; + + prev = buf->curs1 - 1; + + i = prev & M_EDIT_BUF_SIZE; + c = buf->buffers1[prev >> S_EDIT_BUF_SIZE][i]; + + if (i == 0) + { + g_free (buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE]); + buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE] = NULL; + } + + buf->curs1 = prev; + + return c; +} + /* --------------------------------------------------------------------------------------------- */ /** * Load file into editor buffer diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index 4f83672c9..b62e9a380 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -60,6 +60,8 @@ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int * void edit_buffer_insert (edit_buffer_t * buf, int c); void edit_buffer_insert_ahead (edit_buffer_t * buf, int c); +int edit_buffer_delete (edit_buffer_t * buf); +int edit_buffer_backspace (edit_buffer_t * buf); off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size); off_t edit_buffer_write_file (edit_buffer_t * buf, int fd); From 60fe43d932b835e37d3c6f356b50e0beb287ec56 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 18 Feb 2013 13:30:02 +0400 Subject: [PATCH 12/25] (edit_cursor_move): refactoring using editor buffer API. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 48 ++++++++++------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index c4d231d33..24d31f5c8 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -2668,63 +2668,35 @@ edit_backspace (WEdit * edit, gboolean byte_delete) void edit_cursor_move (WEdit * edit, off_t increment) { - /* this is the same as a combination of two of the above routines, with only one push onto the undo stack */ - int c; - if (increment < 0) { - for (; increment < 0; increment++) + for (; increment < 0 && edit->buffer.curs1 != 0; increment++) { - if (edit->buffer.curs1 == 0) - return; + int c; edit_push_undo_action (edit, CURS_RIGHT); - 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 - - (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1] = c; - edit->buffer.curs2++; - c = edit->buffer.buffers1[(edit->buffer.curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->buffer.curs1 - - 1) & M_EDIT_BUF_SIZE]; - if (!((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE)) - { - g_free (edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE]); - edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = NULL; - } - edit->buffer.curs1--; + c = edit_buffer_get_previous_byte (&edit->buffer); + edit_buffer_insert_ahead (&edit->buffer, c); + c = edit_buffer_backspace (&edit->buffer); if (c == '\n') { edit->curs_line--; edit->force |= REDRAW_LINE_BELOW; } } - } else { - for (; increment > 0; increment--) + for (; increment > 0 && edit->buffer.curs2 != 0; increment--) { - if (edit->buffer.curs2 == 0) - return; + int c; edit_push_undo_action (edit, CURS_LEFT); - 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; - edit->buffer.curs1++; - c = edit->buffer.buffers2[(edit->buffer.curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - - ((edit->buffer.curs2 - - 1) & M_EDIT_BUF_SIZE) - 1]; - if (!(edit->buffer.curs2 & M_EDIT_BUF_SIZE)) - { - g_free (edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE]); - edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE] = 0; - } - edit->buffer.curs2--; + c = edit_buffer_get_current_byte (&edit->buffer); + edit_buffer_insert (&edit->buffer, c); + c = edit_buffer_delete (&edit->buffer); if (c == '\n') { edit->curs_line++; From 7facc1da05a62aafba56d0e5eb244cf8745bf458 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 19 Feb 2013 16:16:20 +0400 Subject: [PATCH 13/25] Use GPtrArray to store editor buffers. Signed-off-by: Andrew Borodin --- src/editor/editbuffer.c | 162 +++++++++++++++++++++++----------------- src/editor/editbuffer.h | 4 +- 2 files changed, 97 insertions(+), 69 deletions(-) diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index f76204ba2..747d47122 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -95,11 +95,10 @@ * * @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; + void *b; if (byte_index >= (buf->curs1 + buf->curs2) || byte_index < 0) return NULL; @@ -109,12 +108,12 @@ edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) 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 = g_ptr_array_index (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]; + b = g_ptr_array_index (buf->buffers1, byte_index >> S_EDIT_BUF_SIZE); + return (char *) b + (byte_index & M_EDIT_BUF_SIZE); } /* --------------------------------------------------------------------------------------------- */ @@ -129,11 +128,11 @@ edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) void edit_buffer_init (edit_buffer_t * buf) { - memset (buf->buffers1, 0, sizeof (buf->buffers1)); - memset (buf->buffers2, 0, sizeof (buf->buffers2)); + buf->buffers1 = g_ptr_array_sized_new (MAXBUFF + 1); + buf->buffers2 = g_ptr_array_sized_new (MAXBUFF + 1); + buf->curs1 = 0; buf->curs2 = 0; - buf->buffers2[0] = g_malloc0 (EDIT_BUF_SIZE); } /* --------------------------------------------------------------------------------------------- */ @@ -146,12 +145,16 @@ edit_buffer_init (edit_buffer_t * buf) void edit_buffer_clean (edit_buffer_t * buf) { - size_t j; - - for (j = 0; j <= MAXBUFF; j++) + if (buf->buffers1 != NULL) { - g_free (buf->buffers1[j]); - g_free (buf->buffers2[j]); + g_ptr_array_foreach (buf->buffers1, (GFunc) g_free, NULL); + g_ptr_array_free (buf->buffers1, TRUE); + } + + if (buf->buffers2 != NULL) + { + g_ptr_array_foreach (buf->buffers2, (GFunc) g_free, NULL); + g_ptr_array_free (buf->buffers2, TRUE); } } @@ -311,16 +314,18 @@ edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char void edit_buffer_insert (edit_buffer_t * buf, int c) { + void *b; off_t i; i = buf->curs1 & M_EDIT_BUF_SIZE; /* add a new buffer if we've reached the end of the last one */ if (i == 0) - buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); + g_ptr_array_add (buf->buffers1, g_malloc0 (EDIT_BUF_SIZE)); /* perform the insertion */ - buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE][i] = (unsigned char) c; + b = g_ptr_array_index (buf->buffers1, buf->curs1 >> S_EDIT_BUF_SIZE); + *((unsigned char *) b + i) = (unsigned char) c; /* update cursor position */ buf->curs1++; @@ -338,16 +343,18 @@ edit_buffer_insert (edit_buffer_t * buf, int c) void edit_buffer_insert_ahead (edit_buffer_t * buf, int c) { + void *b; off_t i; i = buf->curs2 & M_EDIT_BUF_SIZE; /* add a new buffer if we've reached the end of the last one */ - if (((buf->curs2 + 1) & M_EDIT_BUF_SIZE) == 0) - buf->buffers2[(buf->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); + if (i == 0) + g_ptr_array_add (buf->buffers2, g_malloc0 (EDIT_BUF_SIZE)); /* perform the insertion */ - buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - 1 - i] = (unsigned char) c; + b = g_ptr_array_index (buf->buffers2, buf->curs2 >> S_EDIT_BUF_SIZE); + *((unsigned char *) b + EDIT_BUF_SIZE - 1 - i) = (unsigned char) c; /* update cursor position */ buf->curs2++; @@ -365,19 +372,23 @@ edit_buffer_insert_ahead (edit_buffer_t * buf, int c) int edit_buffer_delete (edit_buffer_t * buf) { + void *b; unsigned char c; off_t prev; off_t i; prev = buf->curs2 - 1; + b = g_ptr_array_index (buf->buffers2, prev >> S_EDIT_BUF_SIZE); i = prev & M_EDIT_BUF_SIZE; - c = buf->buffers2[prev >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - 1 - i]; + c = *((unsigned char *) b + EDIT_BUF_SIZE - 1 - i); - if ((buf->curs2 & M_EDIT_BUF_SIZE) == 0) + if (i == 0) { - g_free (buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE]); - buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE] = NULL; + i = buf->buffers2->len - 1; + b = g_ptr_array_index (buf->buffers2, i); + g_ptr_array_remove_index (buf->buffers2, i); + g_free (b); } buf->curs2 = prev; @@ -397,19 +408,23 @@ edit_buffer_delete (edit_buffer_t * buf) int edit_buffer_backspace (edit_buffer_t * buf) { + void *b; unsigned char c; off_t prev; off_t i; prev = buf->curs1 - 1; + b = g_ptr_array_index (buf->buffers1, prev >> S_EDIT_BUF_SIZE); i = prev & M_EDIT_BUF_SIZE; - c = buf->buffers1[prev >> S_EDIT_BUF_SIZE][i]; + c = *((unsigned char *) b + i); if (i == 0) { - g_free (buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE]); - buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE] = NULL; + i = buf->buffers1->len - 1; + b = g_ptr_array_index (buf->buffers1, i); + g_ptr_array_remove_index (buf->buffers1, i); + g_free (b); } buf->curs1 = prev; @@ -431,21 +446,25 @@ edit_buffer_backspace (edit_buffer_t * buf) off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) { - off_t ret; + off_t ret = 0; off_t i; off_t data_size; + void *b; buf->curs2 = size; i = buf->curs2 >> S_EDIT_BUF_SIZE; - if (buf->buffers2[i] == NULL) - buf->buffers2[i] = g_malloc0 (EDIT_BUF_SIZE); - /* fill last part of buffers2 */ data_size = buf->curs2 & M_EDIT_BUF_SIZE; - ret = mc_read (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size); - if (ret < 0 || ret != data_size) - return ret; + if (data_size != 0) + { + b = g_malloc0 (EDIT_BUF_SIZE); + g_ptr_array_add (buf->buffers2, b); + ret = mc_read (fd, (char *) b + EDIT_BUF_SIZE - data_size, data_size); + if (ret < 0 || ret != data_size) + return ret; + + } /* fullfill other parts of buffers2 from end to begin */ data_size = EDIT_BUF_SIZE; @@ -453,16 +472,28 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) { off_t sz; - /* edit->buffers2[0] is already allocated */ - if (buf->buffers2[i] == NULL) - buf->buffers2[i] = g_malloc0 (data_size); - sz = mc_read (fd, (char *) buf->buffers2[i], data_size); + b = g_malloc0 (data_size); + g_ptr_array_add (buf->buffers2, b); + sz = mc_read (fd, b, data_size); if (sz >= 0) ret += sz; if (sz != data_size) break; } + /* reverse buffer */ + for (i = 0; i < buf->buffers2->len / 2; i++) + { + void **b1, **b2; + + b1 = &g_ptr_array_index (buf->buffers2, i); + b2 = &g_ptr_array_index (buf->buffers2, buf->buffers2->len - 1 - i); + + b = *b1; + *b1 = *b2; + *b2 = b; + } + return ret; } @@ -482,62 +513,59 @@ edit_buffer_write_file (edit_buffer_t * buf, int fd) off_t ret = 0; off_t i; off_t data_size, sz; + void *b; /* write all fullfilled parts of buffers1 from begin to end */ - data_size = EDIT_BUF_SIZE; - for (i = 0; i < buf->curs1 >> S_EDIT_BUF_SIZE; i++) + if (buf->buffers1->len != 0) { - sz = mc_write (fd, (char *) buf->buffers1[i], data_size); + data_size = EDIT_BUF_SIZE; + for (i = 0; i < (off_t) buf->buffers1->len - 1; i++) + { + b = g_ptr_array_index (buf->buffers1, i); + sz = mc_write (fd, b, data_size); + if (sz >= 0) + ret += sz; + else if (i == 0) + ret = sz; + if (sz != data_size) + return ret; + } + + /* write last partially filled part of buffers1 */ + data_size = ((buf->curs1 - 1) & M_EDIT_BUF_SIZE) + 1; + b = g_ptr_array_index (buf->buffers1, i); + sz = mc_write (fd, b, data_size); if (sz >= 0) ret += sz; - else if (i == 0) - ret = sz; - - if (sz != data_size) - return ret; - } - - /* write last partially filled part of buffers1 */ - data_size = buf->curs1 & M_EDIT_BUF_SIZE; - if (data_size != 0) - { - sz = mc_write (fd, (char *) buf->buffers1[i], data_size); - if (sz >= 0) - ret += sz; - if (sz != data_size) return ret; } /* write buffers2 from end to begin, if buffers2 contains some data */ - if (buf->curs2 != 0) + if (buf->buffers2->len != 0) { - buf->curs2--; - /* write last partially filled part of buffers2 */ - i = buf->curs2 >> S_EDIT_BUF_SIZE; - data_size = (buf->curs2 & M_EDIT_BUF_SIZE) + 1; - sz = mc_write (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size); + i = buf->buffers2->len - 1; + b = g_ptr_array_index (buf->buffers2, i); + data_size = ((buf->curs2 - 1) & M_EDIT_BUF_SIZE) + 1; + sz = mc_write (fd, (char *) b + EDIT_BUF_SIZE - data_size, data_size); if (sz >= 0) ret += sz; if (sz == data_size) { - data_size = EDIT_BUF_SIZE; - /* write other fullfilled parts of buffers2 from end to begin */ + data_size = EDIT_BUF_SIZE; while (--i >= 0) { - sz = mc_write (fd, (char *) buf->buffers2[i], data_size); + b = g_ptr_array_index (buf->buffers2, i); + sz = mc_write (fd, b, data_size); if (sz >= 0) ret += sz; - if (sz != data_size) break; } } - - buf->curs2++; } return ret; diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index b62e9a380..2733f9434 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -41,8 +41,8 @@ typedef struct edit_buffer_struct { off_t curs1; /* position of the cursor from the beginning of the file. */ off_t curs2; /* position from the end of the file */ - unsigned char *buffers1[MAXBUFF + 1]; /* all data up to curs1 */ - unsigned char *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */ + GPtrArray *buffers1; /* all data up to curs1 */ + GPtrArray *buffers2; /* all data from end of file down to curs2 */ } edit_buffer_t; /*** global variables defined in .c file *********************************************************/ From ca26181f5da4d634321b6ea12122f7c9550ec85b Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 21 Feb 2013 13:48:05 +0400 Subject: [PATCH 14/25] Rename edit_buffer_t members. Signed-off-by: Andrew Borodin --- src/editor/editbuffer.c | 86 ++++++++++++++++++++--------------------- src/editor/editbuffer.h | 4 +- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 747d47122..da9d2ddb0 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -46,8 +46,6 @@ * * here's a quick sketch of the layout: (don't run this through indent.) * - * (b1 is buffers1 and b2 is buffers2) - * * | * \0\0\0\0\0m e _ f i l e . \nf i n . \n|T h i s _ i s _ s o\0\0\0\0\0\0\0\0\0 * ______________________________________|______________________________________ @@ -108,11 +106,11 @@ edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) off_t p; p = buf->curs1 + buf->curs2 - byte_index - 1; - b = g_ptr_array_index (buf->buffers2, p >> S_EDIT_BUF_SIZE); + b = g_ptr_array_index (buf->b2, p >> S_EDIT_BUF_SIZE); return (char *) b + EDIT_BUF_SIZE - 1 - (p & M_EDIT_BUF_SIZE); } - b = g_ptr_array_index (buf->buffers1, byte_index >> S_EDIT_BUF_SIZE); + b = g_ptr_array_index (buf->b1, byte_index >> S_EDIT_BUF_SIZE); return (char *) b + (byte_index & M_EDIT_BUF_SIZE); } @@ -128,8 +126,8 @@ edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) void edit_buffer_init (edit_buffer_t * buf) { - buf->buffers1 = g_ptr_array_sized_new (MAXBUFF + 1); - buf->buffers2 = g_ptr_array_sized_new (MAXBUFF + 1); + buf->b1 = g_ptr_array_sized_new (MAXBUFF + 1); + buf->b2 = g_ptr_array_sized_new (MAXBUFF + 1); buf->curs1 = 0; buf->curs2 = 0; @@ -145,16 +143,16 @@ edit_buffer_init (edit_buffer_t * buf) void edit_buffer_clean (edit_buffer_t * buf) { - if (buf->buffers1 != NULL) + if (buf->b1 != NULL) { - g_ptr_array_foreach (buf->buffers1, (GFunc) g_free, NULL); - g_ptr_array_free (buf->buffers1, TRUE); + g_ptr_array_foreach (buf->b1, (GFunc) g_free, NULL); + g_ptr_array_free (buf->b1, TRUE); } - if (buf->buffers2 != NULL) + if (buf->b2 != NULL) { - g_ptr_array_foreach (buf->buffers2, (GFunc) g_free, NULL); - g_ptr_array_free (buf->buffers2, TRUE); + g_ptr_array_foreach (buf->b2, (GFunc) g_free, NULL); + g_ptr_array_free (buf->b2, TRUE); } } @@ -321,10 +319,10 @@ edit_buffer_insert (edit_buffer_t * buf, int c) /* add a new buffer if we've reached the end of the last one */ if (i == 0) - g_ptr_array_add (buf->buffers1, g_malloc0 (EDIT_BUF_SIZE)); + g_ptr_array_add (buf->b1, g_malloc0 (EDIT_BUF_SIZE)); /* perform the insertion */ - b = g_ptr_array_index (buf->buffers1, buf->curs1 >> S_EDIT_BUF_SIZE); + b = g_ptr_array_index (buf->b1, buf->curs1 >> S_EDIT_BUF_SIZE); *((unsigned char *) b + i) = (unsigned char) c; /* update cursor position */ @@ -350,10 +348,10 @@ edit_buffer_insert_ahead (edit_buffer_t * buf, int c) /* add a new buffer if we've reached the end of the last one */ if (i == 0) - g_ptr_array_add (buf->buffers2, g_malloc0 (EDIT_BUF_SIZE)); + g_ptr_array_add (buf->b2, g_malloc0 (EDIT_BUF_SIZE)); /* perform the insertion */ - b = g_ptr_array_index (buf->buffers2, buf->curs2 >> S_EDIT_BUF_SIZE); + b = g_ptr_array_index (buf->b2, buf->curs2 >> S_EDIT_BUF_SIZE); *((unsigned char *) b + EDIT_BUF_SIZE - 1 - i) = (unsigned char) c; /* update cursor position */ @@ -379,15 +377,15 @@ edit_buffer_delete (edit_buffer_t * buf) prev = buf->curs2 - 1; - b = g_ptr_array_index (buf->buffers2, prev >> S_EDIT_BUF_SIZE); + b = g_ptr_array_index (buf->b2, prev >> S_EDIT_BUF_SIZE); i = prev & M_EDIT_BUF_SIZE; c = *((unsigned char *) b + EDIT_BUF_SIZE - 1 - i); if (i == 0) { - i = buf->buffers2->len - 1; - b = g_ptr_array_index (buf->buffers2, i); - g_ptr_array_remove_index (buf->buffers2, i); + i = buf->b2->len - 1; + b = g_ptr_array_index (buf->b2, i); + g_ptr_array_remove_index (buf->b2, i); g_free (b); } @@ -415,15 +413,15 @@ edit_buffer_backspace (edit_buffer_t * buf) prev = buf->curs1 - 1; - b = g_ptr_array_index (buf->buffers1, prev >> S_EDIT_BUF_SIZE); + b = g_ptr_array_index (buf->b1, prev >> S_EDIT_BUF_SIZE); i = prev & M_EDIT_BUF_SIZE; c = *((unsigned char *) b + i); if (i == 0) { - i = buf->buffers1->len - 1; - b = g_ptr_array_index (buf->buffers1, i); - g_ptr_array_remove_index (buf->buffers1, i); + i = buf->b1->len - 1; + b = g_ptr_array_index (buf->b1, i); + g_ptr_array_remove_index (buf->b1, i); g_free (b); } @@ -454,26 +452,26 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) buf->curs2 = size; i = buf->curs2 >> S_EDIT_BUF_SIZE; - /* fill last part of buffers2 */ + /* fill last part of b2 */ data_size = buf->curs2 & M_EDIT_BUF_SIZE; if (data_size != 0) { b = g_malloc0 (EDIT_BUF_SIZE); - g_ptr_array_add (buf->buffers2, b); + g_ptr_array_add (buf->b2, b); ret = mc_read (fd, (char *) b + EDIT_BUF_SIZE - data_size, data_size); if (ret < 0 || ret != data_size) return ret; } - /* fullfill other parts of buffers2 from end to begin */ + /* fullfill other parts of b2 from end to begin */ data_size = EDIT_BUF_SIZE; for (--i; i >= 0; i--) { off_t sz; b = g_malloc0 (data_size); - g_ptr_array_add (buf->buffers2, b); + g_ptr_array_add (buf->b2, b); sz = mc_read (fd, b, data_size); if (sz >= 0) ret += sz; @@ -482,12 +480,12 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size) } /* reverse buffer */ - for (i = 0; i < buf->buffers2->len / 2; i++) + for (i = 0; i < buf->b2->len / 2; i++) { void **b1, **b2; - b1 = &g_ptr_array_index (buf->buffers2, i); - b2 = &g_ptr_array_index (buf->buffers2, buf->buffers2->len - 1 - i); + b1 = &g_ptr_array_index (buf->b2, i); + b2 = &g_ptr_array_index (buf->b2, buf->b2->len - 1 - i); b = *b1; *b1 = *b2; @@ -515,13 +513,13 @@ edit_buffer_write_file (edit_buffer_t * buf, int fd) off_t data_size, sz; void *b; - /* write all fullfilled parts of buffers1 from begin to end */ - if (buf->buffers1->len != 0) + /* write all fullfilled parts of b1 from begin to end */ + if (buf->b1->len != 0) { data_size = EDIT_BUF_SIZE; - for (i = 0; i < (off_t) buf->buffers1->len - 1; i++) + for (i = 0; i < (off_t) buf->b1->len - 1; i++) { - b = g_ptr_array_index (buf->buffers1, i); + b = g_ptr_array_index (buf->b1, i); sz = mc_write (fd, b, data_size); if (sz >= 0) ret += sz; @@ -531,9 +529,9 @@ edit_buffer_write_file (edit_buffer_t * buf, int fd) return ret; } - /* write last partially filled part of buffers1 */ + /* write last partially filled part of b1 */ data_size = ((buf->curs1 - 1) & M_EDIT_BUF_SIZE) + 1; - b = g_ptr_array_index (buf->buffers1, i); + b = g_ptr_array_index (buf->b1, i); sz = mc_write (fd, b, data_size); if (sz >= 0) ret += sz; @@ -541,12 +539,12 @@ edit_buffer_write_file (edit_buffer_t * buf, int fd) return ret; } - /* write buffers2 from end to begin, if buffers2 contains some data */ - if (buf->buffers2->len != 0) + /* write b2 from end to begin, if b2 contains some data */ + if (buf->b2->len != 0) { - /* write last partially filled part of buffers2 */ - i = buf->buffers2->len - 1; - b = g_ptr_array_index (buf->buffers2, i); + /* write last partially filled part of b2 */ + i = buf->b2->len - 1; + b = g_ptr_array_index (buf->b2, i); data_size = ((buf->curs2 - 1) & M_EDIT_BUF_SIZE) + 1; sz = mc_write (fd, (char *) b + EDIT_BUF_SIZE - data_size, data_size); if (sz >= 0) @@ -554,11 +552,11 @@ edit_buffer_write_file (edit_buffer_t * buf, int fd) if (sz == data_size) { - /* write other fullfilled parts of buffers2 from end to begin */ + /* write other fullfilled parts of b2 from end to begin */ data_size = EDIT_BUF_SIZE; while (--i >= 0) { - b = g_ptr_array_index (buf->buffers2, i); + b = g_ptr_array_index (buf->b2, i); sz = mc_write (fd, b, data_size); if (sz >= 0) ret += sz; diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index 2733f9434..fb685a6b4 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -41,8 +41,8 @@ typedef struct edit_buffer_struct { off_t curs1; /* position of the cursor from the beginning of the file. */ off_t curs2; /* position from the end of the file */ - GPtrArray *buffers1; /* all data up to curs1 */ - GPtrArray *buffers2; /* all data from end of file down to curs2 */ + GPtrArray *b1; /* all data up to curs1 */ + GPtrArray *b2; /* all data from end of file down to curs2 */ } edit_buffer_t; /*** global variables defined in .c file *********************************************************/ From c466b18f672306f808bb4a38a3c4f3ae72f5e83e Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 24 Feb 2013 16:21:53 +0400 Subject: [PATCH 15/25] (edit_indent_width, edit_insert_indent): move to wordproc.c and make static. Signed-off-by: Andrew Borodin --- src/editor/edit-impl.h | 2 -- src/editor/edit.c | 31 ------------------------------- src/editor/wordproc.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 806044569..4afb797c8 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -285,8 +285,6 @@ void book_mark_restore (WEdit * edit, int color); gboolean edit_line_is_blank (WEdit * edit, long line); gboolean is_break_char (char c); -long edit_indent_width (const WEdit * edit, off_t p); -void edit_insert_indent (WEdit * edit, int indent); void edit_options_dialog (WDialog * h); void edit_syntax_dialog (WEdit * edit); void edit_mail_dialog (WEdit * edit); diff --git a/src/editor/edit.c b/src/editor/edit.c index 24d31f5c8..c0da1506c 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -3196,37 +3196,6 @@ edit_delete_line (WEdit * edit) /* --------------------------------------------------------------------------------------------- */ -long -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_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); -} - -/* --------------------------------------------------------------------------------------------- */ - -void -edit_insert_indent (WEdit * edit, int indent) -{ - if (!option_fill_tabs_with_spaces) - { - while (indent >= TAB_SIZE) - { - edit_insert (edit, '\t'); - indent -= TAB_SIZE; - } - } - while (indent-- > 0) - edit_insert (edit, ' '); -} - -/* --------------------------------------------------------------------------------------------- */ - void edit_push_key_press (WEdit * edit) { diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index 3ade9aab3..3695a530c 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -354,6 +354,37 @@ replace_at (WEdit * edit, long q, int c) edit_insert_ahead (edit, c); } +/* --------------------------------------------------------------------------------------------- */ + +static long +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_buffer_get_byte (&edit->buffer, q)) != NULL + && q < edit->last_byte - 1) + q++; + /* count the number of columns of indentation */ + return (long) edit_move_forward3 (edit, p, 0, q); +} + +/* --------------------------------------------------------------------------------------------- */ + +static void +edit_insert_indent (WEdit * edit, long indent) +{ + if (!option_fill_tabs_with_spaces) + while (indent >= TAB_SIZE) + { + edit_insert (edit, '\t'); + indent -= TAB_SIZE; + } + + while (indent-- > 0) + edit_insert (edit, ' '); +} + /* --------------------------------------------------------------------------------------------- */ /** replaces a block of text */ From c5d35ac93b1c1dd75ba45230f35055b6bae7d51a Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 24 Feb 2013 16:15:11 +0400 Subject: [PATCH 16/25] A lot of type accuracies. Signed-off-by: Andrew Borodin --- src/editor/edit-impl.h | 4 +- src/editor/edit.c | 13 +-- src/editor/wordproc.c | 188 +++++++++++++++++++---------------------- 3 files changed, 98 insertions(+), 107 deletions(-) diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 4afb797c8..8f00d2703 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -226,7 +226,7 @@ gboolean edit_insert_file_cmd (WEdit * edit); char *edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsize * len, gsize * cut); -long edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath); +off_t edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath); gboolean edit_load_back_cmd (WEdit * edit); gboolean edit_load_forward_cmd (WEdit * edit); void edit_block_process_cmd (WEdit * edit, int macro_number); @@ -288,7 +288,7 @@ gboolean is_break_char (char c); void edit_options_dialog (WDialog * h); void edit_syntax_dialog (WEdit * edit); void edit_mail_dialog (WEdit * edit); -void format_paragraph (WEdit * edit, int force); +void format_paragraph (WEdit * edit, gboolean force); /* either command or char_for_insertion must be passed as -1 */ void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion); diff --git a/src/editor/edit.c b/src/editor/edit.c index c0da1506c..c84b05176 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -225,6 +225,7 @@ edit_insert_stream (WEdit * edit, FILE * f) { int c; off_t i = 0; + while ((c = fgetc (f)) >= 0) { edit_insert (edit, c); @@ -1888,7 +1889,7 @@ edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsiz /* --------------------------------------------------------------------------------------------- */ /** inserts a file at the cursor, returns count of inserted bytes on success */ -long +off_t edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath) { char *p; @@ -3420,7 +3421,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) if (option_auto_para_formatting) { - format_paragraph (edit, 0); + format_paragraph (edit, FALSE); edit->force |= REDRAW_PAGE; } else @@ -3553,7 +3554,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit_double_newline (edit); if (option_return_does_auto_indent) edit_auto_indent (edit); - format_paragraph (edit, 0); + format_paragraph (edit, FALSE); } else { @@ -3682,7 +3683,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit_tab_cmd (edit); if (option_auto_para_formatting) { - format_paragraph (edit, 0); + format_paragraph (edit, FALSE); edit->force |= REDRAW_PAGE; } else @@ -3906,7 +3907,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit_goto_cmd (edit); break; case CK_ParagraphFormat: - format_paragraph (edit, 1); + format_paragraph (edit, TRUE); edit->force |= REDRAW_PAGE; break; case CK_MacroDelete: @@ -4010,7 +4011,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) case CK_DeleteToWordEnd: case CK_DeleteToHome: case CK_DeleteToEnd: - format_paragraph (edit, 0); + format_paragraph (edit, FALSE); edit->force |= REDRAW_PAGE; } } diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index 3695a530c..191a58b3d 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -71,7 +71,7 @@ /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -static long +static off_t line_start (WEdit * edit, long line) { off_t p; @@ -86,36 +86,33 @@ line_start (WEdit * edit, long line) p = edit_move_forward (edit, p, line - l, 0); p = edit_bol (edit, p); - while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p))) + while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) p++; return p; } /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean bad_line_start (WEdit * edit, off_t p) { int c; c = edit_buffer_get_byte (&edit->buffer, p); if (c == '.') - { /* `...' is acceptable */ - if (edit_buffer_get_byte (&edit->buffer, p + 1) == '.' - && edit_buffer_get_byte (&edit->buffer, p + 2) == '.') - return 0; - return 1; + { + /* `...' is acceptable */ + return !(edit_buffer_get_byte (&edit->buffer, p + 1) == '.' + && edit_buffer_get_byte (&edit->buffer, p + 2) == '.'); } if (c == '-') { - if (edit_buffer_get_byte (&edit->buffer, p + 1) == '-' - && edit_buffer_get_byte (&edit->buffer, p + 2) == '-') - return 0; /* `---' is acceptable */ - return 1; + /* `---' is acceptable */ + return !(edit_buffer_get_byte (&edit->buffer, p + 1) == '-' + && edit_buffer_get_byte (&edit->buffer, p + 2) == '-'); } - if (strchr (NO_FORMAT_CHARS_START, c)) - return 1; - return 0; + + return (strchr (NO_FORMAT_CHARS_START, c) != NULL); } /* --------------------------------------------------------------------------------------------- */ @@ -124,26 +121,19 @@ bad_line_start (WEdit * edit, off_t p) * Return position in the file. */ -static long -begin_paragraph (WEdit * edit, int force) +static off_t +begin_paragraph (WEdit * edit, gboolean force) { long i; + for (i = edit->curs_line - 1; i >= 0; i--) - { - if (edit_line_is_blank (edit, i)) + if (edit_line_is_blank (edit, i) || + (force && bad_line_start (edit, line_start (edit, i)))) { i++; break; } - if (force) - { - if (bad_line_start (edit, line_start (edit, i))) - { - i++; - break; - } - } - } + return edit_move_backward (edit, edit_bol (edit, edit->buffer.curs1), edit->curs_line - i); } @@ -153,24 +143,19 @@ begin_paragraph (WEdit * edit, int force) * Return position in the file. */ -static long -end_paragraph (WEdit * edit, int force) +static off_t +end_paragraph (WEdit * edit, gboolean force) { long i; + for (i = edit->curs_line + 1; i <= edit->total_lines; i++) - { - if (edit_line_is_blank (edit, i)) + if (edit_line_is_blank (edit, i) || + (force && bad_line_start (edit, line_start (edit, i)))) { i--; break; } - if (force) - if (bad_line_start (edit, line_start (edit, i))) - { - i--; - break; - } - } + return edit_eol (edit, edit_move_forward (edit, edit_bol (edit, edit->buffer.curs1), i - edit->curs_line, 0)); @@ -179,9 +164,10 @@ end_paragraph (WEdit * edit, int force) /* --------------------------------------------------------------------------------------------- */ static unsigned char * -get_paragraph (WEdit * edit, off_t p, off_t q, int indent, int *size) +get_paragraph (WEdit * edit, off_t p, off_t q, gboolean indent, off_t * size) { unsigned char *s, *t; + #if 0 t = g_try_malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10); #else @@ -192,11 +178,11 @@ get_paragraph (WEdit * edit, off_t p, off_t q, int indent, int *size) for (s = t; p < q; p++, s++) { if (indent && edit_buffer_get_byte (&edit->buffer, p - 1) == '\n') - while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p))) + while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) p++; *s = edit_buffer_get_byte (&edit->buffer, p); } - *size = (unsigned long) (s - t); + *size = (off_t) (s - t); /* FIXME: all variables related to 'size' should be fixed */ t[*size] = '\n'; return t; @@ -205,15 +191,13 @@ get_paragraph (WEdit * edit, off_t p, off_t q, int indent, int *size) /* --------------------------------------------------------------------------------------------- */ static inline void -strip_newlines (unsigned char *t, int size) +strip_newlines (unsigned char *t, off_t size) { - unsigned char *p = t; - while (size-- != 0) - { + unsigned char *p; + + for (p = t; size-- != 0; p++) if (*p == '\n') *p = ' '; - p++; - } } /* --------------------------------------------------------------------------------------------- */ @@ -221,23 +205,23 @@ strip_newlines (unsigned char *t, int size) This function calculates the number of chars in a line specified to length l in pixels */ -static inline int -next_tab_pos (int x) +static inline off_t +next_tab_pos (off_t x) { - return x += tab_width - x % tab_width; + x += tab_width - x % tab_width; + return x; } /* --------------------------------------------------------------------------------------------- */ -static inline int -line_pixel_length (unsigned char *t, long b, int l) +static inline off_t +line_pixel_length (unsigned char *t, off_t b, off_t l) { - int x = 0, c, xn = 0; + off_t x = 0, xn = 0; while (TRUE) { - c = t[b]; - switch (c) + switch (t[b]) { case '\n': return b; @@ -258,11 +242,11 @@ line_pixel_length (unsigned char *t, long b, int l) /* --------------------------------------------------------------------------------------------- */ -static int -next_word_start (unsigned char *t, int q, int size) +static off_t +next_word_start (unsigned char *t, off_t q, off_t size) { - int i; - int saw_ws = 0; + off_t i; + gboolean saw_ws = FALSE; for (i = q; i < size; i++) { @@ -272,37 +256,37 @@ next_word_start (unsigned char *t, int q, int size) return -1; case '\t': case ' ': - saw_ws = 1; + saw_ws = TRUE; break; default: - if (saw_ws != 0) + if (saw_ws) return i; break; } } - return -1; + return (-1); } /* --------------------------------------------------------------------------------------------- */ /** find the start of a word */ static inline int -word_start (unsigned char *t, int q, int size) +word_start (unsigned char *t, off_t q, off_t size) { - int i = q; + off_t i; if (t[q] == ' ' || t[q] == '\t') return next_word_start (t, q, size); - while (TRUE) + for (i = q;; i--) { - int c; + unsigned char c; if (i == 0) - return -1; + return (-1); c = t[i - 1]; if (c == '\n') - return -1; + return (-1); if (c == ' ' || c == '\t') return i; i--; @@ -313,17 +297,18 @@ word_start (unsigned char *t, int q, int size) /** replaces ' ' with '\n' to properly format a paragraph */ static inline void -format_this (unsigned char *t, int size, int indent) +format_this (unsigned char *t, off_t size, long indent) { - int q = 0, ww; + off_t q = 0, ww; strip_newlines (t, size); ww = option_word_wrap_line_length * FONT_MEAN_WIDTH - indent; if (ww < FONT_MEAN_WIDTH * 2) ww = FONT_MEAN_WIDTH * 2; + while (TRUE) { - int p; + off_t p; q = line_pixel_length (t, q, ww); if (q > size) @@ -347,7 +332,7 @@ format_this (unsigned char *t, int size, int indent) /* --------------------------------------------------------------------------------------------- */ static inline void -replace_at (WEdit * edit, long q, int c) +replace_at (WEdit * edit, off_t q, int c) { edit_cursor_move (edit, q - edit->buffer.curs1); edit_delete (edit, TRUE); @@ -389,27 +374,29 @@ edit_insert_indent (WEdit * edit, long indent) /** replaces a block of text */ static inline void -put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size) +put_paragraph (WEdit * edit, unsigned char *t, off_t p, long indent, off_t size) { - long cursor; - int i, c = 0; + off_t cursor; + off_t i; + int c = '\0'; cursor = edit->buffer.curs1; - if (indent) - while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p))) + if (indent != 0) + while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) p++; for (i = 0; i < size; i++, p++) { - if (i && indent) + if (i != 0 && indent != 0) { if (t[i - 1] == '\n' && c == '\n') { - while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p))) + while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) p++; } else if (t[i - 1] == '\n') { off_t curs; + edit_cursor_move (edit, p - edit->buffer.curs1); curs = edit->buffer.curs1; edit_insert_indent (edit, indent); @@ -420,7 +407,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_buffer_get_byte (&edit->buffer, p))) + while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) { edit_delete (edit, TRUE); if (cursor > edit->buffer.curs1) @@ -429,6 +416,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size) p = edit->buffer.curs1; } } + c = edit_buffer_get_byte (&edit->buffer, p); if (c != t[i]) replace_at (edit, p, t[i]); @@ -438,10 +426,10 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size) /* --------------------------------------------------------------------------------------------- */ -static inline int +static inline long test_indent (const WEdit * edit, off_t p, off_t q) { - int indent; + long indent; indent = edit_indent_width (edit, p++); if (indent == 0) @@ -459,42 +447,44 @@ test_indent (const WEdit * edit, off_t p, off_t q) /* --------------------------------------------------------------------------------------------- */ void -format_paragraph (WEdit * edit, int force) +format_paragraph (WEdit * edit, gboolean force) { - long p, q; - int size; + off_t p, q; + off_t size; unsigned char *t; - int indent = 0; + long indent; + if (option_word_wrap_line_length < 2) return; if (edit_line_is_blank (edit, edit->curs_line)) return; + p = begin_paragraph (edit, force); q = end_paragraph (edit, force); indent = test_indent (edit, p, q); - t = get_paragraph (edit, p, q, indent, &size); - if (!t) + + t = get_paragraph (edit, p, q, indent != 0, &size); + if (t == NULL) return; + if (!force) { - int i; - if (strchr (NO_FORMAT_CHARS_START, *t)) + off_t i; + + if (strchr (NO_FORMAT_CHARS_START, *t) != NULL) { g_free (t); return; } + for (i = 0; i < size - 1; i++) - { - if (t[i] == '\n') + if (t[i] == '\n' && strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1]) != NULL) { - if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1])) - { - g_free (t); - return; - } + g_free (t); + return; } - } } + format_this (t, q - p, indent); put_paragraph (edit, t, p, indent, size); g_free (t); From 253d27b1a347ad0376b943d8c58ed126c7e8b72f Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 24 Feb 2013 18:14:29 +0400 Subject: [PATCH 17/25] (get_paragraph): refactoring. Signed-off-by: Andrew Borodin --- src/editor/wordproc.c | 62 +++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index 191a58b3d..696a1e0d6 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -163,28 +163,24 @@ end_paragraph (WEdit * edit, gboolean force) /* --------------------------------------------------------------------------------------------- */ -static unsigned char * -get_paragraph (WEdit * edit, off_t p, off_t q, gboolean indent, off_t * size) +static GString * +get_paragraph (const edit_buffer_t * buf, off_t p, off_t q, gboolean indent) { - unsigned char *s, *t; + GString *t; -#if 0 - t = g_try_malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10); -#else - t = g_try_malloc (2 * (q - p) + 100); -#endif - if (t == NULL) - return NULL; - for (s = t; p < q; p++, s++) + t = g_string_sized_new (128); + + for (; p < q; p++) { - if (indent && edit_buffer_get_byte (&edit->buffer, p - 1) == '\n') - while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) + if (indent && edit_buffer_get_byte (buf, p - 1) == '\n') + while (strchr ("\t ", edit_buffer_get_byte (buf, p)) != NULL) p++; - *s = edit_buffer_get_byte (&edit->buffer, p); + + g_string_append_c (t, edit_buffer_get_byte (buf, p)); } - *size = (off_t) (s - t); - /* FIXME: all variables related to 'size' should be fixed */ - t[*size] = '\n'; + + g_string_append_c (t, '\n'); + return t; } @@ -451,8 +447,9 @@ format_paragraph (WEdit * edit, gboolean force) { off_t p, q; off_t size; - unsigned char *t; + GString *t; long indent; + unsigned char *t2; if (option_word_wrap_line_length < 2) return; @@ -463,31 +460,26 @@ format_paragraph (WEdit * edit, gboolean force) q = end_paragraph (edit, force); indent = test_indent (edit, p, q); - t = get_paragraph (edit, p, q, indent != 0, &size); - if (t == NULL) - return; + t = get_paragraph (&edit->buffer, p, q, indent != 0); + size = t->len - 1; if (!force) { off_t i; - if (strchr (NO_FORMAT_CHARS_START, *t) != NULL) - { - g_free (t); - return; - } + if (strchr (NO_FORMAT_CHARS_START, t->str[0]) == NULL) + for (i = 0; i < size - 1; i++) + if (t->str[i] == '\n' && strchr (NO_FORMAT_CHARS_START "\t ", t->str[i + 1]) != NULL) + break; - for (i = 0; i < size - 1; i++) - if (t[i] == '\n' && strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1]) != NULL) - { - g_free (t); - return; - } + g_string_free (t, TRUE); + return; } - format_this (t, q - p, indent); - put_paragraph (edit, t, p, indent, size); - g_free (t); + t2 = (unsigned char *) g_string_free (t, FALSE); + format_this (t2, q - p, indent); + put_paragraph (edit, t2, p, indent, size); + g_free (t2); /* Scroll left as much as possible to show the formatted paragraph */ edit_scroll_left (edit, -edit->start_col); From 32ffd98e87f2d1379794049e7adf58ef87a3bde9 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 25 Feb 2013 16:27:16 +0400 Subject: [PATCH 18/25] Refactoring: move members from WEdit to edit_buffer_t and rename related functions: WEdit::last_byte -> edit_buffer_t::size WEdit::total_lines -> edit_buffer_t::lines WEdit::curs_line -> edit_buffer_t::curs_line edit_count_lines() -> edit_buffer_count_lines() Signed-off-by: Andrew Borodin --- src/editor/edit-impl.h | 1 - src/editor/edit.c | 192 ++++++++++++++++++---------------------- src/editor/editbuffer.c | 31 ++++++- src/editor/editbuffer.h | 9 +- src/editor/editcmd.c | 40 ++++----- src/editor/editdraw.c | 23 ++--- src/editor/editwidget.h | 3 - src/editor/syntax.c | 2 +- src/editor/wordproc.c | 14 +-- 9 files changed, 163 insertions(+), 152 deletions(-) diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 8f00d2703..3a1dbd055 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -153,7 +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); -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); off_t edit_move_backward (const WEdit * edit, off_t current, long lines); diff --git a/src/editor/edit.c b/src/editor/edit.c index c84b05176..faff73f99 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -162,9 +162,9 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) return FALSE; } - ret = (edit_buffer_read_file (&edit->buffer, file, edit->last_byte) == edit->last_byte); + ret = (edit_buffer_read_file (&edit->buffer, file, edit->buffer.size) == edit->buffer.size); if (ret) - edit->total_lines = edit_count_lines (edit, 0, edit->last_byte); + edit->buffer.lines = edit_buffer_count_lines (&edit->buffer, 0, edit->buffer.size); else { gchar *errmsg; @@ -358,11 +358,10 @@ edit_load_file (WEdit * edit) fast_load = FALSE; } - edit_buffer_init (&edit->buffer); - if (fast_load) { - edit->last_byte = edit->stat1.st_size; + edit_buffer_init (&edit->buffer, edit->stat1.st_size); + if (!edit_load_file_fast (edit, edit->filename_vpath)) { edit_clean (edit); @@ -371,7 +370,8 @@ edit_load_file (WEdit * edit) } else { - edit->last_byte = 0; + edit_buffer_init (&edit->buffer, 0); + if (edit->filename_vpath != NULL && *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) != '\0') { @@ -411,7 +411,7 @@ edit_load_position (WEdit * edit) else if (offset > 0) { edit_cursor_move (edit, offset); - line = edit->curs_line; + line = edit->buffer.curs_line; edit->search_start = edit->buffer.curs1; } @@ -432,7 +432,7 @@ edit_save_position (WEdit * edit) return; book_mark_serialize (edit, BOOK_MARK_COLOR); - save_file_position (edit->filename_vpath, edit->curs_line + 1, edit->curs_col, edit->buffer.curs1, + save_file_position (edit->filename_vpath, edit->buffer.curs_line + 1, edit->curs_col, edit->buffer.curs1, edit->serialized_bookmarks); edit->serialized_bookmarks = NULL; } @@ -614,13 +614,13 @@ edit_find_line (WEdit * edit, long line) memset (edit->line_numbers, 0, sizeof (edit->line_numbers)); memset (edit->line_offsets, 0, sizeof (edit->line_offsets)); /* three offsets that we *know* are line 0 at 0 and these two: */ - edit->line_numbers[1] = edit->curs_line; + edit->line_numbers[1] = edit->buffer.curs_line; edit->line_offsets[1] = edit_bol (edit, edit->buffer.curs1); - edit->line_numbers[2] = edit->total_lines; - edit->line_offsets[2] = edit_bol (edit, edit->last_byte); + edit->line_numbers[2] = edit->buffer.lines; + edit->line_offsets[2] = edit_bol (edit, edit->buffer.size); edit->caches_valid = TRUE; } - if (line >= edit->total_lines) + if (line >= edit->buffer.lines) return edit->line_offsets[2]; if (line <= 0) return 0; @@ -661,17 +661,17 @@ edit_move_up_paragraph (WEdit * edit, gboolean do_scroll) { long i = 0; - if (edit->curs_line > 1) + if (edit->buffer.curs_line > 1) { - if (!edit_line_is_blank (edit, edit->curs_line)) + if (!edit_line_is_blank (edit, edit->buffer.curs_line)) { - for (i = edit->curs_line - 1; i != 0; i--) + for (i = edit->buffer.curs_line - 1; i != 0; i--) if (edit_line_is_blank (edit, i)) break; } - else if (edit_line_is_blank (edit, edit->curs_line - 1)) + else if (edit_line_is_blank (edit, edit->buffer.curs_line - 1)) { - for (i = edit->curs_line - 1; i != 0; i--) + for (i = edit->buffer.curs_line - 1; i != 0; i--) if (!edit_line_is_blank (edit, i)) { i++; @@ -680,13 +680,13 @@ edit_move_up_paragraph (WEdit * edit, gboolean do_scroll) } else { - for (i = edit->curs_line - 1; i != 0; i--) + for (i = edit->buffer.curs_line - 1; i != 0; i--) if (edit_line_is_blank (edit, i)) break; } } - edit_move_up (edit, edit->curs_line - i, do_scroll); + edit_move_up (edit, edit->buffer.curs_line - i, do_scroll); } /* --------------------------------------------------------------------------------------------- */ @@ -698,18 +698,18 @@ edit_move_down_paragraph (WEdit * edit, gboolean do_scroll) { long i; - if (edit->curs_line >= edit->total_lines - 1) - i = edit->total_lines; - else if (!edit_line_is_blank (edit, edit->curs_line)) + if (edit->buffer.curs_line >= edit->buffer.lines - 1) + i = edit->buffer.lines; + else if (!edit_line_is_blank (edit, edit->buffer.curs_line)) { - for (i = edit->curs_line + 1; i != 0; i++) - if (edit_line_is_blank (edit, i) || i >= edit->total_lines) + for (i = edit->buffer.curs_line + 1; i != 0; i++) + if (edit_line_is_blank (edit, i) || i >= edit->buffer.lines) break; } - else if (edit_line_is_blank (edit, edit->curs_line + 1)) + else if (edit_line_is_blank (edit, edit->buffer.curs_line + 1)) { - for (i = edit->curs_line + 1; i != 0; i++) - if (!edit_line_is_blank (edit, i) || i > edit->total_lines) + for (i = edit->buffer.curs_line + 1; i != 0; i++) + if (!edit_line_is_blank (edit, i) || i > edit->buffer.lines) { i--; break; @@ -717,11 +717,11 @@ edit_move_down_paragraph (WEdit * edit, gboolean do_scroll) } else { - for (i = edit->curs_line + 1; i != 0; i++) - if (edit_line_is_blank (edit, i) || i >= edit->total_lines) + for (i = edit->buffer.curs_line + 1; i != 0; i++) + if (edit_line_is_blank (edit, i) || i >= edit->buffer.lines) break; } - edit_move_down (edit, i - edit->curs_line, do_scroll); + edit_move_down (edit, i - edit->buffer.curs_line, do_scroll); } /* --------------------------------------------------------------------------------------------- */ @@ -749,7 +749,7 @@ edit_end_page (WEdit * edit) static void edit_move_to_top (WEdit * edit) { - if (edit->curs_line) + if (edit->buffer.curs_line != 0) { edit_cursor_move (edit, -edit->buffer.curs1); edit_move_to_prev_col (edit, 0); @@ -759,18 +759,17 @@ edit_move_to_top (WEdit * edit) } } - /* --------------------------------------------------------------------------------------------- */ /** goto end of text */ static void edit_move_to_bottom (WEdit * edit) { - if (edit->curs_line < edit->total_lines) + if (edit->buffer.curs_line < edit->buffer.lines) { - edit_move_down (edit, edit->total_lines - edit->curs_row, 0); - edit->start_display = edit->last_byte; - edit->start_line = edit->total_lines; + edit_move_down (edit, edit->buffer.lines - edit->curs_row, 0); + edit->start_display = edit->buffer.size; + edit->start_line = edit->buffer.lines; edit_scroll_upward (edit, WIDGET (edit)->lines - 1); edit->force |= REDRAW_PAGE; } @@ -894,7 +893,7 @@ edit_right_word_move (WEdit * edit, int s) && edit->over_col == 0 && edit->buffer.curs1 == edit_eol (edit, edit->buffer.curs1)) break; edit_cursor_move (edit, 1); - if (edit->buffer.curs1 >= edit->last_byte) + if (edit->buffer.curs1 >= edit->buffer.size) break; c1 = edit_buffer_get_previous_byte (&edit->buffer); c2 = edit_buffer_get_current_byte (&edit->buffer); @@ -983,7 +982,7 @@ static void edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean direction) { long p; - long l = direction ? edit->curs_line : edit->total_lines - edit->curs_line; + long l = direction ? edit->buffer.curs_line : edit->buffer.lines - edit->buffer.curs_line; if (lines > l) lines = l; @@ -1010,7 +1009,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 + if (edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->buffer.size && edit_buffer_get_current_byte (&edit->buffer) >= 256) { edit_right_char_move_cmd (edit); @@ -1027,7 +1026,7 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi static void edit_right_delete_word (WEdit * edit) { - while (edit->buffer.curs1 < edit->last_byte) + while (edit->buffer.curs1 < edit->buffer.size) { int c1, c2; @@ -1130,12 +1129,12 @@ edit_do_undo (WEdit * edit) if (edit->start_display > ac - KEY_PRESS) { - edit->start_line -= edit_count_lines (edit, ac - KEY_PRESS, edit->start_display); + edit->start_line -= edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display); edit->force |= REDRAW_PAGE; } else if (edit->start_display < ac - KEY_PRESS) { - edit->start_line += edit_count_lines (edit, edit->start_display, ac - KEY_PRESS); + edit->start_line += edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS); edit->force |= REDRAW_PAGE; } edit->start_display = ac - KEY_PRESS; /* see push and pop above */ @@ -1206,12 +1205,12 @@ edit_do_redo (WEdit * edit) if (edit->start_display > ac - KEY_PRESS) { - edit->start_line -= edit_count_lines (edit, ac - KEY_PRESS, edit->start_display); + edit->start_line -= edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display); edit->force |= REDRAW_PAGE; } else if (edit->start_display < ac - KEY_PRESS) { - edit->start_line += edit_count_lines (edit, edit->start_display, ac - KEY_PRESS); + edit->start_line += edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS); edit->force |= REDRAW_PAGE; } edit->start_display = ac - KEY_PRESS; /* see push and pop above */ @@ -1449,7 +1448,7 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack for (q = edit->buffer.curs1 + inc;; q += inc) { /* out of buffer? */ - if (q >= edit->last_byte || q < 0) + if (q >= edit->buffer.size || q < 0) break; a = edit_buffer_get_byte (&edit->buffer, q); /* don't want to eat CPU */ @@ -1508,7 +1507,7 @@ edit_move_block_to_right (WEdit * edit) do { edit_cursor_move (edit, cur_bol - edit->buffer.curs1); - if (!edit_line_is_blank (edit, edit->curs_line)) + if (!edit_line_is_blank (edit, edit->buffer.curs_line)) { if (option_fill_tabs_with_spaces) insert_spaces_tab (edit, option_fake_half_tabs); @@ -1631,9 +1630,9 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * for (p = edit->buffer.curs1;; p++) { - if (p == edit->last_byte) + if (p == edit->buffer.size) { - edit_cursor_move (edit, edit->last_byte - edit->buffer.curs1); + edit_cursor_move (edit, edit->buffer.size - edit->buffer.curs1); edit_insert_ahead (edit, '\n'); p++; break; @@ -1751,14 +1750,14 @@ edit_write_stream (WEdit * edit, FILE * f) if (edit->lb == LB_ASIS) { - for (i = 0; i < edit->last_byte; i++) + for (i = 0; i < edit->buffer.size; i++) if (fputc (edit_buffer_get_byte (&edit->buffer, i), f) < 0) break; return i; } /* change line breaks */ - for (i = 0; i < edit->last_byte; i++) + for (i = 0; i < edit->buffer.size; i++) { unsigned char c; @@ -1838,7 +1837,7 @@ edit_write_stream (WEdit * edit, FILE * f) } } - return edit->last_byte; + return edit->buffer.size; } /* --------------------------------------------------------------------------------------------- */ @@ -2466,9 +2465,9 @@ edit_insert (WEdit * edit, int c) /* now we must update some info on the file and check if a redraw is required */ if (c == '\n') { - book_mark_inc (edit, edit->curs_line); - edit->curs_line++; - edit->total_lines++; + book_mark_inc (edit, edit->buffer.curs_line); + edit->buffer.curs_line++; + edit->buffer.lines++; edit->force |= REDRAW_LINE_ABOVE | REDRAW_AFTER_CURSOR; } @@ -2486,7 +2485,7 @@ edit_insert (WEdit * edit, int c) edit_buffer_insert (&edit->buffer, c); /* update file length */ - edit->last_byte++; + edit->buffer.size++; } /* --------------------------------------------------------------------------------------------- */ @@ -2507,8 +2506,8 @@ edit_insert_ahead (WEdit * edit, int c) edit_modification (edit); if (c == '\n') { - book_mark_inc (edit, edit->curs_line); - edit->total_lines++; + book_mark_inc (edit, edit->buffer.curs_line); + edit->buffer.lines++; edit->force |= REDRAW_AFTER_CURSOR; } /* ordinary char and not space */ @@ -2523,7 +2522,7 @@ edit_insert_ahead (WEdit * edit, int c) edit_buffer_insert_ahead (&edit->buffer, c); - edit->last_byte++; + edit->buffer.size++; } /* --------------------------------------------------------------------------------------------- */ @@ -2580,15 +2579,15 @@ edit_delete (WEdit * edit, gboolean byte_delete) p = edit_buffer_delete (&edit->buffer); - edit->last_byte--; + edit->buffer.size--; edit_push_undo_action (edit, p + 256); } edit_modification (edit); if (p == '\n') { - book_mark_dec (edit, edit->curs_line); - edit->total_lines--; + book_mark_dec (edit, edit->buffer.curs_line); + edit->buffer.lines--; edit->force |= REDRAW_AFTER_CURSOR; } if (edit->buffer.curs1 < edit->start_display) @@ -2641,15 +2640,15 @@ edit_backspace (WEdit * edit, gboolean byte_delete) p = edit_buffer_backspace (&edit->buffer); - edit->last_byte--; + edit->buffer.size--; edit_push_undo_action (edit, p); } edit_modification (edit); if (p == '\n') { - book_mark_dec (edit, edit->curs_line); - edit->curs_line--; - edit->total_lines--; + book_mark_dec (edit, edit->buffer.curs_line); + edit->buffer.curs_line--; + edit->buffer.lines--; edit->force |= REDRAW_AFTER_CURSOR; } @@ -2682,7 +2681,7 @@ edit_cursor_move (WEdit * edit, off_t increment) c = edit_buffer_backspace (&edit->buffer); if (c == '\n') { - edit->curs_line--; + edit->buffer.curs_line--; edit->force |= REDRAW_LINE_BELOW; } } @@ -2700,7 +2699,7 @@ edit_cursor_move (WEdit * edit, off_t increment) c = edit_buffer_delete (&edit->buffer); if (c == '\n') { - edit->curs_line++; + edit->buffer.curs_line++; edit->force |= REDRAW_LINE_ABOVE; } } @@ -2715,8 +2714,8 @@ edit_cursor_move (WEdit * edit, off_t increment) off_t edit_eol (const WEdit * edit, off_t current) { - if (current >= edit->last_byte) - return edit->last_byte; + if (current >= edit->buffer.size) + return edit->buffer.size; for (; edit_buffer_get_byte (&edit->buffer, current) != '\n'; current++) ; @@ -2739,23 +2738,6 @@ edit_bol (const WEdit * edit, off_t current) return current; } -/* --------------------------------------------------------------------------------------------- */ - -long -edit_count_lines (const WEdit * edit, off_t current, off_t upto) -{ - long lines = 0; - - if (upto > edit->last_byte) - upto = edit->last_byte; - if (current < 0) - current = 0; - while (current < upto) - if (edit_buffer_get_byte (&edit->buffer, current++) == '\n') - lines++; - return lines; -} - /* --------------------------------------------------------------------------------------------- */ /* If lines is zero this returns the count of lines from current to upto. */ /* If upto is zero returns index of lines forward current. */ @@ -2764,9 +2746,7 @@ off_t edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto) { if (upto != 0) - { - return (off_t) edit_count_lines (edit, current, upto); - } + return (off_t) edit_buffer_count_lines (&edit->buffer, current, upto); else { long next; @@ -2775,7 +2755,7 @@ edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto) while (lines-- != 0) { next = edit_eol (edit, current) + 1; - if (next > edit->last_byte) + if (next > edit->buffer.size) break; else current = next; @@ -2814,7 +2794,7 @@ edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) cols = -10; } else - q = edit->last_byte + 2; + q = edit->buffer.size + 2; for (col = 0, p = current; p < q; p++) { @@ -2885,7 +2865,7 @@ edit_get_col (const WEdit * edit) void edit_update_curs_row (WEdit * edit) { - edit->curs_row = edit->curs_line - edit->start_line; + edit->curs_row = edit->buffer.curs_line - edit->start_line; } /* --------------------------------------------------------------------------------------------- */ @@ -2932,7 +2912,7 @@ edit_scroll_downward (WEdit * edit, long i) { long lines_below; - lines_below = edit->total_lines - edit->start_line - (WIDGET (edit)->lines - 1); + lines_below = edit->buffer.lines - edit->start_line - (WIDGET (edit)->lines - 1); if (lines_below > 0) { if (i > lines_below) @@ -3048,10 +3028,10 @@ edit_line_is_blank (WEdit * edit, long line) void edit_move_to_line (WEdit * e, long line) { - if (line < e->curs_line) - edit_move_up (e, e->curs_line - line, 0); + if (line < e->buffer.curs_line) + edit_move_up (e, e->buffer.curs_line - line, 0); else - edit_move_down (e, line - e->curs_line, 0); + edit_move_down (e, line - e->buffer.curs_line, 0); edit_scroll_screen_over_cursor (e); } @@ -3138,7 +3118,7 @@ edit_mark_current_word_cmd (WEdit * edit) } edit->mark1 = pos; - for (; pos < edit->last_byte; pos++) + for (; pos < edit->buffer.size; pos++) { int c1, c2; @@ -3149,7 +3129,7 @@ edit_mark_current_word_cmd (WEdit * edit) if ((my_type_of (c1) & my_type_of (c2)) == 0) break; } - edit->mark2 = min (pos + 1, edit->last_byte); + edit->mark2 = min (pos + 1, edit->buffer.size); edit->force |= REDRAW_LINE_ABOVE | REDRAW_AFTER_CURSOR; } @@ -3711,7 +3691,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit_mark_cmd (edit, FALSE); break; case CK_MarkAll: - edit_set_markers (edit, 0, edit->last_byte, 0, 0); + edit_set_markers (edit, 0, edit->buffer.size, 0, 0); edit->force |= REDRAW_PAGE; break; case CK_Unmark: @@ -3734,11 +3714,11 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) break; case CK_Bookmark: - book_mark_clear (edit, edit->curs_line, BOOK_MARK_FOUND_COLOR); - if (book_mark_query_color (edit, edit->curs_line, BOOK_MARK_COLOR)) - book_mark_clear (edit, edit->curs_line, BOOK_MARK_COLOR); + book_mark_clear (edit, edit->buffer.curs_line, BOOK_MARK_FOUND_COLOR); + if (book_mark_query_color (edit, edit->buffer.curs_line, BOOK_MARK_COLOR)) + book_mark_clear (edit, edit->buffer.curs_line, BOOK_MARK_COLOR); else - book_mark_insert (edit, edit->curs_line, BOOK_MARK_COLOR); + book_mark_insert (edit, edit->buffer.curs_line, BOOK_MARK_COLOR); break; case CK_BookmarkFlush: book_mark_flush (edit, BOOK_MARK_COLOR); @@ -3750,7 +3730,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) { edit_book_mark_t *p; - p = book_mark_find (edit, edit->curs_line); + p = book_mark_find (edit, edit->buffer.curs_line); if (p->next != NULL) { p = p->next; @@ -3765,8 +3745,8 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) { edit_book_mark_t *p; - p = book_mark_find (edit, edit->curs_line); - while (p->line == edit->curs_line) + p = book_mark_find (edit, edit->buffer.curs_line); + while (p->line == edit->buffer.curs_line) if (p->prev != NULL) p = p->prev; if (p->line >= 0) diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index da9d2ddb0..0b1cd184a 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -124,13 +124,16 @@ edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) */ void -edit_buffer_init (edit_buffer_t * buf) +edit_buffer_init (edit_buffer_t * buf, off_t size) { buf->b1 = g_ptr_array_sized_new (MAXBUFF + 1); buf->b2 = g_ptr_array_sized_new (MAXBUFF + 1); buf->curs1 = 0; buf->curs2 = 0; + + buf->size = size; + buf->lines = 0; } /* --------------------------------------------------------------------------------------------- */ @@ -300,6 +303,32 @@ edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char } #endif /* HAVE_CHARSET */ +/* --------------------------------------------------------------------------------------------- */ +/** + * Count lines in editor buffer. + * + * @param buf editor buffer + * @param first start byte offset + * @param last finish byte offset + * + * @return line numbers between "first" and "last" bytes + */ + +long +edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last) +{ + long lines = 0; + + first = max (first, 0); + last = min (last, buf->size); + + while (first < last) + if (edit_buffer_get_byte (buf, first++) == '\n') + lines++; + + return lines; +} + /* --------------------------------------------------------------------------------------------- */ /** * Basic low level single character buffer alterations and movements at the cursor: insert character diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index fb685a6b4..3b30f42dc 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -38,18 +38,22 @@ /*** structures declarations (and typedefs of structures)*****************************************/ -typedef struct edit_buffer_struct { +typedef struct edit_buffer_struct +{ off_t curs1; /* position of the cursor from the beginning of the file. */ off_t curs2; /* position from the end of the file */ GPtrArray *b1; /* all data up to curs1 */ GPtrArray *b2; /* all data from end of file down to curs2 */ + off_t size; /* file size */ + long lines; /* total lines in the file */ + long curs_line; /* line number of the cursor. */ } edit_buffer_t; /*** global variables defined in .c file *********************************************************/ /*** declarations of public functions ************************************************************/ -void edit_buffer_init (edit_buffer_t * buf); +void edit_buffer_init (edit_buffer_t * buf, off_t size); void edit_buffer_clean (edit_buffer_t * buf); int edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index); @@ -57,6 +61,7 @@ int edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index); 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 +long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last); void edit_buffer_insert (edit_buffer_t * buf, int c); void edit_buffer_insert_ahead (edit_buffer_t * buf, int c); diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 6bc47edc9..94409033b 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -311,7 +311,7 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) { /* do not change line breaks */ filelen = edit_buffer_write_file (&edit->buffer, fd); - if (filelen != edit->last_byte) + if (filelen != edit->buffer.size) { mc_close (fd); goto error_save; @@ -347,7 +347,7 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) } } - if (filelen != edit->last_byte) + if (filelen != edit->buffer.size) goto error_save; if (this_save_mode == EDIT_DO_BACKUP) @@ -395,8 +395,8 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) static gboolean edit_check_newline (WEdit * edit) { - return !(option_check_nl_at_eof && edit->last_byte > 0 - && edit_buffer_get_byte (&edit->buffer, edit->last_byte - 1) != '\n' + return !(option_check_nl_at_eof && edit->buffer.size > 0 + && edit_buffer_get_byte (&edit->buffer, edit->buffer.size - 1) != '\n' && edit_query_dialog2 (_("Warning"), _("The file you are saving is not finished with a newline"), _("C&ontinue"), _("&Cancel"))); @@ -573,7 +573,7 @@ edit_block_delete (WEdit * edit) edit_push_markers (edit); - curs_line = edit->curs_line; + curs_line = edit->buffer.curs_line; curs_pos = edit->curs_col + edit->over_col; @@ -780,7 +780,7 @@ editcmd_find (WEdit * edit, gsize * len) off_t search_start = edit->search_start; off_t search_end; off_t start_mark = 0; - off_t end_mark = edit->last_byte; + off_t end_mark = edit->buffer.size; int mark_res = 0; char end_string_symbol; @@ -802,11 +802,11 @@ editcmd_find (WEdit * edit, gsize * len) && (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, + edit_calculate_start_of_next_line (edit, start_mark, edit->buffer.size, end_string_symbol); } if ((edit->search_line_type & AT_END_LINE) != 0 - && (end_mark - 1 != edit->last_byte + && (end_mark - 1 != edit->buffer.size || 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); @@ -926,12 +926,12 @@ edit_do_search (WEdit * edit) search_create_bookmark = FALSE; book_mark_flush (edit, -1); - while (mc_search_run (edit->search, (void *) edit, q, edit->last_byte, &len)) + while (mc_search_run (edit->search, (void *) edit, q, edit->buffer.size, &len)) { if (found == 0) edit->search_start = edit->search->normal_offset; found++; - l += edit_count_lines (edit, q, edit->search->normal_offset); + l += edit_buffer_count_lines (&edit->buffer, q, edit->search->normal_offset); if (l != l_last) { book_mark_insert (edit, l, BOOK_MARK_FOUND_COLOR); @@ -1072,7 +1072,7 @@ pipe_mail (WEdit * edit, char *to, char *subject, char *cc) if (p) { off_t i; - for (i = 0; i < edit->last_byte; i++) + for (i = 0; i < edit->buffer.size; i++) fputc (edit_buffer_get_byte (&edit->buffer, i), p); pclose (p); } @@ -1139,7 +1139,7 @@ edit_collect_completions_get_current_word (WEdit * edit, mc_search_t * srch, off off_t i; GString *temp; - if (!mc_search_run (srch, (void *) edit, word_start, edit->last_byte, &len)) + if (!mc_search_run (srch, (void *) edit, word_start, edit->buffer.size, &len)) return NULL; temp = g_string_sized_new (len); @@ -1179,7 +1179,7 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len, if (mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "editor_wordcompletion_collect_entire_file", 0)) { - last_byte = edit->last_byte; + last_byte = edit->buffer.size; } else { @@ -1300,9 +1300,9 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long } for (p = edit->buffer.curs1;; p++) { - if (p == edit->last_byte) + if (p == edit->buffer.size) { - edit_cursor_move (edit, edit->last_byte - edit->buffer.curs1); + edit_cursor_move (edit, edit->buffer.size - edit->buffer.curs1); edit_insert_ahead (edit, '\n'); p++; break; @@ -2546,7 +2546,7 @@ edit_replace_cmd (WEdit * edit, int again) edit->search_start = edit->search->normal_offset; /*returns negative on not found or error in pattern */ - if ((edit->search_start >= 0) && (edit->search_start < edit->last_byte)) + if ((edit->search_start >= 0) && (edit->search_start < edit->buffer.size)) { gsize i; GString *repl_str; @@ -2627,7 +2627,7 @@ edit_replace_cmd (WEdit * edit, int again) { edit->search_start += edit->found_len + (len == 0 ? 1 : 0); - if (edit->search_start >= edit->last_byte) + if (edit->search_start >= edit->buffer.size) break; } @@ -2967,7 +2967,7 @@ edit_goto_cmd (WEdit * edit) line = l; if (l < 0) - l = edit->total_lines + l + 2; + l = edit->buffer.lines + l + 2; edit_move_display (edit, l - WIDGET (edit)->lines / 2 - 1); edit_move_to_line (edit, l - 1); edit->force |= REDRAW_COMPLETELY; @@ -3561,7 +3561,7 @@ edit_suggest_current_word (WEdit * edit) void edit_spellcheck_file (WEdit * edit) { - if (edit->curs_line > 0) + if (edit->buffer.curs_line > 0) { edit_cursor_move (edit, -edit->buffer.curs1); edit_move_to_prev_col (edit, 0); @@ -3576,7 +3576,7 @@ edit_spellcheck_file (WEdit * edit) do { - if (edit->buffer.curs1 >= edit->last_byte) + if (edit->buffer.curs1 >= edit->buffer.size) return; c1 = c2; diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 434ddd877..789fe4a0a 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -114,7 +114,7 @@ status_string (WEdit * edit, char *s, int w) * otherwise print the current character as is (if printable), * as decimal and as hex. */ - if (edit->buffer.curs1 < edit->last_byte) + if (edit->buffer.curs1 < edit->buffer.size) { #ifdef HAVE_CHARSET if (edit->utf8) @@ -159,8 +159,8 @@ status_string (WEdit * edit, char *s, int w) macro_index < 0 ? '-' : 'R', edit->overwrite == 0 ? '-' : 'O', edit->curs_col + edit->over_col, - edit->curs_line + 1, - edit->total_lines + 1, (long) edit->buffer.curs1, (long) edit->last_byte, byte_str, + edit->buffer.curs_line + 1, + edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, byte_str, #ifdef HAVE_CHARSET mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : #endif @@ -175,8 +175,8 @@ status_string (WEdit * edit, char *s, int w) edit->curs_col + edit->over_col, edit->start_line + 1, edit->curs_row, - edit->curs_line + 1, - edit->total_lines + 1, (long) edit->buffer.curs1, (long) edit->last_byte, byte_str, + edit->buffer.curs_line + 1, + edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, byte_str, #ifdef HAVE_CHARSET mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : #endif @@ -233,8 +233,8 @@ edit_status_fullscreen (WEdit * edit, int color) { size_t percent = 100; - if (edit->total_lines + 1 != 0) - percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1); + if (edit->buffer.lines + 1 != 0) + percent = (edit->buffer.curs_line + 1) * 100 / (edit->buffer.lines + 1); widget_move (h, 0, w - 6 - 6); tty_printf (" %3d%%", percent); } @@ -292,7 +292,8 @@ edit_status_window (WEdit * edit) edit_move (2, w->lines - 1); tty_printf ("%3ld %5ld/%ld %6ld/%ld", edit->curs_col + edit->over_col, - edit->curs_line + 1, edit->total_lines + 1, edit->buffer.curs1, edit->last_byte); + edit->buffer.curs_line + 1, edit->buffer.lines + 1, edit->buffer.curs1, + edit->buffer.size); } /* @@ -303,7 +304,7 @@ edit_status_window (WEdit * edit) if (cols > 46) { edit_move (32, w->lines - 1); - if (edit->buffer.curs1 >= edit->last_byte) + if (edit->buffer.curs1 >= edit->buffer.size) tty_print_string ("[ ]"); #ifdef HAVE_CHARSET else if (edit->utf8) @@ -545,7 +546,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c if (option_line_state) { cur_line = edit->start_line + row; - if (cur_line <= (unsigned int) edit->total_lines) + if (cur_line <= (unsigned int) edit->buffer.lines) { g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1); } @@ -564,7 +565,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c { eval_marks (edit, &m1, &m2); - if (row <= edit->total_lines - edit->start_line) + if (row <= edit->buffer.lines - edit->start_line) { off_t tws = 0; if (tty_use_colors () && visible_tws) diff --git a/src/editor/editwidget.h b/src/editor/editwidget.h index 1f62827a6..90c73f6ee 100644 --- a/src/editor/editwidget.h +++ b/src/editor/editwidget.h @@ -97,7 +97,6 @@ struct WEdit off_t found_start; /* the found word from a search - start position */ /* display information */ - off_t last_byte; /* Last byte of file */ long start_display; /* First char displayed */ long start_col; /* First displayed column, negative */ long max_column; /* The maximum cursor position ever reached used to calc hori scroll bar */ @@ -115,11 +114,9 @@ struct WEdit unsigned int fullscreen:1; /* Is window fullscreen or not */ long prev_col; /* recent column position of the cursor - used when moving up or down past lines that are shorter than the current line */ - long curs_line; /* line number of the cursor. */ long start_line; /* line number of the top of the page */ /* file info */ - long total_lines; /* total lines in the file */ off_t mark1; /* position of highlight start */ off_t mark2; /* position of highlight end */ off_t end_mark_curs; /* position of cursor after end of highlighting */ diff --git a/src/editor/syntax.c b/src/editor/syntax.c index 4097b1d0b..d94540a20 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -1399,7 +1399,7 @@ edit_get_syntax_color (WEdit * edit, off_t byte_index) if (!tty_use_colors ()) return 0; - if (edit->rules != NULL && byte_index < edit->last_byte && option_syntax_highlighting) + if (edit->rules != NULL && byte_index < edit->buffer.size && option_syntax_highlighting) { edit_get_rule (edit, byte_index); return translate_rule_to_color (edit, &edit->rule); diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index 696a1e0d6..a488d7596 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -77,7 +77,7 @@ line_start (WEdit * edit, long line) off_t p; long l; - l = edit->curs_line; + l = edit->buffer.curs_line; p = edit->buffer.curs1; if (line < l) @@ -126,7 +126,7 @@ begin_paragraph (WEdit * edit, gboolean force) { long i; - for (i = edit->curs_line - 1; i >= 0; i--) + for (i = edit->buffer.curs_line - 1; i >= 0; i--) if (edit_line_is_blank (edit, i) || (force && bad_line_start (edit, line_start (edit, i)))) { @@ -134,7 +134,7 @@ begin_paragraph (WEdit * edit, gboolean force) break; } - return edit_move_backward (edit, edit_bol (edit, edit->buffer.curs1), edit->curs_line - i); + return edit_move_backward (edit, edit_bol (edit, edit->buffer.curs1), edit->buffer.curs_line - i); } /* --------------------------------------------------------------------------------------------- */ @@ -148,7 +148,7 @@ end_paragraph (WEdit * edit, gboolean force) { long i; - for (i = edit->curs_line + 1; i <= edit->total_lines; i++) + for (i = edit->buffer.curs_line + 1; i <= edit->buffer.lines; i++) if (edit_line_is_blank (edit, i) || (force && bad_line_start (edit, line_start (edit, i)))) { @@ -158,7 +158,7 @@ end_paragraph (WEdit * edit, gboolean force) return edit_eol (edit, edit_move_forward (edit, edit_bol (edit, edit->buffer.curs1), - i - edit->curs_line, 0)); + i - edit->buffer.curs_line, 0)); } /* --------------------------------------------------------------------------------------------- */ @@ -344,7 +344,7 @@ edit_indent_width (const WEdit * edit, off_t p) /* move to the end of the leading whitespace of the line */ while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, q)) != NULL - && q < edit->last_byte - 1) + && q < edit->buffer.size - 1) q++; /* count the number of columns of indentation */ return (long) edit_move_forward3 (edit, p, 0, q); @@ -453,7 +453,7 @@ format_paragraph (WEdit * edit, gboolean force) if (option_word_wrap_line_length < 2) return; - if (edit_line_is_blank (edit, edit->curs_line)) + if (edit_line_is_blank (edit, edit->buffer.curs_line)) return; p = begin_paragraph (edit, force); From 506b3d4eee80b494b7650a3c4944a1d8df5653a5 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 25 Feb 2013 17:08:53 +0400 Subject: [PATCH 19/25] Refactoring: rename functions of getting BOL and EOFL: edit_bol() -> edit_buffer_get_bol() edit_eol() -> edit_buffer_get_eol() Signed-off-by: Andrew Borodin --- src/editor/edit-impl.h | 2 - src/editor/edit.c | 110 +++++++++++++++------------------------- src/editor/editbuffer.c | 44 ++++++++++++++++ src/editor/editbuffer.h | 32 ++++++++++++ src/editor/editcmd.c | 28 +++++----- src/editor/editdraw.c | 10 ++-- src/editor/editwidget.c | 8 +-- src/editor/wordproc.c | 8 +-- 8 files changed, 145 insertions(+), 97 deletions(-) diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 3a1dbd055..f510906bb 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -166,8 +166,6 @@ void edit_move_up (WEdit * edit, long i, gboolean do_scroll); void edit_move_down (WEdit * edit, long i, gboolean do_scroll); void edit_move_to_prev_col (WEdit * edit, off_t p); long edit_get_col (const WEdit * edit); -off_t edit_bol (const WEdit * edit, off_t current); -off_t edit_eol (const WEdit * edit, off_t current); void edit_update_curs_row (WEdit * edit); void edit_update_curs_col (WEdit * edit); void edit_find_bracket (WEdit * edit); diff --git a/src/editor/edit.c b/src/editor/edit.c index faff73f99..e850c6fca 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -417,7 +417,7 @@ edit_load_position (WEdit * edit) book_mark_restore (edit, BOOK_MARK_COLOR); - edit_move_to_prev_col (edit, edit_bol (edit, edit->buffer.curs1)); + edit_move_to_prev_col (edit, edit_buffer_get_current_bol (&edit->buffer)); edit_move_display (edit, line - (WIDGET (edit)->lines / 2)); } @@ -567,7 +567,7 @@ is_in_indent (const WEdit * edit) { off_t p; - for (p = edit_bol (edit, edit->buffer.curs1); p < edit->buffer.curs1; p++) + for (p = edit_buffer_get_current_bol (&edit->buffer); p < edit->buffer.curs1; p++) if (strchr (" \t", edit_buffer_get_byte (&edit->buffer, p)) == NULL) return FALSE; @@ -589,8 +589,8 @@ is_blank (const WEdit * edit, off_t offset) off_t s, f; int c; - s = edit_bol (edit, offset); - f = edit_eol (edit, offset) - 1; + s = edit_buffer_get_bol (&edit->buffer, offset); + f = edit_buffer_get_eol (&edit->buffer, offset) - 1; while (s <= f) { c = edit_buffer_get_byte (&edit->buffer, s++); @@ -615,9 +615,9 @@ edit_find_line (WEdit * edit, long line) memset (edit->line_offsets, 0, sizeof (edit->line_offsets)); /* three offsets that we *know* are line 0 at 0 and these two: */ edit->line_numbers[1] = edit->buffer.curs_line; - edit->line_offsets[1] = edit_bol (edit, edit->buffer.curs1); + edit->line_offsets[1] = edit_buffer_get_current_bol (&edit->buffer); edit->line_numbers[2] = edit->buffer.lines; - edit->line_offsets[2] = edit_bol (edit, edit->buffer.size); + edit->line_offsets[2] = edit_buffer_get_bol (&edit->buffer, edit->buffer.size); edit->caches_valid = TRUE; } if (line >= edit->buffer.lines) @@ -781,7 +781,7 @@ edit_move_to_bottom (WEdit * edit) static void edit_cursor_to_bol (WEdit * edit) { - edit_cursor_move (edit, edit_bol (edit, edit->buffer.curs1) - edit->buffer.curs1); + edit_cursor_move (edit, edit_buffer_get_current_bol (&edit->buffer) - edit->buffer.curs1); edit->search_start = edit->buffer.curs1; edit->prev_col = edit_get_col (edit); edit->over_col = 0; @@ -793,7 +793,7 @@ edit_cursor_to_bol (WEdit * edit) static void edit_cursor_to_eol (WEdit * edit) { - edit_cursor_move (edit, edit_eol (edit, edit->buffer.curs1) - edit->buffer.curs1); + edit_cursor_move (edit, edit_buffer_get_current_eol (&edit->buffer) - edit->buffer.curs1); edit->search_start = edit->buffer.curs1; edit->prev_col = edit_get_col (edit); edit->over_col = 0; @@ -852,7 +852,8 @@ edit_left_word_move (WEdit * edit, int s) if (edit->column_highlight && edit->mark1 != edit->mark2 - && edit->over_col == 0 && edit->buffer.curs1 == edit_bol (edit, edit->buffer.curs1)) + && edit->over_col == 0 + && edit->buffer.curs1 == edit_buffer_get_current_bol (&edit->buffer)) break; edit_cursor_move (edit, -1); if (edit->buffer.curs1 == 0) @@ -890,7 +891,8 @@ edit_right_word_move (WEdit * edit, int s) if (edit->column_highlight && edit->mark1 != edit->mark2 - && edit->over_col == 0 && edit->buffer.curs1 == edit_eol (edit, edit->buffer.curs1)) + && edit->over_col == 0 + && edit->buffer.curs1 == edit_buffer_get_current_eol (&edit->buffer)) break; edit_cursor_move (edit, 1); if (edit->buffer.curs1 >= edit->buffer.size) @@ -952,7 +954,8 @@ edit_left_char_move_cmd (WEdit * edit) if (edit->column_highlight && option_cursor_beyond_eol && edit->mark1 != edit->mark2 - && edit->over_col == 0 && edit->buffer.curs1 == edit_bol (edit, edit->buffer.curs1)) + && edit->over_col == 0 + && edit->buffer.curs1 == edit_buffer_get_current_bol (&edit->buffer)) return; #ifdef HAVE_CHARSET if (edit->utf8) @@ -999,12 +1002,9 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi else edit_scroll_downward (edit, lines); } - p = edit_bol (edit, edit->buffer.curs1); - + p = edit_buffer_get_current_bol (&edit->buffer); p = direction ? edit_move_backward (edit, p, lines) : edit_move_forward (edit, p, lines, 0); - edit_cursor_move (edit, p - edit->buffer.curs1); - edit_move_to_prev_col (edit, p); #ifdef HAVE_CHARSET @@ -1111,13 +1111,15 @@ edit_do_undo (WEdit * edit) { edit->mark1 = ac - MARK_1; edit->column1 = - (long) edit_move_forward3 (edit, edit_bol (edit, edit->mark1), 0, edit->mark1); + (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), 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_bol (edit, edit->mark2), 0, edit->mark2); + (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2), 0, + edit->mark2); } else if (ac >= MARK_CURS - 2 && ac < KEY_PRESS) { @@ -1190,13 +1192,13 @@ edit_do_redo (WEdit * edit) { edit->mark1 = ac - MARK_1; edit->column1 = - (long) edit_move_forward3 (edit, edit_bol (edit, edit->mark1), 0, edit->mark1); + (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), 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_bol (edit, edit->mark2), 0, edit->mark2); + (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2), 0, edit->mark2); } /* more than one pop usually means something big */ if (count++) @@ -1501,8 +1503,8 @@ edit_move_block_to_right (WEdit * edit) if (eval_marks (edit, &start_mark, &end_mark)) return; - start_bol = edit_bol (edit, start_mark); - cur_bol = edit_bol (edit, end_mark - 1); + start_bol = edit_buffer_get_bol (&edit->buffer, start_mark); + cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1); do { @@ -1513,13 +1515,13 @@ edit_move_block_to_right (WEdit * edit) insert_spaces_tab (edit, option_fake_half_tabs); else edit_insert (edit, '\t'); - edit_cursor_move (edit, edit_bol (edit, cur_bol) - edit->buffer.curs1); + edit_cursor_move (edit, edit_buffer_get_bol (&edit->buffer, cur_bol) - edit->buffer.curs1); } if (cur_bol == 0) break; - cur_bol = edit_bol (edit, cur_bol - 1); + cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1); } while (cur_bol >= start_bol); @@ -1538,8 +1540,8 @@ edit_move_block_to_left (WEdit * edit) if (eval_marks (edit, &start_mark, &end_mark)) return; - start_bol = edit_bol (edit, start_mark); - cur_bol = edit_bol (edit, end_mark - 1); + start_bol = edit_buffer_get_bol (&edit->buffer, start_mark); + cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1); do { @@ -1567,7 +1569,7 @@ edit_move_block_to_left (WEdit * edit) if (cur_bol == 0) break; - cur_bol = edit_bol (edit, cur_bol - 1); + cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1); } while (cur_bol >= start_bol); @@ -2706,38 +2708,6 @@ edit_cursor_move (WEdit * edit, off_t increment) } } -/* These functions return positions relative to lines */ - -/* --------------------------------------------------------------------------------------------- */ -/** returns index of last char on line + 1 */ - -off_t -edit_eol (const WEdit * edit, off_t current) -{ - if (current >= edit->buffer.size) - return edit->buffer.size; - - for (; edit_buffer_get_byte (&edit->buffer, current) != '\n'; current++) - ; - - return current; -} - -/* --------------------------------------------------------------------------------------------- */ -/** returns index of first char on line */ - -off_t -edit_bol (const WEdit * edit, off_t current) -{ - if (current <= 0) - return 0; - - for (; edit_buffer_get_byte (&edit->buffer, current - 1) != '\n'; current--) - ; - - return current; -} - /* --------------------------------------------------------------------------------------------- */ /* If lines is zero this returns the count of lines from current to upto. */ /* If upto is zero returns index of lines forward current. */ @@ -2754,7 +2724,7 @@ edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto) lines = 0; while (lines-- != 0) { - next = edit_eol (edit, current) + 1; + next = edit_buffer_get_eol (&edit->buffer, current) + 1; if (next > edit->buffer.size) break; else @@ -2772,9 +2742,9 @@ edit_move_backward (const WEdit * edit, off_t current, long lines) { if (lines < 0) lines = 0; - current = edit_bol (edit, current); + current = edit_buffer_get_bol (&edit->buffer, current); while (lines-- != 0 && current != 0) - current = edit_bol (edit, current - 1); + current = edit_buffer_get_bol (&edit->buffer, current - 1); return current; } @@ -2855,7 +2825,8 @@ edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) long edit_get_col (const WEdit * edit) { - return (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, edit->buffer.curs1); + return (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, + edit->buffer.curs1); } /* --------------------------------------------------------------------------------------------- */ @@ -2873,7 +2844,8 @@ edit_update_curs_row (WEdit * edit) void edit_update_curs_col (WEdit * edit) { - edit->curs_col = (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, edit->buffer.curs1); + edit->curs_col = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), + 0, edit->buffer.curs1); } /* --------------------------------------------------------------------------------------------- */ @@ -2966,8 +2938,8 @@ edit_move_to_prev_col (WEdit * edit, off_t p) { long line_len; - line_len = (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, - edit_eol (edit, edit->buffer.curs1)); + line_len = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, + edit_buffer_get_current_eol (&edit->buffer)); if (line_len < prev + edit->over_col) { edit->over_col = prev + over - line_len; @@ -2997,7 +2969,7 @@ 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_bol (edit, edit->buffer.curs1); + p = edit_buffer_get_current_bol (&edit->buffer); edit_cursor_move (edit, edit_move_forward3 (edit, p, edit->curs_col, 0) - edit->buffer.curs1); if (!left_of_four_spaces (edit)) @@ -3139,10 +3111,8 @@ edit_mark_current_word_cmd (WEdit * edit) void edit_mark_current_line_cmd (WEdit * edit) { - long pos = edit->buffer.curs1; - - edit->mark1 = edit_bol (edit, pos); - edit->mark2 = edit_eol (edit, pos); + edit->mark1 = edit_buffer_get_current_bol (&edit->buffer); + edit->mark2 = edit_buffer_get_current_eol (&edit->buffer); edit->force |= REDRAW_LINE_ABOVE | REDRAW_AFTER_CURSOR; } diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 0b1cd184a..babb59eab 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -329,6 +329,50 @@ edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last) return lines; } +/* --------------------------------------------------------------------------------------------- */ +/** + * Get "begin-of-line" offset of line contained specified byte offset + * + * @param buf editor buffer + * @param current byte offset + * + * @return index of first char of line + */ + +off_t +edit_buffer_get_bol (const edit_buffer_t * buf, off_t current) +{ + if (current <= 0) + return 0; + + for (; edit_buffer_get_byte (buf, current - 1) != '\n'; current--) + ; + + return current; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Get "end-of-line" offset of line contained specified byte offset + * + * @param buf editor buffer + * @param current byte offset + * + * @return index of last char of line + 1 + */ + +off_t +edit_buffer_get_eol (const edit_buffer_t * buf, off_t current) +{ + if (current >= buf->size) + return buf->size; + + for (; edit_buffer_get_byte (buf, current) != '\n'; current++) + ; + + return current; +} + /* --------------------------------------------------------------------------------------------- */ /** * Basic low level single character buffer alterations and movements at the cursor: insert character diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index 3b30f42dc..f3f839ba2 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -62,6 +62,8 @@ int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width); #endif long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last); +off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current); +off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current); void edit_buffer_insert (edit_buffer_t * buf, int c); void edit_buffer_insert_ahead (edit_buffer_t * buf, int c); @@ -87,6 +89,36 @@ edit_buffer_get_previous_byte (const edit_buffer_t * buf) return edit_buffer_get_byte (buf, buf->curs1 - 1); } +/* --------------------------------------------------------------------------------------------- */ +/** + * Get "begin-of-line" offset of current line + * + * @param buf editor buffer + * + * @return index of first char of current line + */ + +static inline off_t +edit_buffer_get_current_bol (const edit_buffer_t * buf) +{ + return edit_buffer_get_bol (buf, buf->curs1); +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Get "end-of-line" offset of current line + * + * @param buf editor buffer + * + * @return index of first char of current line + 1 + */ + +static inline off_t +edit_buffer_get_current_eol (const edit_buffer_t * buf) +{ + return edit_buffer_get_eol (buf, buf->curs1); +} + /* --------------------------------------------------------------------------------------------- */ #endif /* MC__EDIT_BUFFER_H */ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 94409033b..127f28e65 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -512,14 +512,14 @@ edit_delete_column_of_text (WEdit * edit) eval_marks (edit, &m1, &m2); n = edit_move_forward (edit, m1, 0, m2) + 1; - c = (long) edit_move_forward3 (edit, edit_bol (edit, m1), 0, m1); - d = (long) edit_move_forward3 (edit, edit_bol (edit, m2), 0, m2); + 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); b = max (min (c, d), min (edit->column1, edit->column2)); c = max (c, max (edit->column1, edit->column2)); while (n--) { - r = edit_bol (edit, edit->buffer.curs1); + r = edit_buffer_get_current_bol (&edit->buffer); p = edit_move_forward3 (edit, r, b, 0); q = edit_move_forward3 (edit, r, c, 0); if (p < m1) @@ -593,8 +593,8 @@ edit_block_delete (WEdit * edit) /* 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_bol (edit, edit->buffer.curs1), 0, - edit_eol (edit, edit->buffer.curs1)); + line_width = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, + edit_buffer_get_current_eol (&edit->buffer)); if (option_cursor_beyond_eol && curs_pos > line_width) edit->over_col = curs_pos - line_width; } @@ -1011,7 +1011,7 @@ 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_bol (edit, start), 0, start); + x = edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, start), 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') @@ -2242,10 +2242,10 @@ eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark) && (((edit->mark1 > end_mark_curs) && (edit->column1 < edit->column2)) || ((edit->mark1 < end_mark_curs) && (edit->column1 > edit->column2)))) { - start_bol = edit_bol (edit, *start_mark); - start_eol = edit_eol (edit, start_bol - 1) + 1; - end_bol = edit_bol (edit, *end_mark); - end_eol = edit_eol (edit, *end_mark); + 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); @@ -2356,10 +2356,12 @@ edit_block_move_cmd (WEdit * edit) x2 = x + edit->over_col; /* do nothing when cursor inside first line of selected area */ - if ((edit_eol (edit, edit->buffer.curs1) == edit_eol (edit, start_mark)) && x2 > c1 && x2 <= c2) + if ((edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1) == edit_buffer_get_eol (&edit->buffer, start_mark)) + && x2 > c1 && x2 <= c2) return; - if (edit->buffer.curs1 > start_mark && edit->buffer.curs1 < edit_eol (edit, end_mark)) + if (edit->buffer.curs1 > start_mark + && edit->buffer.curs1 < edit_buffer_get_eol (&edit->buffer, end_mark)) { if (x > c2) x -= b_width; @@ -2374,7 +2376,7 @@ 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_bol (edit, edit->buffer.curs1), x, 0); + current = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), x, 0); edit_cursor_move (edit, current - edit->buffer.curs1); edit_scroll_screen_over_cursor (edit); diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 789fe4a0a..891b4dabe 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -570,7 +570,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c off_t tws = 0; if (tty_use_colors () && visible_tws) { - tws = edit_eol (edit, b); + tws = edit_buffer_get_eol (&edit->buffer, b); while (tws > b && ((c = edit_buffer_get_byte (&edit->buffer, tws - 1)) == ' ' || c == '\t')) tws--; } @@ -827,7 +827,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c static inline void edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column) { - off_t b = edit_bol (edit, curs); + off_t b = edit_buffer_get_bol (&edit->buffer, curs); edit_draw_this_line (edit, b, row, start_column, end_column); } @@ -933,7 +933,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, } /* if (force & REDRAW_LINE) ---> default */ - b = edit_bol (edit, edit->buffer.curs1); + b = edit_buffer_get_current_bol (&edit->buffer); if (curs_row >= start_row && curs_row <= end_row) { if (key_pending (edit)) @@ -958,7 +958,7 @@ 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_move_backward (edit, edit_bol (edit, edit->buffer.curs1), 1); + b = edit_move_backward (edit, edit_buffer_get_current_bol (&edit->buffer), 1); if (row >= start_row && row <= end_row) { if (key_pending (edit)) @@ -970,7 +970,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1) { row = curs_row + 1; - b = edit_bol (edit, edit->buffer.curs1); + b = edit_buffer_get_current_bol (&edit->buffer); b = edit_move_forward (edit, b, 1, 0); if (row >= start_row && row <= end_row) { diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 7197fbc08..e387c783b 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -529,8 +529,10 @@ edit_event (Gpm_Event * event, void *data) edit->prev_col = local.x - edit->start_col - option_line_state_width - 1; else { - long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, - edit_eol (edit, edit->buffer.curs1)); + long line_len; + + line_len = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, + edit_buffer_get_current_eol (&edit->buffer)); if (local.x > line_len) { @@ -552,7 +554,7 @@ edit_event (Gpm_Event * event, void *data) else if (local.y < (edit->curs_row + 1)) edit_move_up (edit, (edit->curs_row + 1) - local.y, 0); else - edit_move_to_prev_col (edit, edit_bol (edit, edit->buffer.curs1)); + edit_move_to_prev_col (edit, edit_buffer_get_current_bol (&edit->buffer)); if ((local.type & GPM_DOWN) != 0) { diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index a488d7596..7e40839cd 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -85,7 +85,7 @@ line_start (WEdit * edit, long line) else if (line > l) p = edit_move_forward (edit, p, line - l, 0); - p = edit_bol (edit, p); + p = edit_buffer_get_bol (&edit->buffer, p); while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) p++; return p; @@ -134,7 +134,7 @@ begin_paragraph (WEdit * edit, gboolean force) break; } - return edit_move_backward (edit, edit_bol (edit, edit->buffer.curs1), edit->buffer.curs_line - i); + return edit_move_backward (edit, edit_buffer_get_current_bol (&edit->buffer), edit->buffer.curs_line - i); } /* --------------------------------------------------------------------------------------------- */ @@ -156,8 +156,8 @@ end_paragraph (WEdit * edit, gboolean force) break; } - return edit_eol (edit, - edit_move_forward (edit, edit_bol (edit, edit->buffer.curs1), + return edit_buffer_get_eol (&edit->buffer, + edit_move_forward (edit, edit_buffer_get_current_bol (&edit->buffer), i - edit->buffer.curs_line, 0)); } From 25924c77d91e50ae0ca51ea846b2848cd0d8179e Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 26 Feb 2013 14:19:46 +0400 Subject: [PATCH 20/25] Refactoring of functions that operate with editor buffer. Signed-off-by: Andrew Borodin --- src/editor/edit-impl.h | 4 -- src/editor/edit.c | 142 ++++++++++------------------------------ src/editor/editbuffer.c | 106 ++++++++++++++++++++++++++++++ src/editor/editbuffer.h | 5 ++ src/editor/editcmd.c | 108 +++++++++++++++--------------- src/editor/editdraw.c | 15 +++-- src/editor/wordproc.c | 35 +++++----- 7 files changed, 226 insertions(+), 189 deletions(-) diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index f510906bb..d673d0c6e 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -153,9 +153,7 @@ 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); -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); -off_t edit_move_backward (const WEdit * edit, off_t current, long lines); void edit_scroll_screen_over_cursor (WEdit * edit); void edit_render_keypress (WEdit * edit); void edit_scroll_upward (WEdit * edit, long i); @@ -221,8 +219,6 @@ gboolean edit_save_block (WEdit * edit, const char *filename, off_t start, off_t gboolean edit_save_block_cmd (WEdit * edit); gboolean edit_insert_file_cmd (WEdit * edit); -char *edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsize * len, - gsize * cut); off_t edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath); gboolean edit_load_back_cmd (WEdit * edit); gboolean edit_load_forward_cmd (WEdit * edit); diff --git a/src/editor/edit.c b/src/editor/edit.c index e850c6fca..89e172812 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -145,7 +145,7 @@ static const struct edit_filters */ static gboolean -edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) +edit_load_file_fast (edit_buffer_t * buf, const vfs_path_t * filename_vpath) { int file; gboolean ret; @@ -162,9 +162,9 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath) return FALSE; } - ret = (edit_buffer_read_file (&edit->buffer, file, edit->buffer.size) == edit->buffer.size); + ret = (edit_buffer_read_file (buf, file, buf->size) == buf->size); if (ret) - edit->buffer.lines = edit_buffer_count_lines (&edit->buffer, 0, edit->buffer.size); + buf->lines = edit_buffer_count_lines (buf, 0, buf->size); else { gchar *errmsg; @@ -362,7 +362,7 @@ edit_load_file (WEdit * edit) { edit_buffer_init (&edit->buffer, edit->stat1.st_size); - if (!edit_load_file_fast (edit, edit->filename_vpath)) + if (!edit_load_file_fast (&edit->buffer, edit->filename_vpath)) { edit_clean (edit); return FALSE; @@ -563,12 +563,12 @@ edit_modification (WEdit * edit) */ static gboolean -is_in_indent (const WEdit * edit) +is_in_indent (const edit_buffer_t * buf) { off_t p; - for (p = edit_buffer_get_current_bol (&edit->buffer); p < edit->buffer.curs1; p++) - if (strchr (" \t", edit_buffer_get_byte (&edit->buffer, p)) == NULL) + for (p = edit_buffer_get_current_bol (buf); p < buf->curs1; p++) + if (strchr (" \t", edit_buffer_get_byte (buf, p)) == NULL) return FALSE; return TRUE; @@ -584,16 +584,17 @@ is_in_indent (const WEdit * edit) */ static gboolean -is_blank (const WEdit * edit, off_t offset) +is_blank (const edit_buffer_t * buf, off_t offset) { off_t s, f; - int c; - s = edit_buffer_get_bol (&edit->buffer, offset); - f = edit_buffer_get_eol (&edit->buffer, offset) - 1; + s = edit_buffer_get_bol (buf, offset); + f = edit_buffer_get_eol (buf, offset) - 1; while (s <= f) { - c = edit_buffer_get_byte (&edit->buffer, s++); + int c; + + c = edit_buffer_get_byte (buf, s++); if (!isspace (c)) return FALSE; } @@ -644,10 +645,12 @@ edit_find_line (WEdit * edit, long line) i = 3 + (rand () % (N_LINE_CACHES - 3)); if (line > edit->line_numbers[j]) edit->line_offsets[i] = - edit_move_forward (edit, edit->line_offsets[j], line - edit->line_numbers[j], 0); + edit_buffer_move_forward (&edit->buffer, edit->line_offsets[j], + line - edit->line_numbers[j], 0); else edit->line_offsets[i] = - edit_move_backward (edit, edit->line_offsets[j], edit->line_numbers[j] - line); + edit_buffer_move_backward (&edit->buffer, edit->line_offsets[j], + edit->line_numbers[j] - line); edit->line_numbers[i] = line; return edit->line_offsets[i]; } @@ -965,14 +968,11 @@ edit_left_char_move_cmd (WEdit * edit) cw = 1; } #endif + if (option_cursor_beyond_eol && edit->over_col > 0) - { edit->over_col--; - } else - { edit_cursor_move (edit, -cw); - } } /* --------------------------------------------------------------------------------------------- */ @@ -1003,7 +1003,8 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi edit_scroll_downward (edit, lines); } p = edit_buffer_get_current_bol (&edit->buffer); - p = direction ? edit_move_backward (edit, p, lines) : edit_move_forward (edit, p, lines, 0); + p = direction ? edit_buffer_move_backward (&edit->buffer, p, lines) : + edit_buffer_move_forward (&edit->buffer, p, lines, 0); edit_cursor_move (edit, p - edit->buffer.curs1); edit_move_to_prev_col (edit, p); @@ -1308,7 +1309,7 @@ edit_auto_indent (WEdit * edit) p = edit->buffer.curs1; /* use the previous line as a template */ - p = edit_move_backward (edit, p, 1); + p = edit_buffer_move_backward (&edit->buffer, p, 1); /* copy the leading whitespace of the line */ while (TRUE) { /* no range check - the line _is_ \n-terminated */ @@ -1359,7 +1360,7 @@ insert_spaces_tab (WEdit * edit, gboolean half) static inline void edit_tab_cmd (WEdit * edit) { - if (option_fake_half_tabs && is_in_indent (edit)) + if (option_fake_half_tabs && is_in_indent (&edit->buffer)) { /* insert a half tab (usually four spaces) unless there is a half tab already behind, then delete it and insert a @@ -1850,43 +1851,6 @@ is_break_char (char c) return (isspace (c) || strchr ("{}[]()<>=|/\\!?~-+`'\",.;:#$%^&*", c)); } -/* --------------------------------------------------------------------------------------------- */ - -char * -edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsize * len, - gsize * cut) -{ - off_t word_start; - long cut_len = 0; - GString *match_expr; - int c1, c2; - - for (word_start = start_pos; word_start != 0; word_start--, cut_len++) - { - 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; - } - - match_expr = g_string_sized_new (16); - - do - { - 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')); - - *len = match_expr->len; - *start = word_start; - *cut = cut_len; - - return g_string_free (match_expr, FALSE); -} - /* --------------------------------------------------------------------------------------------- */ /** inserts a file at the cursor, returns count of inserted bytes on success */ @@ -2226,7 +2190,6 @@ edit_set_codeset (WEdit * edit) } #endif - /* --------------------------------------------------------------------------------------------- */ /** @@ -2360,6 +2323,8 @@ edit_push_undo_action (WEdit * edit, long c) } } +/* --------------------------------------------------------------------------------------------- */ + void edit_push_redo_action (WEdit * edit, long c) { @@ -2708,46 +2673,6 @@ edit_cursor_move (WEdit * edit, off_t increment) } } -/* --------------------------------------------------------------------------------------------- */ -/* If lines is zero this returns the count of lines from current to upto. */ -/* If upto is zero returns index of lines forward current. */ - -off_t -edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto) -{ - if (upto != 0) - return (off_t) edit_buffer_count_lines (&edit->buffer, current, upto); - else - { - long next; - if (lines < 0) - lines = 0; - while (lines-- != 0) - { - next = edit_buffer_get_eol (&edit->buffer, current) + 1; - if (next > edit->buffer.size) - break; - else - current = next; - } - return current; - } -} - -/* --------------------------------------------------------------------------------------------- */ -/** Returns offset of 'lines' lines up from current */ - -off_t -edit_move_backward (const WEdit * edit, off_t current, long lines) -{ - if (lines < 0) - lines = 0; - current = edit_buffer_get_bol (&edit->buffer, current); - while (lines-- != 0 && current != 0) - current = edit_buffer_get_bol (&edit->buffer, current - 1); - return current; -} - /* --------------------------------------------------------------------------------------------- */ /* If cols is zero this returns the count of columns from current to upto. */ /* If upto is zero returns index of cols across from current. */ @@ -2869,7 +2794,7 @@ edit_scroll_upward (WEdit * edit, long i) if (i != 0) { edit->start_line -= i; - edit->start_display = edit_move_backward (edit, edit->start_display, i); + edit->start_display = edit_buffer_move_backward (&edit->buffer, edit->start_display, i); edit->force |= REDRAW_PAGE; edit->force &= (0xfff - REDRAW_CHAR_ONLY); } @@ -2890,7 +2815,7 @@ edit_scroll_downward (WEdit * edit, long i) if (i > lines_below) i = lines_below; edit->start_line += i; - edit->start_display = edit_move_forward (edit, edit->start_display, i, 0); + edit->start_display = edit_buffer_move_forward (&edit->buffer, edit->start_display, i, 0); edit->force |= REDRAW_PAGE; edit->force &= (0xfff - REDRAW_CHAR_ONLY); } @@ -2956,7 +2881,7 @@ edit_move_to_prev_col (WEdit * edit, off_t p) else { edit->over_col = 0; - if (option_fake_half_tabs && is_in_indent (edit)) + if (option_fake_half_tabs && is_in_indent (&edit->buffer)) { long fake_half_tabs; @@ -2991,7 +2916,7 @@ edit_move_to_prev_col (WEdit * edit, off_t p) gboolean edit_line_is_blank (WEdit * edit, long line) { - return is_blank (edit, edit_find_line (edit, line)); + return is_blank (&edit->buffer, edit_find_line (edit, line)); } /* --------------------------------------------------------------------------------------------- */ @@ -3442,13 +3367,14 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit_block_delete_cmd (edit); else if (option_cursor_beyond_eol && edit->over_col > 0) edit->over_col--; - else if (option_backspace_through_tabs && is_in_indent (edit)) + else if (option_backspace_through_tabs && is_in_indent (&edit->buffer)) { 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)) + else if (option_fake_half_tabs && is_in_indent (&edit->buffer) + && right_of_four_spaces (edit)) { int i; @@ -3467,7 +3393,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) if (option_cursor_beyond_eol && edit->over_col > 0) edit_insert_over (edit); - if (option_fake_half_tabs && is_in_indent (edit) && left_of_four_spaces (edit)) + if (option_fake_half_tabs && is_in_indent (&edit->buffer) && left_of_four_spaces (edit)) { int i; @@ -3533,7 +3459,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit->column_highlight = 1; case CK_Left: case CK_MarkLeft: - if (option_fake_half_tabs && is_in_indent (edit) && right_of_four_spaces (edit)) + if (option_fake_half_tabs && is_in_indent (&edit->buffer) && right_of_four_spaces (edit)) { if (option_cursor_beyond_eol && edit->over_col > 0) edit->over_col--; @@ -3548,7 +3474,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit->column_highlight = 1; case CK_Right: case CK_MarkRight: - if (option_fake_half_tabs && is_in_indent (edit) && left_of_four_spaces (edit)) + if (option_fake_half_tabs && is_in_indent (&edit->buffer) && left_of_four_spaces (edit)) { edit_cursor_move (edit, HALF_TAB_SIZE); edit->force &= (0xFFF - REDRAW_CHAR_ONLY); diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index babb59eab..f05d74fd9 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -39,6 +39,7 @@ #include "lib/vfs/vfs.h" +#include "edit-impl.h" #include "editbuffer.h" /* --------------------------------------------------------------------------------------------- */ @@ -373,6 +374,52 @@ edit_buffer_get_eol (const edit_buffer_t * buf, off_t current) return current; } +/* --------------------------------------------------------------------------------------------- */ +/** + * Get word from specified offset. + * + * @param buf editor buffer + * @param current start_pos offset + * @param start actual start word ofset + * @param cut + * + * @return word as newly allocated object + */ + +GString * +edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start, + gsize * cut) +{ + off_t word_start; + long cut_len = 0; + GString *match_expr; + int c1, c2; + + for (word_start = start_pos; word_start != 0; word_start--, cut_len++) + { + c1 = edit_buffer_get_byte (buf, word_start); + c2 = edit_buffer_get_byte (buf, word_start - 1); + + if (is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n') + break; + } + + match_expr = g_string_sized_new (16); + + do + { + c1 = edit_buffer_get_byte (buf, word_start + match_expr->len); + c2 = edit_buffer_get_byte (buf, 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')); + + *start = word_start; + *cut = cut_len; + + return match_expr; +} + /* --------------------------------------------------------------------------------------------- */ /** * Basic low level single character buffer alterations and movements at the cursor: insert character @@ -503,6 +550,65 @@ edit_buffer_backspace (edit_buffer_t * buf) return c; } + +/* --------------------------------------------------------------------------------------------- */ +/** + * Calculate forward offset with specified number of lines. + * + * @param buf editor buffer + * @param current current offset + * @param lines number of lines to move forward + * @param upto offset to count lines between current and upto. + * + * @return If lines is zero returns the count of lines from current to upto. + * If upto is zero returns offset of lines forward current. + * Else returns forward offset with specified number of lines + */ + +off_t +edit_buffer_move_forward (const edit_buffer_t * buf, off_t current, long lines, off_t upto) +{ + long next; + + if (upto != 0) + return (off_t) edit_buffer_count_lines (buf, current, upto); + + lines = max (lines, 0); + + while (lines-- != 0) + { + next = edit_buffer_get_eol (buf, current) + 1; + if (next > buf->size) + break; + current = next; + } + + return current; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Calculate backward offset with specified number of lines. + * + * @param buf editor buffer + * @param current current offset + * @param lines number of lines to move bacward + * + * @return backward offset with specified number of lines. + */ + +off_t +edit_buffer_move_backward (const edit_buffer_t * buf, off_t current, long lines) +{ + lines = max (lines, 0); + current = edit_buffer_get_bol (buf, current); + + while (lines-- != 0 && current != 0) + current = edit_buffer_get_bol (buf, current - 1); + + return current; +} + /* --------------------------------------------------------------------------------------------- */ /** * Load file into editor buffer diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index f3f839ba2..d6a3c9e7c 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -64,12 +64,17 @@ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int * long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last); off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current); off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current); +GString *edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start, + gsize * cut); void edit_buffer_insert (edit_buffer_t * buf, int c); void edit_buffer_insert_ahead (edit_buffer_t * buf, int c); int edit_buffer_delete (edit_buffer_t * buf); int edit_buffer_backspace (edit_buffer_t * buf); +off_t edit_buffer_move_forward (const edit_buffer_t * buf, off_t current, long lines, off_t upto); +off_t edit_buffer_move_backward (const edit_buffer_t * buf, off_t current, long lines); + off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size); off_t edit_buffer_write_file (edit_buffer_t * buf, int fd); diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 127f28e65..4f9455271 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -393,13 +393,13 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) /* --------------------------------------------------------------------------------------------- */ static gboolean -edit_check_newline (WEdit * edit) +edit_check_newline (const edit_buffer_t * buf) { - return !(option_check_nl_at_eof && edit->buffer.size > 0 - && edit_buffer_get_byte (&edit->buffer, edit->buffer.size - 1) != '\n' + return !(option_check_nl_at_eof && buf->size > 0 + && edit_buffer_get_byte (buf, buf->size - 1) != '\n' && edit_query_dialog2 (_("Warning"), _("The file you are saving is not finished with a newline"), - _("C&ontinue"), _("&Cancel"))); + _("C&ontinue"), _("&Cancel")) != 0); } /* --------------------------------------------------------------------------------------------- */ @@ -511,7 +511,7 @@ edit_delete_column_of_text (WEdit * edit) long b, c, d; eval_marks (edit, &m1, &m2); - n = edit_move_forward (edit, m1, 0, m2) + 1; + n = edit_buffer_move_forward (&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); b = max (min (c, d), min (edit->column1, edit->column2)); @@ -536,7 +536,8 @@ edit_delete_column_of_text (WEdit * edit) } if (n) /* move to next line except on the last delete */ - edit_cursor_move (edit, edit_move_forward (edit, edit->buffer.curs1, 1, 0) - edit->buffer.curs1); + edit_cursor_move (edit, edit_buffer_move_forward (&edit->buffer, edit->buffer.curs1, 1, 0) - + edit->buffer.curs1); } } @@ -659,7 +660,7 @@ edit_get_search_line_type (mc_search_t * search) /** * Calculating the start position of next line. * - * @param edit editor object + * @param buf editor buffer object * @param current_pos current position * @param max_pos max position * @param end_string_symbol end of line symbol @@ -667,7 +668,7 @@ edit_get_search_line_type (mc_search_t * search) */ static off_t -edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_pos, +edit_calculate_start_of_next_line (const edit_buffer_t * buf, off_t current_pos, off_t max_pos, char end_string_symbol) { off_t i; @@ -675,7 +676,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_buffer_get_byte (&edit->buffer, i) == end_string_symbol) + if (edit_buffer_get_byte (buf, i) == end_string_symbol) break; } @@ -686,19 +687,19 @@ edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_po /** * Calculating the end position of previous line. * - * @param edit editor object + * @param buf editor buffer object * @param current_pos current position * @param end_string_symbol end of line symbol * @return end position of previous line */ static off_t -edit_calculate_end_of_previous_line (WEdit * edit, off_t current_pos, char end_string_symbol) +edit_calculate_end_of_previous_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol) { off_t i; for (i = current_pos - 1; i >= 0; i--) - if (edit_buffer_get_byte (&edit->buffer, i) == end_string_symbol) + if (edit_buffer_get_byte (buf, i) == end_string_symbol) break; return i; @@ -708,17 +709,17 @@ edit_calculate_end_of_previous_line (WEdit * edit, off_t current_pos, char end_s /** * Calculating the start position of previous line. * - * @param edit editor object + * @param buf editor buffer object * @param current_pos current position * @param end_string_symbol end of line symbol * @return start position of previous line */ static inline off_t -edit_calculate_start_of_previous_line (WEdit * edit, off_t current_pos, char end_string_symbol) +edit_calculate_start_of_previous_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol) { - current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol); - current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol); + current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol); + current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol); return (current_pos + 1); } @@ -727,16 +728,16 @@ edit_calculate_start_of_previous_line (WEdit * edit, off_t current_pos, char end /** * Calculating the start position of current line. * - * @param edit editor object + * @param buf editor buffer object * @param current_pos current position * @param end_string_symbol end of line symbol * @return start position of current line */ static inline off_t -edit_calculate_start_of_current_line (WEdit * edit, off_t current_pos, char end_string_symbol) +edit_calculate_start_of_current_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol) { - current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol); + current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol); return (current_pos + 1); } @@ -802,15 +803,13 @@ editcmd_find (WEdit * edit, gsize * len) && (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->buffer.size, + edit_calculate_start_of_next_line (&edit->buffer, start_mark, edit->buffer.size, end_string_symbol); } if ((edit->search_line_type & AT_END_LINE) != 0 && (end_mark - 1 != edit->buffer.size || 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); - } + end_mark = edit_calculate_end_of_previous_line (&edit->buffer, end_mark, end_string_symbol); if (start_mark >= end_mark) { edit->search->error = MC_SEARCH_E_NOTFOUND; @@ -832,7 +831,7 @@ editcmd_find (WEdit * edit, gsize * len) if ((edit->search_line_type & AT_START_LINE) != 0) search_start = - edit_calculate_start_of_current_line (edit, search_start, end_string_symbol); + edit_calculate_start_of_current_line (&edit->buffer, search_start, end_string_symbol); while (search_start >= start_mark) { @@ -850,7 +849,7 @@ editcmd_find (WEdit * edit, gsize * len) if ((edit->search_line_type & AT_START_LINE) != 0) search_start = - edit_calculate_start_of_previous_line (edit, search_start, end_string_symbol); + edit_calculate_start_of_previous_line (&edit->buffer, search_start, end_string_symbol); else search_start--; } @@ -861,7 +860,7 @@ editcmd_find (WEdit * edit, gsize * len) /* forward search */ if ((edit->search_line_type & AT_START_LINE) != 0 && search_start != start_mark) search_start = - edit_calculate_start_of_next_line (edit, search_start, end_mark, end_string_symbol); + edit_calculate_start_of_next_line (&edit->buffer, search_start, end_mark, end_string_symbol); return mc_search_run (edit->search, (void *) edit, search_start, end_mark, len); } return FALSE; @@ -1050,7 +1049,7 @@ edit_save_block_to_clip_file (WEdit * edit, off_t start, off_t finish) /* --------------------------------------------------------------------------------------------- */ static void -pipe_mail (WEdit * edit, char *to, char *subject, char *cc) +pipe_mail (const edit_buffer_t * buf, char *to, char *subject, char *cc) { FILE *p = 0; char *s; @@ -1063,17 +1062,18 @@ pipe_mail (WEdit * edit, char *to, char *subject, char *cc) g_free (subject); g_free (cc); - if (s) + if (s != NULL) { p = popen (s, "w"); g_free (s); } - if (p) + if (p != NULL) { off_t i; - for (i = 0; i < edit->buffer.size; i++) - fputc (edit_buffer_get_byte (&edit->buffer, i), p); + + for (i = 0; i < buf->size; i++) + fputc (edit_buffer_get_byte (buf, i), p); pclose (p); } } @@ -1082,16 +1082,16 @@ pipe_mail (WEdit * edit, char *to, char *subject, char *cc) /** find first character of current word */ static gboolean -edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len) +edit_find_word_start (const edit_buffer_t * buf, off_t * word_start, gsize * word_len) { int c, last; off_t i; /* return if at begin of file */ - if (edit->buffer.curs1 <= 0) + if (buf->curs1 <= 0) return FALSE; - c = edit_buffer_get_previous_byte (&edit->buffer); + c = edit_buffer_get_previous_byte (buf); /* return if not at end or in word */ if (is_break_char (c)) return FALSE; @@ -1100,11 +1100,11 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len) for (i = 2;; i++) { /* return if at begin of file */ - if (edit->buffer.curs1 < i) + if (buf->curs1 < i) return FALSE; last = c; - c = edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - i); + c = edit_buffer_get_byte (buf, buf->curs1 - i); if (is_break_char (c)) { @@ -1112,7 +1112,7 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len) if (isdigit (last)) return FALSE; - *word_start = edit->buffer.curs1 - (i - 1); /* start found */ + *word_start = buf->curs1 - (i - 1); /* start found */ *word_len = (gsize) (i - 1); break; } @@ -1627,7 +1627,7 @@ edit_save_as_cmd (WEdit * edit) int save_lock = 0; int different_filename = 0; - if (!edit_check_newline (edit)) + if (!edit_check_newline (&edit->buffer)) return FALSE; exp_vpath = edit_get_save_file_as (edit); @@ -2009,7 +2009,7 @@ edit_save_confirm_cmd (WEdit * edit) if (edit->filename_vpath == NULL) return edit_save_as_cmd (edit); - if (!edit_check_newline (edit)) + if (!edit_check_newline (&edit->buffer)) return FALSE; if (edit_confirm_save) @@ -2760,7 +2760,7 @@ edit_ok_to_exit (WEdit * edit) if (!mc_global.midnight_shutdown) { - if (!edit_check_newline (edit)) + if (!edit_check_newline (&edit->buffer)) { g_free (fname); return FALSE; @@ -3230,7 +3230,7 @@ edit_mail_dialog (WEdit * edit) mail_cc_last = tmail_cc; mail_subject_last = tmail_subject; mail_to_last = tmail_to; - pipe_mail (edit, mail_to_last, mail_subject_last, mail_cc_last); + pipe_mail (&edit->buffer, mail_to_last, mail_subject_last, mail_cc_last); } } @@ -3254,7 +3254,7 @@ edit_complete_word_cmd (WEdit * edit) GString *compl[MAX_WORD_COMPLETIONS]; /* completions */ /* search start of word to be completed */ - if (!edit_find_word_start (edit, &word_start, &word_len)) + if (!edit_find_word_start (&edit->buffer, &word_start, &word_len)) return; /* prepare match expression */ @@ -3434,7 +3434,7 @@ edit_get_match_keyword_cmd (WEdit * edit) } /* search start of word to be completed */ - if (!edit_find_word_start (edit, &word_start, &word_len)) + if (!edit_find_word_start (&edit->buffer, &word_start, &word_len)) return; /* prepare match expression */ @@ -3487,29 +3487,31 @@ edit_suggest_current_word (WEdit * edit) gsize word_len = 0; off_t word_start = 0; int retval = B_SKIP_WORD; - char *match_word; + GString *match_word; /* search start of word to spell check */ - match_word = edit_get_word_from_pos (edit, edit->buffer.curs1, &word_start, &word_len, &cut_len); + match_word = edit_buffer_get_word_from_pos (&edit->buffer, edit->buffer.curs1, &word_start, + &cut_len); + word_len = match_word->len; #ifdef HAVE_CHARSET if (mc_global.source_codepage >= 0 && (mc_global.source_codepage != mc_global.display_codepage)) { GString *tmp_word; - tmp_word = str_convert_to_display (match_word); - g_free (match_word); - match_word = g_string_free (tmp_word, FALSE); + tmp_word = str_convert_to_display (match_word->str); + g_string_free (match_word, TRUE); + match_word = tmp_word; } #endif - if (!aspell_check (match_word, (int) word_len)) + if (!aspell_check (match_word->str, (int) word_len)) { GArray *suggest; unsigned int res; suggest = g_array_new (TRUE, FALSE, sizeof (char *)); - res = aspell_suggest (suggest, match_word, (int) word_len); + res = aspell_suggest (suggest, match_word->str, (int) word_len); if (res != 0) { char *new_word = NULL; @@ -3520,7 +3522,7 @@ edit_suggest_current_word (WEdit * edit) edit_scroll_screen_over_cursor (edit); edit_render_keypress (edit); - retval = spell_dialog_spell_suggest_show (edit, match_word, &new_word, suggest); + retval = spell_dialog_spell_suggest_show (edit, match_word->str, &new_word, suggest); edit_cursor_move (edit, word_len - cut_len); if (retval == B_ENTER && new_word != NULL) @@ -3547,14 +3549,14 @@ edit_suggest_current_word (WEdit * edit) g_free (cp_word); } else if (retval == B_ADD_WORD && match_word != NULL) - aspell_add_to_dict (match_word, (int) word_len); + aspell_add_to_dict (match_word->str, (int) word_len); } g_array_free (suggest, TRUE); edit->found_start = 0; edit->found_len = 0; } - g_free (match_word); + g_string_free (match_word, TRUE); return retval; } diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 891b4dabe..7d4846e41 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -903,13 +903,13 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, if ((force & REDRAW_PAGE) != 0) { row = start_row; - b = edit_move_forward (edit, edit->start_display, start_row, 0); + b = edit_buffer_move_forward (&edit->buffer, edit->start_display, start_row, 0); while (row <= end_row) { if (key_pending (edit)) return; edit_draw_this_line (edit, b, row, start_column, end_column); - b = edit_move_forward (edit, b, 1, 0); + b = edit_buffer_move_forward (&edit->buffer, b, 1, 0); row++; } } @@ -928,7 +928,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, if (key_pending (edit)) return; edit_draw_this_line (edit, b, row, start_column, end_column); - b = edit_move_forward (edit, b, 1, 0); + b = edit_buffer_move_forward (&edit->buffer, b, 1, 0); } } @@ -944,13 +944,13 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row) { row = curs_row + 1 < start_row ? start_row : curs_row + 1; - b = edit_move_forward (edit, b, 1, 0); + b = edit_buffer_move_forward (&edit->buffer, b, 1, 0); while (row <= end_row) { if (key_pending (edit)) return; edit_draw_this_line (edit, b, row, start_column, end_column); - b = edit_move_forward (edit, b, 1, 0); + b = edit_buffer_move_forward (&edit->buffer, b, 1, 0); row++; } } @@ -958,7 +958,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_move_backward (edit, edit_buffer_get_current_bol (&edit->buffer), 1); + b = edit_buffer_move_backward (&edit->buffer, + edit_buffer_get_current_bol (&edit->buffer), 1); if (row >= start_row && row <= end_row) { if (key_pending (edit)) @@ -971,7 +972,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, { row = curs_row + 1; b = edit_buffer_get_current_bol (&edit->buffer); - b = edit_move_forward (edit, b, 1, 0); + b = edit_buffer_move_forward (&edit->buffer, b, 1, 0); if (row >= start_row && row <= end_row) { if (key_pending (edit)) diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index 7e40839cd..36c4097bc 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -72,21 +72,21 @@ /* --------------------------------------------------------------------------------------------- */ static off_t -line_start (WEdit * edit, long line) +line_start (const edit_buffer_t * buf, long line) { off_t p; long l; - l = edit->buffer.curs_line; - p = edit->buffer.curs1; + l = buf->curs_line; + p = buf->curs1; if (line < l) - p = edit_move_backward (edit, p, l - line); + p = edit_buffer_move_backward (buf, p, l - line); else if (line > l) - p = edit_move_forward (edit, p, line - l, 0); + p = edit_buffer_move_forward (buf, p, line - l, 0); - p = edit_buffer_get_bol (&edit->buffer, p); - while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) + p = edit_buffer_get_bol (buf, p); + while (strchr ("\t ", edit_buffer_get_byte (buf, p)) != NULL) p++; return p; } @@ -94,22 +94,22 @@ line_start (WEdit * edit, long line) /* --------------------------------------------------------------------------------------------- */ static gboolean -bad_line_start (WEdit * edit, off_t p) +bad_line_start (const edit_buffer_t * buf, off_t p) { int c; - c = edit_buffer_get_byte (&edit->buffer, p); + c = edit_buffer_get_byte (buf, p); if (c == '.') { /* `...' is acceptable */ - return !(edit_buffer_get_byte (&edit->buffer, p + 1) == '.' - && edit_buffer_get_byte (&edit->buffer, p + 2) == '.'); + return !(edit_buffer_get_byte (buf, p + 1) == '.' + && edit_buffer_get_byte (buf, p + 2) == '.'); } if (c == '-') { /* `---' is acceptable */ - return !(edit_buffer_get_byte (&edit->buffer, p + 1) == '-' - && edit_buffer_get_byte (&edit->buffer, p + 2) == '-'); + return !(edit_buffer_get_byte (buf, p + 1) == '-' + && edit_buffer_get_byte (buf, p + 2) == '-'); } return (strchr (NO_FORMAT_CHARS_START, c) != NULL); @@ -128,13 +128,14 @@ begin_paragraph (WEdit * edit, gboolean force) for (i = edit->buffer.curs_line - 1; i >= 0; i--) if (edit_line_is_blank (edit, i) || - (force && bad_line_start (edit, line_start (edit, i)))) + (force && bad_line_start (&edit->buffer, line_start (&edit->buffer, i)))) { i++; break; } - return edit_move_backward (edit, edit_buffer_get_current_bol (&edit->buffer), edit->buffer.curs_line - i); + return edit_buffer_move_backward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer), + edit->buffer.curs_line - i); } /* --------------------------------------------------------------------------------------------- */ @@ -150,14 +151,14 @@ end_paragraph (WEdit * edit, gboolean force) for (i = edit->buffer.curs_line + 1; i <= edit->buffer.lines; i++) if (edit_line_is_blank (edit, i) || - (force && bad_line_start (edit, line_start (edit, i)))) + (force && bad_line_start (&edit->buffer, line_start (&edit->buffer, i)))) { i--; break; } return edit_buffer_get_eol (&edit->buffer, - edit_move_forward (edit, edit_buffer_get_current_bol (&edit->buffer), + edit_buffer_move_forward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer), i - edit->buffer.curs_line, 0)); } From ccf82ada1295361bf7f04cc1cf3b53c50b3f3da7 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 28 Feb 2013 16:55:51 +0400 Subject: [PATCH 21/25] Add functions to transform string to unsigned integer: * (xstrtoumax): from gnulib. * (parse_integer): from coreutils (dd.c). Signed-off-by: Andrew Borodin --- lib/strutil.h | 24 +++ lib/strutil/Makefile.am | 3 +- lib/strutil/strutil.c | 39 +++++ lib/strutil/xstrtol.c | 238 ++++++++++++++++++++++++++++++ tests/lib/strutil/Makefile.am | 6 +- tests/lib/strutil/parse_integer.c | 168 +++++++++++++++++++++ 6 files changed, 476 insertions(+), 2 deletions(-) create mode 100644 lib/strutil/xstrtol.c create mode 100644 tests/lib/strutil/parse_integer.c diff --git a/lib/strutil.h b/lib/strutil.h index 6124b097d..8b66c1e58 100644 --- a/lib/strutil.h +++ b/lib/strutil.h @@ -4,6 +4,7 @@ #include "lib/global.h" /* include glib.h */ #include +#include #include #ifdef HAVE_ASSERT_H #include /* assert() */ @@ -86,6 +87,20 @@ typedef enum J_CENTER_LEFT_FIT = 0x14 } align_crt_t; +/* string-to-integer parsing results + */ +typedef enum +{ + LONGINT_OK = 0, + + /* These two values can be ORed together, to indicate that both errors occurred. */ + LONGINT_OVERFLOW = 1, + LONGINT_INVALID_SUFFIX_CHAR = 2, + + LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW), + LONGINT_INVALID = 4 +} strtol_error_t; + /*** structures declarations (and typedefs of structures)*****************************************/ /* all functions in str_class must be defined for every encoding */ @@ -540,7 +555,13 @@ char *strrstr_skip_count (const char *haystack, const char *needle, size_t skip_ char *str_replace_all (const char *haystack, const char *needle, const char *replacement); +strtol_error_t xstrtoumax (const char *s, char **ptr, int base, uintmax_t * val, + const char *valid_suffixes); +uintmax_t parse_integer (const char *str, gboolean * invalid); + +/* --------------------------------------------------------------------------------------------- */ /*** inline functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ static inline void str_replace (char *s, char from, char to) @@ -552,6 +573,7 @@ str_replace (char *s, char from, char to) } } +/* --------------------------------------------------------------------------------------------- */ /* * strcpy is unsafe on overlapping memory areas, so define memmove-alike * string function. @@ -584,4 +606,6 @@ str_move (char *dest, const char *src) return (char *) memmove (dest, src, n); } +/* --------------------------------------------------------------------------------------------- */ + #endif /* MC_STRUTIL_H */ diff --git a/lib/strutil/Makefile.am b/lib/strutil/Makefile.am index fa09f31d8..07973c61b 100644 --- a/lib/strutil/Makefile.am +++ b/lib/strutil/Makefile.am @@ -7,6 +7,7 @@ libmcstrutil_la_SOURCES = \ strutilascii.c \ strutil.c \ strutilutf8.c \ - strverscmp.c + strverscmp.c \ + xstrtol.c AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) diff --git a/lib/strutil/strutil.c b/lib/strutil/strutil.c index 2bd11d25d..35647acf0 100644 --- a/lib/strutil/strutil.c +++ b/lib/strutil/strutil.c @@ -832,3 +832,42 @@ strrstr_skip_count (const char *haystack, const char *needle, size_t skip_count) } /* --------------------------------------------------------------------------------------------- */ +/* Interprete string as a non-negative decimal integer, optionally multiplied by various values. + * + * @param str input value + * @param invalid set to TRUE if "str" does not represent a number in this format + * + * @return non-integer representation of "str", 0 in case of error. + */ + +uintmax_t +parse_integer (const char *str, gboolean * invalid) +{ + uintmax_t n; + char *suffix; + strtol_error_t e; + + e = xstrtoumax (str, &suffix, 10, &n, "bcEGkKMPTwYZ0"); + if (e == LONGINT_INVALID_SUFFIX_CHAR && *suffix == 'x') + { + uintmax_t multiplier; + + multiplier = parse_integer (suffix + 1, invalid); + if (multiplier != 0 && n * multiplier / multiplier != n) + { + *invalid = TRUE; + return 0; + } + + n *= multiplier; + } + else if (e != LONGINT_OK) + { + *invalid = TRUE; + n = 0; + } + + return n; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/strutil/xstrtol.c b/lib/strutil/xstrtol.c new file mode 100644 index 000000000..0326303d7 --- /dev/null +++ b/lib/strutil/xstrtol.c @@ -0,0 +1,238 @@ +/* A more useful interface to strtol. + + Copyright (C) 1995-1996, 1998-2001, 2003-2007, 2009-2012 Free Software + Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Jim Meyering. */ + +#include + +/* Some pre-ANSI implementations (e.g. SunOS 4) + need stderr defined if assertion checking is enabled. */ +#include + +#ifdef HAVE_ASSERT_H +#include +#endif +#include +#include +#include +#include +#include +#include + +#include "lib/strutil.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +static strtol_error_t +bkm_scale (uintmax_t * x, int scale_factor) +{ + if (UINTMAX_MAX / scale_factor < *x) + { + *x = UINTMAX_MAX; + return LONGINT_OVERFLOW; + } + + *x *= scale_factor; + return LONGINT_OK; +} + +/* --------------------------------------------------------------------------------------------- */ + +static strtol_error_t +bkm_scale_by_power (uintmax_t * x, int base, int power) +{ + strtol_error_t err = LONGINT_OK; + while (power-- != 0) + err |= bkm_scale (x, base); + return err; +} + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +strtol_error_t +xstrtoumax (const char *s, char **ptr, int base, uintmax_t * val, const char *valid_suffixes) +{ + char *t_ptr; + char **p; + uintmax_t tmp; + strtol_error_t err = LONGINT_OK; + +#ifdef HAVE_ASSERT_H + assert (0 <= base && base <= 36); +#endif + + p = (ptr != NULL ? ptr : &t_ptr); + + { + const char *q = s; + unsigned char ch = *q; + + while (isspace (ch)) + ch = *++q; + + if (ch == '-') + return LONGINT_INVALID; + } + + errno = 0; + tmp = strtol (s, p, base); + + if (*p == s) + { + /* If there is no number but there is a valid suffix, assume the + number is 1. The string is invalid otherwise. */ + if (valid_suffixes != NULL && **p != '\0' && strchr (valid_suffixes, **p) != NULL) + tmp = 1; + else + return LONGINT_INVALID; + } + else if (errno != 0) + { + if (errno != ERANGE) + return LONGINT_INVALID; + err = LONGINT_OVERFLOW; + } + + /* Let valid_suffixes == NULL mean "allow any suffix". */ + /* FIXME: update all callers except the ones that allow suffixes + after the number, changing last parameter NULL to "". */ + if (valid_suffixes == NULL) + { + *val = tmp; + return err; + } + + if (**p != '\0') + { + int suffixes = 1; + strtol_error_t overflow; + + if (strchr (valid_suffixes, **p) == NULL) + { + *val = tmp; + return err | LONGINT_INVALID_SUFFIX_CHAR; + } + + base = 1024; + + if (strchr (valid_suffixes, '0') != NULL) + { + /* The "valid suffix" '0' is a special flag meaning that + an optional second suffix is allowed, which can change + the base. A suffix "B" (e.g. "100MB") stands for a power + of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for + a power of 1024. If no suffix (e.g. "100M"), assume + power-of-1024. */ + + switch (p[0][1]) + { + case 'i': + if (p[0][2] == 'B') + suffixes += 2; + break; + + case 'B': + case 'D': /* 'D' is obsolescent */ + base = 1000; + suffixes++; + break; + } + } + + switch (**p) + { + case 'b': + overflow = bkm_scale (&tmp, 512); + break; + + case 'B': + overflow = bkm_scale (&tmp, 1024); + break; + + case 'c': + overflow = 0; + break; + + case 'E': /* exa or exbi */ + overflow = bkm_scale_by_power (&tmp, base, 6); + break; + + case 'G': /* giga or gibi */ + case 'g': /* 'g' is undocumented; for compatibility only */ + overflow = bkm_scale_by_power (&tmp, base, 3); + break; + + case 'k': /* kilo */ + case 'K': /* kibi */ + overflow = bkm_scale_by_power (&tmp, base, 1); + break; + + case 'M': /* mega or mebi */ + case 'm': /* 'm' is undocumented; for compatibility only */ + overflow = bkm_scale_by_power (&tmp, base, 2); + break; + + case 'P': /* peta or pebi */ + overflow = bkm_scale_by_power (&tmp, base, 5); + break; + + case 'T': /* tera or tebi */ + case 't': /* 't' is undocumented; for compatibility only */ + overflow = bkm_scale_by_power (&tmp, base, 4); + break; + + case 'w': + overflow = bkm_scale (&tmp, 2); + break; + + case 'Y': /* yotta or 2**80 */ + overflow = bkm_scale_by_power (&tmp, base, 8); + break; + + case 'Z': /* zetta or 2**70 */ + overflow = bkm_scale_by_power (&tmp, base, 7); + break; + + default: + *val = tmp; + return err | LONGINT_INVALID_SUFFIX_CHAR; + } + + err |= overflow; + *p += suffixes; + if (**p != '\0') + err |= LONGINT_INVALID_SUFFIX_CHAR; + } + + *val = tmp; + return err; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/strutil/Makefile.am b/tests/lib/strutil/Makefile.am index 25c94a9a1..609dba0f6 100644 --- a/tests/lib/strutil/Makefile.am +++ b/tests/lib/strutil/Makefile.am @@ -8,9 +8,13 @@ AM_CPPFLAGS = \ LIBS = @CHECK_LIBS@ $(top_builddir)/lib/libmc.la TESTS = \ - replace__str_replace_all + replace__str_replace_all \ + parse_integer check_PROGRAMS = $(TESTS) replace__str_replace_all_SOURCES = \ replace__str_replace_all.c + +parse_integer_SOURCES = \ + parse_integer.c diff --git a/tests/lib/strutil/parse_integer.c b/tests/lib/strutil/parse_integer.c new file mode 100644 index 000000000..e670862cb --- /dev/null +++ b/tests/lib/strutil/parse_integer.c @@ -0,0 +1,168 @@ +/* + lib/strutil - tests for lib/strutil/parse_integer function. + + Copyright (C) 2013 + The Free Software Foundation, Inc. + + Written by: + Andrew Borodin , 2013 + + This file is part of the Midnight Commander. + + The Midnight Commander is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#define TEST_SUITE_NAME "/lib/strutil" + +#include "tests/mctest.h" + +#include + +#include "lib/strutil.h" + +/* --------------------------------------------------------------------------------------------- */ + +/* @Before */ +static void +setup (void) +{ +} + +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ +static void +teardown (void) +{ +} + +/* --------------------------------------------------------------------------------------------- */ + +/* @DataSource("str_replace_all_test_ds") */ +/* *INDENT-OFF* */ +static const struct parse_integer_test_ds +{ + const char *haystack; + uintmax_t expected_result; + gboolean invalid; +} parse_integer_test_ds[] = +{ + { + /* too big */ + "99999999999999999999999999999999999999999999999999999999999999999999", + 0, + TRUE + }, + { + "x", + 0, + TRUE + }, + { + "9x", + 0, + TRUE + }, + { + "1", + 1, + FALSE + }, + { + "-1", + 0, + TRUE + }, + { + "1k", + 1024, + FALSE + }, + { + "1K", + 1024, + FALSE + }, + { + "1M", + 1024 * 1024, + FALSE + }, + { + "1m", + 0, + TRUE + }, + { + "64M", + 64 * 1024 * 1024, + FALSE + }, + { + "1G", + 1 * 1024 * 1024 * 1024, + FALSE + } +}; +/* *INDENT-ON* */ + +/* @Test(dataSource = "str_replace_all_test_ds") */ +/* *INDENT-OFF* */ +START_TEST (parse_integer_test) +/* *INDENT-ON* */ +{ + /* given */ + uintmax_t actual_result; + gboolean invalid = FALSE; + const struct parse_integer_test_ds *data = &parse_integer_test_ds[_i]; + + /* when */ + actual_result = parse_integer (data->haystack, &invalid); + + /* then */ + fail_unless (invalid == data->invalid && actual_result == data->expected_result, + "actial ( %" PRIuMAX ") not equal to\nexpected (%" PRIuMAX ")", + actual_result, data->expected_result); +} +/* *INDENT-OFF* */ +END_TEST +/* *INDENT-ON* */ + +/* --------------------------------------------------------------------------------------------- */ + +int +main (void) +{ + int number_failed; + + Suite *s = suite_create (TEST_SUITE_NAME); + TCase *tc_core = tcase_create ("Core"); + SRunner *sr; + + tcase_add_checked_fixture (tc_core, setup, teardown); + + /* Add new tests here: *************** */ + tcase_add_loop_test (tc_core, parse_integer_test, 0, G_N_ELEMENTS (parse_integer_test_ds)); + /* *********************************** */ + + suite_add_tcase (s, tc_core); + sr = srunner_create (s); + srunner_set_log (sr, "parse_integer.log"); + srunner_run_all (sr, CK_NOFORK); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + return (number_failed == 0) ? 0 : 1; +} + +/* --------------------------------------------------------------------------------------------- */ From c6d6aaedd512a1c4951be9af24d0a7951c932f35 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 20 Feb 2013 13:32:04 +0400 Subject: [PATCH 22/25] Drop limit of edited file size. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 13 ++++--------- src/editor/editbuffer.c | 20 ++++++++++++++++++-- src/editor/editbuffer.h | 27 --------------------------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index 89e172812..f873e8d45 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -294,8 +294,10 @@ check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat if (st->st_size > 0) edit->delete_file = 0; - if (st->st_size >= SIZE_LIMIT) - errmsg = g_strdup_printf (_("File \"%s\" is too large"), vfs_path_as_str (filename_vpath)); + /* TODO: + * Add ini option of file size alarm threshold. + * Add here the query dialog "The file is too large. Open it anyway?". + */ cleanup: (void) mc_close (file); @@ -2413,10 +2415,6 @@ edit_push_redo_action (WEdit * edit, long c) void edit_insert (WEdit * edit, int c) { - /* check if file has grown to large */ - if (edit->last_byte >= SIZE_LIMIT) - return; - /* first we must update the position of the display window */ if (edit->buffer.curs1 < edit->start_display) { @@ -2461,9 +2459,6 @@ edit_insert (WEdit * edit, int c) void edit_insert_ahead (WEdit * edit, int c) { - if (edit->last_byte >= SIZE_LIMIT) - return; - if (edit->buffer.curs1 < edit->start_display) { edit->start_display++; diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index f05d74fd9..d7e599ab2 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -79,6 +79,22 @@ /*** file scope macro definitions ****************************************************************/ +/* + * The editor keeps data in two arrays of buffers. + * All buffers have the same size, which must be a power of 2. + */ + +/* Configurable: log2 of the buffer size in bytes */ +#ifndef S_EDIT_BUF_SIZE +#define S_EDIT_BUF_SIZE 16 +#endif + +/* Size of the buffer */ +#define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE) + +/* Buffer mask (used to find cursor position relative to the buffer) */ +#define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1) + /*** file scope type declarations ****************************************************************/ /*** file scope variables ************************************************************************/ @@ -127,8 +143,8 @@ edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) void edit_buffer_init (edit_buffer_t * buf, off_t size) { - buf->b1 = g_ptr_array_sized_new (MAXBUFF + 1); - buf->b2 = g_ptr_array_sized_new (MAXBUFF + 1); + buf->b1 = g_ptr_array_sized_new (32); + buf->b2 = g_ptr_array_sized_new (32); buf->curs1 = 0; buf->curs2 = 0; diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index d6a3c9e7c..06caf1db5 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -7,33 +7,6 @@ /*** typedefs(not structures) and defined constants **********************************************/ -/* - * The editor keeps data in two arrays of buffers. - * All buffers have the same size, which must be a power of 2. - */ - -/* Configurable: log2 of the buffer size in bytes */ -#ifndef S_EDIT_BUF_SIZE -#define S_EDIT_BUF_SIZE 16 -#endif - -/* Size of the buffer */ -#define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE) - -/* Buffer mask (used to find cursor position relative to the buffer) */ -#define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1) - -/* - * Configurable: Maximal allowed number of buffers in each buffer array. - * This number can be increased for systems with enough physical memory. - */ -#ifndef MAXBUFF -#define MAXBUFF 1024 -#endif - -/* Maximal length of file that can be opened */ -#define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2)) - /*** enums ***************************************************************************************/ /*** structures declarations (and typedefs of structures)*****************************************/ From dcf78f5382f63663412c81c4bbf5c0c883c3260f Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 1 Mar 2013 12:02:25 +0400 Subject: [PATCH 23/25] Add threshold for file size. Add "editor_filesize_threshold" ini option to ask open file if it size is larger than specified threshold. Supported string value formats are: "640000000", "64000K", "64M". Default value is 64M. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 43 +++++++++++++++---- src/editor/edit.h | 1 + src/setup.c | 1 + .../editor/editcmd__edit_complete_word_cmd.c | 2 + 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index f873e8d45..7354197fb 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -41,6 +41,7 @@ #include #include #include +#include /* UINTMAX_MAX */ #include #include @@ -101,6 +102,7 @@ int option_group_undo = 0; int show_right_margin = 0; char *option_backup_ext = NULL; +char *option_filesize_threshold = NULL; unsigned int edit_stack_iterator = 0; edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO]; @@ -135,6 +137,8 @@ static const struct edit_filters /* *INDENT-ON* */ }; +static const off_t option_filesize_default_threshold = 64 * 1024 * 1024; /* 64 MB */ + /* --------------------------------------------------------------------------------------------- */ /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -247,8 +251,10 @@ edit_insert_stream (WEdit * edit, FILE * f) static gboolean check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat *st) { + static uintmax_t threshold = UINTMAX_MAX; int file; gchar *errmsg = NULL; + gboolean ret = TRUE; /* Try opening an existing file */ file = mc_open (filename_vpath, O_NONBLOCK | O_RDONLY | O_BINARY, 0666); @@ -287,6 +293,16 @@ check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat goto cleanup; } + /* get file size threshold for alarm */ + if (threshold == UINTMAX_MAX) + { + gboolean err = FALSE; + + threshold = parse_integer (option_filesize_threshold, &err); + if (err) + threshold = option_filesize_default_threshold; + } + /* * Don't delete non-empty files. * O_EXCL should prevent it, but let's be on the safe side. @@ -294,21 +310,32 @@ check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat if (st->st_size > 0) edit->delete_file = 0; - /* TODO: - * Add ini option of file size alarm threshold. - * Add here the query dialog "The file is too large. Open it anyway?". - */ + if ((uintmax_t) st->st_size > threshold) + { + int act; + + errmsg = g_strdup_printf (_("File \"%s\" is too large.\nOpen it anyway?"), + vfs_path_as_str (filename_vpath)); + act = edit_query_dialog2 (_("Warning"), errmsg, _("&Yes"), _("&No")); + g_free (errmsg); + errmsg = NULL; + + if (act == 1) + ret = FALSE; + } cleanup: - (void) mc_close (file); - if (errmsg != NULL) { edit_error_dialog (_("Error"), errmsg); g_free (errmsg); - return FALSE; + ret = FALSE; } - return TRUE; + + if (!ret) + (void) mc_close (file); + + return ret; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/edit.h b/src/editor/edit.h index 3ff18607c..2382d732f 100644 --- a/src/editor/edit.h +++ b/src/editor/edit.h @@ -47,6 +47,7 @@ extern int option_save_position; extern int option_syntax_highlighting; extern int option_group_undo; extern char *option_backup_ext; +extern char *option_filesize_threshold; extern int edit_confirm_save; diff --git a/src/setup.c b/src/setup.c index acb0cc58b..bdd49d964 100644 --- a/src/setup.c +++ b/src/setup.c @@ -373,6 +373,7 @@ static const struct } str_options[] = { #ifdef USE_INTERNAL_EDIT { "editor_backup_extension", &option_backup_ext, "~" }, + { "editor_filesize_threshold", &option_filesize_threshold, "64M" }, #endif { "mcview_eof", &mcview_show_eof, "" }, { NULL, NULL, NULL } diff --git a/tests/src/editor/editcmd__edit_complete_word_cmd.c b/tests/src/editor/editcmd__edit_complete_word_cmd.c index 57dd64cb8..a938e4588 100644 --- a/tests/src/editor/editcmd__edit_complete_word_cmd.c +++ b/tests/src/editor/editcmd__edit_complete_word_cmd.c @@ -155,6 +155,8 @@ my_setup (void) load_codepages_list (); #endif /* HAVE_CHARSET */ + option_filesize_threshold = (char *) "64M"; + test_edit = edit_init (NULL, 0, 0, 24, 80, vfs_path_from_str ("test-data.txt"), 1); editcmd_dialog_completion_show__init (); } From c5924af3c454585a2307a473e8c8e2dcc3cbe4a6 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 8 Jun 2013 20:48:56 +0400 Subject: [PATCH 24/25] Indentation. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 54 +++++++++++++++++++++++------------------ src/editor/editbuffer.h | 2 +- src/editor/editcmd.c | 38 ++++++++++++++++++----------- src/editor/editdraw.c | 9 ++++--- src/editor/syntax.c | 3 ++- src/editor/wordproc.c | 15 +++++++----- 6 files changed, 73 insertions(+), 48 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index 7354197fb..1dc8cf14a 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -461,8 +461,8 @@ edit_save_position (WEdit * edit) return; book_mark_serialize (edit, BOOK_MARK_COLOR); - save_file_position (edit->filename_vpath, edit->buffer.curs_line + 1, edit->curs_col, edit->buffer.curs1, - edit->serialized_bookmarks); + save_file_position (edit->filename_vpath, edit->buffer.curs_line + 1, edit->curs_col, + edit->buffer.curs1, edit->serialized_bookmarks); edit->serialized_bookmarks = NULL; } @@ -986,8 +986,7 @@ edit_left_char_move_cmd (WEdit * edit) if (edit->column_highlight && option_cursor_beyond_eol && edit->mark1 != edit->mark2 - && edit->over_col == 0 - && edit->buffer.curs1 == edit_buffer_get_current_bol (&edit->buffer)) + && edit->over_col == 0 && edit->buffer.curs1 == edit_buffer_get_current_bol (&edit->buffer)) return; #ifdef HAVE_CHARSET if (edit->utf8) @@ -1033,7 +1032,7 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi } p = edit_buffer_get_current_bol (&edit->buffer); p = direction ? edit_buffer_move_backward (&edit->buffer, p, lines) : - edit_buffer_move_forward (&edit->buffer, p, lines, 0); + edit_buffer_move_forward (&edit->buffer, p, lines, 0); edit_cursor_move (edit, p - edit->buffer.curs1); edit_move_to_prev_col (edit, p); @@ -1141,15 +1140,15 @@ edit_do_undo (WEdit * edit) { edit->mark1 = ac - MARK_1; edit->column1 = - (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), 0, - edit->mark1); + (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), + 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); + (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2), + 0, edit->mark2); } else if (ac >= MARK_CURS - 2 && ac < KEY_PRESS) { @@ -1161,12 +1160,14 @@ edit_do_undo (WEdit * edit) if (edit->start_display > ac - KEY_PRESS) { - edit->start_line -= edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display); + edit->start_line -= + edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display); edit->force |= REDRAW_PAGE; } else if (edit->start_display < ac - KEY_PRESS) { - edit->start_line += edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS); + edit->start_line += + edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS); edit->force |= REDRAW_PAGE; } edit->start_display = ac - KEY_PRESS; /* see push and pop above */ @@ -1222,13 +1223,15 @@ edit_do_redo (WEdit * edit) { edit->mark1 = ac - MARK_1; edit->column1 = - (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), 0, edit->mark1); + (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), + 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); + (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2), + 0, edit->mark2); } /* more than one pop usually means something big */ if (count++) @@ -1237,12 +1240,14 @@ edit_do_redo (WEdit * edit) if (edit->start_display > ac - KEY_PRESS) { - edit->start_line -= edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display); + edit->start_line -= + edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display); edit->force |= REDRAW_PAGE; } else if (edit->start_display < ac - KEY_PRESS) { - edit->start_line += edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS); + edit->start_line += + edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS); edit->force |= REDRAW_PAGE; } edit->start_display = ac - KEY_PRESS; /* see push and pop above */ @@ -1545,7 +1550,8 @@ edit_move_block_to_right (WEdit * edit) insert_spaces_tab (edit, option_fake_half_tabs); else edit_insert (edit, '\t'); - edit_cursor_move (edit, edit_buffer_get_bol (&edit->buffer, cur_bol) - edit->buffer.curs1); + edit_cursor_move (edit, + edit_buffer_get_bol (&edit->buffer, cur_bol) - edit->buffer.curs1); } if (cur_bol == 0) @@ -1804,7 +1810,7 @@ edit_write_stream (WEdit * edit, FILE * f) { /* (c == '\n' || c == '\r') */ unsigned char c1; - c1 = edit_buffer_get_byte (&edit->buffer, i + 1); /* next char */ + c1 = edit_buffer_get_byte (&edit->buffer, i + 1); /* next char */ switch (edit->lb) { @@ -2879,7 +2885,8 @@ edit_move_to_prev_col (WEdit * edit, off_t p) long prev = edit->prev_col; long over = edit->over_col; - edit_cursor_move (edit, edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->buffer.curs1); + edit_cursor_move (edit, + edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->buffer.curs1); if (option_cursor_beyond_eol) { @@ -2918,9 +2925,11 @@ edit_move_to_prev_col (WEdit * edit, off_t p) 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); + edit_move_forward3 (edit, p, edit->curs_col, + 0) - edit->buffer.curs1); if (!left_of_four_spaces (edit)) - edit_cursor_move (edit, edit_move_forward3 (edit, p, q, 0) - edit->buffer.curs1); + edit_cursor_move (edit, + edit_move_forward3 (edit, p, q, 0) - edit->buffer.curs1); } } } @@ -3391,12 +3400,11 @@ 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->buffer)) { - while (edit_buffer_get_previous_byte (&edit->buffer) != '\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->buffer) - && right_of_four_spaces (edit)) + && right_of_four_spaces (edit)) { int i; diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index 06caf1db5..a55dd5c9d 100644 --- a/src/editor/editbuffer.h +++ b/src/editor/editbuffer.h @@ -99,4 +99,4 @@ edit_buffer_get_current_eol (const edit_buffer_t * buf) /* --------------------------------------------------------------------------------------------- */ -#endif /* MC__EDIT_BUFFER_H */ +#endif /* MC__EDIT_BUFFER_H */ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 4f9455271..57bba8a47 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -536,8 +536,9 @@ edit_delete_column_of_text (WEdit * edit) } if (n) /* move to next line except on the last delete */ - edit_cursor_move (edit, edit_buffer_move_forward (&edit->buffer, edit->buffer.curs1, 1, 0) - - edit->buffer.curs1); + edit_cursor_move (edit, + edit_buffer_move_forward (&edit->buffer, edit->buffer.curs1, 1, + 0) - edit->buffer.curs1); } } @@ -694,7 +695,8 @@ edit_calculate_start_of_next_line (const edit_buffer_t * buf, off_t current_pos, */ static off_t -edit_calculate_end_of_previous_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol) +edit_calculate_end_of_previous_line (const edit_buffer_t * buf, off_t current_pos, + char end_string_symbol) { off_t i; @@ -716,7 +718,8 @@ edit_calculate_end_of_previous_line (const edit_buffer_t * buf, off_t current_po */ static inline off_t -edit_calculate_start_of_previous_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol) +edit_calculate_start_of_previous_line (const edit_buffer_t * buf, off_t current_pos, + char end_string_symbol) { current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol); current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol); @@ -735,7 +738,8 @@ edit_calculate_start_of_previous_line (const edit_buffer_t * buf, off_t current_ */ static inline off_t -edit_calculate_start_of_current_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol) +edit_calculate_start_of_current_line (const edit_buffer_t * buf, off_t current_pos, + char end_string_symbol) { current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol); @@ -800,7 +804,8 @@ 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_buffer_get_byte (&edit->buffer, 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->buffer, start_mark, edit->buffer.size, @@ -809,7 +814,8 @@ editcmd_find (WEdit * edit, gsize * len) if ((edit->search_line_type & AT_END_LINE) != 0 && (end_mark - 1 != edit->buffer.size || edit_buffer_get_byte (&edit->buffer, end_mark) != end_string_symbol)) - end_mark = edit_calculate_end_of_previous_line (&edit->buffer, end_mark, end_string_symbol); + end_mark = + edit_calculate_end_of_previous_line (&edit->buffer, end_mark, end_string_symbol); if (start_mark >= end_mark) { edit->search->error = MC_SEARCH_E_NOTFOUND; @@ -831,7 +837,8 @@ editcmd_find (WEdit * edit, gsize * len) if ((edit->search_line_type & AT_START_LINE) != 0) search_start = - edit_calculate_start_of_current_line (&edit->buffer, search_start, end_string_symbol); + edit_calculate_start_of_current_line (&edit->buffer, search_start, + end_string_symbol); while (search_start >= start_mark) { @@ -849,7 +856,8 @@ editcmd_find (WEdit * edit, gsize * len) if ((edit->search_line_type & AT_START_LINE) != 0) search_start = - edit_calculate_start_of_previous_line (&edit->buffer, search_start, end_string_symbol); + edit_calculate_start_of_previous_line (&edit->buffer, search_start, + end_string_symbol); else search_start--; } @@ -860,7 +868,8 @@ editcmd_find (WEdit * edit, gsize * len) /* forward search */ if ((edit->search_line_type & AT_START_LINE) != 0 && search_start != start_mark) search_start = - edit_calculate_start_of_next_line (&edit->buffer, search_start, end_mark, end_string_symbol); + edit_calculate_start_of_next_line (&edit->buffer, search_start, end_mark, + end_string_symbol); return mc_search_run (edit->search, (void *) edit, search_start, end_mark, len); } return FALSE; @@ -1112,7 +1121,7 @@ edit_find_word_start (const edit_buffer_t * buf, off_t * word_start, gsize * wor if (isdigit (last)) return FALSE; - *word_start = buf->curs1 - (i - 1); /* start found */ + *word_start = buf->curs1 - (i - 1); /* start found */ *word_len = (gsize) (i - 1); break; } @@ -2356,8 +2365,8 @@ 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) + if ((edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1) == + edit_buffer_get_eol (&edit->buffer, start_mark)) && x2 > c1 && x2 <= c2) return; if (edit->buffer.curs1 > start_mark @@ -2408,7 +2417,8 @@ edit_block_move_cmd (WEdit * edit) while (count-- > start_mark) edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); - edit_set_markers (edit, edit->buffer.curs1, edit->buffer.curs1 + end_mark - start_mark, 0, 0); + edit_set_markers (edit, edit->buffer.curs1, edit->buffer.curs1 + end_mark - start_mark, 0, + 0); /* Place cursor at the end of text selection */ if (option_cursor_after_inserted_block) diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 7d4846e41..bf920d7c9 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -160,7 +160,8 @@ status_string (WEdit * edit, char *s, int w) edit->overwrite == 0 ? '-' : 'O', edit->curs_col + edit->over_col, edit->buffer.curs_line + 1, - edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, byte_str, + edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, + byte_str, #ifdef HAVE_CHARSET mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : #endif @@ -176,7 +177,8 @@ status_string (WEdit * edit, char *s, int w) edit->start_line + 1, edit->curs_row, edit->buffer.curs_line + 1, - edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, byte_str, + edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, + byte_str, #ifdef HAVE_CHARSET mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : #endif @@ -571,7 +573,8 @@ 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_buffer_get_eol (&edit->buffer, b); - while (tws > b && ((c = edit_buffer_get_byte (&edit->buffer, tws - 1)) == ' ' || c == '\t')) + while (tws > b + && ((c = edit_buffer_get_byte (&edit->buffer, tws - 1)) == ' ' || c == '\t')) tws--; } diff --git a/src/editor/syntax.c b/src/editor/syntax.c index d94540a20..b3db58563 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -317,7 +317,8 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text, } } return (whole_right != NULL && - strchr (whole_right, xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i))) != NULL) ? -1 : i; + strchr (whole_right, + xx_tolower (edit, edit_buffer_get_byte (&edit->buffer, i))) != NULL) ? -1 : i; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index 36c4097bc..555ce07f2 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -103,13 +103,13 @@ bad_line_start (const edit_buffer_t * buf, off_t p) { /* `...' is acceptable */ return !(edit_buffer_get_byte (buf, p + 1) == '.' - && edit_buffer_get_byte (buf, p + 2) == '.'); + && edit_buffer_get_byte (buf, p + 2) == '.'); } if (c == '-') { /* `---' is acceptable */ return !(edit_buffer_get_byte (buf, p + 1) == '-' - && edit_buffer_get_byte (buf, p + 2) == '-'); + && edit_buffer_get_byte (buf, p + 2) == '-'); } return (strchr (NO_FORMAT_CHARS_START, c) != NULL); @@ -158,8 +158,10 @@ end_paragraph (WEdit * edit, gboolean force) } return edit_buffer_get_eol (&edit->buffer, - edit_buffer_move_forward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer), - i - edit->buffer.curs_line, 0)); + edit_buffer_move_forward (&edit->buffer, + edit_buffer_get_current_bol + (&edit->buffer), + i - edit->buffer.curs_line, 0)); } /* --------------------------------------------------------------------------------------------- */ @@ -418,7 +420,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, long indent, off_t size) if (c != t[i]) replace_at (edit, p, t[i]); } - edit_cursor_move (edit, cursor - edit->buffer.curs1); /* restore cursor position */ + edit_cursor_move (edit, cursor - edit->buffer.curs1); /* restore cursor position */ } /* --------------------------------------------------------------------------------------------- */ @@ -470,7 +472,8 @@ format_paragraph (WEdit * edit, gboolean force) if (strchr (NO_FORMAT_CHARS_START, t->str[0]) == NULL) for (i = 0; i < size - 1; i++) - if (t->str[i] == '\n' && strchr (NO_FORMAT_CHARS_START "\t ", t->str[i + 1]) != NULL) + if (t->str[i] == '\n' + && strchr (NO_FORMAT_CHARS_START "\t ", t->str[i + 1]) != NULL) break; g_string_free (t, TRUE); From 6fff56c2f6b68eed0d05284d98eef5800f231be0 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 5 Jul 2013 09:16:42 +0400 Subject: [PATCH 25/25] Refresh po/*.po files. Signed-off-by: Andrew Borodin --- po/az.po | 6 +- po/be.po | 8 +- po/bg.po | 8 +- po/ca.po | 8 +- po/cs.po | 8 +- po/da.po | 8 +- po/de.po | 8 +- po/de_CH.po | 6 +- po/el.po | 8 +- po/eo.po | 8 +- po/es.po | 8 +- po/et.po | 6 +- po/eu.po | 8 +- po/fa.po | 8 +- po/fi.po | 6 +- po/fi_FI.po | 6 +- po/fr.po | 8 +- po/gl.po | 8 +- po/hr.po | 6 +- po/hu.po | 8 +- po/ia.po | 8 +- po/id.po | 6 +- po/it.po | 8 +- po/it_IT.po | 6 +- po/ja.po | 6 +- po/ka.po | 6 +- po/ko.po | 6 +- po/lt.po | 6 +- po/lv.po | 6 +- po/mc.pot | 577 ++++++++++++++++++++++++++-------------------------- po/mn.po | 6 +- po/nb.po | 6 +- po/nl.po | 8 +- po/pl.po | 8 +- po/pt.po | 8 +- po/pt_BR.po | 8 +- po/ro.po | 6 +- po/ru.po | 64 +++--- po/sk.po | 6 +- po/sl.po | 6 +- po/sr.po | 6 +- po/sv.po | 6 +- po/sv_SE.po | 6 +- po/ta.po | 6 +- po/tr.po | 6 +- po/uk.po | 8 +- po/vi.po | 6 +- po/wa.po | 6 +- po/zh_CN.po | 8 +- po/zh_TW.po | 6 +- 50 files changed, 528 insertions(+), 445 deletions(-) diff --git a/po/az.po b/po/az.po index 72f659743..cd5ca67c4 100644 --- a/po/az.po +++ b/po/az.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Azerbaijani (http://www.transifex.com/projects/p/mc/language/" @@ -860,7 +860,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/be.po b/po/be.po index b5696c0d4..7903e555b 100644 --- a/po/be.po +++ b/po/be.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Павал Шаламіцкі \n" "Language-Team: Belarusian (http://www.transifex.com/projects/p/mc/language/" @@ -924,8 +924,10 @@ msgstr "Немагчыма атрымаць памер або дазволы ф msgid "\"%s\" is not a regular file" msgstr "«%s» ня ёсьць звычайным файлам" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Файл «%s» — завялікі" #, c-format diff --git a/po/bg.po b/po/bg.po index b1f9d2cc6..a60fe8e6e 100644 --- a/po/bg.po +++ b/po/bg.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Yasen Pramatarov \n" "Language-Team: Bulgarian (http://www.transifex.com/projects/p/mc/language/" @@ -860,8 +860,10 @@ msgstr "" msgid "\"%s\" is not a regular file" msgstr "" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Файлът \"%s\" е твърде голям" #, c-format diff --git a/po/ca.po b/po/ca.po index d710c15d4..6a6e059e4 100644 --- a/po/ca.po +++ b/po/ca.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Daniel \n" "Language-Team: Catalan (http://www.transifex.com/projects/p/mc/language/" @@ -865,8 +865,10 @@ msgstr "" msgid "\"%s\" is not a regular file" msgstr "\"%s\" no és un fitxer estàndard" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "El fitxer \"%s\" és massa gran" #, c-format diff --git a/po/cs.po b/po/cs.po index 59df1bf08..83a65be66 100644 --- a/po/cs.po +++ b/po/cs.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Czech (http://www.transifex.com/projects/p/mc/language/cs/)\n" @@ -880,8 +880,10 @@ msgstr "Nelze zjistit velikost/práva k souboru %s" msgid "\"%s\" is not a regular file" msgstr "„%s“ není normální soubor" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Soubor „%s“ je příliš velký" #, c-format diff --git a/po/da.po b/po/da.po index 5f9b7cb76..9ccc7fa72 100644 --- a/po/da.po +++ b/po/da.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Danish (http://www.transifex.com/projects/p/mc/language/da/)\n" @@ -880,8 +880,10 @@ msgstr "Kan ikke indhente størrelse/tilladelser for %s" msgid "\"%s\" is not a regular file" msgstr "»%s« er ikke en regulær fil" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Fil »%s« er for stor" #, c-format diff --git a/po/de.po b/po/de.po index f5d513825..6da93443a 100644 --- a/po/de.po +++ b/po/de.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-17 11:42+0000\n" "Last-Translator: Fabian Affolter \n" "Language-Team: German (http://www.transifex.com/projects/p/mc/language/de/)\n" @@ -902,8 +902,10 @@ msgstr "Kann Größe/Zugriffsrechte der Datei \"%s\" nicht ermitteln" msgid "\"%s\" is not a regular file" msgstr "\"%s\" ist keine normale Datei" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Die Datei \"%s\" ist zu groß" #, c-format diff --git a/po/de_CH.po b/po/de_CH.po index a048fbbac..128a73b17 100644 --- a/po/de_CH.po +++ b/po/de_CH.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: German (Switzerland) (http://www.transifex.com/projects/p/mc/" @@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/el.po b/po/el.po index 505d08839..6c12aa668 100644 --- a/po/el.po +++ b/po/el.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Panos Bouklis \n" "Language-Team: Greek (http://www.transifex.com/projects/p/mc/language/el/)\n" @@ -883,8 +883,10 @@ msgstr "Αδυναμία λήψης του μεγέθους/αδειών για msgid "\"%s\" is not a regular file" msgstr "Το \"%s\" δεν είναι συνηθισμένο αρχείο" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Το αρχείο \"%s\" είναι πολύ μεγάλο" #, c-format diff --git a/po/eo.po b/po/eo.po index be6aa1c95..d63573672 100644 --- a/po/eo.po +++ b/po/eo.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 13:34+0000\n" "Last-Translator: Keith Bowes \n" "Language-Team: Esperanto (http://www.transifex.com/projects/p/mc/language/" @@ -919,8 +919,10 @@ msgstr "Ne eblas akiri grandon/permesojn por %s" msgid "\"%s\" is not a regular file" msgstr "\"%s\" estas ne normala dosiero" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Dosiero \"%s\" estas tro granda" #, c-format diff --git a/po/es.po b/po/es.po index c19f83b8c..c90b20b45 100644 --- a/po/es.po +++ b/po/es.po @@ -12,7 +12,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: David Martin \n" "Language-Team: Spanish (http://www.transifex.com/projects/p/mc/language/" @@ -929,8 +929,10 @@ msgstr "Imposible obtener tamaño/permisos para %s" msgid "\"%s\" is not a regular file" msgstr "«%s» no es un archivo ordinario" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "El archivo «%s» es demasiado grande" #, c-format diff --git a/po/et.po b/po/et.po index 0d2f94bca..c1efe8db5 100644 --- a/po/et.po +++ b/po/et.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2011-07-11 17:34+0000\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -855,7 +855,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/eu.po b/po/eu.po index 1cfc0fc7f..531bcfb34 100644 --- a/po/eu.po +++ b/po/eu.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Basque (http://www.transifex.com/projects/p/mc/language/eu/)\n" @@ -901,8 +901,10 @@ msgstr "%s-ren neurria/baimenak ezin eskuratu" msgid "\"%s\" is not a regular file" msgstr "\"%s\" ez da fitxategi arrunta" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "\"%s\" fitxategia handiegia da" #, c-format diff --git a/po/fa.po b/po/fa.po index 59fbbcd89..bda25f30b 100644 --- a/po/fa.po +++ b/po/fa.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Sina Saharkhiz \n" "Language-Team: Persian (http://www.transifex.com/projects/p/mc/language/" @@ -860,8 +860,10 @@ msgstr "" msgid "\"%s\" is not a regular file" msgstr "" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "فایل \"%s\" بیش از حد بزرگ است" #, c-format diff --git a/po/fi.po b/po/fi.po index 1b7463179..1907d00c2 100644 --- a/po/fi.po +++ b/po/fi.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Finnish (http://www.transifex.com/projects/p/mc/language/" @@ -858,7 +858,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/fi_FI.po b/po/fi_FI.po index 69d9e63ae..21aefb118 100644 --- a/po/fi_FI.po +++ b/po/fi_FI.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: LANGUAGE \n" @@ -866,7 +866,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/fr.po b/po/fr.po index 4f1e650c0..808f443ce 100644 --- a/po/fr.po +++ b/po/fr.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Stéphane Aulery \n" "Language-Team: French (http://www.transifex.com/projects/p/mc/language/fr/)\n" @@ -877,8 +877,10 @@ msgstr "Impossible d'obtenir la taille ou les permissions de %s" msgid "\"%s\" is not a regular file" msgstr "" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Le fichier \"%s\" est trop grand" #, c-format diff --git a/po/gl.po b/po/gl.po index 0e7de4cb7..4a18958ec 100644 --- a/po/gl.po +++ b/po/gl.po @@ -12,7 +12,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-26 10:28+0000\n" "Last-Translator: mbouzada \n" "Language-Team: Galician (http://www.transifex.com/projects/p/mc/language/" @@ -927,8 +927,10 @@ msgstr "Non é posíbel obter tamaño/permisos do ficheiro: %s" msgid "\"%s\" is not a regular file" msgstr "«%s» non é un ficheiro regular" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "O ficheiro «%s» é demasiado grande" #, c-format diff --git a/po/hr.po b/po/hr.po index a00290db4..09162e3c5 100644 --- a/po/hr.po +++ b/po/hr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2010-12-29 10:19+0000\n" "Last-Translator: FULL NAME \n" "Language-Team: Croatian (http://www.transifex.com/projects/p/mc/language/" @@ -858,7 +858,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/hu.po b/po/hu.po index 22abde9ce..1b22d9736 100644 --- a/po/hu.po +++ b/po/hu.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Rezső Páder \n" "Language-Team: Hungarian (http://www.transifex.com/projects/p/mc/language/" @@ -927,8 +927,10 @@ msgstr "Méret/hozzáférés lekérdezése nem sikerült: %s" msgid "\"%s\" is not a regular file" msgstr "\"%s\": speciális fájl" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "A(z) \"%s\" fájl túl nagy" #, c-format diff --git a/po/ia.po b/po/ia.po index 26cc39d29..d09a5b2d5 100644 --- a/po/ia.po +++ b/po/ia.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Martijn Dekker \n" "Language-Team: Interlingua (http://www.transifex.com/projects/p/mc/language/" @@ -880,8 +880,10 @@ msgstr "Impossibile obtener dimension/permissiones pro %s" msgid "\"%s\" is not a regular file" msgstr "\"%s\" non es un file regular" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Le file \"%s\" es multo grande" #, c-format diff --git a/po/id.po b/po/id.po index a56a12419..5eb9e8c54 100644 --- a/po/id.po +++ b/po/id.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Andika Triwidada \n" "Language-Team: Indonesian (http://www.transifex.com/projects/p/mc/language/" @@ -867,7 +867,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/it.po b/po/it.po index a0f090112..f2bb6a57d 100644 --- a/po/it.po +++ b/po/it.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-05-03 00:01+0200\n" "Last-Translator: Marco Ciampa \n" "Language-Team: Italian (http://www.transifex.com/projects/p/mc/language/" @@ -925,8 +925,10 @@ msgstr "Impossibile ottenere dimensioni/permessi per %s" msgid "\"%s\" is not a regular file" msgstr "\"%s\" non è un file normale" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Il file \"%s\" è troppo grande" #, c-format diff --git a/po/it_IT.po b/po/it_IT.po index 87f0a8ed4..7dd88d1b7 100644 --- a/po/it_IT.po +++ b/po/it_IT.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2011-12-07 11:21+0000\n" "Last-Translator: slavazanko \n" "Language-Team: Italian (Italy) (http://www.transifex.net/projects/p/mc/team/" @@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/ja.po b/po/ja.po index e134f9210..a1ebf58b8 100644 --- a/po/ja.po +++ b/po/ja.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Japanese (http://www.transifex.com/projects/p/mc/language/" @@ -870,7 +870,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/ka.po b/po/ka.po index 434ebfdab..235480194 100644 --- a/po/ka.po +++ b/po/ka.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: George Machitidze \n" "Language-Team: Georgian (http://www.transifex.com/projects/p/mc/language/" @@ -858,7 +858,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/ko.po b/po/ko.po index 6fd3d5999..f00c12ec8 100644 --- a/po/ko.po +++ b/po/ko.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Korean (http://www.transifex.com/projects/p/mc/language/ko/)\n" @@ -863,7 +863,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/lt.po b/po/lt.po index e339d55cc..ff612f697 100644 --- a/po/lt.po +++ b/po/lt.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Lithuanian (http://www.transifex.com/projects/p/mc/language/" @@ -862,7 +862,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/lv.po b/po/lv.po index 27a1060cf..0636659ab 100644 --- a/po/lv.po +++ b/po/lv.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: LANGUAGE \n" @@ -860,7 +860,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/mc.pot b/po/mc.pot index 6e40b1353..9c95230f4 100644 --- a/po/mc.pot +++ b/po/mc.pot @@ -5,9 +5,9 @@ # msgid "" msgstr "" -"Project-Id-Version: mc 4.8.8-83-ge94a084\n" +"Project-Id-Version: mc 4.8.8-126-g3b71dbd\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -106,9 +106,9 @@ msgid "" "to %s\n" msgstr "" -#: lib/search/lib.c:43 src/diffviewer/search.c:230 src/editor/editcmd.c:833 -#: src/editor/editcmd.c:854 src/editor/editcmd.c:894 src/editor/editcmd.c:982 -#: src/editor/editcmd.c:2683 src/viewer/search.c:107 +#: lib/search/lib.c:43 src/diffviewer/search.c:230 src/editor/editcmd.c:801 +#: src/editor/editcmd.c:822 src/editor/editcmd.c:864 src/editor/editcmd.c:953 +#: src/editor/editcmd.c:2658 src/viewer/search.c:107 msgid "Search string not found" msgstr "" @@ -129,19 +129,19 @@ msgstr "" msgid "Regular expression error" msgstr "" -#: lib/search/search.c:50 src/diffviewer/ydiff.c:2352 +#: lib/search/search.c:51 src/diffviewer/ydiff.c:2352 msgid "No&rmal" msgstr "" -#: lib/search/search.c:51 src/filemanager/find.c:518 +#: lib/search/search.c:52 src/filemanager/find.c:518 msgid "Re&gular expression" msgstr "" -#: lib/search/search.c:52 +#: lib/search/search.c:53 msgid "He&xadecimal" msgstr "" -#: lib/search/search.c:53 +#: lib/search/search.c:54 msgid "Wil&dcard search" msgstr "" @@ -552,13 +552,13 @@ msgid "" msgstr "" #: lib/utilunix.c:514 lib/utilunix.c:519 lib/utilunix.c:574 -#: src/editor/editcmd.c:206 src/editor/editcmd.c:229 src/editor/editcmd.c:437 -#: src/editor/editcmd.c:598 src/editor/editcmd.c:1703 -#: src/editor/editcmd.c:3400 src/editor/editcmd.c:3429 +#: src/editor/edit.c:319 src/editor/editcmd.c:206 src/editor/editcmd.c:229 +#: src/editor/editcmd.c:400 src/editor/editcmd.c:563 src/editor/editcmd.c:1675 +#: src/editor/editcmd.c:3375 src/editor/editcmd.c:3404 #: src/editor/editcmd_dialogs.c:471 src/execute.c:133 -#: src/filemanager/file.c:1670 src/filemanager/panel.c:4251 src/help.c:362 +#: src/filemanager/file.c:1671 src/filemanager/panel.c:4251 src/help.c:362 #: src/main.c:359 src/main.c:389 src/subshell.c:389 src/subshell.c:1058 -#: src/viewer/actions_cmd.c:399 +#: src/viewer/actions_cmd.c:420 msgid "Warning" msgstr "" @@ -663,31 +663,31 @@ msgstr "" msgid "Do you want clean this history?" msgstr "" -#: lib/widget/listbox.c:285 src/diffviewer/ydiff.c:3099 -#: src/editor/editcmd.c:208 src/editor/editcmd.c:231 src/editor/editcmd.c:2807 -#: src/editor/editcmd.c:2813 src/filemanager/cmd.c:143 -#: src/filemanager/file.c:692 src/filemanager/file.c:2784 +#: lib/widget/listbox.c:285 src/diffviewer/ydiff.c:3099 src/editor/edit.c:319 +#: src/editor/editcmd.c:208 src/editor/editcmd.c:231 src/editor/editcmd.c:2782 +#: src/editor/editcmd.c:2788 src/filemanager/cmd.c:143 +#: src/filemanager/file.c:693 src/filemanager/file.c:2786 #: src/filemanager/filegui.c:430 src/filemanager/hotlist.c:1115 #: src/filemanager/hotlist.c:1132 src/filemanager/midnight.c:1002 #: src/filemanager/midnight.c:1010 src/filemanager/panel.c:2599 -#: src/filemanager/tree.c:873 src/subshell.c:1060 src/viewer/actions_cmd.c:596 -#: src/viewer/actions_cmd.c:602 src/viewer/search.c:332 +#: src/filemanager/tree.c:873 src/subshell.c:1060 src/viewer/actions_cmd.c:617 +#: src/viewer/actions_cmd.c:623 src/viewer/search.c:323 msgid "&Yes" msgstr "" -#: lib/widget/listbox.c:285 src/diffviewer/ydiff.c:3099 -#: src/editor/editcmd.c:208 src/editor/editcmd.c:2807 -#: src/editor/editcmd.c:2813 src/filemanager/cmd.c:143 -#: src/filemanager/file.c:692 src/filemanager/file.c:2784 +#: lib/widget/listbox.c:285 src/diffviewer/ydiff.c:3099 src/editor/edit.c:319 +#: src/editor/editcmd.c:208 src/editor/editcmd.c:2782 +#: src/editor/editcmd.c:2788 src/filemanager/cmd.c:143 +#: src/filemanager/file.c:693 src/filemanager/file.c:2786 #: src/filemanager/filegui.c:432 src/filemanager/hotlist.c:1115 #: src/filemanager/hotlist.c:1132 src/filemanager/midnight.c:1002 #: src/filemanager/midnight.c:1010 src/filemanager/panel.c:2599 -#: src/filemanager/tree.c:873 src/subshell.c:1060 src/viewer/actions_cmd.c:596 -#: src/viewer/actions_cmd.c:602 src/viewer/search.c:333 +#: src/filemanager/tree.c:873 src/subshell.c:1060 src/viewer/actions_cmd.c:617 +#: src/viewer/actions_cmd.c:623 src/viewer/search.c:324 msgid "&No" msgstr "" -#: lib/widget/quick.h:215 src/editor/editcmd.c:2683 +#: lib/widget/quick.h:215 src/editor/editcmd.c:2658 #: src/editor/editcmd_dialogs.c:121 src/editor/editwidget.c:150 #: src/filemanager/boxes.c:1110 src/filemanager/filegui.c:1207 #: src/filemanager/find.c:526 src/filemanager/layout.c:451 src/subshell.c:392 @@ -695,17 +695,17 @@ msgid "&OK" msgstr "" #: lib/widget/quick.h:216 src/editor/editcmd.c:208 src/editor/editcmd.c:231 -#: src/editor/editcmd.c:439 src/editor/editcmd.c:601 src/editor/editcmd.c:1704 -#: src/editor/editcmd.c:2058 src/editor/editcmd.c:2807 -#: src/editor/editcmd.c:3403 src/editor/editcmd.c:3432 +#: src/editor/editcmd.c:402 src/editor/editcmd.c:566 src/editor/editcmd.c:1676 +#: src/editor/editcmd.c:2030 src/editor/editcmd.c:2782 +#: src/editor/editcmd.c:3378 src/editor/editcmd.c:3407 #: src/editor/editcmd_dialogs.c:123 src/editor/editcmd_dialogs.c:278 #: src/editor/editcmd_dialogs.c:473 src/editor/spell_dialogs.c:99 #: src/filemanager/achown.c:97 src/filemanager/chmod.c:126 -#: src/filemanager/chown.c:92 src/filemanager/cmd.c:1275 +#: src/filemanager/chown.c:92 src/filemanager/cmd.c:1279 #: src/filemanager/filegui.c:1211 src/filemanager/find.c:526 #: src/filemanager/hotlist.c:192 src/filemanager/hotlist.c:971 #: src/filemanager/hotlist.c:1033 src/filemanager/layout.c:452 -#: src/filemanager/panelize.c:143 src/learn.c:258 src/viewer/hex.c:389 +#: src/filemanager/panelize.c:144 src/learn.c:258 src/viewer/hex.c:389 msgid "&Cancel" msgstr "" @@ -713,10 +713,10 @@ msgstr "" msgid "Background process:" msgstr "" -#: lib/widget/wtools.c:287 lib/widget/wtools.c:412 src/editor/edit.c:215 -#: src/editor/edit.c:247 src/editor/edit.c:377 src/editor/edit.c:2132 -#: src/editor/edit.c:2142 src/editor/editcmd.c:293 src/editor/editcmd.c:303 -#: src/editor/editcmd.c:381 src/editor/editcmd.c:2908 src/editor/spell.c:318 +#: lib/widget/wtools.c:287 lib/widget/wtools.c:412 src/editor/edit.c:164 +#: src/editor/edit.c:177 src/editor/edit.c:330 src/editor/edit.c:1922 +#: src/editor/edit.c:1932 src/editor/editcmd.c:293 src/editor/editcmd.c:303 +#: src/editor/editcmd.c:344 src/editor/editcmd.c:2883 src/editor/spell.c:318 #: src/editor/spell.c:555 src/editor/spell.c:563 #: tests/src/execute__common.c:145 #: tests/src/execute__execute_with_vfs_arg.c:154 @@ -909,8 +909,8 @@ msgstr "" msgid "Two files are required to evoke the diffviewer." msgstr "" -#: src/background.c:213 src/background.c:287 src/filemanager/file.c:604 -#: src/filemanager/file.c:646 +#: src/background.c:213 src/background.c:287 src/filemanager/file.c:605 +#: src/filemanager/file.c:647 msgid "Background process error" msgstr "" @@ -938,7 +938,7 @@ msgid "" "than we can handle." msgstr "" -#: src/diffviewer/internal.h:15 src/editor/edit-impl.h:101 +#: src/diffviewer/internal.h:15 src/editor/edit-impl.h:74 msgid "&Dismiss" msgstr "" @@ -973,10 +973,9 @@ msgstr "" #: src/diffviewer/search.c:106 src/diffviewer/search.c:230 #: src/diffviewer/search.c:243 src/diffviewer/search.c:270 -#: src/editor/editcmd.c:982 src/editor/editcmd.c:1012 -#: src/editor/editcmd.c:2577 src/editor/editcmd_dialogs.c:130 -#: src/viewer/dialogs.c:112 src/viewer/search.c:150 src/viewer/search.c:253 -#: src/viewer/search.c:356 +#: src/editor/editcmd.c:953 src/editor/editcmd.c:983 src/editor/editcmd.c:2552 +#: src/editor/editcmd_dialogs.c:130 src/viewer/dialogs.c:112 +#: src/viewer/search.c:142 src/viewer/search.c:244 src/viewer/search.c:347 msgid "Search" msgstr "" @@ -1062,17 +1061,17 @@ msgstr "" msgid "Goto line (right)" msgstr "" -#: src/diffviewer/ydiff.c:2912 src/editor/editcmd.c:2987 +#: src/diffviewer/ydiff.c:2912 src/editor/editcmd.c:2962 msgid "Enter line:" msgstr "" -#: src/diffviewer/ydiff.c:2953 src/editor/editwidget.c:975 +#: src/diffviewer/ydiff.c:2953 src/editor/editwidget.c:977 #: src/filemanager/midnight.c:1618 src/filemanager/tree.c:1204 src/help.c:1146 #: src/viewer/display.c:86 msgid "ButtonBar|Help" msgstr "" -#: src/diffviewer/ydiff.c:2954 src/editor/editwidget.c:976 +#: src/diffviewer/ydiff.c:2954 src/editor/editwidget.c:978 #: src/viewer/display.c:98 msgid "ButtonBar|Save" msgstr "" @@ -1086,7 +1085,7 @@ msgstr "" msgid "ButtonBar|Merge" msgstr "" -#: src/diffviewer/ydiff.c:2957 src/editor/editwidget.c:981 +#: src/diffviewer/ydiff.c:2957 src/editor/editwidget.c:983 #: src/viewer/display.c:108 msgid "ButtonBar|Search" msgstr "" @@ -1095,14 +1094,14 @@ msgstr "" msgid "ButtonBar|Options" msgstr "" -#: src/diffviewer/ydiff.c:2959 src/editor/editwidget.c:984 +#: src/diffviewer/ydiff.c:2959 src/editor/editwidget.c:986 #: src/filemanager/midnight.c:1627 src/help.c:1155 src/viewer/display.c:120 #: src/viewer/display.c:123 msgid "ButtonBar|Quit" msgstr "" -#: src/diffviewer/ydiff.c:3096 src/editor/editcmd.c:2813 -#: src/viewer/actions_cmd.c:594 src/viewer/actions_cmd.c:600 +#: src/diffviewer/ydiff.c:3096 src/editor/editcmd.c:2788 +#: src/viewer/actions_cmd.c:615 src/viewer/actions_cmd.c:621 msgid "Quit" msgstr "" @@ -1127,7 +1126,7 @@ msgid "\"%s\" is a directory" msgstr "" #: src/diffviewer/ydiff.c:3577 src/diffviewer/ydiff.c:3594 -#: src/filemanager/file.c:2686 src/viewer/mcviewer.c:336 +#: src/filemanager/file.c:2688 src/viewer/mcviewer.c:336 #, c-format msgid "" "Cannot stat \"%s\"\n" @@ -1154,37 +1153,39 @@ msgstr "" msgid "< Reload Current Syntax >" msgstr "" -#: src/editor/edit.c:214 src/editor/edit.c:337 +#: src/editor/edit.c:163 src/editor/edit.c:271 #, c-format msgid "Cannot open %s for reading" msgstr "" -#: src/editor/edit.c:246 +#: src/editor/edit.c:176 #, c-format msgid "Error reading %s" msgstr "" -#: src/editor/edit.c:349 +#: src/editor/edit.c:283 #, c-format msgid "Cannot get size/permissions for %s" msgstr "" -#: src/editor/edit.c:358 +#: src/editor/edit.c:292 #, c-format msgid "\"%s\" is not a regular file" msgstr "" -#: src/editor/edit.c:370 +#: src/editor/edit.c:317 #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" -#: src/editor/edit.c:2131 +#: src/editor/edit.c:1921 #, c-format msgid "Error reading from pipe: %s" msgstr "" -#: src/editor/edit.c:2141 +#: src/editor/edit.c:1931 #, c-format msgid "Cannot open pipe for reading: %s" msgstr "" @@ -1207,308 +1208,308 @@ msgstr "" msgid "Cannot open pipe for writing: %s" msgstr "" -#: src/editor/editcmd.c:380 +#: src/editor/editcmd.c:343 #, c-format msgid "Cannot open file for writing: %s" msgstr "" -#: src/editor/editcmd.c:438 +#: src/editor/editcmd.c:401 msgid "The file you are saving is not finished with a newline" msgstr "" -#: src/editor/editcmd.c:439 src/editor/editcmd.c:601 src/editor/editcmd.c:3402 -#: src/editor/editcmd.c:3431 src/editor/editcmd_dialogs.c:473 +#: src/editor/editcmd.c:402 src/editor/editcmd.c:566 src/editor/editcmd.c:3377 +#: src/editor/editcmd.c:3406 src/editor/editcmd_dialogs.c:473 msgid "C&ontinue" msgstr "" -#: src/editor/editcmd.c:452 +#: src/editor/editcmd.c:415 msgid "&Do not change" msgstr "" -#: src/editor/editcmd.c:453 +#: src/editor/editcmd.c:416 msgid "&Unix format (LF)" msgstr "" -#: src/editor/editcmd.c:454 +#: src/editor/editcmd.c:417 msgid "&Windows/DOS format (CR LF)" msgstr "" -#: src/editor/editcmd.c:455 +#: src/editor/editcmd.c:418 msgid "&Macintosh format (CR)" msgstr "" -#: src/editor/editcmd.c:461 src/editor/editcmd.c:2079 -#: src/editor/editcmd.c:3030 src/editor/editcmd.c:3062 -#: src/filemanager/cmd.c:856 +#: src/editor/editcmd.c:424 src/editor/editcmd.c:2051 +#: src/editor/editcmd.c:3005 src/editor/editcmd.c:3037 +#: src/filemanager/cmd.c:860 msgid "Enter file name:" msgstr "" -#: src/editor/editcmd.c:465 +#: src/editor/editcmd.c:428 msgid "Change line breaks to:" msgstr "" -#: src/editor/editcmd.c:474 +#: src/editor/editcmd.c:437 msgid "Save As" msgstr "" -#: src/editor/editcmd.c:600 +#: src/editor/editcmd.c:565 msgid "Block is large, you may not be able to undo this action" msgstr "" -#: src/editor/editcmd.c:1600 +#: src/editor/editcmd.c:1572 msgid "&Quick save" msgstr "" -#: src/editor/editcmd.c:1601 +#: src/editor/editcmd.c:1573 msgid "&Safe save" msgstr "" -#: src/editor/editcmd.c:1602 +#: src/editor/editcmd.c:1574 msgid "&Do backups with following extension:" msgstr "" -#: src/editor/editcmd.c:1623 +#: src/editor/editcmd.c:1595 msgid "Check &POSIX new line" msgstr "" -#: src/editor/editcmd.c:1631 +#: src/editor/editcmd.c:1603 msgid "Edit Save Mode" msgstr "" -#: src/editor/editcmd.c:1688 src/editor/editcmd.c:1758 +#: src/editor/editcmd.c:1660 src/editor/editcmd.c:1730 msgid "Save as" msgstr "" -#: src/editor/editcmd.c:1690 +#: src/editor/editcmd.c:1662 msgid "Cannot save: destination is not a regular file" msgstr "" -#: src/editor/editcmd.c:1704 +#: src/editor/editcmd.c:1676 msgid "A file already exists with this name" msgstr "" -#: src/editor/editcmd.c:1704 +#: src/editor/editcmd.c:1676 msgid "&Overwrite" msgstr "" -#: src/editor/editcmd.c:1758 src/editor/editcmd.c:3040 +#: src/editor/editcmd.c:1730 src/editor/editcmd.c:3015 msgid "Cannot save file" msgstr "" -#: src/editor/editcmd.c:1783 src/editor/editcmd.c:1786 +#: src/editor/editcmd.c:1755 src/editor/editcmd.c:1758 msgid "Delete macro" msgstr "" -#: src/editor/editcmd.c:1783 +#: src/editor/editcmd.c:1755 msgid "Press macro hotkey:" msgstr "" -#: src/editor/editcmd.c:1786 +#: src/editor/editcmd.c:1758 msgid "Macro not deleted" msgstr "" -#: src/editor/editcmd.c:1841 +#: src/editor/editcmd.c:1813 msgid "Save macro" msgstr "" -#: src/editor/editcmd.c:1841 +#: src/editor/editcmd.c:1813 msgid "Press the macro's new hotkey:" msgstr "" -#: src/editor/editcmd.c:1915 +#: src/editor/editcmd.c:1887 msgid "Repeat last commands" msgstr "" -#: src/editor/editcmd.c:1915 +#: src/editor/editcmd.c:1887 msgid "Repeat times:" msgstr "" -#: src/editor/editcmd.c:2056 +#: src/editor/editcmd.c:2028 #, c-format msgid "Confirm save file: \"%s\"" msgstr "" -#: src/editor/editcmd.c:2058 src/viewer/hex.c:377 src/viewer/hex.c:389 +#: src/editor/editcmd.c:2030 src/viewer/hex.c:377 src/viewer/hex.c:389 msgid "Save file" msgstr "" -#: src/editor/editcmd.c:2058 src/editor/editmenu.c:77 src/learn.c:196 +#: src/editor/editcmd.c:2030 src/editor/editmenu.c:77 src/learn.c:196 #: src/learn.c:257 msgid "&Save" msgstr "" -#: src/editor/editcmd.c:2079 +#: src/editor/editcmd.c:2051 msgid "Load" msgstr "" -#: src/editor/editcmd.c:2112 +#: src/editor/editcmd.c:2084 msgid "Syntax file edit" msgstr "" -#: src/editor/editcmd.c:2113 +#: src/editor/editcmd.c:2085 msgid "Which syntax file you want to edit?" msgstr "" -#: src/editor/editcmd.c:2114 src/editor/editcmd.c:2159 -#: src/filemanager/cmd.c:1095 src/filemanager/cmd.c:1131 -#: src/filemanager/cmd.c:1189 +#: src/editor/editcmd.c:2086 src/editor/editcmd.c:2131 +#: src/filemanager/cmd.c:1099 src/filemanager/cmd.c:1135 +#: src/filemanager/cmd.c:1193 msgid "&User" msgstr "" -#: src/editor/editcmd.c:2114 src/editor/editcmd.c:2159 +#: src/editor/editcmd.c:2086 src/editor/editcmd.c:2131 msgid "&System wide" msgstr "" -#: src/editor/editcmd.c:2157 src/filemanager/cmd.c:1129 +#: src/editor/editcmd.c:2129 src/filemanager/cmd.c:1133 msgid "Menu edit" msgstr "" -#: src/editor/editcmd.c:2158 src/filemanager/cmd.c:1130 +#: src/editor/editcmd.c:2130 src/filemanager/cmd.c:1134 msgid "Which menu file do you want to edit?" msgstr "" -#: src/editor/editcmd.c:2159 src/filemanager/cmd.c:1131 +#: src/editor/editcmd.c:2131 src/filemanager/cmd.c:1135 msgid "&Local" msgstr "" -#: src/editor/editcmd.c:2642 src/editor/editcmd.c:2683 -#: src/editor/editcmd.c:2694 src/editor/editcmd_dialogs.c:220 +#: src/editor/editcmd.c:2617 src/editor/editcmd.c:2658 +#: src/editor/editcmd.c:2669 src/editor/editcmd_dialogs.c:220 msgid "Replace" msgstr "" -#: src/editor/editcmd.c:2694 +#: src/editor/editcmd.c:2669 #, c-format msgid "%ld replacements made" msgstr "" -#: src/editor/editcmd.c:2779 src/editor/editwidget.c:394 +#: src/editor/editcmd.c:2754 src/editor/editwidget.c:394 msgid "[NoName]" msgstr "" -#: src/editor/editcmd.c:2806 +#: src/editor/editcmd.c:2781 #, c-format msgid "" "File %s was modified.\n" "Save before close?" msgstr "" -#: src/editor/editcmd.c:2807 +#: src/editor/editcmd.c:2782 msgid "Close file" msgstr "" -#: src/editor/editcmd.c:2811 +#: src/editor/editcmd.c:2786 #, c-format msgid "" "Midnight Commander is being shut down.\n" "Save modified file %s?" msgstr "" -#: src/editor/editcmd.c:2908 +#: src/editor/editcmd.c:2883 msgid "This function is not implemented" msgstr "" -#: src/editor/editcmd.c:2922 +#: src/editor/editcmd.c:2897 msgid "Copy to clipboard" msgstr "" -#: src/editor/editcmd.c:2922 src/editor/editcmd.c:2942 +#: src/editor/editcmd.c:2897 src/editor/editcmd.c:2917 msgid "Unable to save to file" msgstr "" -#: src/editor/editcmd.c:2942 +#: src/editor/editcmd.c:2917 msgid "Cut to clipboard" msgstr "" -#: src/editor/editcmd.c:2987 +#: src/editor/editcmd.c:2962 msgid "Goto line" msgstr "" -#: src/editor/editcmd.c:3030 src/editor/editcmd.c:3040 +#: src/editor/editcmd.c:3005 src/editor/editcmd.c:3015 msgid "Save block" msgstr "" -#: src/editor/editcmd.c:3062 src/editor/editcmd.c:3077 +#: src/editor/editcmd.c:3037 src/editor/editcmd.c:3052 msgid "Insert file" msgstr "" -#: src/editor/editcmd.c:3077 +#: src/editor/editcmd.c:3052 msgid "Cannot insert file" msgstr "" -#: src/editor/editcmd.c:3099 +#: src/editor/editcmd.c:3074 msgid "Sort block" msgstr "" -#: src/editor/editcmd.c:3099 +#: src/editor/editcmd.c:3074 msgid "You must first highlight a block of text" msgstr "" -#: src/editor/editcmd.c:3107 +#: src/editor/editcmd.c:3082 msgid "Run sort" msgstr "" -#: src/editor/editcmd.c:3108 +#: src/editor/editcmd.c:3083 msgid "Enter sort options (see manpage) separated by whitespace:" msgstr "" -#: src/editor/editcmd.c:3129 src/editor/editcmd.c:3136 +#: src/editor/editcmd.c:3104 src/editor/editcmd.c:3111 msgid "Sort" msgstr "" -#: src/editor/editcmd.c:3129 +#: src/editor/editcmd.c:3104 msgid "Cannot execute sort command" msgstr "" -#: src/editor/editcmd.c:3135 +#: src/editor/editcmd.c:3110 #, c-format msgid "Sort returned non-zero: %s" msgstr "" -#: src/editor/editcmd.c:3170 +#: src/editor/editcmd.c:3145 msgid "Paste output of external command" msgstr "" -#: src/editor/editcmd.c:3171 +#: src/editor/editcmd.c:3146 msgid "Enter shell command(s):" msgstr "" -#: src/editor/editcmd.c:3188 +#: src/editor/editcmd.c:3163 msgid "External command" msgstr "" -#: src/editor/editcmd.c:3188 +#: src/editor/editcmd.c:3163 msgid "Cannot execute command" msgstr "" -#: src/editor/editcmd.c:3239 +#: src/editor/editcmd.c:3214 msgid "mail -s -c " msgstr "" -#: src/editor/editcmd.c:3240 +#: src/editor/editcmd.c:3215 msgid "To" msgstr "" -#: src/editor/editcmd.c:3243 +#: src/editor/editcmd.c:3218 msgid "Subject" msgstr "" -#: src/editor/editcmd.c:3246 +#: src/editor/editcmd.c:3221 msgid "Copies to" msgstr "" -#: src/editor/editcmd.c:3256 +#: src/editor/editcmd.c:3231 msgid "Mail" msgstr "" -#: src/editor/editcmd.c:3363 +#: src/editor/editcmd.c:3338 msgid "Insert literal" msgstr "" -#: src/editor/editcmd.c:3364 +#: src/editor/editcmd.c:3339 msgid "Press any key:" msgstr "" -#: src/editor/editcmd.c:3401 src/editor/editcmd.c:3430 +#: src/editor/editcmd.c:3376 src/editor/editcmd.c:3405 msgid "" "Current text was modified without a file save.\n" "Continue discards these changes" @@ -1534,14 +1535,14 @@ msgstr "" msgid "&Replace" msgstr "" -#: src/editor/editcmd_dialogs.c:276 src/filemanager/file.c:692 +#: src/editor/editcmd_dialogs.c:276 src/filemanager/file.c:693 #: src/filemanager/filegui.c:440 msgid "A&ll" msgstr "" #: src/editor/editcmd_dialogs.c:277 src/editor/spell_dialogs.c:97 -#: src/filemanager/file.c:607 src/filemanager/file.c:648 -#: src/filemanager/file.c:2495 src/filemanager/filegui.c:272 +#: src/filemanager/file.c:608 src/filemanager/file.c:649 +#: src/filemanager/file.c:2497 src/filemanager/filegui.c:272 msgid "&Skip" msgstr "" @@ -1559,7 +1560,7 @@ msgid "" "Continue discards these changes." msgstr "" -#: src/editor/editdraw.c:263 src/editor/editwidget.c:339 +#: src/editor/editdraw.c:265 src/editor/editwidget.c:339 msgid "NoName" msgstr "" @@ -1635,7 +1636,7 @@ msgstr "" msgid "Mo&ve" msgstr "" -#: src/editor/editmenu.c:112 src/filemanager/file.c:1952 +#: src/editor/editmenu.c:112 src/filemanager/file.c:1954 #: src/filemanager/midnight.c:257 msgid "&Delete" msgstr "" @@ -1967,28 +1968,28 @@ msgstr "" msgid "Edit: " msgstr "" -#: src/editor/editwidget.c:977 +#: src/editor/editwidget.c:979 msgid "ButtonBar|Mark" msgstr "" -#: src/editor/editwidget.c:978 +#: src/editor/editwidget.c:980 msgid "ButtonBar|Replac" msgstr "" -#: src/editor/editwidget.c:979 src/filemanager/midnight.c:1622 +#: src/editor/editwidget.c:981 src/filemanager/midnight.c:1622 #: src/filemanager/tree.c:1209 msgid "ButtonBar|Copy" msgstr "" -#: src/editor/editwidget.c:980 +#: src/editor/editwidget.c:982 msgid "ButtonBar|Move" msgstr "" -#: src/editor/editwidget.c:982 src/filemanager/midnight.c:1625 +#: src/editor/editwidget.c:984 src/filemanager/midnight.c:1625 msgid "ButtonBar|Delete" msgstr "" -#: src/editor/editwidget.c:983 src/filemanager/midnight.c:1626 +#: src/editor/editwidget.c:985 src/filemanager/midnight.c:1626 msgid "ButtonBar|PullDn" msgstr "" @@ -2016,18 +2017,18 @@ msgstr "" msgid "Select language" msgstr "" -#: src/editor/syntax.c:1499 src/editor/syntax.c:1505 +#: src/editor/syntax.c:1501 src/editor/syntax.c:1507 msgid "Load syntax file" msgstr "" -#: src/editor/syntax.c:1500 src/filemanager/usermenu.c:941 src/help.c:1087 +#: src/editor/syntax.c:1502 src/filemanager/usermenu.c:941 src/help.c:1087 #, c-format msgid "" "Cannot open file %s\n" "%s" msgstr "" -#: src/editor/syntax.c:1506 +#: src/editor/syntax.c:1508 #, c-format msgid "Error in file %s on line %d" msgstr "" @@ -2640,7 +2641,7 @@ msgstr "" msgid "Files tagged, want to cd?" msgstr "" -#: src/filemanager/cmd.c:150 src/filemanager/cmd.c:1258 +#: src/filemanager/cmd.c:150 src/filemanager/cmd.c:1262 #: src/filemanager/panel.c:2574 src/filemanager/panel.c:3158 msgid "Cannot change directory" msgstr "" @@ -2666,179 +2667,179 @@ msgstr "" msgid "&Case sensitive" msgstr "" -#: src/filemanager/cmd.c:436 +#: src/filemanager/cmd.c:438 #, c-format msgid "Link %s to:" msgstr "" -#: src/filemanager/cmd.c:438 +#: src/filemanager/cmd.c:440 msgid "Link" msgstr "" -#: src/filemanager/cmd.c:444 +#: src/filemanager/cmd.c:446 #, c-format msgid "link: %s" msgstr "" -#: src/filemanager/cmd.c:481 +#: src/filemanager/cmd.c:483 #, c-format msgid "symlink: %s" msgstr "" -#: src/filemanager/cmd.c:538 src/filemanager/panel.c:4543 +#: src/filemanager/cmd.c:540 src/filemanager/panel.c:4543 #, c-format msgid "Cannot chdir to \"%s\"" msgstr "" -#: src/filemanager/cmd.c:733 +#: src/filemanager/cmd.c:735 msgid "View file" msgstr "" -#: src/filemanager/cmd.c:733 +#: src/filemanager/cmd.c:735 msgid "Filename:" msgstr "" -#: src/filemanager/cmd.c:767 +#: src/filemanager/cmd.c:769 msgid "Filtered view" msgstr "" -#: src/filemanager/cmd.c:768 +#: src/filemanager/cmd.c:770 msgid "Filter command and arguments:" msgstr "" -#: src/filemanager/cmd.c:856 +#: src/filemanager/cmd.c:860 msgid "Edit file" msgstr "" -#: src/filemanager/cmd.c:944 +#: src/filemanager/cmd.c:948 msgid "Create a new Directory" msgstr "" -#: src/filemanager/cmd.c:945 +#: src/filemanager/cmd.c:949 msgid "Enter directory name:" msgstr "" -#: src/filemanager/cmd.c:1070 +#: src/filemanager/cmd.c:1074 msgid "Select" msgstr "" -#: src/filemanager/cmd.c:1078 +#: src/filemanager/cmd.c:1082 msgid "Unselect" msgstr "" -#: src/filemanager/cmd.c:1093 +#: src/filemanager/cmd.c:1097 msgid "Extension file edit" msgstr "" -#: src/filemanager/cmd.c:1094 +#: src/filemanager/cmd.c:1098 msgid "Which extension file you want to edit?" msgstr "" -#: src/filemanager/cmd.c:1095 src/filemanager/cmd.c:1131 -#: src/filemanager/cmd.c:1189 +#: src/filemanager/cmd.c:1099 src/filemanager/cmd.c:1135 +#: src/filemanager/cmd.c:1193 msgid "&System Wide" msgstr "" -#: src/filemanager/cmd.c:1187 +#: src/filemanager/cmd.c:1191 msgid "Highlighting groups file edit" msgstr "" -#: src/filemanager/cmd.c:1188 +#: src/filemanager/cmd.c:1192 msgid "Which highlighting file you want to edit?" msgstr "" -#: src/filemanager/cmd.c:1273 +#: src/filemanager/cmd.c:1277 msgid "Compare directories" msgstr "" -#: src/filemanager/cmd.c:1274 +#: src/filemanager/cmd.c:1278 msgid "Select compare method:" msgstr "" -#: src/filemanager/cmd.c:1275 +#: src/filemanager/cmd.c:1279 msgid "&Quick" msgstr "" -#: src/filemanager/cmd.c:1275 +#: src/filemanager/cmd.c:1279 msgid "&Size only" msgstr "" -#: src/filemanager/cmd.c:1275 +#: src/filemanager/cmd.c:1279 msgid "&Thorough" msgstr "" -#: src/filemanager/cmd.c:1290 +#: src/filemanager/cmd.c:1294 msgid "" "Both panels should be in the listing mode\n" "to use this command" msgstr "" -#: src/filemanager/cmd.c:1338 +#: src/filemanager/cmd.c:1342 msgid "" "Not an xterm or Linux console;\n" "the panels cannot be toggled." msgstr "" -#: src/filemanager/cmd.c:1374 +#: src/filemanager/cmd.c:1378 #, c-format msgid "Symlink '%s' points to:" msgstr "" -#: src/filemanager/cmd.c:1381 +#: src/filemanager/cmd.c:1385 msgid "Edit symlink" msgstr "" -#: src/filemanager/cmd.c:1390 +#: src/filemanager/cmd.c:1394 #, c-format msgid "edit symlink, unable to remove %s: %s" msgstr "" -#: src/filemanager/cmd.c:1399 +#: src/filemanager/cmd.c:1403 #, c-format msgid "edit symlink: %s" msgstr "" -#: src/filemanager/cmd.c:1414 +#: src/filemanager/cmd.c:1418 #, c-format msgid "'%s' is not a symbolic link" msgstr "" -#: src/filemanager/cmd.c:1519 +#: src/filemanager/cmd.c:1523 msgid "FTP to machine" msgstr "" -#: src/filemanager/cmd.c:1530 +#: src/filemanager/cmd.c:1534 msgid "SFTP to machine" msgstr "" -#: src/filemanager/cmd.c:1542 +#: src/filemanager/cmd.c:1546 msgid "Shell link to machine" msgstr "" -#: src/filemanager/cmd.c:1554 +#: src/filemanager/cmd.c:1558 msgid "SMB link to machine" msgstr "" -#: src/filemanager/cmd.c:1565 +#: src/filemanager/cmd.c:1569 msgid "Undelete files on an ext2 file system" msgstr "" -#: src/filemanager/cmd.c:1566 +#: src/filemanager/cmd.c:1570 msgid "" "Enter device (without /dev/) to undelete\n" "files on: (F1 for details)" msgstr "" -#: src/filemanager/cmd.c:1709 src/filemanager/cmd.c:1711 +#: src/filemanager/cmd.c:1713 src/filemanager/cmd.c:1715 msgid "Setup" msgstr "" -#: src/filemanager/cmd.c:1709 +#: src/filemanager/cmd.c:1713 #, c-format msgid "Setup saved to %s" msgstr "" -#: src/filemanager/cmd.c:1711 +#: src/filemanager/cmd.c:1715 #, c-format msgid "Unable to save setup to %s" msgstr "" @@ -2855,7 +2856,7 @@ msgid "" "%s" msgstr "" -#: src/filemanager/dir.c:572 src/filemanager/dir.c:651 +#: src/filemanager/dir.c:572 src/filemanager/dir.c:652 msgid "Cannot read directory contents" msgstr "" @@ -2895,123 +2896,123 @@ msgid "" "to copy it from %smc.ext or use that file as an example of how to write it." msgstr "" -#: src/filemanager/file.c:97 src/filemanager/file.c:1950 +#: src/filemanager/file.c:98 src/filemanager/file.c:1952 #: src/filemanager/tree.c:766 msgid "DialogTitle|Copy" msgstr "" -#: src/filemanager/file.c:98 src/filemanager/tree.c:804 +#: src/filemanager/file.c:99 src/filemanager/tree.c:804 msgid "DialogTitle|Move" msgstr "" -#: src/filemanager/file.c:99 src/filemanager/hotlist.c:1114 +#: src/filemanager/file.c:100 src/filemanager/hotlist.c:1114 #: src/filemanager/hotlist.c:1131 src/filemanager/tree.c:873 msgid "DialogTitle|Delete" msgstr "" -#: src/filemanager/file.c:142 +#: src/filemanager/file.c:143 msgid "FileOperation|Copy" msgstr "" -#: src/filemanager/file.c:143 +#: src/filemanager/file.c:144 msgid "FileOperation|Move" msgstr "" -#: src/filemanager/file.c:144 +#: src/filemanager/file.c:145 msgid "FileOperation|Delete" msgstr "" -#: src/filemanager/file.c:157 +#: src/filemanager/file.c:158 #, no-c-format msgid "%o %f \"%s\"%m" msgstr "" -#: src/filemanager/file.c:159 +#: src/filemanager/file.c:160 #, no-c-format msgid "%o %d %f%m" msgstr "" -#: src/filemanager/file.c:162 +#: src/filemanager/file.c:163 msgid "file" msgstr "" -#: src/filemanager/file.c:163 +#: src/filemanager/file.c:164 msgid "files" msgstr "" -#: src/filemanager/file.c:164 +#: src/filemanager/file.c:165 msgid "directory" msgstr "" -#: src/filemanager/file.c:165 +#: src/filemanager/file.c:166 msgid "directories" msgstr "" -#: src/filemanager/file.c:166 +#: src/filemanager/file.c:167 msgid "files/directories" msgstr "" #. TRANSLATORS: keep leading space here to split words in Copy/Move dialog -#: src/filemanager/file.c:168 +#: src/filemanager/file.c:169 msgid " with source mask:" msgstr "" -#: src/filemanager/file.c:169 src/filemanager/filegui.c:1196 +#: src/filemanager/file.c:170 src/filemanager/filegui.c:1196 msgid "to:" msgstr "" -#: src/filemanager/file.c:172 +#: src/filemanager/file.c:173 #, c-format msgid "%s?" msgstr "" -#: src/filemanager/file.c:329 +#: src/filemanager/file.c:330 msgid "Cannot make the hardlink" msgstr "" -#: src/filemanager/file.c:381 +#: src/filemanager/file.c:382 #, c-format msgid "" "Cannot read source link \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:397 +#: src/filemanager/file.c:398 msgid "" "Cannot make stable symlinks acrossnon-local filesystems:\n" "\n" "Option Stable Symlinks will be disabled" msgstr "" -#: src/filemanager/file.c:469 +#: src/filemanager/file.c:470 #, c-format msgid "" "Cannot create target symlink \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:607 src/filemanager/file.c:648 -#: src/filemanager/file.c:692 src/filemanager/file.c:2494 +#: src/filemanager/file.c:608 src/filemanager/file.c:649 +#: src/filemanager/file.c:693 src/filemanager/file.c:2496 #: src/filemanager/filegui.c:275 src/filemanager/filegui.c:448 msgid "&Abort" msgstr "" -#: src/filemanager/file.c:648 +#: src/filemanager/file.c:649 msgid "Ski&p all" msgstr "" -#: src/filemanager/file.c:648 src/viewer/hex.c:389 +#: src/filemanager/file.c:649 src/viewer/hex.c:389 msgid "&Retry" msgstr "" -#: src/filemanager/file.c:683 +#: src/filemanager/file.c:684 #, c-format msgid "" "Directory \"%s\" not empty.\n" "Delete it recursively?" msgstr "" -#: src/filemanager/file.c:684 +#: src/filemanager/file.c:685 #, c-format msgid "" "Background process:\n" @@ -3019,18 +3020,18 @@ msgid "" "Delete it recursively?" msgstr "" -#: src/filemanager/file.c:692 src/filemanager/filegui.c:444 +#: src/filemanager/file.c:693 src/filemanager/filegui.c:444 msgid "Non&e" msgstr "" -#: src/filemanager/file.c:908 +#: src/filemanager/file.c:909 #, c-format msgid "" "Cannot stat file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:921 src/filemanager/file.c:1570 +#: src/filemanager/file.c:922 src/filemanager/file.c:1571 #, c-format msgid "" "\"%s\"\n" @@ -3039,176 +3040,176 @@ msgid "" "are the same file" msgstr "" -#: src/filemanager/file.c:927 +#: src/filemanager/file.c:928 #, c-format msgid "Cannot overwrite directory \"%s\"" msgstr "" -#: src/filemanager/file.c:972 +#: src/filemanager/file.c:973 #, c-format msgid "" "Cannot move file \"%s\" to \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1004 +#: src/filemanager/file.c:1005 #, c-format msgid "" "Cannot remove file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1048 +#: src/filemanager/file.c:1049 #, c-format msgid "" "Cannot delete file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1131 src/filemanager/file.c:1200 -#: src/filemanager/file.c:2476 +#: src/filemanager/file.c:1132 src/filemanager/file.c:1201 +#: src/filemanager/file.c:2478 #, c-format msgid "" "Cannot remove directory \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1537 src/filemanager/file.c:2359 +#: src/filemanager/file.c:1538 src/filemanager/file.c:2361 #, c-format msgid "" "Cannot overwrite directory \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1556 +#: src/filemanager/file.c:1557 #, c-format msgid "" "Cannot stat source file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1607 +#: src/filemanager/file.c:1608 #, c-format msgid "" "Cannot create special file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1619 src/filemanager/file.c:1963 +#: src/filemanager/file.c:1620 src/filemanager/file.c:1965 #, c-format msgid "" "Cannot chown target file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1634 src/filemanager/file.c:1983 +#: src/filemanager/file.c:1635 src/filemanager/file.c:1985 #, c-format msgid "" "Cannot chmod target file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1655 +#: src/filemanager/file.c:1656 #, c-format msgid "" "Cannot open source file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1670 +#: src/filemanager/file.c:1671 msgid "Reget failed, about to overwrite file" msgstr "" -#: src/filemanager/file.c:1682 +#: src/filemanager/file.c:1683 #, c-format msgid "" "Cannot fstat source file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1720 +#: src/filemanager/file.c:1721 #, c-format msgid "" "Cannot create target file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1742 +#: src/filemanager/file.c:1743 #, c-format msgid "" "Cannot fstat target file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1762 +#: src/filemanager/file.c:1763 #, c-format msgid "" "Cannot preallocate space for target file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1806 +#: src/filemanager/file.c:1807 #, c-format msgid "" "Cannot read source file\"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1847 +#: src/filemanager/file.c:1848 #, c-format msgid "" "Cannot write target file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1886 +#: src/filemanager/file.c:1887 msgid "(stalled)" msgstr "" -#: src/filemanager/file.c:1921 +#: src/filemanager/file.c:1923 #, c-format msgid "" "Cannot close source file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1933 +#: src/filemanager/file.c:1935 #, c-format msgid "" "Cannot close target file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:1951 +#: src/filemanager/file.c:1953 msgid "Incomplete file was retrieved. Keep it?" msgstr "" -#: src/filemanager/file.c:1952 +#: src/filemanager/file.c:1954 msgid "&Keep" msgstr "" -#: src/filemanager/file.c:2050 +#: src/filemanager/file.c:2052 #, c-format msgid "" "Cannot stat source directory \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:2084 +#: src/filemanager/file.c:2086 #, c-format msgid "" "Source \"%s\" is not a directory\n" "%s" msgstr "" -#: src/filemanager/file.c:2096 +#: src/filemanager/file.c:2098 #, c-format msgid "" "Cannot copy cyclic symbolic link\n" "\"%s\"" msgstr "" -#: src/filemanager/file.c:2138 src/filemanager/file.c:2965 +#: src/filemanager/file.c:2140 src/filemanager/file.c:2967 #: src/filemanager/tree.c:819 #, c-format msgid "" @@ -3216,21 +3217,21 @@ msgid "" "%s" msgstr "" -#: src/filemanager/file.c:2167 +#: src/filemanager/file.c:2169 #, c-format msgid "" "Cannot create target directory \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:2192 +#: src/filemanager/file.c:2194 #, c-format msgid "" "Cannot chown target directory \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:2326 +#: src/filemanager/file.c:2328 #, c-format msgid "" "\"%s\"\n" @@ -3239,36 +3240,36 @@ msgid "" "are the same directory" msgstr "" -#: src/filemanager/file.c:2361 +#: src/filemanager/file.c:2363 #, c-format msgid "" "Cannot overwrite file \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:2384 +#: src/filemanager/file.c:2386 #, c-format msgid "" "Cannot move directory \"%s\" to \"%s\"\n" "%s" msgstr "" -#: src/filemanager/file.c:2515 +#: src/filemanager/file.c:2517 msgid "Directory scanning" msgstr "" -#: src/filemanager/file.c:2568 +#: src/filemanager/file.c:2570 #, c-format msgid "" "%s\n" "Directories: %zd, total size: %s" msgstr "" -#: src/filemanager/file.c:2678 +#: src/filemanager/file.c:2680 msgid "Cannot operate on \"..\"!" msgstr "" -#: src/filemanager/file.c:2806 +#: src/filemanager/file.c:2808 msgid "Sorry, I could not put the job in background" msgstr "" @@ -3436,7 +3437,7 @@ msgstr "" msgid "&Again" msgstr "" -#: src/filemanager/find.c:194 src/filemanager/panelize.c:140 +#: src/filemanager/find.c:194 src/filemanager/panelize.c:141 msgid "Pane&lize" msgstr "" @@ -3521,7 +3522,7 @@ msgid_plural "Finished (ignored %zd directories)" msgstr[0] "" msgstr[1] "" -#: src/filemanager/find.c:1289 src/viewer/search.c:253 +#: src/filemanager/find.c:1289 src/viewer/search.c:244 #, c-format msgid "Searching %s" msgstr "" @@ -3563,7 +3564,7 @@ msgstr "" msgid "&Insert" msgstr "" -#: src/filemanager/hotlist.c:202 src/filemanager/panelize.c:141 +#: src/filemanager/hotlist.c:202 src/filemanager/panelize.c:142 msgid "&Remove" msgstr "" @@ -4251,56 +4252,56 @@ msgstr "" msgid "User supplied format looks invalid, reverting to default." msgstr "" -#: src/filemanager/panelize.c:142 +#: src/filemanager/panelize.c:143 msgid "&Add new" msgstr "" -#: src/filemanager/panelize.c:174 src/filemanager/panelize.c:394 +#: src/filemanager/panelize.c:175 src/filemanager/panelize.c:395 msgid "External panelize" msgstr "" -#: src/filemanager/panelize.c:183 src/filemanager/panelize.c:285 -#: src/filemanager/panelize.c:593 src/filemanager/panelize.c:640 +#: src/filemanager/panelize.c:184 src/filemanager/panelize.c:286 +#: src/filemanager/panelize.c:595 src/filemanager/panelize.c:642 msgid "Other command" msgstr "" -#: src/filemanager/panelize.c:187 +#: src/filemanager/panelize.c:188 msgid "Command" msgstr "" -#: src/filemanager/panelize.c:265 +#: src/filemanager/panelize.c:266 msgid "Add to external panelize" msgstr "" -#: src/filemanager/panelize.c:266 +#: src/filemanager/panelize.c:267 msgid "Enter command label:" msgstr "" -#: src/filemanager/panelize.c:325 +#: src/filemanager/panelize.c:326 msgid "Cannot invoke command." msgstr "" -#: src/filemanager/panelize.c:394 +#: src/filemanager/panelize.c:395 msgid "Pipe close failed" msgstr "" -#: src/filemanager/panelize.c:533 +#: src/filemanager/panelize.c:535 msgid "Cannot run external panelize in a non-local directory" msgstr "" -#: src/filemanager/panelize.c:597 +#: src/filemanager/panelize.c:599 msgid "Modified git files" msgstr "" -#: src/filemanager/panelize.c:598 +#: src/filemanager/panelize.c:600 msgid "Find rejects after patching" msgstr "" -#: src/filemanager/panelize.c:600 +#: src/filemanager/panelize.c:602 msgid "Find *.orig after patching" msgstr "" -#: src/filemanager/panelize.c:602 +#: src/filemanager/panelize.c:604 msgid "Find SUID and SGID programs" msgstr "" @@ -4539,7 +4540,7 @@ msgstr "" msgid "%b %e %H:%M" msgstr "" -#: src/setup.c:1194 +#: src/setup.c:1195 #, c-format msgid "" "Cannot save file %s:\n" @@ -4950,16 +4951,16 @@ msgid "" "%s\n" msgstr "" -#: src/vfs/sftpfs/config_parcer.c:222 +#: src/vfs/sftpfs/config_parcer.c:225 #, c-format msgid "sftp: an error occurred while reading %s: %s" msgstr "" -#: src/vfs/sftpfs/config_parcer.c:321 +#: src/vfs/sftpfs/config_parcer.c:324 msgid "sftp: Unable to get current user name." msgstr "" -#: src/vfs/sftpfs/connection.c:76 src/vfs/sftpfs/vfs_subclass.c:109 +#: src/vfs/sftpfs/connection.c:76 src/vfs/sftpfs/vfs_subclass.c:100 msgid "sftp: Invalid host name." msgstr "" @@ -5168,19 +5169,19 @@ msgstr "" msgid "Ext2lib error" msgstr "" -#: src/viewer/actions_cmd.c:399 +#: src/viewer/actions_cmd.c:420 msgid "Invalid value" msgstr "" -#: src/viewer/actions_cmd.c:595 +#: src/viewer/actions_cmd.c:616 msgid "File was modified. Save with exit?" msgstr "" -#: src/viewer/actions_cmd.c:596 +#: src/viewer/actions_cmd.c:617 msgid "&Cancel quit" msgstr "" -#: src/viewer/actions_cmd.c:601 +#: src/viewer/actions_cmd.c:622 msgid "" "Midnight Commander is being shut down.\n" "Save modified file?" @@ -5291,15 +5292,15 @@ msgid "" "%s" msgstr "" -#: src/viewer/search.c:150 +#: src/viewer/search.c:142 msgid "Seeking to search result" msgstr "" -#: src/viewer/search.c:332 +#: src/viewer/search.c:323 msgid "Search done" msgstr "" -#: src/viewer/search.c:332 +#: src/viewer/search.c:323 msgid "Continue from beginning?" msgstr "" diff --git a/po/mn.po b/po/mn.po index 7abb03ee6..3156cfa70 100644 --- a/po/mn.po +++ b/po/mn.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: LANGUAGE \n" @@ -859,7 +859,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/nb.po b/po/nb.po index baf651e19..6f56a2b17 100644 --- a/po/nb.po +++ b/po/nb.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: LANGUAGE \n" @@ -859,7 +859,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/nl.po b/po/nl.po index aa3de36ae..79c3ee8eb 100644 --- a/po/nl.po +++ b/po/nl.po @@ -13,7 +13,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-31 16:08+0000\n" "Last-Translator: Richard E. van der Luit \n" "Language-Team: Dutch (http://www.transifex.com/projects/p/mc/language/nl/)\n" @@ -920,8 +920,10 @@ msgstr "Kan geen grootte-/rechteninformatie verkrijgen voor %s" msgid "\"%s\" is not a regular file" msgstr "\"%s\" is geen normaal bestand" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Bestand \"%s\" is te groot" #, c-format diff --git a/po/pl.po b/po/pl.po index c312d1d53..852c186a5 100644 --- a/po/pl.po +++ b/po/pl.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 18:27+0000\n" "Last-Translator: Piotr Drąg \n" "Language-Team: Polish (http://www.transifex.com/projects/p/mc/language/pl/)\n" @@ -925,8 +925,10 @@ msgstr "Nie można uzyskać rozmiaru/uprawnień dla %s" msgid "\"%s\" is not a regular file" msgstr "\"%s\" nie jest zwykłym plikiem" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Plik \"%s\" jest za duży" #, c-format diff --git a/po/pt.po b/po/pt.po index 2aa2266e6..66ddfbf65 100644 --- a/po/pt.po +++ b/po/pt.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Gilberto J \n" "Language-Team: Portuguese (http://www.transifex.com/projects/p/mc/language/" @@ -925,8 +925,10 @@ msgstr "Não é possível obter tamanho/permissões para %s" msgid "\"%s\" is not a regular file" msgstr "\"%s\" não é um ficheiro regular" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Ficheiro \"%s\" é demasiado grande" #, c-format diff --git a/po/pt_BR.po b/po/pt_BR.po index ac3b1fb9a..08dba5ccb 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Enrico Nicoletto \n" "Language-Team: Portuguese (Brazil) (http://www.transifex.com/projects/p/mc/" @@ -883,8 +883,10 @@ msgstr "Não foi possível obter tamanho/permissões para %s" msgid "\"%s\" is not a regular file" msgstr "\"%s\" não é um arquivo regular" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Arquivo \"%s\" é muito grande" #, c-format diff --git a/po/ro.po b/po/ro.po index 03dfbcc4d..5f4584c5a 100644 --- a/po/ro.po +++ b/po/ro.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Romanian (http://www.transifex.com/projects/p/mc/language/" @@ -861,7 +861,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/ru.po b/po/ru.po index c842c107e..65568517b 100644 --- a/po/ru.po +++ b/po/ru.po @@ -18,17 +18,15 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" -"PO-Revision-Date: 2013-06-16 08:43+0000\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" +"PO-Revision-Date: 2013-07-05 09:15+0300\n" "Last-Translator: Andrew Borodin \n" -"Language-Team: Russian (http://www.transifex.com/projects/p/mc/language/" -"ru/)\n" +"Language-Team: Russian (http://www.transifex.com/projects/p/mc/language/ru/)\n" "Language: ru\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" -"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" msgid "Warning: cannot load codepages list" msgstr "Внимание: невозможно загрузить список кодировок" @@ -117,8 +115,7 @@ msgid "Not implemented yet" msgstr "Пока не реализовано" msgid "Num of replace tokens not equal to num of found tokens" -msgstr "" -"Количество шаблонных полей не соответствует количеству полей для замены" +msgstr "Количество шаблонных полей не соответствует количеству полей для замены" #, c-format msgid "Invalid token number %d" @@ -616,8 +613,7 @@ msgid "Load definitions of key bindings from specified file" msgstr "Чтение определений привязок клавиш из указанного файла" msgid "Don't load definitions of key bindings from file, use defaults" -msgstr "" -"Не загружать привязки клавиш из файла, использовать привязки по умолчанию" +msgstr "Не загружать привязки клавиш из файла, использовать привязки по умолчанию" msgid "Requests to run in black and white" msgstr "Принудительно установить черно-белый режим" @@ -654,26 +650,22 @@ msgid "" msgstr "" "--colors КЛЮЧЕВОЕ_СЛОВО={ТЕКСТ},{ФОН},{АТРИБУТ}:КЛЮЧЕВОЕ_СЛОВО2=...\n" "\n" -"{ТЕКСТ}, {ФОН} и {АТРИБУТ} можно опустить, чтобы использовать значения по " -"умолчанию\n" +"{ТЕКСТ}, {ФОН} и {АТРИБУТ} можно опустить, чтобы использовать значения по умолчанию\n" "\n" "Ключевые слова:\n" " Общие: errors, disabled, reverse, gauge, header\n" " input, inputmark, inputunchanged, commandlinemark\n" " bbarhotkey, bbarbutton, statusbar\n" " Отображение файлов: normal, selected, marked, markselect\n" -" Диалоги: dnormal, dfocus, dhotnormal, dhotfocus, " -"errdhotnormal,\n" +" Диалоги: dnormal, dfocus, dhotnormal, dhotfocus, errdhotnormal,\n" " errdhotfocus\n" -" Меню: menunormal, menuhot, menusel, menuhotsel, " -"menuinactive\n" +" Меню: menunormal, menuhot, menusel, menuhotsel, menuinactive\n" " Всплывающие меню: pmenunormal, pmenusel, pmenutitle\n" " Редактор: editnormal, editbold, editmarked, editwhitespace,\n" " editlinestate, editbg, editframe, editframeactive\n" " editframedrag\n" " Просмотрщик: viewbold, viewunderline, viewselected\n" -" Справка: helpnormal, helpitalic, helpbold, helplink, " -"helpslink\n" +" Справка: helpnormal, helpitalic, helpbold, helplink, helpslink\n" #. TRANSLATORS: don't translate color names and attributes msgid "" @@ -697,8 +689,7 @@ msgstr "" " от color16 до color255 или от rgb000 до rgb555 и от gray0 до gray23\n" "\n" "Атрибуты:\n" -" bold, underline, reverse, blink; несколько атрибутов объединяются знаком " -"\"+\"\n" +" bold, underline, reverse, blink; несколько атрибутов объединяются знаком \"+\"\n" msgid "Color options" msgstr "Цветовые настройки" @@ -938,8 +929,12 @@ msgid "\"%s\" is not a regular file" msgstr "\"%s\" не является обычным файлом" #, c-format -msgid "File \"%s\" is too large" -msgstr "Файл \"%s\" слишком большой" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" +msgstr "" +"Файл \"%s\" слишком большой.\n" +"Всё равно открыть?" #, c-format msgid "Error reading from pipe: %s" @@ -2244,25 +2239,16 @@ msgid " %s%s file error" msgstr "ошибка файла %s%s" #, c-format -msgid "" -"The format of the %smc.ext file has changed with version 3.0. It seems that " -"the installation failed. Please fetch a fresh copy from the Midnight " -"Commander package." -msgstr "" -"Формат %smc.ext изменён с версии 3.0. Возможно, произошёл сбой при " -"установке. Пожалуйста, возьмите свежую копию из пакета Midnight Commander." +msgid "The format of the %smc.ext file has changed with version 3.0. It seems that the installation failed. Please fetch a fresh copy from the Midnight Commander package." +msgstr "Формат %smc.ext изменён с версии 3.0. Возможно, произошёл сбой при установке. Пожалуйста, возьмите свежую копию из пакета Midnight Commander." #, c-format msgid "%s file error" msgstr "ошибка файла %s" #, c-format -msgid "" -"The format of the %s file has changed with version 3.0. You may either want " -"to copy it from %smc.ext or use that file as an example of how to write it." -msgstr "" -"Формат файла %s изменён с версии 3.0. Вы можете либо скопировать его с %s/mc." -"ext, либо использовать этот файл как пример и написать свой." +msgid "The format of the %s file has changed with version 3.0. You may either want to copy it from %smc.ext or use that file as an example of how to write it." +msgstr "Формат файла %s изменён с версии 3.0. Вы можете либо скопировать его с %s/mc.ext, либо использовать этот файл как пример и написать свой." msgid "DialogTitle|Copy" msgstr "Копирование" @@ -2332,8 +2318,7 @@ msgid "" "\n" "Option Stable Symlinks will be disabled" msgstr "" -"Невозможно создать устойчивые симв. ссылки через нелокальные файловые " -"системы:\n" +"Невозможно создать устойчивые симв. ссылки через нелокальные файловые системы:\n" "\n" "Опция \"Устойчивые символические ссылки\" будет отменена" @@ -4289,12 +4274,12 @@ msgstr "" msgid "Cannot view: not a regular file" msgstr "Просмотр невозможен: необычный файл" -#, fuzzy, c-format +#, c-format msgid "" "Cannot open \"%s\" in parse mode\n" "%s" msgstr "" -"Невозможно открыть \"%s\"\n" +"Невозможно открыть \"%s\" в режиме фильтра\n" "%s" msgid "Seeking to search result" @@ -4308,3 +4293,4 @@ msgstr "Продолжить с начала?" msgid "Cannot fetch a local copy of /ftp://some.host/editme.txt" msgstr "Невозможно получить локальную копию /ftp://some.host/editme.txt" + diff --git a/po/sk.po b/po/sk.po index cf517e9c8..fc5c15e47 100644 --- a/po/sk.po +++ b/po/sk.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Jose Riha \n" "Language-Team: Slovak (http://www.transifex.com/projects/p/mc/language/sk/)\n" @@ -870,7 +870,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/sl.po b/po/sl.po index 58954d4ca..6f03633f4 100644 --- a/po/sl.po +++ b/po/sl.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Slovenian (http://www.transifex.com/projects/p/mc/language/" @@ -870,7 +870,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/sr.po b/po/sr.po index c84733e6b..c90d3ecad 100644 --- a/po/sr.po +++ b/po/sr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Serbian (http://www.transifex.com/projects/p/mc/language/" @@ -861,7 +861,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/sv.po b/po/sv.po index 47d2c97b2..750f7b625 100644 --- a/po/sv.po +++ b/po/sv.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Cybjit \n" "Language-Team: Swedish (http://www.transifex.com/projects/p/mc/language/" @@ -861,7 +861,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/sv_SE.po b/po/sv_SE.po index d19cc58cb..631498497 100644 --- a/po/sv_SE.po +++ b/po/sv_SE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2011-12-07 11:21+0000\n" "Last-Translator: slavazanko \n" "Language-Team: Swedish (Sweden) (http://www.transifex.net/projects/p/mc/team/" @@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/ta.po b/po/ta.po index 32511898e..ea99631fc 100644 --- a/po/ta.po +++ b/po/ta.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: LANGUAGE \n" @@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/tr.po b/po/tr.po index 1814cbfb7..eece74adb 100644 --- a/po/tr.po +++ b/po/tr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Turkish (http://www.transifex.com/projects/p/mc/language/" @@ -860,7 +860,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/uk.po b/po/uk.po index 4e11a941f..f05a90c87 100644 --- a/po/uk.po +++ b/po/uk.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: peinguin \n" "Language-Team: Ukrainian (http://www.transifex.com/projects/p/mc/language/" @@ -924,8 +924,10 @@ msgstr "Не вдалося отримати розмір/права досту msgid "\"%s\" is not a regular file" msgstr "«%s» не є звичайним файлом" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "Файл «%s» завеликий" #, c-format diff --git a/po/vi.po b/po/vi.po index 2db576a5a..633e63475 100644 --- a/po/vi.po +++ b/po/vi.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: LANGUAGE \n" @@ -859,7 +859,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/wa.po b/po/wa.po index 3c99a1891..dac1a6565 100644 --- a/po/wa.po +++ b/po/wa.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: LANGUAGE \n" @@ -857,7 +857,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format diff --git a/po/zh_CN.po b/po/zh_CN.po index 87d15bf18..c482b49b7 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: Chinese (China) (http://www.transifex.com/projects/p/mc/" @@ -902,8 +902,10 @@ msgstr "无法获取文件%s的大小和权限信息" msgid "\"%s\" is not a regular file" msgstr "\"%s\"不是一个常规文件" -#, c-format -msgid "File \"%s\" is too large" +#, fuzzy, c-format +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "文件\"%s\"太大" #, c-format diff --git a/po/zh_TW.po b/po/zh_TW.po index 3a143a01a..20686cc90 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Midnight Commander\n" "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n" -"POT-Creation-Date: 2013-06-27 16:02+0400\n" +"POT-Creation-Date: 2013-07-05 09:13+0400\n" "PO-Revision-Date: 2013-03-13 08:51+0000\n" "Last-Translator: Slava Zanko \n" "Language-Team: LANGUAGE \n" @@ -859,7 +859,9 @@ msgid "\"%s\" is not a regular file" msgstr "" #, c-format -msgid "File \"%s\" is too large" +msgid "" +"File \"%s\" is too large.\n" +"Open it anyway?" msgstr "" #, c-format