break_line(), do_para_search() (renamed find_paragraph()), and
do_justify(); removal of breakable(). (DLR)
- Still more steps toward full wide/multibyte character support.
- Make whitespace display mode work with multibyte characters,
+ Make sure all rcfile arguments are valid multibyte strings,
+ make whitespace display mode work with multibyte characters,
and add a few related documentation updates. New function
- make_mbstring(); changes to do_help(), main(), parse_rcfile(),
- and display_string(). (DLR)
+ make_mbstring(); changes to make_mbchar(), make_mbstring(),
+ do_help(), main(), parse_rcfile(), and display_string(). (DLR)
- cut.c:
do_cut_text()
- If keep_cutbuffer is FALSE, only blow away the text in the
}
/* Convert the value in chr to a multibyte character with the same
- * wide character value as chr. Return the multibyte character and its
- * length. */
-char *make_mbchar(int chr, char *chr_mb, int *chr_mb_len)
+ * wide character value as chr. Return the (dynamically allocated)
+ * multibyte character and its length. */
+char *make_mbchar(int chr, int *chr_mb_len)
{
assert(chr_mb != NULL && chr_mb_len != NULL);
+ char *chr_mb;
+
#ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) {
+ chr_mb = charalloc(MB_CUR_MAX);
*chr_mb_len = wctomb(chr_mb, chr);
if (*chr_mb_len <= 0) {
} else {
#endif
*chr_mb_len = 1;
+ chr_mb = charalloc(1);
chr_mb[0] = (char)chr;
#ifdef NANO_WIDE
}
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
/* Convert the string str to a valid multibyte string with the same wide
- * character values as str. Return the multibyte string. */
-char *make_mbstring(char *str, char *str_mb)
+ * character values as str. Return the (dynamically allocated)
+ * multibyte string. */
+char *make_mbstring(char *str)
{
- assert(str != NULL && str_mb != NULL);
+ assert(str != NULL);
+
+ char *str_mb;
#ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) {
char *chr_mb = charalloc(MB_CUR_MAX);
int chr_mb_len;
- size_t str_mb_len = 0;
-
str_mb = charalloc((MB_CUR_MAX * strlen(str)) + 1);
+ size_t str_mb_len = 0;
while (*str != '\0') {
bool bad_char;
chr_mb_len = parse_mbchar(str, chr_mb, &bad_char, NULL);
if (bad_char) {
- char *bad_chr_mb = charalloc(MB_CUR_MAX);
+ char *bad_chr_mb;
int bad_chr_mb_len;
bad_chr_mb = make_mbchar((unsigned char)chr_mb[0],
- bad_chr_mb, &bad_chr_mb_len);
+ &bad_chr_mb_len);
for (i = 0; i < bad_chr_mb_len; i++)
str_mb[str_mb_len + i] = bad_chr_mb[i];
#endif
int mbwidth(const char *c);
int mb_cur_max(void);
-char *make_mbchar(int chr, char *chr_mb, int *chr_mb_len);
+char *make_mbchar(int chr, int *chr_mb_len);
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
-char *make_mbstring(char *str, char *str_mb);
+char *make_mbstring(char *str);
#endif
int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t
*col);
if (*option == '"')
option++;
ptr = parse_argument(ptr);
+ option = make_mbstring(option);
#ifdef DEBUG
fprintf(stderr, "option = \"%s\"\n", option);
#endif
#ifndef DISABLE_OPERATINGDIR
if (strcasecmp(rcopts[i].name, "operatingdir") == 0)
- operating_dir = mallocstrcpy(NULL, option);
+ operating_dir = option;
else
#endif
#ifndef DISABLE_WRAPJUSTIFY
N_("Requested fill size %s invalid"),
option);
wrap_at = -CHARS_FROM_EOL;
- }
+ } else
+ free(option);
} else
#endif
#ifndef NANO_SMALL
if (strcasecmp(rcopts[i].name, "whitespace") == 0) {
- whitespace = make_mbstring(option, whitespace);
+ whitespace = option;
if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) {
rcfile_error(
N_("Two single-column characters required"));
#endif
#ifndef DISABLE_JUSTIFY
if (strcasecmp(rcopts[i].name, "punct") == 0) {
- punct = mallocstrcpy(NULL, option);
+ punct = option;
if (strchr(punct, '\t') != NULL ||
strchr(punct, ' ') != NULL) {
rcfile_error(
}
} else if (strcasecmp(rcopts[i].name,
"brackets") == 0) {
- brackets = mallocstrcpy(NULL, option);
+ brackets = option;
if (strchr(brackets, '\t') != NULL ||
strchr(brackets, ' ') != NULL) {
rcfile_error(
}
} else if (strcasecmp(rcopts[i].name,
"quotestr") == 0)
- quotestr = mallocstrcpy(NULL, option);
+ quotestr = option;
else
#endif
#ifndef NANO_SMALL
if (strcasecmp(rcopts[i].name,
"backupdir") == 0)
- backup_dir = mallocstrcpy(NULL, option);
+ backup_dir = option;
else
#endif
#ifndef DISABLE_SPELLER
if (strcasecmp(rcopts[i].name, "speller") == 0)
- alt_speller = mallocstrcpy(NULL, option);
+ alt_speller = option;
else
#endif
if (strcasecmp(rcopts[i].name,
N_("Requested tab size %s invalid"),
option);
tabsize = -1;
- }
+ } else
+ free(option);
} else
assert(FALSE);
}
);
if (byte != ERR) {
- char *byte_mb = charalloc(mb_cur_max());
+ char *byte_mb;
int byte_mb_len, *seq, i;
/* If we've read in a complete byte
/* Put back the multibyte equivalent of the
* byte value. */
- byte_mb = make_mbchar(byte, byte_mb,
- &byte_mb_len);
+ byte_mb = make_mbchar(byte, &byte_mb_len);
seq = (int *)nmalloc(byte_mb_len *
sizeof(int));
/* Otherwise, read in keystrokes until we have a complete word
* sequence, and put back the corresponding word value. */
else {
- char *word_mb = charalloc(mb_cur_max());
+ char *word_mb;
int word_mb_len, *seq, i;
while (word == ERR) {
}
/* Put back the multibyte equivalent of the word value. */
- word_mb = make_mbchar(word, word_mb, &word_mb_len);
+ word_mb = make_mbchar(word, &word_mb_len);
seq = (int *)nmalloc(word_mb_len * sizeof(int));
* character, interpret that character as though it's a
* normal non-control character. */
if (!ISSET(NO_UTF8) && bad_char) {
- char *bad_buf_mb = charalloc(mb_cur_max());
+ char *bad_buf_mb;
int bad_buf_mb_len;
bad_buf_mb = make_mbchar((unsigned char)*buf_mb,
- bad_buf_mb, &bad_buf_mb_len);
+ &bad_buf_mb_len);
for (i = 0; i < bad_buf_mb_len; i++)
converted[index++] = bad_buf_mb[i];