Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libedit add literal escape sequence support, patterned a...
details: https://anonhg.NetBSD.org/src/rev/6c2f7afd481b
branches: trunk
changeset: 825050:6c2f7afd481b
user: christos <christos%NetBSD.org@localhost>
date: Tue Jun 27 23:25:13 2017 +0000
description:
add literal escape sequence support, patterned after the tcsh ones.
diffstat:
lib/libedit/Makefile | 4 +-
lib/libedit/el.c | 6 +-
lib/libedit/el.h | 8 ++-
lib/libedit/literal.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++
lib/libedit/literal.h | 53 ++++++++++++++++++++++++
lib/libedit/prompt.c | 19 +++++---
6 files changed, 184 insertions(+), 15 deletions(-)
diffs (truncated from 307 to 300 lines):
diff -r 92c532d653c3 -r 6c2f7afd481b lib/libedit/Makefile
--- a/lib/libedit/Makefile Tue Jun 27 23:24:19 2017 +0000
+++ b/lib/libedit/Makefile Tue Jun 27 23:25:13 2017 +0000
@@ -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.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 -r 92c532d653c3 -r 6c2f7afd481b lib/libedit/el.c
--- a/lib/libedit/el.c Tue Jun 27 23:24:19 2017 +0000
+++ b/lib/libedit/el.c Tue Jun 27 23:25:13 2017 +0000
@@ -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 @@
(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 @@
hist_end(el);
prompt_end(el);
sig_end(el);
+ literal_end(el);
el_free(el->el_prog);
el_free(el->el_visual.cbuff);
diff -r 92c532d653c3 -r 6c2f7afd481b lib/libedit/el.h
--- a/lib/libedit/el.h Tue Jun 27 23:24:19 2017 +0000
+++ b/lib/libedit/el.h Tue Jun 27 23:25:13 2017 +0000
@@ -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 @@
#include "tty.h"
#include "prompt.h"
+#include "literal.h"
#include "keymacro.h"
#include "terminal.h"
#include "refresh.h"
@@ -115,8 +116,8 @@
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 @@
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 -r 92c532d653c3 -r 6c2f7afd481b lib/libedit/literal.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libedit/literal.c Tue Jun 27 23:25:13 2017 +0000
@@ -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 -r 92c532d653c3 -r 6c2f7afd481b lib/libedit/literal.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libedit/literal.h Tue Jun 27 23:25:13 2017 +0000
@@ -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 -r 92c532d653c3 -r 6c2f7afd481b lib/libedit/prompt.c
--- a/lib/libedit/prompt.c Tue Jun 27 23:24:19 2017 +0000
+++ b/lib/libedit/prompt.c Tue Jun 27 23:25:13 2017 +0000
@@ -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 @@
{
el_prompt_t *elp;
wchar_t *p;
- int ignore = 0;
if (op == EL_PROMPT)
elp = &el->el_prompt;
@@ -99,13 +98,17 @@
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)
Home |
Main Index |
Thread Index |
Old Index