Module Name: src Committed By: christos Date: Tue Feb 8 15:05:10 UTC 2022
Modified Files: src/lib/libedit: chared.c histedit.h readline.c src/lib/libedit/readline: readline.h Log Message: PR/56693: Walter Lozano: Add support for rl_delete_text and rl_set_key To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/lib/libedit/chared.c cvs rdiff -u -r1.59 -r1.60 src/lib/libedit/histedit.h cvs rdiff -u -r1.171 -r1.172 src/lib/libedit/readline.c cvs rdiff -u -r1.51 -r1.52 src/lib/libedit/readline/readline.h 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/chared.c diff -u src/lib/libedit/chared.c:1.60 src/lib/libedit/chared.c:1.61 --- src/lib/libedit/chared.c:1.60 Tue Jan 11 13:30:15 2022 +++ src/lib/libedit/chared.c Tue Feb 8 10:05:10 2022 @@ -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_deletestr(EditLine *el, int n) 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 */ Index: src/lib/libedit/histedit.h diff -u src/lib/libedit/histedit.h:1.59 src/lib/libedit/histedit.h:1.60 --- src/lib/libedit/histedit.h:1.59 Tue Jan 11 13:30:15 2022 +++ src/lib/libedit/histedit.h Tue Feb 8 10:05:10 2022 @@ -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 @@ const LineInfo *el_line(EditLine *); 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 ==== Index: src/lib/libedit/readline.c diff -u src/lib/libedit/readline.c:1.171 src/lib/libedit/readline.c:1.172 --- src/lib/libedit/readline.c:1.171 Mon Jan 31 09:44:49 2022 +++ src/lib/libedit/readline.c Tue Feb 8 10:05:10 2022 @@ -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 @@ rl_replace_line(const char * text, int c 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 @@ rl_bind_key_in_map(int key __attribute__ 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) Index: src/lib/libedit/readline/readline.h diff -u src/lib/libedit/readline/readline.h:1.51 src/lib/libedit/readline/readline.h:1.52 --- src/lib/libedit/readline/readline.h:1.51 Mon Jan 31 09:44:49 2022 +++ src/lib/libedit/readline/readline.h Tue Feb 8 10:05:10 2022 @@ -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_crlf(void); 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 @@ void rl_set_keymap(Keymap); 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);