From 8664830831c4de74ef07eed9f716edca19aa00e9 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 11 Oct 2011 13:37:51 +0400 Subject: [PATCH] Editor: reduce scope of some functions. Following fuctions are used in in src/editor/edit.c file only: edit_get_byte_ptr edit_get_buf_ptr edit_get_prev_utf Now they are static. Signed-off-by: Andrew Borodin --- src/editor/edit-impl.h | 3 - src/editor/edit.c | 233 ++++++++++++++++++++++++------------------------- 2 files changed, 115 insertions(+), 121 deletions(-) diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index c8dde8bed..21b0bd6dc 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -202,10 +202,7 @@ void edit_init_menu (struct WMenuBar *menubar); void menu_save_mode_cmd (void); int edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch); int edit_get_byte (WEdit * edit, long byte_index); -char *edit_get_byte_ptr (WEdit * edit, long byte_index); -char *edit_get_buf_ptr (WEdit * edit, long byte_index); int edit_get_utf (WEdit * edit, long byte_index, int *char_width); -int edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width); long edit_count_lines (WEdit * edit, long current, long upto); long edit_move_forward (WEdit * edit, long current, long lines, long upto); long edit_move_forward3 (WEdit * edit, long current, int cols, long upto); diff --git a/src/editor/edit.c b/src/editor/edit.c index e5831f105..0459b19b0 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -669,6 +669,121 @@ edit_modification (WEdit * edit) /* --------------------------------------------------------------------------------------------- */ +static char * +edit_get_byte_ptr (WEdit * edit, long byte_index) +{ + if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) + return NULL; + + if (byte_index >= edit->curs1) + { + unsigned long p; + + p = edit->curs1 + edit->curs2 - byte_index - 1; + return (char *) (edit->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] + + (byte_index & M_EDIT_BUF_SIZE)); +} + +/* --------------------------------------------------------------------------------------------- */ + +static char * +edit_get_buf_ptr (WEdit * edit, long byte_index) +{ + if (byte_index >= (edit->curs1 + edit->curs2)) + byte_index--; + + if (byte_index < 0) + return NULL; + + if (byte_index >= edit->curs1) + { + unsigned long p; + + p = edit->curs1 + edit->curs2 - 1; + return (char *) (edit->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] + (0 & M_EDIT_BUF_SIZE)); +} + +/* --------------------------------------------------------------------------------------------- */ + +static int +edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width) +{ + gchar *str, *buf = NULL; + int res = -1; + gunichar ch; + gchar *next_ch = NULL; + int width = 0; + + if (byte_index > 0) + byte_index--; + + if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) + { + *char_width = 0; + return 0; + } + + ch = edit_get_utf (edit, byte_index, &width); + + if (width == 1) + { + *char_width = width; + return ch; + } + + str = edit_get_byte_ptr (edit, byte_index); + buf = edit_get_buf_ptr (edit, byte_index); + if (str == NULL || buf == NULL) + { + *char_width = 0; + return 0; + } + /* get prev utf8 char */ + if (str != buf) + str = g_utf8_find_prev_char (buf, str); + + if (str == NULL) + { + *char_width = 0; + return 0; + } + else + 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; +} + +/* --------------------------------------------------------------------------------------------- */ + static int edit_backspace (WEdit * edit, const int byte_delete) { @@ -1710,53 +1825,6 @@ edit_get_byte (WEdit * edit, long byte_index) /* --------------------------------------------------------------------------------------------- */ -char * -edit_get_byte_ptr (WEdit * edit, long byte_index) -{ - unsigned long p; - if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) - return NULL; - - if (byte_index >= edit->curs1) - { - p = edit->curs1 + edit->curs2 - byte_index - 1; - return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] + - (EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1)); - } - else - { - return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] + - (byte_index & M_EDIT_BUF_SIZE)); - } -} - -/* --------------------------------------------------------------------------------------------- */ - -char * -edit_get_buf_ptr (WEdit * edit, long byte_index) -{ - unsigned long p; - - if (byte_index >= (edit->curs1 + edit->curs2)) - byte_index--; - - if (byte_index < 0) - return NULL; - - if (byte_index >= edit->curs1) - { - p = edit->curs1 + edit->curs2 - 1; - return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] + - (EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1)); - } - else - { - return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] + (0 & M_EDIT_BUF_SIZE)); - } -} - -/* --------------------------------------------------------------------------------------------- */ - int edit_get_utf (WEdit * edit, long byte_index, int *char_width) { @@ -1808,77 +1876,6 @@ edit_get_utf (WEdit * edit, long byte_index, int *char_width) /* --------------------------------------------------------------------------------------------- */ -int -edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width) -{ - gchar *str, *buf = NULL; - int res = -1; - gunichar ch; - gchar *next_ch = NULL; - int width = 0; - - if (byte_index > 0) - byte_index--; - - if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) - { - *char_width = 0; - return 0; - } - - ch = edit_get_utf (edit, byte_index, &width); - - if (width == 1) - { - *char_width = width; - return ch; - } - - str = edit_get_byte_ptr (edit, byte_index); - buf = edit_get_buf_ptr (edit, byte_index); - if (str == NULL || buf == NULL) - { - *char_width = 0; - return 0; - } - /* get prev utf8 char */ - if (str != buf) - str = g_utf8_find_prev_char (buf, str); - - if (str == NULL) - { - *char_width = 0; - return 0; - } - else - 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; -} - -/* --------------------------------------------------------------------------------------------- */ - char * edit_get_write_filter (const char *write_name, const char *filename) { -- 2.11.4.GIT