Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit - handle literal escape sequence printing.



details:   https://anonhg.NetBSD.org/src/rev/6cbf8dcd9eca
branches:  trunk
changeset: 825047:6cbf8dcd9eca
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Jun 27 23:23:09 2017 +0000

description:
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.

diffstat:

 lib/libedit/terminal.c |  99 ++++++++++++++++++++++++-------------------------
 1 files changed, 49 insertions(+), 50 deletions(-)

diffs (143 lines):

diff -r 952ce6f034d3 -r 6cbf8dcd9eca lib/libedit/terminal.c
--- a/lib/libedit/terminal.c    Tue Jun 27 23:22:20 2017 +0000
+++ b/lib/libedit/terminal.c    Tue Jun 27 23:23:09 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: terminal.c,v 1.32 2016/05/09 21:46:56 christos Exp $   */
+/*     $NetBSD: terminal.c,v 1.33 2017/06/27 23:23:09 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)term.c     8.2 (Berkeley) 4/30/95";
 #else
-__RCSID("$NetBSD: terminal.c,v 1.32 2016/05/09 21:46:56 christos Exp $");
+__RCSID("$NetBSD: terminal.c,v 1.33 2017/06/27 23:23:09 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -419,6 +419,45 @@
        return 0;
 }
 
+static wchar_t **
+terminal_alloc_buffer(EditLine *el)
+{
+       wint_t **b;
+       coord_t *c = &el->el_terminal.t_size;
+       int i;
+
+       b =  el_malloc(sizeof(*b) * (size_t)(c->v + 1));
+       if (b == NULL)
+               return NULL;
+       for (i = 0; i < c->v; i++) {
+               b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
+               if (b[i] == NULL) {
+                       while (--i >= 0)
+                               el_free(b[i]);
+                       el_free(b);
+                       return NULL;
+               }
+       }
+       b[c->v] = NULL;
+       return b;
+}
+
+static void
+terminal_free_buffer(wint_t ***bp)
+{
+       wint_t **b;
+       wint_t **bufp;
+
+       if (*bp == NULL)
+               return;
+
+       b = *bp;
+       *bp = NULL;
+
+       for (bufp = b; *bufp != NULL; bufp++)
+               el_free(*bufp);
+       el_free(b);
+}
 
 /* terminal_alloc_display():
  *     Allocate a new display.
@@ -426,39 +465,12 @@
 static int
 terminal_alloc_display(EditLine *el)
 {
-       int i;
-       wchar_t **b;
-       coord_t *c = &el->el_terminal.t_size;
-
-       b =  el_malloc(sizeof(*b) * (size_t)(c->v + 1));
-       if (b == NULL)
+       el->el_display = terminal_alloc_buffer(el);
+       if (el->el_display == NULL)
                goto done;
-       for (i = 0; i < c->v; i++) {
-               b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
-               if (b[i] == NULL) {
-                       while (--i >= 0)
-                               el_free(b[i]);
-                       el_free(b);
-                       goto done;
-               }
-       }
-       b[c->v] = NULL;
-       el->el_display = b;
-
-       b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
-       if (b == NULL)
+       el->el_vdisplay = terminal_alloc_buffer(el);
+       if (el->el_vdisplay == NULL)
                goto done;
-       for (i = 0; i < c->v; i++) {
-               b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
-               if (b[i] == NULL) {
-                       while (--i >= 0)
-                               el_free(b[i]);
-                       el_free(b);
-                       goto done;
-               }
-       }
-       b[c->v] = NULL;
-       el->el_vdisplay = b;
        return 0;
 done:
        terminal_free_display(el);
@@ -472,23 +484,8 @@
 static void
 terminal_free_display(EditLine *el)
 {
-       wchar_t **b;
-       wchar_t **bufp;
-
-       b = el->el_display;
-       el->el_display = NULL;
-       if (b != NULL) {
-               for (bufp = b; *bufp != NULL; bufp++)
-                       el_free(*bufp);
-               el_free(b);
-       }
-       b = el->el_vdisplay;
-       el->el_vdisplay = NULL;
-       if (b != NULL) {
-               for (bufp = b; *bufp != NULL; bufp++)
-                       el_free(*bufp);
-               el_free(b);
-       }
+       terminal_free_buffer(&el->el_display);
+       terminal_free_buffer(&el->el_vdisplay);
 }
 
 
@@ -1254,6 +1251,8 @@
        ssize_t i;
        if (c == (wint_t)MB_FILL_CHAR)
                return 0;
+       if (c & EL_LITERAL)
+               return fputs(literal_get(el, c), el->el_outfile);
        i = ct_encode_char(buf, (size_t)MB_LEN_MAX, c);
        if (i <= 0)
                return (int)i;



Home | Main Index | Thread Index | Old Index