summaryrefslogtreecommitdiffstats
path: root/dist/el.c
diff options
context:
space:
mode:
Diffstat (limited to 'dist/el.c')
-rw-r--r--dist/el.c108
1 files changed, 78 insertions, 30 deletions
diff --git a/dist/el.c b/dist/el.c
index 3cff286..57ca255 100644
--- a/dist/el.c
+++ b/dist/el.c
@@ -1,4 +1,4 @@
-/* $NetBSD: el.c,v 1.23 2001/09/27 19:29:50 christos Exp $ */
+/* $NetBSD: el.c,v 1.40 2005/08/01 23:00:15 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -15,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -36,20 +32,18 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.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.23 2001/09/27 19:29:50 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.40 2005/08/01 23:00:15 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
/*
* el.c: EditLine interface functions
*/
-#include "sys.h"
-
#include <sys/types.h>
#include <sys/param.h>
#include <string.h>
@@ -65,9 +59,6 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
{
EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
-#ifdef DEBUG
- char *tty;
-#endif
if (el == NULL)
return (NULL);
@@ -77,14 +68,21 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
el->el_infd = fileno(fin);
el->el_outfile = fout;
el->el_errfile = ferr;
- el->el_prog = strdup(prog);
+ if ((el->el_prog = el_strdup(prog)) == NULL) {
+ el_free(el);
+ return NULL;
+ }
/*
* Initialize all the modules. Order is important!!!
*/
el->el_flags = 0;
- (void) term_init(el);
+ if (term_init(el) == -1) {
+ el_free(el->el_prog);
+ el_free(el);
+ return NULL;
+ }
(void) key_init(el);
(void) map_init(el);
if (tty_init(el) == -1)
@@ -135,7 +133,7 @@ el_reset(EditLine *el)
{
tty_cookedmode(el);
- ch_reset(el); /* XXX: Do we want that? */
+ ch_reset(el, 0); /* XXX: Do we want that? */
}
@@ -146,7 +144,7 @@ public int
el_set(EditLine *el, int op, ...)
{
va_list va;
- int rv;
+ int rv = 0;
if (el == NULL)
return (-1);
@@ -171,7 +169,6 @@ el_set(EditLine *el, int op, ...)
el->el_flags |= HANDLE_SIGNALS;
else
el->el_flags &= ~HANDLE_SIGNALS;
- rv = 0;
break;
case EL_BIND:
@@ -180,7 +177,7 @@ el_set(EditLine *el, int op, ...)
case EL_ECHOTC:
case EL_SETTY:
{
- char *argv[20];
+ const char *argv[20];
int i;
for (i = 1; i < 20; i++)
@@ -255,8 +252,34 @@ el_set(EditLine *el, int op, ...)
break;
}
+ case EL_CLIENTDATA:
+ el->el_data = va_arg(va, void *);
+ break;
+
+ case EL_UNBUFFERED:
+ rv = va_arg(va, int);
+ if (rv && !(el->el_flags & UNBUFFERED)) {
+ el->el_flags |= UNBUFFERED;
+ read_prepare(el);
+ } else if (!rv && (el->el_flags & UNBUFFERED)) {
+ el->el_flags &= ~UNBUFFERED;
+ read_finish(el);
+ }
+ rv = 0;
+ break;
+
+ case EL_PREP_TERM:
+ rv = va_arg(va, int);
+ if (rv)
+ (void) tty_rawmode(el);
+ else
+ (void) tty_cookedmode(el);
+ rv = 0;
+ break;
+
default:
rv = -1;
+ break;
}
va_end(va);
@@ -277,11 +300,11 @@ el_get(EditLine *el, int op, void *ret)
switch (op) {
case EL_PROMPT:
case EL_RPROMPT:
- rv = prompt_get(el, (el_pfunc_t *) & ret, op);
+ rv = prompt_get(el, (void *) &ret, op);
break;
case EL_EDITOR:
- rv = map_get_editor(el, (const char **) &ret);
+ rv = map_get_editor(el, (void *) &ret);
break;
case EL_SIGNAL:
@@ -294,21 +317,22 @@ el_get(EditLine *el, int op, void *ret)
rv = 0;
break;
-#if 0 /* XXX */
case EL_TERMINAL:
- rv = term_get(el, (const char *) &ret);
+ term_get(el, (const char **)ret);
+ rv = 0;
break;
+#if 0 /* XXX */
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY:
{
- char *argv[20];
+ const char *argv[20];
int i;
- for (i = 1; i < 20; i++)
+ for (i = 1; i < sizeof(argv) / sizeof(argv[0]); i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
break;
@@ -370,6 +394,16 @@ el_get(EditLine *el, int op, void *ret)
rv = 0;
break;
+ case EL_CLIENTDATA:
+ *((void **)ret) = el->el_data;
+ rv = 0;
+ break;
+
+ case EL_UNBUFFERED:
+ *((int *) ret) = (!(el->el_flags & UNBUFFERED));
+ rv = 0;
+ break;
+
default:
rv = -1;
}
@@ -388,7 +422,6 @@ el_line(EditLine *el)
return (const LineInfo *) (void *) &el->el_line;
}
-static const char elpath[] = "/.editrc";
/* el_source():
* Source a file
@@ -398,10 +431,14 @@ el_source(EditLine *el, const char *fname)
{
FILE *fp;
size_t len;
- char *ptr, path[MAXPATHLEN];
+ char *ptr;
fp = NULL;
if (fname == NULL) {
+#ifdef HAVE_ISSETUGID
+ static const char elpath[] = "/.editrc";
+ char path[MAXPATHLEN];
+
if (issetugid())
return (-1);
if ((ptr = getenv("HOME")) == NULL)
@@ -411,6 +448,14 @@ el_source(EditLine *el, const char *fname)
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
return (-1);
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)
fp = fopen(fname, "r");
@@ -469,7 +514,7 @@ el_beep(EditLine *el)
*/
protected int
/*ARGSUSED*/
-el_editmode(EditLine *el, int argc, char **argv)
+el_editmode(EditLine *el, int argc, const char **argv)
{
const char *how;
@@ -477,10 +522,13 @@ el_editmode(EditLine *el, int argc, char **argv)
return (-1);
how = argv[1];
- if (strcmp(how, "on") == 0)
+ if (strcmp(how, "on") == 0) {
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;
+ }
else {
(void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
return (-1);
OpenPOWER on IntegriCloud