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.44 retrieving revision 1.51 diff -u -p -r1.44 -r1.51 --- src/lib/libedit/readline.c 2003/12/05 13:37:48 1.44 +++ src/lib/libedit/readline.c 2005/04/12 22:01:40 1.51 @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.44 2003/12/05 13:37:48 lukem Exp $ */ +/* $NetBSD: readline.c,v 1.51 2005/04/12 22:01:40 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.44 2003/12/05 13:37:48 lukem Exp $"); +__RCSID("$NetBSD: readline.c,v 1.51 2005/04/12 22:01:40 christos Exp $"); #endif /* not lint && not SCCSID */ #include @@ -61,10 +61,10 @@ __RCSID("$NetBSD: readline.c,v 1.44 2003 #ifdef HAVE_ALLOCA_H #include #endif -#include "histedit.h" -#include "readline/readline.h" #include "el.h" #include "fcns.h" /* for EL_NUM_FCNS */ +#include "histedit.h" +#include "readline/readline.h" /* for rl_complete() */ #define TAB '\r' @@ -161,15 +161,17 @@ static int el_rl_complete_cmdnum = 0; /* internal functions */ static unsigned char _el_rl_complete(EditLine *, int); +static unsigned char _el_rl_tstp(EditLine *, int); static char *_get_prompt(EditLine *); static HIST_ENTRY *_move_history(int); static int _history_expand_command(const char *, size_t, size_t, char **); static char *_rl_compat_sub(const char *, const char *, const char *, int); -static int rl_complete_internal(int); +static int _rl_complete_internal(int); static int _rl_qsort_string_compare(const void *, const void *); static int _rl_event_read_char(EditLine *, char *); +static void _rl_update_pos(void); /* ARGSUSED */ @@ -272,6 +274,15 @@ rl_initialize(void) "ReadLine compatible completion function", _el_rl_complete); el_set(e, EL_BIND, "^I", "rl_complete", NULL); + + /* + * Send TSTP when ^Z is pressed. + */ + el_set(e, EL_ADDFN, "rl_tstp", + "ReadLine compatible suspend function", + _el_rl_tstp); + el_set(e, EL_BIND, "^Z", "rl_tstp", NULL); + /* * Find out where the rl_complete function was added; this is * used later to detect that lastcmd was also rl_complete. @@ -293,7 +304,7 @@ rl_initialize(void) li = el_line(e); /* a cheesy way to get rid of const cast. */ rl_line_buffer = memchr(li->buffer, *li->buffer, 1); - rl_point = rl_end = 0; + _rl_update_pos(); if (rl_startup_hook) (*rl_startup_hook)(NULL, 0); @@ -1539,7 +1550,8 @@ filename_completion_function(const char char * username_completion_function(const char *text, int state) { - struct passwd *pwd; + struct passwd *pwd, pwres; + char pwbuf[1024]; if (text[0] == '\0') return (NULL); @@ -1550,7 +1562,8 @@ username_completion_function(const char if (state == 0) setpwent(); - while ((pwd = getpwent()) && text[0] == pwd->pw_name[0] + while (getpwent_r(&pwres, pwbuf, sizeof(pwbuf), &pwd) == 0 + && text[0] == pwd->pw_name[0] && strcmp(text, pwd->pw_name) == 0); if (pwd == NULL) { @@ -1571,6 +1584,16 @@ _el_rl_complete(EditLine *el __attribute return (unsigned char) rl_complete(0, ch); } +/* + * el-compatible wrapper to send TSTP on ^Z + */ +/* ARGSUSED */ +static unsigned char +_el_rl_tstp(EditLine *el __attribute__((__unused__)), int ch __attribute__((__unused__))) +{ + (void)kill(0, SIGTSTP); + return CC_NORM; +} /* * returns list of completions for text given @@ -1698,7 +1721,7 @@ rl_display_match_list (matches, len, max * Note: '*' support is not implemented */ static int -rl_complete_internal(int what_to_do) +_rl_complete_internal(int what_to_do) { Function *complet_func; const LineInfo *li; @@ -1731,8 +1754,7 @@ rl_complete_internal(int what_to_do) /* these can be used by function called in completion_matches() */ /* or (*rl_attempted_completion_function)() */ - rl_point = li->cursor - li->buffer; - rl_end = li->lastchar - li->buffer; + _rl_update_pos(); if (rl_attempted_completion_function) { int end = li->cursor - li->buffer; @@ -1740,9 +1762,13 @@ rl_complete_internal(int what_to_do) (end - len), end); } else matches = 0; - if (!rl_attempted_completion_function || !matches) + if (!rl_attempted_completion_function || + (!rl_attempted_completion_over && !matches)) matches = completion_matches(temp, (CPFunction *)complet_func); + if (rl_attempted_completion_over) + rl_attempted_completion_over = 0; + if (matches) { int i, retval = CC_REFRESH; int matches_num, maxlen, match_len, match_display=1; @@ -1839,20 +1865,24 @@ rl_complete_internal(int what_to_do) * complete word at current point */ int +/*ARGSUSED*/ rl_complete(int ignore, int invoking_key) { if (h == NULL || e == NULL) rl_initialize(); if (rl_inhibit_completion) { - rl_insert(ignore, invoking_key); + char arr[2]; + arr[0] = (char)invoking_key; + arr[1] = '\0'; + el_insertstr(e, arr); return (CC_REFRESH); } else if (e->el_state.lastcmd == el_rl_complete_cmdnum) - return rl_complete_internal('?'); + return _rl_complete_internal('?'); else if (_rl_complete_show_all) - return rl_complete_internal('!'); + return _rl_complete_internal('!'); else - return (rl_complete_internal(TAB)); + return _rl_complete_internal(TAB); } @@ -1947,6 +1977,9 @@ rl_bind_wrapper(EditLine *el, unsigned c { if (map[c] == NULL) return CC_ERROR; + + _rl_update_pos(); + (*map[c])(NULL, c); /* If rl_done was set by the above call, deal with it here */ @@ -1991,6 +2024,7 @@ rl_callback_read_char() } else wbuf = NULL; (*(void (*)(const char *))rl_linefunc)(wbuf); + el_set(e, EL_UNBUFFERED, 1); } } @@ -2066,6 +2100,16 @@ rl_parse_and_bind(const char *line) return (argc ? 1 : 0); } +int +rl_variable_bind(const char *var, const char *value) +{ + /* + * The proper return value is undocument, but this is what the + * readline source seems to do. + */ + return ((el_set(e, EL_BIND, "", var, value) == -1) ? 1 : 0); +} + void rl_stuff_char(int c) { @@ -2117,3 +2161,12 @@ _rl_event_read_char(EditLine *el, char * el_set(el, EL_GETCFN, EL_BUILTIN_GETCFN); return(num_read); } + +static void +_rl_update_pos(void) +{ + const LineInfo *li = el_line(e); + + rl_point = li->cursor - li->buffer; + rl_end = li->lastchar - li->buffer; +}