Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libedit/readline.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libedit/readline.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.137 retrieving revision 1.143 diff -u -p -r1.137 -r1.143 --- src/lib/libedit/readline.c 2016/08/24 13:10:59 1.137 +++ src/lib/libedit/readline.c 2017/09/05 18:07:59 1.143 @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.137 2016/08/24 13:10:59 christos Exp $ */ +/* $NetBSD: readline.c,v 1.143 2017/09/05 18:07:59 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.137 2016/08/24 13:10:59 christos Exp $"); +__RCSID("$NetBSD: readline.c,v 1.143 2017/09/05 18:07:59 christos Exp $"); #endif /* not lint && not SCCSID */ #include @@ -122,6 +122,7 @@ int readline_echoing_p = 1; int _rl_print_completions_horizontally = 0; VFunction *rl_redisplay_function = NULL; Function *rl_startup_hook = NULL; +int rl_did_startup_hook = 0; VFunction *rl_completion_display_matches_hook = NULL; VFunction *rl_prep_term_function = (VFunction *)rl_prep_terminal; VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal; @@ -196,7 +197,7 @@ _getc_function(EditLine *el __attribute_ { int i; - i = (*rl_getc_function)(NULL); + i = (*rl_getc_function)(rl_instream); if (i == -1) return 0; *c = (wchar_t)i; @@ -289,7 +290,9 @@ rl_initialize(void) if (tcgetattr(fileno(rl_instream), &t) != -1 && (t.c_lflag & ECHO) == 0) editmode = 0; - e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr); + e = el_init_internal(rl_readline_name, rl_instream, rl_outstream, + stderr, fileno(rl_instream), fileno(rl_outstream), fileno(stderr), + NO_RESET); if (!editmode) el_set(e, EL_EDITMODE, 0); @@ -371,7 +374,7 @@ rl_initialize(void) el_set(e, EL_BIND, "\\e[1;5C", "em-next-word", NULL); el_set(e, EL_BIND, "\\e[1;5D", "ed-prev-word", NULL); el_set(e, EL_BIND, "\\e[5C", "em-next-word", NULL); - el_set(e, EL_BIND, "\\e[5D", "ed-erev-word", NULL); + el_set(e, EL_BIND, "\\e[5D", "ed-prev-word", NULL); el_set(e, EL_BIND, "\\e\\e[C", "em-next-word", NULL); el_set(e, EL_BIND, "\\e\\e[D", "ed-prev-word", NULL); @@ -385,8 +388,7 @@ rl_initialize(void) _resize_fun(e, &rl_line_buffer); _rl_update_pos(); - if (rl_startup_hook) - (*rl_startup_hook)(NULL, 0); + tty_end(e); return 0; } @@ -408,14 +410,21 @@ readline(const char *p) if (e == NULL || h == NULL) rl_initialize(); + if (rl_did_startup_hook == 0 && rl_startup_hook) { + rl_did_startup_hook = 1; + (*rl_startup_hook)(NULL, 0); + } + tty_init(e); + rl_done = 0; (void)setjmp(topbuf); + buf = NULL; /* update prompt accordingly to what has been passed */ if (rl_set_prompt(prompt) == -1) - return NULL; + goto out; if (rl_pre_input_hook) (*rl_pre_input_hook)(NULL, 0); @@ -440,7 +449,7 @@ readline(const char *p) buf = strdup(ret); if (buf == NULL) - return NULL; + goto out; lastidx = count - 1; if (buf[lastidx] == '\n') buf[lastidx] = '\0'; @@ -450,6 +459,8 @@ readline(const char *p) history(h, &ev, H_GETSIZE); history_length = ev.num; +out: + tty_end(e); return buf; } @@ -556,7 +567,7 @@ get_history_event(const char *cmd, int * idx++; } if (sign) - num = history_length - num + 1; + num = history_length - num + history_base; if (!(he = history_get(num))) return NULL; @@ -1365,6 +1376,28 @@ write_history(const char *filename) (errno ? errno : EINVAL) : 0; } +int +append_history(int n, const char *filename) +{ + HistEvent ev; + FILE *fp; + + if (h == NULL || e == NULL) + rl_initialize(); + if (filename == NULL && (filename = _default_history_file()) == NULL) + return errno; + + if ((fp = fopen(filename, "a")) == NULL) + return errno; + + if (history(h, &ev, H_NSAVE_FP, (size_t)n, fp) == -1) { + int serrno = errno ? errno : EINVAL; + fclose(fp); + return serrno; + } + fclose(fp); + return 0; +} /* * returns history ``num''th event @@ -1812,18 +1845,6 @@ _el_rl_tstp(EditLine *el __attribute__(( return CC_NORM; } -/* - * Display list of strings in columnar format on readline's output stream. - * 'matches' is list of strings, 'len' is number of strings in 'matches', - * 'max' is maximum length of string in 'matches'. - */ -void -rl_display_match_list(char **matches, int len, int max) -{ - - fn_display_match_list(e, matches, (size_t)len, (size_t)max); -} - static const char * /*ARGSUSED*/ _rl_completion_append_character_function(const char *dummy @@ -1837,6 +1858,19 @@ _rl_completion_append_character_function /* + * Display list of strings in columnar format on readline's output stream. + * 'matches' is list of strings, 'len' is number of strings in 'matches', + * 'max' is maximum length of string in 'matches'. + */ +void +rl_display_match_list(char **matches, int len, int max) +{ + + fn_display_match_list(e, matches, (size_t)len, (size_t)max, + _rl_completion_append_character_function); +} + +/* * complete word at current point */ /* ARGSUSED */ @@ -2057,8 +2091,9 @@ rl_callback_handler_install(const char * void rl_callback_handler_remove(void) { - el_set(e, EL_UNBUFFERED, 0); rl_linefunc = NULL; + el_end(e); + e = NULL; } void @@ -2368,3 +2403,9 @@ rl_set_keyboard_input_timeout(int u __at { return 0; } + +void +rl_resize_terminal(void) +{ + el_resize(e); +}