mirror of git://git.sv.gnu.org/nano.git
control characters can only be properly filtered out in both non-UTF-8
and UTF-8 mode inside the output routines, so do it there instead of inside the input routines git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2382 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
77abec7ecf
commit
efec641a82
22
ChangeLog
22
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_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()
|
||||
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()
|
||||
(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
|
||||
|
|
|
@ -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 isascii isblank iswalnum iswblank iswspace strcasecmp strncasecmp strcasestr strnlen getline getdelim mblen mbtowc wctomb wcwidth)
|
||||
AC_CHECK_FUNCS(snprintf vsnprintf 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,,
|
||||
|
|
12
src/chars.c
12
src/chars.c
|
@ -79,18 +79,6 @@ bool is_alnum_wchar(wchar_t wc)
|
|||
{
|
||||
return iswalnum(wc);
|
||||
}
|
||||
|
||||
/* 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
|
||||
;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function is equivalent to isblank(). */
|
||||
|
|
57
src/nano.c
57
src/nano.c
|
@ -1210,14 +1210,15 @@ void do_verbatim_input(void)
|
|||
/* Read in all the verbatim characters. */
|
||||
kbinput = get_verbatim_kbinput(edit, &kbinput_len);
|
||||
|
||||
/* Display all the verbatim characters at once. */
|
||||
/* Display all the verbatim characters at once, not filtering out
|
||||
* control characters. */
|
||||
output = charalloc(kbinput_len + 1);
|
||||
|
||||
for (i = 0; i < kbinput_len; i++)
|
||||
output[i] = (char)kbinput[i];
|
||||
output[i] = '\0';
|
||||
|
||||
do_output(output, kbinput_len);
|
||||
do_output(output, kbinput_len, TRUE);
|
||||
|
||||
free(output);
|
||||
}
|
||||
|
@ -1313,7 +1314,7 @@ void do_tab(void)
|
|||
{
|
||||
char *kbinput = "\t";
|
||||
|
||||
do_output(kbinput, 1);
|
||||
do_output(kbinput, 1, TRUE);
|
||||
}
|
||||
|
||||
/* Someone hits return *gasp!* */
|
||||
|
@ -3615,18 +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 && (
|
||||
#ifdef NANO_WIDE
|
||||
/* Keep non-ASCII control characters if we're in UTF-8
|
||||
* mode, since they might be part of a UTF-8
|
||||
* sequence. */
|
||||
(!ISSET(NO_UTF8) && !is_ascii_char(input)) ||
|
||||
#endif
|
||||
!is_cntrl_char(input))) {
|
||||
/* If we got a character, and it isn't a shortcut or toggle,
|
||||
* 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) {
|
||||
if (ISSET(VIEW_MODE))
|
||||
print_view_warning();
|
||||
else {
|
||||
|
@ -3645,7 +3639,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
|||
if (*s_or_t == TRUE || get_buffer_len() == 0) {
|
||||
if (kbinput != NULL) {
|
||||
/* Display all the characters in the input buffer at
|
||||
* once. */
|
||||
* once, filtering out control characters. */
|
||||
char *output = charalloc(kbinput_len + 1);
|
||||
size_t i;
|
||||
|
||||
|
@ -3653,7 +3647,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
|||
output[i] = (char)kbinput[i];
|
||||
output[i] = '\0';
|
||||
|
||||
do_output(output, kbinput_len);
|
||||
do_output(output, kbinput_len, FALSE);
|
||||
|
||||
free(output);
|
||||
|
||||
|
@ -3776,8 +3770,9 @@ bool do_mouse(void)
|
|||
#endif /* !DISABLE_MOUSE */
|
||||
|
||||
/* The user typed kbinput_len multibyte characters. Add them to the
|
||||
* edit buffer. */
|
||||
void do_output(char *output, size_t output_len)
|
||||
* edit buffer, filtering out all control characters if allow_cntrls is
|
||||
* TRUE. */
|
||||
void do_output(char *output, size_t output_len, bool allow_cntrls)
|
||||
{
|
||||
size_t current_len = strlen(current->data), i = 0;
|
||||
bool old_constupdate = ISSET(CONSTUPDATE);
|
||||
|
@ -3794,14 +3789,18 @@ void do_output(char *output, size_t output_len)
|
|||
UNSET(CONSTUPDATE);
|
||||
|
||||
while (i < output_len) {
|
||||
/* Null to newline, if needed. */
|
||||
if (output[i] == '\0')
|
||||
output[i] = '\n';
|
||||
/* Newline to Enter, if needed. */
|
||||
else if (output[i] == '\n') {
|
||||
do_enter();
|
||||
i++;
|
||||
continue;
|
||||
/* If allow_cntrls is FALSE, filter out nulls and newlines,
|
||||
* since they're control characters. */
|
||||
if (allow_cntrls) {
|
||||
/* Null to newline, if needed. */
|
||||
if (output[i] == '\0')
|
||||
output[i] = '\n';
|
||||
/* Newline to Enter, if needed. */
|
||||
else if (output[i] == '\n') {
|
||||
do_enter();
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Interpret the next multibyte character. If it's an invalid
|
||||
|
@ -3811,6 +3810,10 @@ void do_output(char *output, size_t output_len)
|
|||
|
||||
i += char_buf_len;
|
||||
|
||||
/* If allow_cntrls is FALSE, filter out a control character. */
|
||||
if (!allow_cntrls && is_cntrl_mbchar(output + i - char_buf_len))
|
||||
continue;
|
||||
|
||||
/* When a character is inserted on the current magicline, it
|
||||
* means we need a new one! */
|
||||
if (filebot == current)
|
||||
|
|
|
@ -156,7 +156,6 @@ bool is_alnum_char(int c);
|
|||
bool is_alnum_mbchar(const char *c);
|
||||
#ifdef NANO_WIDE
|
||||
bool is_alnum_wchar(wchar_t wc);
|
||||
bool is_ascii_char(int c);
|
||||
#endif
|
||||
bool is_blank_char(int c);
|
||||
bool is_blank_mbchar(const char *c);
|
||||
|
@ -463,7 +462,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
|||
#ifndef DISABLE_MOUSE
|
||||
bool do_mouse(void);
|
||||
#endif
|
||||
void do_output(char *output, size_t output_len);
|
||||
void do_output(char *output, size_t output_len, bool allow_cntrls);
|
||||
|
||||
/* Public functions in rcfile.c. */
|
||||
#ifdef ENABLE_NANORC
|
||||
|
@ -626,7 +625,7 @@ void do_statusbar_prev_word(void);
|
|||
#endif
|
||||
void do_statusbar_verbatim_input(bool *got_enter);
|
||||
void do_statusbar_output(char *output, size_t output_len, bool
|
||||
*got_enter);
|
||||
*got_enter, bool allow_cntrls);
|
||||
size_t xplustabs(void);
|
||||
size_t actual_x(const char *str, size_t xplus);
|
||||
size_t strnlenpt(const char *buf, size_t size);
|
||||
|
|
60
src/winio.c
60
src/winio.c
|
@ -1676,18 +1676,11 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
|||
*s_or_t = have_shortcut;
|
||||
|
||||
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 && (
|
||||
#ifdef NANO_WIDE
|
||||
/* Keep non-ASCII control characters if we're in UTF-8
|
||||
* mode, since they might be part of a UTF-8
|
||||
* sequence. */
|
||||
(!ISSET(NO_UTF8) && !is_ascii_char(input)) ||
|
||||
#endif
|
||||
!is_cntrl_char(input))) {
|
||||
/* If we got a character, and it isn't a shortcut or toggle,
|
||||
* 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) {
|
||||
/* If we're using restricted mode, the filename isn't blank,
|
||||
* and we're at the "Write File" prompt, disable text
|
||||
* input. */
|
||||
|
@ -1707,7 +1700,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
|||
if (kbinput != NULL) {
|
||||
|
||||
/* Display all the characters in the input buffer at
|
||||
* once. */
|
||||
* once, filtering out control characters. */
|
||||
char *output = charalloc(kbinput_len + 1);
|
||||
size_t i;
|
||||
bool got_enter;
|
||||
|
@ -1717,7 +1710,8 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
|||
output[i] = (char)kbinput[i];
|
||||
output[i] = '\0';
|
||||
|
||||
do_statusbar_output(output, kbinput_len, &got_enter);
|
||||
do_statusbar_output(output, kbinput_len, &got_enter,
|
||||
FALSE);
|
||||
|
||||
free(output);
|
||||
|
||||
|
@ -2037,20 +2031,21 @@ void do_statusbar_verbatim_input(bool *got_enter)
|
|||
/* Read in all the verbatim characters. */
|
||||
kbinput = get_verbatim_kbinput(bottomwin, &kbinput_len);
|
||||
|
||||
/* Display all the verbatim characters at once. */
|
||||
/* Display all the verbatim characters at once, not filtering out
|
||||
* control characters. */
|
||||
output = charalloc(kbinput_len + 1);
|
||||
|
||||
for (i = 0; i < kbinput_len; i++)
|
||||
output[i] = (char)kbinput[i];
|
||||
output[i] = '\0';
|
||||
|
||||
do_statusbar_output(output, kbinput_len, got_enter);
|
||||
do_statusbar_output(output, kbinput_len, got_enter, TRUE);
|
||||
|
||||
free(output);
|
||||
}
|
||||
|
||||
void do_statusbar_output(char *output, size_t output_len, bool
|
||||
*got_enter)
|
||||
*got_enter, bool allow_cntrls)
|
||||
{
|
||||
size_t answer_len = strlen(answer), i = 0;
|
||||
char *char_buf = charalloc(mb_cur_max());
|
||||
|
@ -2061,17 +2056,22 @@ void do_statusbar_output(char *output, size_t output_len, bool
|
|||
*got_enter = FALSE;
|
||||
|
||||
while (i < output_len) {
|
||||
/* Null to newline, if needed. */
|
||||
if (output[i] == '\0')
|
||||
output[i] = '\n';
|
||||
/* Newline to Enter, if needed. */
|
||||
else if (output[i] == '\n') {
|
||||
/* Set got_enter to TRUE to indicate that we got the Enter
|
||||
* key, put back the rest of the characters in output so
|
||||
* that they can be parsed and output again, and get out. */
|
||||
*got_enter = TRUE;
|
||||
unparse_kbinput(output + i, output_len - i);
|
||||
return;
|
||||
/* If allow_cntrls is FALSE, filter out nulls and newlines,
|
||||
* since they're control characters. */
|
||||
if (allow_cntrls) {
|
||||
/* Null to newline, if needed. */
|
||||
if (output[i] == '\0')
|
||||
output[i] = '\n';
|
||||
/* Newline to Enter, if needed. */
|
||||
else if (output[i] == '\n') {
|
||||
/* Set got_enter to TRUE to indicate that we got the
|
||||
* Enter key, put back the rest of the characters in
|
||||
* output so that they can be parsed and output again,
|
||||
* and get out. */
|
||||
*got_enter = TRUE;
|
||||
unparse_kbinput(output + i, output_len - i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Interpret the next multibyte character. If it's an invalid
|
||||
|
@ -2081,6 +2081,10 @@ void do_statusbar_output(char *output, size_t output_len, bool
|
|||
|
||||
i += char_buf_len;
|
||||
|
||||
/* If allow_cntrls is FALSE, filter out a control character. */
|
||||
if (!allow_cntrls && is_cntrl_mbchar(output + i - char_buf_len))
|
||||
continue;
|
||||
|
||||
/* More dangerousness fun =) */
|
||||
answer = charealloc(answer, answer_len + (char_buf_len * 2));
|
||||
|
||||
|
|
Loading…
Reference in New Issue