/* Search for a line in the history containing STRING. If DIR is < 0, the search is backwards through previous entries, else through subsequent entries. */ static void noninc_dosearch (char *string, int dir) { int oldpos, pos; HIST_ENTRY *entry; if (string == 0 || *string == '\0' || noninc_history_pos < 0) { DING (); return; } pos = noninc_search_from_pos (string, noninc_history_pos + dir, dir); if (pos == -1) { /* Search failed, current history position unchanged. */ maybe_unsave_line (); rl_clear_message (); rl_point = 0; DING (); return; } noninc_history_pos = pos; oldpos = where_history (); history_set_pos (noninc_history_pos); entry = current_history (); #if defined (VI_MODE) if (rl_editing_mode != vi_mode) #endif history_set_pos (oldpos); { int line_len; line_len = strlen (entry->line); if (line_len >= rl_line_buffer_len) rl_extend_line_buffer (line_len); strcpy (rl_line_buffer, entry->line); } rl_undo_list = (UNDO_LIST *)entry->data; rl_end = strlen (rl_line_buffer); rl_point = 0; rl_clear_message (); if (saved_line_for_history) _rl_free_history_entry (saved_line_for_history); saved_line_for_history = (HIST_ENTRY *)NULL; }
/* A simplified loop for vi. Don't dispatch key at end. Don't recognize minus sign? Should this do rl_save_prompt/rl_restore_prompt? */ static int rl_digit_loop1(void) { int key, c; RL_SETSTATE(RL_STATE_NUMERICARG); while (1) { if (rl_numeric_arg > 1000000) { rl_explicit_arg = rl_numeric_arg = 0; rl_ding (); rl_clear_message (); RL_UNSETSTATE(RL_STATE_NUMERICARG); return 1; } rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); RL_SETSTATE(RL_STATE_MOREINPUT); key = c = rl_read_key (); RL_UNSETSTATE(RL_STATE_MOREINPUT); if (c >= 0 && _rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument) { rl_numeric_arg *= 4; continue; } c = UNMETA (c); if (_rl_digit_p (c)) { if (rl_explicit_arg) rl_numeric_arg = (rl_numeric_arg * 10) + _rl_digit_value (c); else rl_numeric_arg = _rl_digit_value (c); rl_explicit_arg = 1; } else { rl_clear_message (); rl_stuff_char (key); break; } } RL_UNSETSTATE(RL_STATE_NUMERICARG); return (0); }
void __fmtstring(1, 0) cli_display(const char *fmt, va_list ap) { int point, end; char *buf; point = rl_point; end = rl_end; rl_point = rl_end = 0; rl_save_prompt(); rl_clear_message(); if (vasprintf(&buf, fmt, ap) < 0) fprintf(rl_outstream, "cli_display: out of memory\n"); else { fprintf(rl_outstream, "%s\n", buf); xfree(buf); } rl_restore_prompt(); rl_point = point; rl_end = end; rl_forced_update_display(); }
/* A simplified loop for vi. Don't dispatch key at end. Don't recognize minus sign? */ static int rl_digit_loop1 (void) { int key, c; while (1) { rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg, 0); key = c = rl_read_key (); if (_rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == (Function *)rl_universal_argument) { rl_numeric_arg *= 4; continue; } c = UNMETA (c); if (digit_p (c)) { if (rl_explicit_arg) rl_numeric_arg = (rl_numeric_arg * 10) + digit_value (c); else rl_numeric_arg = digit_value (c); rl_explicit_arg = 1; } else { rl_clear_message (); rl_stuff_char (key); break; } } return (0); }
/* What to do when you abort reading an argument. */ int rl_discard_argument (void) { rl_ding (); rl_clear_message (); _rl_reset_argument (); return 0; }
int _rl_arg_overflow () { if (rl_numeric_arg > 1000000) { _rl_argcxt = 0; rl_explicit_arg = rl_numeric_arg = 0; rl_ding (); rl_restore_prompt (); rl_clear_message (); RL_UNSETSTATE(RL_STATE_NUMERICARG); return 1; } return 0; }
/* display (or remove, if message == NULL) message in echo area, with the appropriate bookkeeping */ void message_in_echo_area(char *message) { static int message_in_echo_area = FALSE; DPRINTF1(DEBUG_READLINE, "message: %s", mangle_string_for_debug_log(message, MANGLE_LENGTH)); if (message) { rl_save_prompt(); message_in_echo_area = TRUE; rl_message(message); } else { if (message_in_echo_area) rl_restore_prompt(); rl_clear_message(); message_in_echo_area = FALSE; } }
/* How to abort things. */ int _rl_abort_internal (void) { rl_ding (); rl_clear_message (); _rl_reset_argument (); rl_clear_pending_input (); RL_UNSETSTATE (RL_STATE_MACRODEF); while (rl_executing_macro) _rl_pop_executing_macro (); RL_UNSETSTATE (RL_STATE_MULTIKEY); /* XXX */ rl_last_func = (rl_command_func_t *)NULL; _rl_longjmp (_rl_top_level, 1); return (0); }
static char *cli_append_multiline(char *line) { bool complete = false; size_t len; char *s; if (line == NULL && multiline == NULL) { eof = true; return NULL; } len = strlen(line); if (line[len - 1] == '\\') { line[len - 1] = '\0'; len--; } else if (multiline == NULL) return line; else complete = 1; if (multiline == NULL) { multiline = line; rl_save_prompt(); rl_clear_message(); rl_set_prompt(".... "); } else { len += strlen(multiline); s = xmalloc(len + 1); snprintf(s, len + 1, "%s%s", multiline, line); xfree(multiline); multiline = s; } line = NULL; if (complete) { line = multiline; multiline = NULL; rl_restore_prompt(); } return line; }
int _rl_arg_callback (_rl_arg_cxt cxt) { int c, r; c = _rl_arg_getchar (); if (c < 0) return (1); /* EOF */ if (_rl_argcxt & NUM_READONE) { _rl_argcxt &= ~NUM_READONE; rl_restore_prompt (); rl_clear_message (); RL_UNSETSTATE(RL_STATE_NUMERICARG); rl_execute_next (c); return 0; } r = _rl_arg_dispatch (cxt, c); if (r > 0) rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); return (r != 1); }
/* Search non-interactively through the history list. DIR < 0 means to search backwards through the history of previous commands; otherwise the search is for commands subsequent to the current position in the history list. PCHAR is the character to use for prompting when reading the search string; if not specified (0), it defaults to `:'. */ static void noninc_search (int dir, int pchar) { int saved_point, c, pmtlen; char *p; maybe_save_line (); saved_point = rl_point; /* Use the line buffer to read the search string. */ rl_line_buffer[0] = 0; rl_end = rl_point = 0; /* XXX - this needs fixing to work with the prompt expansion stuff - XXX */ pmtlen = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; p = xmalloc (2 + pmtlen); if (pmtlen) strcpy (p, rl_prompt); p[pmtlen] = pchar ? pchar : ':'; p[pmtlen + 1] = '\0'; rl_message (p, 0, 0); free (p); /* Read the search string. */ while ((c = rl_read_key ()) != '\0') { switch (c) { case CTRL('H'): case RUBOUT: if (rl_point == 0) { maybe_unsave_line (); rl_clear_message (); rl_point = saved_point; return; } rl_rubout (1, c); break; case CTRL('W'): rl_unix_word_rubout (1, c); break; case CTRL('U'): rl_unix_line_discard (1, c); break; case RETURN: case NEWLINE: goto dosearch; /* NOTREACHED */ break; case CTRL('C'): case CTRL('G'): maybe_unsave_line (); rl_clear_message (); rl_point = saved_point; DING (); return; default: rl_insert (1, c); break; } rl_redisplay (); } dosearch: /* If rl_point == 0, we want to re-use the previous search string and start from the saved history position. If there's no previous search string, punt. */ if (rl_point == 0) { if (!noninc_search_string) { DING (); return; } } else { /* We want to start the search from the current history position. */ noninc_history_pos = where_history (); if (noninc_search_string) free (noninc_search_string); noninc_search_string = strdup (rl_line_buffer); } noninc_dosearch (noninc_search_string, dir); }
/* Process C as part of the current numeric argument. Return -1 if the argument should be aborted, 0 if we should not read any more chars, and 1 if we should continue to read chars. */ int _rl_arg_dispatch (_rl_arg_cxt cxt, int c) { int key, r; key = c; /* If we see a key bound to `universal-argument' after seeing digits, it ends the argument but is otherwise ignored. */ if (c >= 0 && _rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument) { if ((cxt & NUM_SAWDIGITS) == 0) { rl_numeric_arg *= 4; return 1; } else if (RL_ISSTATE (RL_STATE_CALLBACK)) { _rl_argcxt |= NUM_READONE; return 0; /* XXX */ } else { RL_SETSTATE(RL_STATE_MOREINPUT); key = rl_read_key (); RL_UNSETSTATE(RL_STATE_MOREINPUT); rl_restore_prompt (); rl_clear_message (); RL_UNSETSTATE(RL_STATE_NUMERICARG); if (key < 0) return -1; return (_rl_dispatch (key, _rl_keymap)); } } c = UNMETA (c); if (_rl_digit_p (c)) { r = _rl_digit_value (c); rl_numeric_arg = rl_explicit_arg ? (rl_numeric_arg * 10) + r : r; rl_explicit_arg = 1; _rl_argcxt |= NUM_SAWDIGITS; } else if (c == '-' && rl_explicit_arg == 0) { rl_numeric_arg = 1; _rl_argcxt |= NUM_SAWMINUS; rl_arg_sign = -1; } else { /* Make M-- command equivalent to M--1 command. */ if ((_rl_argcxt & NUM_SAWMINUS) && rl_numeric_arg == 1 && rl_explicit_arg == 0) rl_explicit_arg = 1; rl_restore_prompt (); rl_clear_message (); RL_UNSETSTATE(RL_STATE_NUMERICARG); r = _rl_dispatch (key, _rl_keymap); if (RL_ISSTATE (RL_STATE_CALLBACK)) { /* At worst, this will cause an extra redisplay. Otherwise, we have to wait until the next character comes in. */ if (rl_done == 0) (*rl_redisplay_function) (); r = 0; } return r; } return 1; }