commit 496488c5d21d68fd51978c256f963dc74535513b
parent a17a130d6c0bfa883a92ba44a2f05fb22c32196c
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Wed, 16 Mar 2005 15:34:22 +0000
when getting printable input from the edit window or statusbar prompt,
don't swallow non-ASCII control characters, since they're parts of UTF-8
sequences
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2378 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
6 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -94,17 +94,17 @@ CVS code -
support to a few more functions as well, and move multibyte
character-specific functions to their own source file. New
file chars.c; new functions is_alnum_char(),
- is_alnum_mbchar(), is_alnum_wchar(), is_blank_mbchar(),
- is_blank_wchar(), is_cntrl_mbchar(), is_cntrl_wchar(),
- control_mbrep(), control_wrep(), mbwidth(), mb_cur_max(),
- make_mbchar(), mbstrlen(), mbstrnlen(), mbstrcasecmp(),
- mbstrncasecmp(), mbstrcasestr(), and mbrevstrcasestr();
- changes to help_init(), is_byte() (moved to chars.c),
- is_blank_char() (moved to chars.c), is_cntrl_char() (moved to
- chars.c), nstricmp() (renamed nstrcasecmp() and moved to
- chars.c), nstrnicmp() (renamed nstrncasecmp() and moved to
- chars.c), nstristr() (renamed nstrcasestr() and moved to
- chars.c), revstrstr() (moved to chars.c), revstristr()
+ is_alnum_mbchar(), is_alnum_wchar(), is_ascii_char(),
+ is_blank_mbchar(), is_blank_wchar(), is_cntrl_mbchar(),
+ is_cntrl_wchar(), control_mbrep(), control_wrep(), mbwidth(),
+ mb_cur_max(), make_mbchar(), mbstrlen(), mbstrnlen(),
+ mbstrcasecmp(), mbstrncasecmp(), mbstrcasestr(), and
+ mbrevstrcasestr(); changes to help_init(), is_byte() (moved to
+ chars.c), is_blank_char() (moved to chars.c), is_cntrl_char()
+ (moved to chars.c), nstricmp() (renamed nstrcasecmp() and
+ moved to chars.c), nstrnicmp() (renamed nstrncasecmp() and
+ moved to chars.c), nstristr() (renamed nstrcasestr() and moved
+ to chars.c), revstrstr() (moved to chars.c), revstristr()
(renamed revstrcasestr() and moved to chars.c), nstrnlen()
(moved to chars.c), parse_char() (renamed parse_mbchar() and
moved to chars.c), move_left() (renamed move_mbleft() and
@@ -328,8 +328,8 @@ CVS code -
obsolete and it defines a struct termio that we don't use
anywhere. (DLR)
- Typo fixes. (DLR)
- - Add checks for iswalnum(), iswblank() or iswspace(), mblen(),
- and wctype.h. (DLR)
+ - Add checks for isascii(), iswalnum(), iswblank() or
+ iswspace(), mblen(), and wctype.h. (DLR)
- doc/faq.html:
- Remove now-inaccurate note about verbatim input's not working
at prompts, and update its description to mention that it
diff --git a/configure.ac b/configure.ac
@@ -291,7 +291,7 @@ AC_MSG_WARN([*** Can not use slang when cross-compiling])),
esac], [AC_MSG_RESULT(no)])
dnl Checks for functions
-AC_CHECK_FUNCS(snprintf vsnprintf isblank iswalnum iswblank iswspace strcasecmp strncasecmp strcasestr strnlen getline getdelim mblen mbtowc wctomb wcwidth)
+AC_CHECK_FUNCS(snprintf vsnprintf isascii isblank iswalnum iswblank iswspace strcasecmp strncasecmp strcasestr strnlen getline getdelim mblen mbtowc wctomb wcwidth)
if test "x$ac_cv_func_snprintf" = "xno" -o "x$ac_cv_func_vsnprintf" = "xno"
then
AM_PATH_GLIB_2_0(2.0.0,,
diff --git a/src/chars.c b/src/chars.c
@@ -81,6 +81,18 @@ bool is_alnum_wchar(wchar_t wc)
}
#endif
+/* This function is equivalent to isascii(). */
+bool is_ascii_char(int c)
+{
+ return
+#ifdef HAVE_ISASCII
+ isascii(c)
+#else
+ ((unsigned int)c == (signed char)c)
+#endif
+ ;
+}
+
/* This function is equivalent to isblank(). */
bool is_blank_char(int c)
{
diff --git a/src/nano.c b/src/nano.c
@@ -3616,10 +3616,11 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
if (allow_funcs) {
/* If we got a character, and it isn't a shortcut, toggle, or
- * control character, it's a normal text character. Display the
- * warning if we're in view mode, or add the character to the
- * input buffer if we're not. */
- if (input != ERR && *s_or_t == FALSE && !is_cntrl_char(input)) {
+ * ASCII control character, it's a normal text character.
+ * Display the warning if we're in view mode, or add the
+ * character to the input buffer if we're not. */
+ if (input != ERR && *s_or_t == FALSE &&
+ (!is_ascii_char(input) || !is_cntrl_char(input))) {
if (ISSET(VIEW_MODE))
print_view_warning();
else {
diff --git a/src/proto.h b/src/proto.h
@@ -157,6 +157,7 @@ bool is_alnum_mbchar(const char *c);
#ifdef NANO_WIDE
bool is_alnum_wchar(wchar_t wc);
#endif
+bool is_ascii_char(int c);
bool is_blank_char(int c);
bool is_blank_mbchar(const char *c);
#ifdef NANO_WIDE
diff --git a/src/winio.c b/src/winio.c
@@ -1676,7 +1676,12 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
*s_or_t = have_shortcut;
if (allow_funcs) {
- if (input != ERR && *s_or_t == FALSE && !is_cntrl_char(input)) {
+ /* If we got a character, and it isn't a shortcut, toggle, or
+ * ASCII control character, it's a normal text character.
+ * Display the warning if we're in view mode, or add the
+ * character to the input buffer if we're not. */
+ if (input != ERR && *s_or_t == FALSE &&
+ (!is_ascii_char(input) || !is_cntrl_char(input))) {
/* If we're using restricted mode, the filename isn't blank,
* and we're at the "Write File" prompt, disable text
* input. */