From 6e60db6989f6f530b189c0160c3538c3ffb14829 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Thu, 10 Mar 2005 22:52:21 +0000 Subject: [PATCH] make whitespace display mode work with multibyte characters git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2346 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 7 +++++++ doc/nanorc.sample | 5 +++-- src/global.c | 1 + src/nano.c | 13 ++++++++----- src/proto.h | 1 + src/rcfile.c | 21 ++++++++++++++++----- src/winio.c | 21 +++++++++++++++------ 7 files changed, 51 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index b13c15dd..52d8a8ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -171,6 +171,10 @@ CVS code - parse_syntax(), parse_colors(), parse_rcfile(), do_rcfile(), etc. (David Benbennick) DLR: Rename colortoint() to color_to_int(), and add a few miscellaneous tweaks. + - Still more steps toward full wide/multibyte character support. + Make whitespace display mode work with multibyte characters, + and add a few related documentation updates. Changes to + do_help(), main(), parse_rcfile(), and display_string(). (DLR) - cut.c: do_cut_text() - If keep_cutbuffer is FALSE, only blow away the text in the @@ -325,6 +329,9 @@ CVS code - Piefel) - Add the "morespace" option. (DLR) - Add support for characters to the "c-file" regexes. (DLR) + - Add the hexadecimal equivalents of the decimal values + suggested for whitespace display, now that it can handle + multibyte characters. (DLR) - nano.1. nanorc.5, nano.texi: - Add the "morespace" option, and sync with the descriptions in nanorc.sample in a few places. (DLR) diff --git a/doc/nanorc.sample b/doc/nanorc.sample index ef8eaa12..63d7f778 100644 --- a/doc/nanorc.sample +++ b/doc/nanorc.sample @@ -118,11 +118,12 @@ ## Save automatically on exit, don't prompt. # set tempfile -## Disallow file modification, why would you want this in an rc file? ;) +## Disallow file modification; why would you want this in an rcfile? ;) # set view ## The two characters used to display the first characters of tabs and -## spaces. 187 and 183 seem to be good values for these. +## spaces. 187 decimal (00BB hexadecimal) and 183 decimal (00B7 +## hexadecimal) seem to be good values for these. # set whitespace " " ## Color setup diff --git a/src/global.c b/src/global.c index 5c2996bd..19a37de5 100644 --- a/src/global.c +++ b/src/global.c @@ -78,6 +78,7 @@ openfilestruct *open_files = NULL; /* The list of open file char *whitespace = NULL; /* Characters used when displaying the first characters of tabs and spaces. */ +int whitespace_len[2]; /* The length of the characters. */ #endif #ifndef DISABLE_JUSTIFY diff --git a/src/nano.c b/src/nano.c index 4c1b4960..96bdb531 100644 --- a/src/nano.c +++ b/src/nano.c @@ -380,10 +380,10 @@ void help_init(void) "Esc key twice. Escape-key sequences are notated with the Meta " "(M) symbol and can be entered using either the Esc, Alt or " "Meta key depending on your keyboard setup. Also, pressing Esc " - "twice and then typing a three-digit number from 000 to 255 " - "will enter the character with the corresponding value. The " - "following keystrokes are available in the main editor window. " - "Alternative keys are shown in parentheses:\n\n"); + "twice and then typing a three-digit decimal number from 000 to " + " 255 will enter the character with the corresponding value. " + "The following keystrokes are available in the main editor " + " window. Alternative keys are shown in parentheses:\n\n"); htx = _(htx); @@ -4271,8 +4271,11 @@ int main(int argc, char **argv) #if !defined(NANO_SMALL) && defined(ENABLE_NANORC) /* If whitespace wasn't specified, set its default value. */ - if (whitespace == NULL) + if (whitespace == NULL) { whitespace = mallocstrcpy(NULL, " "); + whitespace_len[0] = 1; + whitespace_len[1] = 1; + } #endif /* If tabsize wasn't specified, set its default value. */ diff --git a/src/proto.h b/src/proto.h index a39217a6..3f7c30c6 100644 --- a/src/proto.h +++ b/src/proto.h @@ -47,6 +47,7 @@ extern int currslen; #if !defined(NANO_SMALL) && defined(ENABLE_NANORC) extern char *whitespace; +extern int whitespace_len[2]; #endif #ifndef DISABLE_JUSTIFY diff --git a/src/rcfile.c b/src/rcfile.c index a1b60e2f..03c30565 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -570,13 +570,24 @@ void parse_rcfile(FILE *rcstream) #endif #ifndef NANO_SMALL if (strcasecmp(rcopts[i].name, "whitespace") == 0) { - size_t ws_len; - whitespace = mallocstrcpy(NULL, option); - ws_len = strlen(whitespace); - if (ws_len != 2 || (ws_len == 2 && (is_cntrl_char(whitespace[0]) || is_cntrl_char(whitespace[1])))) { - rcfile_error(N_("Two non-control characters required")); + /* We use display_string() here so that any + * 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) { + rcfile_error(N_("Two single-column characters required")); free(whitespace); whitespace = NULL; + } else { + whitespace_len[0] = + parse_mbchar(whitespace, NULL, + NULL, NULL); + whitespace_len[1] = + parse_mbchar(whitespace + + whitespace_len[0], NULL, + NULL, NULL); } } else #endif diff --git a/src/winio.c b/src/winio.c index 67185526..bc0b9201 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2278,11 +2278,15 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool NULL); if (*buf_mb == '\t') { - converted[index++] = #if !defined(NANO_SMALL) && defined(ENABLE_NANORC) - ISSET(WHITESPACE_DISPLAY) ? whitespace[0] : + if (ISSET(WHITESPACE_DISPLAY)) { + int i; + + for (i = 0; i < whitespace_len[0]; i++) + converted[index++] = whitespace[i]; + } else #endif - ' '; + converted[index++] = ' '; start_col++; while (start_col % tabsize != 0) { converted[index++] = ' '; @@ -2308,11 +2312,16 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool free(ctrl_buf_mb); } else if (*buf_mb == ' ') { - converted[index++] = #if !defined(NANO_SMALL) && defined(ENABLE_NANORC) - ISSET(WHITESPACE_DISPLAY) ? whitespace[1] : + if (ISSET(WHITESPACE_DISPLAY)) { + int i; + + for (i = whitespace_len[0]; i < whitespace_len[0] + + whitespace_len[1]; i++) + converted[index++] = whitespace[i]; + } else #endif - ' '; + converted[index++] = ' '; start_col++; } else { int i; -- 2.39.5