dumb: covert char input buffer to zchar
authorborg323 <4010067-borg323@users.noreply.gitlab.com>
Mon, 10 Jun 2019 16:31:56 +0000 (19:31 +0300)
committerborg323 <4010067-borg323@users.noreply.gitlab.com>
Mon, 10 Jun 2019 16:31:56 +0000 (19:31 +0300)
src/dumb/dumb_input.c

index 48a6ddc782dec509781f1f5fca9a2408fdbed45d..97ee4c135f7b295d203706c07375f4ded89e5e7f 100644 (file)
@@ -361,6 +361,9 @@ zchar os_read_line (int UNUSED (max), zchar *buf, int timeout, int UNUSED(width)
   int terminator;
   static bool timed_out_last_time;
   int timed_out;
+#ifdef USE_UTF8
+  int i, len;
+#endif
 
   /* Discard any keys read for single key input.  */
   read_key_buffer[0] = '\0';
@@ -396,7 +399,19 @@ zchar os_read_line (int UNUSED (max), zchar *buf, int timeout, int UNUSED(width)
   dumb_display_user_input(read_line_buffer);
 
   /* copy to the buffer and save the rest for next time.  */
+#ifndef USE_UTF8
   strncat((char*) buf, read_line_buffer, (INPUT_BUFFER_SIZE - strlen((char *)buf)) - 2);
+#else
+  for (len = 0;; len++)
+    if (!buf[len])
+      break;
+  for (i = 0; i < INPUT_BUFFER_SIZE - len - 2; i++) {
+    buf[len + i] = read_line_buffer[i];
+    if (!read_line_buffer[i])
+      break;
+  }
+  buf[len + i] = 0;
+#endif
   p = read_line_buffer + strlen(read_line_buffer) + 1;
   memmove(read_line_buffer, p, strlen(p) + 1);