add multibyte character support to indent_length(), convert the "smart

home" routines to use it (since it returns the number of bytes taken up
by spacing characters at the beginning of the line), and rearrange a few
initializations near asserts


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2307 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-01-31 18:59:30 +00:00
parent 2921be2f38
commit 3eeb823f92
4 changed files with 41 additions and 52 deletions

View File

@ -110,10 +110,10 @@ CVS code -
chars.c), move_left() (renamed move_mbleft() and moved to
chars.c), move_right() (renamed move_mbright() and moved to
chars.c), do_home(), do_verbatim_input(), do_delete(),
do_tab(), do_next_word(), do_prev_word(), do_input(),
do_output(), strstrwrapper(), get_buffer(), unget_input(),
unget_kbinput(), get_input(), parse_kbinput(),
unparse_kbinput(), parse_verbatim_kbinput(),
do_tab(), do_enter(), indent_length(), do_next_word(),
do_prev_word(), do_input(), do_output(), strstrwrapper(),
get_buffer(), unget_input(), unget_kbinput(), get_input(),
parse_kbinput(), unparse_kbinput(), parse_verbatim_kbinput(),
do_statusbar_input(), do_statusbar_home(),
do_statusbar_verbatim_kbinput(), do_statusbar_output(), and
display_string(); removal of buffer_to_keys() and

View File

@ -57,26 +57,8 @@ void do_home(void)
#ifndef NANO_SMALL
if (ISSET(SMART_HOME)) {
size_t current_x_save = current_x;
char *blank_mb = charalloc(mb_cur_max());
int blank_mb_len;
current_x = 0;
while (current->data[current_x] != '\0') {
blank_mb_len = parse_mbchar(current->data + current_x,
blank_mb
#ifdef NANO_WIDE
, NULL
#endif
, NULL);
if (!is_blank_mbchar(blank_mb))
break;
current_x += blank_mb_len;
}
free(blank_mb);
current_x = indent_length(current->data);
if (current_x == current_x_save ||
current->data[current_x] == '\0')

View File

@ -1330,11 +1330,13 @@ void do_next_word(void)
{
size_t pww_save = placewewant;
const filestruct *current_save = current;
char *char_mb = charalloc(mb_cur_max());
char *char_mb;
int char_mb_len;
assert(current != NULL && current->data != NULL);
char_mb = charalloc(mb_cur_max());
/* Move forward until we find the character after the last letter of
* the current word. */
while (current->data[current_x] != '\0') {
@ -1399,12 +1401,14 @@ void do_prev_word(void)
{
size_t pww_save = placewewant;
const filestruct *current_save = current;
char *char_mb = charalloc(mb_cur_max());
char *char_mb;
int char_mb_len;
bool begin_line = FALSE;
assert(current != NULL && current->data != NULL);
char_mb = charalloc(mb_cur_max());
/* Move backward until we find the character before the first letter
* of the current word. */
while (!begin_line) {
@ -1633,7 +1637,7 @@ bool do_wrap(filestruct *inptr)
if (ISSET(AUTOINDENT)) {
/* Indentation comes from the next line if wrapping, else from
* this line. */
indentation = (wrapping ? wrap_line : inptr->data);
indentation = wrapping ? wrap_line : inptr->data;
indent_len = indent_length(indentation);
if (wrapping)
/* The wrap_line text should not duplicate indentation.
@ -2296,21 +2300,38 @@ void do_spell(void)
}
#endif /* !DISABLE_SPELLER */
#if !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)
#ifndef NANO_SMALL
/* The "indentation" of a line is the whitespace between the quote part
* and the non-whitespace of the line. */
size_t indent_length(const char *line)
{
size_t len = 0;
char *blank_mb;
int blank_mb_len;
assert(line != NULL);
while (is_blank_char(*line)) {
line++;
len++;
blank_mb = charalloc(mb_cur_max());
while (*line != '\0') {
blank_mb_len = parse_mbchar(line, blank_mb
#ifdef NANO_WIDE
, NULL
#endif
, NULL);
if (!is_blank_mbchar(blank_mb))
break;
line += blank_mb_len;
len += blank_mb_len;
}
free(blank_mb);
return len;
}
#endif /* !NANO_SMALL || !DISABLE_JUSTIFY */
#endif /* !NANO_SMALL */
#ifndef DISABLE_JUSTIFY
/* justify_format() replaces Tab by Space and multiple spaces by 1

View File

@ -1819,26 +1819,8 @@ void do_statusbar_home(void)
#ifndef NANO_SMALL
if (ISSET(SMART_HOME)) {
size_t statusbar_x_save = statusbar_x;
char *blank_mb = charalloc(mb_cur_max());
int blank_mb_len;
statusbar_x = 0;
while (statusbar_x < statusbar_xend) {
blank_mb_len = parse_mbchar(answer + statusbar_x,
blank_mb
#ifdef NANO_WIDE
, NULL
#endif
, NULL);
if (!is_blank_mbchar(blank_mb))
break;
statusbar_x += blank_mb_len;
}
free(blank_mb);
statusbar_x = indent_length(answer);
if (statusbar_x == statusbar_x_save ||
statusbar_x == statusbar_xend)
@ -1904,11 +1886,13 @@ void do_statusbar_cut_text(void)
#ifndef NANO_SMALL
void do_statusbar_next_word(void)
{
char *char_mb = charalloc(mb_cur_max());
char *char_mb;
int char_mb_len;
assert(answer != NULL);
char_mb = charalloc(mb_cur_max());
/* Move forward until we find the character after the last letter of
* the current word. */
while (statusbar_x < statusbar_xend) {
@ -1950,12 +1934,14 @@ void do_statusbar_next_word(void)
void do_statusbar_prev_word(void)
{
char *char_mb = charalloc(mb_cur_max());
char *char_mb;
int char_mb_len;
bool begin_line = FALSE;
assert(answer != NULL);
char_mb = charalloc(mb_cur_max());
/* Move backward until we find the character before the first letter
* of the current word. */
while (!begin_line) {