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 */