improve the handling of whitespace display mode in multibyte locales:

use new function make_mbstring() instead of display_string() to make
sure the multibyte string is valid and interpreted properly


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2348 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-03-11 04:03:32 +00:00
parent 55dfc3d3e9
commit e0fb4d5641
4 changed files with 60 additions and 8 deletions

View File

@ -173,8 +173,9 @@ CVS code -
color_to_int(), and add a few miscellaneous tweaks. color_to_int(), and add a few miscellaneous tweaks.
- Still more steps toward full wide/multibyte character support. - Still more steps toward full wide/multibyte character support.
Make whitespace display mode work with multibyte characters, Make whitespace display mode work with multibyte characters,
and add a few related documentation updates. Changes to and add a few related documentation updates. New function
do_help(), main(), parse_rcfile(), and display_string(). (DLR) make_mbstring(); changes to do_help(), main(), parse_rcfile(),
and display_string(). (DLR)
- cut.c: - cut.c:
do_cut_text() do_cut_text()
- If keep_cutbuffer is FALSE, only blow away the text in the - If keep_cutbuffer is FALSE, only blow away the text in the

View File

@ -297,6 +297,58 @@ char *make_mbchar(int chr, char *chr_mb, int *chr_mb_len)
return chr_mb; return chr_mb;
} }
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
/* Convert the string str to a valid multibyte string with the same wide
* character values as str. Return the multibyte string. */
char *make_mbstring(char *str, char *str_mb)
{
assert(str != NULL && str_mb != NULL);
#ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) {
char *chr_mb = charalloc(MB_CUR_MAX);
int chr_mb_len;
size_t str_mb_len = 0;
str_mb = charalloc((MB_CUR_MAX * strlen(str)) + 1);
while (*str != '\0') {
bool bad_char;
int i;
chr_mb_len = parse_mbchar(str, chr_mb, &bad_char, NULL);
if (bad_char) {
char *bad_chr_mb = charalloc(MB_CUR_MAX);
int bad_chr_mb_len;
bad_chr_mb = make_mbchar((unsigned char)chr_mb[0],
bad_chr_mb, &bad_chr_mb_len);
for (i = 0; i < bad_chr_mb_len; i++)
str_mb[str_mb_len + i] = bad_chr_mb[i];
str_mb_len += bad_chr_mb_len;
free(bad_chr_mb);
} else {
for (i = 0; i < chr_mb_len; i++)
str_mb[str_mb_len + i] = chr_mb[i];
str_mb_len += chr_mb_len;
}
str += chr_mb_len;
}
free(chr_mb);
null_at(&str_mb, str_mb_len);
return str_mb;
} else
#endif
return mallocstrcpy(str_mb, str);
}
#endif
/* Parse a multibyte character from buf. Return the number of bytes /* Parse a multibyte character from buf. Return the number of bytes
* used. If chr isn't NULL, store the multibyte character in it. If * used. If chr isn't NULL, store the multibyte character in it. If
* bad_chr isn't NULL, set it to TRUE if we have a bad multibyte * bad_chr isn't NULL, set it to TRUE if we have a bad multibyte
@ -330,6 +382,7 @@ int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t
/* Save the multibyte character in chr. */ /* Save the multibyte character in chr. */
if (chr != NULL) { if (chr != NULL) {
int i; int i;
for (i = 0; i < buf_mb_len; i++) for (i = 0; i < buf_mb_len; i++)
chr[i] = buf[i]; chr[i] = buf[i];
} }

View File

@ -175,6 +175,9 @@ wchar_t control_wrep(wchar_t c);
int mbwidth(const char *c); int mbwidth(const char *c);
int mb_cur_max(void); int mb_cur_max(void);
char *make_mbchar(int chr, char *chr_mb, int *chr_mb_len); char *make_mbchar(int chr, char *chr_mb, int *chr_mb_len);
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
char *make_mbstring(char *str, char *str_mb);
#endif
int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t
*col); *col);
size_t move_mbleft(const char *buf, size_t pos); size_t move_mbleft(const char *buf, size_t pos);

View File

@ -570,12 +570,7 @@ void parse_rcfile(FILE *rcstream)
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (strcasecmp(rcopts[i].name, "whitespace") == 0) { if (strcasecmp(rcopts[i].name, "whitespace") == 0) {
/* We use display_string() here so that any whitespace = make_mbstring(option, whitespace);
* invalid multibyte characters in option
* will be converted to valid multibyte
* characters in whitespace. */
whitespace = display_string(option, 0, 3, FALSE);
if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) { if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) {
rcfile_error(N_("Two single-column characters required")); rcfile_error(N_("Two single-column characters required"));
free(whitespace); free(whitespace);