mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
Upgrade to libedit-2.9
BitKeeper/deleted/.del-readline.h~ac6080227e4b72fc: Delete: cmd-line-utils/libedit/readline/readline.h
This commit is contained in:
parent
7f0f4c5875
commit
948d88da93
42 changed files with 2857 additions and 1313 deletions
|
@ -1306,7 +1306,7 @@ static void initialize_readline (char *name)
|
||||||
setlocale(LC_ALL,""); /* so as libedit use isprint */
|
setlocale(LC_ALL,""); /* so as libedit use isprint */
|
||||||
#endif
|
#endif
|
||||||
rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion;
|
rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion;
|
||||||
rl_completion_entry_function= (CPFunction*)&no_completion;
|
rl_completion_entry_function= (Function*)&no_completion;
|
||||||
#else
|
#else
|
||||||
rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion;
|
rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion;
|
||||||
rl_completion_entry_function= (Function*)&no_completion;
|
rl_completion_entry_function= (Function*)&no_completion;
|
||||||
|
|
|
@ -20,7 +20,7 @@ EXTRA_libedit_a_SOURCES = np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \
|
||||||
libedit_a_LIBADD = @LIBEDIT_LOBJECTS@
|
libedit_a_LIBADD = @LIBEDIT_LOBJECTS@
|
||||||
libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@
|
libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@
|
||||||
|
|
||||||
pkginclude_HEADERS = readline/readline.h
|
pkginclude_HEADERS = editline/readline.h
|
||||||
|
|
||||||
noinst_HEADERS = chared.h el.h histedit.h key.h parse.h refresh.h sig.h \
|
noinst_HEADERS = chared.h el.h histedit.h key.h parse.h refresh.h sig.h \
|
||||||
sys.h tokenizer.h config.h hist.h map.h prompt.h read.h \
|
sys.h tokenizer.h config.h hist.h map.h prompt.h read.h \
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $ */
|
/* $NetBSD: chared.c,v 1.22 2004/08/13 12:10:38 mycroft Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* chared.c: Character editor utilities
|
* chared.c: Character editor utilities
|
||||||
|
@ -62,13 +51,13 @@ cv_undo(EditLine *el)
|
||||||
{
|
{
|
||||||
c_undo_t *vu = &el->el_chared.c_undo;
|
c_undo_t *vu = &el->el_chared.c_undo;
|
||||||
c_redo_t *r = &el->el_chared.c_redo;
|
c_redo_t *r = &el->el_chared.c_redo;
|
||||||
int size;
|
uint size;
|
||||||
|
|
||||||
/* Save entire line for undo */
|
/* Save entire line for undo */
|
||||||
size = el->el_line.lastchar - el->el_line.buffer;
|
size = el->el_line.lastchar - el->el_line.buffer;
|
||||||
vu->len = size;
|
vu->len = size;
|
||||||
vu->cursor = el->el_line.cursor - el->el_line.buffer;
|
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 */
|
/* save command info for redo */
|
||||||
r->count = el->el_state.doingarg ? el->el_state.argument : 0;
|
r->count = el->el_state.doingarg ? el->el_state.argument : 0;
|
||||||
|
@ -139,6 +128,21 @@ c_delafter(EditLine *el, int num)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* c_delafter1():
|
||||||
|
* Delete the character after the cursor, do not yank
|
||||||
|
*/
|
||||||
|
protected void
|
||||||
|
c_delafter1(EditLine *el)
|
||||||
|
{
|
||||||
|
char *cp;
|
||||||
|
|
||||||
|
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
|
||||||
|
*cp = cp[1];
|
||||||
|
|
||||||
|
el->el_line.lastchar--;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* c_delbefore():
|
/* c_delbefore():
|
||||||
* Delete num characters before the cursor
|
* Delete num characters before the cursor
|
||||||
*/
|
*/
|
||||||
|
@ -167,6 +171,21 @@ c_delbefore(EditLine *el, int num)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* c_delbefore1():
|
||||||
|
* Delete the character before the cursor, do not yank
|
||||||
|
*/
|
||||||
|
protected void
|
||||||
|
c_delbefore1(EditLine *el)
|
||||||
|
{
|
||||||
|
char *cp;
|
||||||
|
|
||||||
|
for (cp = el->el_line.cursor - 1; cp <= el->el_line.lastchar; cp++)
|
||||||
|
*cp = cp[1];
|
||||||
|
|
||||||
|
el->el_line.lastchar--;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ce__isword():
|
/* ce__isword():
|
||||||
* Return if p is part of a word according to emacs
|
* Return if p is part of a word according to emacs
|
||||||
*/
|
*/
|
||||||
|
@ -460,8 +479,8 @@ ch_init(EditLine *el)
|
||||||
el->el_state.argument = 1;
|
el->el_state.argument = 1;
|
||||||
el->el_state.lastcmd = ED_UNASSIGNED;
|
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.level = -1;
|
||||||
|
el->el_chared.c_macro.offset = 0;
|
||||||
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
|
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
|
||||||
sizeof(char *));
|
sizeof(char *));
|
||||||
if (el->el_chared.c_macro.macro == NULL)
|
if (el->el_chared.c_macro.macro == NULL)
|
||||||
|
@ -582,7 +601,7 @@ ch_enlargebufs(el, addlen)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Safe to set enlarged buffer size */
|
/* 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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: chared.h,v 1.11 2002/11/20 16:50:08 christos Exp $ */
|
/* $NetBSD: chared.h,v 1.14 2004/08/13 12:10:39 mycroft Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -66,8 +62,8 @@
|
||||||
|
|
||||||
typedef struct c_macro_t {
|
typedef struct c_macro_t {
|
||||||
int level;
|
int level;
|
||||||
|
int offset;
|
||||||
char **macro;
|
char **macro;
|
||||||
char *nline;
|
|
||||||
} c_macro_t;
|
} c_macro_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -158,7 +154,9 @@ protected char *c__next_word(char *, char *, int, int (*)(int));
|
||||||
protected char *c__prev_word(char *, char *, int, int (*)(int));
|
protected char *c__prev_word(char *, char *, int, int (*)(int));
|
||||||
protected void c_insert(EditLine *, int);
|
protected void c_insert(EditLine *, int);
|
||||||
protected void c_delbefore(EditLine *, int);
|
protected void c_delbefore(EditLine *, int);
|
||||||
|
protected void c_delbefore1(EditLine *);
|
||||||
protected void c_delafter(EditLine *, int);
|
protected void c_delafter(EditLine *, int);
|
||||||
|
protected void c_delafter1(EditLine *);
|
||||||
protected int c_gets(EditLine *, char *, const char *);
|
protected int c_gets(EditLine *, char *, const char *);
|
||||||
protected int c_hpos(EditLine *);
|
protected int c_hpos(EditLine *);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */
|
/* $NetBSD: common.c,v 1.16 2003/08/07 16:44:30 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* common.c: Common Editor functions
|
* common.c: Common Editor functions
|
||||||
|
@ -56,7 +45,7 @@ __RCSID("$NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $");
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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);
|
re_goto_bottom(el);
|
||||||
|
@ -113,7 +102,7 @@ ed_insert(EditLine *el, int c)
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
char *cp, *p, *kp;
|
||||||
|
|
||||||
|
@ -141,7 +130,7 @@ ed_delete_prev_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_delete_next_char(EditLine *el, int c __attribute__((unused)))
|
ed_delete_next_char(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
#ifdef notdef /* XXX */
|
#ifdef notdef /* XXX */
|
||||||
#define EL el->el_line
|
#define EL el->el_line
|
||||||
|
@ -192,7 +181,7 @@ ed_delete_next_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_kill_line(EditLine *el, int c __attribute__((unused)))
|
ed_kill_line(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *kp, *cp;
|
char *kp, *cp;
|
||||||
|
|
||||||
|
@ -213,7 +202,7 @@ ed_kill_line(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_line.cursor = el->el_line.lastchar;
|
||||||
|
@ -236,7 +225,7 @@ ed_move_to_end(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_line.cursor = el->el_line.buffer;
|
||||||
|
@ -285,7 +274,7 @@ ed_transpose_chars(EditLine *el, int c)
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
char *lim = el->el_line.lastchar;
|
||||||
|
|
||||||
|
@ -314,7 +303,7 @@ ed_next_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor == el->el_line.buffer)
|
||||||
|
@ -340,7 +329,7 @@ ed_prev_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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) {
|
if (el->el_line.cursor > el->el_line.buffer) {
|
||||||
|
@ -437,8 +426,7 @@ ed_argument_digit(EditLine *el, int c)
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_unassigned(EditLine *el __attribute__((unused)),
|
ed_unassigned(EditLine *el, int c __attribute__((__unused__)))
|
||||||
int c __attribute__((unused)))
|
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_ERROR);
|
return (CC_ERROR);
|
||||||
|
@ -455,8 +443,8 @@ ed_unassigned(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_tty_sigint(EditLine *el __attribute__((unused)),
|
ed_tty_sigint(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
|
@ -469,8 +457,8 @@ ed_tty_sigint(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_tty_dsusp(EditLine *el __attribute__((unused)),
|
ed_tty_dsusp(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
|
@ -483,8 +471,8 @@ ed_tty_dsusp(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_tty_flush_output(EditLine *el __attribute__((unused)),
|
ed_tty_flush_output(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
|
@ -497,8 +485,8 @@ ed_tty_flush_output(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_tty_sigquit(EditLine *el __attribute__((unused)),
|
ed_tty_sigquit(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
|
@ -511,8 +499,8 @@ ed_tty_sigquit(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_tty_sigtstp(EditLine *el __attribute__((unused)),
|
ed_tty_sigtstp(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
|
@ -525,8 +513,8 @@ ed_tty_sigtstp(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_tty_stop_output(EditLine *el __attribute__((unused)),
|
ed_tty_stop_output(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
|
@ -539,8 +527,8 @@ ed_tty_stop_output(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_tty_start_output(EditLine *el __attribute__((unused)),
|
ed_tty_start_output(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
|
@ -553,7 +541,7 @@ ed_tty_start_output(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_newline(EditLine *el, int c __attribute__((unused)))
|
ed_newline(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
re_goto_bottom(el);
|
re_goto_bottom(el);
|
||||||
|
@ -569,7 +557,7 @@ ed_newline(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor <= el->el_line.buffer)
|
||||||
|
@ -589,7 +577,7 @@ ed_delete_prev_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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 */
|
term_clear_screen(el); /* clear the whole real screen */
|
||||||
|
@ -604,8 +592,8 @@ ed_clear_screen(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_redisplay(EditLine *el __attribute__((unused)),
|
ed_redisplay(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_REDISPLAY);
|
return (CC_REDISPLAY);
|
||||||
|
@ -618,7 +606,7 @@ ed_redisplay(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_start_over(EditLine *el, int c __attribute__((unused)))
|
ed_start_over(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
ch_reset(el);
|
ch_reset(el);
|
||||||
|
@ -632,8 +620,8 @@ ed_start_over(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_sequence_lead_in(EditLine *el __attribute__((unused)),
|
ed_sequence_lead_in(EditLine *el __attribute__((__unused__)),
|
||||||
int c __attribute__((unused)))
|
int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
|
@ -646,7 +634,7 @@ ed_sequence_lead_in(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_prev_history(EditLine *el, int c __attribute__((unused)))
|
ed_prev_history(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char beep = 0;
|
char beep = 0;
|
||||||
int sv_event = el->el_history.eventno;
|
int sv_event = el->el_history.eventno;
|
||||||
|
@ -684,7 +672,7 @@ ed_prev_history(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el_action_t beep = CC_REFRESH, rval;
|
||||||
|
|
||||||
|
@ -711,7 +699,7 @@ ed_next_history(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_search_prev_history(EditLine *el, int c __attribute__((unused)))
|
ed_search_prev_history(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
const char *hp;
|
const char *hp;
|
||||||
int h;
|
int h;
|
||||||
|
@ -779,7 +767,7 @@ ed_search_prev_history(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_search_next_history(EditLine *el, int c __attribute__((unused)))
|
ed_search_next_history(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
const char *hp;
|
const char *hp;
|
||||||
int h;
|
int h;
|
||||||
|
@ -833,7 +821,7 @@ ed_search_next_history(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_prev_line(EditLine *el, int c __attribute__((unused)))
|
ed_prev_line(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int nchars = c_hpos(el);
|
int nchars = c_hpos(el);
|
||||||
|
@ -876,7 +864,7 @@ ed_prev_line(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_next_line(EditLine *el, int c __attribute__((unused)))
|
ed_next_line(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int nchars = c_hpos(el);
|
int nchars = c_hpos(el);
|
||||||
|
@ -910,7 +898,7 @@ ed_next_line(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
ed_command(EditLine *el, int c __attribute__((unused)))
|
ed_command(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char tmpbuf[EL_BUFSIZ];
|
char tmpbuf[EL_BUFSIZ];
|
||||||
int tmplen;
|
int tmplen;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: readline.h,v 1.1 2001/01/05 21:15:50 jdolecek Exp $ */
|
/* $NetBSD: readline.h,v 1.12 2004/09/08 18:15:37 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#ifndef _READLINE_H_
|
#ifndef _READLINE_H_
|
||||||
#define _READLINE_H_
|
#define _READLINE_H_
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
@ -48,11 +48,45 @@ typedef void VFunction(void);
|
||||||
typedef char *CPFunction(const char *, int);
|
typedef char *CPFunction(const char *, int);
|
||||||
typedef char **CPPFunction(const char *, int, int);
|
typedef char **CPPFunction(const char *, int, int);
|
||||||
|
|
||||||
|
typedef void *histdata_t;
|
||||||
|
|
||||||
typedef struct _hist_entry {
|
typedef struct _hist_entry {
|
||||||
const char *line;
|
const char *line;
|
||||||
const char *data;
|
histdata_t *data;
|
||||||
} HIST_ENTRY;
|
} 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 <sys/ioctl.h>
|
||||||
|
#ifdef __GLIBC__
|
||||||
|
#include <sys/ttydefaults.h>
|
||||||
|
#endif
|
||||||
|
#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 */
|
/* global variables used by readline enabled applications */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -68,12 +102,31 @@ extern int max_input_history;
|
||||||
extern char *rl_basic_word_break_characters;
|
extern char *rl_basic_word_break_characters;
|
||||||
extern char *rl_completer_word_break_characters;
|
extern char *rl_completer_word_break_characters;
|
||||||
extern char *rl_completer_quote_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 CPPFunction *rl_attempted_completion_function;
|
||||||
extern int rl_completion_type;
|
extern int rl_completion_type;
|
||||||
extern int rl_completion_query_items;
|
extern int rl_completion_query_items;
|
||||||
extern char *rl_special_prefixes;
|
extern char *rl_special_prefixes;
|
||||||
extern int rl_completion_append_character;
|
extern int rl_completion_append_character;
|
||||||
|
extern int rl_inhibit_completion;
|
||||||
|
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;
|
||||||
|
/*
|
||||||
|
* 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 */
|
/* supported functions */
|
||||||
char *readline(const char *);
|
char *readline(const char *);
|
||||||
|
@ -99,6 +152,8 @@ int read_history(const char *);
|
||||||
int write_history(const char *);
|
int write_history(const char *);
|
||||||
int history_expand(char *, char **);
|
int history_expand(char *, char **);
|
||||||
char **history_tokenize(const 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 *tilde_expand(char *);
|
||||||
char *filename_completion_function(const char *, int);
|
char *filename_completion_function(const char *, int);
|
||||||
|
@ -111,6 +166,26 @@ void rl_display_match_list(char **, int, int);
|
||||||
int rl_insert(int, int);
|
int rl_insert(int, int);
|
||||||
void rl_reset_terminal(const char *);
|
void rl_reset_terminal(const char *);
|
||||||
int rl_bind_key(int, int (*)(int, int));
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: el.c,v 1.30 2002/11/12 00:00:23 thorpej Exp $ */
|
/* $NetBSD: el.c,v 1.39 2004/07/08 00:51:36 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* el.c: EditLine interface functions
|
* el.c: EditLine interface functions
|
||||||
|
@ -72,7 +61,10 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
|
||||||
el->el_infd = fileno(fin);
|
el->el_infd = fileno(fin);
|
||||||
el->el_outfile = fout;
|
el->el_outfile = fout;
|
||||||
el->el_errfile = ferr;
|
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!!!
|
* Initialize all the modules. Order is important!!!
|
||||||
|
@ -80,11 +72,11 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
|
||||||
el->el_flags = 0;
|
el->el_flags = 0;
|
||||||
|
|
||||||
if (term_init(el) == -1) {
|
if (term_init(el) == -1) {
|
||||||
free(el->el_prog);
|
el_free(el->el_prog);
|
||||||
el_free(el);
|
el_free(el);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
(void) el_key_init(el);
|
(void) key_init(el);
|
||||||
(void) map_init(el);
|
(void) map_init(el);
|
||||||
if (tty_init(el) == -1)
|
if (tty_init(el) == -1)
|
||||||
el->el_flags |= NO_TTY;
|
el->el_flags |= NO_TTY;
|
||||||
|
@ -112,7 +104,7 @@ el_end(EditLine *el)
|
||||||
el_reset(el);
|
el_reset(el);
|
||||||
|
|
||||||
term_end(el);
|
term_end(el);
|
||||||
el_key_end(el);
|
key_end(el);
|
||||||
map_end(el);
|
map_end(el);
|
||||||
tty_end(el);
|
tty_end(el);
|
||||||
ch_end(el);
|
ch_end(el);
|
||||||
|
@ -257,6 +249,27 @@ el_set(EditLine *el, int op, ...)
|
||||||
el->el_data = va_arg(va, void *);
|
el->el_data = va_arg(va, void *);
|
||||||
break;
|
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)
|
||||||
|
(void) tty_rawmode(el);
|
||||||
|
else
|
||||||
|
(void) tty_cookedmode(el);
|
||||||
|
rv = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rv = -1;
|
rv = -1;
|
||||||
break;
|
break;
|
||||||
|
@ -297,21 +310,22 @@ el_get(EditLine *el, int op, void *ret)
|
||||||
rv = 0;
|
rv = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if 0 /* XXX */
|
|
||||||
case EL_TERMINAL:
|
case EL_TERMINAL:
|
||||||
rv = term_get(el, (const char *) &ret);
|
term_get(el, (const char **)ret);
|
||||||
|
rv = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#if 0 /* XXX */
|
||||||
case EL_BIND:
|
case EL_BIND:
|
||||||
case EL_TELLTC:
|
case EL_TELLTC:
|
||||||
case EL_SETTC:
|
case EL_SETTC:
|
||||||
case EL_ECHOTC:
|
case EL_ECHOTC:
|
||||||
case EL_SETTY:
|
case EL_SETTY:
|
||||||
{
|
{
|
||||||
char *argv[20];
|
const char *argv[20];
|
||||||
int i;
|
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)
|
if ((argv[i] = va_arg(va, char *)) == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -378,6 +392,11 @@ el_get(EditLine *el, int op, void *ret)
|
||||||
rv = 0;
|
rv = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EL_UNBUFFERED:
|
||||||
|
*((int *) ret) = (!(el->el_flags & UNBUFFERED));
|
||||||
|
rv = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rv = -1;
|
rv = -1;
|
||||||
}
|
}
|
||||||
|
@ -409,12 +428,17 @@ el_source(EditLine *el, const char *fname)
|
||||||
|
|
||||||
fp = NULL;
|
fp = NULL;
|
||||||
if (fname == NULL) {
|
if (fname == NULL) {
|
||||||
#ifdef HAVE_ISSETUGID
|
|
||||||
static const char elpath[] = "/.editrc";
|
static const char elpath[] = "/.editrc";
|
||||||
|
#ifdef MAXPATHLEN
|
||||||
char path[MAXPATHLEN];
|
char path[MAXPATHLEN];
|
||||||
|
#else
|
||||||
|
char path[4096];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_ISSETUGID
|
||||||
if (issetugid())
|
if (issetugid())
|
||||||
return (-1);
|
return (-1);
|
||||||
|
#endif
|
||||||
if ((ptr = getenv("HOME")) == NULL)
|
if ((ptr = getenv("HOME")) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
|
if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
|
||||||
|
@ -422,14 +446,6 @@ el_source(EditLine *el, const char *fname)
|
||||||
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
|
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
|
||||||
return (-1);
|
return (-1);
|
||||||
fname = path;
|
fname = path;
|
||||||
#else
|
|
||||||
/*
|
|
||||||
* If issetugid() is missing, always return an error, in order
|
|
||||||
* to keep from inadvertently opening up the user to a security
|
|
||||||
* hole.
|
|
||||||
*/
|
|
||||||
return (-1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
|
@ -496,10 +512,13 @@ el_editmode(EditLine *el, int argc, const char **argv)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
how = argv[1];
|
how = argv[1];
|
||||||
if (strcmp(how, "on") == 0)
|
if (strcmp(how, "on") == 0) {
|
||||||
el->el_flags &= ~EDIT_DISABLED;
|
el->el_flags &= ~EDIT_DISABLED;
|
||||||
else if (strcmp(how, "off") == 0)
|
tty_rawmode(el);
|
||||||
|
} else if (strcmp(how, "off") == 0) {
|
||||||
|
tty_cookedmode(el);
|
||||||
el->el_flags |= EDIT_DISABLED;
|
el->el_flags |= EDIT_DISABLED;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
(void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
|
(void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: el.h,v 1.13 2002/11/15 14:32:33 christos Exp $ */
|
/* $NetBSD: el.h,v 1.16 2003/10/18 23:48:42 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -55,9 +51,10 @@
|
||||||
|
|
||||||
#define EL_BUFSIZ 1024 /* Maximum line size */
|
#define EL_BUFSIZ 1024 /* Maximum line size */
|
||||||
|
|
||||||
#define HANDLE_SIGNALS 1<<0
|
#define HANDLE_SIGNALS 0x01
|
||||||
#define NO_TTY 1<<1
|
#define NO_TTY 0x02
|
||||||
#define EDIT_DISABLED 1<<2
|
#define EDIT_DISABLED 0x04
|
||||||
|
#define UNBUFFERED 0x08
|
||||||
|
|
||||||
typedef int bool_t; /* True or not */
|
typedef int bool_t; /* True or not */
|
||||||
|
|
||||||
|
@ -91,6 +88,7 @@ typedef struct el_state_t {
|
||||||
/*
|
/*
|
||||||
* Until we come up with something better...
|
* Until we come up with something better...
|
||||||
*/
|
*/
|
||||||
|
#define el_strdup(a) strdup(a)
|
||||||
#define el_malloc(a) malloc(a)
|
#define el_malloc(a) malloc(a)
|
||||||
#define el_realloc(a,b) realloc(a, b)
|
#define el_realloc(a,b) realloc(a, b)
|
||||||
#define el_free(a) free(a)
|
#define el_free(a) free(a)
|
||||||
|
@ -98,7 +96,7 @@ typedef struct el_state_t {
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "prompt.h"
|
#include "prompt.h"
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
#include "libedit_term.h"
|
#include "el_term.h"
|
||||||
#include "refresh.h"
|
#include "refresh.h"
|
||||||
#include "chared.h"
|
#include "chared.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
131
cmd-line-utils/libedit/el_term.h
Normal file
131
cmd-line-utils/libedit/el_term.h
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
/* $NetBSD: term.h,v 1.15 2003/09/14 21:48:55 christos Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1992, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to Berkeley by
|
||||||
|
* Christos Zoulas of Cornell University.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 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. 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.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)term.h 8.1 (Berkeley) 6/4/93
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* el.term.h: Termcap header
|
||||||
|
*/
|
||||||
|
#ifndef _h_el_term
|
||||||
|
#define _h_el_term
|
||||||
|
|
||||||
|
#include "histedit.h"
|
||||||
|
|
||||||
|
typedef struct { /* Symbolic function key bindings */
|
||||||
|
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 */
|
||||||
|
#define TERM_CAN_DELETE 0x002 /* Has delete cap */
|
||||||
|
#define TERM_CAN_CEOL 0x004 /* Has CEOL cap */
|
||||||
|
#define TERM_CAN_TAB 0x008 /* Can use tabs */
|
||||||
|
#define TERM_CAN_ME 0x010 /* Can turn all attrs. */
|
||||||
|
#define TERM_CAN_UP 0x020 /* Can move up */
|
||||||
|
#define TERM_HAS_META 0x040 /* Has a meta key */
|
||||||
|
#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
|
||||||
|
#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
|
||||||
|
char *t_buf; /* Termcap buffer */
|
||||||
|
int t_loc; /* location used */
|
||||||
|
char **t_str; /* termcap strings */
|
||||||
|
int *t_val; /* termcap values */
|
||||||
|
char *t_cap; /* Termcap buffer */
|
||||||
|
fkey_t *t_fkey; /* Array of keys */
|
||||||
|
} el_term_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fKey indexes
|
||||||
|
*/
|
||||||
|
#define A_K_DN 0
|
||||||
|
#define A_K_UP 1
|
||||||
|
#define A_K_LT 2
|
||||||
|
#define A_K_RT 3
|
||||||
|
#define A_K_HO 4
|
||||||
|
#define A_K_EN 5
|
||||||
|
#define A_K_NKEYS 6
|
||||||
|
|
||||||
|
#ifdef _SUNOS
|
||||||
|
extern int tgetent(char *, const char *);
|
||||||
|
extern int tgetflag(char *);
|
||||||
|
extern int tgetnum(char *);
|
||||||
|
extern int tputs(const char *, int, int (*)(int));
|
||||||
|
extern char* tgoto(const char*, int, int);
|
||||||
|
extern char* tgetstr(char*, char**);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected void term_move_to_line(EditLine *, int);
|
||||||
|
protected void term_move_to_char(EditLine *, int);
|
||||||
|
protected void term_clear_EOL(EditLine *, int);
|
||||||
|
protected void term_overwrite(EditLine *, const char *, int);
|
||||||
|
protected void term_insertwrite(EditLine *, char *, int);
|
||||||
|
protected void term_deletechars(EditLine *, int);
|
||||||
|
protected void term_clear_screen(EditLine *);
|
||||||
|
protected void term_beep(EditLine *);
|
||||||
|
protected int term_change_size(EditLine *, int, int);
|
||||||
|
protected int term_get_size(EditLine *, int *, int *);
|
||||||
|
protected int term_init(EditLine *);
|
||||||
|
protected void term_bind_arrow(EditLine *);
|
||||||
|
protected void term_print_arrow(EditLine *, const char *);
|
||||||
|
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 **);
|
||||||
|
protected int term_echotc(EditLine *, int, const char **);
|
||||||
|
protected int term__putc(int);
|
||||||
|
protected void term__flush(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Easy access macros
|
||||||
|
*/
|
||||||
|
#define EL_FLAGS (el)->el_term.t_flags
|
||||||
|
|
||||||
|
#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
|
||||||
|
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
|
||||||
|
#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
|
||||||
|
#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB)
|
||||||
|
#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME)
|
||||||
|
#define EL_HAS_META (EL_FLAGS & TERM_HAS_META)
|
||||||
|
#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS)
|
||||||
|
#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS)
|
||||||
|
|
||||||
|
#endif /* _h_el_term */
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: emacs.c,v 1.12 2002/11/15 14:32:33 christos Exp $ */
|
/* $NetBSD: emacs.c,v 1.19 2004/10/28 21:14:52 dsl Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* emacs.c: Emacs functions
|
* emacs.c: Emacs functions
|
||||||
|
@ -56,7 +45,7 @@ __RCSID("$NetBSD: emacs.c,v 1.12 2002/11/15 14:32:33 christos Exp $");
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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) {
|
if (el->el_line.cursor == el->el_line.lastchar) {
|
||||||
|
@ -75,7 +64,10 @@ em_delete_or_list(EditLine *el, int c __attribute__((unused)))
|
||||||
return (CC_ERROR);
|
return (CC_ERROR);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c_delafter(el, el->el_state.argument); /* delete after dot */
|
if (el->el_state.doingarg)
|
||||||
|
c_delafter(el, el->el_state.argument);
|
||||||
|
else
|
||||||
|
c_delafter1(el);
|
||||||
if (el->el_line.cursor > el->el_line.lastchar)
|
if (el->el_line.cursor > el->el_line.lastchar)
|
||||||
el->el_line.cursor = el->el_line.lastchar;
|
el->el_line.cursor = el->el_line.lastchar;
|
||||||
/* bounds check */
|
/* bounds check */
|
||||||
|
@ -90,7 +82,7 @@ em_delete_or_list(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
char *cp, *p, *kp;
|
||||||
|
|
||||||
|
@ -119,14 +111,12 @@ em_delete_next_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_yank(EditLine *el, int c __attribute__((unused)))
|
em_yank(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *kp, *cp;
|
char *kp, *cp;
|
||||||
|
|
||||||
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) {
|
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
|
||||||
if (!ch_enlargebufs(el, 1))
|
return (CC_NORM);
|
||||||
return (CC_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (el->el_line.lastchar +
|
if (el->el_line.lastchar +
|
||||||
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
|
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
|
||||||
|
@ -156,7 +146,7 @@ em_yank(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_kill_line(EditLine *el, int c __attribute__((unused)))
|
em_kill_line(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *kp, *cp;
|
char *kp, *cp;
|
||||||
|
|
||||||
|
@ -178,7 +168,7 @@ em_kill_line(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_kill_region(EditLine *el, int c __attribute__((unused)))
|
em_kill_region(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *kp, *cp;
|
char *kp, *cp;
|
||||||
|
|
||||||
|
@ -211,7 +201,7 @@ em_kill_region(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_copy_region(EditLine *el, int c __attribute__((unused)))
|
em_copy_region(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *kp, *cp;
|
char *kp, *cp;
|
||||||
|
|
||||||
|
@ -235,12 +225,12 @@ em_copy_region(EditLine *el, int c __attribute__((unused)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* em_gosmacs_traspose():
|
/* em_gosmacs_transpose():
|
||||||
* Exchange the two characters before the cursor
|
* Exchange the two characters before the cursor
|
||||||
* Gosling emacs transpose chars [^T]
|
* Gosling emacs transpose chars [^T]
|
||||||
*/
|
*/
|
||||||
protected el_action_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]) {
|
if (el->el_line.cursor > &el->el_line.buffer[1]) {
|
||||||
|
@ -260,7 +250,7 @@ em_gosmacs_traspose(EditLine *el, int c)
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor == el->el_line.lastchar)
|
||||||
return (CC_ERROR);
|
return (CC_ERROR);
|
||||||
|
@ -285,7 +275,7 @@ em_next_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_upper_case(EditLine *el, int c __attribute__((unused)))
|
em_upper_case(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *cp, *ep;
|
char *cp, *ep;
|
||||||
|
|
||||||
|
@ -293,8 +283,8 @@ em_upper_case(EditLine *el, int c __attribute__((unused)))
|
||||||
el->el_state.argument, ce__isword);
|
el->el_state.argument, ce__isword);
|
||||||
|
|
||||||
for (cp = el->el_line.cursor; cp < ep; cp++)
|
for (cp = el->el_line.cursor; cp < ep; cp++)
|
||||||
if (islower((unsigned char) *cp))
|
if (islower((unsigned char)*cp))
|
||||||
*cp = toupper(*cp);
|
*cp = toupper((unsigned char)*cp);
|
||||||
|
|
||||||
el->el_line.cursor = ep;
|
el->el_line.cursor = ep;
|
||||||
if (el->el_line.cursor > el->el_line.lastchar)
|
if (el->el_line.cursor > el->el_line.lastchar)
|
||||||
|
@ -309,7 +299,7 @@ em_upper_case(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_capitol_case(EditLine *el, int c __attribute__((unused)))
|
em_capitol_case(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *cp, *ep;
|
char *cp, *ep;
|
||||||
|
|
||||||
|
@ -317,16 +307,16 @@ em_capitol_case(EditLine *el, int c __attribute__((unused)))
|
||||||
el->el_state.argument, ce__isword);
|
el->el_state.argument, ce__isword);
|
||||||
|
|
||||||
for (cp = el->el_line.cursor; cp < ep; cp++) {
|
for (cp = el->el_line.cursor; cp < ep; cp++) {
|
||||||
if (isalpha((unsigned char) *cp)) {
|
if (isalpha((unsigned char)*cp)) {
|
||||||
if (islower((unsigned char) *cp))
|
if (islower((unsigned char)*cp))
|
||||||
*cp = toupper(*cp);
|
*cp = toupper((unsigned char)*cp);
|
||||||
cp++;
|
cp++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; cp < ep; cp++)
|
for (; cp < ep; cp++)
|
||||||
if (isupper((unsigned char) *cp))
|
if (isupper((unsigned char)*cp))
|
||||||
*cp = tolower(*cp);
|
*cp = tolower((unsigned char)*cp);
|
||||||
|
|
||||||
el->el_line.cursor = ep;
|
el->el_line.cursor = ep;
|
||||||
if (el->el_line.cursor > el->el_line.lastchar)
|
if (el->el_line.cursor > el->el_line.lastchar)
|
||||||
|
@ -341,7 +331,7 @@ em_capitol_case(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_lower_case(EditLine *el, int c __attribute__((unused)))
|
em_lower_case(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *cp, *ep;
|
char *cp, *ep;
|
||||||
|
|
||||||
|
@ -349,8 +339,8 @@ em_lower_case(EditLine *el, int c __attribute__((unused)))
|
||||||
el->el_state.argument, ce__isword);
|
el->el_state.argument, ce__isword);
|
||||||
|
|
||||||
for (cp = el->el_line.cursor; cp < ep; cp++)
|
for (cp = el->el_line.cursor; cp < ep; cp++)
|
||||||
if (isupper((unsigned char) *cp))
|
if (isupper((unsigned char)*cp))
|
||||||
*cp = tolower(*cp);
|
*cp = tolower((unsigned char)*cp);
|
||||||
|
|
||||||
el->el_line.cursor = ep;
|
el->el_line.cursor = ep;
|
||||||
if (el->el_line.cursor > el->el_line.lastchar)
|
if (el->el_line.cursor > el->el_line.lastchar)
|
||||||
|
@ -365,7 +355,7 @@ em_lower_case(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_chared.c_kill.mark = el->el_line.cursor;
|
||||||
|
@ -379,7 +369,7 @@ em_set_mark(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_exchange_mark(EditLine *el, int c __attribute__((unused)))
|
em_exchange_mark(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
|
@ -396,7 +386,7 @@ em_exchange_mark(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_universal_argument(EditLine *el, int c __attribute__((unused)))
|
em_universal_argument(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{ /* multiply current argument by 4 */
|
{ /* multiply current argument by 4 */
|
||||||
|
|
||||||
if (el->el_state.argument > 1000000)
|
if (el->el_state.argument > 1000000)
|
||||||
|
@ -413,7 +403,7 @@ em_universal_argument(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
em_meta_next(EditLine *el, int c __attribute__((unused)))
|
em_meta_next(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
el->el_state.metanext = 1;
|
el->el_state.metanext = 1;
|
||||||
|
@ -426,7 +416,7 @@ em_meta_next(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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) ?
|
el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
|
||||||
|
@ -440,7 +430,7 @@ em_toggle_overwrite(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
char *cp, *oldc, *dp;
|
||||||
|
|
||||||
|
@ -467,7 +457,7 @@ em_copy_prev_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_search.patlen = 0;
|
||||||
|
@ -480,9 +470,32 @@ em_inc_search_next(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_search.patlen = 0;
|
||||||
return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
|
return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* em_delete_prev_char():
|
||||||
|
* Delete the character to the left of the cursor
|
||||||
|
* [^?]
|
||||||
|
*/
|
||||||
|
protected el_action_t
|
||||||
|
/*ARGSUSED*/
|
||||||
|
em_delete_prev_char(EditLine *el, int c __attribute__((__unused__)))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (el->el_line.cursor <= el->el_line.buffer)
|
||||||
|
return (CC_ERROR);
|
||||||
|
|
||||||
|
if (el->el_state.doingarg)
|
||||||
|
c_delbefore(el, el->el_state.argument);
|
||||||
|
else
|
||||||
|
c_delbefore1(el);
|
||||||
|
el->el_line.cursor -= el->el_state.argument;
|
||||||
|
if (el->el_line.cursor < el->el_line.buffer)
|
||||||
|
el->el_line.cursor = el->el_line.buffer;
|
||||||
|
return (CC_REFRESH);
|
||||||
|
}
|
||||||
|
|
|
@ -1,109 +1,88 @@
|
||||||
|
/* $NetBSD: fgetln.c,v 1.2 2003/12/10 01:30:27 lukem Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by Christos Zoulas.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 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 NetBSD
|
||||||
|
* Foundation, Inc. and its contributors.
|
||||||
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "compat.h"
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef HAVE_FGETLN
|
|
||||||
|
|
||||||
#ifdef HAVE_GETLINE
|
char *
|
||||||
|
fgetln(FILE *fp, size_t *len)
|
||||||
extern int getline (char **lineptr, size_t *n, FILE *stream);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The interface here is that of GNU libc's getline */
|
|
||||||
static int
|
|
||||||
getline (char **lineptr, size_t *n, FILE *stream)
|
|
||||||
{
|
{
|
||||||
#define EXPAND_CHUNK 16
|
static char *buf = NULL;
|
||||||
|
static size_t bufsiz = 0;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
int n_read = 0;
|
|
||||||
char *line = *lineptr;
|
|
||||||
|
|
||||||
if (lineptr == NULL) return -1;
|
if (buf == NULL) {
|
||||||
if (n == NULL) return -1;
|
bufsiz = BUFSIZ;
|
||||||
if (stream == NULL) return -1;
|
if ((buf = malloc(bufsiz)) == NULL)
|
||||||
if (*lineptr == NULL || *n == 0) return -1;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FLOCKFILE
|
if (fgets(buf, bufsiz, fp) == NULL)
|
||||||
flockfile (stream);
|
return NULL;
|
||||||
#endif
|
*len = 0;
|
||||||
|
|
||||||
while (1)
|
while ((ptr = strchr(&buf[*len], '\n')) == NULL) {
|
||||||
{
|
size_t nbufsiz = bufsiz + BUFSIZ;
|
||||||
int c;
|
char *nbuf = realloc(buf, nbufsiz);
|
||||||
|
|
||||||
#ifdef HAVE_FLOCKFILE
|
if (nbuf == NULL) {
|
||||||
c = getc_unlocked (stream);
|
int oerrno = errno;
|
||||||
#else
|
free(buf);
|
||||||
c = getc (stream);
|
errno = oerrno;
|
||||||
#endif
|
buf = NULL;
|
||||||
|
return NULL;
|
||||||
|
} else
|
||||||
|
buf = nbuf;
|
||||||
|
|
||||||
if (c == EOF)
|
*len = bufsiz;
|
||||||
{
|
if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL)
|
||||||
if (n_read > 0)
|
return buf;
|
||||||
line[n_read] = '\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n_read + 2 >= *n)
|
bufsiz = nbufsiz;
|
||||||
{
|
}
|
||||||
size_t new_size;
|
|
||||||
|
|
||||||
if (*n == 0)
|
*len = (ptr - buf) + 1;
|
||||||
new_size = 16;
|
return buf;
|
||||||
else
|
|
||||||
new_size = *n * 2;
|
|
||||||
|
|
||||||
if (*n >= new_size) /* Overflowed size_t */
|
|
||||||
line = NULL;
|
|
||||||
else
|
|
||||||
line = (char *) (*lineptr ? (char*) realloc(*lineptr, new_size) :
|
|
||||||
(char*) malloc(new_size));
|
|
||||||
|
|
||||||
if (line)
|
|
||||||
{
|
|
||||||
*lineptr = line;
|
|
||||||
*n = new_size;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (*n > 0)
|
|
||||||
{
|
|
||||||
(*lineptr)[*n - 1] = '\0';
|
|
||||||
n_read = *n - 2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
line[n_read] = c;
|
|
||||||
n_read++;
|
|
||||||
|
|
||||||
if (c == '\n')
|
|
||||||
{
|
|
||||||
line[n_read] = '\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_FLOCKFILE
|
|
||||||
funlockfile (stream);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return n_read - 1;
|
|
||||||
}
|
}
|
||||||
#endif /* ! HAVE_GETLINE */
|
|
||||||
|
|
||||||
char *fgetln(FILE *stream, size_t *len)
|
|
||||||
{
|
|
||||||
char *ptr = NULL;
|
|
||||||
int sz;
|
|
||||||
size_t length= 0;
|
|
||||||
|
|
||||||
sz = getline(&ptr, &length, stream);
|
|
||||||
if(len) {
|
|
||||||
*len = sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sz >= 0 ? ptr : NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: hist.c,v 1.12 2003/01/21 18:40:23 christos Exp $ */
|
/* $NetBSD: hist.c,v 1.15 2003/11/01 23:36:39 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* hist.c: History access functions
|
* hist.c: History access functions
|
||||||
|
@ -157,7 +146,6 @@ hist_get(EditLine *el)
|
||||||
* process a history command
|
* process a history command
|
||||||
*/
|
*/
|
||||||
protected int
|
protected int
|
||||||
/*ARGSUSED*/
|
|
||||||
hist_command(EditLine *el, int argc, const char **argv)
|
hist_command(EditLine *el, int argc, const char **argv)
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
|
@ -167,7 +155,7 @@ hist_command(EditLine *el, int argc, const char **argv)
|
||||||
if (el->el_history.ref == NULL)
|
if (el->el_history.ref == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (argc == 0 || strcmp(argv[0], "list") == 1) {
|
if (argc == 1 || strcmp(argv[1], "list") == 0) {
|
||||||
/* List history entries */
|
/* List history entries */
|
||||||
|
|
||||||
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
|
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
|
||||||
|
@ -176,15 +164,15 @@ hist_command(EditLine *el, int argc, const char **argv)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 3)
|
||||||
return (-1);
|
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);
|
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 history(el->el_history.ref, &ev, H_SETUNIQUE, num);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: hist.h,v 1.9 2003/01/21 18:40:23 christos Exp $ */
|
/* $NetBSD: hist.h,v 1.10 2003/08/07 16:44:31 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: histedit.h,v 1.21 2003/01/21 18:40:24 christos Exp $ */
|
/* $NetBSD: histedit.h,v 1.25 2003/12/05 13:37:48 lukem Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -45,7 +41,7 @@
|
||||||
#define _HISTEDIT_H_
|
#define _HISTEDIT_H_
|
||||||
|
|
||||||
#define LIBEDIT_MAJOR 2
|
#define LIBEDIT_MAJOR 2
|
||||||
#define LIBEDIT_MINOR 6
|
#define LIBEDIT_MINOR 9
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -53,6 +49,7 @@
|
||||||
/*
|
/*
|
||||||
* ==== Editing ====
|
* ==== Editing ====
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct editline EditLine;
|
typedef struct editline EditLine;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -64,7 +61,6 @@ typedef struct lineinfo {
|
||||||
const char *lastchar;
|
const char *lastchar;
|
||||||
} LineInfo;
|
} LineInfo;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* EditLine editor function return codes.
|
* EditLine editor function return codes.
|
||||||
* For user-defined function interface
|
* For user-defined function interface
|
||||||
|
@ -84,9 +80,8 @@ typedef struct lineinfo {
|
||||||
* Initialization, cleanup, and resetting
|
* Initialization, cleanup, and resetting
|
||||||
*/
|
*/
|
||||||
EditLine *el_init(const char *, FILE *, FILE *, FILE *);
|
EditLine *el_init(const char *, FILE *, FILE *, FILE *);
|
||||||
void el_reset(EditLine *);
|
|
||||||
void el_end(EditLine *);
|
void el_end(EditLine *);
|
||||||
|
void el_reset(EditLine *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a line, a character or push a string back in the input queue
|
* Get a line, a character or push a string back in the input queue
|
||||||
|
@ -131,6 +126,8 @@ int el_get(EditLine *, int, void *);
|
||||||
#define EL_RPROMPT 12 /* , el_pfunc_t); */
|
#define EL_RPROMPT 12 /* , el_pfunc_t); */
|
||||||
#define EL_GETCFN 13 /* , el_rfunc_t); */
|
#define EL_GETCFN 13 /* , el_rfunc_t); */
|
||||||
#define EL_CLIENTDATA 14 /* , void *); */
|
#define EL_CLIENTDATA 14 /* , void *); */
|
||||||
|
#define EL_UNBUFFERED 15 /* , int); */
|
||||||
|
#define EL_PREP_TERM 16 /* , int); */
|
||||||
|
|
||||||
#define EL_BUILTIN_GETCFN (NULL)
|
#define EL_BUILTIN_GETCFN (NULL)
|
||||||
|
|
||||||
|
@ -146,7 +143,6 @@ int el_source(EditLine *, const char *);
|
||||||
*/
|
*/
|
||||||
void el_resize(EditLine *);
|
void el_resize(EditLine *);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* User-defined function interface.
|
* User-defined function interface.
|
||||||
*/
|
*/
|
||||||
|
@ -154,6 +150,7 @@ const LineInfo *el_line(EditLine *);
|
||||||
int el_insertstr(EditLine *, const char *);
|
int el_insertstr(EditLine *, const char *);
|
||||||
void el_deletestr(EditLine *, int);
|
void el_deletestr(EditLine *, int);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ==== History ====
|
* ==== History ====
|
||||||
*/
|
*/
|
||||||
|
@ -196,4 +193,22 @@ int history(History *, HistEvent *, int, ...);
|
||||||
#define H_SETUNIQUE 20 /* , int); */
|
#define H_SETUNIQUE 20 /* , int); */
|
||||||
#define H_GETUNIQUE 21 /* , void); */
|
#define H_GETUNIQUE 21 /* , void); */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ==== Tokenization ====
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct tokenizer Tokenizer;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* String tokenization functions, using simplified sh(1) quoting rules
|
||||||
|
*/
|
||||||
|
Tokenizer *tok_init(const char *);
|
||||||
|
void tok_end(Tokenizer *);
|
||||||
|
void tok_reset(Tokenizer *);
|
||||||
|
int tok_line(Tokenizer *, const LineInfo *,
|
||||||
|
int *, const char ***, int *, int *);
|
||||||
|
int tok_str(Tokenizer *, const char *,
|
||||||
|
int *, const char ***);
|
||||||
|
|
||||||
#endif /* _HISTEDIT_H_ */
|
#endif /* _HISTEDIT_H_ */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: history.c,v 1.22 2003/01/21 18:40:24 christos Exp $ */
|
/* $NetBSD: history.c,v 1.28 2004/11/27 18:31:45 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* hist.c: History access functions
|
* hist.c: History access functions
|
||||||
|
@ -51,11 +40,7 @@ __RCSID("$NetBSD: history.c,v 1.22 2003/01/21 18:40:24 christos Exp $");
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#ifdef HAVE_VIS_H
|
|
||||||
#include <vis.h>
|
#include <vis.h>
|
||||||
#else
|
|
||||||
#include "np/vis.h"
|
|
||||||
#endif
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
static const char hist_cookie[] = "_HiStOrY_V2_\n";
|
static const char hist_cookie[] = "_HiStOrY_V2_\n";
|
||||||
|
@ -91,6 +76,7 @@ struct history {
|
||||||
#define HENTER(h, ev, str) (*(h)->h_enter)((h)->h_ref, ev, str)
|
#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 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_malloc(a) malloc(a)
|
||||||
#define h_realloc(a, b) realloc((a), (b))
|
#define h_realloc(a, b) realloc((a), (b))
|
||||||
#define h_free(a) free(a)
|
#define h_free(a) free(a)
|
||||||
|
@ -249,20 +235,19 @@ history_def_next(ptr_t p, HistEvent *ev)
|
||||||
{
|
{
|
||||||
history_t *h = (history_t *) p;
|
history_t *h = (history_t *) p;
|
||||||
|
|
||||||
if (h->cursor != &h->list)
|
if (h->cursor == &h->list) {
|
||||||
h->cursor = h->cursor->next;
|
|
||||||
else {
|
|
||||||
he_seterrev(ev, _HE_EMPTY_LIST);
|
he_seterrev(ev, _HE_EMPTY_LIST);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h->cursor != &h->list)
|
if (h->cursor->next == &h->list) {
|
||||||
*ev = h->cursor->ev;
|
|
||||||
else {
|
|
||||||
he_seterrev(ev, _HE_END_REACHED);
|
he_seterrev(ev, _HE_END_REACHED);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h->cursor = h->cursor->next;
|
||||||
|
*ev = h->cursor->ev;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,21 +260,20 @@ history_def_prev(ptr_t p, HistEvent *ev)
|
||||||
{
|
{
|
||||||
history_t *h = (history_t *) p;
|
history_t *h = (history_t *) p;
|
||||||
|
|
||||||
if (h->cursor != &h->list)
|
if (h->cursor == &h->list) {
|
||||||
h->cursor = h->cursor->prev;
|
|
||||||
else {
|
|
||||||
he_seterrev(ev,
|
he_seterrev(ev,
|
||||||
(h->cur > 0) ? _HE_END_REACHED : _HE_EMPTY_LIST);
|
(h->cur > 0) ? _HE_END_REACHED : _HE_EMPTY_LIST);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h->cursor != &h->list)
|
if (h->cursor->prev == &h->list) {
|
||||||
*ev = h->cursor->ev;
|
|
||||||
else {
|
|
||||||
he_seterrev(ev, _HE_START_REACHED);
|
he_seterrev(ev, _HE_START_REACHED);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h->cursor = h->cursor->prev;
|
||||||
|
*ev = h->cursor->ev;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +358,8 @@ history_def_add(ptr_t p, HistEvent *ev, const char *str)
|
||||||
*/
|
*/
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
private void
|
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;
|
HistEventPrivate *evp = (void *)&hp->ev;
|
||||||
if (hp == &h->list)
|
if (hp == &h->list)
|
||||||
|
@ -397,7 +382,7 @@ history_def_insert(history_t *h, HistEvent *ev, const char *str)
|
||||||
h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t));
|
h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t));
|
||||||
if (h->cursor == NULL)
|
if (h->cursor == NULL)
|
||||||
goto oomem;
|
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);
|
h_free((ptr_t)h->cursor);
|
||||||
goto oomem;
|
goto oomem;
|
||||||
}
|
}
|
||||||
|
@ -447,7 +432,7 @@ history_def_enter(ptr_t p, HistEvent *ev, const char *str)
|
||||||
*/
|
*/
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
private int
|
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));
|
history_t *h = (history_t *) h_malloc(sizeof(history_t));
|
||||||
if (h == NULL)
|
if (h == NULL)
|
||||||
|
@ -661,6 +646,12 @@ history_load(History *h, const char *fname)
|
||||||
if ((fp = fopen(fname, "r")) == NULL)
|
if ((fp = fopen(fname, "r")) == NULL)
|
||||||
return (i);
|
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);
|
ptr = h_malloc(max_size = 1024);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -674,7 +665,7 @@ history_load(History *h, const char *fname)
|
||||||
|
|
||||||
if (max_size < sz) {
|
if (max_size < sz) {
|
||||||
char *nptr;
|
char *nptr;
|
||||||
max_size = (sz + 1023) & ~1023;
|
max_size = (sz + 1024) & ~1023;
|
||||||
nptr = h_realloc(ptr, max_size);
|
nptr = h_realloc(ptr, max_size);
|
||||||
if (nptr == NULL) {
|
if (nptr == NULL) {
|
||||||
i = -1;
|
i = -1;
|
||||||
|
@ -714,16 +705,18 @@ history_save(History *h, const char *fname)
|
||||||
|
|
||||||
if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
|
if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
|
||||||
goto done;
|
goto done;
|
||||||
|
if (fputs(hist_cookie, fp) == EOF)
|
||||||
|
goto done;
|
||||||
ptr = h_malloc(max_size = 1024);
|
ptr = h_malloc(max_size = 1024);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
for (i = 0, retval = HLAST(h, &ev);
|
for (i = 0, retval = HLAST(h, &ev);
|
||||||
retval != -1;
|
retval != -1;
|
||||||
retval = HPREV(h, &ev), i++) {
|
retval = HPREV(h, &ev), i++) {
|
||||||
len = strlen(ev.str) * 4 + 1;
|
len = strlen(ev.str) * 4;
|
||||||
if (len >= max_size) {
|
if (len >= max_size) {
|
||||||
char *nptr;
|
char *nptr;
|
||||||
max_size = (len + 1023) & ~1023;
|
max_size = (len + 1024) & ~1023;
|
||||||
nptr = h_realloc(ptr, max_size);
|
nptr = h_realloc(ptr, max_size);
|
||||||
if (nptr == NULL) {
|
if (nptr == NULL) {
|
||||||
i = -1;
|
i = -1;
|
||||||
|
@ -732,7 +725,7 @@ history_save(History *h, const char *fname)
|
||||||
ptr = nptr;
|
ptr = nptr;
|
||||||
}
|
}
|
||||||
(void) strvis(ptr, ev.str, VIS_WHITE);
|
(void) strvis(ptr, ev.str, VIS_WHITE);
|
||||||
(void) fprintf(fp, "%s\n", ev.str);
|
(void) fprintf(fp, "%s\n", ptr);
|
||||||
}
|
}
|
||||||
oomem:
|
oomem:
|
||||||
h_free((ptr_t)ptr);
|
h_free((ptr_t)ptr);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: key.c,v 1.13 2002/03/18 16:00:55 christos Exp $ */
|
/* $NetBSD: key.c,v 1.15 2003/10/18 23:48:42 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* key.c: This module contains the procedures for maintaining
|
* key.c: This module contains the procedures for maintaining
|
||||||
|
@ -103,14 +92,14 @@ private int key__decode_char(char *, int, int);
|
||||||
* Initialize the key maps
|
* Initialize the key maps
|
||||||
*/
|
*/
|
||||||
protected int
|
protected int
|
||||||
el_key_init(EditLine *el)
|
key_init(EditLine *el)
|
||||||
{
|
{
|
||||||
|
|
||||||
el->el_key.buf = (char *) el_malloc(KEY_BUFSIZ);
|
el->el_key.buf = (char *) el_malloc(KEY_BUFSIZ);
|
||||||
if (el->el_key.buf == NULL)
|
if (el->el_key.buf == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
el->el_key.map = NULL;
|
el->el_key.map = NULL;
|
||||||
el_key_reset(el);
|
key_reset(el);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +108,7 @@ el_key_init(EditLine *el)
|
||||||
* Free the key maps
|
* Free the key maps
|
||||||
*/
|
*/
|
||||||
protected void
|
protected void
|
||||||
el_key_end(EditLine *el)
|
key_end(EditLine *el)
|
||||||
{
|
{
|
||||||
|
|
||||||
el_free((ptr_t) el->el_key.buf);
|
el_free((ptr_t) el->el_key.buf);
|
||||||
|
@ -133,7 +122,7 @@ el_key_end(EditLine *el)
|
||||||
* Associate cmd with a key value
|
* Associate cmd with a key value
|
||||||
*/
|
*/
|
||||||
protected key_value_t *
|
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;
|
el->el_key.val.cmd = (el_action_t) cmd;
|
||||||
|
@ -145,7 +134,7 @@ el_key_map_cmd(EditLine *el, int cmd)
|
||||||
* Associate str with a key value
|
* Associate str with a key value
|
||||||
*/
|
*/
|
||||||
protected key_value_t *
|
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;
|
el->el_key.val.str = str;
|
||||||
|
@ -159,7 +148,7 @@ el_key_map_str(EditLine *el, char *str)
|
||||||
* [Always bind the ansi arrow keys?]
|
* [Always bind the ansi arrow keys?]
|
||||||
*/
|
*/
|
||||||
protected void
|
protected void
|
||||||
el_key_reset(EditLine *el)
|
key_reset(EditLine *el)
|
||||||
{
|
{
|
||||||
|
|
||||||
node__put(el, el->el_key.map);
|
node__put(el, el->el_key.map);
|
||||||
|
@ -177,7 +166,7 @@ el_key_reset(EditLine *el)
|
||||||
* The last character read is returned in *ch.
|
* The last character read is returned in *ch.
|
||||||
*/
|
*/
|
||||||
protected int
|
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));
|
return (node_trav(el, el->el_key.map, ch, val));
|
||||||
|
@ -191,7 +180,7 @@ el_key_get(EditLine *el, char *ch, key_value_t *val)
|
||||||
* out str or a unix command.
|
* out str or a unix command.
|
||||||
*/
|
*/
|
||||||
protected void
|
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') {
|
if (key[0] == '\0') {
|
||||||
|
@ -219,7 +208,7 @@ el_key_add(EditLine *el, const char *key, key_value_t *val, int ntype)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected void
|
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) &&
|
if ((map[(unsigned char)*in] == ED_SEQUENCE_LEAD_IN) &&
|
||||||
|
@ -227,7 +216,7 @@ el_key_clear(EditLine *el, el_action_t *map, const char *in)
|
||||||
el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) ||
|
el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) ||
|
||||||
(map == el->el_map.alt &&
|
(map == el->el_map.alt &&
|
||||||
el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN)))
|
el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN)))
|
||||||
(void) el_key_delete(el, in);
|
(void) key_delete(el, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,7 +225,7 @@ el_key_clear(EditLine *el, el_action_t *map, const char *in)
|
||||||
* they exists.
|
* they exists.
|
||||||
*/
|
*/
|
||||||
protected int
|
protected int
|
||||||
el_key_delete(EditLine *el, const char *key)
|
key_delete(EditLine *el, const char *key)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (key[0] == '\0') {
|
if (key[0] == '\0') {
|
||||||
|
@ -257,7 +246,7 @@ el_key_delete(EditLine *el, const char *key)
|
||||||
* Print entire el->el_key.map if null
|
* Print entire el->el_key.map if null
|
||||||
*/
|
*/
|
||||||
protected void
|
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 */
|
/* do nothing if el->el_key.map is empty and null key specified */
|
||||||
|
@ -356,7 +345,8 @@ node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int
|
||||||
break;
|
break;
|
||||||
case XK_STR:
|
case XK_STR:
|
||||||
case XK_EXE:
|
case XK_EXE:
|
||||||
ptr->val.str = strdup(val->str);
|
if ((ptr->val.str = el_strdup(val->str)) == NULL)
|
||||||
|
return -1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
|
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
|
||||||
|
@ -504,7 +494,7 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
|
||||||
if (str[1] == 0) {
|
if (str[1] == 0) {
|
||||||
el->el_key.buf[ncnt + 1] = '"';
|
el->el_key.buf[ncnt + 1] = '"';
|
||||||
el->el_key.buf[ncnt + 2] = '\0';
|
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);
|
&ptr->val, ptr->type);
|
||||||
return (0);
|
return (0);
|
||||||
} else
|
} else
|
||||||
|
@ -552,7 +542,7 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt)
|
||||||
/* print this key and function */
|
/* print this key and function */
|
||||||
el->el_key.buf[ncnt + 1] = '"';
|
el->el_key.buf[ncnt + 1] = '"';
|
||||||
el->el_key.buf[ncnt + 2] = '\0';
|
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
|
} else
|
||||||
(void) node_enum(el, ptr->next, ncnt + 1);
|
(void) node_enum(el, ptr->next, ncnt + 1);
|
||||||
|
|
||||||
|
@ -568,7 +558,7 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt)
|
||||||
* function specified by val
|
* function specified by val
|
||||||
*/
|
*/
|
||||||
protected void
|
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;
|
el_bindings_t *fp;
|
||||||
char unparsbuf[EL_BUFSIZ];
|
char unparsbuf[EL_BUFSIZ];
|
||||||
|
@ -579,7 +569,7 @@ el_key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
|
||||||
case XK_STR:
|
case XK_STR:
|
||||||
case XK_EXE:
|
case XK_EXE:
|
||||||
(void) fprintf(el->el_outfile, fmt, key,
|
(void) fprintf(el->el_outfile, fmt, key,
|
||||||
el_key__decode_str(val->str, unparsbuf,
|
key__decode_str(val->str, unparsbuf,
|
||||||
ntype == XK_STR ? "\"\"" : "[]"));
|
ntype == XK_STR ? "\"\"" : "[]"));
|
||||||
break;
|
break;
|
||||||
case XK_CMD:
|
case XK_CMD:
|
||||||
|
@ -644,7 +634,7 @@ key__decode_char(char *buf, int cnt, int ch)
|
||||||
* Make a printable version of the ey
|
* Make a printable version of the ey
|
||||||
*/
|
*/
|
||||||
protected char *
|
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;
|
char *b;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: key.h,v 1.6 2002/03/18 16:00:55 christos Exp $ */
|
/* $NetBSD: key.h,v 1.8 2003/08/07 16:44:32 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -62,19 +58,22 @@ typedef struct el_key_t {
|
||||||
#define XK_NOD 2
|
#define XK_NOD 2
|
||||||
#define XK_EXE 3
|
#define XK_EXE 3
|
||||||
|
|
||||||
protected int el_key_init(EditLine *);
|
#undef key_end
|
||||||
protected void el_key_end(EditLine *);
|
#undef key_clear
|
||||||
protected key_value_t *el_key_map_cmd(EditLine *, int);
|
#undef key_print
|
||||||
protected key_value_t *el_key_map_str(EditLine *, char *);
|
|
||||||
protected void el_key_reset(EditLine *);
|
protected int key_init(EditLine *);
|
||||||
protected int el_key_get(EditLine *, char *, key_value_t *);
|
protected void key_end(EditLine *);
|
||||||
protected void el_key_add(EditLine *,
|
protected key_value_t *key_map_cmd(EditLine *, int);
|
||||||
const char *, key_value_t *, int);
|
protected key_value_t *key_map_str(EditLine *, char *);
|
||||||
protected void el_key_clear(EditLine *, el_action_t *, const char *);
|
protected void key_reset(EditLine *);
|
||||||
protected int el_key_delete(EditLine *, const char *);
|
protected int key_get(EditLine *, char *, key_value_t *);
|
||||||
protected void el_key_print(EditLine *, const char *);
|
protected void key_add(EditLine *, const char *, key_value_t *, int);
|
||||||
protected void el_key_kprint(EditLine *, const char *, key_value_t *,
|
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);
|
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 */
|
#endif /* _h_el_key */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: map.c,v 1.18 2002/11/15 14:32:33 christos Exp $ */
|
/* $NetBSD: map.c,v 1.20 2004/08/13 12:10:39 mycroft Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* map.c: Editor function definitions
|
* map.c: Editor function definitions
|
||||||
|
@ -71,7 +60,7 @@ private const el_action_t el_map_emacs[] = {
|
||||||
/* 5 */ ED_MOVE_TO_END, /* ^E */
|
/* 5 */ ED_MOVE_TO_END, /* ^E */
|
||||||
/* 6 */ ED_NEXT_CHAR, /* ^F */
|
/* 6 */ ED_NEXT_CHAR, /* ^F */
|
||||||
/* 7 */ ED_UNASSIGNED, /* ^G */
|
/* 7 */ ED_UNASSIGNED, /* ^G */
|
||||||
/* 8 */ ED_DELETE_PREV_CHAR, /* ^H */
|
/* 8 */ EM_DELETE_PREV_CHAR, /* ^H */
|
||||||
/* 9 */ ED_UNASSIGNED, /* ^I */
|
/* 9 */ ED_UNASSIGNED, /* ^I */
|
||||||
/* 10 */ ED_NEWLINE, /* ^J */
|
/* 10 */ ED_NEWLINE, /* ^J */
|
||||||
/* 11 */ ED_KILL_LINE, /* ^K */
|
/* 11 */ ED_KILL_LINE, /* ^K */
|
||||||
|
@ -190,7 +179,7 @@ private const el_action_t el_map_emacs[] = {
|
||||||
/* 124 */ ED_INSERT, /* | */
|
/* 124 */ ED_INSERT, /* | */
|
||||||
/* 125 */ ED_INSERT, /* } */
|
/* 125 */ ED_INSERT, /* } */
|
||||||
/* 126 */ ED_INSERT, /* ~ */
|
/* 126 */ ED_INSERT, /* ~ */
|
||||||
/* 127 */ ED_DELETE_PREV_CHAR, /* ^? */
|
/* 127 */ EM_DELETE_PREV_CHAR, /* ^? */
|
||||||
/* 128 */ ED_UNASSIGNED, /* M-^@ */
|
/* 128 */ ED_UNASSIGNED, /* M-^@ */
|
||||||
/* 129 */ ED_UNASSIGNED, /* M-^A */
|
/* 129 */ ED_UNASSIGNED, /* M-^A */
|
||||||
/* 130 */ ED_UNASSIGNED, /* M-^B */
|
/* 130 */ ED_UNASSIGNED, /* M-^B */
|
||||||
|
@ -1011,8 +1000,7 @@ map_init_meta(EditLine *el)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
buf[1] = i & 0177;
|
buf[1] = i & 0177;
|
||||||
el_key_add(el, buf,
|
key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD);
|
||||||
el_key_map_cmd(el, (int) map[i]), XK_CMD);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
|
map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
|
||||||
|
@ -1034,7 +1022,7 @@ map_init_vi(EditLine *el)
|
||||||
el->el_map.type = MAP_VI;
|
el->el_map.type = MAP_VI;
|
||||||
el->el_map.current = el->el_map.key;
|
el->el_map.current = el->el_map.key;
|
||||||
|
|
||||||
el_key_reset(el);
|
key_reset(el);
|
||||||
|
|
||||||
for (i = 0; i < N_KEYS; i++) {
|
for (i = 0; i < N_KEYS; i++) {
|
||||||
key[i] = vii[i];
|
key[i] = vii[i];
|
||||||
|
@ -1063,7 +1051,7 @@ map_init_emacs(EditLine *el)
|
||||||
|
|
||||||
el->el_map.type = MAP_EMACS;
|
el->el_map.type = MAP_EMACS;
|
||||||
el->el_map.current = el->el_map.key;
|
el->el_map.current = el->el_map.key;
|
||||||
el_key_reset(el);
|
key_reset(el);
|
||||||
|
|
||||||
for (i = 0; i < N_KEYS; i++) {
|
for (i = 0; i < N_KEYS; i++) {
|
||||||
key[i] = emacs[i];
|
key[i] = emacs[i];
|
||||||
|
@ -1076,7 +1064,7 @@ map_init_emacs(EditLine *el)
|
||||||
buf[0] = CONTROL('X');
|
buf[0] = CONTROL('X');
|
||||||
buf[1] = CONTROL('X');
|
buf[1] = CONTROL('X');
|
||||||
buf[2] = 0;
|
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);
|
tty_bind_char(el, 1);
|
||||||
term_bind_arrow(el);
|
term_bind_arrow(el);
|
||||||
|
@ -1133,7 +1121,7 @@ map_print_key(EditLine *el, el_action_t *map, const char *in)
|
||||||
el_bindings_t *bp;
|
el_bindings_t *bp;
|
||||||
|
|
||||||
if (in[0] == '\0' || in[1] == '\0') {
|
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++)
|
for (bp = el->el_map.help; bp->name != NULL; bp++)
|
||||||
if (bp->func == map[(unsigned char) *in]) {
|
if (bp->func == map[(unsigned char) *in]) {
|
||||||
(void) fprintf(el->el_outfile,
|
(void) fprintf(el->el_outfile,
|
||||||
|
@ -1141,7 +1129,7 @@ map_print_key(EditLine *el, el_action_t *map, const char *in)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
el_key_print(el, in);
|
key_print(el, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1163,20 +1151,20 @@ map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
|
||||||
if (first == last)
|
if (first == last)
|
||||||
(void) fprintf(el->el_outfile,
|
(void) fprintf(el->el_outfile,
|
||||||
"%-15s-> is undefined\n",
|
"%-15s-> is undefined\n",
|
||||||
el_key__decode_str(firstbuf, unparsbuf, STRQQ));
|
key__decode_str(firstbuf, unparsbuf, STRQQ));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (bp = el->el_map.help; bp->name != NULL; bp++) {
|
for (bp = el->el_map.help; bp->name != NULL; bp++) {
|
||||||
if (bp->func == map[first]) {
|
if (bp->func == map[first]) {
|
||||||
if (first == last) {
|
if (first == last) {
|
||||||
(void) fprintf(el->el_outfile, "%-15s-> %s\n",
|
(void) fprintf(el->el_outfile, "%-15s-> %s\n",
|
||||||
el_key__decode_str(firstbuf, unparsbuf, STRQQ),
|
key__decode_str(firstbuf, unparsbuf, STRQQ),
|
||||||
bp->name);
|
bp->name);
|
||||||
} else {
|
} else {
|
||||||
(void) fprintf(el->el_outfile,
|
(void) fprintf(el->el_outfile,
|
||||||
"%-4s to %-7s-> %s\n",
|
"%-4s to %-7s-> %s\n",
|
||||||
el_key__decode_str(firstbuf, unparsbuf, STRQQ),
|
key__decode_str(firstbuf, unparsbuf, STRQQ),
|
||||||
el_key__decode_str(lastbuf, extrabuf, STRQQ),
|
key__decode_str(lastbuf, extrabuf, STRQQ),
|
||||||
bp->name);
|
bp->name);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -1230,7 +1218,7 @@ map_print_all_keys(EditLine *el)
|
||||||
map_print_some_keys(el, el->el_map.alt, prev, i - 1);
|
map_print_some_keys(el, el->el_map.alt, prev, i - 1);
|
||||||
|
|
||||||
(void) fprintf(el->el_outfile, "Multi-character bindings\n");
|
(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");
|
(void) fprintf(el->el_outfile, "Arrow key bindings\n");
|
||||||
term_print_arrow(el, "");
|
term_print_arrow(el, "");
|
||||||
}
|
}
|
||||||
|
@ -1323,9 +1311,9 @@ map_bind(EditLine *el, int argc, const char **argv)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (in[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)
|
else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
|
||||||
(void) el_key_delete(el, in);
|
(void) key_delete(el, in);
|
||||||
else
|
else
|
||||||
map[(unsigned char) *in] = ED_UNASSIGNED;
|
map[(unsigned char) *in] = ED_UNASSIGNED;
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -1353,9 +1341,9 @@ map_bind(EditLine *el, int argc, const char **argv)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (key)
|
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
|
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;
|
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1366,13 +1354,13 @@ map_bind(EditLine *el, int argc, const char **argv)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (key)
|
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 {
|
else {
|
||||||
if (in[1]) {
|
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;
|
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
|
||||||
} else {
|
} else {
|
||||||
el_key_clear(el, map, in);
|
key_clear(el, map, in);
|
||||||
map[(unsigned char) *in] = cmd;
|
map[(unsigned char) *in] = cmd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: map.h,v 1.7 2002/03/18 16:00:56 christos Exp $ */
|
/* $NetBSD: map.h,v 1.8 2003/08/07 16:44:32 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: parse.c,v 1.16 2003/01/21 18:40:24 christos Exp $ */
|
/* $NetBSD: parse.c,v 1.20 2003/12/05 13:37:48 lukem Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* parse.c: parse an editline extended command
|
* parse.c: parse an editline extended command
|
||||||
|
@ -59,7 +48,6 @@ __RCSID("$NetBSD: parse.c,v 1.16 2003/01/21 18:40:24 christos Exp $");
|
||||||
* setty
|
* setty
|
||||||
*/
|
*/
|
||||||
#include "el.h"
|
#include "el.h"
|
||||||
#include "tokenizer.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
private const struct {
|
private const struct {
|
||||||
|
@ -87,9 +75,8 @@ parse_line(EditLine *el, const char *line)
|
||||||
int argc;
|
int argc;
|
||||||
Tokenizer *tok;
|
Tokenizer *tok;
|
||||||
|
|
||||||
if (!(tok = tok_init(NULL)))
|
tok = tok_init(NULL);
|
||||||
return -1;
|
tok_str(tok, line, &argc, &argv);
|
||||||
tok_line(tok, line, &argc, &argv);
|
|
||||||
argc = el_parse(el, argc, argv);
|
argc = el_parse(el, argc, argv);
|
||||||
tok_end(tok);
|
tok_end(tok);
|
||||||
return (argc);
|
return (argc);
|
||||||
|
@ -207,7 +194,7 @@ parse__escape(const char **const ptr)
|
||||||
c = *p;
|
c = *p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (*p == '^' && isalpha((unsigned char) p[1])) {
|
} else if (*p == '^') {
|
||||||
p++;
|
p++;
|
||||||
c = (*p == '?') ? '\177' : (*p & 0237);
|
c = (*p == '?') ? '\177' : (*p & 0237);
|
||||||
} else
|
} else
|
||||||
|
@ -215,6 +202,7 @@ parse__escape(const char **const ptr)
|
||||||
*ptr = ++p;
|
*ptr = ++p;
|
||||||
return (c);
|
return (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse__string():
|
/* parse__string():
|
||||||
* Parse the escapes from in and put the raw string out
|
* Parse the escapes from in and put the raw string out
|
||||||
*/
|
*/
|
||||||
|
@ -237,6 +225,14 @@ parse__string(char *out, const char *in)
|
||||||
*out++ = n;
|
*out++ = n;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'M':
|
||||||
|
if (in[1] == '-' && in[2] != '\0') {
|
||||||
|
*out++ = '\033';
|
||||||
|
in += 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
|
||||||
default:
|
default:
|
||||||
*out++ = *in++;
|
*out++ = *in++;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: parse.h,v 1.4 2000/09/04 22:06:31 lukem Exp $ */
|
/* $NetBSD: parse.h,v 1.5 2003/08/07 16:44:32 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: prompt.c,v 1.9 2002/03/18 16:00:56 christos Exp $ */
|
/* $NetBSD: prompt.c,v 1.11 2003/08/07 16:44:32 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* prompt.c: Prompt printing functions
|
* prompt.c: Prompt printing functions
|
||||||
|
@ -59,7 +48,7 @@ private char *prompt_default_r(EditLine *);
|
||||||
*/
|
*/
|
||||||
private char *
|
private char *
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
prompt_default(EditLine *el __attribute__((unused)))
|
prompt_default(EditLine *el __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
static char a[3] = {'?', ' ', '\0'};
|
static char a[3] = {'?', ' ', '\0'};
|
||||||
|
|
||||||
|
@ -72,7 +61,7 @@ prompt_default(EditLine *el __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
private char *
|
private char *
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
prompt_default_r(EditLine *el __attribute__((unused)))
|
prompt_default_r(EditLine *el __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
static char a[1] = {'\0'};
|
static char a[1] = {'\0'};
|
||||||
|
|
||||||
|
@ -127,7 +116,7 @@ prompt_init(EditLine *el)
|
||||||
*/
|
*/
|
||||||
protected void
|
protected void
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
prompt_end(EditLine *el __attribute__((unused)))
|
prompt_end(EditLine *el __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: prompt.h,v 1.5 2000/09/04 22:06:31 lukem Exp $ */
|
/* $NetBSD: prompt.h,v 1.6 2003/08/07 16:44:32 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: read.c,v 1.24 2002/11/20 16:50:08 christos Exp $ */
|
/* $NetBSD: read.c,v 1.35 2005/03/09 23:55:02 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,20 +32,14 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* read.c: Clean this junk up! This is horrible code.
|
* read.c: Clean this junk up! This is horrible code.
|
||||||
* Terminal read functions
|
* Terminal read functions
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "el.h"
|
#include "el.h"
|
||||||
|
@ -97,6 +87,10 @@ el_read_getfn(EditLine *el)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(A,B) ((A) < (B) ? (A) : (B))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG_EDIT
|
#ifdef DEBUG_EDIT
|
||||||
private void
|
private void
|
||||||
read_debug(EditLine *el)
|
read_debug(EditLine *el)
|
||||||
|
@ -121,11 +115,7 @@ read_debug(EditLine *el)
|
||||||
*/
|
*/
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
private int
|
private int
|
||||||
read__fixio(int fd
|
read__fixio(int fd __attribute__((__unused__)), int e)
|
||||||
#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)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (e) {
|
switch (e) {
|
||||||
|
@ -190,18 +180,10 @@ read_preread(EditLine *el)
|
||||||
{
|
{
|
||||||
int chrs = 0;
|
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)
|
if (el->el_tty.t_mode == ED_IO)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
#ifdef FIONREAD
|
#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);
|
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
|
||||||
if (chrs > 0) {
|
if (chrs > 0) {
|
||||||
char buf[EL_BUFSIZ];
|
char buf[EL_BUFSIZ];
|
||||||
|
@ -210,8 +192,7 @@ read_preread(EditLine *el)
|
||||||
(size_t) MIN(chrs, EL_BUFSIZ - 1));
|
(size_t) MIN(chrs, EL_BUFSIZ - 1));
|
||||||
if (chrs > 0) {
|
if (chrs > 0) {
|
||||||
buf[chrs] = '\0';
|
buf[chrs] = '\0';
|
||||||
el->el_chared.c_macro.nline = strdup(buf);
|
el_push(el, buf);
|
||||||
el_push(el, el->el_chared.c_macro.nline);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* FIONREAD */
|
#endif /* FIONREAD */
|
||||||
|
@ -230,11 +211,12 @@ el_push(EditLine *el, char *str)
|
||||||
|
|
||||||
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
|
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
|
||||||
ma->level++;
|
ma->level++;
|
||||||
ma->macro[ma->level] = str;
|
if ((ma->macro[ma->level] = el_strdup(str)) != NULL)
|
||||||
} else {
|
return;
|
||||||
term_beep(el);
|
ma->level--;
|
||||||
term__flush();
|
|
||||||
}
|
}
|
||||||
|
term_beep(el);
|
||||||
|
term__flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -266,7 +248,7 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
|
||||||
cmd = el->el_map.current[(unsigned char) *ch];
|
cmd = el->el_map.current[(unsigned char) *ch];
|
||||||
if (cmd == ED_SEQUENCE_LEAD_IN) {
|
if (cmd == ED_SEQUENCE_LEAD_IN) {
|
||||||
key_value_t val;
|
key_value_t val;
|
||||||
switch (el_key_get(el, ch, &val)) {
|
switch (key_get(el, ch, &val)) {
|
||||||
case XK_CMD:
|
case XK_CMD:
|
||||||
cmd = val.cmd;
|
cmd = val.cmd;
|
||||||
break;
|
break;
|
||||||
|
@ -331,14 +313,16 @@ el_getc(EditLine *el, char *cp)
|
||||||
if (ma->level < 0)
|
if (ma->level < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (*ma->macro[ma->level] == 0) {
|
if (ma->macro[ma->level][ma->offset] == '\0') {
|
||||||
ma->level--;
|
el_free(ma->macro[ma->level--]);
|
||||||
|
ma->offset = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*cp = *ma->macro[ma->level]++ & 0377;
|
*cp = ma->macro[ma->level][ma->offset++] & 0377;
|
||||||
if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode
|
if (ma->macro[ma->level][ma->offset] == '\0') {
|
||||||
* On */
|
/* Needed for QuoteMode On */
|
||||||
ma->level--;
|
el_free(ma->macro[ma->level--]);
|
||||||
|
ma->offset = 0;
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -359,6 +343,35 @@ el_getc(EditLine *el, char *cp)
|
||||||
return (num_read);
|
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 */
|
||||||
|
|
||||||
|
if (el->el_flags & UNBUFFERED)
|
||||||
|
term__flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 *
|
public const char *
|
||||||
el_gets(EditLine *el, int *nread)
|
el_gets(EditLine *el, int *nread)
|
||||||
|
@ -367,13 +380,11 @@ el_gets(EditLine *el, int *nread)
|
||||||
el_action_t cmdnum = 0;
|
el_action_t cmdnum = 0;
|
||||||
int num; /* how many chars we have read at NL */
|
int num; /* how many chars we have read at NL */
|
||||||
char ch;
|
char ch;
|
||||||
|
int crlf = 0;
|
||||||
#ifdef FIONREAD
|
#ifdef FIONREAD
|
||||||
c_macro_t *ma = &el->el_chared.c_macro;
|
c_macro_t *ma = &el->el_chared.c_macro;
|
||||||
#endif /* FIONREAD */
|
#endif /* FIONREAD */
|
||||||
|
|
||||||
if (el->el_flags & HANDLE_SIGNALS)
|
|
||||||
sig_set(el);
|
|
||||||
|
|
||||||
if (el->el_flags & NO_TTY) {
|
if (el->el_flags & NO_TTY) {
|
||||||
char *cp = el->el_line.buffer;
|
char *cp = el->el_line.buffer;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
|
@ -387,6 +398,8 @@ el_gets(EditLine *el, int *nread)
|
||||||
cp = &el->el_line.buffer[idx];
|
cp = &el->el_line.buffer[idx];
|
||||||
}
|
}
|
||||||
cp++;
|
cp++;
|
||||||
|
if (el->el_flags & UNBUFFERED)
|
||||||
|
break;
|
||||||
if (cp[-1] == '\r' || cp[-1] == '\n')
|
if (cp[-1] == '\r' || cp[-1] == '\n')
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -398,12 +411,6 @@ el_gets(EditLine *el, int *nread)
|
||||||
return (el->el_line.buffer);
|
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
|
#ifdef FIONREAD
|
||||||
if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
|
if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
|
||||||
|
@ -420,11 +427,16 @@ el_gets(EditLine *el, int *nread)
|
||||||
}
|
}
|
||||||
#endif /* FIONREAD */
|
#endif /* FIONREAD */
|
||||||
|
|
||||||
re_refresh(el); /* print the prompt */
|
if ((el->el_flags & UNBUFFERED) == 0)
|
||||||
|
read_prepare(el);
|
||||||
|
|
||||||
if (el->el_flags & EDIT_DISABLED) {
|
if (el->el_flags & EDIT_DISABLED) {
|
||||||
char *cp = el->el_line.buffer;
|
char *cp;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
|
if ((el->el_flags & UNBUFFERED) == 0)
|
||||||
|
cp = el->el_line.buffer;
|
||||||
|
else
|
||||||
|
cp = el->el_line.lastchar;
|
||||||
|
|
||||||
term__flush();
|
term__flush();
|
||||||
|
|
||||||
|
@ -439,7 +451,10 @@ el_gets(EditLine *el, int *nread)
|
||||||
if (*cp == 4) /* ought to be stty eof */
|
if (*cp == 4) /* ought to be stty eof */
|
||||||
break;
|
break;
|
||||||
cp++;
|
cp++;
|
||||||
if (cp[-1] == '\r' || cp[-1] == '\n')
|
crlf = cp[-1] == '\r' || cp[-1] == '\n';
|
||||||
|
if (el->el_flags & UNBUFFERED)
|
||||||
|
break;
|
||||||
|
if (crlf)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,8 +478,7 @@ el_gets(EditLine *el, int *nread)
|
||||||
#endif /* DEBUG_READ */
|
#endif /* DEBUG_READ */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((unsigned int)cmdnum >= (unsigned int)(el->el_map.nfunc))
|
if ((uint)cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
|
||||||
{ /* BUG CHECK command */
|
|
||||||
#ifdef DEBUG_EDIT
|
#ifdef DEBUG_EDIT
|
||||||
(void) fprintf(el->el_errfile,
|
(void) fprintf(el->el_errfile,
|
||||||
"ERROR: illegal command from key 0%o\r\n", ch);
|
"ERROR: illegal command from key 0%o\r\n", ch);
|
||||||
|
@ -494,7 +508,7 @@ el_gets(EditLine *el, int *nread)
|
||||||
el->el_chared.c_redo.pos < el->el_chared.c_redo.lim) {
|
el->el_chared.c_redo.pos < el->el_chared.c_redo.lim) {
|
||||||
if (cmdnum == VI_DELETE_PREV_CHAR &&
|
if (cmdnum == VI_DELETE_PREV_CHAR &&
|
||||||
el->el_chared.c_redo.pos != el->el_chared.c_redo.buf
|
el->el_chared.c_redo.pos != el->el_chared.c_redo.buf
|
||||||
&& isprint(el->el_chared.c_redo.pos[-1]))
|
&& isprint((unsigned char)el->el_chared.c_redo.pos[-1]))
|
||||||
el->el_chared.c_redo.pos--;
|
el->el_chared.c_redo.pos--;
|
||||||
else
|
else
|
||||||
*el->el_chared.c_redo.pos++ = ch;
|
*el->el_chared.c_redo.pos++ = ch;
|
||||||
|
@ -536,7 +550,13 @@ el_gets(EditLine *el, int *nread)
|
||||||
continue; /* keep going... */
|
continue; /* keep going... */
|
||||||
|
|
||||||
case CC_EOF: /* end of file typed */
|
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++ = CONTROL('d');
|
||||||
|
el->el_line.cursor = el->el_line.lastchar;
|
||||||
|
num = 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CC_NEWLINE: /* normal end of line */
|
case CC_NEWLINE: /* normal end of line */
|
||||||
|
@ -567,14 +587,19 @@ el_gets(EditLine *el, int *nread)
|
||||||
el->el_state.argument = 1;
|
el->el_state.argument = 1;
|
||||||
el->el_state.doingarg = 0;
|
el->el_state.doingarg = 0;
|
||||||
el->el_chared.c_vcmd.action = NOP;
|
el->el_chared.c_vcmd.action = NOP;
|
||||||
|
if (el->el_flags & UNBUFFERED)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
term__flush(); /* flush any buffered output */
|
term__flush(); /* flush any buffered output */
|
||||||
/* make sure the tty is set up correctly */
|
/* make sure the tty is set up correctly */
|
||||||
(void) tty_cookedmode(el);
|
if ((el->el_flags & UNBUFFERED) == 0) {
|
||||||
if (el->el_flags & HANDLE_SIGNALS)
|
read_finish(el);
|
||||||
sig_clr(el);
|
if (nread)
|
||||||
if (nread)
|
*nread = num;
|
||||||
*nread = num;
|
} else {
|
||||||
|
if (nread)
|
||||||
|
*nread = el->el_line.lastchar - el->el_line.buffer;
|
||||||
|
}
|
||||||
return (num ? el->el_line.buffer : NULL);
|
return (num ? el->el_line.buffer : NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: read.h,v 1.1 2001/09/27 19:29:50 christos Exp $ */
|
/* $NetBSD: read.h,v 1.4 2004/02/27 14:52:18 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||||
|
@ -49,6 +49,8 @@ typedef struct el_read_t {
|
||||||
} el_read_t;
|
} el_read_t;
|
||||||
|
|
||||||
protected int read_init(EditLine *);
|
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 int el_read_setfn(EditLine *, el_rfunc_t);
|
||||||
protected el_rfunc_t el_read_getfn(EditLine *);
|
protected el_rfunc_t el_read_getfn(EditLine *);
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: refresh.c,v 1.24 2003/03/10 21:18:49 christos Exp $ */
|
/* $NetBSD: refresh.c,v 1.26 2003/08/07 16:44:33 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* refresh.c: Lower level screen refreshing functions
|
* refresh.c: Lower level screen refreshing functions
|
||||||
|
@ -57,8 +46,8 @@ __RCSID("$NetBSD: refresh.c,v 1.24 2003/03/10 21:18:49 christos Exp $");
|
||||||
|
|
||||||
private void re_addc(EditLine *, int);
|
private void re_addc(EditLine *, int);
|
||||||
private void re_update_line(EditLine *, char *, char *, int);
|
private void re_update_line(EditLine *, char *, char *, int);
|
||||||
private void re_insert (EditLine *el, char *, int, int, char *, int);
|
private void re_insert (EditLine *, char *, int, int, char *, int);
|
||||||
private void re_delete(EditLine *el, char *, int, int, int);
|
private void re_delete(EditLine *, char *, int, int, int);
|
||||||
private void re_fastputc(EditLine *, int);
|
private void re_fastputc(EditLine *, int);
|
||||||
private void re__strncopy(char *, char *, size_t);
|
private void re__strncopy(char *, char *, size_t);
|
||||||
private void re__copy_and_pad(char *, const char *, size_t);
|
private void re__copy_and_pad(char *, const char *, size_t);
|
||||||
|
@ -338,8 +327,8 @@ re_goto_bottom(EditLine *el)
|
||||||
*/
|
*/
|
||||||
private void
|
private void
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
re_insert(EditLine *el __attribute__((unused)),
|
re_insert(EditLine *el __attribute__((__unused__)),
|
||||||
char *d, int dat, int dlen, char *s, int num)
|
char *d, int dat, int dlen, char *s, int num)
|
||||||
{
|
{
|
||||||
char *a, *b;
|
char *a, *b;
|
||||||
|
|
||||||
|
@ -382,8 +371,8 @@ re_insert(EditLine *el __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
private void
|
private void
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
re_delete(EditLine *el __attribute__((unused)),
|
re_delete(EditLine *el __attribute__((__unused__)),
|
||||||
char *d, int dat, int dlen, int num)
|
char *d, int dat, int dlen, int num)
|
||||||
{
|
{
|
||||||
char *a, *b;
|
char *a, *b;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: refresh.h,v 1.4 2001/01/10 07:45:42 jdolecek Exp $ */
|
/* $NetBSD: refresh.h,v 1.5 2003/08/07 16:44:33 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: search.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */
|
/* $NetBSD: search.c,v 1.20 2004/11/04 01:16:03 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,21 +32,13 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* search.c: History and character search functions
|
* search.c: History and character search functions
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#if defined(REGEX)
|
#if defined(REGEX)
|
||||||
#include <sys/types.h>
|
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#elif defined(REGEXP)
|
#elif defined(REGEXP)
|
||||||
#include <regexp.h>
|
#include <regexp.h>
|
||||||
|
@ -227,8 +215,11 @@ ce_inc_search(EditLine *el, int dir)
|
||||||
if (el->el_search.patlen == 0) { /* first round */
|
if (el->el_search.patlen == 0) { /* first round */
|
||||||
pchar = ':';
|
pchar = ':';
|
||||||
#ifdef ANCHOR
|
#ifdef ANCHOR
|
||||||
|
#define LEN 2
|
||||||
el->el_search.patbuf[el->el_search.patlen++] = '.';
|
el->el_search.patbuf[el->el_search.patlen++] = '.';
|
||||||
el->el_search.patbuf[el->el_search.patlen++] = '*';
|
el->el_search.patbuf[el->el_search.patlen++] = '*';
|
||||||
|
#else
|
||||||
|
#define LEN 0
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
done = redo = 0;
|
done = redo = 0;
|
||||||
|
@ -237,7 +228,7 @@ ce_inc_search(EditLine *el, int dir)
|
||||||
*cp; *el->el_line.lastchar++ = *cp++)
|
*cp; *el->el_line.lastchar++ = *cp++)
|
||||||
continue;
|
continue;
|
||||||
*el->el_line.lastchar++ = pchar;
|
*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];
|
cp < &el->el_search.patbuf[el->el_search.patlen];
|
||||||
*el->el_line.lastchar++ = *cp++)
|
*el->el_line.lastchar++ = *cp++)
|
||||||
continue;
|
continue;
|
||||||
|
@ -250,7 +241,7 @@ ce_inc_search(EditLine *el, int dir)
|
||||||
switch (el->el_map.current[(unsigned char) ch]) {
|
switch (el->el_map.current[(unsigned char) ch]) {
|
||||||
case ED_INSERT:
|
case ED_INSERT:
|
||||||
case ED_DIGIT:
|
case ED_DIGIT:
|
||||||
if (el->el_search.patlen > EL_BUFSIZ - 3)
|
if (el->el_search.patlen >= EL_BUFSIZ - LEN)
|
||||||
term_beep(el);
|
term_beep(el);
|
||||||
else {
|
else {
|
||||||
el->el_search.patbuf[el->el_search.patlen++] =
|
el->el_search.patbuf[el->el_search.patlen++] =
|
||||||
|
@ -271,8 +262,9 @@ ce_inc_search(EditLine *el, int dir)
|
||||||
redo++;
|
redo++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EM_DELETE_PREV_CHAR:
|
||||||
case ED_DELETE_PREV_CHAR:
|
case ED_DELETE_PREV_CHAR:
|
||||||
if (el->el_search.patlen > 1)
|
if (el->el_search.patlen > LEN)
|
||||||
done++;
|
done++;
|
||||||
else
|
else
|
||||||
term_beep(el);
|
term_beep(el);
|
||||||
|
@ -287,17 +279,18 @@ ce_inc_search(EditLine *el, int dir)
|
||||||
|
|
||||||
case 0027: /* ^W: Append word */
|
case 0027: /* ^W: Append word */
|
||||||
/* No can do if globbing characters in pattern */
|
/* No can do if globbing characters in pattern */
|
||||||
for (cp = &el->el_search.patbuf[1];; cp++)
|
for (cp = &el->el_search.patbuf[LEN];; cp++)
|
||||||
if (cp >= &el->el_search.patbuf[el->el_search.patlen]) {
|
if (cp >= &el->el_search.patbuf[
|
||||||
|
el->el_search.patlen]) {
|
||||||
el->el_line.cursor +=
|
el->el_line.cursor +=
|
||||||
el->el_search.patlen - 1;
|
el->el_search.patlen - LEN - 1;
|
||||||
cp = c__next_word(el->el_line.cursor,
|
cp = c__next_word(el->el_line.cursor,
|
||||||
el->el_line.lastchar, 1,
|
el->el_line.lastchar, 1,
|
||||||
ce__isword);
|
ce__isword);
|
||||||
while (el->el_line.cursor < cp &&
|
while (el->el_line.cursor < cp &&
|
||||||
*el->el_line.cursor != '\n') {
|
*el->el_line.cursor != '\n') {
|
||||||
if (el->el_search.patlen >
|
if (el->el_search.patlen >=
|
||||||
EL_BUFSIZ - 3) {
|
EL_BUFSIZ - LEN) {
|
||||||
term_beep(el);
|
term_beep(el);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -339,13 +332,13 @@ ce_inc_search(EditLine *el, int dir)
|
||||||
/* Can't search if unmatched '[' */
|
/* Can't search if unmatched '[' */
|
||||||
for (cp = &el->el_search.patbuf[el->el_search.patlen-1],
|
for (cp = &el->el_search.patbuf[el->el_search.patlen-1],
|
||||||
ch = ']';
|
ch = ']';
|
||||||
cp > el->el_search.patbuf;
|
cp >= &el->el_search.patbuf[LEN];
|
||||||
cp--)
|
cp--)
|
||||||
if (*cp == '[' || *cp == ']') {
|
if (*cp == '[' || *cp == ']') {
|
||||||
ch = *cp;
|
ch = *cp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (el->el_search.patlen > 1 && ch != '[') {
|
if (el->el_search.patlen > LEN && ch != '[') {
|
||||||
if (redo && newdir == dir) {
|
if (redo && newdir == dir) {
|
||||||
if (pchar == '?') { /* wrap around */
|
if (pchar == '?') { /* wrap around */
|
||||||
el->el_history.eventno =
|
el->el_history.eventno =
|
||||||
|
@ -375,9 +368,8 @@ ce_inc_search(EditLine *el, int dir)
|
||||||
'\0';
|
'\0';
|
||||||
if (el->el_line.cursor < el->el_line.buffer ||
|
if (el->el_line.cursor < el->el_line.buffer ||
|
||||||
el->el_line.cursor > el->el_line.lastchar ||
|
el->el_line.cursor > el->el_line.lastchar ||
|
||||||
(ret = ce_search_line(el,
|
(ret = ce_search_line(el, newdir))
|
||||||
&el->el_search.patbuf[1],
|
== CC_ERROR) {
|
||||||
newdir)) == CC_ERROR) {
|
|
||||||
/* avoid c_setpat */
|
/* avoid c_setpat */
|
||||||
el->el_state.lastcmd =
|
el->el_state.lastcmd =
|
||||||
(el_action_t) newdir;
|
(el_action_t) newdir;
|
||||||
|
@ -390,11 +382,11 @@ ce_inc_search(EditLine *el, int dir)
|
||||||
el->el_line.lastchar :
|
el->el_line.lastchar :
|
||||||
el->el_line.buffer;
|
el->el_line.buffer;
|
||||||
(void) ce_search_line(el,
|
(void) ce_search_line(el,
|
||||||
&el->el_search.patbuf[1],
|
|
||||||
newdir);
|
newdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
el->el_search.patbuf[--el->el_search.patlen] =
|
el->el_search.patlen -= LEN;
|
||||||
|
el->el_search.patbuf[el->el_search.patlen] =
|
||||||
'\0';
|
'\0';
|
||||||
if (ret == CC_ERROR) {
|
if (ret == CC_ERROR) {
|
||||||
term_beep(el);
|
term_beep(el);
|
||||||
|
@ -453,9 +445,6 @@ cv_search(EditLine *el, int dir)
|
||||||
#ifdef ANCHOR
|
#ifdef ANCHOR
|
||||||
tmpbuf[0] = '.';
|
tmpbuf[0] = '.';
|
||||||
tmpbuf[1] = '*';
|
tmpbuf[1] = '*';
|
||||||
#define LEN 2
|
|
||||||
#else
|
|
||||||
#define LEN 0
|
|
||||||
#endif
|
#endif
|
||||||
tmplen = LEN;
|
tmplen = LEN;
|
||||||
|
|
||||||
|
@ -521,24 +510,39 @@ cv_search(EditLine *el, int dir)
|
||||||
* Look for a pattern inside a line
|
* Look for a pattern inside a line
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
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) {
|
if (dir == ED_SEARCH_PREV_HISTORY) {
|
||||||
for (cp = el->el_line.cursor; cp >= el->el_line.buffer; cp--)
|
for (; cp >= el->el_line.buffer; cp--) {
|
||||||
if (el_match(cp, pattern)) {
|
if (el_match(cp, ocp)) {
|
||||||
|
*ocp = oc;
|
||||||
el->el_line.cursor = cp;
|
el->el_line.cursor = cp;
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
*ocp = oc;
|
||||||
return (CC_ERROR);
|
return (CC_ERROR);
|
||||||
} else {
|
} else {
|
||||||
for (cp = el->el_line.cursor; *cp != '\0' &&
|
for (; *cp != '\0' && cp < el->el_line.limit; cp++) {
|
||||||
cp < el->el_line.limit; cp++)
|
if (el_match(cp, ocp)) {
|
||||||
if (el_match(cp, pattern)) {
|
*ocp = oc;
|
||||||
el->el_line.cursor = cp;
|
el->el_line.cursor = cp;
|
||||||
return (CC_NORM);
|
return (CC_NORM);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
*ocp = oc;
|
||||||
return (CC_ERROR);
|
return (CC_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: search.h,v 1.6 2002/11/15 14:32:34 christos Exp $ */
|
/* $NetBSD: search.h,v 1.8 2003/10/18 23:27:36 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -63,7 +59,7 @@ protected int c_hmatch(EditLine *, const char *);
|
||||||
protected void c_setpat(EditLine *);
|
protected void c_setpat(EditLine *);
|
||||||
protected el_action_t ce_inc_search(EditLine *, int);
|
protected el_action_t ce_inc_search(EditLine *, int);
|
||||||
protected el_action_t cv_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_repeat_srch(EditLine *, int);
|
||||||
protected el_action_t cv_csearch(EditLine *, int, int, int, int);
|
protected el_action_t cv_csearch(EditLine *, int, int, int, int);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: sig.c,v 1.10 2003/03/10 00:58:05 christos Exp $ */
|
/* $NetBSD: sig.c,v 1.11 2003/08/07 16:44:33 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sig.c: Signal handling stuff.
|
* sig.c: Signal handling stuff.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: sig.h,v 1.4 2003/03/10 00:58:05 christos Exp $ */
|
/* $NetBSD: sig.h,v 1.5 2003/08/07 16:44:33 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,28 +1,73 @@
|
||||||
|
/* $NetBSD: strlcpy.c,v 1.14 2003/10/27 00:12:42 lukem Exp $ */
|
||||||
|
/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
|
||||||
|
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef HAVE_STRLCPY
|
#ifdef _LIBC
|
||||||
size_t strlcpy(char *dst, const char *src, size_t size)
|
# ifdef __weak_alias
|
||||||
{
|
__weak_alias(strlcpy, _strlcpy)
|
||||||
if(size) {
|
# endif
|
||||||
strncpy(dst, src, size-1);
|
#endif
|
||||||
dst[size-1] = '\0';
|
|
||||||
} else {
|
#if !HAVE_STRLCPY
|
||||||
dst[0] = '\0';
|
/*
|
||||||
}
|
* Copy src to string dst of size siz. At most siz-1 characters
|
||||||
return strlen(src);
|
* will be copied. Always NUL terminates (unless siz == 0).
|
||||||
}
|
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||||
|
*/
|
||||||
size_t strlcat(char *dst, const char *src, size_t size)
|
size_t
|
||||||
{
|
#ifdef _LIBC
|
||||||
int dl = strlen(dst);
|
_strlcpy(dst, src, siz)
|
||||||
int sz = size-dl-1;
|
#else
|
||||||
|
strlcpy(dst, src, siz)
|
||||||
if(sz >= 0) {
|
#endif
|
||||||
strncat(dst, src, sz);
|
char *dst;
|
||||||
dst[sz] = '\0';
|
const char *src;
|
||||||
}
|
size_t siz;
|
||||||
|
{
|
||||||
return dl+strlen(src);
|
char *d = dst;
|
||||||
}
|
const char *s = src;
|
||||||
|
size_t n = siz;
|
||||||
|
|
||||||
|
_DIAGASSERT(dst != NULL);
|
||||||
|
_DIAGASSERT(src != NULL);
|
||||||
|
|
||||||
|
/* Copy as many bytes as will fit */
|
||||||
|
if (n != 0 && --n != 0) {
|
||||||
|
do {
|
||||||
|
if ((*d++ = *s++) == 0)
|
||||||
|
break;
|
||||||
|
} while (--n != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||||
|
if (n == 0) {
|
||||||
|
if (siz != 0)
|
||||||
|
*d = '\0'; /* NUL-terminate dst */
|
||||||
|
while (*s++)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(s - src - 1); /* count does not include NUL */
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: sys.h,v 1.6 2003/03/10 00:57:38 christos Exp $ */
|
/* $NetBSD: sys.h,v 1.9 2004/01/17 17:57:40 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -48,6 +44,28 @@
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
|
||||||
|
# define __attribute__(A)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __P
|
||||||
|
# define __P(x) x
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _DIAGASSERT
|
||||||
|
# define _DIAGASSERT(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __BEGIN_DECLS
|
||||||
|
# ifdef __cplusplus
|
||||||
|
# define __BEGIN_DECLS extern "C" {
|
||||||
|
# define __END_DECLS }
|
||||||
|
# else
|
||||||
|
# define __BEGIN_DECLS
|
||||||
|
# define __END_DECLS
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef public
|
#ifndef public
|
||||||
# define public /* Externally visible functions/variables */
|
# define public /* Externally visible functions/variables */
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,6 +79,10 @@
|
||||||
/* When we want to hide everything */
|
/* When we want to hide everything */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_U_INT32_T
|
||||||
|
typedef unsigned int u_int32_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _PTR_T
|
#ifndef _PTR_T
|
||||||
# define _PTR_T
|
# define _PTR_T
|
||||||
typedef void *ptr_t;
|
typedef void *ptr_t;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: term.c,v 1.35 2002/03/18 16:00:59 christos Exp $ */
|
/* $NetBSD: term.c,v 1.40 2004/05/22 23:21:28 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,14 +32,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* term.c: Editor/termcap-curses interface
|
* term.c: Editor/termcap-curses interface
|
||||||
|
@ -55,24 +44,23 @@ __RCSID("$NetBSD: term.c,v 1.35 2002/03/18 16:00:59 christos Exp $");
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef HAVE_TERMCAP_H
|
|
||||||
#include <termcap.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_CURSES_H
|
#ifdef HAVE_CURSES_H
|
||||||
#include <curses.h>
|
# include <curses.h>
|
||||||
#endif
|
#elif HAVE_NCURSES_H
|
||||||
#ifdef HAVE_NCURSES_H
|
# include <ncurses.h>
|
||||||
#include <ncurses.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "el.h"
|
/* Solaris's term.h does horrid things. */
|
||||||
|
#if (defined(HAVE_TERM_H) && !defined(_SUNOS))
|
||||||
#if !defined(HAVE_TERMCAP_H) && defined(HAVE_TERM_H)
|
# include <term.h>
|
||||||
#include <term.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#include "el.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IMPORTANT NOTE: these routines are allowed to look at the current screen
|
* 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
|
* and the current possition assuming that it is correct. If this is not
|
||||||
|
@ -356,6 +344,7 @@ term_init(EditLine *el)
|
||||||
term_init_arrow(el);
|
term_init_arrow(el);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* term_end():
|
/* term_end():
|
||||||
* Clean up the terminal stuff
|
* Clean up the terminal stuff
|
||||||
*/
|
*/
|
||||||
|
@ -372,6 +361,8 @@ term_end(EditLine *el)
|
||||||
el->el_term.t_str = NULL;
|
el->el_term.t_str = NULL;
|
||||||
el_free((ptr_t) el->el_term.t_val);
|
el_free((ptr_t) el->el_term.t_val);
|
||||||
el->el_term.t_val = NULL;
|
el->el_term.t_val = NULL;
|
||||||
|
el_free((ptr_t) el->el_term.t_fkey);
|
||||||
|
el->el_term.t_fkey = NULL;
|
||||||
term_free_display(el);
|
term_free_display(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,7 +639,8 @@ mc_again:
|
||||||
* from col 0
|
* from col 0
|
||||||
*/
|
*/
|
||||||
if (EL_CAN_TAB ?
|
if (EL_CAN_TAB ?
|
||||||
(((unsigned int)-del) > (((unsigned int) where >> 3) +
|
((unsigned int)-del >
|
||||||
|
(((unsigned int) where >> 3) +
|
||||||
(where & 07)))
|
(where & 07)))
|
||||||
: (-del > where)) {
|
: (-del > where)) {
|
||||||
term__putc('\r'); /* do a CR */
|
term__putc('\r'); /* do a CR */
|
||||||
|
@ -876,6 +868,12 @@ term_clear_to_bottom(EditLine *el)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
protected void
|
||||||
|
term_get(EditLine *el, const char **term)
|
||||||
|
{
|
||||||
|
*term = el->el_term.t_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* term_set():
|
/* term_set():
|
||||||
* Read in the terminal capabilities from the requested terminal
|
* Read in the terminal capabilities from the requested terminal
|
||||||
|
@ -937,8 +935,11 @@ term_set(EditLine *el, const char *term)
|
||||||
/* Get the size */
|
/* Get the size */
|
||||||
Val(T_co) = tgetnum("co");
|
Val(T_co) = tgetnum("co");
|
||||||
Val(T_li) = tgetnum("li");
|
Val(T_li) = tgetnum("li");
|
||||||
for (t = tstr; t->name != NULL; t++)
|
for (t = tstr; t->name != NULL; t++) {
|
||||||
term_alloc(el, t, tgetstr(t->name, &area));
|
/* XXX: some systems tgetstr needs non const */
|
||||||
|
term_alloc(el, t, tgetstr(strchr(t->name, *t->name),
|
||||||
|
&area));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Val(T_co) < 2)
|
if (Val(T_co) < 2)
|
||||||
|
@ -957,6 +958,7 @@ term_set(EditLine *el, const char *term)
|
||||||
return (-1);
|
return (-1);
|
||||||
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
|
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||||
term_bind_arrow(el);
|
term_bind_arrow(el);
|
||||||
|
el->el_term.t_name = term;
|
||||||
return (i <= 0 ? -1 : 0);
|
return (i <= 0 ? -1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1078,32 +1080,32 @@ term_reset_arrow(EditLine *el)
|
||||||
static const char stOH[] = {033, 'O', 'H', '\0'};
|
static const char stOH[] = {033, 'O', 'H', '\0'};
|
||||||
static const char stOF[] = {033, 'O', 'F', '\0'};
|
static const char stOF[] = {033, 'O', 'F', '\0'};
|
||||||
|
|
||||||
el_key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
|
||||||
|
|
||||||
if (el->el_map.type == MAP_VI) {
|
if (el->el_map.type == MAP_VI) {
|
||||||
el_key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1157,7 +1159,7 @@ term_print_arrow(EditLine *el, const char *name)
|
||||||
for (i = 0; i < A_K_NKEYS; i++)
|
for (i = 0; i < A_K_NKEYS; i++)
|
||||||
if (*name == '\0' || strcmp(name, arrow[i].name) == 0)
|
if (*name == '\0' || strcmp(name, arrow[i].name) == 0)
|
||||||
if (arrow[i].type != XK_NOD)
|
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);
|
arrow[i].type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1198,20 +1200,20 @@ term_bind_arrow(EditLine *el)
|
||||||
* unassigned key.
|
* unassigned key.
|
||||||
*/
|
*/
|
||||||
if (arrow[i].type == XK_NOD)
|
if (arrow[i].type == XK_NOD)
|
||||||
el_key_clear(el, map, p);
|
key_clear(el, map, p);
|
||||||
else {
|
else {
|
||||||
if (p[1] && (dmap[j] == map[j] ||
|
if (p[1] && (dmap[j] == map[j] ||
|
||||||
map[j] == ED_SEQUENCE_LEAD_IN)) {
|
map[j] == ED_SEQUENCE_LEAD_IN)) {
|
||||||
el_key_add(el, p, &arrow[i].fun,
|
key_add(el, p, &arrow[i].fun,
|
||||||
arrow[i].type);
|
arrow[i].type);
|
||||||
map[j] = ED_SEQUENCE_LEAD_IN;
|
map[j] = ED_SEQUENCE_LEAD_IN;
|
||||||
} else if (map[j] == ED_UNASSIGNED) {
|
} else if (map[j] == ED_UNASSIGNED) {
|
||||||
el_key_clear(el, map, p);
|
key_clear(el, map, p);
|
||||||
if (arrow[i].type == XK_CMD)
|
if (arrow[i].type == XK_CMD)
|
||||||
map[j] = arrow[i].fun.cmd;
|
map[j] = arrow[i].fun.cmd;
|
||||||
else
|
else
|
||||||
el_key_add(el, p, &arrow[i].fun,
|
key_add(el, p, &arrow[i].fun,
|
||||||
arrow[i].type);
|
arrow[i].type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1244,12 +1246,10 @@ term__flush(void)
|
||||||
/* term_telltc():
|
/* term_telltc():
|
||||||
* Print the current termcap characteristics
|
* Print the current termcap characteristics
|
||||||
*/
|
*/
|
||||||
char *el_key__decode_str(const char *, char *, const char *);
|
|
||||||
|
|
||||||
protected int
|
protected int
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
term_telltc(EditLine *el, int argc __attribute__((unused)),
|
term_telltc(EditLine *el, int argc __attribute__((__unused__)),
|
||||||
const char **argv __attribute__((unused)))
|
const char **argv __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
const struct termcapstr *t;
|
const struct termcapstr *t;
|
||||||
char **ts;
|
char **ts;
|
||||||
|
@ -1273,7 +1273,7 @@ term_telltc(EditLine *el, int argc __attribute__((unused)),
|
||||||
(void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n",
|
(void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n",
|
||||||
t->long_name,
|
t->long_name,
|
||||||
t->name, *ts && **ts ?
|
t->name, *ts && **ts ?
|
||||||
el_key__decode_str(*ts, upbuf, "") : "(empty)");
|
key__decode_str(*ts, upbuf, "") : "(empty)");
|
||||||
(void) fputc('\n', el->el_outfile);
|
(void) fputc('\n', el->el_outfile);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -1284,8 +1284,8 @@ term_telltc(EditLine *el, int argc __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected int
|
protected int
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
term_settc(EditLine *el, int argc __attribute__((unused)),
|
term_settc(EditLine *el, int argc __attribute__((__unused__)),
|
||||||
const char **argv __attribute__((unused)))
|
const char **argv)
|
||||||
{
|
{
|
||||||
const struct termcapstr *ts;
|
const struct termcapstr *ts;
|
||||||
const struct termcapval *tv;
|
const struct termcapval *tv;
|
||||||
|
@ -1361,9 +1361,8 @@ term_settc(EditLine *el, int argc __attribute__((unused)),
|
||||||
*/
|
*/
|
||||||
protected int
|
protected int
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
term_echotc(EditLine *el __attribute__((unused)),
|
term_echotc(EditLine *el, int argc __attribute__((__unused__)),
|
||||||
int argc __attribute__((unused)),
|
const char **argv)
|
||||||
const char **argv __attribute__((unused)))
|
|
||||||
{
|
{
|
||||||
char *cap, *scap, *ep;
|
char *cap, *scap, *ep;
|
||||||
int arg_need, arg_cols, arg_rows;
|
int arg_need, arg_cols, arg_rows;
|
||||||
|
@ -1422,7 +1421,7 @@ term_echotc(EditLine *el __attribute__((unused)),
|
||||||
}
|
}
|
||||||
(void) fprintf(el->el_outfile, fmtd, 0);
|
(void) fprintf(el->el_outfile, fmtd, 0);
|
||||||
#else
|
#else
|
||||||
(void) fprintf(el->el_outfile, fmtd, el->el_tty.t_speed);
|
(void) fprintf(el->el_outfile, fmtd, (int)el->el_tty.t_speed);
|
||||||
#endif
|
#endif
|
||||||
return (0);
|
return (0);
|
||||||
} else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) {
|
} else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) {
|
||||||
|
@ -1441,8 +1440,10 @@ term_echotc(EditLine *el __attribute__((unused)),
|
||||||
scap = el->el_term.t_str[t - tstr];
|
scap = el->el_term.t_str[t - tstr];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (t->name == NULL)
|
if (t->name == NULL) {
|
||||||
scap = tgetstr(*argv, &area);
|
/* XXX: some systems tgetstr needs non const */
|
||||||
|
scap = tgetstr(strchr(*argv, **argv), &area);
|
||||||
|
}
|
||||||
if (!scap || scap[0] == '\0') {
|
if (!scap || scap[0] == '\0') {
|
||||||
if (!silent)
|
if (!silent)
|
||||||
(void) fprintf(el->el_errfile,
|
(void) fprintf(el->el_errfile,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: tokenizer.c,v 1.11 2002/10/27 20:24:29 christos Exp $ */
|
/* $NetBSD: tokenizer.c,v 1.14 2003/12/05 13:37:48 lukem Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,21 +32,14 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tokenize.c: Bourne shell like tokenizer
|
* tokenize.c: Bourne shell like tokenizer
|
||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "tokenizer.h"
|
#include "histedit.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
Q_none, Q_single, Q_double, Q_one, Q_doubleone
|
Q_none, Q_single, Q_double, Q_one, Q_doubleone
|
||||||
|
@ -64,6 +53,7 @@ typedef enum {
|
||||||
#define WINCR 20
|
#define WINCR 20
|
||||||
#define AINCR 10
|
#define AINCR 10
|
||||||
|
|
||||||
|
#define tok_strdup(a) strdup(a)
|
||||||
#define tok_malloc(a) malloc(a)
|
#define tok_malloc(a) malloc(a)
|
||||||
#define tok_free(a) free(a)
|
#define tok_free(a) free(a)
|
||||||
#define tok_realloc(a, b) realloc(a, b)
|
#define tok_realloc(a, b) realloc(a, b)
|
||||||
|
@ -111,7 +101,7 @@ tok_init(const char *ifs)
|
||||||
|
|
||||||
if (tok == NULL)
|
if (tok == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
tok->ifs = strdup(ifs ? ifs : IFS);
|
tok->ifs = tok_strdup(ifs ? ifs : IFS);
|
||||||
if (tok->ifs == NULL) {
|
if (tok->ifs == NULL) {
|
||||||
tok_free((ptr_t)tok);
|
tok_free((ptr_t)tok);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -173,21 +163,39 @@ tok_end(Tokenizer *tok)
|
||||||
|
|
||||||
|
|
||||||
/* tok_line():
|
/* tok_line():
|
||||||
* Bourne shell like tokenizing
|
* Bourne shell (sh(1)) like tokenizing
|
||||||
* Return:
|
* Arguments:
|
||||||
* -1: Internal error
|
* tok current tokenizer state (setup with tok_init())
|
||||||
* 3: Quoted return
|
* line line to parse
|
||||||
* 2: Unmatched double quote
|
* Returns:
|
||||||
* 1: Unmatched single quote
|
* -1 Internal error
|
||||||
* 0: Ok
|
* 3 Quoted return
|
||||||
|
* 2 Unmatched double quote
|
||||||
|
* 1 Unmatched single quote
|
||||||
|
* 0 Ok
|
||||||
|
* Modifies (if return value is 0):
|
||||||
|
* argc number of arguments
|
||||||
|
* argv argument array
|
||||||
|
* cursorc if !NULL, argv element containing cursor
|
||||||
|
* cursorv if !NULL, offset in argv[cursorc] of cursor
|
||||||
*/
|
*/
|
||||||
public int
|
public int
|
||||||
tok_line(Tokenizer *tok, const char *line, int *argc, const char ***argv)
|
tok_line(Tokenizer *tok, const LineInfo *line,
|
||||||
|
int *argc, const char ***argv, int *cursorc, int *cursoro)
|
||||||
{
|
{
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
|
int cc, co;
|
||||||
|
|
||||||
for (;;) {
|
cc = co = -1;
|
||||||
switch (*(ptr = line++)) {
|
ptr = line->buffer;
|
||||||
|
for (ptr = line->buffer; ;ptr++) {
|
||||||
|
if (ptr >= line->lastchar)
|
||||||
|
ptr = "";
|
||||||
|
if (ptr == line->cursor) {
|
||||||
|
cc = tok->argc;
|
||||||
|
co = tok->wptr - tok->wstart;
|
||||||
|
}
|
||||||
|
switch (*ptr) {
|
||||||
case '\'':
|
case '\'':
|
||||||
tok->flags |= TOK_KEEP;
|
tok->flags |= TOK_KEEP;
|
||||||
tok->flags &= ~TOK_EAT;
|
tok->flags &= ~TOK_EAT;
|
||||||
|
@ -286,10 +294,7 @@ tok_line(Tokenizer *tok, const char *line, int *argc, const char ***argv)
|
||||||
tok->flags &= ~TOK_EAT;
|
tok->flags &= ~TOK_EAT;
|
||||||
switch (tok->quote) {
|
switch (tok->quote) {
|
||||||
case Q_none:
|
case Q_none:
|
||||||
tok_finish(tok);
|
goto tok_line_outok;
|
||||||
*argv = (const char **)tok->argv;
|
|
||||||
*argc = tok->argc;
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
case Q_single:
|
case Q_single:
|
||||||
case Q_double:
|
case Q_double:
|
||||||
|
@ -319,10 +324,7 @@ tok_line(Tokenizer *tok, const char *line, int *argc, const char ***argv)
|
||||||
tok->flags &= ~TOK_EAT;
|
tok->flags &= ~TOK_EAT;
|
||||||
return (3);
|
return (3);
|
||||||
}
|
}
|
||||||
tok_finish(tok);
|
goto tok_line_outok;
|
||||||
*argv = (const char **)tok->argv;
|
|
||||||
*argc = tok->argc;
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
case Q_single:
|
case Q_single:
|
||||||
return (1);
|
return (1);
|
||||||
|
@ -407,4 +409,32 @@ tok_line(Tokenizer *tok, const char *line, int *argc, const char ***argv)
|
||||||
tok->argv = p;
|
tok->argv = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tok_line_outok:
|
||||||
|
if (cc == -1 && co == -1) {
|
||||||
|
cc = tok->argc;
|
||||||
|
co = tok->wptr - tok->wstart;
|
||||||
|
}
|
||||||
|
if (cursorc != NULL)
|
||||||
|
*cursorc = cc;
|
||||||
|
if (cursoro != NULL)
|
||||||
|
*cursoro = co;
|
||||||
|
tok_finish(tok);
|
||||||
|
*argv = (const char **)tok->argv;
|
||||||
|
*argc = tok->argc;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tok_str():
|
||||||
|
* Simpler version of tok_line, taking a NUL terminated line
|
||||||
|
* and splitting into words, ignoring cursor state.
|
||||||
|
*/
|
||||||
|
public int
|
||||||
|
tok_str(Tokenizer *tok, const char *line, int *argc, const char ***argv)
|
||||||
|
{
|
||||||
|
LineInfo li;
|
||||||
|
|
||||||
|
memset(&li, 0, sizeof(li));
|
||||||
|
li.buffer = line;
|
||||||
|
li.cursor = li.lastchar = strchr(line, '\0');
|
||||||
|
return (tok_line(tok, &li, argc, argv, NULL, NULL));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: tty.c,v 1.16 2002/03/18 16:01:01 christos Exp $ */
|
/* $NetBSD: tty.c,v 1.21 2004/08/13 12:10:39 mycroft Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,18 +32,12 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tty.c: tty interface stuff
|
* tty.c: tty interface stuff
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "el.h"
|
#include "el.h"
|
||||||
|
|
||||||
|
@ -124,11 +114,11 @@ private const ttychar_t ttychar = {
|
||||||
private const ttymap_t tty_map[] = {
|
private const ttymap_t tty_map[] = {
|
||||||
#ifdef VERASE
|
#ifdef VERASE
|
||||||
{C_ERASE, VERASE,
|
{C_ERASE, VERASE,
|
||||||
{ED_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
|
{EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
|
||||||
#endif /* VERASE */
|
#endif /* VERASE */
|
||||||
#ifdef VERASE2
|
#ifdef VERASE2
|
||||||
{C_ERASE2, VERASE2,
|
{C_ERASE2, VERASE2,
|
||||||
{ED_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
|
{EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
|
||||||
#endif /* VERASE2 */
|
#endif /* VERASE2 */
|
||||||
#ifdef VKILL
|
#ifdef VKILL
|
||||||
{C_KILL, VKILL,
|
{C_KILL, VKILL,
|
||||||
|
@ -455,6 +445,7 @@ private const ttymodes_t ttymodes[] = {
|
||||||
#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
|
#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
|
||||||
#define tty__cooked_mode(td) ((td)->c_lflag & ICANON)
|
#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__getchar(struct termios *, unsigned char *);
|
||||||
private void tty__setchar(struct termios *, unsigned char *);
|
private void tty__setchar(struct termios *, unsigned char *);
|
||||||
private speed_t tty__getspeed(struct termios *);
|
private speed_t tty__getspeed(struct termios *);
|
||||||
|
@ -568,7 +559,7 @@ tty_init(EditLine *el)
|
||||||
*/
|
*/
|
||||||
protected void
|
protected void
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
tty_end(EditLine *el __attribute__((unused)))
|
tty_end(EditLine *el __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
/* XXX: Maybe reset to an initial state? */
|
/* XXX: Maybe reset to an initial state? */
|
||||||
|
@ -588,6 +579,113 @@ tty__getspeed(struct termios *td)
|
||||||
return (spd);
|
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():
|
/* tty__getchar():
|
||||||
* Get the tty characters
|
* Get the tty characters
|
||||||
|
@ -784,15 +882,15 @@ tty_bind_char(EditLine *el, int force)
|
||||||
if (new[0] == old[0] && !force)
|
if (new[0] == old[0] && !force)
|
||||||
continue;
|
continue;
|
||||||
/* Put the old default binding back, and set the new binding */
|
/* 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]];
|
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_VI == 1, MAP_EMACS == 0... */
|
||||||
map[new[0]] = tp->bind[el->el_map.type];
|
map[new[0]] = tp->bind[el->el_map.type];
|
||||||
if (dalt) {
|
if (dalt) {
|
||||||
el_key_clear(el, alt, (char *)old);
|
key_clear(el, alt, (char *)old);
|
||||||
alt[old[0]] = dalt[old[0]];
|
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];
|
alt[new[0]] = tp->bind[el->el_map.type + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1041,13 +1139,14 @@ tty_noquotemode(EditLine *el)
|
||||||
*/
|
*/
|
||||||
protected int
|
protected int
|
||||||
/*ARGSUSED*/
|
/*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;
|
const ttymodes_t *m;
|
||||||
char x;
|
char x;
|
||||||
int aflag = 0;
|
int aflag = 0;
|
||||||
const char *s, *d;
|
const char *s, *d;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
struct termios *tios = &el->el_tty.t_ex;
|
||||||
int z = EX_IO;
|
int z = EX_IO;
|
||||||
|
|
||||||
if (argv == NULL)
|
if (argv == NULL)
|
||||||
|
@ -1062,14 +1161,17 @@ tty_stty(EditLine *el, int argc __attribute__((unused)), const char **argv)
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
argv++;
|
argv++;
|
||||||
|
tios = &el->el_tty.t_ed;
|
||||||
z = ED_IO;
|
z = ED_IO;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
argv++;
|
argv++;
|
||||||
|
tios = &el->el_tty.t_ex;
|
||||||
z = EX_IO;
|
z = EX_IO;
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
argv++;
|
argv++;
|
||||||
|
tios = &el->el_tty.t_ts;
|
||||||
z = QU_IO;
|
z = QU_IO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1119,6 +1221,7 @@ tty_stty(EditLine *el, int argc __attribute__((unused)), const char **argv)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
while (argv && (s = *argv++)) {
|
while (argv && (s = *argv++)) {
|
||||||
|
char *p;
|
||||||
switch (*s) {
|
switch (*s) {
|
||||||
case '+':
|
case '+':
|
||||||
case '-':
|
case '-':
|
||||||
|
@ -1129,8 +1232,11 @@ tty_stty(EditLine *el, int argc __attribute__((unused)), const char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
d = s;
|
d = s;
|
||||||
|
if ((p = strchr(s, '=')) != NULL)
|
||||||
|
*p++ = '\0';
|
||||||
for (m = ttymodes; m->m_name; m++)
|
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;
|
break;
|
||||||
|
|
||||||
if (!m->m_name) {
|
if (!m->m_name) {
|
||||||
|
@ -1138,6 +1244,16 @@ tty_stty(EditLine *el, int argc __attribute__((unused)), const char **argv)
|
||||||
"%s: Invalid argument `%s'.\n", name, d);
|
"%s: Invalid argument `%s'.\n", name, d);
|
||||||
return (-1);
|
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;
|
||||||
|
assert(c-- != 0);
|
||||||
|
c = tty__getcharindex(c);
|
||||||
|
assert(c != -1);
|
||||||
|
tios->c_cc[c] = v;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
switch (x) {
|
switch (x) {
|
||||||
case '+':
|
case '+':
|
||||||
el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value;
|
el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: tty.h,v 1.9 2002/03/18 16:01:01 christos Exp $ */
|
/* $NetBSD: tty.h,v 1.10 2003/08/07 16:44:34 agc Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
|
311
cmd-line-utils/libedit/unvis.c
Normal file
311
cmd-line-utils/libedit/unvis.c
Normal file
|
@ -0,0 +1,311 @@
|
||||||
|
/* $NetBSD: unvis.c,v 1.24 2003/08/07 16:42:59 agc Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 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. 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.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#define __LIBC12_SOURCE__
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
|
#ifdef __weak_alias
|
||||||
|
__weak_alias(strunvis,_strunvis)
|
||||||
|
__weak_alias(unvis,_unvis)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __warn_references
|
||||||
|
__warn_references(unvis,
|
||||||
|
"warning: reference to compatibility unvis(); include <vis.h> for correct reference")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !HAVE_VIS
|
||||||
|
/*
|
||||||
|
* decode driven by state machine
|
||||||
|
*/
|
||||||
|
#define S_GROUND 0 /* haven't seen escape char */
|
||||||
|
#define S_START 1 /* start decoding special sequence */
|
||||||
|
#define S_META 2 /* metachar started (M) */
|
||||||
|
#define S_META1 3 /* metachar more, regular char (-) */
|
||||||
|
#define S_CTRL 4 /* control char started (^) */
|
||||||
|
#define S_OCTAL2 5 /* octal digit 2 */
|
||||||
|
#define S_OCTAL3 6 /* octal digit 3 */
|
||||||
|
#define S_HEX1 7 /* hex digit */
|
||||||
|
#define S_HEX2 8 /* hex digit 2 */
|
||||||
|
|
||||||
|
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
|
||||||
|
#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10))
|
||||||
|
|
||||||
|
int
|
||||||
|
unvis(cp, c, astate, flag)
|
||||||
|
char *cp;
|
||||||
|
int c;
|
||||||
|
int *astate, flag;
|
||||||
|
{
|
||||||
|
return __unvis13(cp, (int)c, astate, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unvis - decode characters previously encoded by vis
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
__unvis13(cp, c, astate, flag)
|
||||||
|
char *cp;
|
||||||
|
int c;
|
||||||
|
int *astate, flag;
|
||||||
|
{
|
||||||
|
|
||||||
|
_DIAGASSERT(cp != NULL);
|
||||||
|
_DIAGASSERT(astate != NULL);
|
||||||
|
|
||||||
|
if (flag & UNVIS_END) {
|
||||||
|
if (*astate == S_OCTAL2 || *astate == S_OCTAL3
|
||||||
|
|| *astate == S_HEX2) {
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
}
|
||||||
|
return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (*astate) {
|
||||||
|
|
||||||
|
case S_GROUND:
|
||||||
|
*cp = 0;
|
||||||
|
if (c == '\\') {
|
||||||
|
*astate = S_START;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if ((flag & VIS_HTTPSTYLE) && c == '%') {
|
||||||
|
*astate = S_HEX1;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
*cp = c;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
|
||||||
|
case S_START:
|
||||||
|
switch(c) {
|
||||||
|
case '\\':
|
||||||
|
*cp = c;
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case '0': case '1': case '2': case '3':
|
||||||
|
case '4': case '5': case '6': case '7':
|
||||||
|
*cp = (c - '0');
|
||||||
|
*astate = S_OCTAL2;
|
||||||
|
return (0);
|
||||||
|
case 'M':
|
||||||
|
*cp = (char)0200;
|
||||||
|
*astate = S_META;
|
||||||
|
return (0);
|
||||||
|
case '^':
|
||||||
|
*astate = S_CTRL;
|
||||||
|
return (0);
|
||||||
|
case 'n':
|
||||||
|
*cp = '\n';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case 'r':
|
||||||
|
*cp = '\r';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case 'b':
|
||||||
|
*cp = '\b';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case 'a':
|
||||||
|
*cp = '\007';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case 'v':
|
||||||
|
*cp = '\v';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case 't':
|
||||||
|
*cp = '\t';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case 'f':
|
||||||
|
*cp = '\f';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case 's':
|
||||||
|
*cp = ' ';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case 'E':
|
||||||
|
*cp = '\033';
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
case '\n':
|
||||||
|
/*
|
||||||
|
* hidden newline
|
||||||
|
*/
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_NOCHAR);
|
||||||
|
case '$':
|
||||||
|
/*
|
||||||
|
* hidden marker
|
||||||
|
*/
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_NOCHAR);
|
||||||
|
}
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_SYNBAD);
|
||||||
|
|
||||||
|
case S_META:
|
||||||
|
if (c == '-')
|
||||||
|
*astate = S_META1;
|
||||||
|
else if (c == '^')
|
||||||
|
*astate = S_CTRL;
|
||||||
|
else {
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_SYNBAD);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
case S_META1:
|
||||||
|
*astate = S_GROUND;
|
||||||
|
*cp |= c;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
|
||||||
|
case S_CTRL:
|
||||||
|
if (c == '?')
|
||||||
|
*cp |= 0177;
|
||||||
|
else
|
||||||
|
*cp |= c & 037;
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
|
||||||
|
case S_OCTAL2: /* second possible octal digit */
|
||||||
|
if (isoctal(c)) {
|
||||||
|
/*
|
||||||
|
* yes - and maybe a third
|
||||||
|
*/
|
||||||
|
*cp = (*cp << 3) + (c - '0');
|
||||||
|
*astate = S_OCTAL3;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* no - done with current sequence, push back passed char
|
||||||
|
*/
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALIDPUSH);
|
||||||
|
|
||||||
|
case S_OCTAL3: /* third possible octal digit */
|
||||||
|
*astate = S_GROUND;
|
||||||
|
if (isoctal(c)) {
|
||||||
|
*cp = (*cp << 3) + (c - '0');
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* we were done, push back passed char
|
||||||
|
*/
|
||||||
|
return (UNVIS_VALIDPUSH);
|
||||||
|
case S_HEX1:
|
||||||
|
if (isxdigit(c)) {
|
||||||
|
*cp = xtod(c);
|
||||||
|
*astate = S_HEX2;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* no - done with current sequence, push back passed char
|
||||||
|
*/
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_VALIDPUSH);
|
||||||
|
case S_HEX2:
|
||||||
|
*astate = S_GROUND;
|
||||||
|
if (isxdigit(c)) {
|
||||||
|
*cp = xtod(c) | (*cp << 4);
|
||||||
|
return (UNVIS_VALID);
|
||||||
|
}
|
||||||
|
return (UNVIS_VALIDPUSH);
|
||||||
|
default:
|
||||||
|
/*
|
||||||
|
* decoder in unknown state - (probably uninitialized)
|
||||||
|
*/
|
||||||
|
*astate = S_GROUND;
|
||||||
|
return (UNVIS_SYNBAD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* strunvis - decode src into dst
|
||||||
|
*
|
||||||
|
* Number of chars decoded into dst is returned, -1 on error.
|
||||||
|
* Dst is null terminated.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
strunvisx(dst, src, flag)
|
||||||
|
char *dst;
|
||||||
|
const char *src;
|
||||||
|
int flag;
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
char *start = dst;
|
||||||
|
int state = 0;
|
||||||
|
|
||||||
|
_DIAGASSERT(src != NULL);
|
||||||
|
_DIAGASSERT(dst != NULL);
|
||||||
|
|
||||||
|
while ((c = *src++) != '\0') {
|
||||||
|
again:
|
||||||
|
switch (__unvis13(dst, c, &state, flag)) {
|
||||||
|
case UNVIS_VALID:
|
||||||
|
dst++;
|
||||||
|
break;
|
||||||
|
case UNVIS_VALIDPUSH:
|
||||||
|
dst++;
|
||||||
|
goto again;
|
||||||
|
case 0:
|
||||||
|
case UNVIS_NOCHAR:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (__unvis13(dst, c, &state, UNVIS_END) == UNVIS_VALID)
|
||||||
|
dst++;
|
||||||
|
*dst = '\0';
|
||||||
|
return (dst - start);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
strunvis(dst, src)
|
||||||
|
char *dst;
|
||||||
|
const char *src;
|
||||||
|
{
|
||||||
|
return strunvisx(dst, src, 0);
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: vi.c,v 1.16 2003/03/10 11:09:25 dsl Exp $ */
|
/* $NetBSD: vi.c,v 1.20 2004/08/13 12:10:39 mycroft Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -15,11 +15,7 @@
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* 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
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -36,18 +32,11 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <config.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
|
||||||
#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 $");
|
|
||||||
#endif
|
|
||||||
#endif /* not lint && not SCCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vi.c: Vi mode commands.
|
* vi.c: Vi mode commands.
|
||||||
|
@ -123,7 +112,7 @@ cv_paste(EditLine *el, int c)
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_paste_next(EditLine *el, int c __attribute__((unused)))
|
vi_paste_next(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (cv_paste(el, 0));
|
return (cv_paste(el, 0));
|
||||||
|
@ -136,7 +125,7 @@ vi_paste_next(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_paste_prev(EditLine *el, int c __attribute__((unused)))
|
vi_paste_prev(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (cv_paste(el, 1));
|
return (cv_paste(el, 1));
|
||||||
|
@ -149,7 +138,7 @@ vi_paste_prev(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor == el->el_line.buffer)
|
||||||
|
@ -174,7 +163,7 @@ vi_prev_big_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor == el->el_line.buffer)
|
||||||
|
@ -199,7 +188,7 @@ vi_prev_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor >= el->el_line.lastchar - 1)
|
||||||
|
@ -223,7 +212,7 @@ vi_next_big_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor >= el->el_line.lastchar - 1)
|
||||||
|
@ -278,7 +267,7 @@ vi_change_case(EditLine *el, int c)
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_change_meta(EditLine *el, int c __attribute__((unused)))
|
vi_change_meta(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -295,7 +284,7 @@ vi_change_meta(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_line.cursor = el->el_line.buffer;
|
||||||
|
@ -311,7 +300,7 @@ vi_insert_at_bol(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor >= el->el_line.lastchar)
|
||||||
|
@ -330,7 +319,7 @@ vi_replace_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_map.current = el->el_map.key;
|
||||||
|
@ -346,7 +335,7 @@ vi_replace_mode(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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);
|
c_delafter(el, el->el_state.argument);
|
||||||
|
@ -361,7 +350,7 @@ vi_substitute_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_substitute_line(EditLine *el, int c __attribute__((unused)))
|
vi_substitute_line(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
cv_undo(el);
|
cv_undo(el);
|
||||||
|
@ -379,7 +368,7 @@ vi_substitute_line(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_change_to_eol(EditLine *el, int c __attribute__((unused)))
|
vi_change_to_eol(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
cv_undo(el);
|
cv_undo(el);
|
||||||
|
@ -397,7 +386,7 @@ vi_change_to_eol(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_map.current = el->el_map.key;
|
||||||
|
@ -412,7 +401,7 @@ vi_insert(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_add(EditLine *el, int c __attribute__((unused)))
|
vi_add(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -437,7 +426,7 @@ vi_add(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_map.current = el->el_map.key;
|
||||||
|
@ -453,7 +442,7 @@ vi_add_at_eol(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_delete_meta(EditLine *el, int c __attribute__((unused)))
|
vi_delete_meta(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
return (cv_action(el, DELETE));
|
return (cv_action(el, DELETE));
|
||||||
|
@ -466,7 +455,7 @@ vi_delete_meta(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor == el->el_line.lastchar)
|
||||||
|
@ -490,7 +479,7 @@ vi_end_big_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_line.cursor == el->el_line.lastchar)
|
||||||
|
@ -514,7 +503,7 @@ vi_end_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
c_undo_t un = el->el_chared.c_undo;
|
||||||
|
|
||||||
|
@ -540,7 +529,7 @@ vi_undo(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_command_mode(EditLine *el, int c __attribute__((unused)))
|
vi_command_mode(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
|
|
||||||
/* [Esc] cancels pending action */
|
/* [Esc] cancels pending action */
|
||||||
|
@ -585,20 +574,14 @@ vi_zero(EditLine *el, int c)
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_delete_prev_char(EditLine *el, int c __attribute__((unused)))
|
vi_delete_prev_char(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *cp;
|
|
||||||
|
|
||||||
cp = el->el_line.cursor;
|
if (el->el_line.cursor <= el->el_line.buffer)
|
||||||
if (cp <= el->el_line.buffer)
|
|
||||||
return (CC_ERROR);
|
return (CC_ERROR);
|
||||||
|
|
||||||
/* do the delete here so we dont mess up the undo and paste buffers */
|
c_delbefore1(el);
|
||||||
el->el_line.cursor = --cp;
|
el->el_line.cursor--;
|
||||||
for (; cp < el->el_line.lastchar; cp++)
|
|
||||||
cp[0] = cp[1];
|
|
||||||
el->el_line.lastchar = cp - 1;
|
|
||||||
|
|
||||||
return (CC_REFRESH);
|
return (CC_REFRESH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,23 +592,35 @@ vi_delete_prev_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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) {
|
||||||
if (el->el_line.cursor == el->el_line.lastchar &&
|
if (el->el_line.cursor == el->el_line.buffer) {
|
||||||
el->el_line.cursor == el->el_line.buffer) {
|
term_overwrite(el, STReof, 4); /* then do a EOF */
|
||||||
#endif
|
term__flush();
|
||||||
term_overwrite(el, STReof, 4); /* then do a EOF */
|
return (CC_EOF);
|
||||||
term__flush();
|
} else {
|
||||||
return (CC_EOF);
|
/*
|
||||||
#ifdef notyet
|
* Here we could list completions, but it is an
|
||||||
|
* error right now
|
||||||
|
*/
|
||||||
|
term_beep(el);
|
||||||
|
return (CC_ERROR);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef notyet
|
||||||
re_goto_bottom(el);
|
re_goto_bottom(el);
|
||||||
*el->el_line.lastchar = '\0'; /* just in case */
|
*el->el_line.lastchar = '\0'; /* just in case */
|
||||||
return (CC_LIST_CHOICES);
|
return (CC_LIST_CHOICES);
|
||||||
}
|
#else
|
||||||
|
/*
|
||||||
|
* Just complain for now.
|
||||||
|
*/
|
||||||
|
term_beep(el);
|
||||||
|
return (CC_ERROR);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -635,7 +630,7 @@ vi_list_or_eof(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_kill_line_prev(EditLine *el, int c __attribute__((unused)))
|
vi_kill_line_prev(EditLine *el, int c __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
char *kp, *cp;
|
char *kp, *cp;
|
||||||
|
|
||||||
|
@ -656,7 +651,7 @@ vi_kill_line_prev(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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));
|
return (cv_search(el, ED_SEARCH_PREV_HISTORY));
|
||||||
|
@ -669,7 +664,7 @@ vi_search_prev(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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));
|
return (cv_search(el, ED_SEARCH_NEXT_HISTORY));
|
||||||
|
@ -682,7 +677,7 @@ vi_search_next(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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)
|
if (el->el_search.patlen == 0)
|
||||||
|
@ -698,7 +693,7 @@ vi_repeat_search_next(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
protected el_action_t
|
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)
|
if (el->el_search.patlen == 0)
|
||||||
|
@ -716,7 +711,7 @@ vi_repeat_search_prev(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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);
|
return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0);
|
||||||
}
|
}
|
||||||
|
@ -728,7 +723,7 @@ vi_next_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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);
|
return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0);
|
||||||
}
|
}
|
||||||
|
@ -740,7 +735,7 @@ vi_prev_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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);
|
return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1);
|
||||||
}
|
}
|
||||||
|
@ -752,7 +747,7 @@ vi_to_next_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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);
|
return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1);
|
||||||
}
|
}
|
||||||
|
@ -764,7 +759,7 @@ vi_to_prev_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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,
|
return cv_csearch(el, el->el_search.chadir, el->el_search.chacha,
|
||||||
|
@ -778,7 +773,7 @@ vi_repeat_next_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el_action_t r;
|
||||||
int dir = el->el_search.chadir;
|
int dir = el->el_search.chadir;
|
||||||
|
@ -796,7 +791,7 @@ vi_repeat_prev_char(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_match(EditLine *el, int c __attribute__((unused)))
|
vi_match(EditLine *el, int c)
|
||||||
{
|
{
|
||||||
const char match_chars[] = "()[]{}";
|
const char match_chars[] = "()[]{}";
|
||||||
char *cp;
|
char *cp;
|
||||||
|
@ -843,7 +838,7 @@ vi_match(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_undo_line(EditLine *el, int c __attribute__((unused)))
|
vi_undo_line(EditLine *el, int c)
|
||||||
{
|
{
|
||||||
|
|
||||||
cv_undo(el);
|
cv_undo(el);
|
||||||
|
@ -857,7 +852,7 @@ vi_undo_line(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_line.cursor = el->el_line.buffer;
|
||||||
|
@ -871,7 +866,7 @@ vi_to_column(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_yank_end(EditLine *el, int c __attribute__((unused)))
|
vi_yank_end(EditLine *el, int c)
|
||||||
{
|
{
|
||||||
|
|
||||||
cv_yank(el, el->el_line.cursor,
|
cv_yank(el, el->el_line.cursor,
|
||||||
|
@ -885,7 +880,7 @@ vi_yank_end(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_yank(EditLine *el, int c __attribute__((unused)))
|
vi_yank(EditLine *el, int c)
|
||||||
{
|
{
|
||||||
|
|
||||||
return cv_action(el, YANK);
|
return cv_action(el, YANK);
|
||||||
|
@ -897,7 +892,7 @@ vi_yank(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
el->el_line.cursor = el->el_line.buffer;
|
||||||
|
@ -915,7 +910,7 @@ vi_comment_out(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_alias(EditLine *el __attribute__((unused)), int c __attribute__((unused)))
|
vi_alias(EditLine *el, int c)
|
||||||
{
|
{
|
||||||
#ifdef __weak_extern
|
#ifdef __weak_extern
|
||||||
char alias_name[3];
|
char alias_name[3];
|
||||||
|
@ -947,7 +942,7 @@ vi_alias(EditLine *el __attribute__((unused)), int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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;
|
int sv_event_no = el->el_history.eventno;
|
||||||
el_action_t rval;
|
el_action_t rval;
|
||||||
|
@ -992,7 +987,7 @@ vi_to_history_line(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_histedit(EditLine *el, int c __attribute__((unused)))
|
vi_histedit(EditLine *el, int c)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
@ -1048,7 +1043,7 @@ vi_histedit(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*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 *wp = HIST_FIRST(el);
|
||||||
const char *wep, *wsp;
|
const char *wep, *wsp;
|
||||||
|
@ -1097,7 +1092,7 @@ vi_history_word(EditLine *el, int c __attribute__((unused)))
|
||||||
*/
|
*/
|
||||||
protected el_action_t
|
protected el_action_t
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
vi_redo(EditLine *el, int c __attribute__((unused)))
|
vi_redo(EditLine *el, int c)
|
||||||
{
|
{
|
||||||
c_redo_t *r = &el->el_chared.c_redo;
|
c_redo_t *r = &el->el_chared.c_redo;
|
||||||
|
|
||||||
|
|
392
cmd-line-utils/libedit/vis.c
Normal file
392
cmd-line-utils/libedit/vis.c
Normal file
|
@ -0,0 +1,392 @@
|
||||||
|
/* $NetBSD: vis.c,v 1.27 2004/02/26 23:01:15 enami Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 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
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 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
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* AIX requires this to be the first thing in the file. */
|
||||||
|
#if defined (_AIX) && !defined (__GNUC__)
|
||||||
|
#pragma alloca
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
# undef alloca
|
||||||
|
# define alloca(n) __builtin_alloca (n)
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_ALLOCA_H
|
||||||
|
# include <alloca.h>
|
||||||
|
# else
|
||||||
|
# ifndef _AIX
|
||||||
|
extern char *alloca ();
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <vis.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef __weak_alias
|
||||||
|
__weak_alias(strsvis,_strsvis)
|
||||||
|
__weak_alias(strsvisx,_strsvisx)
|
||||||
|
__weak_alias(strvis,_strvis)
|
||||||
|
__weak_alias(strvisx,_strvisx)
|
||||||
|
__weak_alias(svis,_svis)
|
||||||
|
__weak_alias(vis,_vis)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !HAVE_VIS || !HAVE_SVIS
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#undef BELL
|
||||||
|
#define BELL '\a'
|
||||||
|
|
||||||
|
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
|
||||||
|
#define iswhite(c) (c == ' ' || c == '\t' || c == '\n')
|
||||||
|
#define issafe(c) (c == '\b' || c == BELL || c == '\r')
|
||||||
|
#define xtoa(c) "0123456789abcdef"[c]
|
||||||
|
|
||||||
|
#define MAXEXTRAS 5
|
||||||
|
|
||||||
|
|
||||||
|
#define MAKEEXTRALIST(flag, extra, orig) \
|
||||||
|
do { \
|
||||||
|
const char *o = orig; \
|
||||||
|
char *e; \
|
||||||
|
while (*o++) \
|
||||||
|
continue; \
|
||||||
|
extra = alloca((size_t)((o - orig) + MAXEXTRAS)); \
|
||||||
|
for (o = orig, e = extra; (*e++ = *o++) != '\0';) \
|
||||||
|
continue; \
|
||||||
|
e--; \
|
||||||
|
if (flag & VIS_SP) *e++ = ' '; \
|
||||||
|
if (flag & VIS_TAB) *e++ = '\t'; \
|
||||||
|
if (flag & VIS_NL) *e++ = '\n'; \
|
||||||
|
if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; \
|
||||||
|
*e = '\0'; \
|
||||||
|
} while (/*CONSTCOND*/0)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is HVIS, the macro of vis used to HTTP style (RFC 1808)
|
||||||
|
*/
|
||||||
|
#define HVIS(dst, c, flag, nextc, extra) \
|
||||||
|
do \
|
||||||
|
if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { \
|
||||||
|
*dst++ = '%'; \
|
||||||
|
*dst++ = xtoa(((unsigned int)c >> 4) & 0xf); \
|
||||||
|
*dst++ = xtoa((unsigned int)c & 0xf); \
|
||||||
|
} else { \
|
||||||
|
SVIS(dst, c, flag, nextc, extra); \
|
||||||
|
} \
|
||||||
|
while (/*CONSTCOND*/0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is SVIS, the central macro of vis.
|
||||||
|
* dst: Pointer to the destination buffer
|
||||||
|
* c: Character to encode
|
||||||
|
* flag: Flag word
|
||||||
|
* nextc: The character following 'c'
|
||||||
|
* extra: Pointer to the list of extra characters to be
|
||||||
|
* backslash-protected.
|
||||||
|
*/
|
||||||
|
#define SVIS(dst, c, flag, nextc, extra) \
|
||||||
|
do { \
|
||||||
|
int isextra; \
|
||||||
|
isextra = strchr(extra, c) != NULL; \
|
||||||
|
if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \
|
||||||
|
((flag & VIS_SAFE) && issafe(c)))) { \
|
||||||
|
*dst++ = c; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
if (flag & VIS_CSTYLE) { \
|
||||||
|
switch (c) { \
|
||||||
|
case '\n': \
|
||||||
|
*dst++ = '\\'; *dst++ = 'n'; \
|
||||||
|
continue; \
|
||||||
|
case '\r': \
|
||||||
|
*dst++ = '\\'; *dst++ = 'r'; \
|
||||||
|
continue; \
|
||||||
|
case '\b': \
|
||||||
|
*dst++ = '\\'; *dst++ = 'b'; \
|
||||||
|
continue; \
|
||||||
|
case BELL: \
|
||||||
|
*dst++ = '\\'; *dst++ = 'a'; \
|
||||||
|
continue; \
|
||||||
|
case '\v': \
|
||||||
|
*dst++ = '\\'; *dst++ = 'v'; \
|
||||||
|
continue; \
|
||||||
|
case '\t': \
|
||||||
|
*dst++ = '\\'; *dst++ = 't'; \
|
||||||
|
continue; \
|
||||||
|
case '\f': \
|
||||||
|
*dst++ = '\\'; *dst++ = 'f'; \
|
||||||
|
continue; \
|
||||||
|
case ' ': \
|
||||||
|
*dst++ = '\\'; *dst++ = 's'; \
|
||||||
|
continue; \
|
||||||
|
case '\0': \
|
||||||
|
*dst++ = '\\'; *dst++ = '0'; \
|
||||||
|
if (isoctal(nextc)) { \
|
||||||
|
*dst++ = '0'; \
|
||||||
|
*dst++ = '0'; \
|
||||||
|
} \
|
||||||
|
continue; \
|
||||||
|
default: \
|
||||||
|
if (isgraph(c)) { \
|
||||||
|
*dst++ = '\\'; *dst++ = c; \
|
||||||
|
continue; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \
|
||||||
|
*dst++ = '\\'; \
|
||||||
|
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0'; \
|
||||||
|
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0'; \
|
||||||
|
*dst++ = (c & 07) + '0'; \
|
||||||
|
} else { \
|
||||||
|
if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \
|
||||||
|
if (c & 0200) { \
|
||||||
|
c &= 0177; *dst++ = 'M'; \
|
||||||
|
} \
|
||||||
|
if (iscntrl(c)) { \
|
||||||
|
*dst++ = '^'; \
|
||||||
|
if (c == 0177) \
|
||||||
|
*dst++ = '?'; \
|
||||||
|
else \
|
||||||
|
*dst++ = c + '@'; \
|
||||||
|
} else { \
|
||||||
|
*dst++ = '-'; *dst++ = c; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (/*CONSTCOND*/0)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* svis - visually encode characters, also encoding the characters
|
||||||
|
* pointed to by `extra'
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
svis(dst, c, flag, nextc, extra)
|
||||||
|
char *dst;
|
||||||
|
int c, flag, nextc;
|
||||||
|
const char *extra;
|
||||||
|
{
|
||||||
|
char *nextra;
|
||||||
|
_DIAGASSERT(dst != NULL);
|
||||||
|
_DIAGASSERT(extra != NULL);
|
||||||
|
MAKEEXTRALIST(flag, nextra, extra);
|
||||||
|
if (flag & VIS_HTTPSTYLE)
|
||||||
|
HVIS(dst, c, flag, nextc, nextra);
|
||||||
|
else
|
||||||
|
SVIS(dst, c, flag, nextc, nextra);
|
||||||
|
*dst = '\0';
|
||||||
|
return(dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* strsvis, strsvisx - visually encode characters from src into dst
|
||||||
|
*
|
||||||
|
* Extra is a pointer to a \0-terminated list of characters to
|
||||||
|
* be encoded, too. These functions are useful e. g. to
|
||||||
|
* encode strings in such a way so that they are not interpreted
|
||||||
|
* by a shell.
|
||||||
|
*
|
||||||
|
* Dst must be 4 times the size of src to account for possible
|
||||||
|
* expansion. The length of dst, not including the trailing NULL,
|
||||||
|
* is returned.
|
||||||
|
*
|
||||||
|
* Strsvisx encodes exactly len bytes from src into dst.
|
||||||
|
* This is useful for encoding a block of data.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
strsvis(dst, csrc, flag, extra)
|
||||||
|
char *dst;
|
||||||
|
const char *csrc;
|
||||||
|
int flag;
|
||||||
|
const char *extra;
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
char *start;
|
||||||
|
char *nextra;
|
||||||
|
const unsigned char *src = (const unsigned char *)csrc;
|
||||||
|
|
||||||
|
_DIAGASSERT(dst != NULL);
|
||||||
|
_DIAGASSERT(src != NULL);
|
||||||
|
_DIAGASSERT(extra != NULL);
|
||||||
|
MAKEEXTRALIST(flag, nextra, extra);
|
||||||
|
if (flag & VIS_HTTPSTYLE) {
|
||||||
|
for (start = dst; (c = *src++) != '\0'; /* empty */)
|
||||||
|
HVIS(dst, c, flag, *src, nextra);
|
||||||
|
} else {
|
||||||
|
for (start = dst; (c = *src++) != '\0'; /* empty */)
|
||||||
|
SVIS(dst, c, flag, *src, nextra);
|
||||||
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
return (dst - start);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
strsvisx(dst, csrc, len, flag, extra)
|
||||||
|
char *dst;
|
||||||
|
const char *csrc;
|
||||||
|
size_t len;
|
||||||
|
int flag;
|
||||||
|
const char *extra;
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
char *start;
|
||||||
|
char *nextra;
|
||||||
|
const unsigned char *src = (const unsigned char *)csrc;
|
||||||
|
|
||||||
|
_DIAGASSERT(dst != NULL);
|
||||||
|
_DIAGASSERT(src != NULL);
|
||||||
|
_DIAGASSERT(extra != NULL);
|
||||||
|
MAKEEXTRALIST(flag, nextra, extra);
|
||||||
|
|
||||||
|
if (flag & VIS_HTTPSTYLE) {
|
||||||
|
for (start = dst; len > 0; len--) {
|
||||||
|
c = *src++;
|
||||||
|
HVIS(dst, c, flag, len ? *src : '\0', nextra);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (start = dst; len > 0; len--) {
|
||||||
|
c = *src++;
|
||||||
|
SVIS(dst, c, flag, len ? *src : '\0', nextra);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
return (dst - start);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !HAVE_VIS
|
||||||
|
/*
|
||||||
|
* vis - visually encode characters
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
vis(dst, c, flag, nextc)
|
||||||
|
char *dst;
|
||||||
|
int c, flag, nextc;
|
||||||
|
|
||||||
|
{
|
||||||
|
char *extra;
|
||||||
|
|
||||||
|
_DIAGASSERT(dst != NULL);
|
||||||
|
|
||||||
|
MAKEEXTRALIST(flag, extra, "");
|
||||||
|
if (flag & VIS_HTTPSTYLE)
|
||||||
|
HVIS(dst, c, flag, nextc, extra);
|
||||||
|
else
|
||||||
|
SVIS(dst, c, flag, nextc, extra);
|
||||||
|
*dst = '\0';
|
||||||
|
return (dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* strvis, strvisx - visually encode characters from src into dst
|
||||||
|
*
|
||||||
|
* Dst must be 4 times the size of src to account for possible
|
||||||
|
* expansion. The length of dst, not including the trailing NULL,
|
||||||
|
* is returned.
|
||||||
|
*
|
||||||
|
* Strvisx encodes exactly len bytes from src into dst.
|
||||||
|
* This is useful for encoding a block of data.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
strvis(dst, src, flag)
|
||||||
|
char *dst;
|
||||||
|
const char *src;
|
||||||
|
int flag;
|
||||||
|
{
|
||||||
|
char *extra;
|
||||||
|
|
||||||
|
MAKEEXTRALIST(flag, extra, "");
|
||||||
|
return (strsvis(dst, src, flag, extra));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
strvisx(dst, src, len, flag)
|
||||||
|
char *dst;
|
||||||
|
const char *src;
|
||||||
|
size_t len;
|
||||||
|
int flag;
|
||||||
|
{
|
||||||
|
char *extra;
|
||||||
|
|
||||||
|
MAKEEXTRALIST(flag, extra, "");
|
||||||
|
return (strsvisx(dst, src, len, flag, extra));
|
||||||
|
}
|
||||||
|
#endif
|
92
cmd-line-utils/libedit/vis.h
Normal file
92
cmd-line-utils/libedit/vis.h
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/* $NetBSD: vis.h,v 1.15 2005/02/03 04:39:32 perry Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 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. 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.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)vis.h 8.1 (Berkeley) 6/2/93
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _VIS_H_
|
||||||
|
#define _VIS_H_
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* to select alternate encoding format
|
||||||
|
*/
|
||||||
|
#define VIS_OCTAL 0x01 /* use octal \ddd format */
|
||||||
|
#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropiate */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* to alter set of characters encoded (default is to encode all
|
||||||
|
* non-graphic except space, tab, and newline).
|
||||||
|
*/
|
||||||
|
#define VIS_SP 0x04 /* also encode space */
|
||||||
|
#define VIS_TAB 0x08 /* also encode tab */
|
||||||
|
#define VIS_NL 0x10 /* also encode newline */
|
||||||
|
#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
|
||||||
|
#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* other
|
||||||
|
*/
|
||||||
|
#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
|
||||||
|
#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unvis return codes
|
||||||
|
*/
|
||||||
|
#define UNVIS_VALID 1 /* character valid */
|
||||||
|
#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */
|
||||||
|
#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */
|
||||||
|
#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */
|
||||||
|
#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unvis flags
|
||||||
|
*/
|
||||||
|
#define UNVIS_END 1 /* no more characters */
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
char *vis(char *, int, int, int);
|
||||||
|
char *svis(char *, int, int, int, const char *);
|
||||||
|
int strvis(char *, const char *, int);
|
||||||
|
int strsvis(char *, const char *, int, const char *);
|
||||||
|
int strvisx(char *, const char *, size_t, int);
|
||||||
|
int strsvisx(char *, const char *, size_t, int, const char *);
|
||||||
|
int strunvis(char *, const char *);
|
||||||
|
int strunvisx(char *, const char *, int);
|
||||||
|
#ifdef __LIBC12_SOURCE__
|
||||||
|
int unvis(char *, int, int *, int);
|
||||||
|
int __unvis13(char *, int, int *, int);
|
||||||
|
#else
|
||||||
|
int unvis(char *, int, int *, int);
|
||||||
|
#endif
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* !_VIS_H_ */
|
Loading…
Reference in a new issue