wrappers; change other ctype wrappers to take wint_t instead
of wchar_t; rename some functions for consistency; and don't
count matches between valid and invalid multibyte sequences
- anymore, as it causes problems when doing a replace. Changes
- to is_alnum_mbchar(), is_blank_char() (renamed nisblank()),
- is_blank_mbchar(), is_blank_wchar() (renamed niswblank()),
- is_cntrl_wchar(), control_rep(), control_mbrep(),
- mbstrncasecmp(), mbstrcasestr(), mbrevstrcasestr(), etc.;
- removal of is_alnum_char() and is_alnum_wchar(). (DLR)
+ anymore, as it causes problems when doing a replace. New
+ function is_valid_mbstring(); changes to is_alnum_mbchar(),
+ is_blank_char() (renamed nisblank()), is_blank_mbchar(),
+ is_blank_wchar() (renamed niswblank()), is_cntrl_wchar(),
+ control_rep(), control_mbrep(), make_mbstring() (renamed
+ make_valid_mbstring()), mbstrncasecmp(), mbstrcasestr(),
+ mbrevstrcasestr(), etc.; removal of is_alnum_char() and
+ is_alnum_wchar(). (DLR)
- Implement word count via Meta-D at the main window. Note that
this is disabled when NANO_SMALL is defined. New functions
do_word_count() and do_next_word_void(); changes to
(DLR)
- Properly generate an error if we get a color directive without
a regex string. (DLR)
+ parse_rcfile()
+ - Properly generate an error if we get an invalid multibyte
+ string for an option, instead of working around it. (DLR)
- search.c:
do_gotoline()
- Properly show an error message if we try to go to line 0,
return chr_mb;
}
-#if defined(ENABLE_NANORC) || defined(NANO_EXTRA)
+#ifdef ENABLE_NANORC
+/* Check if the string str is a valid multibyte string. Return TRUE if
+ * it is, and FALSE otherwise. */
+bool is_valid_mbstring(const char *str)
+{
+ assert(str != NULL);
+
+#ifdef NANO_WIDE
+ if (!ISSET(NO_UTF8)) {
+ while (*str != '\0') {
+ int chr_mb_len;
+ bool bad_chr;
+
+ chr_mb_len = parse_mbchar(str, NULL, &bad_chr, NULL);
+
+ if (bad_chr)
+ return FALSE;
+
+ str += chr_mb_len;
+ }
+ }
+#endif
+
+ return TRUE;
+}
+#endif /* ENABLE_NANORC */
+
+#ifdef NANO_EXTRA
/* Convert the string str to a valid multibyte string with the same wide
* character values as str. Return the (dynamically allocated)
* multibyte string. */
-char *make_mbstring(const char *str)
+char *make_valid_mbstring(const char *str)
{
assert(str != NULL);
#ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) {
char *chr_mb = charalloc(MB_CUR_MAX);
- int chr_mb_len;
char *str_mb = charalloc((MB_CUR_MAX * strlen(str)) + 1);
size_t str_mb_len = 0;
while (*str != '\0') {
+ int chr_mb_len, i;
bool bad_chr;
- int i;
chr_mb_len = parse_mbchar(str, chr_mb, &bad_chr, NULL);
#endif
return mallocstrcpy(NULL, str);
}
-#endif /* ENABLE_NANORC || NANO_EXTRA */
+#endif /* NANO_EXTRA */
/* Parse a multibyte character from buf. Return the number of bytes
* used. If chr isn't NULL, store the multibyte character in it. If
int mbwidth(const char *c);
int mb_cur_max(void);
char *make_mbchar(int chr, int *chr_mb_len);
-#if defined(ENABLE_NANORC) || defined(NANO_EXTRA)
-char *make_mbstring(const char *str);
+#ifdef ENABLE_NANORC
+bool is_valid_mbstring(const char *str);
+#endif
+#ifdef NANO_EXTRA
+char *make_valid_mbstring(const char *str);
#endif
int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t
*col);
option++;
ptr = parse_argument(ptr);
- /* Make sure option is a valid multibyte
- * string. */
- option = make_mbstring(option);
+ option = mallocstrcpy(NULL, option);
#ifdef DEBUG
fprintf(stderr, "option = \"%s\"\n", option);
#endif
+
+ /* Make sure option is a valid multibyte
+ * string. */
+ if (!is_valid_mbstring(option)) {
+ rcfile_error(
+ N_("Option is not a valid multibyte string"));
+ break;
+ }
+
#ifndef DISABLE_OPERATINGDIR
if (strcasecmp(rcopts[i].name, "operatingdir") == 0)
operating_dir = option;
#ifndef NANO_SMALL
if (strcasecmp(rcopts[i].name, "whitespace") == 0) {
whitespace = option;
- if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) {
+ if (mbstrlen(whitespace) != 2 ||
+ strlenpt(whitespace) != 2) {
rcfile_error(
N_("Two single-column characters required"));
free(whitespace);
what = mallocstrcpy(NULL, _(xlcredits[xlpos]));
xlpos++;
} else
- what = make_mbstring(credits[crpos]);
+ what = make_valid_mbstring(credits[crpos]);
start_x = COLS / 2 - strlenpt(what) / 2 - 1;
mvwaddstr(edit, editwinrows - 1 - (editwinrows % 2),