summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libedit/common.c2
-rw-r--r--lib/libedit/editline.3112
-rw-r--r--lib/libedit/editrc.532
-rw-r--r--lib/libedit/el.c46
-rw-r--r--lib/libedit/el.h1
-rw-r--r--lib/libedit/histedit.h6
-rw-r--r--lib/libedit/history.c109
-rw-r--r--lib/libedit/key.c35
-rw-r--r--lib/libedit/key.h4
-rw-r--r--lib/libedit/prompt.c50
-rw-r--r--lib/libedit/prompt.h6
-rw-r--r--lib/libedit/read.c105
-rw-r--r--lib/libedit/refresh.c213
-rw-r--r--lib/libedit/search.c4
-rw-r--r--lib/libedit/sig.c78
-rw-r--r--lib/libedit/sig.h9
-rw-r--r--lib/libedit/term.c184
-rw-r--r--lib/libedit/term.h6
-rw-r--r--lib/libedit/tty.c2
-rw-r--r--lib/libedit/vi.c40
20 files changed, 634 insertions, 410 deletions
diff --git a/lib/libedit/common.c b/lib/libedit/common.c
index d314eef..0599554 100644
--- a/lib/libedit/common.c
+++ b/lib/libedit/common.c
@@ -905,7 +905,7 @@ ed_command(EditLine *el, int c __unused)
int tmplen;
tmplen = c_gets(el, tmpbuf, "\n: ");
- term__putc('\n');
+ term__putc(el, '\n');
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
term_beep(el);
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3
index 9661d66..fe58321 100644
--- a/lib/libedit/editline.3
+++ b/lib/libedit/editline.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: editline.3,v 1.55 2007/01/12 16:31:13 christos Exp $
+.\" $NetBSD: editline.3,v 1.70 2009/07/05 21:55:24 perry Exp $
.\"
.\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 12, 2007
+.Dd July 5, 2009
.Dt EDITLINE 3
.Os
.Sh NAME
@@ -162,6 +162,14 @@ is modified to contain the number of characters read.
Returns the line read if successful, or
.Dv NULL
if no characters were read or if an error occurred.
+If an error occurred,
+.Fa count
+is set to \-1 and
+.Dv errno
+contains the error code that caused it.
+The return value may not remain valid across calls to
+.Fn el_gets
+and must be copied if the data is to be retained.
.It Fn el_getc
Read a character from the tty.
.Fa ch
@@ -222,10 +230,30 @@ are supported, along with the required argument list:
Define prompt printing function as
.Fa f ,
which is to return a string that contains the prompt.
+.It Dv EL_PROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c"
+Same as
+.Dv EL_PROMPT ,
+but the
+.Fa c
+argument indicates the start/stop literal prompt character.
+.Pp
+If a start/stop literal character is found in the prompt, the
+character itself
+is not printed, but characters after it are printed directly to the
+terminal without affecting the state of the current line.
+A subsequent second start/stop literal character ends this behavior.
+This is typically used to embed literal escape sequences that change the
+color/style of the terminal in the prompt.
+.Dv 0
+unsets it.
+.It Dv EL_REFRESH
+Re-display the current line on the next terminal line.
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
Define right side prompt printing function as
.Fa f ,
which is to return a string that contains the prompt.
+.It Dv EL_RPROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c"
+Define the right prompt printing function but with a literal escape character.
.It Dv EL_TERMINAL , Fa "const char *type"
Define terminal type of the tty to be
.Fa type ,
@@ -259,66 +287,43 @@ reading command input:
and
.Dv SIGWINCH .
Otherwise, the current signal handlers will be used.
-.It Dv EL_BIND , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_BIND , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic bind
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_ECHOTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_ECHOTC , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic echotc
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_SETTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_SETTC , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic settc
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_SETTY , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_SETTY , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic setty
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_TELLTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_TELLTC , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic telltc
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_ADDFN , Xo
-.Fa "const char *name" ,
-.Fa "const char *help" ,
-.Fa "unsigned char (*func)(EditLine *e, int ch)"
-.Xc
+.It Dv EL_ADDFN , Fa "const char *name" , Fa "const char *help" , \
+Fa "unsigned char (*func)(EditLine *e, int ch)"
Add a user defined function,
.Fn func ,
referred to as
@@ -360,10 +365,8 @@ Beep, and flush tty.
.It Dv CC_FATAL
Fatal error, reset tty to known state.
.El
-.It Dv EL_HIST , Xo
-.Fa "History *(*func)(History *, int op, ...)" ,
-.Fa "const char *ptr"
-.Xc
+.It Dv EL_HIST , Fa "History *(*func)(History *, int op, ...)" , \
+Fa "const char *ptr"
Defines which history function to use, which is usually
.Fn history .
.Fa ptr
@@ -435,10 +438,22 @@ The following values for
are supported, along with actual type of
.Fa result :
.Bl -tag -width 4n
-.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
-Return a pointer to the function that displays the prompt.
-.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
-Return a pointer to the function that displays the rightside prompt.
+.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c"
+Return a pointer to the function that displays the prompt in
+.Fa f .
+If
+.Fa c
+is not
+.Dv NULL ,
+return the start/stop literal prompt character in it.
+.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c"
+Return a pointer to the function that displays the prompt in
+.Fa f .
+If
+.Fa c
+is not
+.Dv NULL ,
+return the start/stop literal prompt character in it.
.It Dv EL_EDITOR , Fa "const char *"
Return the name of the editor, which will be one of
.Dq emacs
@@ -603,18 +618,11 @@ assumed to be created with
.Fn history_init .
.It Dv H_CLEAR
Clear the history.
-.It Dv H_FUNC , Xo
-.Fa "void *ptr" ,
-.Fa "history_gfun_t first" ,
-.Fa "history_gfun_t next" ,
-.Fa "history_gfun_t last" ,
-.Fa "history_gfun_t prev" ,
-.Fa "history_gfun_t curr" ,
-.Fa "history_sfun_t set" ,
-.Fa "history_vfun_t clear" ,
-.Fa "history_efun_t enter" ,
-.Fa "history_efun_t add"
-.Xc
+.It Dv H_FUNC , Fa "void *ptr" , Fa "history_gfun_t first" , \
+Fa "history_gfun_t next" , Fa "history_gfun_t last" , \
+Fa "history_gfun_t prev" , Fa "history_gfun_t curr" , \
+Fa "history_sfun_t set" , Fa "history_vfun_t clear" , \
+Fa "history_efun_t enter" , Fa "history_efun_t add"
Define functions to perform various history operations.
.Fa ptr
is the argument given to a function when it is invoked.
diff --git a/lib/libedit/editrc.5 b/lib/libedit/editrc.5
index 2fa1a63..d276670 100644
--- a/lib/libedit/editrc.5
+++ b/lib/libedit/editrc.5
@@ -1,4 +1,4 @@
-.\" $NetBSD: editrc.5,v 1.20 2006/08/21 12:45:30 christos Exp $
+.\" $NetBSD: editrc.5,v 1.24 2009/04/11 22:17:52 wiz Exp $
.\"
.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -89,16 +89,8 @@ shell.
.Pp
The following builtin commands are available:
.Bl -tag -width 4n
-.It Ic bind Xo
-.Op Fl a
-.Op Fl e
-.Op Fl k
-.Op Fl l
-.Op Fl r
-.Op Fl s
-.Op Fl v
-.Op Ar key Op Ar command
-.Xc
+.It Ic bind Oo Fl a Oc Oo Fl e Oc Oo Fl k Oc Oo Fl l Oc Oo Fl r Oc \
+Oo Fl s Oc Oo Fl v Oc Oo Ar key Op Ar command Oc
Without options, list all bound keys, and the editor command to which
each is bound.
If
@@ -192,11 +184,7 @@ if it has any, notably
.Sq \e
and
.Sq ^ .
-.It Ic echotc Xo
-.Op Fl sv
-.Ar arg
-.Ar ...
-.Xc
+.It Ic echotc Oo Fl sv Oc Ar arg Ar ...
Exercise terminal capabilities given in
.Ar arg Ar ... .
If
@@ -252,16 +240,8 @@ to
as defined in
.Xr termcap 5 .
No sanity checking is done.
-.It Ic setty Xo
-.Op Fl a
-.Op Fl d
-.Op Fl q
-.Op Fl x
-.Op Ar +mode
-.Op Ar -mode
-.Op Ar mode
-.Op Ar char=c
-.Xc
+.It Ic setty Oo Fl a Oc Oo Fl d Oc Oo Fl q Oc Oo Fl x Oc Oo Ar +mode Oc \
+Oo Ar -mode Oc Oo Ar mode Oc Oo Ar char=c Oc
Control which tty modes that
.Nm
will not allow the user to change.
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index 3b4036f..8dcd698 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: el.c,v 1.44 2006/12/15 22:13:33 christos Exp $
+ * $NetBSD: el.c,v 1.55 2009/07/25 21:19:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <ctype.h>
#include "el.h"
#define HAVE_ISSETUGID
@@ -156,9 +157,21 @@ el_set(EditLine *el, int op, ...)
switch (op) {
case EL_PROMPT:
- case EL_RPROMPT:
- rv = prompt_set(el, va_arg(ap, el_pfunc_t), op);
+ case EL_RPROMPT: {
+ el_pfunc_t p = va_arg(ap, el_pfunc_t);
+
+ rv = prompt_set(el, p, 0, op);
break;
+ }
+
+ case EL_PROMPT_ESC:
+ case EL_RPROMPT_ESC: {
+ el_pfunc_t p = va_arg(ap, el_pfunc_t);
+ char c = va_arg(ap, int);
+
+ rv = prompt_set(el, p, c, op);
+ break;
+ }
case EL_TERMINAL:
rv = term_set(el, va_arg(ap, char *));
@@ -309,6 +322,12 @@ el_set(EditLine *el, int op, ...)
break;
}
+ case EL_REFRESH:
+ re_clear_display(el);
+ re_refresh(el);
+ term__flush(el);
+ break;
+
default:
rv = -1;
break;
@@ -335,9 +354,13 @@ el_get(EditLine *el, int op, ...)
switch (op) {
case EL_PROMPT:
- case EL_RPROMPT:
- rv = prompt_get(el, va_arg(ap, el_pfunc_t *), op);
+ case EL_RPROMPT: {
+ el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
+ char *c = va_arg(ap, char *);
+
+ rv = prompt_get(el, p, c, op);
break;
+ }
case EL_EDITOR:
rv = map_get_editor(el, va_arg(ap, const char **));
@@ -364,7 +387,7 @@ el_get(EditLine *el, int op, ...)
char *argv[20];
int i;
- for (i = 1; i < sizeof(argv) / sizeof(argv[0]); i++)
+ for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
@@ -495,12 +518,14 @@ el_source(EditLine *el, const char *fname)
FILE *fp;
size_t len;
char *ptr;
+#ifdef HAVE_ISSETUGID
+ char path[MAXPATHLEN];
+#endif
fp = NULL;
if (fname == NULL) {
#ifdef HAVE_ISSETUGID
static const char elpath[] = "/.editrc";
- char path[MAXPATHLEN];
if (issetugid())
return (-1);
@@ -529,6 +554,13 @@ el_source(EditLine *el, const char *fname)
if (len > 0 && ptr[len - 1] == '\n')
--len;
ptr[len] = '\0';
+
+ /* loop until first non-space char or EOL */
+ while (*ptr != '\0' && isspace((unsigned char)*ptr))
+ ptr++;
+ if (*ptr == '#')
+ continue; /* ignore, this is a comment line */
+
if (parse_line(el, ptr) == -1) {
(void) fclose(fp);
return (-1);
diff --git a/lib/libedit/el.h b/lib/libedit/el.h
index 8d0d152..67d01ff 100644
--- a/lib/libedit/el.h
+++ b/lib/libedit/el.h
@@ -115,6 +115,7 @@ struct editline {
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
int el_flags; /* Various flags. */
+ int el_errno; /* Local copy of errno */
coord_t el_cursor; /* Cursor location */
char **el_display; /* Real screen image = what is there */
char **el_vdisplay; /* Virtual screen image = what we see */
diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h
index 8417bb3..24af1d5 100644
--- a/lib/libedit/histedit.h
+++ b/lib/libedit/histedit.h
@@ -131,10 +131,10 @@ unsigned char _el_fn_sh_complete(EditLine *, int);
#define EL_GETCFN 13 /* , el_rfunc_t); */
#define EL_CLIENTDATA 14 /* , void *); */
#define EL_UNBUFFERED 15 /* , int); */
-#define EL_PREP_TERM 16 /* , int); */
+#define EL_PREP_TERM 16 /* , int); */
#define EL_GETTC 17 /* , const char *, ..., NULL); */
-#define EL_GETFP 18 /* , int, FILE **) */
-#define EL_SETFP 19 /* , int, FILE *) */
+#define EL_GETFP 18 /* , int, FILE **); */
+#define EL_SETFP 19 /* , int, FILE *); */
#define EL_REFRESH 20 /* , void); set */
#define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */
#define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */
diff --git a/lib/libedit/history.c b/lib/libedit/history.c
index 76b3b07..8f30a05 100644
--- a/lib/libedit/history.c
+++ b/lib/libedit/history.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: history.c,v 1.32 2006/09/28 13:52:51 christos Exp $
+ * $NetBSD: history.c,v 1.34 2009/09/07 21:24:33 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -116,6 +116,7 @@ private int history_prev_string(History *, HistEvent *, const char *);
*/
typedef struct hentry_t {
HistEvent ev; /* What we return */
+ void *data; /* data */
struct hentry_t *next; /* Next entry */
struct hentry_t *prev; /* Previous entry */
} hentry_t;
@@ -145,6 +146,9 @@ private int history_def_init(ptr_t *, HistEvent *, int);
private int history_def_insert(history_t *, HistEvent *, const char *);
private void history_def_delete(history_t *, HistEvent *, hentry_t *);
+private int history_deldata_nth(history_t *, HistEvent *, int, void **);
+private int history_set_nth(ptr_t, HistEvent *, int);
+
#define history_def_setsize(p, num)(void) (((history_t *)p)->max = (num))
#define history_def_getsize(p) (((history_t *)p)->cur)
#define history_def_getunique(p) (((((history_t *)p)->flags) & H_UNIQUE) != 0)
@@ -335,6 +339,31 @@ history_def_set(ptr_t p, HistEvent *ev, const int n)
}
+/* history_set_nth():
+ * Default function to set the current event in the history to the
+ * n-th one.
+ */
+private int
+history_set_nth(ptr_t p, HistEvent *ev, int n)
+{
+ history_t *h = (history_t *) p;
+
+ if (h->cur == 0) {
+ he_seterrev(ev, _HE_EMPTY_LIST);
+ return (-1);
+ }
+ for (h->cursor = h->list.prev; h->cursor != &h->list;
+ h->cursor = h->cursor->prev)
+ if (n-- <= 0)
+ break;
+ if (h->cursor == &h->list) {
+ he_seterrev(ev, _HE_NOT_FOUND);
+ return (-1);
+ }
+ return (0);
+}
+
+
/* history_def_add():
* Append string to element
*/
@@ -363,6 +392,24 @@ history_def_add(ptr_t p, HistEvent *ev, const char *str)
}
+private int
+history_deldata_nth(history_t *h, HistEvent *ev,
+ int num, void **data)
+{
+ if (history_set_nth(h, ev, num) != 0)
+ return (-1);
+ /* magic value to skip delete (just set to n-th history) */
+ if (data == (void **)-1)
+ return (0);
+ ev->str = strdup(h->cursor->ev.str);
+ ev->num = h->cursor->ev.num;
+ if (data)
+ *data = h->cursor->data;
+ history_def_delete(h, ev, h->cursor);
+ return (0);
+}
+
+
/* history_def_del():
* Delete element hp of the h list
*/
@@ -392,8 +439,11 @@ history_def_delete(history_t *h,
HistEventPrivate *evp = (void *)&hp->ev;
if (hp == &h->list)
abort();
- if (h->cursor == hp)
+ if (h->cursor == hp) {
h->cursor = hp->prev;
+ if (h->cursor == &h->list)
+ h->cursor = hp->next;
+ }
hp->prev->next = hp->next;
hp->next->prev = hp->prev;
h_free((ptr_t) evp->str);
@@ -416,6 +466,7 @@ history_def_insert(history_t *h, HistEvent *ev, const char *str)
h_free((ptr_t)h->cursor);
goto oomem;
}
+ h->cursor->data = NULL;
h->cursor->ev.num = ++h->eventid;
h->cursor->next = h->list.next;
h->cursor->prev = &h->list;
@@ -711,8 +762,8 @@ history_load(History *h, const char *fname)
(void) strunvis(ptr, line);
line[sz] = c;
if (HENTER(h, &ev, ptr) == -1) {
- h_free((ptr_t)ptr);
- return -1;
+ i = -1;
+ goto oomem;
}
}
oomem:
@@ -787,6 +838,23 @@ history_prev_event(History *h, HistEvent *ev, int num)
}
+private int
+history_next_evdata(History *h, HistEvent *ev, int num, void **d)
+{
+ int retval;
+
+ for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
+ if (num-- <= 0) {
+ if (d)
+ *d = ((history_t *)h->h_ref)->cursor->data;
+ return (0);
+ }
+
+ he_seterrev(ev, _HE_NOT_FOUND);
+ return (-1);
+}
+
+
/* history_next_event():
* Find the next event, with number given
*/
@@ -976,11 +1044,42 @@ history(History *h, HistEvent *ev, int fun, ...)
retval = 0;
break;
+ case H_NEXT_EVDATA:
+ {
+ int num = va_arg(va, int);
+ void **d = va_arg(va, void **);
+ retval = history_next_evdata(h, ev, num, d);
+ break;
+ }
+
+ case H_DELDATA:
+ {
+ int num = va_arg(va, int);
+ void **d = va_arg(va, void **);
+ retval = history_deldata_nth((history_t *)h->h_ref, ev, num, d);
+ break;
+ }
+
+ case H_REPLACE: /* only use after H_NEXT_EVDATA */
+ {
+ const char *line = va_arg(va, const char *);
+ void *d = va_arg(va, void *);
+ const char *s;
+ if(!line || !(s = strdup(line))) {
+ retval = -1;
+ break;
+ }
+ ((history_t *)h->h_ref)->cursor->ev.str = s;
+ ((history_t *)h->h_ref)->cursor->data = d;
+ retval = 0;
+ break;
+ }
+
default:
retval = -1;
he_seterrev(ev, _HE_UNKNOWN);
break;
}
va_end(va);
- return (retval);
+ return retval;
}
diff --git a/lib/libedit/key.c b/lib/libedit/key.c
index 0b9d05d..5a0b779 100644
--- a/lib/libedit/key.c
+++ b/lib/libedit/key.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: key.c,v 1.19 2006/03/23 20:22:51 christos Exp $
+ * $NetBSD: key.c,v 1.20 2009/02/15 21:55:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -86,8 +86,8 @@ private void node__free(key_node_t *);
private void node__put(EditLine *, key_node_t *);
private int node__delete(EditLine *, key_node_t **, const char *);
private int node_lookup(EditLine *, const char *, key_node_t *,
- int);
-private int node_enum(EditLine *, key_node_t *, int);
+ size_t);
+private int node_enum(EditLine *, key_node_t *, size_t);
#define KEY_BUFSIZ EL_BUFSIZ
@@ -478,9 +478,9 @@ node__free(key_node_t *k)
* Print if last node
*/
private int
-node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
+node_lookup(EditLine *el, const char *str, key_node_t *ptr, size_t cnt)
{
- int ncnt;
+ size_t ncnt;
if (ptr == NULL)
return (-1); /* cannot have null ptr */
@@ -493,7 +493,8 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
/* If match put this char into el->el_key.buf. Recurse */
if (ptr->ch == *str) {
/* match found */
- ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
+ ncnt = key__decode_char(el->el_key.buf,
+ (size_t)KEY_BUFSIZ, cnt,
(unsigned char) ptr->ch);
if (ptr->next != NULL)
/* not yet at leaf */
@@ -527,9 +528,9 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
* Traverse the node printing the characters it is bound in buffer
*/
private int
-node_enum(EditLine *el, key_node_t *ptr, int cnt)
+node_enum(EditLine *el, key_node_t *ptr, size_t cnt)
{
- int ncnt;
+ size_t ncnt;
if (cnt >= KEY_BUFSIZ - 5) { /* buffer too small */
el->el_key.buf[++cnt] = '"';
@@ -547,7 +548,7 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt)
return (-1);
}
/* put this char at end of str */
- ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
+ ncnt = key__decode_char(el->el_key.buf, (size_t)KEY_BUFSIZ, cnt,
(unsigned char)ptr->ch);
if (ptr->next == NULL) {
/* print this key and function */
@@ -615,8 +616,8 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
/* key__decode_char():
* Put a printable form of char in buf.
*/
-protected int
-key__decode_char(char *buf, int cnt, int off, int ch)
+protected size_t
+key__decode_char(char *buf, size_t cnt, size_t off, int ch)
{
char *sb = buf + off;
char *eb = buf + cnt;
@@ -626,7 +627,7 @@ key__decode_char(char *buf, int cnt, int off, int ch)
if (ch == 0) {
ADDC('^');
ADDC('@');
- return b - sb;
+ return (int)(b - sb);
}
if (iscntrl(ch)) {
ADDC('^');
@@ -648,15 +649,15 @@ key__decode_char(char *buf, int cnt, int off, int ch)
ADDC((((unsigned int) ch >> 3) & 7) + '0');
ADDC((ch & 7) + '0');
}
- return b - sb;
+ return (size_t)(b - sb);
}
/* key__decode_str():
* Make a printable version of the ey
*/
-protected int
-key__decode_str(const char *str, char *buf, int len, const char *sep)
+protected size_t
+key__decode_str(const char *str, char *buf, size_t len, const char *sep)
{
char *b = buf, *eb = b + len;
const char *p;
@@ -699,7 +700,7 @@ key__decode_str(const char *str, char *buf, int len, const char *sep)
}
done:
ADDC('\0');
- if (b - buf >= len)
+ if ((size_t)(b - buf) >= len)
buf[len - 1] = '\0';
- return b - buf;
+ return (size_t)(b - buf);
}
diff --git a/lib/libedit/key.h b/lib/libedit/key.h
index 3a21292..1997adc 100644
--- a/lib/libedit/key.h
+++ b/lib/libedit/key.h
@@ -76,8 +76,8 @@ protected int key_delete(EditLine *, const char *);
protected void key_print(EditLine *, const char *);
protected void key_kprint(EditLine *, const char *, key_value_t *,
int);
-protected int key__decode_str(const char *, char *, int,
+protected size_t key__decode_str(const char *, char *, size_t,
const char *);
-protected int key__decode_char(char *, int, int, int);
+protected size_t key__decode_char(char *, size_t, size_t, int);
#endif /* _h_el_key */
diff --git a/lib/libedit/prompt.c b/lib/libedit/prompt.c
index 3d72da7..76d2d64 100644
--- a/lib/libedit/prompt.c
+++ b/lib/libedit/prompt.c
@@ -85,14 +85,23 @@ prompt_print(EditLine *el, int op)
{
el_prompt_t *elp;
char *p;
+ int ignore = 0;
if (op == EL_PROMPT)
elp = &el->el_prompt;
else
elp = &el->el_rprompt;
- p = (elp->p_func) (el);
- while (*p)
- re_putc(el, *p++, 1);
+
+ for (p = (*elp->p_func)(el); *p; p++) {
+ if (elp->p_ignore == *p) {
+ ignore = !ignore;
+ continue;
+ }
+ if (ignore)
+ term__putc(el, *p);
+ else
+ re_putc(el, *p, 1);
+ }
elp->p_pos.v = el->el_refresh.r_cursor.v;
elp->p_pos.h = el->el_refresh.r_cursor.h;
@@ -109,10 +118,12 @@ prompt_init(EditLine *el)
el->el_prompt.p_func = prompt_default;
el->el_prompt.p_pos.v = 0;
el->el_prompt.p_pos.h = 0;
+ el->el_prompt.p_ignore = '\0';
el->el_rprompt.p_func = prompt_default_r;
el->el_rprompt.p_pos.v = 0;
el->el_rprompt.p_pos.h = 0;
- return (0);
+ el->el_rprompt.p_ignore = '\0';
+ return 0;
}
@@ -130,24 +141,29 @@ prompt_end(EditLine *el __unused)
* Install a prompt printing function
*/
protected int
-prompt_set(EditLine *el, el_pfunc_t prf, int op)
+prompt_set(EditLine *el, el_pfunc_t prf, char c, int op)
{
el_prompt_t *p;
- if (op == EL_PROMPT)
+ if (op == EL_PROMPT || op == EL_PROMPT_ESC)
p = &el->el_prompt;
else
p = &el->el_rprompt;
+
if (prf == NULL) {
- if (op == EL_PROMPT)
+ if (op == EL_PROMPT || op == EL_PROMPT_ESC)
p->p_func = prompt_default;
else
p->p_func = prompt_default_r;
} else
p->p_func = prf;
+
+ p->p_ignore = c;
+
p->p_pos.v = 0;
p->p_pos.h = 0;
- return (0);
+
+ return 0;
}
@@ -155,14 +171,22 @@ prompt_set(EditLine *el, el_pfunc_t prf, int op)
* Retrieve the prompt printing function
*/
protected int
-prompt_get(EditLine *el, el_pfunc_t *prf, int op)
+prompt_get(EditLine *el, el_pfunc_t *prf, char *c, int op)
{
+ el_prompt_t *p;
if (prf == NULL)
- return (-1);
+ return -1;
+
if (op == EL_PROMPT)
- *prf = el->el_prompt.p_func;
+ p = &el->el_prompt;
else
- *prf = el->el_rprompt.p_func;
- return (0);
+ p = &el->el_rprompt;
+
+ *prf = el->el_rprompt.p_func;
+
+ if (c)
+ *c = p->p_ignore;
+
+ return 0;
}
diff --git a/lib/libedit/prompt.h b/lib/libedit/prompt.h
index 6523add..fe69ca4 100644
--- a/lib/libedit/prompt.h
+++ b/lib/libedit/prompt.h
@@ -47,11 +47,13 @@ typedef char * (*el_pfunc_t)(EditLine*);
typedef struct el_prompt_t {
el_pfunc_t p_func; /* Function to return the prompt */
coord_t p_pos; /* position in the line after prompt */
+ char p_ignore; /* character to start/end literal
+*/
} el_prompt_t;
protected void prompt_print(EditLine *, int);
-protected int prompt_set(EditLine *, el_pfunc_t, int);
-protected int prompt_get(EditLine *, el_pfunc_t *, int);
+protected int prompt_set(EditLine *, el_pfunc_t, char, int);
+protected int prompt_get(EditLine *, el_pfunc_t *, char *, int);
protected int prompt_init(EditLine *);
protected void prompt_end(EditLine *);
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index 0caba5d..ed2b609 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: read.c,v 1.40 2007/03/01 21:41:45 christos Exp $
+ * $NetBSD: read.c,v 1.52 2009/07/22 15:57:00 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -49,7 +49,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include "el.h"
-#define OKCMD -1
+#define OKCMD -1 /* must be -1! */
private int read__fixio(int, int);
private int read_preread(EditLine *);
@@ -170,7 +170,7 @@ read__fixio(int fd __unused, int e)
return (e ? 0 : -1);
case EINTR:
- return (0);
+ return (-1);
default:
return (-1);
@@ -222,7 +222,7 @@ el_push(EditLine *el, const char *str)
ma->level--;
}
term_beep(el);
- term__flush();
+ term__flush(el);
}
@@ -235,9 +235,12 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
el_action_t cmd;
int num;
+ el->el_errno = 0;
do {
- if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
+ if ((num = el_getc(el, ch)) != 1) { /* if EOF or error */
+ el->el_errno = num == 0 ? 0 : errno;
return (num);
+ }
#ifdef KANJI
if ((*ch & 0200)) {
@@ -286,18 +289,25 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
private int
read_char(EditLine *el, char *cp)
{
- int num_read;
+ ssize_t num_read;
int tried = 0;
- while ((num_read = read(el->el_infd, cp, 1)) == -1)
+ again:
+ el->el_signal->sig_no = 0;
+ while ((num_read = read(el->el_infd, cp, 1)) == -1) {
+ if (el->el_signal->sig_no == SIGCONT) {
+ sig_set(el);
+ el_set(el, EL_REFRESH);
+ goto again;
+ }
if (!tried && read__fixio(el->el_infd, errno) == 0)
tried = 1;
else {
*cp = '\0';
return (-1);
}
-
- return (num_read);
+ }
+ return (int)num_read;
}
/* read_pop():
@@ -309,8 +319,9 @@ read_pop(c_macro_t *ma)
int i;
el_free(ma->macro[0]);
- for (i = ma->level--; i > 0; i--)
- ma->macro[i - 1] = ma->macro[i];
+ for (i = 0; i < ma->level; i++)
+ ma->macro[i] = ma->macro[i + 1];
+ ma->level--;
ma->offset = 0;
}
@@ -323,7 +334,7 @@ el_getc(EditLine *el, char *cp)
int num_read;
c_macro_t *ma = &el->el_chared.c_macro;
- term__flush();
+ term__flush(el);
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
@@ -382,7 +393,7 @@ read_prepare(EditLine *el)
re_refresh(el); /* print the prompt */
if (el->el_flags & UNBUFFERED)
- term__flush();
+ term__flush(el);
}
protected void
@@ -402,15 +413,20 @@ el_gets(EditLine *el, int *nread)
int num; /* how many chars we have read at NL */
char ch;
int crlf = 0;
+ int nrb;
#ifdef FIONREAD
c_macro_t *ma = &el->el_chared.c_macro;
#endif /* FIONREAD */
+ if (nread == NULL)
+ nread = &nrb;
+ *nread = 0;
+
if (el->el_flags & NO_TTY) {
char *cp = el->el_line.buffer;
size_t idx;
- while ((*el->el_read.read_char)(el, cp) == 1) {
+ while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
/* make sure there is space for next character */
if (cp + 1 >= el->el_line.limit) {
idx = (cp - el->el_line.buffer);
@@ -424,12 +440,16 @@ el_gets(EditLine *el, int *nread)
if (cp[-1] == '\r' || cp[-1] == '\n')
break;
}
+ if (num == -1) {
+ if (errno == EINTR)
+ cp = el->el_line.buffer;
+ el->el_errno = errno;
+ }
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
- if (nread)
- *nread = el->el_line.cursor - el->el_line.buffer;
- return (el->el_line.buffer);
+ *nread = (int)(el->el_line.cursor - el->el_line.buffer);
+ goto done;
}
@@ -440,8 +460,8 @@ el_gets(EditLine *el, int *nread)
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
if (chrs == 0) {
if (tty_rawmode(el) < 0) {
- if (nread)
- *nread = 0;
+ errno = 0;
+ *nread = 0;
return (NULL);
}
}
@@ -454,14 +474,15 @@ el_gets(EditLine *el, int *nread)
if (el->el_flags & EDIT_DISABLED) {
char *cp;
size_t idx;
+
if ((el->el_flags & UNBUFFERED) == 0)
cp = el->el_line.buffer;
else
cp = el->el_line.lastchar;
- term__flush();
+ term__flush(el);
- while ((*el->el_read.read_char)(el, cp) == 1) {
+ while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
/* make sure there is space next character */
if (cp + 1 >= el->el_line.limit) {
idx = (cp - el->el_line.buffer);
@@ -469,8 +490,6 @@ el_gets(EditLine *el, int *nread)
break;
cp = &el->el_line.buffer[idx];
}
- if (*cp == 4) /* ought to be stty eof */
- break;
cp++;
crlf = cp[-1] == '\r' || cp[-1] == '\n';
if (el->el_flags & UNBUFFERED)
@@ -479,11 +498,15 @@ el_gets(EditLine *el, int *nread)
break;
}
+ if (num == -1) {
+ if (errno == EINTR)
+ cp = el->el_line.buffer;
+ el->el_errno = errno;
+ }
+
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
- if (nread)
- *nread = el->el_line.cursor - el->el_line.buffer;
- return (el->el_line.buffer);
+ goto done;
}
for (num = OKCMD; num == OKCMD;) { /* while still editing this
@@ -499,7 +522,13 @@ el_gets(EditLine *el, int *nread)
#endif /* DEBUG_READ */
break;
}
- if ((unsigned int)cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
+ if (el->el_errno == EINTR) {
+ el->el_line.buffer[0] = '\0';
+ el->el_line.lastchar =
+ el->el_line.cursor = el->el_line.buffer;
+ break;
+ }
+ if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) { /* BUG CHECK command */
#ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile,
"ERROR: illegal command from key 0%o\r\n", ch);
@@ -581,7 +610,7 @@ el_gets(EditLine *el, int *nread)
break;
case CC_NEWLINE: /* normal end of line */
- num = el->el_line.lastchar - el->el_line.buffer;
+ num = (int)(el->el_line.lastchar - el->el_line.buffer);
break;
case CC_FATAL: /* fatal error, reset to known state */
@@ -602,7 +631,7 @@ el_gets(EditLine *el, int *nread)
"*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
term_beep(el);
- term__flush();
+ term__flush(el);
break;
}
el->el_state.argument = 1;
@@ -612,15 +641,21 @@ el_gets(EditLine *el, int *nread)
break;
}
- term__flush(); /* flush any buffered output */
+ term__flush(el); /* flush any buffered output */
/* make sure the tty is set up correctly */
if ((el->el_flags & UNBUFFERED) == 0) {
read_finish(el);
- if (nread)
- *nread = num;
+ *nread = num != -1 ? num : 0;
} else {
- if (nread)
- *nread = el->el_line.lastchar - el->el_line.buffer;
+ *nread = (int)(el->el_line.lastchar - el->el_line.buffer);
}
- return (num ? el->el_line.buffer : NULL);
+done:
+ if (*nread == 0) {
+ if (num == -1) {
+ *nread = -1;
+ errno = el->el_errno;
+ }
+ return NULL;
+ } else
+ return el->el_line.buffer;
}
diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c
index 22e1de4..8fe8229 100644
--- a/lib/libedit/refresh.c
+++ b/lib/libedit/refresh.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: refresh.c,v 1.27 2005/11/09 22:11:10 christos Exp $
+ * $NetBSD: refresh.c,v 1.34 2009/12/28 22:15:36 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include "el.h"
+private void re_nextline(EditLine *);
private void re_addc(EditLine *, int);
private void re_update_line(EditLine *, char *, char *, int);
private void re_insert (EditLine *, char *, int, int, char *, int);
@@ -86,6 +87,37 @@ re_printstr(EditLine *el, const char *str, char *f, char *t)
#define ELRE_DEBUG(a, b)
#endif
+/* re_nextline():
+ * Move to the next line or scroll
+ */
+private void
+re_nextline(EditLine *el)
+{
+ el->el_refresh.r_cursor.h = 0; /* reset it. */
+
+ /*
+ * If we would overflow (input is longer than terminal size),
+ * emulate scroll by dropping first line and shuffling the rest.
+ * We do this via pointer shuffling - it's safe in this case
+ * and we avoid memcpy().
+ */
+ if (el->el_refresh.r_cursor.v + 1 >= el->el_term.t_size.v) {
+ int i, lins = el->el_term.t_size.v;
+ char *firstline = el->el_vdisplay[0];
+
+ for(i = 1; i < lins; i++)
+ el->el_vdisplay[i - 1] = el->el_vdisplay[i];
+
+ firstline[0] = '\0'; /* empty the string */
+ el->el_vdisplay[i - 1] = firstline;
+ } else
+ el->el_refresh.r_cursor.v++;
+
+ ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
+ (__F, "\r\nre_putc: overflow! r_cursor.v == %d > %d\r\n",
+ el->el_refresh.r_cursor.v, el->el_term.t_size.v),
+ abort());
+}
/* re_addc():
* Draw c, expanding tabs, control chars etc.
@@ -101,10 +133,8 @@ re_addc(EditLine *el, int c)
if (c == '\n') { /* expand the newline */
int oldv = el->el_refresh.r_cursor.v;
re_putc(el, '\0', 0); /* assure end of line */
- if (oldv == el->el_refresh.r_cursor.v) { /* XXX */
- el->el_refresh.r_cursor.h = 0; /* reset cursor pos */
- el->el_refresh.r_cursor.v++;
- }
+ if (oldv == el->el_refresh.r_cursor.v) /* XXX */
+ re_nextline(el);
return;
}
if (c == '\t') { /* expand the tab */
@@ -144,33 +174,12 @@ re_putc(EditLine *el, int c, int shift)
el->el_refresh.r_cursor.h++; /* advance to next place */
if (el->el_refresh.r_cursor.h >= el->el_term.t_size.h) {
- el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h] = '\0';
/* assure end of line */
- el->el_refresh.r_cursor.h = 0; /* reset it. */
-
- /*
- * If we would overflow (input is longer than terminal size),
- * emulate scroll by dropping first line and shuffling the rest.
- * We do this via pointer shuffling - it's safe in this case
- * and we avoid memcpy().
- */
- if (el->el_refresh.r_cursor.v + 1 >= el->el_term.t_size.v) {
- int i, lins = el->el_term.t_size.v;
- char *firstline = el->el_vdisplay[0];
-
- for(i=1; i < lins; i++)
- el->el_vdisplay[i-1] = el->el_vdisplay[i];
-
- firstline[0] = '\0'; /* empty the string */
- el->el_vdisplay[i-1] = firstline;
- } else
- el->el_refresh.r_cursor.v++;
-
- ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
- (__F, "\r\nre_putc: overflow! r_cursor.v == %d > %d\r\n",
- el->el_refresh.r_cursor.v, el->el_term.t_size.v),
- abort());
+ el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h]
+ = '\0';
+ re_nextline(el);
}
+
}
@@ -298,7 +307,7 @@ re_refresh(EditLine *el)
term_move_to_char(el, 0);
term_clear_EOL(el, (int) strlen(el->el_display[i]));
#ifdef DEBUG_REFRESH
- term_overwrite(el, "C\b", 2);
+ term_overwrite(el, "C\b", (size_t)2);
#endif /* DEBUG_REFRESH */
el->el_display[i][0] = '\0';
}
@@ -321,9 +330,9 @@ re_goto_bottom(EditLine *el)
{
term_move_to_line(el, el->el_refresh.r_oldcv);
- term__putc('\n');
+ term__putc(el, '\n');
re_clear_display(el);
- term__flush();
+ term__flush(el);
}
@@ -475,6 +484,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
char *ofd, *ols, *oe, *nfd, *nls, *ne;
char *osb, *ose, *nsb, *nse;
int fx, sx;
+ size_t len;
/*
* find first diff
@@ -601,12 +611,12 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* fx is the number of characters we need to insert/delete: in the
* beginning to bring the two same begins together
*/
- fx = (nsb - nfd) - (osb - ofd);
+ fx = (int)((nsb - nfd) - (osb - ofd));
/*
* sx is the number of characters we need to insert/delete: in the
* end to bring the two same last parts together
*/
- sx = (nls - nse) - (ols - ose);
+ sx = (int)((nls - nse) - (ols - ose));
if (!EL_CAN_INSERT) {
if (fx > 0) {
@@ -655,8 +665,8 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* Now that we are done with pragmatics we recompute fx, sx
*/
- fx = (nsb - nfd) - (osb - ofd);
- sx = (nls - nse) - (ols - ose);
+ fx = (int)((nsb - nfd) - (osb - ofd));
+ sx = (int)((nls - nse) - (ols - ose));
ELRE_DEBUG(1, (__F, "fx %d, sx %d\n", fx, sx));
ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n",
@@ -739,7 +749,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* Move to the first char to insert, where the first diff is.
*/
- term_move_to_char(el, nfd - new);
+ term_move_to_char(el, (int)(nfd - new));
/*
* Check if we have stuff to keep at end
*/
@@ -752,20 +762,21 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in early first diff\n"));
term_insertwrite(el, nfd, fx);
- re_insert(el, old, ofd - old,
+ re_insert(el, old, (int)(ofd - old),
el->el_term.t_size.h, nfd, fx);
}
/*
* write (nsb-nfd) - fx chars of new starting at
* (nfd + fx)
*/
- term_overwrite(el, nfd + fx, (nsb - nfd) - fx);
- re__strncopy(ofd + fx, nfd + fx,
- (size_t) ((nsb - nfd) - fx));
+ len = (size_t) ((nsb - nfd) - fx);
+ term_overwrite(el, (nfd + fx), len);
+ re__strncopy(ofd + fx, nfd + fx, len);
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
+ len = (size_t)(nsb - nfd);
+ term_overwrite(el, nfd, len);
+ re__strncopy(ofd, nfd, len);
/*
* Done
*/
@@ -777,7 +788,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* move to the first char to delete where the first diff is
*/
- term_move_to_char(el, ofd - old);
+ term_move_to_char(el, (int)(ofd - old));
/*
* Check if we have stuff to save
*/
@@ -791,14 +802,15 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(!EL_CAN_DELETE, (__F,
"ERROR: cannot delete in first diff\n"));
term_deletechars(el, -fx);
- re_delete(el, old, ofd - old,
+ re_delete(el, old, (int)(ofd - old),
el->el_term.t_size.h, -fx);
}
/*
* write (nsb-nfd) chars of new starting at nfd
*/
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
+ len = (size_t) (nsb - nfd);
+ term_overwrite(el, nfd, len);
+ re__strncopy(ofd, nfd, len);
} else {
ELRE_DEBUG(1, (__F,
@@ -806,8 +818,9 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* write (nsb-nfd) chars of new starting at nfd
*/
- term_overwrite(el, nfd, (nsb - nfd));
- re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
+ term_overwrite(el, nfd, (size_t)(nsb - nfd));
+ re_clear_eol(el, fx, sx,
+ (int)((oe - old) - (ne - new)));
/*
* Done
*/
@@ -826,7 +839,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* fx is the number of characters inserted (+) or deleted (-)
*/
- term_move_to_char(el, (ose - old) + fx);
+ term_move_to_char(el, (int)((ose - old) + fx));
/*
* Check if we have stuff to save
*/
@@ -843,12 +856,13 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* write (nls-nse) chars of new starting at nse
*/
- term_overwrite(el, nse, (nls - nse));
+ term_overwrite(el, nse, (size_t)(nls - nse));
} else {
ELRE_DEBUG(1, (__F,
"but with nothing left to save\r\n"));
- term_overwrite(el, nse, (nls - nse));
- re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
+ term_overwrite(el, nse, (size_t)(nls - nse));
+ re_clear_eol(el, fx, sx,
+ (int)((oe - old) - (ne - new)));
}
}
/*
@@ -858,7 +872,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n",
nfd - new));
- term_move_to_char(el, nfd - new);
+ term_move_to_char(el, (int)(nfd - new));
/*
* Check if we have stuff to keep at the end
*/
@@ -869,7 +883,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* to zero above as a flag saying that we hadn't done
* an early first insert.
*/
- fx = (nsb - nfd) - (osb - ofd);
+ fx = (int)((nsb - nfd) - (osb - ofd));
if (fx > 0) {
/*
* insert fx chars of new starting at nfd
@@ -877,20 +891,21 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in late first diff\n"));
term_insertwrite(el, nfd, fx);
- re_insert(el, old, ofd - old,
+ re_insert(el, old, (int)(ofd - old),
el->el_term.t_size.h, nfd, fx);
}
/*
* write (nsb-nfd) - fx chars of new starting at
* (nfd + fx)
*/
- term_overwrite(el, nfd + fx, (nsb - nfd) - fx);
- re__strncopy(ofd + fx, nfd + fx,
- (size_t) ((nsb - nfd) - fx));
+ len = (size_t) ((nsb - nfd) - fx);
+ term_overwrite(el, (nfd + fx), len);
+ re__strncopy(ofd + fx, nfd + fx, len);
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
+ len = (size_t) (nsb - nfd);
+ term_overwrite(el, nfd, len);
+ re__strncopy(ofd, nfd, len);
}
}
/*
@@ -898,8 +913,8 @@ re_update_line(EditLine *el, char *old, char *new, int i)
*/
if (sx >= 0) {
ELRE_DEBUG(1, (__F,
- "second diff insert at %d...\r\n", nse - new));
- term_move_to_char(el, nse - new);
+ "second diff insert at %d...\r\n", (int)(nse - new)));
+ term_move_to_char(el, (int)(nse - new));
if (ols != oe) {
ELRE_DEBUG(1, (__F, "with stuff to keep at end\r\n"));
if (sx > 0) {
@@ -912,10 +927,11 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* write (nls-nse) - sx chars of new starting at
* (nse + sx)
*/
- term_overwrite(el, nse + sx, (nls - nse) - sx);
+ term_overwrite(el, (nse + sx),
+ (size_t)((nls - nse) - sx));
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nse, (nls - nse));
+ term_overwrite(el, nse, (size_t)(nls - nse));
/*
* No need to do a clear-to-end here because we were
@@ -974,34 +990,28 @@ re_refresh_cursor(EditLine *el)
/* do input buffer to el->el_line.cursor */
for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
c = *cp;
- h++; /* all chars at least this long */
- if (c == '\n') {/* handle newline in data part too */
+ switch (c) {
+ case '\n': /* handle newline in data part too */
h = 0;
v++;
- } else {
- if (c == '\t') { /* if a tab, to next tab stop */
- while (h & 07) {
- h++;
- }
- } else if (iscntrl((unsigned char) c)) {
- /* if control char */
+ break;
+ case '\t': /* if a tab, to next tab stop */
+ while (++h & 07)
+ continue;
+ break;
+ default:
+ if (iscntrl((unsigned char) c))
+ h += 2; /* ^x */
+ else if (!isprint((unsigned char) c))
+ h += 4; /* octal \xxx */
+ else
h++;
- if (h > th) { /* if overflow, compensate */
- h = 1;
- v++;
- }
- } else if (!isprint((unsigned char) c)) {
- h += 3;
- if (h > th) { /* if overflow, compensate */
- h = h - th;
- v++;
- }
- }
+ break;
}
if (h >= th) { /* check, extra long tabs picked up here also */
- h = 0;
+ h -= th;
v++;
}
}
@@ -1009,7 +1019,7 @@ re_refresh_cursor(EditLine *el)
/* now go there */
term_move_to_line(el, v);
term_move_to_char(el, h);
- term__flush();
+ term__flush(el);
}
@@ -1020,7 +1030,7 @@ private void
re_fastputc(EditLine *el, int c)
{
- term__putc(c);
+ term__putc(el, c);
el->el_display[el->el_cursor.v][el->el_cursor.h++] = c;
if (el->el_cursor.h >= el->el_term.t_size.h) {
/* if we must overflow */
@@ -1036,23 +1046,23 @@ re_fastputc(EditLine *el, int c)
int i, lins = el->el_term.t_size.v;
char *firstline = el->el_display[0];
- for(i=1; i < lins; i++)
- el->el_display[i-1] = el->el_display[i];
+ for(i = 1; i < lins; i++)
+ el->el_display[i - 1] = el->el_display[i];
re__copy_and_pad(firstline, "", 0);
- el->el_display[i-1] = firstline;
+ el->el_display[i - 1] = firstline;
} else {
el->el_cursor.v++;
el->el_refresh.r_oldcv++;
}
if (EL_HAS_AUTO_MARGINS) {
if (EL_HAS_MAGIC_MARGINS) {
- term__putc(' ');
- term__putc('\b');
+ term__putc(el, ' ');
+ term__putc(el, '\b');
}
} else {
- term__putc('\r');
- term__putc('\n');
+ term__putc(el, '\r');
+ term__putc(el, '\n');
}
}
}
@@ -1092,7 +1102,7 @@ re_fastaddc(EditLine *el)
re_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0'));
re_fastputc(el, (c & 7) + '0');
}
- term__flush();
+ term__flush(el);
}
@@ -1121,17 +1131,16 @@ re_clear_lines(EditLine *el)
if (EL_CAN_CEOL) {
int i;
- term_move_to_char(el, 0);
- for (i = 0; i <= el->el_refresh.r_oldcv; i++) {
+ for (i = el->el_refresh.r_oldcv; i >= 0; i--) {
/* for each line on the screen */
term_move_to_line(el, i);
+ term_move_to_char(el, 0);
term_clear_EOL(el, el->el_term.t_size.h);
}
- term_move_to_line(el, 0);
} else {
term_move_to_line(el, el->el_refresh.r_oldcv);
/* go to last line */
- term__putc('\r'); /* go to BOL */
- term__putc('\n'); /* go to new line */
+ term__putc(el, '\r'); /* go to BOL */
+ term__putc(el, '\n'); /* go to new line */
}
}
diff --git a/lib/libedit/search.c b/lib/libedit/search.c
index 991bad2..af3da8c 100644
--- a/lib/libedit/search.c
+++ b/lib/libedit/search.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: search.c,v 1.20 2004/11/04 01:16:03 christos Exp $
+ * $NetBSD: search.c,v 1.21 2009/02/15 21:55:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -207,7 +207,7 @@ ce_inc_search(EditLine *el, int dir)
el_action_t ret = CC_NORM;
int ohisteventno = el->el_history.eventno;
- int oldpatlen = el->el_search.patlen;
+ size_t oldpatlen = el->el_search.patlen;
int newdir = dir;
int done, redo;
diff --git a/lib/libedit/sig.c b/lib/libedit/sig.c
index a895aea..e48dbef 100644
--- a/lib/libedit/sig.c
+++ b/lib/libedit/sig.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: sig.c,v 1.11 2003/08/07 16:44:33 agc Exp $
+ * $NetBSD: sig.c,v 1.15 2009/02/19 15:20:22 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -73,12 +73,14 @@ sig_handler(int signo)
(void) sigaddset(&nset, signo);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
+ sel->el_signal->sig_no = signo;
+
switch (signo) {
case SIGCONT:
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
- term__flush();
+ term__flush(sel);
break;
case SIGWINCH:
@@ -94,7 +96,10 @@ sig_handler(int signo)
if (signo == sighdl[i])
break;
- (void) signal(signo, sel->el_signal[i]);
+ (void) sigaction(signo, &sel->el_signal->sig_action[i], NULL);
+ sel->el_signal->sig_action[i].sa_handler = SIG_ERR;
+ sel->el_signal->sig_action[i].sa_flags = 0;
+ sigemptyset(&sel->el_signal->sig_action[i].sa_mask);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
(void) kill(0, signo);
}
@@ -106,26 +111,29 @@ sig_handler(int signo)
protected int
sig_init(EditLine *el)
{
- int i;
- sigset_t nset, oset;
+ size_t i;
+ sigset_t *nset, oset;
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
+ el->el_signal = el_malloc(sizeof(*el->el_signal));
+ if (el->el_signal == NULL)
+ return -1;
+
+ nset = &el->el_signal->sig_set;
+ (void) sigemptyset(nset);
+#define _DO(a) (void) sigaddset(nset, a);
ALLSIGS
#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
+ (void) sigprocmask(SIG_BLOCK, nset, &oset);
-#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(el_signalhandler_t))
-
- el->el_signal = (el_signalhandler_t *) el_malloc(SIGSIZE);
- if (el->el_signal == NULL)
- return (-1);
- for (i = 0; sighdl[i] != -1; i++)
- el->el_signal[i] = SIG_ERR;
+ for (i = 0; sighdl[i] != -1; i++) {
+ el->el_signal->sig_action[i].sa_handler = SIG_ERR;
+ el->el_signal->sig_action[i].sa_flags = 0;
+ sigemptyset(&el->el_signal->sig_action[i].sa_mask);
+ }
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
- return (0);
+ return 0;
}
@@ -147,20 +155,21 @@ sig_end(EditLine *el)
protected void
sig_set(EditLine *el)
{
- int i;
- sigset_t nset, oset;
+ size_t i;
+ sigset_t oset;
+ struct sigaction osa, nsa;
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
- ALLSIGS
-#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
+ nsa.sa_handler = sig_handler;
+ nsa.sa_flags = 0;
+ sigemptyset(&nsa.sa_mask);
+
+ (void) sigprocmask(SIG_BLOCK, &el->el_signal->sig_set, &oset);
for (i = 0; sighdl[i] != -1; i++) {
- el_signalhandler_t s;
/* This could happen if we get interrupted */
- if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
- el->el_signal[i] = s;
+ if (sigaction(sighdl[i], &nsa, &osa) != -1 &&
+ osa.sa_handler != sig_handler)
+ el->el_signal->sig_action[i] = osa;
}
sel = el;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
@@ -173,20 +182,17 @@ sig_set(EditLine *el)
protected void
sig_clr(EditLine *el)
{
- int i;
- sigset_t nset, oset;
+ size_t i;
+ sigset_t oset;
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
- ALLSIGS
-#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
+ (void) sigprocmask(SIG_BLOCK, &el->el_signal->sig_set, &oset);
for (i = 0; sighdl[i] != -1; i++)
- if (el->el_signal[i] != SIG_ERR)
- (void) signal(sighdl[i], el->el_signal[i]);
+ if (el->el_signal->sig_action[i].sa_handler != SIG_ERR)
+ (void)sigaction(sighdl[i],
+ &el->el_signal->sig_action[i], NULL);
sel = NULL; /* we are going to die if the handler is
* called */
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
+ (void)sigprocmask(SIG_SETMASK, &oset, NULL);
}
diff --git a/lib/libedit/sig.h b/lib/libedit/sig.h
index b1ce14b..6c1260d 100644
--- a/lib/libedit/sig.h
+++ b/lib/libedit/sig.h
@@ -51,15 +51,18 @@
#define ALLSIGS \
_DO(SIGINT) \
_DO(SIGTSTP) \
- _DO(SIGSTOP) \
_DO(SIGQUIT) \
_DO(SIGHUP) \
_DO(SIGTERM) \
_DO(SIGCONT) \
_DO(SIGWINCH)
+#define ALLSIGSNO 7
-typedef void (*el_signalhandler_t)(int);
-typedef el_signalhandler_t *el_signal_t;
+typedef struct {
+ struct sigaction sig_action[ALLSIGSNO];
+ sigset_t sig_set;
+ volatile sig_atomic_t sig_no;
+} *el_signal_t;
protected void sig_end(EditLine*);
protected int sig_init(EditLine*);
diff --git a/lib/libedit/term.c b/lib/libedit/term.c
index 1d89279..4899193 100644
--- a/lib/libedit/term.c
+++ b/lib/libedit/term.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: term.c,v 1.46 2006/11/24 00:01:17 christos Exp $
+ * $NetBSD: term.c,v 1.56 2009/12/28 21:54:21 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -261,9 +261,13 @@ private int term_alloc_display(EditLine *);
private void term_alloc(EditLine *, const struct termcapstr *, const char *);
private void term_init_arrow(EditLine *);
private void term_reset_arrow(EditLine *);
+private int term_putc(int);
+private void term_tputs(EditLine *, const char *, int);
-
-private FILE *term_outfile = NULL; /* XXX: How do we fix that? */
+#ifdef _REENTRANT
+private pthread_mutex_t term_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+private FILE *term_outfile = NULL;
/* term_setflags():
@@ -311,7 +315,6 @@ term_setflags(EditLine *el)
#endif /* DEBUG_SCREEN */
}
-
/* term_init():
* Initialize the terminal stuff
*/
@@ -337,7 +340,6 @@ term_init(EditLine *el)
if (el->el_term.t_val == NULL)
return (-1);
(void) memset(el->el_term.t_val, 0, T_val * sizeof(int));
- term_outfile = el->el_outfile;
term_init_arrow(el);
(void) term_set(el, NULL);
return (0);
@@ -372,7 +374,7 @@ private void
term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
{
char termbuf[TC_BUFSIZE];
- int tlen, clen;
+ size_t tlen, clen;
char **tlist = el->el_term.t_str;
char **tmp, **str = &tlist[t - tstr];
@@ -399,7 +401,7 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
/* XXX strcpy is safe */
(void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc],
cap);
- el->el_term.t_loc += clen + 1; /* one for \0 */
+ el->el_term.t_loc += (int)clen + 1; /* one for \0 */
return;
}
/*
@@ -416,7 +418,7 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
termbuf[tlen++] = '\0';
}
memcpy(el->el_term.t_buf, termbuf, TC_BUFSIZE);
- el->el_term.t_loc = tlen;
+ el->el_term.t_loc = (int)tlen;
if (el->el_term.t_loc + 3 >= TC_BUFSIZE) {
(void) fprintf(el->el_errfile,
"Out of termcap string space.\n");
@@ -424,7 +426,7 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
}
/* XXX strcpy is safe */
(void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
- el->el_term.t_loc += clen + 1; /* one for \0 */
+ el->el_term.t_loc += (int)clen + 1; /* one for \0 */
return;
}
@@ -542,19 +544,20 @@ term_move_to_line(EditLine *el, int where)
el->el_display[el->el_cursor.v][0] != '\0') {
/* move without newline */
term_move_to_char(el, el->el_term.t_size.h - 1);
- term_overwrite(el,
- &el->el_display[el->el_cursor.v][el->el_cursor.h],
- 1);
+ term_overwrite(el, &el->el_display
+ [el->el_cursor.v][el->el_cursor.h],
+ (size_t)(el->el_term.t_size.h -
+ el->el_cursor.h));
/* updates Cursor */
del--;
} else {
if ((del > 1) && GoodStr(T_DO)) {
- (void) tputs(tgoto(Str(T_DO), del, del),
- del, term__putc);
+ term_tputs(el, tgoto(Str(T_DO), del,
+ del), del);
del = 0;
} else {
for (; del > 0; del--)
- term__putc('\n');
+ term__putc(el, '\n');
/* because the \n will become \r\n */
el->el_cursor.h = 0;
}
@@ -562,12 +565,11 @@ term_move_to_line(EditLine *el, int where)
}
} else { /* del < 0 */
if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up)))
- (void) tputs(tgoto(Str(T_UP), -del, -del), -del,
- term__putc);
+ term_tputs(el, tgoto(Str(T_UP), -del, -del), -del);
else {
if (GoodStr(T_up))
for (; del < 0; del++)
- (void) tputs(Str(T_up), 1, term__putc);
+ term_tputs(el, Str(T_up), 1);
}
}
el->el_cursor.v = where;/* now where is here */
@@ -594,7 +596,7 @@ mc_again:
return;
}
if (!where) { /* if where is first column */
- term__putc('\r'); /* do a CR */
+ term__putc(el, '\r'); /* do a CR */
el->el_cursor.h = 0;
return;
}
@@ -602,25 +604,24 @@ mc_again:
if ((del < -4 || del > 4) && GoodStr(T_ch))
/* go there directly */
- (void) tputs(tgoto(Str(T_ch), where, where), where, term__putc);
+ term_tputs(el, tgoto(Str(T_ch), where, where), where);
else {
if (del > 0) { /* moving forward */
if ((del > 4) && GoodStr(T_RI))
- (void) tputs(tgoto(Str(T_RI), del, del),
- del, term__putc);
+ term_tputs(el, tgoto(Str(T_RI), del, del), del);
else {
/* if I can do tabs, use them */
if (EL_CAN_TAB) {
if ((el->el_cursor.h & 0370) !=
- (where & 0370)) {
+ (where & ~0x7)) {
/* if not within tab stop */
for (i =
(el->el_cursor.h & 0370);
- i < (where & 0370);
+ i < (where & ~0x7);
i += 8)
- term__putc('\t');
+ term__putc(el, '\t');
/* then tab over */
- el->el_cursor.h = where & 0370;
+ el->el_cursor.h = where & ~0x7;
}
}
/*
@@ -631,15 +632,15 @@ mc_again:
* NOTE THAT term_overwrite() WILL CHANGE
* el->el_cursor.h!!!
*/
- term_overwrite(el,
- &el->el_display[el->el_cursor.v][el->el_cursor.h],
- where - el->el_cursor.h);
+ term_overwrite(el, &el->el_display[
+ el->el_cursor.v][el->el_cursor.h],
+ (size_t)(where - el->el_cursor.h));
}
} else { /* del < 0 := moving backward */
if ((-del > 4) && GoodStr(T_LE))
- (void) tputs(tgoto(Str(T_LE), -del, -del),
- -del, term__putc);
+ term_tputs(el, tgoto(Str(T_LE), -del, -del),
+ -del);
else { /* can't go directly there */
/*
* if the "cost" is greater than the "cost"
@@ -650,12 +651,12 @@ mc_again:
(((unsigned int) where >> 3) +
(where & 07)))
: (-del > where)) {
- term__putc('\r'); /* do a CR */
+ term__putc(el, '\r'); /* do a CR */
el->el_cursor.h = 0;
goto mc_again; /* and try again */
}
for (i = 0; i < -del; i++)
- term__putc('\b');
+ term__putc(el, '\b');
}
}
}
@@ -667,20 +668,21 @@ mc_again:
* Overstrike num characters
*/
protected void
-term_overwrite(EditLine *el, const char *cp, int n)
+term_overwrite(EditLine *el, const char *cp, size_t n)
{
- if (n <= 0)
- return; /* catch bugs */
+ if (n == 0)
+ return;
- if (n > el->el_term.t_size.h) {
+ if (n > (size_t)el->el_term.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
"term_overwrite: n is riduculous: %d\r\n", n);
#endif /* DEBUG_SCREEN */
return;
}
+
do {
- term__putc(*cp++);
+ term__putc(el, *cp++);
el->el_cursor.h++;
} while (--n);
@@ -695,12 +697,13 @@ term_overwrite(EditLine *el, const char *cp, int n)
if ((c = el->el_display[el->el_cursor.v][el->el_cursor.h])
!= '\0')
term_overwrite(el, &c, 1);
- else
- term__putc(' ');
- el->el_cursor.h = 1;
+ else {
+ term__putc(el, ' ');
+ el->el_cursor.h = 1;
+ }
}
} else /* no wrap, but cursor stays on screen */
- el->el_cursor.h = el->el_term.t_size.h;
+ el->el_cursor.h = el->el_term.t_size.h - 1;
}
}
@@ -730,19 +733,18 @@ term_deletechars(EditLine *el, int num)
if (GoodStr(T_DC)) /* if I have multiple delete */
if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more
* expen. */
- (void) tputs(tgoto(Str(T_DC), num, num),
- num, term__putc);
+ term_tputs(el, tgoto(Str(T_DC), num, num), num);
return;
}
if (GoodStr(T_dm)) /* if I have delete mode */
- (void) tputs(Str(T_dm), 1, term__putc);
+ term_tputs(el, Str(T_dm), 1);
if (GoodStr(T_dc)) /* else do one at a time */
while (num--)
- (void) tputs(Str(T_dc), 1, term__putc);
+ term_tputs(el, Str(T_dc), 1);
if (GoodStr(T_ed)) /* if I have delete mode */
- (void) tputs(Str(T_ed), 1, term__putc);
+ term_tputs(el, Str(T_ed), 1);
}
@@ -771,37 +773,35 @@ term_insertwrite(EditLine *el, char *cp, int num)
if (GoodStr(T_IC)) /* if I have multiple insert */
if ((num > 1) || !GoodStr(T_ic)) {
/* if ic would be more expensive */
- (void) tputs(tgoto(Str(T_IC), num, num),
- num, term__putc);
- term_overwrite(el, cp, num);
+ term_tputs(el, tgoto(Str(T_IC), num, num), num);
+ term_overwrite(el, cp, (size_t)num);
/* this updates el_cursor.h */
return;
}
if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */
- (void) tputs(Str(T_im), 1, term__putc);
+ term_tputs(el, Str(T_im), 1);
el->el_cursor.h += num;
do
- term__putc(*cp++);
+ term__putc(el, *cp++);
while (--num);
if (GoodStr(T_ip)) /* have to make num chars insert */
- (void) tputs(Str(T_ip), 1, term__putc);
+ term_tputs(el, Str(T_ip), 1);
- (void) tputs(Str(T_ei), 1, term__putc);
+ term_tputs(el, Str(T_ei), 1);
return;
}
do {
if (GoodStr(T_ic)) /* have to make num chars insert */
- (void) tputs(Str(T_ic), 1, term__putc);
- /* insert a char */
+ term_tputs(el, Str(T_ic), 1);
- term__putc(*cp++);
+ term__putc(el, *cp++);
el->el_cursor.h++;
if (GoodStr(T_ip)) /* have to make num chars insert */
- (void) tputs(Str(T_ip), 1, term__putc);
+ term_tputs(el, Str(T_ip), 1);
/* pad the inserted char */
} while (--num);
@@ -817,10 +817,10 @@ term_clear_EOL(EditLine *el, int num)
int i;
if (EL_CAN_CEOL && GoodStr(T_ce))
- (void) tputs(Str(T_ce), 1, term__putc);
+ term_tputs(el, Str(T_ce), 1);
else {
for (i = 0; i < num; i++)
- term__putc(' ');
+ term__putc(el, ' ');
el->el_cursor.h += num; /* have written num spaces */
}
}
@@ -835,14 +835,14 @@ term_clear_screen(EditLine *el)
if (GoodStr(T_cl))
/* send the clear screen code */
- (void) tputs(Str(T_cl), Val(T_li), term__putc);
+ term_tputs(el, Str(T_cl), Val(T_li));
else if (GoodStr(T_ho) && GoodStr(T_cd)) {
- (void) tputs(Str(T_ho), Val(T_li), term__putc); /* home */
+ term_tputs(el, Str(T_ho), Val(T_li)); /* home */
/* clear to bottom of screen */
- (void) tputs(Str(T_cd), Val(T_li), term__putc);
+ term_tputs(el, Str(T_cd), Val(T_li));
} else {
- term__putc('\r');
- term__putc('\n');
+ term__putc(el, '\r');
+ term__putc(el, '\n');
}
}
@@ -855,9 +855,9 @@ term_beep(EditLine *el)
{
if (GoodStr(T_bl))
/* what termcap says we should use */
- (void) tputs(Str(T_bl), 1, term__putc);
+ term_tputs(el, Str(T_bl), 1);
else
- term__putc('\007'); /* an ASCII bell; ^G */
+ term__putc(el, '\007'); /* an ASCII bell; ^G */
}
@@ -869,9 +869,9 @@ protected void
term_clear_to_bottom(EditLine *el)
{
if (GoodStr(T_cd))
- (void) tputs(Str(T_cd), Val(T_li), term__putc);
+ term_tputs(el, Str(T_cd), Val(T_li));
else if (GoodStr(T_ce))
- (void) tputs(Str(T_ce), Val(T_li), term__putc);
+ term_tputs(el, Str(T_ce), Val(T_li));
}
#endif
@@ -1238,26 +1238,49 @@ term_bind_arrow(EditLine *el)
}
}
+/* term_putc():
+ * Add a character
+ */
+private int
+term_putc(int c)
+{
+
+ if (term_outfile == NULL)
+ return -1;
+ return fputc(c, term_outfile);
+}
+
+private void
+term_tputs(EditLine *el, const char *cap, int affcnt)
+{
+#ifdef _REENTRANT
+ pthread_mutex_lock(&term_mutex);
+#endif
+ term_outfile = el->el_outfile;
+ (void)tputs(cap, affcnt, term_putc);
+#ifdef _REENTRANT
+ pthread_mutex_unlock(&term_mutex);
+#endif
+}
/* term__putc():
* Add a character
*/
protected int
-term__putc(int c)
+term__putc(EditLine *el, int c)
{
- return (fputc(c, term_outfile));
+ return fputc(c, el->el_outfile);
}
-
/* term__flush():
* Flush output
*/
protected void
-term__flush(void)
+term__flush(EditLine *el)
{
- (void) fflush(term_outfile);
+ (void) fflush(el->el_outfile);
}
/* term_writec():
@@ -1267,10 +1290,10 @@ protected void
term_writec(EditLine *el, int c)
{
char buf[8];
- int cnt = key__decode_char(buf, sizeof(buf), 0, c);
+ size_t cnt = key__decode_char(buf, sizeof(buf), 0, c);
buf[cnt] = '\0';
- term_overwrite(el, buf, cnt);
- term__flush();
+ term_overwrite(el, buf, (size_t)cnt);
+ term__flush(el);
}
@@ -1585,7 +1608,7 @@ term_echotc(EditLine *el, int argc __unused,
*argv);
return (-1);
}
- (void) tputs(scap, 1, term__putc);
+ term_tputs(el, scap, 1);
break;
case 1:
argv++;
@@ -1613,7 +1636,7 @@ term_echotc(EditLine *el, int argc __unused,
*argv);
return (-1);
}
- (void) tputs(tgoto(scap, arg_cols, arg_rows), 1, term__putc);
+ term_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
break;
default:
/* This is wrong, but I will ignore it... */
@@ -1669,8 +1692,7 @@ term_echotc(EditLine *el, int argc __unused,
*argv);
return (-1);
}
- (void) tputs(tgoto(scap, arg_cols, arg_rows), arg_rows,
- term__putc);
+ term_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
break;
}
return (0);
diff --git a/lib/libedit/term.h b/lib/libedit/term.h
index 15d393c..4bf4685 100644
--- a/lib/libedit/term.h
+++ b/lib/libedit/term.h
@@ -85,7 +85,7 @@ typedef struct {
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_overwrite(EditLine *, const char *, size_t);
protected void term_insertwrite(EditLine *, char *, int);
protected void term_deletechars(EditLine *, int);
protected void term_clear_screen(EditLine *);
@@ -105,8 +105,8 @@ protected int term_gettc(EditLine *, int, char **);
protected int term_telltc(EditLine *, int, const char **);
protected int term_echotc(EditLine *, int, const char **);
protected void term_writec(EditLine *, int);
-protected int term__putc(int);
-protected void term__flush(void);
+protected int term__putc(EditLine *, int);
+protected void term__flush(EditLine *);
/*
* Easy access macros
diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c
index fca3c2b..c0b4638 100644
--- a/lib/libedit/tty.c
+++ b/lib/libedit/tty.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: tty.c,v 1.24 2006/03/18 09:07:05 christos Exp $
+ * $NetBSD: tty.c,v 1.25 2006/03/18 09:09:41 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index ae57e07..4826901 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: vi.c,v 1.25 2006/03/06 21:11:56 christos Exp $
+ * $NetBSD: vi.c,v 1.30 2009/02/21 23:31:56 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -63,7 +63,7 @@ cv_action(EditLine *el, int c)
if (!(c & YANK))
cv_undo(el);
cv_yank(el, el->el_line.buffer,
- el->el_line.lastchar - el->el_line.buffer);
+ (int)(el->el_line.lastchar - el->el_line.buffer));
el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_vcmd.pos = 0;
if (!(c & YANK)) {
@@ -87,12 +87,12 @@ private el_action_t
cv_paste(EditLine *el, int c)
{
c_kill_t *k = &el->el_chared.c_kill;
- int len = k->last - k->buf;
+ size_t len = (size_t)(k->last - k->buf);
if (k->buf == NULL || len == 0)
return (CC_ERROR);
#ifdef DEBUG_PASTE
- (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", len, k->buf);
+ (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf);
#endif
cv_undo(el);
@@ -100,10 +100,10 @@ cv_paste(EditLine *el, int c)
if (!c && el->el_line.cursor < el->el_line.lastchar)
el->el_line.cursor++;
- c_insert(el, len);
+ c_insert(el, (int)len);
if (el->el_line.cursor + len > el->el_line.lastchar)
return (CC_ERROR);
- (void) memcpy(el->el_line.cursor, k->buf, len +0u);
+ (void) memcpy(el->el_line.cursor, k->buf, len);
return (CC_REFRESH);
}
@@ -358,7 +358,7 @@ vi_substitute_line(EditLine *el, int c __unused)
cv_undo(el);
cv_yank(el, el->el_line.buffer,
- el->el_line.lastchar - el->el_line.buffer);
+ (int)(el->el_line.lastchar - el->el_line.buffer));
(void) em_kill_line(el, 0);
el->el_map.current = el->el_map.key;
return (CC_REFRESH);
@@ -376,7 +376,7 @@ vi_change_to_eol(EditLine *el, int c __unused)
cv_undo(el);
cv_yank(el, el->el_line.cursor,
- el->el_line.lastchar - el->el_line.cursor);
+ (int)(el->el_line.lastchar - el->el_line.cursor));
(void) ed_kill_line(el, 0);
el->el_map.current = el->el_map.key;
return (CC_REFRESH);
@@ -516,7 +516,8 @@ vi_undo(EditLine *el, int c __unused)
/* switch line buffer and undo buffer */
el->el_chared.c_undo.buf = el->el_line.buffer;
el->el_chared.c_undo.len = el->el_line.lastchar - el->el_line.buffer;
- el->el_chared.c_undo.cursor = el->el_line.cursor - el->el_line.buffer;
+ el->el_chared.c_undo.cursor =
+ (int)(el->el_line.cursor - el->el_line.buffer);
el->el_line.limit = un.buf + (el->el_line.limit - el->el_line.buffer);
el->el_line.buffer = un.buf;
el->el_line.cursor = un.buf + un.cursor;
@@ -641,7 +642,7 @@ vi_kill_line_prev(EditLine *el, int c __unused)
while (cp < el->el_line.cursor)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
- c_delbefore(el, el->el_line.cursor - el->el_line.buffer);
+ c_delbefore(el, (int)(el->el_line.cursor - el->el_line.buffer));
el->el_line.cursor = el->el_line.buffer; /* zap! */
return (CC_REFRESH);
}
@@ -797,7 +798,7 @@ vi_match(EditLine *el, int c)
{
const char match_chars[] = "()[]{}";
char *cp;
- int delta, i, count;
+ size_t delta, i, count;
char o_ch, c_ch;
*el->el_line.lastchar = '\0'; /* just in case */
@@ -872,7 +873,7 @@ vi_yank_end(EditLine *el, int c)
{
cv_yank(el, el->el_line.cursor,
- el->el_line.lastchar - el->el_line.cursor);
+ (int)(el->el_line.lastchar - el->el_line.cursor));
return CC_REFRESH;
}
@@ -993,7 +994,8 @@ vi_histedit(EditLine *el, int c)
{
int fd;
pid_t pid;
- int st;
+ ssize_t st;
+ int status;
char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
char *cp;
@@ -1006,7 +1008,7 @@ vi_histedit(EditLine *el, int c)
if (fd < 0)
return CC_ERROR;
cp = el->el_line.buffer;
- write(fd, cp, el->el_line.lastchar - cp +0u);
+ write(fd, cp, (size_t)(el->el_line.lastchar - cp));
write(fd, "\n", 1);
pid = fork();
switch (pid) {
@@ -1016,14 +1018,14 @@ vi_histedit(EditLine *el, int c)
return CC_ERROR;
case 0:
close(fd);
- execlp("vi", "vi", tempfile, NULL);
+ execlp("vi", "vi", tempfile, (char *)NULL);
exit(0);
/*NOTREACHED*/
default:
- while (waitpid(pid, &st, 0) != pid)
+ while (waitpid(pid, &status, 0) != pid)
continue;
- lseek(fd, 0ll, SEEK_SET);
- st = read(fd, cp, el->el_line.limit - cp +0u);
+ lseek(fd, (off_t)0, SEEK_SET);
+ st = read(fd, cp, (size_t)(el->el_line.limit - cp));
if (st > 0 && cp[st - 1] == '\n')
st--;
el->el_line.cursor = cp;
@@ -1072,7 +1074,7 @@ vi_history_word(EditLine *el, int c)
return CC_ERROR;
cv_undo(el);
- len = wep - wsp;
+ len = (int)(wep - wsp);
if (el->el_line.cursor < el->el_line.lastchar)
el->el_line.cursor++;
c_insert(el, len + 1);
OpenPOWER on IntegriCloud