Module Name:    src
Committed By:   christos
Date:           Tue Jun 27 23:25:13 UTC 2017

Modified Files:
        src/lib/libedit: Makefile el.c el.h prompt.c
Added Files:
        src/lib/libedit: literal.c literal.h

Log Message:
add literal escape sequence support, patterned after the tcsh ones.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/libedit/Makefile
cvs rdiff -u -r1.93 -r1.94 src/lib/libedit/el.c
cvs rdiff -u -r1.41 -r1.42 src/lib/libedit/el.h
cvs rdiff -u -r0 -r1.1 src/lib/libedit/literal.c src/lib/libedit/literal.h
cvs rdiff -u -r1.26 -r1.27 src/lib/libedit/prompt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/Makefile
diff -u src/lib/libedit/Makefile:1.63 src/lib/libedit/Makefile:1.64
--- src/lib/libedit/Makefile:1.63	Tue May 24 13:42:54 2016
+++ src/lib/libedit/Makefile	Tue Jun 27 19:25:13 2017
@@ -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
 

Index: src/lib/libedit/el.c
diff -u src/lib/libedit/el.c:1.93 src/lib/libedit/el.c:1.94
--- src/lib/libedit/el.c:1.93	Mon Jun 26 20:47:37 2017
+++ src/lib/libedit/el.c	Tue Jun 27 19:25:13 2017
@@ -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, 
 	(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);

Index: src/lib/libedit/el.h
diff -u src/lib/libedit/el.h:1.41 src/lib/libedit/el.h:1.42
--- src/lib/libedit/el.h:1.41	Tue May 24 11:00:45 2016
+++ src/lib/libedit/el.h	Tue Jun 27 19:25:13 2017
@@ -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		*/

Index: src/lib/libedit/prompt.c
diff -u src/lib/libedit/prompt.c:1.26 src/lib/libedit/prompt.c:1.27
--- src/lib/libedit/prompt.c:1.26	Mon May  9 17:46:56 2016
+++ src/lib/libedit/prompt.c	Tue Jun 27 19:25:13 2017
@@ -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;

Added files:

Index: src/lib/libedit/literal.c
diff -u /dev/null src/lib/libedit/literal.c:1.1
--- /dev/null	Tue Jun 27 19:25:13 2017
+++ src/lib/libedit/literal.c	Tue Jun 27 19:25:13 2017
@@ -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];
+}
Index: src/lib/libedit/literal.h
diff -u /dev/null src/lib/libedit/literal.h:1.1
--- /dev/null	Tue Jun 27 19:25:13 2017
+++ src/lib/libedit/literal.h	Tue Jun 27 19:25:13 2017
@@ -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 */

Reply via email to