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
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,,
{
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(). */
/* 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);
}
{
char *kbinput = "\t";
- do_output(kbinput, 1);
+ do_output(kbinput, 1, TRUE);
}
/* Someone hits return *gasp!* */
);
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 {
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;
output[i] = (char)kbinput[i];
output[i] = '\0';
- do_output(output, kbinput_len);
+ do_output(output, kbinput_len, FALSE);
free(output);
#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);
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
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)
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);
#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
#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);
*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. */
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;
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);
/* 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());
*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
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));