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-d3aeb78583b8
master
David Lawrence Ramsey 2005-06-14 01:55:56 +00:00
parent 42af2216fe
commit d5d4dde1eb
4 changed files with 68 additions and 12 deletions

View File

@ -54,12 +54,15 @@ CVS code -
and NANO_APPEND_KEY are. Changes to shortcut_init(), usage(),
main(), search_init(), nanorc.sample, nano.1, nanorc.5,
nano.texi, etc. (DLR)
- Various cleanups in chars.c. Remove some unnecessary (w)ctype
wrappers; change other ctype wrappers to take wint_t instead
of wchar_t; rename some functions for consistency; and don't
count matches between valid and invalid multibyte sequences
anymore, as it causes problems when doing a replace. New
function is_valid_mbstring(); changes to is_alnum_mbchar(),
- Various cleanups and improvements in chars.c. Remove some
unnecessary w?ctype wrappers; change other ctype wrappers to
take wint_t instead of wchar_t; rename some functions for
consistency; add functions to detect blank characters in a
string, for use in rcfile option parsing; and don't count
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_wchar() (renamed niswblank()), is_cntrl_wchar(),
control_rep(), control_mbrep(), make_mbstring() (renamed
@ -189,6 +192,9 @@ CVS code -
parse_rcfile()
- Properly generate an error if we get an invalid multibyte
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:
do_gotoline()
- Properly show an error message if we try to go to line 0,

View File

@ -795,6 +795,54 @@ size_t mbstrnlen(const char *s, size_t maxlen)
}
#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. */
char *mbstrchr(const char *s, char *c)
{

View File

@ -219,6 +219,10 @@ size_t nstrnlen(const char *s, size_t maxlen);
#endif
size_t mbstrnlen(const char *s, size_t maxlen);
#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);
#endif

View File

@ -620,20 +620,18 @@ void parse_rcfile(FILE *rcstream)
#ifndef DISABLE_JUSTIFY
if (strcasecmp(rcopts[i].name, "punct") == 0) {
punct = option;
if (strchr(punct, '\t') != NULL ||
strchr(punct, ' ') != NULL) {
if (has_blank_mbchars(punct)) {
rcfile_error(
N_("Non-tab and non-space characters required"));
N_("Non-blank characters required"));
free(punct);
punct = NULL;
}
} else if (strcasecmp(rcopts[i].name,
"brackets") == 0) {
brackets = option;
if (strchr(brackets, '\t') != NULL ||
strchr(brackets, ' ') != NULL) {
if (has_blank_mbchars(brackets)) {
rcfile_error(
N_("Non-tab and non-space characters required"));
N_("Non-blank characters required"));
free(brackets);
brackets = NULL;
}