+static void
+vi_Back_motion(char *command)
+{
+ while (cursor > 0 && isspace(command[cursor-1]))
+ input_backward(1);
+ while (cursor > 0 && !isspace(command[cursor-1]))
+ input_backward(1);
+}
+
+static void
+vi_back_motion(char *command)
+{
+ if (cursor <= 0)
+ return;
+ input_backward(1);
+ while (cursor > 0 && isspace(command[cursor]))
+ input_backward(1);
+ if (cursor <= 0)
+ return;
+ if (isalnum(command[cursor]) || command[cursor] == '_') {
+ while (cursor > 0 &&
+ (isalnum(command[cursor-1]) ||
+ command[cursor-1] == '_'))
+ input_backward(1);
+ } else if (ispunct(command[cursor])) {
+ while (cursor > 0 &&
+ (ispunct(command[cursor-1])))
+ input_backward(1);
+ }
+}
+#endif
+
+/*
+ * the normal emacs mode and vi's insert mode are the same.
+ * commands entered when in vi command mode ("escape mode") get
+ * an extra bit added to distinguish them. this lets them share
+ * much of the code in the big switch and while loop. i
+ * experimented with an ugly macro to make the case labels for
+ * these cases go away entirely when vi mode isn't configured, in
+ * hopes of letting the jump tables get smaller:
+ * #define vcase(caselabel) caselabel
+ * and then
+ * case CNTRL('A'):
+ * case vcase(VICMD('0'):)
+ * but it didn't seem to make any difference in code size,
+ * and the macro-ized code was too ugly.
+ */
+
+#define VI_cmdbit 0x100
+#define VICMD(somecmd) ((somecmd)|VI_cmdbit)
+
+/* convert uppercase ascii to equivalent control char, for readability */
+#define CNTRL(uc_char) ((uc_char) - 0x40)
+
+
+int cmdedit_read_input(char *prompt, char command[BUFSIZ])
+{
+
+ int break_out = 0;
+ int lastWasTab = FALSE;
+ unsigned char c;
+#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
+ unsigned int ic, prevc;
+ int vi_cmdmode = 0;
+#endif
+ /* prepare before init handlers */
+ cmdedit_y = 0; /* quasireal y, not true work if line > xt*yt */
+ len = 0;
+ command_ps = command;
+
+ getTermSettings(0, (void *) &initial_settings);
+ memcpy(&new_settings, &initial_settings, sizeof(struct termios));
+ new_settings.c_lflag &= ~ICANON; /* unbuffered input */
+ /* Turn off echoing and CTRL-C, so we can trap it */
+ new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG);
+ /* Hmm, in linux c_cc[] not parsed if set ~ICANON */
+ new_settings.c_cc[VMIN] = 1;
+ new_settings.c_cc[VTIME] = 0;
+ /* Turn off CTRL-C, so we can trap it */
+# ifndef _POSIX_VDISABLE
+# define _POSIX_VDISABLE '\0'
+# endif
+ new_settings.c_cc[VINTR] = _POSIX_VDISABLE;