improvements to wide/multibyte character input and output, using wide
curses functions where applicable


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2182 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
diff --git a/src/nano.c b/src/nano.c
index abdd425..e1cf6ad 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -3567,26 +3567,22 @@
 	/* Do we have to call edit_refresh(), or can we get away with
 	 * update_line()? */
 
-    char key[
 #ifdef NANO_WIDE
-	MB_LEN_MAX
+    char *key =
+	charalloc(MB_CUR_MAX)
 #else
-	1
+	charalloc(1)
 #endif
-	];		/* The current multibyte character we have. */
-    int key_len;	/* The length of the current multibyte
-			 * character. */
+	;
 
     assert(current != NULL && current->data != NULL);
 
     /* Turn off constant cursor position display. */
     UNSET(CONSTUPDATE);
 
-#ifdef NANO_WIDE
-    wctomb(NULL, 0);
-#endif
-
     for (i = 0; i < kbinput_len; i++) {
+	int key_len;
+
 	/* Null to newline, if needed. */
 	if (kbinput[i] == '\0')
 	    kbinput[i] = '\n';
@@ -3628,7 +3624,7 @@
 	charcpy(&current->data[current_x], key, key_len);
 	current_len += key_len;
 	/* FIXME: Should totsize be the number of single-byte characters
-	 * or the number of multibyte characters?  Assume for former for
+	 * or the number of multibyte characters?  Assume the former for
 	 * now. */
 	totsize += key_len;
 	set_modified();
@@ -3669,15 +3665,13 @@
 #endif
     }
 
-#ifdef NANO_WIDE
-    wctomb(NULL, 0);
-#endif
-
     /* Turn constant cursor position display back on if it was on
      * before. */
     if (old_constupdate)
 	SET(CONSTUPDATE);
 
+    free(key);
+
     if (do_refresh)
 	edit_refresh();
     else