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.42 retrieving revision 1.49.2.3 diff -u -p -r1.42 -r1.49.2.3 --- src/lib/libedit/readline.c 2003/11/02 01:45:14 1.42 +++ src/lib/libedit/readline.c 2005/07/12 11:33:40 1.49.2.3 @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.42 2003/11/02 01:45:14 christos Exp $ */ +/* $NetBSD: readline.c,v 1.49.2.3 2005/07/12 11:33:40 tron 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.42 2003/11/02 01:45:14 christos Exp $"); +__RCSID("$NetBSD: readline.c,v 1.49.2.3 2005/07/12 11:33:40 tron Exp $"); #endif /* not lint && not SCCSID */ #include @@ -61,11 +61,10 @@ __RCSID("$NetBSD: readline.c,v 1.42 2003 #ifdef HAVE_ALLOCA_H #include #endif -#include "histedit.h" -#include "readline/readline.h" #include "el.h" -#include "tokenizer.h" #include "fcns.h" /* for EL_NUM_FCNS */ +#include "histedit.h" +#include "readline/readline.h" /* for rl_complete() */ #define TAB '\r' @@ -86,7 +85,7 @@ FILE *rl_outstream = NULL; int rl_point = 0; int rl_end = 0; char *rl_line_buffer = NULL; -VFunction *rl_linefunc = NULL; +VCPFunction *rl_linefunc = NULL; int rl_done = 0; VFunction *rl_event_hook = NULL; @@ -162,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 */ @@ -273,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. @@ -294,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); @@ -1540,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); @@ -1551,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) { @@ -1572,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 @@ -1699,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; @@ -1732,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; @@ -1840,20 +1861,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); } @@ -1948,6 +1973,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 */ @@ -1992,11 +2020,12 @@ rl_callback_read_char() } else wbuf = NULL; (*(void (*)(const char *))rl_linefunc)(wbuf); + el_set(e, EL_UNBUFFERED, 1); } } void -rl_callback_handler_install (const char *prompt, VFunction *linefunc) +rl_callback_handler_install (const char *prompt, VCPFunction *linefunc) { if (e == NULL) { rl_initialize(); @@ -2061,7 +2090,7 @@ rl_parse_and_bind(const char *line) Tokenizer *tok; tok = tok_init(NULL); - tok_line(tok, line, &argc, &argv); + tok_str(tok, line, &argc, &argv); argc = el_parse(e, argc, argv); tok_end(tok); return (argc ? 1 : 0); @@ -2080,7 +2109,7 @@ rl_stuff_char(int c) static int _rl_event_read_char(EditLine *el, char *cp) { - int n, num_read; + int n, num_read = 0; *cp = 0; while (rl_event_hook) { @@ -2118,3 +2147,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; +}