1
1

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 <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2011-10-11 13:37:51 +04:00 коммит произвёл Slava Zanko
родитель 9ac22ec544
Коммит 8664830831
2 изменённых файлов: 115 добавлений и 121 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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)
{