commit d8640480c368c9d31fc97954b4c5874540903649
parent 6315e2ff3981c2d10ee76a7237aeda9c300497fa
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Sun, 12 Jun 2005 17:48:46 +0000
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
Diffstat:
5 files changed, 72 insertions(+), 81 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -54,6 +54,13 @@ 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 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:
make_mbstring()
- 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)
- nano.h:
- Add macro charset(), a wrapper that calls memset(). (DLR)
+ - Readd #defines for the isblank() and iswblank() equivalents.
+ (DLR)
- rcfile.c:
color_to_int()
- Since colorname's being NULL is handled elsewhere now, assert
diff --git a/src/chars.c b/src/chars.c
@@ -46,12 +46,6 @@ bool is_byte(int 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. */
bool is_alnum_mbchar(const char *c)
{
@@ -67,31 +61,27 @@ bool is_alnum_mbchar(const char *c)
wc = (unsigned char)*c;
}
- return is_alnum_wchar(wc);
+ return iswalnum(wc);
} else
#endif
- return is_alnum_char((unsigned char)*c);
+ return isalnum((unsigned char)*c);
}
-#ifdef NANO_WIDE
-/* This function is equivalent to isalnum() for wide characters. */
-bool is_alnum_wchar(wchar_t wc)
+#ifndef HAVE_ISBLANK
+/* This function is equivalent to isblank(). */
+bool nisblank(int c)
{
- return iswalnum(wc);
+ return isspace(c) && (c == '\t' || !is_cntrl_char(c));
}
#endif
-/* This function is equivalent to isblank(). */
-bool is_blank_char(int c)
+#if defined(NANO_WIDE) && !defined(HAVE_ISWBLANK)
+/* This function is equivalent to iswblank(). */
+bool niswblank(wint_t wc)
{
- return
-#ifdef HAVE_ISBLANK
- isblank(c)
-#else
- isspace(c) && (c == '\t' || !is_cntrl_char(c))
-#endif
- ;
+ return iswspace(wc) && (wc == '\t' || !is_cntrl_wchar(wc));
}
+#endif
/* This function is equivalent to isblank() for multibyte characters. */
bool is_blank_mbchar(const char *c)
@@ -108,25 +98,11 @@ bool is_blank_mbchar(const char *c)
wc = (unsigned char)*c;
}
- return is_blank_wchar(wc);
+ return iswblank(wc);
} else
#endif
- return is_blank_char((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
- ;
+ return isblank((unsigned char)*c);
}
-#endif
/* This function is equivalent to iscntrl(), except in that it also
* handles control characters with their high bits set. */
@@ -136,6 +112,17 @@ bool is_cntrl_char(int c)
(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,
* except in that it also handles multibyte control characters with
* their high bits set. */
@@ -159,16 +146,6 @@ bool is_cntrl_mbchar(const 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
* is c + 64. We return that character. */
unsigned char control_rep(unsigned char c)
@@ -182,7 +159,22 @@ unsigned char control_rep(unsigned char c)
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. */
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
}
-#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. */
int mbwidth(const char *c)
{
diff --git a/src/nano.h b/src/nano.h
@@ -105,8 +105,15 @@
#endif
#endif
-/* If no strcasecmp(), strncasecmp(), strcasestr(), strnlen(),
- * getdelim(), or getline(), use the versions we have. */
+/* If no isblank(), iswblank(), strcasecmp(), strncasecmp(),
+ * 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
#define strcasecmp nstrcasecmp
#endif
diff --git a/src/proto.h b/src/proto.h
@@ -160,26 +160,24 @@ extern char *homedir;
/* Public functions in chars.c. */
bool is_byte(int c);
-bool is_alnum_char(int c);
bool is_alnum_mbchar(const char *c);
-#ifdef NANO_WIDE
-bool is_alnum_wchar(wchar_t wc);
+#ifndef HAVE_ISBLANK
+bool nisblank(int c);
#endif
-bool is_blank_char(int c);
-bool is_blank_mbchar(const char *c);
-#ifdef NANO_WIDE
-bool is_blank_wchar(wchar_t wc);
+#if defined(NANO_WIDE) && !defined(HAVE_ISWBLANK)
+bool niswblank(wint_t wc);
#endif
+bool is_blank_mbchar(const char *c);
bool is_cntrl_char(int c);
-bool is_cntrl_mbchar(const char *c);
#ifdef NANO_WIDE
-bool is_cntrl_wchar(wchar_t wc);
+bool is_cntrl_wchar(wint_t wc);
#endif
+bool is_cntrl_mbchar(const char *c);
unsigned char control_rep(unsigned char c);
-char *control_mbrep(const char *c, char *crep, int *crep_len);
#ifdef NANO_WIDE
wchar_t control_wrep(wchar_t c);
#endif
+char *control_mbrep(const char *c, char *crep, int *crep_len);
int mbwidth(const char *c);
int mb_cur_max(void);
char *make_mbchar(int chr, int *chr_mb_len);
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -129,7 +129,7 @@ void rcfile_error(const char *msg, ...)
* the end of the line. */
char *parse_next_word(char *ptr)
{
- while (!is_blank_char(*ptr) && *ptr != '\0')
+ while (!isblank(*ptr) && *ptr != '\0')
ptr++;
if (*ptr == '\0')
@@ -138,7 +138,7 @@ char *parse_next_word(char *ptr)
/* Null-terminate and advance ptr. */
*ptr++ = '\0';
- while (is_blank_char(*ptr))
+ while (isblank(*ptr))
ptr++;
return ptr;
@@ -178,7 +178,7 @@ char *parse_argument(char *ptr)
ptr = last_quote + 1;
}
if (ptr != NULL)
- while (is_blank_char(*ptr))
+ while (isblank(*ptr))
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
* blank character, or \0. */
- while ((*ptr != '"' || (!is_blank_char(*(ptr + 1)) &&
+ while ((*ptr != '"' || (!isblank(*(ptr + 1)) &&
*(ptr + 1) != '\0')) && *ptr != '\0')
ptr++;
@@ -242,7 +242,7 @@ char *parse_next_regex(char *ptr)
/* Null terminate and advance ptr. */
*ptr++ = '\0';
- while (is_blank_char(*ptr))
+ while (isblank(*ptr))
ptr++;
return ptr;
@@ -507,7 +507,7 @@ void parse_rcfile(FILE *rcstream)
lineno++;
ptr = buf;
- while (is_blank_char(*ptr))
+ while (isblank(*ptr))
ptr++;
/* If we have a blank line or a comment, skip to the next