From: Date: April 6 2005 4:44am Subject: bk commit into 5.0 tree (jimw:1.1876) BUG#9568 List-Archive: http://lists.mysql.com/internals/23693 X-Bug: 9568 Message-Id: <20050406024401.19270A8B91@rama.trainedmonkey.com> Below is the list of changes that have just been committed into a local 5.0 repository of jimw. When jimw does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.1876 05/04/05 19:43:56 jimw@stripped +40 -0 Update bundled libedit to latest version from OpenBSD CVS with one change to revert to using strvis() instead of the less widely available strnvis(). This also fixes Bug #9568 (warning with gcc compile). cmd-line-utils/libedit/vi.c 1.4 05/04/05 19:43:53 jimw@stripped +71 -62 Update to latest OpenBSD CVS version cmd-line-utils/libedit/tty.h 1.3 05/04/05 19:43:53 jimw@stripped +3 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/tty.c 1.5 05/04/05 19:43:53 jimw@stripped +136 -14 Update to latest OpenBSD CVS version cmd-line-utils/libedit/tokenizer.h 1.3 05/04/05 19:43:53 jimw@stripped +3 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/tokenizer.c 1.4 05/04/05 19:43:53 jimw@stripped +6 -8 Update to latest OpenBSD CVS version cmd-line-utils/libedit/term.c 1.7 05/04/05 19:43:53 jimw@stripped +63 -60 Update to latest OpenBSD CVS version cmd-line-utils/libedit/sys.h 1.3 05/04/05 19:43:53 jimw@stripped +7 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/sig.h 1.4 05/04/05 19:43:53 jimw@stripped +3 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/sig.c 1.5 05/04/05 19:43:53 jimw@stripped +4 -7 Update to latest OpenBSD CVS version cmd-line-utils/libedit/search.h 1.3 05/04/05 19:43:53 jimw@stripped +4 -7 Update to latest OpenBSD CVS version cmd-line-utils/libedit/search.c 1.5 05/04/05 19:43:53 jimw@stripped +44 -33 Update to latest OpenBSD CVS version cmd-line-utils/libedit/refresh.h 1.2 05/04/05 19:43:53 jimw@stripped +3 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/refresh.c 1.6 05/04/05 19:43:53 jimw@stripped +10 -13 Update to latest OpenBSD CVS version cmd-line-utils/libedit/readline/readline.h 1.4 05/04/05 19:43:53 jimw@stripped +76 -3 Update to latest OpenBSD CVS version cmd-line-utils/libedit/readline.c 1.7 05/04/05 19:43:53 jimw@stripped +763 -414 Update to latest OpenBSD CVS version cmd-line-utils/libedit/read.h 1.2 05/04/05 19:43:53 jimw@stripped +4 -1 Update to latest OpenBSD CVS version cmd-line-utils/libedit/read.c 1.6 05/04/05 19:43:53 jimw@stripped +78 -52 Update to latest OpenBSD CVS version cmd-line-utils/libedit/prompt.h 1.2 05/04/05 19:43:53 jimw@stripped +3 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/prompt.c 1.4 05/04/05 19:43:53 jimw@stripped +7 -10 Update to latest OpenBSD CVS version cmd-line-utils/libedit/parse.h 1.2 05/04/05 19:43:53 jimw@stripped +3 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/parse.c 1.5 05/04/05 19:43:53 jimw@stripped +15 -10 Update to latest OpenBSD CVS version cmd-line-utils/libedit/map.h 1.3 05/04/05 19:43:53 jimw@stripped +3 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/map.c 1.7 05/04/05 19:43:53 jimw@stripped +23 -27 Update to latest OpenBSD CVS version cmd-line-utils/libedit/libedit_term.h 1.3 05/04/05 19:43:53 jimw@stripped +6 -7 Update to latest OpenBSD CVS version cmd-line-utils/libedit/key.h 1.5 05/04/05 19:43:53 jimw@stripped +19 -19 Update to latest OpenBSD CVS version cmd-line-utils/libedit/key.c 1.5 05/04/05 19:43:53 jimw@stripped +23 -25 Update to latest OpenBSD CVS version cmd-line-utils/libedit/history.c 1.8 05/04/05 19:43:52 jimw@stripped +35 -22 Update to latest OpenBSD CVS version cmd-line-utils/libedit/histedit.h 1.3 05/04/05 19:43:52 jimw@stripped +6 -7 Update to latest OpenBSD CVS version cmd-line-utils/libedit/hist.h 1.3 05/04/05 19:43:52 jimw@stripped +3 -6 Update to latest OpenBSD CVS version cmd-line-utils/libedit/hist.c 1.4 05/04/05 19:43:52 jimw@stripped +9 -13 Update to latest OpenBSD CVS version cmd-line-utils/libedit/emacs.c 1.4 05/04/05 19:43:52 jimw@stripped +26 -31 Update to latest OpenBSD CVS version cmd-line-utils/libedit/el.h 1.5 05/04/05 19:43:52 jimw@stripped +8 -9 Update to latest OpenBSD CVS version cmd-line-utils/libedit/el.c 1.6 05/04/05 19:43:52 jimw@stripped +56 -20 Update to latest OpenBSD CVS version cmd-line-utils/libedit/editrc.5 1.2 05/04/05 19:43:52 jimw@stripped +50 -33 Update to latest OpenBSD CVS version cmd-line-utils/libedit/editline.3 1.2 05/04/05 19:43:52 jimw@stripped +78 -21 Update to latest OpenBSD CVS version cmd-line-utils/libedit/common.c 1.4 05/04/05 19:43:52 jimw@stripped +43 -47 Update to latest OpenBSD CVS version cmd-line-utils/libedit/chared.h 1.3 05/04/05 19:43:52 jimw@stripped +4 -7 Update to latest OpenBSD CVS version cmd-line-utils/libedit/chared.c 1.5 05/04/05 19:43:52 jimw@stripped +8 -11 Update to latest OpenBSD CVS version cmd-line-utils/libedit/TEST/test.c 1.2 05/04/05 19:43:52 jimw@stripped +15 -19 Update to latest OpenBSD CVS version client/mysql.cc 1.162 05/04/05 19:43:52 jimw@stripped +1 -1 Update to latest libedit API # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: jimw # Host: rama.(none) # Root: /home/jimw/my/mysql-5.0-libedit --- 1.161/client/mysql.cc 2005-03-25 10:51:07 -08:00 +++ 1.162/client/mysql.cc 2005-04-05 19:43:52 -07:00 @@ -1323,7 +1323,7 @@ setlocale(LC_ALL,""); /* so as libedit use isprint */ #endif rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion; - rl_completion_entry_function= (CPFunction*)&no_completion; + rl_completion_entry_function= (Function*)&no_completion; #else rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion; rl_completion_entry_function= (Function*)&no_completion; --- 1.1/cmd-line-utils/libedit/TEST/test.c 2003-01-18 08:28:15 -08:00 +++ 1.2/cmd-line-utils/libedit/TEST/test.c 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $ */ +/* $OpenBSD: test.c,v 1.6 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: test.c,v 1.13 2003/08/07 16:44:35 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,25 +33,23 @@ * SUCH DAMAGE. */ -#include -#include "compat.h" +#include "config.h" #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +//__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\ +// The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $"); +static const char *rcsid = "$OpenBSD: test.c,v 1.6 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ /* * test.c: A little test program */ -#include "sys.h" #include #include #include @@ -130,7 +125,10 @@ int num; const char *buf; Tokenizer *tok; - int lastevent = 0, ncontinuation; +#if 0 + int lastevent = 0; +#endif + int ncontinuation; History *hist; HistEvent ev; @@ -175,16 +173,14 @@ while ((buf = el_gets(el, &num)) != NULL && num != 0) { int ac; - char **av; + const char **av; #ifdef DEBUG (void) fprintf(stderr, "got %d %s", num, buf); #endif if (!continuation && num == 1) continue; - if (tok_line(tok, buf, &ac, &av) > 0) - ncontinuation = 1; - + ncontinuation = tok_line(tok, buf, &ac, &av) > 0; #if 0 if (continuation) { /* @@ -192,7 +188,7 @@ * moved around in history. */ if (history(hist, &ev, H_SET, lastevent) == -1) - err(1, "%d: %s\n", lastevent, ev.str); + err(1, "%d: %s", lastevent, ev.str); history(hist, &ev, H_ADD , buf); } else { history(hist, &ev, H_ENTER, buf); @@ -240,7 +236,7 @@ } else if (el_parse(el, ac, av) == -1) { switch (fork()) { case 0: - execvp(av[0], av); + execvp(av[0], (char *const *)av); perror(av[0]); _exit(1); /*NOTREACHED*/ --- 1.4/cmd-line-utils/libedit/chared.c 2004-08-31 05:50:59 -07:00 +++ 1.5/cmd-line-utils/libedit/chared.c 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $ */ +/* $OpenBSD: chared.c,v 1.8 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: chared.c,v 1.21 2003/11/02 20:08:41 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $"); +static const char rcsid[] = "$OpenBSD: chared.c,v 1.8 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -62,13 +59,13 @@ { c_undo_t *vu = &el->el_chared.c_undo; c_redo_t *r = &el->el_chared.c_redo; - int size; + uint size; /* Save entire line for undo */ size = el->el_line.lastchar - el->el_line.buffer; vu->len = size; vu->cursor = el->el_line.cursor - el->el_line.buffer; - memcpy(vu->buf, el->el_line.buffer, (size_t)size); + memcpy(vu->buf, el->el_line.buffer, size); /* save command info for redo */ r->count = el->el_state.doingarg ? el->el_state.argument : 0; @@ -460,8 +457,8 @@ el->el_state.argument = 1; el->el_state.lastcmd = ED_UNASSIGNED; - el->el_chared.c_macro.nline = NULL; el->el_chared.c_macro.level = -1; + el->el_chared.c_macro.offset = 0; el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO * sizeof(char *)); if (el->el_chared.c_macro.macro == NULL) @@ -582,7 +579,7 @@ return 0; /* Safe to set enlarged buffer size */ - el->el_line.limit = &newbuffer[newsz - EL_LEAVE]; + el->el_line.limit = &el->el_line.buffer[newsz - EL_LEAVE]; return 1; } --- 1.2/cmd-line-utils/libedit/chared.h 2004-08-24 08:41:36 -07:00 +++ 1.3/cmd-line-utils/libedit/chared.h 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: chared.h,v 1.11 2002/11/20 16:50:08 christos Exp $ */ +/* $OpenBSD: chared.h,v 1.8 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: chared.h,v 1.13 2003/10/18 23:48:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -66,8 +63,8 @@ typedef struct c_macro_t { int level; + int offset; char **macro; - char *nline; } c_macro_t; /* --- 1.3/cmd-line-utils/libedit/common.c 2004-08-24 08:41:36 -07:00 +++ 1.4/cmd-line-utils/libedit/common.c 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */ +/* $OpenBSD: common.c,v 1.6 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: common.c,v 1.16 2003/08/07 16:44:30 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $"); +static const char rcsid[] = "$OpenBSD: common.c,v 1.6 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -56,7 +53,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_end_of_file(EditLine *el, int c __attribute__((unused))) +ed_end_of_file(EditLine *el, int c __attribute__((__unused__))) { re_goto_bottom(el); @@ -113,7 +110,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_delete_prev_word(EditLine *el, int c __attribute__((unused))) +ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__))) { char *cp, *p, *kp; @@ -141,7 +138,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_delete_next_char(EditLine *el, int c __attribute__((unused))) +ed_delete_next_char(EditLine *el, int c __attribute__((__unused__))) { #ifdef notdef /* XXX */ #define EL el->el_line @@ -192,7 +189,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_kill_line(EditLine *el, int c __attribute__((unused))) +ed_kill_line(EditLine *el, int c __attribute__((__unused__))) { char *kp, *cp; @@ -213,7 +210,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_move_to_end(EditLine *el, int c __attribute__((unused))) +ed_move_to_end(EditLine *el, int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.lastchar; @@ -236,7 +233,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_move_to_beg(EditLine *el, int c __attribute__((unused))) +ed_move_to_beg(EditLine *el, int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -285,7 +282,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_next_char(EditLine *el, int c __attribute__((unused))) +ed_next_char(EditLine *el, int c __attribute__((__unused__))) { char *lim = el->el_line.lastchar; @@ -314,7 +311,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_prev_word(EditLine *el, int c __attribute__((unused))) +ed_prev_word(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -340,7 +337,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_prev_char(EditLine *el, int c __attribute__((unused))) +ed_prev_char(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor > el->el_line.buffer) { @@ -437,8 +434,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_unassigned(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_unassigned(EditLine *el, int c __attribute__((__unused__))) { return (CC_ERROR); @@ -455,8 +451,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigint(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_tty_sigint(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -469,8 +465,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_tty_dsusp(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_tty_dsusp(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -483,8 +479,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_tty_flush_output(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_tty_flush_output(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -497,8 +493,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigquit(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_tty_sigquit(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -511,8 +507,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigtstp(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_tty_sigtstp(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -525,8 +521,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_tty_stop_output(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_tty_stop_output(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -539,8 +535,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_tty_start_output(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_tty_start_output(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -553,7 +549,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_newline(EditLine *el, int c __attribute__((unused))) +ed_newline(EditLine *el, int c __attribute__((__unused__))) { re_goto_bottom(el); @@ -569,7 +565,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_delete_prev_char(EditLine *el, int c __attribute__((unused))) +ed_delete_prev_char(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) @@ -589,7 +585,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_clear_screen(EditLine *el, int c __attribute__((unused))) +ed_clear_screen(EditLine *el, int c __attribute__((__unused__))) { term_clear_screen(el); /* clear the whole real screen */ @@ -604,8 +600,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_redisplay(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_redisplay(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_REDISPLAY); @@ -618,7 +614,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_start_over(EditLine *el, int c __attribute__((unused))) +ed_start_over(EditLine *el, int c __attribute__((__unused__))) { ch_reset(el); @@ -632,8 +628,8 @@ */ protected el_action_t /*ARGSUSED*/ -ed_sequence_lead_in(EditLine *el __attribute__((unused)), - int c __attribute__((unused))) +ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -646,7 +642,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_prev_history(EditLine *el, int c __attribute__((unused))) +ed_prev_history(EditLine *el, int c __attribute__((__unused__))) { char beep = 0; int sv_event = el->el_history.eventno; @@ -684,7 +680,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_next_history(EditLine *el, int c __attribute__((unused))) +ed_next_history(EditLine *el, int c __attribute__((__unused__))) { el_action_t beep = CC_REFRESH, rval; @@ -711,7 +707,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_search_prev_history(EditLine *el, int c __attribute__((unused))) +ed_search_prev_history(EditLine *el, int c __attribute__((__unused__))) { const char *hp; int h; @@ -779,7 +775,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_search_next_history(EditLine *el, int c __attribute__((unused))) +ed_search_next_history(EditLine *el, int c __attribute__((__unused__))) { const char *hp; int h; @@ -833,7 +829,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_prev_line(EditLine *el, int c __attribute__((unused))) +ed_prev_line(EditLine *el, int c __attribute__((__unused__))) { char *ptr; int nchars = c_hpos(el); @@ -876,7 +872,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_next_line(EditLine *el, int c __attribute__((unused))) +ed_next_line(EditLine *el, int c __attribute__((__unused__))) { char *ptr; int nchars = c_hpos(el); @@ -910,7 +906,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_command(EditLine *el, int c __attribute__((unused))) +ed_command(EditLine *el, int c __attribute__((__unused__))) { char tmpbuf[EL_BUFSIZ]; int tmplen; --- 1.1/cmd-line-utils/libedit/editline.3 2003-01-18 08:28:15 -08:00 +++ 1.2/cmd-line-utils/libedit/editline.3 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -.\" $NetBSD: editline.3,v 1.21 2001/04/02 18:29:49 wiz Exp $ +.\" $OpenBSD: editline.3,v 1.20 2004/04/14 22:00:35 jfb Exp $ +.\" $NetBSD: editline.3,v 1.42 2003/11/04 13:22:19 christos Exp $ .\" .\" Copyright (c) 1997-1999 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -33,7 +34,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 12, 1999 +.Dd October 17, 2003 .Os .Dt EDITLINE 3 .Sh NAME @@ -55,8 +56,6 @@ .Nm history_end , .Nm history .Nd line editor and history functions -.Sh LIBRARY -.Lb libedit .Sh SYNOPSIS .Fd #include .Ft EditLine * @@ -72,7 +71,7 @@ .Ft void .Fn el_push "EditLine *e" "const char *str" .Ft int -.Fn el_parse "EditLine *e" "int argc" "char *argv[]" +.Fn el_parse "EditLine *e" "int argc" "const char *argv[]" .Ft int .Fn el_set "EditLine *e" "int op" "..." .Ft int @@ -103,10 +102,10 @@ These functions are available in the .Nm libedit library (which needs the -.Nm libtermcap +.Nm libcurses library). Programs should be linked with -.Fl ledit ltermcap . +.Fl ledit lcurses . .Sh LINE EDITING FUNCTIONS The line editing functions use a common data structure, .Fa EditLine , @@ -152,7 +151,7 @@ Read a character from the tty. .Fa ch is modified to contain the character read. -Returns the number of characters read if successful, -1 otherwise. +Returns the number of characters read if successful, \-1 otherwise. .It Fn el_push Pushes .Fa str @@ -174,7 +173,7 @@ .Nm commands. If the command is prefixed with -.Dq prog: +.Dq prog : then .Fn el_parse will only execute the command if @@ -184,7 +183,7 @@ argument supplied to .Fn el_init . The return value is --1 if the command is unknown, +\-1 if the command is unknown, 0 if there was no error or .Dq prog didn't match, or @@ -303,7 +302,7 @@ .It Dv EL_ADDFN , Xo .Fa "const char *name" , .Fa "const char *help" , -.Fa "unsigned char (*func)(EditLine *e, int ch) +.Fa "unsigned char (*func)(EditLine *e, int ch)" .Xc Add a user defined function, .Fn func , @@ -336,7 +335,7 @@ Refresh display, and beep. .It Dv CC_CURSOR Cursor moved, so update and perform -.Dv CC_REFRESH. +.Dv CC_REFRESH . .It Dv CC_REDISPLAY Redisplay entire input line. This is useful if a key binding outputs extra information. @@ -362,12 +361,30 @@ editing is enabled (the default). Note that this is only an indication, and does not affect the operation of -.Nm "" . +.Nm . At this time, it is the caller's responsibility to check this (using .Fn el_get ) to determine if editing should be enabled or not. +.It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)" +Define the character reading function as +.Fa f , +which is to return the number of characters read and store them in +.Fa c . +This function is called internally by +.Fn el_gets +and +.Fn el_getc . +The builtin function can be set or restored with the special function +name ``EL_BUILTIN_GETCFN''. +.It Dv EL_CLIENTDATA , Fa "void *data" +Register +.Fa data +to be associated with this EditLine structure. +It can be retrieved with the corresponding +.Fn el_get +call. .El .It Fn el_get Get @@ -376,6 +393,7 @@ .Fa op determines which parameter to retrieve into .Fa result . +Returns 0 if successful, \-1 otherwise. .Pp The following values for .Fa op @@ -399,6 +417,22 @@ above). .It Dv EL_EDITMODE, Fa "int *" Return non-zero if editing is enabled. +.It Dv EL_GETCFN, Fa "int (**f)(EditLine *, char *)" +Return a pointer to the function that read characters, which is equal to +``EL_BUILTIN_GETCFN'' in the case of the default builtin function. +.It Dv EL_CLIENTDATA , Fa "void **data" +Retrieve +.Fa data +previously registered with the corresponding +.Fn el_set +call. +.It Dv EL_UNBUFFERED, Fa "int" +Sets or clears unbuffered mode. +In this mode, +.Fn el_gets +will return immediately after processing a single character. +.It Dv EL_PREP_TERM, Fa "int" +Sets or clears terminal editing mode. .El .It Fn el_source Initialise @@ -445,7 +479,7 @@ Insert .Fa str into the line at the cursor. -Returns -1 if +Returns \-1 if .Fa str is empty or won't fit, and 0 otherwise. .It Fn el_deletestr @@ -525,7 +559,11 @@ .It Dv H_ADD , Fa "const char *str" Append .Fa str -to the current element of the history, or create an element with +to the current element of the history, or perform the +.Dv H_ENTER +operation with argument +.Fa str +if there is no current element. .It Dv H_APPEND , Fa "const char *str" Append .Fa str @@ -535,6 +573,17 @@ .Fa str as a new element to the history, and, if necessary, removing the oldest entry to keep the list to the created size. +If +.Dv H_SETUNIQUE +has been called with a non-zero argument, the element +will not be entered into the history if its contents match +the ones of the current history element. +If the element is entered +.Fn history +returns 1; if it is ignored as a duplicate returns 0. +Finally +.Fn history +returns \-1 if an error occurred. .It Dv H_PREV_STR , Fa "const char *str" Return the closest previous event that starts with .Fa str . @@ -553,22 +602,30 @@ .It Dv H_SAVE , Fa "const char *file" Save the history list to .Fa file . +.It Dv H_SETUNIQUE , Fa "int unique" +Set if the adjacent identical event strings should not be entered into +the history. +.It Dv H_GETUNIQUE +Retrieve the current setting if if adjacent elements should be entered into +the history. .El .Pp .Fn history -returns 0 if the operation +returns \*(Ge 0 if the operation .Fa op -succeeds. Otherwise, -1 is returned and +succeeds. +Otherwise, \-1 is returned and .Fa ev is updated to contain more details about the error. .El .\"XXX.Sh EXAMPLES .\"XXX: provide some examples .Sh SEE ALSO -.Xr editrc 5 , .Xr sh 1 , +.Xr curses 3 , .Xr signal 3 , -.Xr termcap 3 +.Xr termcap 3 , +.Xr editrc 5 .Sh HISTORY The .Nm @@ -596,8 +653,8 @@ .Dv EL_RPROMPT . Jaromir Dolecek implemented the readline emulation. .Sh BUGS -The tokenization functions are not publically defined in -.Fd . +The tokenization functions are not publicly defined in +.Aq Pa histedit.h . .Pp At this time, it is the responsibility of the caller to check the result of the --- 1.1/cmd-line-utils/libedit/editrc.5 2003-01-18 08:28:15 -08:00 +++ 1.2/cmd-line-utils/libedit/editrc.5 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -.\" $NetBSD: editrc.5,v 1.11 2001/06/19 13:42:09 wiz Exp $ +.\" $OpenBSD: editrc.5,v 1.19 2003/11/25 20:12:38 otto Exp $ +.\" $NetBSD: editrc.5,v 1.19 2003/11/01 23:35:33 christos Exp $ .\" .\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -33,7 +34,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 8, 2000 +.Dd October 18, 2003 .Os .Dt EDITRC 5 .Sh NAME @@ -49,6 +50,7 @@ library. .Pp The format of each line is: +.Pp .Dl [prog:]command [arg [...]] .Pp .Ar command @@ -62,7 +64,7 @@ .Ar prog is the program name string that a program defines when it calls .Xr el_init 3 -to setup +to set up .Xr editline 3 , which is usually .Va argv[0] . @@ -89,19 +91,13 @@ library has some builtin commands, which affect the way that the line editing and history functions operate. These are based on similar named builtins present in the -.Xr tcsh 1 +.Xr tcsh shell. .Pp The following builtin commands are available: .Bl -tag -width 4n .It Ic bind Xo -.Op Fl a -.Op Fl e -.Op Fl k -.Op Fl l -.Op Fl r -.Op Fl s -.Op Fl v +.Op Fl aeklrsv .Op Ar key Op Ar command .Xc Without options, list all bound keys, and the editor command to which @@ -118,16 +114,12 @@ .Ar key . Options include: .Bl -tag -width 4n -.It Fl e -Bind all keys to the standard GNU Emacs-like bindings. -.It Fl v -Bind all keys to the standard -.Xr vi 1 -like -bindings. .It Fl a List or change key bindings in the .Xr vi 1 mode alternate (command mode) key map. +.It Fl e +Bind all keys to the standard GNU Emacs-like bindings. .It Fl k .Ar key is interpreted as a symbolic arrow key name, which may be one of @@ -149,6 +141,10 @@ .Ar command are themselves reinterpreted, and this continues for ten levels of interpretation. +.It Fl v +Bind all keys to the standard +.Xr vi 1 Ns -like +bindings. .El .Pp .Ar command @@ -164,7 +160,7 @@ .Sq No ^ Ar character .Sm on .Po -e.g. +e.g.\& .Sq ^A .Pc , and the following backslashed escape sequences: @@ -213,7 +209,8 @@ .Sq cols , .Sq lines , .Sq rows , -.Sq meta or +.Sq meta +or .Sq tabs , the value of that capability is printed, with .Dq yes @@ -222,7 +219,7 @@ indicating that the terminal does or does not have that capability. .Pp .Fl s -returns an emptry string for non-existent capabilities, rather than +returns an empty string for non-existent capabilities, rather than causing an error. .Fl v causes messages to be verbose. @@ -232,9 +229,6 @@ functionality in a program. .It Ic history List the history. -.It Ic telltc -List the values of all the terminal capabilities (see -.Xr termcap 5 ). .It Ic settc Ar cap Ar val Set the terminal capability .Ar cap @@ -244,13 +238,11 @@ .Xr termcap 5 . No sanity checking is done. .It Ic setty Xo -.Op Fl a -.Op Fl d -.Op Fl q -.Op Fl x +.Op Fl adqx .Op Ar +mode .Op Ar -mode .Op Ar mode +.Op Ar char=c .Xc Control which tty modes that .Nm @@ -291,6 +283,9 @@ on or off or removes control of .Ar mode in the chosen set. +.It Ic telltc +List the values of all the terminal capabilities (see +.Xr termcap 5 ) . .El .Sh EDITOR COMMANDS The following editor commands are available for use in key bindings: @@ -300,11 +295,11 @@ Vi paste previous deletion to the right of the cursor. .It Ic vi-paste-prev Vi paste previous deletion to the left of the cursor. -.It Ic vi-prev-space-word +.It Ic vi-prev-big-word Vi move to the previous space delimited word. .It Ic vi-prev-word Vi move to the previous word. -.It Ic vi-next-space-word +.It Ic vi-next-big-word Vi move to the next space delimited word. .It Ic vi-next-word Vi move to the next word. @@ -332,9 +327,9 @@ Vi enter insert mode at end of line. .It Ic vi-delete-meta Vi delete prefix command. -.It Ic vi-end-word +.It Ic vi-end-big-word Vi move to the end of the current space delimited word. -.It Ic vi-to-end-word +.It Ic vi-end-word Vi move to the end of the current word. .It Ic vi-undo Vi undo last change. @@ -368,6 +363,28 @@ Vi repeat current character search in the same search direction. .It Ic vi-repeat-prev-char Vi repeat current character search in the opposite search direction. +.It Ic vi-match +Vi go to matching () {} or []. +.It Ic vi-undo-line +Vi undo all changes to line. +.It Ic vi-to-column +Vi go to specified column. +.It Ic vi-yank-end +Vi yank to end of line. +.It Ic vi-yank +Vi yank. +.It Ic vi-comment-out +Vi comment out current command. +.It Ic vi-alias +Vi include shell alias. +.It Ic vi-to-history-line +Vi go to specified history file line.. +.It Ic vi-histedit +Vi edit history line with vi. +.It Ic vi-history-word +Vi append word from previous input line. +.It Ic vi-redo +Vi redo last non-motion command. .It Ic em-delete-or-list Delete character under cursor or list completions if at end of line. .It Ic em-delete-next-word @@ -380,7 +397,7 @@ Cut area between mark and cursor and save in cut buffer. .It Ic em-copy-region Copy area between mark and cursor to cut buffer. -.It Ic em-gosmacs-traspose +.It Ic em-gosmacs-transpose Exchange the two characters before the cursor. .It Ic em-next-word Move next to end of current word. @@ -488,4 +505,4 @@ library was written by Christos Zoulas, and this manual was written by Luke Mewburn, with some sections inspired by -.Xr tcsh 1 . +.Xr tcsh . --- 1.5/cmd-line-utils/libedit/el.c 2004-09-03 05:47:32 -07:00 +++ 1.6/cmd-line-utils/libedit/el.c 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: el.c,v 1.30 2002/11/12 00:00:23 thorpej Exp $ */ +/* $OpenBSD: el.c,v 1.14 2004/08/23 18:31:25 otto Exp $ */ +/* $NetBSD: el.c,v 1.36 2003/10/18 23:48:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; #else -__RCSID("$NetBSD: el.c,v 1.30 2002/11/12 00:00:23 thorpej Exp $"); +static const char rcsid[] = "$OpenBSD: el.c,v 1.14 2004/08/23 18:31:25 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -72,7 +69,10 @@ el->el_infd = fileno(fin); el->el_outfile = fout; el->el_errfile = ferr; - el->el_prog = strdup(prog); + if ((el->el_prog = el_strdup(prog)) == NULL) { + el_free(el); + return NULL; + } /* * Initialize all the modules. Order is important!!! @@ -80,11 +80,11 @@ el->el_flags = 0; if (term_init(el) == -1) { - free(el->el_prog); + el_free(el->el_prog); el_free(el); return NULL; } - (void) el_key_init(el); + (void) key_init(el); (void) map_init(el); if (tty_init(el) == -1) el->el_flags |= NO_TTY; @@ -112,7 +112,7 @@ el_reset(el); term_end(el); - el_key_end(el); + key_end(el); map_end(el); tty_end(el); ch_end(el); @@ -257,6 +257,27 @@ el->el_data = va_arg(va, void *); break; + case EL_UNBUFFERED: + rv = va_arg(va, int); + if (rv && !(el->el_flags & UNBUFFERED)) { + el->el_flags |= UNBUFFERED; + read_prepare(el); + } else if (!rv && (el->el_flags & UNBUFFERED)) { + el->el_flags &= ~UNBUFFERED; + read_finish(el); + } + rv = 0; + break; + + case EL_PREP_TERM: + rv = va_arg(va, int); + if (rv) + read_prepare(el); + else + read_finish(el); + rv = 0; + break; + default: rv = -1; break; @@ -297,21 +318,22 @@ rv = 0; break; -#if 0 /* XXX */ case EL_TERMINAL: - rv = term_get(el, (const char *) &ret); + term_get(el, (const char **)ret); + rv = 0; break; +#if 0 /* XXX */ case EL_BIND: case EL_TELLTC: case EL_SETTC: case EL_ECHOTC: case EL_SETTY: { - char *argv[20]; + const char *argv[20]; int i; - for (i = 1; i < 20; i++) + for (i = 1; i < sizeof(argv) / sizeof(argv[0]); i++) if ((argv[i] = va_arg(va, char *)) == NULL) break; @@ -378,6 +400,11 @@ rv = 0; break; + case EL_UNBUFFERED: + *((int *) ret) = (!(el->el_flags & UNBUFFERED)); + rv = 0; + break; + default: rv = -1; } @@ -405,7 +432,7 @@ { FILE *fp; size_t len; - char *ptr; + char *ptr, *lptr = NULL; fp = NULL; if (fname == NULL) { @@ -437,15 +464,24 @@ return (-1); while ((ptr = fgetln(fp, &len)) != NULL) { - if (len > 0 && ptr[len - 1] == '\n') - --len; - ptr[len] = '\0'; + if (ptr[len - 1] == '\n') + ptr[len - 1] = '\0'; + else { + if ((lptr = (char *)malloc(len + 1)) == NULL) { + (void) fclose(fp); + return (-1); + } + memcpy(lptr, ptr, len); + lptr[len] = '\0'; + ptr = lptr; + } if (parse_line(el, ptr) == -1) { + free(lptr); (void) fclose(fp); return (-1); } } - + free(lptr); (void) fclose(fp); return (0); } --- 1.4/cmd-line-utils/libedit/el.h 2004-09-03 05:47:32 -07:00 +++ 1.5/cmd-line-utils/libedit/el.h 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: el.h,v 1.13 2002/11/15 14:32:33 christos Exp $ */ +/* $OpenBSD: el.h,v 1.6 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: el.h,v 1.16 2003/10/18 23:48:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -55,9 +52,10 @@ #define EL_BUFSIZ 1024 /* Maximum line size */ -#define HANDLE_SIGNALS 1<<0 -#define NO_TTY 1<<1 -#define EDIT_DISABLED 1<<2 +#define HANDLE_SIGNALS 0x01 +#define NO_TTY 0x02 +#define EDIT_DISABLED 0x04 +#define UNBUFFERED 0x08 typedef int bool_t; /* True or not */ @@ -91,6 +89,7 @@ /* * Until we come up with something better... */ +#define el_strdup(a) strdup(a) #define el_malloc(a) malloc(a) #define el_realloc(a,b) realloc(a, b) #define el_free(a) free(a) --- 1.3/cmd-line-utils/libedit/emacs.c 2004-08-24 08:41:37 -07:00 +++ 1.4/cmd-line-utils/libedit/emacs.c 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: emacs.c,v 1.12 2002/11/15 14:32:33 christos Exp $ */ +/* $OpenBSD: emacs.c,v 1.7 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: emacs.c,v 1.16 2003/11/02 20:07:58 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: emacs.c,v 1.12 2002/11/15 14:32:33 christos Exp $"); +static const char rcsid[] = "$OpenBSD: emacs.c,v 1.7 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -56,7 +53,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_delete_or_list(EditLine *el, int c __attribute__((unused))) +em_delete_or_list(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) { @@ -90,7 +87,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_delete_next_word(EditLine *el, int c __attribute__((unused))) +em_delete_next_word(EditLine *el, int c __attribute__((__unused__))) { char *cp, *p, *kp; @@ -119,14 +116,12 @@ */ protected el_action_t /*ARGSUSED*/ -em_yank(EditLine *el, int c __attribute__((unused))) +em_yank(EditLine *el, int c __attribute__((__unused__))) { char *kp, *cp; - if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) { - if (!ch_enlargebufs(el, 1)) - return (CC_ERROR); - } + if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) + return (CC_NORM); if (el->el_line.lastchar + (el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >= @@ -156,7 +151,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_kill_line(EditLine *el, int c __attribute__((unused))) +em_kill_line(EditLine *el, int c __attribute__((__unused__))) { char *kp, *cp; @@ -178,7 +173,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_kill_region(EditLine *el, int c __attribute__((unused))) +em_kill_region(EditLine *el, int c __attribute__((__unused__))) { char *kp, *cp; @@ -211,7 +206,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_copy_region(EditLine *el, int c __attribute__((unused))) +em_copy_region(EditLine *el, int c __attribute__((__unused__))) { char *kp, *cp; @@ -235,12 +230,12 @@ } -/* em_gosmacs_traspose(): +/* em_gosmacs_transpose(): * Exchange the two characters before the cursor * Gosling emacs transpose chars [^T] */ protected el_action_t -em_gosmacs_traspose(EditLine *el, int c) +em_gosmacs_transpose(EditLine *el, int c) { if (el->el_line.cursor > &el->el_line.buffer[1]) { @@ -260,7 +255,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_next_word(EditLine *el, int c __attribute__((unused))) +em_next_word(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) return (CC_ERROR); @@ -285,7 +280,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_upper_case(EditLine *el, int c __attribute__((unused))) +em_upper_case(EditLine *el, int c __attribute__((__unused__))) { char *cp, *ep; @@ -309,7 +304,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_capitol_case(EditLine *el, int c __attribute__((unused))) +em_capitol_case(EditLine *el, int c __attribute__((__unused__))) { char *cp, *ep; @@ -341,7 +336,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_lower_case(EditLine *el, int c __attribute__((unused))) +em_lower_case(EditLine *el, int c __attribute__((__unused__))) { char *cp, *ep; @@ -365,7 +360,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_set_mark(EditLine *el, int c __attribute__((unused))) +em_set_mark(EditLine *el, int c __attribute__((__unused__))) { el->el_chared.c_kill.mark = el->el_line.cursor; @@ -379,7 +374,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_exchange_mark(EditLine *el, int c __attribute__((unused))) +em_exchange_mark(EditLine *el, int c __attribute__((__unused__))) { char *cp; @@ -396,7 +391,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_universal_argument(EditLine *el, int c __attribute__((unused))) +em_universal_argument(EditLine *el, int c __attribute__((__unused__))) { /* multiply current argument by 4 */ if (el->el_state.argument > 1000000) @@ -413,7 +408,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_meta_next(EditLine *el, int c __attribute__((unused))) +em_meta_next(EditLine *el, int c __attribute__((__unused__))) { el->el_state.metanext = 1; @@ -426,7 +421,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_toggle_overwrite(EditLine *el, int c __attribute__((unused))) +em_toggle_overwrite(EditLine *el, int c __attribute__((__unused__))) { el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ? @@ -440,7 +435,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_copy_prev_word(EditLine *el, int c __attribute__((unused))) +em_copy_prev_word(EditLine *el, int c __attribute__((__unused__))) { char *cp, *oldc, *dp; @@ -467,7 +462,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_inc_search_next(EditLine *el, int c __attribute__((unused))) +em_inc_search_next(EditLine *el, int c __attribute__((__unused__))) { el->el_search.patlen = 0; @@ -480,7 +475,7 @@ */ protected el_action_t /*ARGSUSED*/ -em_inc_search_prev(EditLine *el, int c __attribute__((unused))) +em_inc_search_prev(EditLine *el, int c __attribute__((__unused__))) { el->el_search.patlen = 0; --- 1.3/cmd-line-utils/libedit/hist.c 2004-08-24 08:41:37 -07:00 +++ 1.4/cmd-line-utils/libedit/hist.c 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: hist.c,v 1.12 2003/01/21 18:40:23 christos Exp $ */ +/* $OpenBSD: hist.c,v 1.7 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: hist.c,v 1.15 2003/11/01 23:36:39 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: hist.c,v 1.12 2003/01/21 18:40:23 christos Exp $"); +static const char rcsid[] = "$OpenBSD: hist.c,v 1.7 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -157,7 +154,6 @@ * process a history command */ protected int -/*ARGSUSED*/ hist_command(EditLine *el, int argc, const char **argv) { const char *str; @@ -167,7 +163,7 @@ if (el->el_history.ref == NULL) return (-1); - if (argc == 0 || strcmp(argv[0], "list") == 1) { + if (argc == 1 || strcmp(argv[1], "list") == 0) { /* List history entries */ for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el)) @@ -176,15 +172,15 @@ return (0); } - if (argc != 2) + if (argc != 3) return (-1); - num = (int)strtol(argv[1], NULL, 0); + num = (int)strtol(argv[2], NULL, 0); - if (strcmp(argv[0], "size") == 0) + if (strcmp(argv[1], "size") == 0) return history(el->el_history.ref, &ev, H_SETSIZE, num); - if (strcmp(argv[0], "unique") == 0) + if (strcmp(argv[1], "unique") == 0) return history(el->el_history.ref, &ev, H_SETUNIQUE, num); return -1; --- 1.2/cmd-line-utils/libedit/hist.h 2004-08-24 08:41:37 -07:00 +++ 1.3/cmd-line-utils/libedit/hist.h 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: hist.h,v 1.9 2003/01/21 18:40:23 christos Exp $ */ +/* $OpenBSD: hist.h,v 1.7 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: hist.h,v 1.10 2003/08/07 16:44:31 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * --- 1.2/cmd-line-utils/libedit/histedit.h 2004-08-24 08:41:37 -07:00 +++ 1.3/cmd-line-utils/libedit/histedit.h 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: histedit.h,v 1.21 2003/01/21 18:40:24 christos Exp $ */ +/* $OpenBSD: histedit.h,v 1.9 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: histedit.h,v 1.24 2003/10/16 22:26:32 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -45,7 +42,7 @@ #define _HISTEDIT_H_ #define LIBEDIT_MAJOR 2 -#define LIBEDIT_MINOR 6 +#define LIBEDIT_MINOR 8 #include #include @@ -131,6 +128,8 @@ #define EL_RPROMPT 12 /* , el_pfunc_t); */ #define EL_GETCFN 13 /* , el_rfunc_t); */ #define EL_CLIENTDATA 14 /* , void *); */ +#define EL_UNBUFFERED 15 /* , int); */ +#define EL_PREP_TERM 16 /* , int); */ #define EL_BUILTIN_GETCFN (NULL) --- 1.7/cmd-line-utils/libedit/history.c 2004-08-27 08:32:23 -07:00 +++ 1.8/cmd-line-utils/libedit/history.c 2005-04-05 19:43:52 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: history.c,v 1.22 2003/01/21 18:40:24 christos Exp $ */ +/* $OpenBSD: history.c,v 1.13 2004/08/23 18:31:25 otto Exp $ */ +/* $NetBSD: history.c,v 1.25 2003/10/18 23:48:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: history.c,v 1.22 2003/01/21 18:40:24 christos Exp $"); +static const char rcsid[] = "$OpenBSD: history.c,v 1.13 2004/08/23 18:31:25 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -91,6 +88,7 @@ #define HENTER(h, ev, str) (*(h)->h_enter)((h)->h_ref, ev, str) #define HADD(h, ev, str) (*(h)->h_add)((h)->h_ref, ev, str) +#define h_strdup(a) strdup(a) #define h_malloc(a) malloc(a) #define h_realloc(a, b) realloc((a), (b)) #define h_free(a) free(a) @@ -374,7 +372,8 @@ */ /* ARGSUSED */ private void -history_def_delete(history_t *h, HistEvent *ev __attribute__((unused)), hentry_t *hp) +history_def_delete(history_t *h, + HistEvent *ev __attribute__((__unused__)), hentry_t *hp) { HistEventPrivate *evp = (void *)&hp->ev; if (hp == &h->list) @@ -397,7 +396,7 @@ h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t)); if (h->cursor == NULL) goto oomem; - if ((h->cursor->ev.str = strdup(str)) == NULL) { + if ((h->cursor->ev.str = h_strdup(str)) == NULL) { h_free((ptr_t)h->cursor); goto oomem; } @@ -447,7 +446,7 @@ */ /* ARGSUSED */ private int -history_def_init(ptr_t *p, HistEvent *ev __attribute__((unused)), int n) +history_def_init(ptr_t *p, HistEvent *ev __attribute__((__unused__)), int n) { history_t *h = (history_t *) h_malloc(sizeof(history_t)); if (h == NULL) @@ -652,27 +651,39 @@ history_load(History *h, const char *fname) { FILE *fp; - char *line; + char *line, *lbuf; size_t sz, max_size; char *ptr; int i = -1; HistEvent ev; + lbuf = NULL; if ((fp = fopen(fname, "r")) == NULL) return (i); + if ((line = fgetln(fp, &sz)) == NULL) + goto done; + + if (strncmp(line, hist_cookie, sz) != 0) + goto done; + ptr = h_malloc(max_size = 1024); if (ptr == NULL) goto done; for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) { - char c = line[sz]; - - if (sz != 0 && line[sz - 1] == '\n') - line[--sz] = '\0'; - else - line[sz] = '\0'; - - if (max_size < sz) { + if (line[sz - 1] == '\n') + line[sz - 1] = '\0'; + else { + lbuf = malloc(sz + 1); + if (lbuf == NULL) { + i = -1; + goto oomem; + } + memcpy(lbuf, line, sz); + lbuf[sz++] = '\0'; + line = lbuf; + } + if (sz > max_size) { char *nptr; max_size = (sz + 1023) & ~1023; nptr = h_realloc(ptr, max_size); @@ -683,7 +694,6 @@ ptr = nptr; } (void) strunvis(ptr, line); - line[sz] = c; if (HENTER(h, &ev, ptr) == -1) { h_free((ptr_t)ptr); return -1; @@ -692,6 +702,7 @@ oomem: h_free((ptr_t)ptr); done: + h_free(lbuf); (void) fclose(fp); return (i); } @@ -714,6 +725,8 @@ if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1) goto done; + if (fputs(hist_cookie, fp) == EOF) + goto done; ptr = h_malloc(max_size = 1024); if (ptr == NULL) goto done; @@ -721,7 +734,7 @@ retval != -1; retval = HPREV(h, &ev), i++) { len = strlen(ev.str) * 4 + 1; - if (len >= max_size) { + if (len > max_size) { char *nptr; max_size = (len + 1023) & ~1023; nptr = h_realloc(ptr, max_size); @@ -732,7 +745,7 @@ ptr = nptr; } (void) strvis(ptr, ev.str, VIS_WHITE); - (void) fprintf(fp, "%s\n", ev.str); + (void) fprintf(fp, "%s\n", ptr); } oomem: h_free((ptr_t)ptr); --- 1.4/cmd-line-utils/libedit/key.c 2004-09-03 05:47:32 -07:00 +++ 1.5/cmd-line-utils/libedit/key.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: key.c,v 1.13 2002/03/18 16:00:55 christos Exp $ */ +/* $OpenBSD: key.c,v 1.9 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: key.c,v 1.15 2003/10/18 23:48:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: key.c,v 1.13 2002/03/18 16:00:55 christos Exp $"); +static const char rcsid[] = "$OpenBSD: key.c,v 1.9 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -103,14 +100,14 @@ * Initialize the key maps */ protected int -el_key_init(EditLine *el) +key_init(EditLine *el) { el->el_key.buf = (char *) el_malloc(KEY_BUFSIZ); if (el->el_key.buf == NULL) return (-1); el->el_key.map = NULL; - el_key_reset(el); + key_reset(el); return (0); } @@ -119,7 +116,7 @@ * Free the key maps */ protected void -el_key_end(EditLine *el) +key_end(EditLine *el) { el_free((ptr_t) el->el_key.buf); @@ -133,7 +130,7 @@ * Associate cmd with a key value */ protected key_value_t * -el_key_map_cmd(EditLine *el, int cmd) +key_map_cmd(EditLine *el, int cmd) { el->el_key.val.cmd = (el_action_t) cmd; @@ -145,7 +142,7 @@ * Associate str with a key value */ protected key_value_t * -el_key_map_str(EditLine *el, char *str) +key_map_str(EditLine *el, char *str) { el->el_key.val.str = str; @@ -159,7 +156,7 @@ * [Always bind the ansi arrow keys?] */ protected void -el_key_reset(EditLine *el) +key_reset(EditLine *el) { node__put(el, el->el_key.map); @@ -177,7 +174,7 @@ * The last character read is returned in *ch. */ protected int -el_key_get(EditLine *el, char *ch, key_value_t *val) +key_get(EditLine *el, char *ch, key_value_t *val) { return (node_trav(el, el->el_key.map, ch, val)); @@ -191,7 +188,7 @@ * out str or a unix command. */ protected void -el_key_add(EditLine *el, const char *key, key_value_t *val, int ntype) +key_add(EditLine *el, const char *key, key_value_t *val, int ntype) { if (key[0] == '\0') { @@ -219,7 +216,7 @@ * */ protected void -el_key_clear(EditLine *el, el_action_t *map, const char *in) +key_clear(EditLine *el, el_action_t *map, const char *in) { if ((map[(unsigned char)*in] == ED_SEQUENCE_LEAD_IN) && @@ -227,7 +224,7 @@ el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) || (map == el->el_map.alt && el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN))) - (void) el_key_delete(el, in); + (void) key_delete(el, in); } @@ -236,7 +233,7 @@ * they exists. */ protected int -el_key_delete(EditLine *el, const char *key) +key_delete(EditLine *el, const char *key) { if (key[0] == '\0') { @@ -257,7 +254,7 @@ * Print entire el->el_key.map if null */ protected void -el_key_print(EditLine *el, const char *key) +key_print(EditLine *el, const char *key) { /* do nothing if el->el_key.map is empty and null key specified */ @@ -356,7 +353,8 @@ break; case XK_STR: case XK_EXE: - ptr->val.str = strdup(val->str); + if ((ptr->val.str = el_strdup(val->str)) == NULL) + return -1; break; default: EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype)); @@ -504,7 +502,7 @@ if (str[1] == 0) { el->el_key.buf[ncnt + 1] = '"'; el->el_key.buf[ncnt + 2] = '\0'; - el_key_kprint(el, el->el_key.buf, + key_kprint(el, el->el_key.buf, &ptr->val, ptr->type); return (0); } else @@ -552,7 +550,7 @@ /* print this key and function */ el->el_key.buf[ncnt + 1] = '"'; el->el_key.buf[ncnt + 2] = '\0'; - el_key_kprint(el, el->el_key.buf, &ptr->val, ptr->type); + key_kprint(el, el->el_key.buf, &ptr->val, ptr->type); } else (void) node_enum(el, ptr->next, ncnt + 1); @@ -568,7 +566,7 @@ * function specified by val */ protected void -el_key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype) +key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype) { el_bindings_t *fp; char unparsbuf[EL_BUFSIZ]; @@ -579,7 +577,7 @@ case XK_STR: case XK_EXE: (void) fprintf(el->el_outfile, fmt, key, - el_key__decode_str(val->str, unparsbuf, + key__decode_str(val->str, unparsbuf, ntype == XK_STR ? "\"\"" : "[]")); break; case XK_CMD: @@ -644,7 +642,7 @@ * Make a printable version of the ey */ protected char * -el_key__decode_str(const char *str, char *buf, const char *sep) +key__decode_str(const char *str, char *buf, const char *sep) { char *b; const char *p; --- 1.4/cmd-line-utils/libedit/key.h 2004-09-03 05:47:32 -07:00 +++ 1.5/cmd-line-utils/libedit/key.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: key.h,v 1.6 2002/03/18 16:00:55 christos Exp $ */ +/* $OpenBSD: key.h,v 1.7 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: key.h,v 1.8 2003/08/07 16:44:32 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -62,19 +59,22 @@ #define XK_NOD 2 #define XK_EXE 3 -protected int el_key_init(EditLine *); -protected void el_key_end(EditLine *); -protected key_value_t *el_key_map_cmd(EditLine *, int); -protected key_value_t *el_key_map_str(EditLine *, char *); -protected void el_key_reset(EditLine *); -protected int el_key_get(EditLine *, char *, key_value_t *); -protected void el_key_add(EditLine *, - const char *, key_value_t *, int); -protected void el_key_clear(EditLine *, el_action_t *, const char *); -protected int el_key_delete(EditLine *, const char *); -protected void el_key_print(EditLine *, const char *); -protected void el_key_kprint(EditLine *, const char *, key_value_t *, +#undef key_end +#undef key_clear +#undef key_print + +protected int key_init(EditLine *); +protected void key_end(EditLine *); +protected key_value_t *key_map_cmd(EditLine *, int); +protected key_value_t *key_map_str(EditLine *, char *); +protected void key_reset(EditLine *); +protected int key_get(EditLine *, char *, key_value_t *); +protected void key_add(EditLine *, const char *, key_value_t *, int); +protected void key_clear(EditLine *, el_action_t *, const char *); +protected int key_delete(EditLine *, const char *); +protected void key_print(EditLine *, const char *); +protected void key_kprint(EditLine *, const char *, key_value_t *, int); -protected char *el_key__decode_str(const char *, char *, const char *); +protected char *key__decode_str(const char *, char *, const char *); #endif /* _h_el_key */ --- 1.6/cmd-line-utils/libedit/map.c 2004-09-03 05:47:32 -07:00 +++ 1.7/cmd-line-utils/libedit/map.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: map.c,v 1.18 2002/11/15 14:32:33 christos Exp $ */ +/* $OpenBSD: map.c,v 1.9 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: map.c,v 1.19 2003/08/07 16:44:32 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: map.c,v 1.18 2002/11/15 14:32:33 christos Exp $"); +static const char rcsid[] = "$OpenBSD: map.c,v 1.9 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -287,7 +284,7 @@ /* 221 */ ED_UNASSIGNED, /* M-] */ /* 222 */ ED_UNASSIGNED, /* M-^ */ /* 223 */ ED_UNASSIGNED, /* M-_ */ - /* 223 */ ED_UNASSIGNED, /* M-` */ + /* 224 */ ED_UNASSIGNED, /* M-a */ /* 225 */ ED_PREV_WORD, /* M-b */ /* 226 */ EM_CAPITOL_CASE, /* M-c */ @@ -1011,8 +1008,7 @@ break; default: buf[1] = i & 0177; - el_key_add(el, buf, - el_key_map_cmd(el, (int) map[i]), XK_CMD); + key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD); break; } map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN; @@ -1034,7 +1030,7 @@ el->el_map.type = MAP_VI; el->el_map.current = el->el_map.key; - el_key_reset(el); + key_reset(el); for (i = 0; i < N_KEYS; i++) { key[i] = vii[i]; @@ -1063,7 +1059,7 @@ el->el_map.type = MAP_EMACS; el->el_map.current = el->el_map.key; - el_key_reset(el); + key_reset(el); for (i = 0; i < N_KEYS; i++) { key[i] = emacs[i]; @@ -1076,7 +1072,7 @@ buf[0] = CONTROL('X'); buf[1] = CONTROL('X'); buf[2] = 0; - el_key_add(el, buf, el_key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD); + key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD); tty_bind_char(el, 1); term_bind_arrow(el); @@ -1133,7 +1129,7 @@ el_bindings_t *bp; if (in[0] == '\0' || in[1] == '\0') { - (void) el_key__decode_str(in, outbuf, ""); + (void) key__decode_str(in, outbuf, ""); for (bp = el->el_map.help; bp->name != NULL; bp++) if (bp->func == map[(unsigned char) *in]) { (void) fprintf(el->el_outfile, @@ -1141,7 +1137,7 @@ return; } } else - el_key_print(el, in); + key_print(el, in); } @@ -1163,20 +1159,20 @@ if (first == last) (void) fprintf(el->el_outfile, "%-15s-> is undefined\n", - el_key__decode_str(firstbuf, unparsbuf, STRQQ)); + key__decode_str(firstbuf, unparsbuf, STRQQ)); return; } for (bp = el->el_map.help; bp->name != NULL; bp++) { if (bp->func == map[first]) { if (first == last) { (void) fprintf(el->el_outfile, "%-15s-> %s\n", - el_key__decode_str(firstbuf, unparsbuf, STRQQ), + key__decode_str(firstbuf, unparsbuf, STRQQ), bp->name); } else { (void) fprintf(el->el_outfile, "%-4s to %-7s-> %s\n", - el_key__decode_str(firstbuf, unparsbuf, STRQQ), - el_key__decode_str(lastbuf, extrabuf, STRQQ), + key__decode_str(firstbuf, unparsbuf, STRQQ), + key__decode_str(lastbuf, extrabuf, STRQQ), bp->name); } return; @@ -1230,7 +1226,7 @@ map_print_some_keys(el, el->el_map.alt, prev, i - 1); (void) fprintf(el->el_outfile, "Multi-character bindings\n"); - el_key_print(el, ""); + key_print(el, ""); (void) fprintf(el->el_outfile, "Arrow key bindings\n"); term_print_arrow(el, ""); } @@ -1323,9 +1319,9 @@ return (-1); } if (in[1]) - (void) el_key_delete(el, in); + (void) key_delete(el, in); else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN) - (void) el_key_delete(el, in); + (void) key_delete(el, in); else map[(unsigned char) *in] = ED_UNASSIGNED; return (0); @@ -1353,9 +1349,9 @@ return (-1); } if (key) - term_set_arrow(el, in, el_key_map_str(el, out), ntype); + term_set_arrow(el, in, key_map_str(el, out), ntype); else - el_key_add(el, in, el_key_map_str(el, out), ntype); + key_add(el, in, key_map_str(el, out), ntype); map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN; break; @@ -1366,13 +1362,13 @@ return (-1); } if (key) - term_set_arrow(el, in, el_key_map_str(el, out), ntype); + term_set_arrow(el, in, key_map_str(el, out), ntype); else { if (in[1]) { - el_key_add(el, in, el_key_map_cmd(el, cmd), ntype); + key_add(el, in, key_map_cmd(el, cmd), ntype); map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN; } else { - el_key_clear(el, map, in); + key_clear(el, map, in); map[(unsigned char) *in] = cmd; } } --- 1.2/cmd-line-utils/libedit/map.h 2004-08-24 08:41:37 -07:00 +++ 1.3/cmd-line-utils/libedit/map.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: map.h,v 1.7 2002/03/18 16:00:56 christos Exp $ */ +/* $OpenBSD: map.h,v 1.7 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: map.h,v 1.8 2003/08/07 16:44:32 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * --- 1.4/cmd-line-utils/libedit/parse.c 2005-01-08 12:25:24 -08:00 +++ 1.5/cmd-line-utils/libedit/parse.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: parse.c,v 1.16 2003/01/21 18:40:24 christos Exp $ */ +/* $OpenBSD: parse.c,v 1.8 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: parse.c,v 1.19 2003/11/02 20:06:57 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: parse.c,v 1.16 2003/01/21 18:40:24 christos Exp $"); +static const char rcsid[] = "$OpenBSD: parse.c,v 1.8 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -87,8 +84,7 @@ int argc; Tokenizer *tok; - if (!(tok = tok_init(NULL))) - return -1; + tok = tok_init(NULL); tok_line(tok, line, &argc, &argv); argc = el_parse(el, argc, argv); tok_end(tok); @@ -207,7 +203,7 @@ c = *p; break; } - } else if (*p == '^' && isalpha((unsigned char) p[1])) { + } else if (*p == '^') { p++; c = (*p == '?') ? '\177' : (*p & 0237); } else @@ -215,6 +211,7 @@ *ptr = ++p; return (c); } + /* parse__string(): * Parse the escapes from in and put the raw string out */ @@ -236,6 +233,14 @@ return (NULL); *out++ = n; break; + + case 'M': + if (in[1] == '-' && in[2] != '\0') { + *out++ = '\033'; + in += 2; + break; + } + /*FALLTHROUGH*/ default: *out++ = *in++; --- 1.1/cmd-line-utils/libedit/parse.h 2003-01-18 08:28:16 -08:00 +++ 1.2/cmd-line-utils/libedit/parse.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: parse.h,v 1.4 2000/09/04 22:06:31 lukem Exp $ */ +/* $OpenBSD: parse.h,v 1.6 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: parse.h,v 1.5 2003/08/07 16:44:32 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * --- 1.3/cmd-line-utils/libedit/prompt.c 2004-08-24 08:41:37 -07:00 +++ 1.4/cmd-line-utils/libedit/prompt.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: prompt.c,v 1.9 2002/03/18 16:00:56 christos Exp $ */ +/* $OpenBSD: prompt.c,v 1.7 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: prompt.c,v 1.11 2003/08/07 16:44:32 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: prompt.c,v 1.9 2002/03/18 16:00:56 christos Exp $"); +static const char rcsid[] = "$OpenBSD: prompt.c,v 1.7 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -59,7 +56,7 @@ */ private char * /*ARGSUSED*/ -prompt_default(EditLine *el __attribute__((unused))) +prompt_default(EditLine *el __attribute__((__unused__))) { static char a[3] = {'?', ' ', '\0'}; @@ -72,7 +69,7 @@ */ private char * /*ARGSUSED*/ -prompt_default_r(EditLine *el __attribute__((unused))) +prompt_default_r(EditLine *el __attribute__((__unused__))) { static char a[1] = {'\0'}; @@ -127,7 +124,7 @@ */ protected void /*ARGSUSED*/ -prompt_end(EditLine *el __attribute__((unused))) +prompt_end(EditLine *el __attribute__((__unused__))) { } --- 1.1/cmd-line-utils/libedit/prompt.h 2003-01-18 08:28:16 -08:00 +++ 1.2/cmd-line-utils/libedit/prompt.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: prompt.h,v 1.5 2000/09/04 22:06:31 lukem Exp $ */ +/* $OpenBSD: prompt.h,v 1.6 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: prompt.h,v 1.6 2003/08/07 16:44:32 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * --- 1.5/cmd-line-utils/libedit/read.c 2004-09-03 05:47:32 -07:00 +++ 1.6/cmd-line-utils/libedit/read.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: read.c,v 1.24 2002/11/20 16:50:08 christos Exp $ */ +/* $OpenBSD: read.c,v 1.11 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: read.c,v 1.30 2003/10/18 23:48:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: read.c,v 1.24 2002/11/20 16:50:08 christos Exp $"); +static const char rcsid[] = "$OpenBSD: read.c,v 1.11 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -50,6 +47,7 @@ * Terminal read functions */ #include +#include #include #include #include "el.h" @@ -97,6 +95,10 @@ } +#ifndef MIN +#define MIN(A,B) ((A) < (B) ? (A) : (B)) +#endif + #ifdef DEBUG_EDIT private void read_debug(EditLine *el) @@ -121,11 +123,7 @@ */ /* ARGSUSED */ private int -read__fixio(int fd -#if !(defined(TRY_AGAIN) && (defined(FIONBIO) || (defined(F_SETFL) && defined(O_NDELAY)))) - __attribute__((unused)) -#endif /* !(defined(TRY_AGAIN) && (defined(FIONBIO) || (defined(F_SETFL) && defined(O_NDELAY)))) */ -, int e) +read__fixio(int fd __attribute__((__unused__)), int e) { switch (e) { @@ -190,18 +188,10 @@ { int chrs = 0; - if (el->el_chared.c_macro.nline) { - el_free((ptr_t) el->el_chared.c_macro.nline); - el->el_chared.c_macro.nline = NULL; - } if (el->el_tty.t_mode == ED_IO) return (0); #ifdef FIONREAD - -#ifndef MIN // definition of MIN is lacking on hpux.. -#define MIN(x,y) (((x)<(y))?(x):(y)) -#endif (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs); if (chrs > 0) { char buf[EL_BUFSIZ]; @@ -210,8 +200,7 @@ (size_t) MIN(chrs, EL_BUFSIZ - 1)); if (chrs > 0) { buf[chrs] = '\0'; - el->el_chared.c_macro.nline = strdup(buf); - el_push(el, el->el_chared.c_macro.nline); + el_push(el, buf); } } #endif /* FIONREAD */ @@ -230,11 +219,12 @@ if (str != NULL && ma->level + 1 < EL_MAXMACRO) { ma->level++; - ma->macro[ma->level] = str; - } else { - term_beep(el); - term__flush(); + if ((ma->macro[ma->level] = el_strdup(str)) != NULL) + return; + ma->level--; } + term_beep(el); + term__flush(); } @@ -266,7 +256,7 @@ cmd = el->el_map.current[(unsigned char) *ch]; if (cmd == ED_SEQUENCE_LEAD_IN) { key_value_t val; - switch (el_key_get(el, ch, &val)) { + switch (key_get(el, ch, &val)) { case XK_CMD: cmd = val.cmd; break; @@ -331,14 +321,16 @@ if (ma->level < 0) break; - if (*ma->macro[ma->level] == 0) { - ma->level--; + if (ma->macro[ma->level][ma->offset] == '\0') { + el_free(ma->macro[ma->level--]); + ma->offset = 0; continue; } - *cp = *ma->macro[ma->level]++ & 0377; - if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode - * On */ - ma->level--; + *cp = ma->macro[ma->level][ma->offset++] & 0377; + if (ma->macro[ma->level][ma->offset] == '\0') { + /* Needed for QuoteMode On */ + el_free(ma->macro[ma->level--]); + ma->offset = 0; } return (1); } @@ -359,6 +351,32 @@ return (num_read); } +protected void +read_prepare(EditLine *el) +{ + if (el->el_flags & HANDLE_SIGNALS) + sig_set(el); + if (el->el_flags & NO_TTY) + return; + if ((el->el_flags & (UNBUFFERED|EDIT_DISABLED)) == UNBUFFERED) + tty_rawmode(el); + + /* This is relatively cheap, and things go terribly wrong if + we have the wrong size. */ + el_resize(el); + re_clear_display(el); /* reset the display stuff */ + ch_reset(el); + re_refresh(el); /* print the prompt */ +} + +protected void +read_finish(EditLine *el) +{ + if ((el->el_flags & UNBUFFERED) == 0) + (void) tty_cookedmode(el); + if (el->el_flags & HANDLE_SIGNALS) + sig_clr(el); +} public const char * el_gets(EditLine *el, int *nread) @@ -367,13 +385,11 @@ el_action_t cmdnum = 0; int num; /* how many chars we have read at NL */ char ch; + int crlf = 0; #ifdef FIONREAD c_macro_t *ma = &el->el_chared.c_macro; #endif /* FIONREAD */ - if (el->el_flags & HANDLE_SIGNALS) - sig_set(el); - if (el->el_flags & NO_TTY) { char *cp = el->el_line.buffer; size_t idx; @@ -387,6 +403,8 @@ cp = &el->el_line.buffer[idx]; } cp++; + if (el->el_flags & UNBUFFERED) + break; if (cp[-1] == '\r' || cp[-1] == '\n') break; } @@ -398,12 +416,6 @@ return (el->el_line.buffer); } - /* This is relatively cheap, and things go terribly wrong if - we have the wrong size. */ - el_resize(el); - - re_clear_display(el); /* reset the display stuff */ - ch_reset(el); #ifdef FIONREAD if (el->el_tty.t_mode == EX_IO && ma->level < 0) { @@ -420,7 +432,8 @@ } #endif /* FIONREAD */ - re_refresh(el); /* print the prompt */ + if ((el->el_flags & UNBUFFERED) == 0) + read_prepare(el); if (el->el_flags & EDIT_DISABLED) { char *cp = el->el_line.buffer; @@ -439,7 +452,10 @@ if (*cp == 4) /* ought to be stty eof */ break; cp++; - if (cp[-1] == '\r' || cp[-1] == '\n') + crlf = cp[-1] == '\r' || cp[-1] == '\n'; + if (el->el_flags & UNBUFFERED) + break; + if (crlf) break; } @@ -463,8 +479,7 @@ #endif /* DEBUG_READ */ break; } - if ((unsigned int)cmdnum >= (unsigned int)(el->el_map.nfunc)) - { /* BUG CHECK command */ + if ((uint)cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */ #ifdef DEBUG_EDIT (void) fprintf(el->el_errfile, "ERROR: illegal command from key 0%o\r\n", ch); @@ -536,7 +551,13 @@ continue; /* keep going... */ case CC_EOF: /* end of file typed */ - num = 0; + if ((el->el_flags & UNBUFFERED) == 0) + num = 0; + else if (num == -1) { + *el->el_line.lastchar++ = CTRL('d'); + el->el_line.cursor = el->el_line.lastchar; + num = 1; + } break; case CC_NEWLINE: /* normal end of line */ @@ -567,14 +588,19 @@ el->el_state.argument = 1; el->el_state.doingarg = 0; el->el_chared.c_vcmd.action = NOP; + if (el->el_flags & UNBUFFERED) + break; } term__flush(); /* flush any buffered output */ /* make sure the tty is set up correctly */ - (void) tty_cookedmode(el); - if (el->el_flags & HANDLE_SIGNALS) - sig_clr(el); - if (nread) - *nread = num; + if ((el->el_flags & UNBUFFERED) == 0) { + read_finish(el); + if (nread) + *nread = num; + } else { + if (nread) + *nread = el->el_line.lastchar - el->el_line.buffer; + } return (num ? el->el_line.buffer : NULL); } --- 1.1/cmd-line-utils/libedit/read.h 2004-08-24 09:52:10 -07:00 +++ 1.2/cmd-line-utils/libedit/read.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: read.h,v 1.1 2001/09/27 19:29:50 christos Exp $ */ +/* $OpenBSD: read.h,v 1.1 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: read.h,v 1.2 2003/09/26 17:44:51 christos Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -49,6 +50,8 @@ } el_read_t; protected int read_init(EditLine *); +protected void read_prepare(EditLine *); +protected void read_finish(EditLine *); protected int el_read_setfn(EditLine *, el_rfunc_t); protected el_rfunc_t el_read_getfn(EditLine *); --- 1.6/cmd-line-utils/libedit/readline.c 2004-08-31 06:28:58 -07:00 +++ 1.7/cmd-line-utils/libedit/readline.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: readline.c,v 1.28 2003/03/10 01:14:54 christos Exp $ */ +/* $OpenBSD: readline.c,v 1.2 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: readline.c,v 1.43 2003/11/03 03:22:55 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +39,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.28 2003/03/10 01:14:54 christos Exp $"); +static const char rcsid[] = "$OpenBSD"; #endif /* not lint && not SCCSID */ #include @@ -51,19 +52,27 @@ #include #include #include +#include +#include +#ifdef HAVE_VIS_H +#include +#else +#include "np/vis.h" +#endif #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 */ /* for rl_complete() */ -#define TAB '\r' +#define TAB '\r' /* see comment at the #ifdef for sense of this */ -#define GDB_411_HACK +/* #define GDB_411_HACK */ /* readline compatibility stuff - look at readline sources/documentation */ /* to see what these variables mean */ @@ -78,6 +87,9 @@ int rl_point = 0; int rl_end = 0; char *rl_line_buffer = NULL; +VFunction *rl_linefunc = NULL; +int rl_done = 0; +VFunction *rl_event_hook = NULL; int history_base = 1; /* probably never subject to change */ int history_length = 0; @@ -86,16 +98,34 @@ char history_subst_char = '^'; char *history_no_expand_chars = expand_chars; Function *history_inhibit_expansion_function = NULL; +char *history_arg_extract(int start, int end, const char *str); int rl_inhibit_completion = 0; int rl_attempted_completion_over = 0; char *rl_basic_word_break_characters = break_chars; char *rl_completer_word_break_characters = NULL; char *rl_completer_quote_characters = NULL; -CPFunction *rl_completion_entry_function = NULL; +Function *rl_completion_entry_function = NULL; CPPFunction *rl_attempted_completion_function = NULL; +Function *rl_pre_input_hook = NULL; +Function *rl_startup1_hook = NULL; +Function *rl_getc_function = NULL; +char *rl_terminal_name = NULL; +int rl_already_prompted = 0; +int rl_filename_completion_desired = 0; +int rl_ignore_completion_duplicates = 0; +int rl_catch_signals = 1; +VFunction *rl_redisplay_function = NULL; +Function *rl_startup_hook = NULL; +VFunction *rl_completion_display_matches_hook = NULL; +VFunction *rl_prep_term_function = NULL; +VFunction *rl_deprep_term_function = NULL; /* + * The current prompt string. + */ +char *rl_prompt = NULL; +/* * This is set to character indicating type of completion being done by * rl_complete_internal(); this is available for application completion * functions. @@ -128,30 +158,28 @@ static History *h = NULL; static EditLine *e = NULL; +static Function *map[256]; static int el_rl_complete_cmdnum = 0; /* internal functions */ static unsigned char _el_rl_complete(EditLine *, int); static char *_get_prompt(EditLine *); static HIST_ENTRY *_move_history(int); -static int _history_search_gen(const char *, int, int); -static int _history_expand_command(const char *, size_t, char **); +static int _history_expand_command(const char *, size_t, size_t, + char **); static char *_rl_compat_sub(const char *, const char *, - const char *, int); + const char *, int); static int rl_complete_internal(int); static int _rl_qsort_string_compare(const void *, const void *); - -/* - * needed for prompt switching in readline() - */ -static char *el_rl_prompt = NULL; +static int _rl_event_read_char(EditLine *, char *); /* ARGSUSED */ static char * -_get_prompt(EditLine *el __attribute__((unused))) +_get_prompt(EditLine *el __attribute__((__unused__))) { - return (el_rl_prompt); + rl_already_prompted = 1; + return (rl_prompt); } @@ -168,7 +196,7 @@ return (HIST_ENTRY *) NULL; rl_he.line = ev.str; - rl_he.data = ""; + rl_he.data = NULL; return (&rl_he); } @@ -221,28 +249,31 @@ el_set(e, EL_HIST, history, h); /* for proper prompt printing in readline() */ - el_rl_prompt = strdup(""); - if (el_rl_prompt == NULL) { + rl_prompt = strdup(""); + if (rl_prompt == NULL) { history_end(h); el_end(e); return -1; } el_set(e, EL_PROMPT, _get_prompt); - el_set(e, EL_SIGNAL, 1); + el_set(e, EL_SIGNAL, rl_catch_signals); /* set default mode to "emacs"-style and read setting afterwards */ /* so this can be overriden */ el_set(e, EL_EDITOR, "emacs"); + if (rl_terminal_name != NULL) + el_set(e, EL_TERMINAL, rl_terminal_name); + else + el_get(e, EL_TERMINAL, &rl_terminal_name); /* - * Word completition - this has to go AFTER rebinding keys + * Word completion - this has to go AFTER rebinding keys * to emacs-style. */ el_set(e, EL_ADDFN, "rl_complete", - "ReadLine compatible completition function", + "ReadLine compatible completion function", _el_rl_complete); el_set(e, EL_BIND, "^I", "rl_complete", NULL); - /* * Find out where the rl_complete function was added; this is * used later to detect that lastcmd was also rl_complete. @@ -266,6 +297,9 @@ rl_line_buffer = memchr(li->buffer, *li->buffer, 1); rl_point = rl_end = 0; + if (rl_startup_hook) + (*rl_startup_hook)(NULL, 0); + return (0); } @@ -281,19 +315,38 @@ int count; const char *ret; char *buf; + static int used_event_hook; if (e == NULL || h == NULL) rl_initialize(); + rl_done = 0; + /* update prompt accordingly to what has been passed */ if (!prompt) prompt = ""; - if (strcmp(el_rl_prompt, prompt) != 0) { - free(el_rl_prompt); - el_rl_prompt = strdup(prompt); - if (el_rl_prompt == NULL) + if (strcmp(rl_prompt, prompt) != 0) { + free(rl_prompt); + rl_prompt = strdup(prompt); + if (rl_prompt == NULL) return NULL; } + + if (rl_pre_input_hook) + (*rl_pre_input_hook)(NULL, 0); + + if (rl_event_hook && !(e->el_flags&NO_TTY)) { + el_set(e, EL_GETCFN, _rl_event_read_char); + used_event_hook = 1; + } + + if (!rl_event_hook && used_event_hook) { + el_set(e, EL_GETCFN, EL_BUILTIN_GETCFN); + used_event_hook = 0; + } + + rl_already_prompted = 0; + /* get one line from input stream */ ret = el_gets(e, &count); @@ -333,73 +386,180 @@ /* * substitute ``what'' with ``with'', returning resulting string; if - * globally == 1, substitutes all occurences of what, otherwise only the + * globally == 1, substitutes all occurrences of what, otherwise only the * first one */ static char * _rl_compat_sub(const char *str, const char *what, const char *with, int globally) { - char *result; - const char *temp, *new; - unsigned int len, with_len, what_len, add; - size_t size, i; + const char *s; + char *r, *result; + size_t len, with_len, what_len; - result = malloc((size = 16)); - if (result == NULL) - return NULL; - temp = str; + len = strlen(str); with_len = strlen(with); what_len = strlen(what); - len = 0; - do { - new = strstr(temp, what); - if (new) { - i = new - temp; - add = i + with_len; - if (i + add + 1 >= size) { - char *nresult; - size += add + 1; - nresult = realloc(result, size); - if (nresult == NULL) { - free(result); - return NULL; - } - result = nresult; - } - (void) strncpy(&result[len], temp, i); - len += i; - (void) strcpy(&result[len], with); /* safe */ - len += with_len; - temp = new + what_len; - } else { - add = strlen(temp); - if (len + add + 1 >= size) { - char *nresult; - size += add + 1; - nresult = realloc(result, size); - if (nresult == NULL) { - free(result); - return NULL; - } - result = nresult; + + /* calculate length we need for result */ + s = str; + while (*s) { + if (*s == *what && !strncmp(s, what, what_len)) { + len += with_len - what_len; + if (!globally) + break; + s += what_len; + } else + s++; + } + len++; + r = result = malloc(len); + if (result == NULL) + return NULL; + s = str; + while (*s) { + if (*s == *what && !strncmp(s, what, what_len)) { + (void)strncpy(r, with, with_len); + r += with_len; + len -= with_len; + s += what_len; + if (!globally) { + (void)strlcpy(r, s, len); + return(result); } - (void) strcpy(&result[len], temp); /* safe */ - len += add; - temp = NULL; + } else + *r++ = *s++; + } + *r = 0; + return(result); +} + +static char *last_search_pat; /* last !?pat[?] search pattern */ +static char *last_search_match; /* last !?pat[?] that matched */ + +const char * +get_history_event(const char *cmd, int *cindex, int qchar) +{ + int idx, sign, sub, num, begin, ret; + size_t len; + char *pat; + const char *rptr; + HistEvent ev; + + idx = *cindex; + if (cmd[idx++] != history_expansion_char) + return(NULL); + + /* find out which event to take */ + if (cmd[idx] == history_expansion_char || cmd[idx] == 0) { + if (history(h, &ev, H_FIRST) != 0) + return(NULL); + *cindex = cmd[idx]? (idx + 1):idx; + return(ev.str); + } + sign = 0; + if (cmd[idx] == '-') { + sign = 1; + idx++; + } + + if ('0' <= cmd[idx] && cmd[idx] <= '9') { + HIST_ENTRY *rl_he; + + num = 0; + while (cmd[idx] && '0' <= cmd[idx] && cmd[idx] <= '9') { + num = num * 10 + cmd[idx] - '0'; + idx++; } - } while (temp && globally); - result[len] = '\0'; + if (sign) + num = history_length - num + 1; - return (result); -} + if (!(rl_he = history_get(num))) + return(NULL); + + *cindex = idx; + return(rl_he->line); + } + sub = 0; + if (cmd[idx] == '?') { + sub = 1; + idx++; + } + begin = idx; + while (cmd[idx]) { + if (cmd[idx] == '\n') + break; + if (sub && cmd[idx] == '?') + break; + if (!sub && (cmd[idx] == ':' || cmd[idx] == ' ' + || cmd[idx] == '\t' || cmd[idx] == qchar)) + break; + idx++; + } + len = idx - begin; + if (sub && cmd[idx] == '?') + idx++; + if (sub && len == 0 && last_search_pat && *last_search_pat) + pat = last_search_pat; + else if (len == 0) + return(NULL); + else { + if ((pat = malloc(len + 1)) == NULL) + return NULL; + (void)strncpy(pat, cmd + begin, len); + pat[len] = '\0'; + } + if (history(h, &ev, H_CURR) != 0) { + if (pat != last_search_pat) + free(pat); + return (NULL); + } + num = ev.num; + + if (sub) { + if (pat != last_search_pat) { + if (last_search_pat) + free(last_search_pat); + last_search_pat = pat; + } + ret = history_search(pat, -1); + } else + ret = history_search_prefix(pat, -1); + + if (ret == -1) { + /* restore to end of list on failed search */ + history(h, &ev, H_FIRST); + (void)fprintf(rl_outstream, "%s: Event not found\n", pat); + if (pat != last_search_pat) + free(pat); + return(NULL); + } + + if (sub && len) { + if (last_search_match && last_search_match != pat) + free(last_search_match); + last_search_match = pat; + } + + if (pat != last_search_pat) + free(pat); + + if (history(h, &ev, H_CURR) != 0) + return(NULL); + *cindex = idx; + rptr = ev.str; + + /* roll back to original position */ + (void)history(h, &ev, H_SET, num); + + return rptr; +} /* * the real function doing history expansion - takes as argument command * to do and data upon which the command should be executed * does expansion the way I've understood readline documentation - * word designator ``%'' isn't supported (yet ?) * * returns 0 if data was not modified, 1 if it was and 2 if the string * should be only printed and not executed; in case of error, @@ -407,144 +567,145 @@ * it's callers responsibility to free() string returned in *result */ static int -_history_expand_command(const char *command, size_t cmdlen, char **result) +_history_expand_command(const char *command, size_t offs, size_t cmdlen, + char **result) { - char **arr, *tempcmd, *line, *search = NULL, *cmd; - const char *event_data = NULL; + char *tmp, *search = NULL, *aptr; + const char *ptr, *cmd; static char *from = NULL, *to = NULL; - int start = -1, end = -1, max, i, idx; - int h_on = 0, t_on = 0, r_on = 0, e_on = 0, p_on = 0, g_on = 0; - int event_num = 0, retval; - size_t cmdsize; + int start, end, idx, has_mods = 0; + int p_on = 0, g_on = 0; *result = NULL; + aptr = NULL; + ptr = NULL; - cmd = alloca(cmdlen + 1); - (void) strncpy(cmd, command, cmdlen); - cmd[cmdlen] = 0; + /* First get event specifier */ + idx = 0; - idx = 1; - /* find out which event to take */ - if (cmd[idx] == history_expansion_char) { - event_num = history_length; - idx++; + if (strchr(":^*$", command[offs + 1])) { + char str[4]; + /* + * "!:" is shorthand for "!!:". + * "!^", "!*" and "!$" are shorthand for + * "!!:^", "!!:*" and "!!:$" respectively. + */ + str[0] = str[1] = '!'; + str[2] = '0'; + ptr = get_history_event(str, &idx, 0); + idx = (command[offs + 1] == ':')? 1:0; + has_mods = 1; } else { - int off, num; - size_t len; - off = idx; - while (cmd[off] && !strchr(":^$*-%", cmd[off])) - off++; - num = atoi(&cmd[idx]); - if (num != 0) { - event_num = num; - if (num < 0) - event_num += history_length + 1; + if (command[offs + 1] == '#') { + /* use command so far */ + if ((aptr = malloc(offs + 1)) == NULL) + return -1; + (void)strncpy(aptr, command, offs); + aptr[offs] = '\0'; + idx = 1; } else { - int prefix = 1, curr_num; - HistEvent ev; + int qchar; - len = off - idx; - if (cmd[idx] == '?') { - idx++, len--; - if (cmd[off - 1] == '?') - len--; - else if (cmd[off] != '\n' && cmd[off] != '\0') - return (-1); - prefix = 0; - } - search = alloca(len + 1); - (void) strncpy(search, &cmd[idx], len); - search[len] = '\0'; - - if (history(h, &ev, H_CURR) != 0) - return (-1); - curr_num = ev.num; - - if (prefix) - retval = history_search_prefix(search, -1); - else - retval = history_search(search, -1); - - if (retval == -1) { - fprintf(rl_outstream, "%s: Event not found\n", - search); - return (-1); - } - if (history(h, &ev, H_CURR) != 0) - return (-1); - event_data = ev.str; - - /* roll back to original position */ - history(h, &ev, H_NEXT_EVENT, curr_num); + qchar = (offs > 0 && command[offs - 1] == '"')? '"':0; + ptr = get_history_event(command + offs, &idx, qchar); } - idx = off; + has_mods = command[offs + idx] == ':'; } - if (!event_data && event_num >= 0) { - HIST_ENTRY *rl_he; - rl_he = history_get(event_num); - if (!rl_he) - return (0); - event_data = rl_he->line; + if (ptr == NULL && aptr == NULL) + return(-1); + + if (!has_mods) { + *result = strdup(aptr? aptr : ptr); + if (aptr) + free(aptr); + return(1); + } + + cmd = command + offs + idx + 1; + + /* Now parse any word designators */ + + if (*cmd == '%') /* last word matched by ?pat? */ + tmp = strdup(last_search_match? last_search_match:""); + else if (strchr("^*$-0123456789", *cmd)) { + start = end = -1; + if (*cmd == '^') + start = end = 1, cmd++; + else if (*cmd == '$') + start = -1, cmd++; + else if (*cmd == '*') + start = 1, cmd++; + else if (*cmd == '-' || isdigit((unsigned char) *cmd)) { + start = 0; + while (*cmd && '0' <= *cmd && *cmd <= '9') + start = start * 10 + *cmd++ - '0'; + + if (*cmd == '-') { + if (isdigit((unsigned char) cmd[1])) { + cmd++; + end = 0; + while (*cmd && '0' <= *cmd && *cmd <= '9') + end = end * 10 + *cmd++ - '0'; + } else if (cmd[1] == '$') { + cmd += 2; + end = -1; + } else { + cmd++; + end = -2; + } + } else if (*cmd == '*') + end = -1, cmd++; + else + end = start; + } + tmp = history_arg_extract(start, end, aptr? aptr:ptr); + if (tmp == NULL) { + (void)fprintf(rl_outstream, "%s: Bad word specifier", + command + offs + idx); + if (aptr) + free(aptr); + return(-1); + } } else - return (-1); + tmp = strdup(aptr? aptr:ptr); - if (cmd[idx] != ':') - return (-1); - cmd += idx + 1; + if (aptr) + free(aptr); + + if (*cmd == 0 || (cmd - (command + offs) >= cmdlen)) { + *result = tmp; + return(1); + } - /* recognize cmd */ - if (*cmd == '^') - start = end = 1, cmd++; - else if (*cmd == '$') - start = end = -1, cmd++; - else if (*cmd == '*') - start = 1, end = -1, cmd++; - else if (isdigit((unsigned char) *cmd)) { - const char *temp; - int shifted = 0; - - start = atoi(cmd); - temp = cmd; - for (; isdigit((unsigned char) *cmd); cmd++); - if (temp != cmd) - shifted = 1; - if (shifted && *cmd == '-') { - if (!isdigit((unsigned char) *(cmd + 1))) - end = -2; - else { - end = atoi(cmd + 1); - for (; isdigit((unsigned char) *cmd); cmd++); - } - } else if (shifted && *cmd == '*') - end = -1, cmd++; - else if (shifted) - end = start; - } - if (*cmd == ':') - cmd++; - - line = strdup(event_data); - if (line == NULL) - return 0; for (; *cmd; cmd++) { if (*cmd == ':') continue; - else if (*cmd == 'h') - h_on = 1 | g_on, g_on = 0; - else if (*cmd == 't') - t_on = 1 | g_on, g_on = 0; - else if (*cmd == 'r') - r_on = 1 | g_on, g_on = 0; - else if (*cmd == 'e') - e_on = 1 | g_on, g_on = 0; - else if (*cmd == 'p') - p_on = 1 | g_on, g_on = 0; + else if (*cmd == 'h') { /* remove trailing path */ + if ((aptr = strrchr(tmp, '/')) != NULL) + *aptr = 0; + } else if (*cmd == 't') { /* remove leading path */ + if ((aptr = strrchr(tmp, '/')) != NULL) { + aptr = strdup(aptr + 1); + free(tmp); + tmp = aptr; + } + } else if (*cmd == 'r') { /* remove trailing suffix */ + if ((aptr = strrchr(tmp, '.')) != NULL) + *aptr = 0; + } else if (*cmd == 'e') { /* remove all but suffix */ + if ((aptr = strrchr(tmp, '.')) != NULL) { + aptr = strdup(aptr); + free(tmp); + tmp = aptr; + } + } else if (*cmd == 'p') /* print only */ + p_on = 1; else if (*cmd == 'g') g_on = 2; else if (*cmd == 's' || *cmd == '&') { char *what, *with, delim; - unsigned int len, from_len; + size_t len, from_len; size_t size; if (*cmd == '&' && (from == NULL || to == NULL)) @@ -559,13 +720,12 @@ } len = 0; for (; *cmd && *cmd != delim; cmd++) { - if (*cmd == '\\' - && *(cmd + 1) == delim) + if (*cmd == '\\' && cmd[1] == delim) cmd++; if (len >= size) { char *nwhat; nwhat = realloc(what, - (size <<= 1)); + (size <<= 1)); if (nwhat == NULL) { free(what); return 0; @@ -611,8 +771,8 @@ with = nwith; } if (*cmd == '&') { - /* safe */ - (void) strcpy(&with[len], from); + (void)strlcpy(&with[len], from, + size - len); len += from_len; continue; } @@ -624,88 +784,18 @@ } with[len] = '\0'; to = with; - - tempcmd = _rl_compat_sub(line, from, to, - (g_on) ? 1 : 0); - if (tempcmd) { - free(line); - line = tempcmd; - } - g_on = 0; } - } - } - - arr = history_tokenize(line); - free(line); /* no more needed */ - if (arr && *arr == NULL) - free(arr), arr = NULL; - if (!arr) - return (-1); - - /* find out max valid idx to array of array */ - max = 0; - for (i = 0; arr[i]; i++) - max++; - max--; - - /* set boundaries to something relevant */ - if (start < 0) - start = 1; - if (end < 0) - end = max - ((end < -1) ? 1 : 0); - - /* check boundaries ... */ - if (start > max || end > max || start > end) - return (-1); - for (i = 0; i <= max; i++) { - char *temp; - if (h_on && (i == 1 || h_on > 1) && - (temp = strrchr(arr[i], '/'))) - *(temp + 1) = '\0'; - if (t_on && (i == 1 || t_on > 1) && - (temp = strrchr(arr[i], '/'))) - (void) strcpy(arr[i], temp + 1); - if (r_on && (i == 1 || r_on > 1) && - (temp = strrchr(arr[i], '.'))) - *temp = '\0'; - if (e_on && (i == 1 || e_on > 1) && - (temp = strrchr(arr[i], '.'))) - (void) strcpy(arr[i], temp); - } - - cmdsize = 1, cmdlen = 0; - if ((tempcmd = malloc(cmdsize)) == NULL) - return 0; - for (i = start; start <= i && i <= end; i++) { - int arr_len; - - arr_len = strlen(arr[i]); - if (cmdlen + arr_len + 1 >= cmdsize) { - char *ntempcmd; - cmdsize += arr_len + 1; - ntempcmd = realloc(tempcmd, cmdsize); - if (ntempcmd == NULL) { - free(tempcmd); - return 0; + aptr = _rl_compat_sub(tmp, from, to, g_on); + if (aptr) { + free(tmp); + tmp = aptr; } - tempcmd = ntempcmd; + g_on = 0; } - (void) strcpy(&tempcmd[cmdlen], arr[i]); /* safe */ - cmdlen += arr_len; - tempcmd[cmdlen++] = ' '; /* add a space */ } - while (cmdlen > 0 && isspace((unsigned char) tempcmd[cmdlen - 1])) - cmdlen--; - tempcmd[cmdlen] = '\0'; - - *result = tempcmd; - - for (i = 0; i <= max; i++) - free(arr[i]); - free(arr), arr = (char **) NULL; - return (p_on) ? 2 : 1; + *result = tmp; + return (p_on? 2:1); } @@ -715,27 +805,37 @@ int history_expand(char *str, char **output) { - int i, retval = 0, idx; - size_t size; - char *temp, *result; + int ret = 0; + size_t idx, i, size; + char *tmp, *result; if (h == NULL || e == NULL) rl_initialize(); - *output = strdup(str); /* do it early */ - if (*output == NULL) - return 0; + if (history_expansion_char == 0) { + *output = strdup(str); + return(0); + } + *output = NULL; if (str[0] == history_subst_char) { /* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */ - temp = alloca(4 + strlen(str) + 1); - temp[0] = temp[1] = history_expansion_char; - temp[2] = ':'; - temp[3] = 's'; - (void) strcpy(temp + 4, str); - str = temp; + size_t sz = 4 + strlen(str) + 1; + *output = malloc(sz); + if (*output == NULL) + return 0; + (*output)[0] = (*output)[1] = history_expansion_char; + (*output)[2] = ':'; + (*output)[3] = 's'; + (void)strlcpy((*output) + 4, str, sz - 4); + str = *output; + } else { + *output = strdup(str); + if (*output == NULL) + return 0; } -#define ADD_STRING(what, len) \ + +#define ADD_STRING(what, len) \ { \ if (idx + len + 1 > size) { \ char *nresult = realloc(result, (size += len + 1));\ @@ -753,35 +853,36 @@ result = NULL; size = idx = 0; for (i = 0; str[i];) { - int start, j, loop_again; - size_t len; + int qchar, loop_again; + size_t len, start, j; + qchar = 0; loop_again = 1; start = j = i; loop: for (; str[j]; j++) { if (str[j] == '\\' && str[j + 1] == history_expansion_char) { - (void) strcpy(&str[j], &str[j + 1]); + size_t sz = strlen(&str[j]) + 1; + (void)strlcpy(&str[j], &str[j + 1], sz); continue; } if (!loop_again) { - if (str[j] == '?') { - while (str[j] && str[++j] != '?'); - if (str[j] == '?') - j++; - } else if (isspace((unsigned char) str[j])) + if (isspace((unsigned char) str[j]) + || str[j] == qchar) break; } if (str[j] == history_expansion_char && !strchr(history_no_expand_chars, str[j + 1]) && (!history_inhibit_expansion_function || - (*history_inhibit_expansion_function)(str, j) == 0)) + (*history_inhibit_expansion_function)(str, + (int)j) == 0)) break; } - if (str[j] && str[j + 1] != '#' && loop_again) { + if (str[j] && loop_again) { i = j; + qchar = (j > 0 && str[j - 1] == '"' )? '"':0; j++; if (str[j] == history_expansion_char) j++; @@ -789,61 +890,117 @@ goto loop; } len = i - start; - temp = &str[start]; - ADD_STRING(temp, len); + tmp = &str[start]; + ADD_STRING(tmp, len); - if (str[i] == '\0' || str[i] != history_expansion_char - || str[i + 1] == '#') { + if (str[i] == '\0' || str[i] != history_expansion_char) { len = j - i; - temp = &str[i]; - ADD_STRING(temp, len); + tmp = &str[i]; + ADD_STRING(tmp, len); if (start == 0) - retval = 0; + ret = 0; else - retval = 1; + ret = 1; break; } - retval = _history_expand_command(&str[i], (size_t) (j - i), - &temp); - if (retval != -1) { - len = strlen(temp); - ADD_STRING(temp, len); + ret = _history_expand_command (str, i, (j - i), &tmp); + if (ret > 0 && tmp) { + len = strlen(tmp); + ADD_STRING(tmp, len); + free(tmp); } i = j; - } /* for(i ...) */ + } - if (retval == 2) { - add_history(temp); + /* ret is 2 for "print only" option */ + if (ret == 2) { + add_history(result); #ifdef GDB_411_HACK /* gdb 4.11 has been shipped with readline, where */ /* history_expand() returned -1 when the line */ /* should not be executed; in readline 2.1+ */ /* it should return 2 in such a case */ - retval = -1; + ret = -1; #endif } free(*output); *output = result; - return (retval); + return (ret); } +/* +* Return a string consisting of arguments of "str" from "start" to "end". +*/ +char * +history_arg_extract(int start, int end, const char *str) +{ + size_t i, len, max; + char **arr, *result; + + arr = history_tokenize(str); + if (!arr) + return(NULL); + if (arr && *arr == NULL) { + free(arr); + return(NULL); + } + + for (max = 0; arr[max]; max++) + continue; + max--; + + if (start == '$') + start = max; + if (end == '$') + end = max; + if (end < 0) + end = max + end + 1; + if (start < 0) + start = end; + + if (start < 0 || end < 0 || start > max || end > max || start > end) + return(NULL); + + for (i = start, len = 0; i <= end; i++) + len += strlen(arr[i]) + 1; + len++; + max = len; + result = malloc(len); + if (result == NULL) + return NULL; + + for (i = start, len = 0; i <= end; i++) { + (void)strlcpy(result + len, arr[i], max - len); + len += strlen(arr[i]); + if (i < end) + result[len++] = ' '; + } + result[len] = 0; + + for (i = 0; arr[i]; i++) + free(arr[i]); + free(arr); + + return(result); +} /* - * Parse the string into individual tokens, similarily to how shell would do it. + * Parse the string into individual tokens, + * similar to how shell would do it. */ char ** history_tokenize(const char *str) { - int size = 1, result_idx = 0, i, start; + int size = 1, idx = 0, i, start; size_t len; char **result = NULL, *temp, delim = '\0'; - for (i = 0; str[i]; i++) { + for (i = 0; str[i];) { while (isspace((unsigned char) str[i])) i++; start = i; - for (; str[i]; i++) { + for (; str[i];) { if (str[i] == '\\') { if (str[i+1] != '\0') i++; @@ -855,9 +1012,11 @@ break; else if (!delim && strchr("'`\"", str[i])) delim = str[i]; + if (str[i]) + i++; } - if (result_idx + 2 >= size) { + if (idx + 2 >= size) { char **nresult; size <<= 1; nresult = realloc(result, size * sizeof(char *)); @@ -870,15 +1029,18 @@ len = i - start; temp = malloc(len + 1); if (temp == NULL) { + for (i = 0; i < idx; i++) + free(result[i]); free(result); return NULL; } - (void) strncpy(temp, &str[start], len); + (void)strncpy(temp, &str[start], len); temp[len] = '\0'; - result[result_idx++] = temp; - result[result_idx] = NULL; + result[idx++] = temp; + result[idx] = NULL; + if (str[i]) + i++; } - return (result); } @@ -962,28 +1124,29 @@ { static HIST_ENTRY she; HistEvent ev; - int i = 1, curr_num; + int curr_num; if (h == NULL || e == NULL) rl_initialize(); - /* rewind to beginning */ + /* save current position */ if (history(h, &ev, H_CURR) != 0) return (NULL); curr_num = ev.num; - if (history(h, &ev, H_LAST) != 0) + + /* start from most recent */ + if (history(h, &ev, H_FIRST) != 0) return (NULL); /* error */ - while (i < num && history(h, &ev, H_PREV) == 0) - i++; - if (i != num) - return (NULL); /* not so many entries */ + + /* look backwards for event matching specified offset */ + if (history(h, &ev, H_NEXT_EVENT, num)) + return (NULL); she.line = ev.str; she.data = NULL; - /* rewind history to the same event it was before */ - (void) history(h, &ev, H_FIRST); - (void) history(h, &ev, H_NEXT_EVENT, curr_num); + /* restore pointer to where it was */ + (void)history(h, &ev, H_SET, curr_num); return (&she); } @@ -1000,11 +1163,11 @@ if (h == NULL || e == NULL) rl_initialize(); - (void) history(h, &ev, H_ENTER, line); + (void)history(h, &ev, H_ENTER, line); if (history(h, &ev, H_GETSIZE) == 0) history_length = ev.num; - return (!(history_length > 0)); /* return 0 if all is okay */ + return (!(history_length > 0)); /* return 0 if all is okay */ } @@ -1086,22 +1249,17 @@ history_set_pos(int pos) { HistEvent ev; - int off, curr_num; + int curr_num; if (pos > history_length || pos < 0) return (-1); history(h, &ev, H_CURR); curr_num = ev.num; - history(h, &ev, H_FIRST); - off = 0; - while (off < pos && history(h, &ev, H_NEXT) == 0) - off++; - if (off != pos) { /* do a rollback in case of error */ - history(h, &ev, H_FIRST); - history(h, &ev, H_NEXT_EVENT, curr_num); - return (-1); + if (history(h, &ev, H_SET, pos)) { + history(h, &ev, H_SET, curr_num); + return(-1); } return (0); } @@ -1130,10 +1288,10 @@ /* - * generic history search function + * searches for first history event containing the str */ -static int -_history_search_gen(const char *str, int direction, int pos) +int +history_search(const char *str, int direction) { HistEvent ev; const char *strp; @@ -1144,38 +1302,25 @@ curr_num = ev.num; for (;;) { - strp = strstr(ev.str, str); - if (strp && (pos < 0 || &ev.str[pos] == strp)) + if ((strp = strstr(ev.str, str)) != NULL) return (int) (strp - ev.str); - if (history(h, &ev, direction < 0 ? H_PREV : H_NEXT) != 0) + if (history(h, &ev, direction < 0 ? H_NEXT:H_PREV) != 0) break; } - - history(h, &ev, direction < 0 ? H_NEXT_EVENT : H_PREV_EVENT, curr_num); - + history(h, &ev, H_SET, curr_num); return (-1); } /* - * searches for first history event containing the str - */ -int -history_search(const char *str, int direction) -{ - - return (_history_search_gen(str, direction, -1)); -} - - -/* * searches for first history event beginning with str */ int history_search_prefix(const char *str, int direction) { + HistEvent ev; - return (_history_search_gen(str, direction, 0)); + return (history(h, &ev, direction < 0? H_PREV_STR:H_NEXT_STR, str)); } @@ -1185,8 +1330,8 @@ */ /* ARGSUSED */ int -history_search_pos(const char *str, - int direction __attribute__((unused)), int pos) +history_search_pos(const char *str, + int direction __attribute__((__unused__)), int pos) { HistEvent ev; int curr_num, off; @@ -1217,7 +1362,7 @@ /********************************/ -/* completition functions */ +/* completion functions */ /* * does tilde expansion of strings of type ``~user/foo'' @@ -1246,7 +1391,7 @@ temp = malloc(len); if (temp == NULL) return NULL; - (void) strncpy(temp, txt + 1, len - 2); + (void)strncpy(temp, txt + 1, len - 2); temp[len - 2] = '\0'; } pass = getpwnam(temp); @@ -1258,10 +1403,11 @@ /* first slash */ txt += len; - temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1); + len = strlen(pass->pw_dir) + 1 + strlen(txt) + 1; + temp = malloc(len); if (temp == NULL) return NULL; - (void) sprintf(temp, "%s/%s", pass->pw_dir, txt); + (void)snprintf(temp, len, "%s/%s", pass->pw_dir, txt); return (temp); } @@ -1288,14 +1434,16 @@ temp = strrchr(text, '/'); if (temp) { char *nptr; + size_t sz; temp++; - nptr = realloc(filename, strlen(temp) + 1); + sz = strlen(temp) + 1; + nptr = realloc(filename, sz); if (nptr == NULL) { free(filename); return NULL; } filename = nptr; - (void) strcpy(filename, temp); + (void)strlcpy(filename, temp, sz); len = temp - text; /* including last slash */ nptr = realloc(dirname, len + 1); if (nptr == NULL) { @@ -1303,34 +1451,38 @@ return NULL; } dirname = nptr; - (void) strncpy(dirname, text, len); + (void)strncpy(dirname, text, len); dirname[len] = '\0'; } else { - filename = strdup(text); - if (filename == NULL) - return NULL; + if (*text == 0) + filename = NULL; + else { + filename = strdup(text); + if (filename == NULL) + return NULL; + } dirname = NULL; } /* support for ``~user'' syntax */ if (dirname && *dirname == '~') { char *nptr; + size_t sz; temp = tilde_expand(dirname); if (temp == NULL) return NULL; - nptr = realloc(dirname, strlen(temp) + 1); + sz = strlen(temp) + 1; + nptr = realloc(dirname, sz); if (nptr == NULL) { free(dirname); return NULL; } dirname = nptr; - (void) strcpy(dirname, temp); /* safe */ + (void)strlcpy(dirname, temp, sz); free(temp); /* no longer needed */ } /* will be used in cycle */ - filename_len = strlen(filename); - if (filename_len == 0) - return (NULL); /* no expansion possible */ + filename_len = filename ? strlen(filename) : 0; if (dir != NULL) { (void)closedir(dir); @@ -1342,10 +1494,16 @@ } /* find the match */ while ((entry = readdir(dir)) != NULL) { + /* skip . and .. */ + if (entry->d_name[0] == '.' && (!entry->d_name[1] + || (entry->d_name[1] == '.' && !entry->d_name[2]))) + continue; + if (filename_len == 0) + break; /* otherwise, get first entry where first */ /* filename_len characters are equal */ if (entry->d_name[0] == filename[0] -#ifndef STRUCT_DIRENT_HAS_D_NAMLEN +#if defined(__SVR4) || defined(__linux__) && strlen(entry->d_name) >= filename_len #else && entry->d_namlen >= filename_len @@ -1358,7 +1516,7 @@ if (entry) { /* match found */ struct stat stbuf; -#ifndef STRUCT_DIRENT_HAS_D_NAMLEN +#if defined(__SVR4) || defined(__linux__) len = strlen(entry->d_name) + #else len = entry->d_namlen + @@ -1367,12 +1525,12 @@ temp = malloc(len); if (temp == NULL) return NULL; - (void) sprintf(temp, "%s%s", - dirname ? dirname : "", entry->d_name); /* safe */ + (void)snprintf(temp, len, "%s%s", + dirname ? dirname : "", entry->d_name); /* test, if it's directory */ if (stat(temp, &stbuf) == 0 && S_ISDIR(stbuf.st_mode)) - strcat(temp, "/"); /* safe */ + strlcat(temp, "/", len); } else { (void)closedir(dir); dir = NULL; @@ -1420,32 +1578,33 @@ */ /* ARGSUSED */ static unsigned char -_el_rl_complete(EditLine *el __attribute__((unused)), int ch) +_el_rl_complete(EditLine *el __attribute__((__unused__)), int ch) { return (unsigned char) rl_complete(0, ch); } /* - * returns list of completitions for text given + * returns list of completions for text given */ char ** completion_matches(const char *text, CPFunction *genfunc) { char **match_list = NULL, *retstr, *prevstr; size_t match_list_len, max_equal, which, i; - unsigned int matches; + size_t matches; if (h == NULL || e == NULL) rl_initialize(); matches = 0; match_list_len = 1; - while ((retstr = (*genfunc) (text, matches)) != NULL) { + while ((retstr = (*genfunc) (text, (int)matches)) != NULL) { /* allow for list terminator here */ - if (matches + 2 >= match_list_len) { + if (matches + 3 >= match_list_len) { char **nmatch_list; - match_list_len <<= 1; + while (matches + 3 >= match_list_len) + match_list_len <<= 1; nmatch_list = realloc(match_list, match_list_len * sizeof(char *)); if (nmatch_list == NULL) { @@ -1477,7 +1636,7 @@ free(match_list); return NULL; } - (void) strncpy(retstr, match_list[1], max_equal); + (void)strncpy(retstr, match_list[1], max_equal); retstr[max_equal] = '\0'; match_list[0] = retstr; @@ -1532,9 +1691,10 @@ idx = 1; for(; count > 0; count--) { - for(i=0; i < limit && matches[idx]; i++, idx++) - fprintf(e->el_outfile, "%-*s ", max, matches[idx]); - fprintf(e->el_outfile, "\n"); + for(i = 0; i < limit && matches[idx]; i++, idx++) + (void)fprintf(e->el_outfile, "%-*s ", max, + matches[idx]); + (void)fprintf(e->el_outfile, "\n"); } } @@ -1552,7 +1712,7 @@ static int rl_complete_internal(int what_to_do) { - CPFunction *complet_func; + Function *complet_func; const LineInfo *li; char *temp, **matches; const char *ctemp; @@ -1565,7 +1725,7 @@ complet_func = rl_completion_entry_function; if (!complet_func) - complet_func = filename_completion_function; + complet_func = (Function *)(void *)filename_completion_function; /* We now look backwards for the start of a filename/variable word */ li = el_line(e); @@ -1573,12 +1733,12 @@ while (ctemp > li->buffer && !strchr(rl_basic_word_break_characters, ctemp[-1]) && (!rl_special_prefixes - || !strchr(rl_special_prefixes, ctemp[-1]) ) ) + || !strchr(rl_special_prefixes, ctemp[-1]) ) ) ctemp--; len = li->cursor - ctemp; temp = alloca(len + 1); - (void) strncpy(temp, ctemp, len); + (void)strncpy(temp, ctemp, len); temp[len] = '\0'; /* these can be used by function called in completion_matches() */ @@ -1586,13 +1746,14 @@ rl_point = li->cursor - li->buffer; rl_end = li->lastchar - li->buffer; - if (!rl_attempted_completion_function) - matches = completion_matches(temp, complet_func); - else { + if (rl_attempted_completion_function) { int end = li->cursor - li->buffer; matches = (*rl_attempted_completion_function) (temp, (int) (end - len), end); - } + } else + matches = 0; + if (!rl_attempted_completion_function || !matches) + matches = completion_matches(temp, (CPFunction *)complet_func); if (matches) { int i, retval = CC_REFRESH; @@ -1613,11 +1774,12 @@ if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) { /* * We found exact match. Add a space after - * it, unless we do filename completition and the + * it, unless we do filename completion and the * object is a directory. */ size_t alen = strlen(matches[0]); - if ((complet_func != filename_completion_function + if ((complet_func != + (Function *)filename_completion_function || (alen > 0 && (matches[0])[alen - 1] != '/')) && rl_completion_append_character) { char buf[2]; @@ -1640,20 +1802,20 @@ matches_num = i - 1; /* newline to get on next line from command line */ - fprintf(e->el_outfile, "\n"); + (void)fprintf(e->el_outfile, "\n"); /* * If there are too many items, ask user for display * confirmation. */ if (matches_num > rl_completion_query_items) { - fprintf(e->el_outfile, - "Display all %d possibilities? (y or n) ", - matches_num); - fflush(e->el_outfile); + (void)fprintf(e->el_outfile, + "Display all %d possibilities? (y or n) ", + matches_num); + (void)fflush(e->el_outfile); if (getc(stdin) != 'y') match_display = 0; - fprintf(e->el_outfile, "\n"); + (void)fprintf(e->el_outfile, "\n"); } if (match_display) @@ -1751,7 +1913,7 @@ */ /* ARGSUSED */ void -rl_reset_terminal(const char *p __attribute__((unused))) +rl_reset_terminal(const char *p __attribute__((__unused__))) { if (h == NULL || e == NULL) @@ -1779,4 +1941,191 @@ el_push(e, arr); return (0); +} + +/*ARGSUSED*/ +int +rl_newline(int count, int c) +{ + /* + * Readline-4.0 appears to ignore the args. + */ + return rl_insert(1, '\n'); +} + +/*ARGSUSED*/ +static unsigned char +rl_bind_wrapper(EditLine *el, unsigned char c) +{ + if (map[c] == NULL) + return CC_ERROR; + (*map[c])(NULL, c); + + /* If rl_done was set by the above call, deal with it here */ + if (rl_done) + return CC_EOF; + + return CC_NORM; +} + +int +rl_add_defun(const char *name, Function *fun, int c) +{ + char dest[8]; + if (c >= sizeof(map) / sizeof(map[0]) || c < 0) + return -1; + map[(unsigned char)c] = fun; + el_set(e, EL_ADDFN, name, name, rl_bind_wrapper); + vis(dest, c, VIS_WHITE|VIS_NOSLASH, 0); + el_set(e, EL_BIND, dest, name); + return 0; +} + +void +rl_callback_read_char() +{ + int count = 0, done = 0; + const char *buf = el_gets(e, &count); + char *wbuf; + + if (buf == NULL || count-- <= 0) + return; + if (count == 0 && buf[0] == CTRL('d')) + done = 1; + if (buf[count] == '\n' || buf[count] == '\r') + done = 2; + + if (done && rl_linefunc != NULL) { + el_set(e, EL_UNBUFFERED, 0); + if (done == 2) { + if ((wbuf = strdup(buf)) != NULL) + wbuf[count] = '\0'; + } else + wbuf = NULL; + (*(void (*)(const char *))rl_linefunc)(wbuf); + } +} + +void +rl_callback_handler_install (const char *prompt, VFunction *linefunc) +{ + if (e == NULL) { + rl_initialize(); + } + if (rl_prompt) + free(rl_prompt); + rl_prompt = prompt ? strdup(strchr(prompt, *prompt)) : NULL; + rl_linefunc = linefunc; + el_set(e, EL_UNBUFFERED, 1); +} + +void +rl_callback_handler_remove(void) +{ + el_set(e, EL_UNBUFFERED, 0); +} + +void +rl_redisplay(void) +{ + char a[2]; + a[0] = CTRL('r'); + a[1] = '\0'; + el_push(e, a); +} + +int +rl_get_previous_history(int count, int key) +{ + char a[2]; + a[0] = key; + a[1] = '\0'; + while (count--) + el_push(e, a); + return 0; +} + +void +/*ARGSUSED*/ +rl_prep_terminal(int meta_flag) +{ + el_set(e, EL_PREP_TERM, 1); +} + +void +rl_deprep_terminal() +{ + el_set(e, EL_PREP_TERM, 0); +} + +int +rl_read_init_file(const char *s) +{ + return(el_source(e, s)); +} + +int +rl_parse_and_bind(const char *line) +{ + const char **argv; + int argc; + Tokenizer *tok; + + tok = tok_init(NULL); + tok_line(tok, line, &argc, &argv); + argc = el_parse(e, argc, argv); + tok_end(tok); + return (argc ? 1 : 0); +} + +void +rl_stuff_char(int c) +{ + char buf[2]; + + buf[0] = c; + buf[1] = '\0'; + el_insertstr(e, buf); +} + +static int +_rl_event_read_char(EditLine *el, char *cp) +{ + int n, num_read = 0; + + *cp = 0; + while (rl_event_hook) { + + (*rl_event_hook)(); + +#if defined(FIONREAD) + if (ioctl(el->el_infd, FIONREAD, &n) < 0) + return(-1); + if (n) + num_read = read(el->el_infd, cp, 1); + else + num_read = 0; +#elif defined(F_SETFL) && defined(O_NDELAY) + if ((n = fcntl(el->el_infd, F_GETFL, 0)) < 0) + return(-1); + if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0) + return(-1); + num_read = read(el->el_infd, cp, 1); + if (fcntl(el->el_infd, F_SETFL, n)) + return(-1); +#else + /* not non-blocking, but what you gonna do? */ + num_read = read(el->el_infd, cp, 1); + return(-1); +#endif + + if (num_read < 0 && errno == EAGAIN) + continue; + if (num_read == 0) + continue; + break; + } + if (!rl_event_hook) + el_set(el, EL_GETCFN, EL_BUILTIN_GETCFN); + return(num_read); } --- 1.3/cmd-line-utils/libedit/readline/readline.h 2004-08-24 08:41:37 -07:00 +++ 1.4/cmd-line-utils/libedit/readline/readline.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: readline.h,v 1.1 2001/01/05 21:15:50 jdolecek Exp $ */ +/* $OpenBSD: readline.h,v 1.2 2003/11/25 20:12:39 otto Exp $ */ +/* $NetBSD: readline.h,v 1.10 2003/10/27 22:26:35 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -36,7 +37,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _READLINE_H_ -#define _READLINE_H_ +#define _READLINE_H_ #include @@ -53,6 +54,36 @@ const char *data; } HIST_ENTRY; +typedef struct _keymap_entry { + char type; +#define ISFUNC 0 +#define ISKMAP 1 +#define ISMACR 2 + Function *function; +} KEYMAP_ENTRY; + +#define KEYMAP_SIZE 256 + +typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE]; +typedef KEYMAP_ENTRY *Keymap; + +#define control_character_threshold 0x20 +#define control_character_bit 0x40 + +#ifndef CTRL +#include +#include +#ifndef CTRL +#define CTRL(c) ((c) & 037) +#endif +#endif +#ifndef UNCTRL +#define UNCTRL(c) (((c) - 'a' + 'A')|control_character_bit) +#endif + +#define RUBOUT 0x7f +#define ABORT_CHAR CTRL('G') + /* global variables used by readline enabled applications */ #ifdef __cplusplus extern "C" { @@ -68,12 +99,32 @@ extern char *rl_basic_word_break_characters; extern char *rl_completer_word_break_characters; extern char *rl_completer_quote_characters; -extern CPFunction *rl_completion_entry_function; +extern Function *rl_completion_entry_function; extern CPPFunction *rl_attempted_completion_function; extern int rl_completion_type; extern int rl_completion_query_items; extern char *rl_special_prefixes; extern int rl_completion_append_character; +extern Function *rl_pre_input_hook; +extern Function *rl_startup_hook; +extern char *rl_terminal_name; +extern int rl_already_prompted; +extern char *rl_prompt; +extern VFunction *rl_event_hook; + +/* + * The following is not implemented + */ +extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, + emacs_meta_keymap, + emacs_ctlx_keymap; +extern int rl_filename_completion_desired; +extern int rl_ignore_completion_duplicates; +extern Function *rl_getc_function; +extern VFunction *rl_redisplay_function; +extern VFunction *rl_completion_display_matches_hook; +extern VFunction *rl_prep_term_function; +extern VFunction *rl_deprep_term_function; /* supported functions */ char *readline(const char *); @@ -99,6 +150,8 @@ int write_history(const char *); int history_expand(char *, char **); char **history_tokenize(const char *); +const char *get_history_event(const char *, int *, int); +char *history_arg_extract(int, int, const char *); char *tilde_expand(char *); char *filename_completion_function(const char *, int); @@ -111,6 +164,26 @@ int rl_insert(int, int); void rl_reset_terminal(const char *); int rl_bind_key(int, int (*)(int, int)); +int rl_newline(int, int); +void rl_callback_read_char(void); +void rl_callback_handler_install(const char *, VFunction *); +void rl_callback_handler_remove(void); +void rl_redisplay(void); +int rl_get_previous_history(int, int); +void rl_prep_terminal(int); +void rl_deprep_terminal(void); +int rl_read_init_file(const char *); +int rl_parse_and_bind(const char *); +void rl_stuff_char(int); +int rl_add_defun(const char *, Function *, int); + +/* + * The following are not implemented + */ +Keymap rl_get_keymap(void); +Keymap rl_make_bare_keymap(void); +int rl_generic_bind(int, const char *, const char *, Keymap); +int rl_bind_key_in_map(int, Function *, Keymap); #ifdef __cplusplus } #endif --- 1.5/cmd-line-utils/libedit/refresh.c 2004-08-24 08:41:37 -07:00 +++ 1.6/cmd-line-utils/libedit/refresh.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: refresh.c,v 1.24 2003/03/10 21:18:49 christos Exp $ */ +/* $OpenBSD: refresh.c,v 1.9 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: refresh.c,v 1.26 2003/08/07 16:44:33 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: refresh.c,v 1.24 2003/03/10 21:18:49 christos Exp $"); +static const char rcsid[] = "$OpenBSD: refresh.c,v 1.9 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -57,8 +54,8 @@ private void re_addc(EditLine *, int); private void re_update_line(EditLine *, char *, char *, int); -private void re_insert (EditLine *el, char *, int, int, char *, int); -private void re_delete(EditLine *el, char *, int, int, int); +private void re_insert (EditLine *, char *, int, int, char *, int); +private void re_delete(EditLine *, char *, int, int, int); private void re_fastputc(EditLine *, int); private void re__strncopy(char *, char *, size_t); private void re__copy_and_pad(char *, const char *, size_t); @@ -338,8 +335,8 @@ */ private void /*ARGSUSED*/ -re_insert(EditLine *el __attribute__((unused)), - char *d, int dat, int dlen, char *s, int num) +re_insert(EditLine *el __attribute__((__unused__)), + char *d, int dat, int dlen, char *s, int num) { char *a, *b; @@ -382,8 +379,8 @@ */ private void /*ARGSUSED*/ -re_delete(EditLine *el __attribute__((unused)), - char *d, int dat, int dlen, int num) +re_delete(EditLine *el __attribute__((__unused__)), + char *d, int dat, int dlen, int num) { char *a, *b; --- 1.1/cmd-line-utils/libedit/refresh.h 2003-01-18 08:28:17 -08:00 +++ 1.2/cmd-line-utils/libedit/refresh.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: refresh.h,v 1.4 2001/01/10 07:45:42 jdolecek Exp $ */ +/* $OpenBSD: refresh.h,v 1.6 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: refresh.h,v 1.5 2003/08/07 16:44:33 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * --- 1.4/cmd-line-utils/libedit/search.c 2004-08-24 12:00:08 -07:00 +++ 1.5/cmd-line-utils/libedit/search.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: search.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */ +/* $OpenBSD: search.c,v 1.10 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: search.c,v 1.19 2003/10/25 06:42:41 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: search.c,v 1.14 2002/11/20 16:50:08 christos Exp $"); +static const char rcsid[] = "$OpenBSD: search.c,v 1.10 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -50,7 +47,6 @@ */ #include #if defined(REGEX) -#include #include #elif defined(REGEXP) #include @@ -227,8 +223,11 @@ if (el->el_search.patlen == 0) { /* first round */ pchar = ':'; #ifdef ANCHOR +#define LEN 2 el->el_search.patbuf[el->el_search.patlen++] = '.'; el->el_search.patbuf[el->el_search.patlen++] = '*'; +#else +#define LEN 0 #endif } done = redo = 0; @@ -237,7 +236,7 @@ *cp; *el->el_line.lastchar++ = *cp++) continue; *el->el_line.lastchar++ = pchar; - for (cp = &el->el_search.patbuf[1]; + for (cp = &el->el_search.patbuf[LEN]; cp < &el->el_search.patbuf[el->el_search.patlen]; *el->el_line.lastchar++ = *cp++) continue; @@ -250,7 +249,7 @@ switch (el->el_map.current[(unsigned char) ch]) { case ED_INSERT: case ED_DIGIT: - if (el->el_search.patlen > EL_BUFSIZ - 3) + if (el->el_search.patlen >= EL_BUFSIZ - LEN) term_beep(el); else { el->el_search.patbuf[el->el_search.patlen++] = @@ -272,7 +271,7 @@ break; case ED_DELETE_PREV_CHAR: - if (el->el_search.patlen > 1) + if (el->el_search.patlen > LEN) done++; else term_beep(el); @@ -287,17 +286,18 @@ case 0027: /* ^W: Append word */ /* No can do if globbing characters in pattern */ - for (cp = &el->el_search.patbuf[1];; cp++) - if (cp >= &el->el_search.patbuf[el->el_search.patlen]) { + for (cp = &el->el_search.patbuf[LEN];; cp++) + if (cp >= &el->el_search.patbuf[ + el->el_search.patlen]) { el->el_line.cursor += - el->el_search.patlen - 1; + el->el_search.patlen - LEN - 1; cp = c__next_word(el->el_line.cursor, el->el_line.lastchar, 1, ce__isword); while (el->el_line.cursor < cp && *el->el_line.cursor != '\n') { - if (el->el_search.patlen > - EL_BUFSIZ - 3) { + if (el->el_search.patlen >= + EL_BUFSIZ - LEN) { term_beep(el); break; } @@ -339,13 +339,13 @@ /* Can't search if unmatched '[' */ for (cp = &el->el_search.patbuf[el->el_search.patlen-1], ch = ']'; - cp > el->el_search.patbuf; + cp >= &el->el_search.patbuf[LEN]; cp--) if (*cp == '[' || *cp == ']') { ch = *cp; break; } - if (el->el_search.patlen > 1 && ch != '[') { + if (el->el_search.patlen > LEN && ch != '[') { if (redo && newdir == dir) { if (pchar == '?') { /* wrap around */ el->el_history.eventno = @@ -375,9 +375,8 @@ '\0'; if (el->el_line.cursor < el->el_line.buffer || el->el_line.cursor > el->el_line.lastchar || - (ret = ce_search_line(el, - &el->el_search.patbuf[1], - newdir)) == CC_ERROR) { + (ret = ce_search_line(el, newdir)) + == CC_ERROR) { /* avoid c_setpat */ el->el_state.lastcmd = (el_action_t) newdir; @@ -390,11 +389,11 @@ el->el_line.lastchar : el->el_line.buffer; (void) ce_search_line(el, - &el->el_search.patbuf[1], newdir); } } - el->el_search.patbuf[--el->el_search.patlen] = + el->el_search.patlen -= LEN; + el->el_search.patbuf[el->el_search.patlen] = '\0'; if (ret == CC_ERROR) { term_beep(el); @@ -453,9 +452,6 @@ #ifdef ANCHOR tmpbuf[0] = '.'; tmpbuf[1] = '*'; -#define LEN 2 -#else -#define LEN 0 #endif tmplen = LEN; @@ -521,24 +517,39 @@ * Look for a pattern inside a line */ protected el_action_t -ce_search_line(EditLine *el, char *pattern, int dir) +ce_search_line(EditLine *el, int dir) { - char *cp; + char *cp = el->el_line.cursor; + char *pattern = el->el_search.patbuf; + char oc, *ocp; +#ifdef ANCHOR + ocp = &pattern[1]; + oc = *ocp; + *ocp = '^'; +#else + ocp = pattern; + oc = *ocp; +#endif if (dir == ED_SEARCH_PREV_HISTORY) { - for (cp = el->el_line.cursor; cp >= el->el_line.buffer; cp--) - if (el_match(cp, pattern)) { + for (; cp >= el->el_line.buffer; cp--) { + if (el_match(cp, ocp)) { + *ocp = oc; el->el_line.cursor = cp; return (CC_NORM); } + } + *ocp = oc; return (CC_ERROR); } else { - for (cp = el->el_line.cursor; *cp != '\0' && - cp < el->el_line.limit; cp++) - if (el_match(cp, pattern)) { + for (; *cp != '\0' && cp < el->el_line.limit; cp++) { + if (el_match(cp, ocp)) { + *ocp = oc; el->el_line.cursor = cp; return (CC_NORM); } + } + *ocp = oc; return (CC_ERROR); } } --- 1.2/cmd-line-utils/libedit/search.h 2004-08-24 08:41:37 -07:00 +++ 1.3/cmd-line-utils/libedit/search.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: search.h,v 1.6 2002/11/15 14:32:34 christos Exp $ */ +/* $OpenBSD: search.h,v 1.7 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: search.h,v 1.8 2003/10/18 23:27:36 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -63,7 +60,7 @@ protected void c_setpat(EditLine *); protected el_action_t ce_inc_search(EditLine *, int); protected el_action_t cv_search(EditLine *, int); -protected el_action_t ce_search_line(EditLine *, char *, int); +protected el_action_t ce_search_line(EditLine *, int); protected el_action_t cv_repeat_srch(EditLine *, int); protected el_action_t cv_csearch(EditLine *, int, int, int, int); --- 1.4/cmd-line-utils/libedit/sig.c 2004-08-24 08:41:37 -07:00 +++ 1.5/cmd-line-utils/libedit/sig.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: sig.c,v 1.10 2003/03/10 00:58:05 christos Exp $ */ +/* $OpenBSD: sig.c,v 1.10 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: sig.c,v 1.11 2003/08/07 16:44:33 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: sig.c,v 1.10 2003/03/10 00:58:05 christos Exp $"); +static const char rcsid[] = "$OpenBSD: sig.c,v 1.10 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ --- 1.3/cmd-line-utils/libedit/sig.h 2004-08-24 08:41:37 -07:00 +++ 1.4/cmd-line-utils/libedit/sig.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: sig.h,v 1.4 2003/03/10 00:58:05 christos Exp $ */ +/* $OpenBSD: sig.h,v 1.6 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: sig.h,v 1.5 2003/08/07 16:44:33 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * --- 1.2/cmd-line-utils/libedit/sys.h 2004-08-24 08:41:37 -07:00 +++ 1.3/cmd-line-utils/libedit/sys.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: sys.h,v 1.6 2003/03/10 00:57:38 christos Exp $ */ +/* $OpenBSD: sys.h,v 1.8 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: sys.h,v 1.8 2003/08/07 16:44:33 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -46,6 +43,10 @@ #ifdef HAVE_SYS_CDEFS_H #include +#endif + +#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8) +# define __attribute__(A) #endif #ifndef public --- 1.6/cmd-line-utils/libedit/term.c 2004-09-15 09:50:29 -07:00 +++ 1.7/cmd-line-utils/libedit/term.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: term.c,v 1.35 2002/03/18 16:00:59 christos Exp $ */ +/* $OpenBSD: term.c,v 1.11 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: term.c,v 1.38 2003/09/14 21:48:55 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; #else -__RCSID("$NetBSD: term.c,v 1.35 2002/03/18 16:00:59 christos Exp $"); +static const char rcsid[] = "$OpenBSD: term.c,v 1.11 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -64,15 +61,15 @@ #ifdef HAVE_NCURSES_H #include #endif - -#include "el.h" - -#if !defined(HAVE_TERMCAP_H) && defined(HAVE_TERM_H) +/* Solaris's term.h does horrid things. */ +#if (defined(HAVE_TERM_H) && !defined(SUNOS)) #include #endif #include #include +#include "el.h" + /* * IMPORTANT NOTE: these routines are allowed to look at the current screen * and the current possition assuming that it is correct. If this is not @@ -356,6 +353,7 @@ term_init_arrow(el); return (0); } + /* term_end(): * Clean up the terminal stuff */ @@ -399,16 +397,16 @@ * New string is shorter; no need to allocate space */ if (clen <= tlen) { - (void) strcpy(*str, cap); /* XXX strcpy is safe */ + (void) strlcpy(*str, cap, tlen + 1); return; } /* * New string is longer; see if we have enough space to append */ if (el->el_term.t_loc + 3 < TC_BUFSIZE) { - /* XXX strcpy is safe */ - (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], - cap); + tlen = TC_BUFSIZE - el->el_term.t_loc; + (void) strlcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], + cap, tlen); el->el_term.t_loc += clen + 1; /* one for \0 */ return; } @@ -432,8 +430,8 @@ "Out of termcap string space.\n"); return; } - /* XXX strcpy is safe */ - (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap); + tlen = TC_BUFSIZE - el->el_term.t_loc; + (void) strlcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap, tlen); el->el_term.t_loc += clen + 1; /* one for \0 */ return; } @@ -648,7 +646,8 @@ * from col 0 */ if (EL_CAN_TAB ? - (((unsigned int)-del) > (((unsigned int) where >> 3) + + ((unsigned int)-del > + (((unsigned int) where >> 3) + (where & 07))) : (-del > where)) { term__putc('\r'); /* do a CR */ @@ -876,6 +875,12 @@ } #endif +protected void +term_get(EditLine *el, const char **term) +{ + *term = el->el_term.t_name; +} + /* term_set(): * Read in the terminal capabilities from the requested terminal @@ -938,7 +943,7 @@ Val(T_co) = tgetnum("co"); Val(T_li) = tgetnum("li"); for (t = tstr; t->name != NULL; t++) - term_alloc(el, t, tgetstr(t->name, &area)); + term_alloc(el, t, tgetstr((char *)t->name, &area)); } if (Val(T_co) < 2) @@ -957,6 +962,7 @@ return (-1); (void) sigprocmask(SIG_SETMASK, &oset, NULL); term_bind_arrow(el); + el->el_term.t_name = term; return (i <= 0 ? -1 : 0); } @@ -1078,32 +1084,32 @@ static const char stOH[] = {033, 'O', 'H', '\0'}; static const char stOF[] = {033, 'O', 'F', '\0'}; - el_key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); - el_key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); - el_key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); - el_key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); - el_key_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); - el_key_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); - el_key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); - el_key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); - el_key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); - el_key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); - el_key_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); - el_key_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); + key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); + key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); + key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); + key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); + key_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); + key_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); + key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); + key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); + key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); + key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); + key_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); + key_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); if (el->el_map.type == MAP_VI) { - el_key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); - el_key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); - el_key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); - el_key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); - el_key_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); - el_key_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); - el_key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); - el_key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); - el_key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); - el_key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); - el_key_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); - el_key_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); + key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); + key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); + key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); + key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); + key_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); + key_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); + key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); + key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); + key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); + key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); + key_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); + key_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); } } @@ -1157,7 +1163,7 @@ for (i = 0; i < A_K_NKEYS; i++) if (*name == '\0' || strcmp(name, arrow[i].name) == 0) if (arrow[i].type != XK_NOD) - el_key_kprint(el, arrow[i].name, &arrow[i].fun, + key_kprint(el, arrow[i].name, &arrow[i].fun, arrow[i].type); } @@ -1198,20 +1204,20 @@ * unassigned key. */ if (arrow[i].type == XK_NOD) - el_key_clear(el, map, p); + key_clear(el, map, p); else { if (p[1] && (dmap[j] == map[j] || map[j] == ED_SEQUENCE_LEAD_IN)) { - el_key_add(el, p, &arrow[i].fun, + key_add(el, p, &arrow[i].fun, arrow[i].type); map[j] = ED_SEQUENCE_LEAD_IN; } else if (map[j] == ED_UNASSIGNED) { - el_key_clear(el, map, p); + key_clear(el, map, p); if (arrow[i].type == XK_CMD) map[j] = arrow[i].fun.cmd; else - el_key_add(el, p, &arrow[i].fun, - arrow[i].type); + key_add(el, p, &arrow[i].fun, + arrow[i].type); } } } @@ -1244,12 +1250,10 @@ /* term_telltc(): * Print the current termcap characteristics */ -char *el_key__decode_str(const char *, char *, const char *); - protected int /*ARGSUSED*/ -term_telltc(EditLine *el, int argc __attribute__((unused)), - const char **argv __attribute__((unused))) +term_telltc(EditLine *el, int argc __attribute__((__unused__)), + const char **argv __attribute__((__unused__))) { const struct termcapstr *t; char **ts; @@ -1273,7 +1277,7 @@ (void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n", t->long_name, t->name, *ts && **ts ? - el_key__decode_str(*ts, upbuf, "") : "(empty)"); + key__decode_str(*ts, upbuf, "") : "(empty)"); (void) fputc('\n', el->el_outfile); return (0); } @@ -1284,8 +1288,8 @@ */ protected int /*ARGSUSED*/ -term_settc(EditLine *el, int argc __attribute__((unused)), - const char **argv __attribute__((unused))) +term_settc(EditLine *el, int argc __attribute__((__unused__)), + const char **argv) { const struct termcapstr *ts; const struct termcapval *tv; @@ -1361,9 +1365,8 @@ */ protected int /*ARGSUSED*/ -term_echotc(EditLine *el __attribute__((unused)), - int argc __attribute__((unused)), - const char **argv __attribute__((unused))) +term_echotc(EditLine *el, int argc __attribute__((__unused__)), + const char **argv) { char *cap, *scap, *ep; int arg_need, arg_cols, arg_rows; @@ -1442,7 +1445,7 @@ break; } if (t->name == NULL) - scap = tgetstr(*argv, &area); + scap = tgetstr((char *)*argv, &area); if (!scap || scap[0] == '\0') { if (!silent) (void) fprintf(el->el_errfile, --- 1.2/cmd-line-utils/libedit/libedit_term.h 2003-02-26 07:05:04 -08:00 +++ 1.3/cmd-line-utils/libedit/libedit_term.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: term.h,v 1.12 2001/01/04 15:56:32 christos Exp $ */ +/* $OpenBSD: term.h,v 1.7 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: term.h,v 1.15 2003/09/14 21:48:55 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -47,13 +44,14 @@ #include "histedit.h" typedef struct { /* Symbolic function key bindings */ - const char *name; /* name of the key */ + const char *name; /* name of the key */ int key; /* Index in termcap table */ key_value_t fun; /* Function bound to it */ int type; /* Type of function */ } fkey_t; typedef struct { + const char *t_name; /* the terminal name */ coord_t t_size; /* # lines and cols */ int t_flags; #define TERM_CAN_INSERT 0x001 /* Has insert cap */ @@ -100,6 +98,7 @@ protected int term_clear_arrow(EditLine *, const char *); protected int term_set_arrow(EditLine *, const char *, key_value_t *, int); protected void term_end(EditLine *); +protected void term_get(EditLine *, const char **); protected int term_set(EditLine *, const char *); protected int term_settc(EditLine *, int, const char **); protected int term_telltc(EditLine *, int, const char **); --- 1.3/cmd-line-utils/libedit/tokenizer.c 2004-08-24 08:41:37 -07:00 +++ 1.4/cmd-line-utils/libedit/tokenizer.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: tokenizer.c,v 1.11 2002/10/27 20:24:29 christos Exp $ */ +/* $OpenBSD: tokenizer.c,v 1.10 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: tokenizer.c,v 1.13 2003/10/18 23:48:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tokenizer.c,v 1.11 2002/10/27 20:24:29 christos Exp $"); +static const char rcsid[] = "$OpenBSD: tokenizer.c,v 1.10 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -64,6 +61,7 @@ #define WINCR 20 #define AINCR 10 +#define tok_strdup(a) strdup(a) #define tok_malloc(a) malloc(a) #define tok_free(a) free(a) #define tok_realloc(a, b) realloc(a, b) @@ -111,7 +109,7 @@ if (tok == NULL) return NULL; - tok->ifs = strdup(ifs ? ifs : IFS); + tok->ifs = tok_strdup(ifs ? ifs : IFS); if (tok->ifs == NULL) { tok_free((ptr_t)tok); return NULL; --- 1.2/cmd-line-utils/libedit/tokenizer.h 2004-08-24 08:41:37 -07:00 +++ 1.3/cmd-line-utils/libedit/tokenizer.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: tokenizer.h,v 1.5 2002/03/18 16:01:00 christos Exp $ */ +/* $OpenBSD: tokenizer.h,v 1.7 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: tokenizer.h,v 1.6 2003/08/07 16:44:34 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * --- 1.4/cmd-line-utils/libedit/tty.c 2004-09-03 05:47:33 -07:00 +++ 1.5/cmd-line-utils/libedit/tty.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: tty.c,v 1.16 2002/03/18 16:01:01 christos Exp $ */ +/* $OpenBSD: tty.c,v 1.10 2003/11/25 20:12:38 otto Exp $ */ +/* $NetBSD: tty.c,v 1.20 2003/10/18 22:37:24 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tty.c,v 1.16 2002/03/18 16:01:01 christos Exp $"); +static const char rcsid[] = "$OpenBSD: tty.c,v 1.10 2003/11/25 20:12:38 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -455,6 +452,7 @@ #define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8) #define tty__cooked_mode(td) ((td)->c_lflag & ICANON) +private int tty__getcharindex(int); private void tty__getchar(struct termios *, unsigned char *); private void tty__setchar(struct termios *, unsigned char *); private speed_t tty__getspeed(struct termios *); @@ -568,7 +566,7 @@ */ protected void /*ARGSUSED*/ -tty_end(EditLine *el __attribute__((unused))) +tty_end(EditLine *el __attribute__((__unused__))) { /* XXX: Maybe reset to an initial state? */ @@ -588,6 +586,113 @@ return (spd); } +/* tty__getspeed(): + * Return the index of the asked char in the c_cc array + */ +private int +tty__getcharindex(int i) +{ + switch (i) { +#ifdef VINTR + case C_INTR: + return VINTR; +#endif /* VINTR */ +#ifdef VQUIT + case C_QUIT: + return VQUIT; +#endif /* VQUIT */ +#ifdef VERASE + case C_ERASE: + return VERASE; +#endif /* VERASE */ +#ifdef VKILL + case C_KILL: + return VKILL; +#endif /* VKILL */ +#ifdef VEOF + case C_EOF: + return VEOF; +#endif /* VEOF */ +#ifdef VEOL + case C_EOL: + return VEOL; +#endif /* VEOL */ +#ifdef VEOL2 + case C_EOL2: + return VEOL2; +#endif /* VEOL2 */ +#ifdef VSWTCH + case C_SWTCH: + return VSWTCH; +#endif /* VSWTCH */ +#ifdef VDSWTCH + case C_DSWTCH: + return VDSWTCH; +#endif /* VDSWTCH */ +#ifdef VERASE2 + case C_ERASE2: + return VERASE2; +#endif /* VERASE2 */ +#ifdef VSTART + case C_START: + return VSTART; +#endif /* VSTART */ +#ifdef VSTOP + case C_STOP: + return VSTOP; +#endif /* VSTOP */ +#ifdef VWERASE + case C_WERASE: + return VWERASE; +#endif /* VWERASE */ +#ifdef VSUSP + case C_SUSP: + return VSUSP; +#endif /* VSUSP */ +#ifdef VDSUSP + case C_DSUSP: + return VDSUSP; +#endif /* VDSUSP */ +#ifdef VREPRINT + case C_REPRINT: + return VREPRINT; +#endif /* VREPRINT */ +#ifdef VDISCARD + case C_DISCARD: + return VDISCARD; +#endif /* VDISCARD */ +#ifdef VLNEXT + case C_LNEXT: + return VLNEXT; +#endif /* VLNEXT */ +#ifdef VSTATUS + case C_STATUS: + return VSTATUS; +#endif /* VSTATUS */ +#ifdef VPAGE + case C_PAGE: + return VPAGE; +#endif /* VPAGE */ +#ifdef VPGOFF + case C_PGOFF: + return VPGOFF; +#endif /* VPGOFF */ +#ifdef VKILL2 + case C_KILL2: + return VKILL2; +#endif /* KILL2 */ +#ifdef VMIN + case C_MIN: + return VMIN; +#endif /* VMIN */ +#ifdef VTIME + case C_TIME: + return VTIME; +#endif /* VTIME */ + default: + return -1; + } +} /* tty__getchar(): * Get the tty characters @@ -784,15 +889,15 @@ if (new[0] == old[0] && !force) continue; /* Put the old default binding back, and set the new binding */ - el_key_clear(el, map, (char *)old); + key_clear(el, map, (char *)old); map[old[0]] = dmap[old[0]]; - el_key_clear(el, map, (char *)new); + key_clear(el, map, (char *)new); /* MAP_VI == 1, MAP_EMACS == 0... */ map[new[0]] = tp->bind[el->el_map.type]; if (dalt) { - el_key_clear(el, alt, (char *)old); + key_clear(el, alt, (char *)old); alt[old[0]] = dalt[old[0]]; - el_key_clear(el, alt, (char *)new); + key_clear(el, alt, (char *)new); alt[new[0]] = tp->bind[el->el_map.type + 1]; } } @@ -1041,13 +1146,14 @@ */ protected int /*ARGSUSED*/ -tty_stty(EditLine *el, int argc __attribute__((unused)), const char **argv) +tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv) { const ttymodes_t *m; char x; int aflag = 0; const char *s, *d; const char *name; + struct termios *tios = &el->el_tty.t_ex; int z = EX_IO; if (argv == NULL) @@ -1062,14 +1168,17 @@ break; case 'd': argv++; + tios = &el->el_tty.t_ed; z = ED_IO; break; case 'x': argv++; + tios = &el->el_tty.t_ex; z = EX_IO; break; case 'q': argv++; + tios = &el->el_tty.t_ts; z = QU_IO; break; default: @@ -1119,6 +1228,7 @@ return (0); } while (argv && (s = *argv++)) { + char *p; switch (*s) { case '+': case '-': @@ -1129,14 +1239,26 @@ break; } d = s; + if ((p = strchr(s, '=')) != NULL) + *p++ = '\0'; for (m = ttymodes; m->m_name; m++) - if (strcmp(m->m_name, d) == 0) + if (strcmp(m->m_name, d) == 0 && + (p == NULL || m->m_type == MD_CHAR)) break; if (!m->m_name) { (void) fprintf(el->el_errfile, "%s: Invalid argument `%s'.\n", name, d); return (-1); + } + if (p) { + int c = ffs((int)m->m_value); + int v = *p ? parse__escape((const char **const) &p) : + el->el_tty.t_vdisable; + c--; + c = tty__getcharindex(c); + tios->c_cc[c] = v; + continue; } switch (x) { case '+': --- 1.2/cmd-line-utils/libedit/tty.h 2004-08-24 08:41:37 -07:00 +++ 1.3/cmd-line-utils/libedit/tty.h 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: tty.h,v 1.9 2002/03/18 16:01:01 christos Exp $ */ +/* $OpenBSD: tty.h,v 1.7 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: tty.h,v 1.10 2003/08/07 16:44:34 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * --- 1.3/cmd-line-utils/libedit/vi.c 2004-08-24 08:41:37 -07:00 +++ 1.4/cmd-line-utils/libedit/vi.c 2005-04-05 19:43:53 -07:00 @@ -1,4 +1,5 @@ -/* $NetBSD: vi.c,v 1.16 2003/03/10 11:09:25 dsl Exp $ */ +/* $OpenBSD: vi.c,v 1.7 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: vi.c,v 1.19 2003/08/07 16:44:35 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -45,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vi.c,v 1.16 2003/03/10 11:09:25 dsl Exp $"); +static const char rcsid[] = "$OpenBSD: vi.c,v 1.7 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -123,7 +120,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_paste_next(EditLine *el, int c __attribute__((unused))) +vi_paste_next(EditLine *el, int c __attribute__((__unused__))) { return (cv_paste(el, 0)); @@ -136,7 +133,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_paste_prev(EditLine *el, int c __attribute__((unused))) +vi_paste_prev(EditLine *el, int c __attribute__((__unused__))) { return (cv_paste(el, 1)); @@ -149,7 +146,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_prev_big_word(EditLine *el, int c __attribute__((unused))) +vi_prev_big_word(EditLine *el, int c) { if (el->el_line.cursor == el->el_line.buffer) @@ -174,7 +171,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_prev_word(EditLine *el, int c __attribute__((unused))) +vi_prev_word(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -199,7 +196,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_next_big_word(EditLine *el, int c __attribute__((unused))) +vi_next_big_word(EditLine *el, int c) { if (el->el_line.cursor >= el->el_line.lastchar - 1) @@ -223,7 +220,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_next_word(EditLine *el, int c __attribute__((unused))) +vi_next_word(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) @@ -278,7 +275,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_change_meta(EditLine *el, int c __attribute__((unused))) +vi_change_meta(EditLine *el, int c __attribute__((__unused__))) { /* @@ -295,7 +292,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_insert_at_bol(EditLine *el, int c __attribute__((unused))) +vi_insert_at_bol(EditLine *el, int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -311,7 +308,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_replace_char(EditLine *el, int c __attribute__((unused))) +vi_replace_char(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar) @@ -330,7 +327,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_replace_mode(EditLine *el, int c __attribute__((unused))) +vi_replace_mode(EditLine *el, int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -346,7 +343,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_substitute_char(EditLine *el, int c __attribute__((unused))) +vi_substitute_char(EditLine *el, int c __attribute__((__unused__))) { c_delafter(el, el->el_state.argument); @@ -361,7 +358,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_substitute_line(EditLine *el, int c __attribute__((unused))) +vi_substitute_line(EditLine *el, int c __attribute__((__unused__))) { cv_undo(el); @@ -379,7 +376,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_change_to_eol(EditLine *el, int c __attribute__((unused))) +vi_change_to_eol(EditLine *el, int c __attribute__((__unused__))) { cv_undo(el); @@ -397,7 +394,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_insert(EditLine *el, int c __attribute__((unused))) +vi_insert(EditLine *el, int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -412,7 +409,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_add(EditLine *el, int c __attribute__((unused))) +vi_add(EditLine *el, int c __attribute__((__unused__))) { int ret; @@ -437,7 +434,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_add_at_eol(EditLine *el, int c __attribute__((unused))) +vi_add_at_eol(EditLine *el, int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -453,7 +450,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_delete_meta(EditLine *el, int c __attribute__((unused))) +vi_delete_meta(EditLine *el, int c __attribute__((__unused__))) { return (cv_action(el, DELETE)); @@ -466,7 +463,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_end_big_word(EditLine *el, int c __attribute__((unused))) +vi_end_big_word(EditLine *el, int c) { if (el->el_line.cursor == el->el_line.lastchar) @@ -490,7 +487,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_end_word(EditLine *el, int c __attribute__((unused))) +vi_end_word(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) @@ -514,7 +511,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_undo(EditLine *el, int c __attribute__((unused))) +vi_undo(EditLine *el, int c __attribute__((__unused__))) { c_undo_t un = el->el_chared.c_undo; @@ -540,7 +537,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_command_mode(EditLine *el, int c __attribute__((unused))) +vi_command_mode(EditLine *el, int c __attribute__((__unused__))) { /* [Esc] cancels pending action */ @@ -585,7 +582,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_delete_prev_char(EditLine *el, int c __attribute__((unused))) +vi_delete_prev_char(EditLine *el, int c __attribute__((__unused__))) { char *cp; @@ -609,23 +606,35 @@ */ protected el_action_t /*ARGSUSED*/ -vi_list_or_eof(EditLine *el, int c __attribute__((unused))) +vi_list_or_eof(EditLine *el, int c __attribute__((__unused__))) { -#ifdef notyet - if (el->el_line.cursor == el->el_line.lastchar && - el->el_line.cursor == el->el_line.buffer) { -#endif - term_overwrite(el, STReof, 4); /* then do a EOF */ - term__flush(); - return (CC_EOF); -#ifdef notyet + if (el->el_line.cursor == el->el_line.lastchar) { + if (el->el_line.cursor == el->el_line.buffer) { + term_overwrite(el, STReof, 4); /* then do a EOF */ + term__flush(); + return (CC_EOF); + } else { + /* + * Here we could list completions, but it is an + * error right now + */ + term_beep(el); + return (CC_ERROR); + } } else { +#ifdef notyet re_goto_bottom(el); *el->el_line.lastchar = '\0'; /* just in case */ return (CC_LIST_CHOICES); - } +#else + /* + * Just complain for now. + */ + term_beep(el); + return (CC_ERROR); #endif + } } @@ -635,7 +644,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_kill_line_prev(EditLine *el, int c __attribute__((unused))) +vi_kill_line_prev(EditLine *el, int c __attribute__((__unused__))) { char *kp, *cp; @@ -656,7 +665,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_search_prev(EditLine *el, int c __attribute__((unused))) +vi_search_prev(EditLine *el, int c __attribute__((__unused__))) { return (cv_search(el, ED_SEARCH_PREV_HISTORY)); @@ -669,7 +678,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_search_next(EditLine *el, int c __attribute__((unused))) +vi_search_next(EditLine *el, int c __attribute__((__unused__))) { return (cv_search(el, ED_SEARCH_NEXT_HISTORY)); @@ -682,7 +691,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_repeat_search_next(EditLine *el, int c __attribute__((unused))) +vi_repeat_search_next(EditLine *el, int c __attribute__((__unused__))) { if (el->el_search.patlen == 0) @@ -698,7 +707,7 @@ */ /*ARGSUSED*/ protected el_action_t -vi_repeat_search_prev(EditLine *el, int c __attribute__((unused))) +vi_repeat_search_prev(EditLine *el, int c __attribute__((__unused__))) { if (el->el_search.patlen == 0) @@ -716,7 +725,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_next_char(EditLine *el, int c __attribute__((unused))) +vi_next_char(EditLine *el, int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0); } @@ -728,7 +737,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_prev_char(EditLine *el, int c __attribute__((unused))) +vi_prev_char(EditLine *el, int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0); } @@ -740,7 +749,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_to_next_char(EditLine *el, int c __attribute__((unused))) +vi_to_next_char(EditLine *el, int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1); } @@ -752,7 +761,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_to_prev_char(EditLine *el, int c __attribute__((unused))) +vi_to_prev_char(EditLine *el, int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1); } @@ -764,7 +773,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_repeat_next_char(EditLine *el, int c __attribute__((unused))) +vi_repeat_next_char(EditLine *el, int c __attribute__((__unused__))) { return cv_csearch(el, el->el_search.chadir, el->el_search.chacha, @@ -778,7 +787,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_repeat_prev_char(EditLine *el, int c __attribute__((unused))) +vi_repeat_prev_char(EditLine *el, int c __attribute__((__unused__))) { el_action_t r; int dir = el->el_search.chadir; @@ -796,7 +805,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_match(EditLine *el, int c __attribute__((unused))) +vi_match(EditLine *el, int c) { const char match_chars[] = "()[]{}"; char *cp; @@ -843,7 +852,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_undo_line(EditLine *el, int c __attribute__((unused))) +vi_undo_line(EditLine *el, int c) { cv_undo(el); @@ -857,7 +866,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_to_column(EditLine *el, int c __attribute__((unused))) +vi_to_column(EditLine *el, int c) { el->el_line.cursor = el->el_line.buffer; @@ -871,7 +880,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_yank_end(EditLine *el, int c __attribute__((unused))) +vi_yank_end(EditLine *el, int c) { cv_yank(el, el->el_line.cursor, @@ -885,7 +894,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_yank(EditLine *el, int c __attribute__((unused))) +vi_yank(EditLine *el, int c) { return cv_action(el, YANK); @@ -897,7 +906,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_comment_out(EditLine *el, int c __attribute__((unused))) +vi_comment_out(EditLine *el, int c) { el->el_line.cursor = el->el_line.buffer; @@ -915,7 +924,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_alias(EditLine *el __attribute__((unused)), int c __attribute__((unused))) +vi_alias(EditLine *el, int c) { #ifdef __weak_extern char alias_name[3]; @@ -947,7 +956,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_to_history_line(EditLine *el, int c __attribute__((unused))) +vi_to_history_line(EditLine *el, int c) { int sv_event_no = el->el_history.eventno; el_action_t rval; @@ -992,7 +1001,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_histedit(EditLine *el, int c __attribute__((unused))) +vi_histedit(EditLine *el, int c) { int fd; pid_t pid; @@ -1019,7 +1028,7 @@ return CC_ERROR; case 0: close(fd); - execlp("vi", "vi", tempfile, 0); + execlp("vi", "vi", tempfile, (char*)NULL); exit(0); /*NOTREACHED*/ default: @@ -1048,7 +1057,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_history_word(EditLine *el, int c __attribute__((unused))) +vi_history_word(EditLine *el, int c) { const char *wp = HIST_FIRST(el); const char *wep, *wsp; @@ -1097,7 +1106,7 @@ */ protected el_action_t /*ARGSUSED*/ -vi_redo(EditLine *el, int c __attribute__((unused))) +vi_redo(EditLine *el, int c) { c_redo_t *r = &el->el_chared.c_redo;