mirror of git://git.sv.gnu.org/nano.git
various cleanups to chars.c and related code
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2631 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
6315e2ff39
commit
d8640480c3
|
@ -54,6 +54,13 @@ 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 ctype
|
||||||
|
wrappers, change other ctype wrappers to take wint_t instead
|
||||||
|
of wchar_t, and rename some functions for consistency. Changes
|
||||||
|
to is_alnum_mbchar(), is_blank_char() (renamed nisblank()),
|
||||||
|
is_blank_mbchar(), is_blank_wchar() (renamed niswblank()), and
|
||||||
|
is_cntrl_wchar(), etc.; removal of is_alnum_char() and
|
||||||
|
is_alnum_wchar(). (DLR)
|
||||||
- chars.c:
|
- chars.c:
|
||||||
make_mbstring()
|
make_mbstring()
|
||||||
- Change erroneous ENABLE_EXTRA #ifdef to NANO_EXTRA to fix a
|
- Change erroneous ENABLE_EXTRA #ifdef to NANO_EXTRA to fix a
|
||||||
|
@ -145,6 +152,8 @@ CVS code -
|
||||||
processing, and rename to disable_extended_io(). (DLR)
|
processing, and rename to disable_extended_io(). (DLR)
|
||||||
- nano.h:
|
- nano.h:
|
||||||
- Add macro charset(), a wrapper that calls memset(). (DLR)
|
- Add macro charset(), a wrapper that calls memset(). (DLR)
|
||||||
|
- Readd #defines for the isblank() and iswblank() equivalents.
|
||||||
|
(DLR)
|
||||||
- rcfile.c:
|
- rcfile.c:
|
||||||
color_to_int()
|
color_to_int()
|
||||||
- Since colorname's being NULL is handled elsewhere now, assert
|
- Since colorname's being NULL is handled elsewhere now, assert
|
||||||
|
|
109
src/chars.c
109
src/chars.c
|
@ -46,12 +46,6 @@ bool is_byte(int c)
|
||||||
return ((unsigned int)c == (unsigned char)c);
|
return ((unsigned int)c == (unsigned char)c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is equivalent to isalnum(). */
|
|
||||||
bool is_alnum_char(int c)
|
|
||||||
{
|
|
||||||
return isalnum(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This function is equivalent to isalnum() for multibyte characters. */
|
/* This function is equivalent to isalnum() for multibyte characters. */
|
||||||
bool is_alnum_mbchar(const char *c)
|
bool is_alnum_mbchar(const char *c)
|
||||||
{
|
{
|
||||||
|
@ -67,31 +61,27 @@ bool is_alnum_mbchar(const char *c)
|
||||||
wc = (unsigned char)*c;
|
wc = (unsigned char)*c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_alnum_wchar(wc);
|
return iswalnum(wc);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
return is_alnum_char((unsigned char)*c);
|
return isalnum((unsigned char)*c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NANO_WIDE
|
#ifndef HAVE_ISBLANK
|
||||||
/* This function is equivalent to isalnum() for wide characters. */
|
|
||||||
bool is_alnum_wchar(wchar_t wc)
|
|
||||||
{
|
|
||||||
return iswalnum(wc);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This function is equivalent to isblank(). */
|
/* This function is equivalent to isblank(). */
|
||||||
bool is_blank_char(int c)
|
bool nisblank(int c)
|
||||||
{
|
{
|
||||||
return
|
return isspace(c) && (c == '\t' || !is_cntrl_char(c));
|
||||||
#ifdef HAVE_ISBLANK
|
|
||||||
isblank(c)
|
|
||||||
#else
|
|
||||||
isspace(c) && (c == '\t' || !is_cntrl_char(c))
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(NANO_WIDE) && !defined(HAVE_ISWBLANK)
|
||||||
|
/* This function is equivalent to iswblank(). */
|
||||||
|
bool niswblank(wint_t wc)
|
||||||
|
{
|
||||||
|
return iswspace(wc) && (wc == '\t' || !is_cntrl_wchar(wc));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* This function is equivalent to isblank() for multibyte characters. */
|
/* This function is equivalent to isblank() for multibyte characters. */
|
||||||
bool is_blank_mbchar(const char *c)
|
bool is_blank_mbchar(const char *c)
|
||||||
|
@ -108,26 +98,12 @@ bool is_blank_mbchar(const char *c)
|
||||||
wc = (unsigned char)*c;
|
wc = (unsigned char)*c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_blank_wchar(wc);
|
return iswblank(wc);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
return is_blank_char((unsigned char)*c);
|
return isblank((unsigned char)*c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NANO_WIDE
|
|
||||||
/* This function is equivalent to isblank() for wide characters. */
|
|
||||||
bool is_blank_wchar(wchar_t wc)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
#ifdef HAVE_ISWBLANK
|
|
||||||
iswblank(wc)
|
|
||||||
#else
|
|
||||||
iswspace(wc) && (wc == '\t' || !is_cntrl_wchar(wc))
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This function is equivalent to iscntrl(), except in that it also
|
/* This function is equivalent to iscntrl(), except in that it also
|
||||||
* handles control characters with their high bits set. */
|
* handles control characters with their high bits set. */
|
||||||
bool is_cntrl_char(int c)
|
bool is_cntrl_char(int c)
|
||||||
|
@ -136,6 +112,17 @@ bool is_cntrl_char(int c)
|
||||||
(127 <= c && c < 160);
|
(127 <= c && c < 160);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NANO_WIDE
|
||||||
|
/* This function is equivalent to iscntrl() for wide characters, except
|
||||||
|
* in that it also handles wide control characters with their high bits
|
||||||
|
* set. */
|
||||||
|
bool is_cntrl_wchar(wint_t wc)
|
||||||
|
{
|
||||||
|
return (-128 <= wc && wc < -96) || (0 <= wc && wc < 32) ||
|
||||||
|
(127 <= wc && wc < 160);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* This function is equivalent to iscntrl() for multibyte characters,
|
/* This function is equivalent to iscntrl() for multibyte characters,
|
||||||
* except in that it also handles multibyte control characters with
|
* except in that it also handles multibyte control characters with
|
||||||
* their high bits set. */
|
* their high bits set. */
|
||||||
|
@ -159,16 +146,6 @@ bool is_cntrl_mbchar(const char *c)
|
||||||
return is_cntrl_char((unsigned char)*c);
|
return is_cntrl_char((unsigned char)*c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NANO_WIDE
|
|
||||||
/* This function is equivalent to iscntrl() for wide characters, except
|
|
||||||
* in that it also handles wide control characters with their high bits
|
|
||||||
* set. */
|
|
||||||
bool is_cntrl_wchar(wchar_t wc)
|
|
||||||
{
|
|
||||||
return (0 <= wc && wc < 32) || (127 <= wc && wc < 160);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* c is a control character. It displays as ^@, ^?, or ^[ch], where ch
|
/* c is a control character. It displays as ^@, ^?, or ^[ch], where ch
|
||||||
* is c + 64. We return that character. */
|
* is c + 64. We return that character. */
|
||||||
unsigned char control_rep(unsigned char c)
|
unsigned char control_rep(unsigned char c)
|
||||||
|
@ -182,7 +159,22 @@ unsigned char control_rep(unsigned char c)
|
||||||
return c + 64;
|
return c + 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* c is a multibyte control character. It displays as ^@, ^?, or ^[ch]
|
#ifdef NANO_WIDE
|
||||||
|
/* c is a wide control character. It displays as ^@, ^?, or ^[ch],
|
||||||
|
* where ch is c + 64. We return that wide character. */
|
||||||
|
wchar_t control_wrep(wchar_t wc)
|
||||||
|
{
|
||||||
|
/* Treat newlines embedded in a line as encoded nulls. */
|
||||||
|
if (wc == '\n')
|
||||||
|
return '@';
|
||||||
|
else if (wc == NANO_CONTROL_8)
|
||||||
|
return '?';
|
||||||
|
else
|
||||||
|
return wc + 64;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* c is a multibyte control character. It displays as ^@, ^?, or ^[ch],
|
||||||
* where ch is c + 64. We return that multibyte character. */
|
* where ch is c + 64. We return that multibyte character. */
|
||||||
char *control_mbrep(const char *c, char *crep, int *crep_len)
|
char *control_mbrep(const char *c, char *crep, int *crep_len)
|
||||||
{
|
{
|
||||||
|
@ -221,21 +213,6 @@ char *control_mbrep(const char *c, char *crep, int *crep_len)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NANO_WIDE
|
|
||||||
/* c is a wide control character. It displays as ^@, ^?, or ^[ch] where
|
|
||||||
* ch is c + 64. We return that wide character. */
|
|
||||||
wchar_t control_wrep(wchar_t wc)
|
|
||||||
{
|
|
||||||
/* Treat newlines embedded in a line as encoded nulls. */
|
|
||||||
if (wc == '\n')
|
|
||||||
return '@';
|
|
||||||
else if (wc == NANO_CONTROL_8)
|
|
||||||
return '?';
|
|
||||||
else
|
|
||||||
return wc + 64;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This function is equivalent to wcwidth() for multibyte characters. */
|
/* This function is equivalent to wcwidth() for multibyte characters. */
|
||||||
int mbwidth(const char *c)
|
int mbwidth(const char *c)
|
||||||
{
|
{
|
||||||
|
|
11
src/nano.h
11
src/nano.h
|
@ -105,8 +105,15 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If no strcasecmp(), strncasecmp(), strcasestr(), strnlen(),
|
/* If no isblank(), iswblank(), strcasecmp(), strncasecmp(),
|
||||||
* getdelim(), or getline(), use the versions we have. */
|
* strcasestr(), strnlen(), getdelim(), or getline(), use the versions
|
||||||
|
* we have. */
|
||||||
|
#ifndef HAVE_ISBLANK
|
||||||
|
#define isblank nisblank
|
||||||
|
#endif
|
||||||
|
#ifndef HAVE_ISWBLANK
|
||||||
|
#define iswblank niswblank
|
||||||
|
#endif
|
||||||
#ifndef HAVE_STRCASECMP
|
#ifndef HAVE_STRCASECMP
|
||||||
#define strcasecmp nstrcasecmp
|
#define strcasecmp nstrcasecmp
|
||||||
#endif
|
#endif
|
||||||
|
|
18
src/proto.h
18
src/proto.h
|
@ -160,26 +160,24 @@ extern char *homedir;
|
||||||
|
|
||||||
/* Public functions in chars.c. */
|
/* Public functions in chars.c. */
|
||||||
bool is_byte(int c);
|
bool is_byte(int c);
|
||||||
bool is_alnum_char(int c);
|
|
||||||
bool is_alnum_mbchar(const char *c);
|
bool is_alnum_mbchar(const char *c);
|
||||||
#ifdef NANO_WIDE
|
#ifndef HAVE_ISBLANK
|
||||||
bool is_alnum_wchar(wchar_t wc);
|
bool nisblank(int c);
|
||||||
|
#endif
|
||||||
|
#if defined(NANO_WIDE) && !defined(HAVE_ISWBLANK)
|
||||||
|
bool niswblank(wint_t wc);
|
||||||
#endif
|
#endif
|
||||||
bool is_blank_char(int c);
|
|
||||||
bool is_blank_mbchar(const char *c);
|
bool is_blank_mbchar(const char *c);
|
||||||
#ifdef NANO_WIDE
|
|
||||||
bool is_blank_wchar(wchar_t wc);
|
|
||||||
#endif
|
|
||||||
bool is_cntrl_char(int c);
|
bool is_cntrl_char(int c);
|
||||||
bool is_cntrl_mbchar(const char *c);
|
|
||||||
#ifdef NANO_WIDE
|
#ifdef NANO_WIDE
|
||||||
bool is_cntrl_wchar(wchar_t wc);
|
bool is_cntrl_wchar(wint_t wc);
|
||||||
#endif
|
#endif
|
||||||
|
bool is_cntrl_mbchar(const char *c);
|
||||||
unsigned char control_rep(unsigned char c);
|
unsigned char control_rep(unsigned char c);
|
||||||
char *control_mbrep(const char *c, char *crep, int *crep_len);
|
|
||||||
#ifdef NANO_WIDE
|
#ifdef NANO_WIDE
|
||||||
wchar_t control_wrep(wchar_t c);
|
wchar_t control_wrep(wchar_t c);
|
||||||
#endif
|
#endif
|
||||||
|
char *control_mbrep(const char *c, char *crep, int *crep_len);
|
||||||
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, int *chr_mb_len);
|
char *make_mbchar(int chr, int *chr_mb_len);
|
||||||
|
|
12
src/rcfile.c
12
src/rcfile.c
|
@ -129,7 +129,7 @@ void rcfile_error(const char *msg, ...)
|
||||||
* the end of the line. */
|
* the end of the line. */
|
||||||
char *parse_next_word(char *ptr)
|
char *parse_next_word(char *ptr)
|
||||||
{
|
{
|
||||||
while (!is_blank_char(*ptr) && *ptr != '\0')
|
while (!isblank(*ptr) && *ptr != '\0')
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
if (*ptr == '\0')
|
if (*ptr == '\0')
|
||||||
|
@ -138,7 +138,7 @@ char *parse_next_word(char *ptr)
|
||||||
/* Null-terminate and advance ptr. */
|
/* Null-terminate and advance ptr. */
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
|
|
||||||
while (is_blank_char(*ptr))
|
while (isblank(*ptr))
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -178,7 +178,7 @@ char *parse_argument(char *ptr)
|
||||||
ptr = last_quote + 1;
|
ptr = last_quote + 1;
|
||||||
}
|
}
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
while (is_blank_char(*ptr))
|
while (isblank(*ptr))
|
||||||
ptr++;
|
ptr++;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ char *parse_next_regex(char *ptr)
|
||||||
|
|
||||||
/* Continue until the end of the line, or a " followed by a space, a
|
/* Continue until the end of the line, or a " followed by a space, a
|
||||||
* blank character, or \0. */
|
* blank character, or \0. */
|
||||||
while ((*ptr != '"' || (!is_blank_char(*(ptr + 1)) &&
|
while ((*ptr != '"' || (!isblank(*(ptr + 1)) &&
|
||||||
*(ptr + 1) != '\0')) && *ptr != '\0')
|
*(ptr + 1) != '\0')) && *ptr != '\0')
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ char *parse_next_regex(char *ptr)
|
||||||
/* Null terminate and advance ptr. */
|
/* Null terminate and advance ptr. */
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
|
|
||||||
while (is_blank_char(*ptr))
|
while (isblank(*ptr))
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -507,7 +507,7 @@ void parse_rcfile(FILE *rcstream)
|
||||||
|
|
||||||
lineno++;
|
lineno++;
|
||||||
ptr = buf;
|
ptr = buf;
|
||||||
while (is_blank_char(*ptr))
|
while (isblank(*ptr))
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
/* If we have a blank line or a comment, skip to the next
|
/* If we have a blank line or a comment, skip to the next
|
||||||
|
|
Loading…
Reference in New Issue