summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2017-06-27 23:25:13 +0000
committerchristos <christos@NetBSD.org>2017-06-27 23:25:13 +0000
commit2a3f18a892178f222416ffa18daec0aaefaecb0e (patch)
tree40046ad867ba1c2a9aae09c52b4c8aa0f0d9c211 /lib
parent080a15b3eacfe45be5cbff0ea3503c3c53c40c79 (diff)
add literal escape sequence support, patterned after the tcsh ones.
Diffstat (limited to 'lib')
-rw-r--r--lib/libedit/Makefile4
-rw-r--r--lib/libedit/el.c6
-rw-r--r--lib/libedit/el.h8
-rw-r--r--lib/libedit/literal.c109
-rw-r--r--lib/libedit/literal.h53
-rw-r--r--lib/libedit/prompt.c19
6 files changed, 184 insertions, 15 deletions
diff --git a/lib/libedit/Makefile b/lib/libedit/Makefile
index 40615bd6485..a7ed9f8161f 100644
--- a/lib/libedit/Makefile
+++ b/lib/libedit/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.63 2016/05/24 17:42:54 christos Exp $
+# $NetBSD: Makefile,v 1.64 2017/06/27 23:25:13 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
@@ -15,7 +15,7 @@ CWARNFLAGS.gcc+= -Wconversion
CWARNFLAGS.clang+= -Wno-cast-qual
SRCS = chared.c chartype.c common.c el.c eln.c emacs.c filecomplete.c \
- hist.c history.c historyn.c keymacro.c map.c \
+ hist.c history.c historyn.c keymacro.c literal.c map.c \
parse.c prompt.c read.c readline.c refresh.c search.c sig.c \
terminal.c tokenizer.c tokenizern.c tty.c vi.c
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index b562731c99e..1ff644c7b5e 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -1,4 +1,4 @@
-/* $NetBSD: el.c,v 1.93 2017/06/27 00:47:37 kre Exp $ */
+/* $NetBSD: el.c,v 1.94 2017/06/27 23:25:13 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else
-__RCSID("$NetBSD: el.c,v 1.93 2017/06/27 00:47:37 kre Exp $");
+__RCSID("$NetBSD: el.c,v 1.94 2017/06/27 23:25:13 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -115,6 +115,7 @@ el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
(void) hist_init(el);
(void) prompt_init(el);
(void) sig_init(el);
+ (void) literal_init(el);
if (read_init(el) == -1) {
el_end(el);
return NULL;
@@ -146,6 +147,7 @@ el_end(EditLine *el)
hist_end(el);
prompt_end(el);
sig_end(el);
+ literal_end(el);
el_free(el->el_prog);
el_free(el->el_visual.cbuff);
diff --git a/lib/libedit/el.h b/lib/libedit/el.h
index c281bc01b4d..c0d52786fd4 100644
--- a/lib/libedit/el.h
+++ b/lib/libedit/el.h
@@ -1,4 +1,4 @@
-/* $NetBSD: el.h,v 1.41 2016/05/24 15:00:45 christos Exp $ */
+/* $NetBSD: el.h,v 1.42 2017/06/27 23:25:13 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -94,6 +94,7 @@ typedef struct el_state_t {
#include "tty.h"
#include "prompt.h"
+#include "literal.h"
#include "keymacro.h"
#include "terminal.h"
#include "refresh.h"
@@ -115,8 +116,8 @@ struct editline {
int el_errfd; /* Error file descriptor */
int el_flags; /* Various flags. */
coord_t el_cursor; /* Cursor location */
- wchar_t **el_display; /* Real screen image = what is there */
- wchar_t **el_vdisplay; /* Virtual screen image = what we see */
+ wint_t **el_display; /* Real screen image = what is there */
+ wint_t **el_vdisplay; /* Virtual screen image = what we see */
void *el_data; /* Client data */
el_line_t el_line; /* The current line information */
el_state_t el_state; /* Current editor state */
@@ -125,6 +126,7 @@ struct editline {
el_refresh_t el_refresh; /* Refresh stuff */
el_prompt_t el_prompt; /* Prompt stuff */
el_prompt_t el_rprompt; /* Prompt stuff */
+ el_literal_t el_literal; /* prompt literal bits */
el_chared_t el_chared; /* Characted editor stuff */
el_map_t el_map; /* Key mapping stuff */
el_keymacro_t el_keymacro; /* Key binding stuff */
diff --git a/lib/libedit/literal.c b/lib/libedit/literal.c
new file mode 100644
index 00000000000..b793b5d13c4
--- /dev/null
+++ b/lib/libedit/literal.c
@@ -0,0 +1,109 @@
+/* $NetBSD: literal.c,v 1.1 2017/06/27 23:25:13 christos Exp $ */
+
+/*-
+ * Copyright (c) 2017 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.
+ *
+ * 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"
+#if !defined(lint) && !defined(SCCSID)
+__RCSID("$NetBSD: literal.c,v 1.1 2017/06/27 23:25:13 christos Exp $");
+#endif /* not lint && not SCCSID */
+
+/*
+ * literal.c: Literal sequences handling.
+ */
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "el.h"
+
+libedit_private void
+literal_init(EditLine *el)
+{
+ el_literal_t *l = &el->el_literal;
+ memset(l, 0, sizeof(*l));
+}
+
+libedit_private void
+literal_end(EditLine *el)
+{
+ el_literal_t *l = &el->el_literal;
+ literal_clear(el);
+ el_free(l->l_buf);
+}
+
+libedit_private void
+literal_clear(EditLine *el)
+{
+ el_literal_t *l = &el->el_literal;
+ size_t i;
+ for (i = 0; i < l->l_idx; l++)
+ el_free(l->l_buf[i]);
+ l->l_len = 0;
+ l->l_idx = 0;
+}
+
+libedit_private wint_t
+literal_add(EditLine *el, const wchar_t *buf, const wchar_t *end)
+{
+ // XXX: Only for narrow chars now.
+ el_literal_t *l = &el->el_literal;
+ size_t i, len;
+ char *b;
+
+ len = (size_t)(end - buf);
+ b = el_malloc(len + 2);
+ if (b == NULL)
+ return 0;
+ for (i = 0; i < len; i++)
+ b[i] = (char)buf[i];
+ b[len] = (char)end[1];
+ b[len + 1] = '\0';
+ if (l->l_idx == l->l_len) {
+ l->l_len += 10;
+ char **bp = el_realloc(l->l_buf, sizeof(*l->l_buf) * l->l_len);
+ if (bp == NULL) {
+ free(b);
+ return 0;
+ }
+ l->l_buf = bp;
+ }
+ l->l_buf[l->l_idx++] = b;
+ return EL_LITERAL | (wint_t)(l->l_idx - 1);
+}
+
+libedit_private const char *
+literal_get(EditLine *el, wint_t idx)
+{
+ el_literal_t *l = &el->el_literal;
+ assert(idx & EL_LITERAL);
+ idx &= ~EL_LITERAL;
+ assert(l->l_idx > (size_t)idx);
+ return l->l_buf[idx];
+}
diff --git a/lib/libedit/literal.h b/lib/libedit/literal.h
new file mode 100644
index 00000000000..5e78d71f1a2
--- /dev/null
+++ b/lib/libedit/literal.h
@@ -0,0 +1,53 @@
+/* $NetBSD: literal.h,v 1.1 2017/06/27 23:25:13 christos Exp $ */
+
+/*-
+ * Copyright (c) 2017 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.
+ *
+ * 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.
+ */
+
+/*
+ * el.literal.h: Literal character
+ */
+#ifndef _h_el_literal
+#define _h_el_literal
+
+#define EL_LITERAL ((wint_t)0x80000000)
+
+typedef struct el_literal_t {
+ char **l_buf; /* array of buffers */
+ size_t l_idx; /* max in use */
+ size_t l_len; /* max allocated */
+} el_literal_t;
+
+libedit_private void literal_init(EditLine *);
+libedit_private void literal_end(EditLine *);
+libedit_private void literal_clear(EditLine *);
+libedit_private wint_t literal_add(EditLine *, const wchar_t *,
+ const wchar_t *);
+libedit_private const char *literal_get(EditLine *, wint_t);
+
+#endif /* _h_el_literal */
diff --git a/lib/libedit/prompt.c b/lib/libedit/prompt.c
index a3d9915ec0e..026a746af5f 100644
--- a/lib/libedit/prompt.c
+++ b/lib/libedit/prompt.c
@@ -1,4 +1,4 @@
-/* $NetBSD: prompt.c,v 1.26 2016/05/09 21:46:56 christos Exp $ */
+/* $NetBSD: prompt.c,v 1.27 2017/06/27 23:25:13 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: prompt.c,v 1.26 2016/05/09 21:46:56 christos Exp $");
+__RCSID("$NetBSD: prompt.c,v 1.27 2017/06/27 23:25:13 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -84,7 +84,6 @@ prompt_print(EditLine *el, int op)
{
el_prompt_t *elp;
wchar_t *p;
- int ignore = 0;
if (op == EL_PROMPT)
elp = &el->el_prompt;
@@ -99,13 +98,17 @@ prompt_print(EditLine *el, int op)
for (; *p; p++) {
if (elp->p_ignore == *p) {
- ignore = !ignore;
+ wchar_t *litstart = ++p;
+ while (*p && *p != elp->p_ignore)
+ p++;
+ if (!*p || !p[1]) {
+ // XXX: We lose the last literal
+ break;
+ }
+ re_putliteral(el, litstart, p++);
continue;
}
- if (ignore)
- terminal__putc(el, *p);
- else
- re_putc(el, *p, 1);
+ re_putc(el, *p, 1);
}
elp->p_pos.v = el->el_refresh.r_cursor.v;