/* add a character to a multi-character command. */ int mca_char(int c) { switch (mca) { case 0: /* not in a multicharacter command. */ case A_PREFIX: /* in the prefix of a command. */ return(NO_MCA); case A_DIGIT: /* * Entering digits of a number. * Terminated by a non-digit. */ if ((!isascii(c) || !isdigit(c)) && c != erase_char && c != kill_char && c != werase_char) { /* * Not part of the number. * Treat as a normal command character. */ *cp = '\0'; number = atoi(cmdbuf); CMD_RESET; mca = 0; return(NO_MCA); } break; } /* * Any other multicharacter command * is terminated by a newline. */ if (c == '\n' || c == '\r') { exec_mca(); return(MCA_DONE); } /* append the char to the command buffer. */ if (cmd_char(c)) return(MCA_DONE); return(MCA_MORE); }
/* * Handle a character of a multi-character command. */ static int mca_char(int c) { int ret; switch (mca) { case 0: /* * We're not in a multicharacter command. */ return (NO_MCA); case A_PREFIX: /* * In the prefix of a command. * This not considered a multichar command * (even tho it uses cmdbuf, etc.). * It is handled in the commands() switch. */ return (NO_MCA); case A_DIGIT: /* * Entering digits of a number. * Terminated by a non-digit. */ if (!((c >= '0' && c <= '9') || c == '.') && editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == A_INVALID) { /* * Not part of the number. * End the number and treat this char * as a normal command character. */ number = cmd_int(&fraction); mca = 0; cmd_accept(); return (NO_MCA); } break; case A_OPT_TOGGLE: ret = mca_opt_char(c); if (ret != NO_MCA) return (ret); break; case A_F_SEARCH: case A_B_SEARCH: case A_FILTER: ret = mca_search_char(c); if (ret != NO_MCA) return (ret); break; default: /* Other multicharacter command. */ break; } /* * The multichar command is terminated by a newline. */ if (c == '\n' || c == '\r') { /* * Execute the command. */ exec_mca(); return (MCA_DONE); } /* * Append the char to the command buffer. */ if (cmd_char(c) == CC_QUIT) /* * Abort the multi-char command. */ return (MCA_DONE); if ((mca == A_F_BRACKET || mca == A_B_BRACKET) && len_cmdbuf() >= 2) { /* * Special case for the bracket-matching commands. * Execute the command after getting exactly two * characters from the user. */ exec_mca(); return (MCA_DONE); } /* * Need another character. */ return (MCA_MORE); }