improve detection of blank characters in the "punct" and "brackets"
rcfile options git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2656 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
42af2216fe
commit
d5d4dde1eb
18
ChangeLog
18
ChangeLog
|
@ -54,12 +54,15 @@ CVS code -
|
||||||
and NANO_APPEND_KEY are. Changes to shortcut_init(), usage(),
|
and NANO_APPEND_KEY are. Changes to shortcut_init(), usage(),
|
||||||
main(), search_init(), nanorc.sample, nano.1, nanorc.5,
|
main(), search_init(), nanorc.sample, nano.1, nanorc.5,
|
||||||
nano.texi, etc. (DLR)
|
nano.texi, etc. (DLR)
|
||||||
- Various cleanups in chars.c. Remove some unnecessary (w)ctype
|
- Various cleanups and improvements in chars.c. Remove some
|
||||||
wrappers; change other ctype wrappers to take wint_t instead
|
unnecessary w?ctype wrappers; change other ctype wrappers to
|
||||||
of wchar_t; rename some functions for consistency; and don't
|
take wint_t instead of wchar_t; rename some functions for
|
||||||
count matches between valid and invalid multibyte sequences
|
consistency; add functions to detect blank characters in a
|
||||||
anymore, as it causes problems when doing a replace. New
|
string, for use in rcfile option parsing; and don't count
|
||||||
function is_valid_mbstring(); changes to is_alnum_mbchar(),
|
matches between valid and invalid multibyte sequences anymore,
|
||||||
|
as it causes problems when doing a replace. New functions
|
||||||
|
is_valid_mbstring(), has_blank_chars(), and
|
||||||
|
has_blank_mbchars(); changes to is_alnum_mbchar(),
|
||||||
is_blank_char() (renamed nisblank()), is_blank_mbchar(),
|
is_blank_char() (renamed nisblank()), is_blank_mbchar(),
|
||||||
is_blank_wchar() (renamed niswblank()), is_cntrl_wchar(),
|
is_blank_wchar() (renamed niswblank()), is_cntrl_wchar(),
|
||||||
control_rep(), control_mbrep(), make_mbstring() (renamed
|
control_rep(), control_mbrep(), make_mbstring() (renamed
|
||||||
|
@ -189,6 +192,9 @@ CVS code -
|
||||||
parse_rcfile()
|
parse_rcfile()
|
||||||
- Properly generate an error if we get an invalid multibyte
|
- Properly generate an error if we get an invalid multibyte
|
||||||
string for an option, instead of working around it. (DLR)
|
string for an option, instead of working around it. (DLR)
|
||||||
|
- Use has_blank_mbchars() to check for blank characters in the
|
||||||
|
"punct" and "brackets" options, and clarify the error message
|
||||||
|
displayed when we find blank characters. (DLR)
|
||||||
- search.c:
|
- search.c:
|
||||||
do_gotoline()
|
do_gotoline()
|
||||||
- Properly show an error message if we try to go to line 0,
|
- Properly show an error message if we try to go to line 0,
|
||||||
|
|
48
src/chars.c
48
src/chars.c
|
@ -795,6 +795,54 @@ size_t mbstrnlen(const char *s, size_t maxlen)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_JUSTIFY
|
#ifndef DISABLE_JUSTIFY
|
||||||
|
#ifdef ENABLE_NANORC
|
||||||
|
/* Return TRUE if the string s contains one or more blank characters,
|
||||||
|
* and FALSE otherwise. */
|
||||||
|
bool has_blank_chars(const char *s)
|
||||||
|
{
|
||||||
|
assert(s != NULL);
|
||||||
|
|
||||||
|
for (; *s != '\0'; s++) {
|
||||||
|
if (isblank(*s))
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return TRUE if the multibyte string s contains one or more blank
|
||||||
|
* multibyte characters, and FALSE otherwise. */
|
||||||
|
bool has_blank_mbchars(const char *s)
|
||||||
|
{
|
||||||
|
assert(str != NULL);
|
||||||
|
|
||||||
|
#ifdef NANO_WIDE
|
||||||
|
if (!ISSET(NO_UTF8)) {
|
||||||
|
char *chr_mb = charalloc(MB_CUR_MAX);
|
||||||
|
bool retval = FALSE;
|
||||||
|
|
||||||
|
while (*s != '\0') {
|
||||||
|
int chr_mb_len;
|
||||||
|
|
||||||
|
chr_mb_len = parse_mbchar(s, chr_mb, NULL, NULL);
|
||||||
|
|
||||||
|
if (is_blank_mbchar(chr_mb)) {
|
||||||
|
retval = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s += chr_mb_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(chr_mb);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
return has_blank_chars(s);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* This function is equivalent to strchr() for multibyte strings. */
|
/* This function is equivalent to strchr() for multibyte strings. */
|
||||||
char *mbstrchr(const char *s, char *c)
|
char *mbstrchr(const char *s, char *c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -219,6 +219,10 @@ size_t nstrnlen(const char *s, size_t maxlen);
|
||||||
#endif
|
#endif
|
||||||
size_t mbstrnlen(const char *s, size_t maxlen);
|
size_t mbstrnlen(const char *s, size_t maxlen);
|
||||||
#ifndef DISABLE_JUSTIFY
|
#ifndef DISABLE_JUSTIFY
|
||||||
|
#ifdef ENABLE_NANORC
|
||||||
|
bool has_blank_chars(const char *s);
|
||||||
|
bool has_blank_mbchars(const char *s);
|
||||||
|
#endif
|
||||||
char *mbstrchr(const char *s, char *c);
|
char *mbstrchr(const char *s, char *c);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
10
src/rcfile.c
10
src/rcfile.c
|
@ -620,20 +620,18 @@ void parse_rcfile(FILE *rcstream)
|
||||||
#ifndef DISABLE_JUSTIFY
|
#ifndef DISABLE_JUSTIFY
|
||||||
if (strcasecmp(rcopts[i].name, "punct") == 0) {
|
if (strcasecmp(rcopts[i].name, "punct") == 0) {
|
||||||
punct = option;
|
punct = option;
|
||||||
if (strchr(punct, '\t') != NULL ||
|
if (has_blank_mbchars(punct)) {
|
||||||
strchr(punct, ' ') != NULL) {
|
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Non-tab and non-space characters required"));
|
N_("Non-blank characters required"));
|
||||||
free(punct);
|
free(punct);
|
||||||
punct = NULL;
|
punct = NULL;
|
||||||
}
|
}
|
||||||
} else if (strcasecmp(rcopts[i].name,
|
} else if (strcasecmp(rcopts[i].name,
|
||||||
"brackets") == 0) {
|
"brackets") == 0) {
|
||||||
brackets = option;
|
brackets = option;
|
||||||
if (strchr(brackets, '\t') != NULL ||
|
if (has_blank_mbchars(brackets)) {
|
||||||
strchr(brackets, ' ') != NULL) {
|
|
||||||
rcfile_error(
|
rcfile_error(
|
||||||
N_("Non-tab and non-space characters required"));
|
N_("Non-blank characters required"));
|
||||||
free(brackets);
|
free(brackets);
|
||||||
brackets = NULL;
|
brackets = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue