Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit PR/56693: Walter Lozano: Add support for rl_dele...



details:   https://anonhg.NetBSD.org/src/rev/110953a5c310
branches:  trunk
changeset: 360010:110953a5c310
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Feb 08 15:05:10 2022 +0000

description:
PR/56693: Walter Lozano: Add support for rl_delete_text and rl_set_key

diffstat:

 lib/libedit/chared.c            |  38 ++++++++++++++++++++++++++++++++++++--
 lib/libedit/histedit.h          |   4 ++--
 lib/libedit/readline.c          |  22 ++++++++++++++++++++--
 lib/libedit/readline/readline.h |   4 +++-
 4 files changed, 61 insertions(+), 7 deletions(-)

diffs (152 lines):

diff -r 45610339aa01 -r 110953a5c310 lib/libedit/chared.c
--- a/lib/libedit/chared.c      Tue Feb 08 12:59:16 2022 +0000
+++ b/lib/libedit/chared.c      Tue Feb 08 15:05:10 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.c,v 1.60 2022/01/11 18:30:15 christos Exp $     */
+/*     $NetBSD: chared.c,v 1.61 2022/02/08 15:05:10 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)chared.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: chared.c,v 1.60 2022/01/11 18:30:15 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.61 2022/02/08 15:05:10 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -624,6 +624,40 @@
                el->el_line.cursor = el->el_line.buffer;
 }
 
+/* el_deletestr1():
+ *     Delete characters between starn and end
+ */
+int
+el_deletestr1(EditLine *el, int start, int end)
+{
+       size_t line_lenght, len;
+       wchar_t * p1, * p2;
+
+       if (end <= start)
+               return 0;
+
+       line_lenght = (size_t) (el->el_line.lastchar - el->el_line.buffer);
+
+       if (start >= (int) line_lenght || end >= (int) line_lenght)
+               return 0;
+
+       len = (size_t) (end - start);
+       if (len > line_lenght - (size_t) end)
+               len = line_lenght - (size_t) end;
+
+       p1 = el->el_line.buffer + start;
+       p2 = el->el_line.buffer + end;
+       for (size_t i = 0; i < len; i++){
+               *p1++ = *p2++;
+               el->el_line.lastchar--;
+       }
+
+       if (el->el_line.cursor < el->el_line.buffer)
+               el->el_line.cursor = el->el_line.buffer;
+
+       return end - start;
+}
+
 /* el_wreplacestr():
  *     Replace the contents of the line with the provided string
  */
diff -r 45610339aa01 -r 110953a5c310 lib/libedit/histedit.h
--- a/lib/libedit/histedit.h    Tue Feb 08 12:59:16 2022 +0000
+++ b/lib/libedit/histedit.h    Tue Feb 08 15:05:10 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: histedit.h,v 1.59 2022/01/11 18:30:15 christos Exp $   */
+/*     $NetBSD: histedit.h,v 1.60 2022/02/08 15:05:10 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -180,7 +180,7 @@
 int             el_insertstr(EditLine *, const char *);
 void            el_deletestr(EditLine *, int);
 int             el_replacestr(EditLine *el, const char *str);
-
+int             el_deletestr1(EditLine *el, int start, int end);
 
 /*
  * ==== History ====
diff -r 45610339aa01 -r 110953a5c310 lib/libedit/readline.c
--- a/lib/libedit/readline.c    Tue Feb 08 12:59:16 2022 +0000
+++ b/lib/libedit/readline.c    Tue Feb 08 15:05:10 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: readline.c,v 1.171 2022/01/31 14:44:49 christos Exp $  */
+/*     $NetBSD: readline.c,v 1.172 2022/02/08 15:05:10 christos Exp $  */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.171 2022/01/31 14:44:49 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.172 2022/02/08 15:05:10 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -2339,6 +2339,16 @@
        el_replacestr(e, text);
 }
 
+int
+rl_delete_text(int start, int end)
+{
+
+       if (h == NULL || e == NULL)
+               rl_initialize();
+
+       return el_deletestr1(e, start, end);
+}
+
 void
 rl_get_screen_size(int *rows, int *cols)
 {
@@ -2510,6 +2520,14 @@
        return 0;
 }
 
+int
+rl_set_key(const char *keyseq  __attribute__((__unused__)),
+       rl_command_func_t *function __attribute__((__unused__)),
+       Keymap k __attribute__((__unused__)))
+{
+       return 0;
+}
+
 /* unsupported, but needed by python */
 void
 rl_cleanup_after_signal(void)
diff -r 45610339aa01 -r 110953a5c310 lib/libedit/readline/readline.h
--- a/lib/libedit/readline/readline.h   Tue Feb 08 12:59:16 2022 +0000
+++ b/lib/libedit/readline/readline.h   Tue Feb 08 15:05:10 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: readline.h,v 1.51 2022/01/31 14:44:49 christos Exp $   */
+/*     $NetBSD: readline.h,v 1.52 2022/02/08 15:05:10 christos Exp $   */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -236,6 +236,7 @@
 int             rl_ding(void);
 char           *rl_copy_text(int, int);
 void            rl_replace_line(const char *, int);
+int             rl_delete_text(int, int);
 void            rl_message(const char *format, ...)
     __attribute__((__format__(__printf__, 1, 2)));
 void            rl_save_prompt(void);
@@ -250,6 +251,7 @@
 Keymap          rl_make_bare_keymap(void);
 int             rl_generic_bind(int, const char *, const char *, Keymap);
 int             rl_bind_key_in_map(int, rl_command_func_t *, Keymap);
+int             rl_set_key(const char *, rl_command_func_t *, Keymap);
 void            rl_cleanup_after_signal(void);
 void            rl_free_line_state(void);
 int             rl_set_keyboard_input_timeout(int);



Home | Main Index | Thread Index | Old Index