Skip to content

Commit

Permalink
Merge pull request #25 from knz/20230308-update-libedit
Browse files Browse the repository at this point in the history
  • Loading branch information
knz committed Mar 8, 2023
2 parents 5399e59 + b343c14 commit 657a11e
Show file tree
Hide file tree
Showing 44 changed files with 1,690 additions and 699 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yaml
@@ -0,0 +1,36 @@
name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
go:
- "1.16"
- "1.17"
- "1.18"
- "1.19"
- "1.20"
steps:
- uses: actions/checkout@v2

- name: Set up Go (${{ matrix.go }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Build (${{ matrix.go }})
run: go build ./...

- name: Test (${{ matrix.go }})
run: go test ./...

- name: Tidy (${{ matrix.go }})
run: '[[ `go version` < "go version go1.15.10" ]] || go mod tidy'
3 changes: 3 additions & 0 deletions go.mod
@@ -0,0 +1,3 @@
module github.com/knz/go-libedit

go 1.16
1 change: 1 addition & 0 deletions unix/shim/libedit-getline.c
@@ -0,0 +1 @@
// Nothing to see here.
1 change: 1 addition & 0 deletions unix/shim/libedit-literal.c
@@ -0,0 +1 @@
// Nothing to see here.
22 changes: 8 additions & 14 deletions unix/src/c-libedit/chared.c
@@ -1,4 +1,4 @@
/* $NetBSD: chared.c,v 1.56 2016/05/22 19:44:26 christos Exp $ */
/* $NetBSD: chared.c,v 1.59 2019/07/23 10:18:52 christos Exp $ */

/*-
* Copyright (c) 1992, 1993
Expand Down Expand Up @@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: chared.c,v 1.56 2016/05/22 19:44:26 christos Exp $");
__RCSID("$NetBSD: chared.c,v 1.59 2019/07/23 10:18:52 christos Exp $");
#endif
#endif /* not lint && not SCCSID */

Expand Down Expand Up @@ -174,7 +174,7 @@ c_delbefore(EditLine *el, int num)
wchar_t *cp;

for (cp = el->el_line.cursor - num;
cp <= el->el_line.lastchar;
&cp[num] <= el->el_line.lastchar;
cp++)
*cp = cp[num];

Expand Down Expand Up @@ -396,26 +396,22 @@ cv__endword(wchar_t *p, wchar_t *high, int n, int (*wtest)(wint_t))
libedit_private int
ch_init(EditLine *el)
{
el->el_line.buffer = el_malloc(EL_BUFSIZ *
el->el_line.buffer = el_calloc(EL_BUFSIZ,
sizeof(*el->el_line.buffer));
if (el->el_line.buffer == NULL)
return -1;

(void) memset(el->el_line.buffer, 0, EL_BUFSIZ *
sizeof(*el->el_line.buffer));
el->el_line.cursor = el->el_line.buffer;
el->el_line.lastchar = el->el_line.buffer;
el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - EL_LEAVE];

el->el_chared.c_undo.buf = el_malloc(EL_BUFSIZ *
el->el_chared.c_undo.buf = el_calloc(EL_BUFSIZ,
sizeof(*el->el_chared.c_undo.buf));
if (el->el_chared.c_undo.buf == NULL)
return -1;
(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ *
sizeof(*el->el_chared.c_undo.buf));
el->el_chared.c_undo.len = -1;
el->el_chared.c_undo.cursor = 0;
el->el_chared.c_redo.buf = el_malloc(EL_BUFSIZ *
el->el_chared.c_redo.buf = el_calloc(EL_BUFSIZ,
sizeof(*el->el_chared.c_redo.buf));
if (el->el_chared.c_redo.buf == NULL)
return -1;
Expand All @@ -426,12 +422,10 @@ ch_init(EditLine *el)
el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_vcmd.pos = el->el_line.buffer;

el->el_chared.c_kill.buf = el_malloc(EL_BUFSIZ *
el->el_chared.c_kill.buf = el_calloc(EL_BUFSIZ,
sizeof(*el->el_chared.c_kill.buf));
if (el->el_chared.c_kill.buf == NULL)
return -1;
(void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ *
sizeof(*el->el_chared.c_kill.buf));
el->el_chared.c_kill.mark = el->el_line.buffer;
el->el_chared.c_kill.last = el->el_chared.c_kill.buf;
el->el_chared.c_resizefun = NULL;
Expand Down Expand Up @@ -591,7 +585,7 @@ ch_end(EditLine *el)


/* el_insertstr():
* Insert string at cursorI
* Insert string at cursor
*/
int
el_winsertstr(EditLine *el, const wchar_t *s)
Expand Down
26 changes: 12 additions & 14 deletions unix/src/c-libedit/chartype.c
@@ -1,4 +1,4 @@
/* $NetBSD: chartype.c,v 1.31 2017/01/09 02:54:18 christos Exp $ */
/* $NetBSD: chartype.c,v 1.35 2019/07/23 10:18:52 christos Exp $ */

/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -31,10 +31,11 @@
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: chartype.c,v 1.31 2017/01/09 02:54:18 christos Exp $");
__RCSID("$NetBSD: chartype.c,v 1.35 2019/07/23 10:18:52 christos Exp $");
#endif /* not lint && not SCCSID */

#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -156,7 +157,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv)
if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1)
return NULL;

wargv = el_malloc((size_t)(argc + 1) * sizeof(*wargv));
wargv = el_calloc((size_t)(argc + 1), sizeof(*wargv));

for (i = 0, p = conv->wbuff; i < argc; ++i) {
if (!argv[i]) { /* don't pass null pointers to mbstowcs */
Expand All @@ -183,17 +184,14 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv)
libedit_private size_t
ct_enc_width(wchar_t c)
{
/* UTF-8 encoding specific values */
if (c < 0x80)
return 1;
else if (c < 0x0800)
return 2;
else if (c < 0x10000)
return 3;
else if (c < 0x110000)
return 4;
else
return 0; /* not a valid codepoint */
mbstate_t mbs;
char buf[MB_LEN_MAX];
size_t size;
memset(&mbs, 0, sizeof(mbs));

if ((size = wcrtomb(buf, c, &mbs)) == (size_t)-1)
return 0;
return size;
}

libedit_private ssize_t
Expand Down
11 changes: 8 additions & 3 deletions unix/src/c-libedit/chartype.h
@@ -1,4 +1,4 @@
/* $NetBSD: chartype.h,v 1.34 2016/05/09 21:46:56 christos Exp $ */
/* $NetBSD: chartype.h,v 1.36 2019/09/15 21:09:11 christos Exp $ */

/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -33,7 +33,12 @@
* supports non-BMP code points without requiring UTF-16, but nothing
* seems to actually advertise this properly, despite Unicode 3.1 having
* been around since 2001... */
#if !defined(__NetBSD__) && !defined(__sun) && !(defined(__APPLE__) && defined(__MACH__)) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
#if !defined(__NetBSD__) && \
!defined(__sun) && \
!(defined(__APPLE__) && defined(__MACH__)) && \
!defined(__OpenBSD__) && \
!defined(__FreeBSD__) && \
!defined(__DragonFly__)
#ifndef __STDC_ISO_10646__
/* In many places it is assumed that the first 127 code points are ASCII
* compatible, so ensure wchar_t indeed does ISO 10646 and not some other
Expand Down Expand Up @@ -82,7 +87,7 @@ libedit_private size_t ct_enc_width(wchar_t);
/* The terminal is thought of in terms of X columns by Y lines. In the cases
* where a wide character takes up more than one column, the adjacent
* occupied column entries will contain this faux character. */
#define MB_FILL_CHAR ((wchar_t)-1)
#define MB_FILL_CHAR ((wint_t)-1)

/* Visual width of character c, taking into account ^? , \0177 and \U+nnnnn
* style visual expansions. */
Expand Down
16 changes: 9 additions & 7 deletions unix/src/c-libedit/common.c
@@ -1,4 +1,4 @@
/* $NetBSD: common.c,v 1.47 2016/05/22 19:44:26 christos Exp $ */
/* $NetBSD: common.c,v 1.49 2020/03/30 06:54:37 ryo Exp $ */

/*-
* Copyright (c) 1992, 1993
Expand Down Expand Up @@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: common.c,v 1.47 2016/05/22 19:44:26 christos Exp $");
__RCSID("$NetBSD: common.c,v 1.49 2020/03/30 06:54:37 ryo Exp $");
#endif
#endif /* not lint && not SCCSID */

Expand Down Expand Up @@ -363,15 +363,17 @@ ed_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
* [^V] [^V]
*/
libedit_private el_action_t
ed_quoted_insert(EditLine *el, wint_t c)
/*ARGSUSED*/
ed_quoted_insert(EditLine *el, wint_t c __attribute__((__unused__)))
{
int num;
wchar_t ch;

tty_quotemode(el);
num = el_wgetc(el, &c);
num = el_wgetc(el, &ch);
tty_noquotemode(el);
if (num == 1)
return ed_insert(el, c);
return ed_insert(el, ch);
else
return ed_end_of_file(el, 0);
}
Expand Down Expand Up @@ -656,7 +658,7 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__)))

while (hp != NULL) {
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
(void) fprintf(el->el_errfile, "Comparing with \"%ls\"\n", hp);
#endif
if ((wcsncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) ||
Expand Down Expand Up @@ -711,7 +713,7 @@ ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__)))

for (h = 1; h < el->el_history.eventno && hp; h++) {
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
(void) fprintf(el->el_errfile, "Comparing with \"%ls\"\n", hp);
#endif
if ((wcsncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) ||
Expand Down
40 changes: 32 additions & 8 deletions unix/src/c-libedit/editline/readline.h
@@ -1,4 +1,4 @@
/* $NetBSD: readline.h,v 1.41 2016/10/28 18:32:35 christos Exp $ */
/* $NetBSD: readline.h,v 1.47 2021/08/21 12:34:59 christos Exp $ */

/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -38,11 +38,14 @@

/* typedefs */
typedef int Function(const char *, int);
typedef char *CPFunction(const char *, int);
typedef void VFunction(void);
typedef void rl_vcpfunc_t(char *);
typedef char **rl_completion_func_t(const char *, int, int);
typedef char *rl_compentry_func_t(const char *, int);
typedef int rl_command_func_t(int, int);
typedef int rl_hook_func_t(void);
typedef int rl_icppfunc_t(char **);

/* only supports length */
typedef struct {
Expand Down Expand Up @@ -97,23 +100,24 @@ extern "C" {
#endif
extern const char *rl_library_version;
extern int rl_readline_version;
extern char *rl_readline_name;
extern const char *rl_readline_name;
extern FILE *rl_instream;
extern FILE *rl_outstream;
extern char *rl_line_buffer;
extern int rl_point, rl_end;
extern int history_base, history_length;
extern int max_input_history;
extern char *rl_basic_word_break_characters;
extern const char *rl_basic_quote_characters;
extern const char *rl_basic_word_break_characters;
extern char *rl_completer_word_break_characters;
extern char *rl_completer_quote_characters;
extern const char *rl_completer_quote_characters;
extern rl_compentry_func_t *rl_completion_entry_function;
extern char *(*rl_completion_word_break_hook)(void);
extern rl_completion_func_t *rl_attempted_completion_function;
extern int rl_attempted_completion_over;
extern int rl_completion_type;
extern int rl_completion_query_items;
extern char *rl_special_prefixes;
extern const char *rl_special_prefixes;
extern int rl_completion_append_character;
extern int rl_inhibit_completion;
extern Function *rl_pre_input_hook;
Expand All @@ -125,6 +129,7 @@ extern int rl_done;
/*
* The following is not implemented
*/
extern unsigned long rl_readline_state;
extern int rl_catch_signals;
extern int rl_catch_sigwinch;
extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
Expand All @@ -137,8 +142,17 @@ extern VFunction *rl_redisplay_function;
extern VFunction *rl_completion_display_matches_hook;
extern VFunction *rl_prep_term_function;
extern VFunction *rl_deprep_term_function;
extern rl_hook_func_t *rl_event_hook;
extern int readline_echoing_p;
extern int _rl_print_completions_horizontally;
extern int _rl_complete_mark_directories;
extern rl_icppfunc_t *rl_directory_completion_hook;
extern int rl_completion_suppress_append;
extern int rl_sort_completion_matches;
extern int _rl_completion_prefix_display_length;
extern int _rl_echoing_p;
extern int history_max_entries;
extern char *rl_display_prompt;

/* supported functions */
char *readline(const char *);
Expand All @@ -147,6 +161,7 @@ int rl_initialize(void);
void using_history(void);
int add_history(const char *);
void clear_history(void);
int append_history(int, const char *);
void stifle_history(int);
int unstifle_history(void);
int history_is_stifled(void);
Expand Down Expand Up @@ -176,12 +191,13 @@ char *filename_completion_function(const char *, int);
char *username_completion_function(const char *, int);
int rl_complete(int, int);
int rl_read_key(void);
char **completion_matches(const char *, rl_compentry_func_t *);
char **completion_matches(/* const */ char *, rl_compentry_func_t *);
void rl_display_match_list(char **, int, int);

int rl_insert(int, int);
int rl_insert_text(const char *);
void rl_reset_terminal(const char *);
int rl_reset_terminal(const char *);
void rl_resize_terminal(void);
int rl_bind_key(int, rl_command_func_t *);
int rl_newline(int, int);
void rl_callback_read_char(void);
Expand All @@ -194,7 +210,7 @@ void rl_deprep_terminal(void);
int rl_read_init_file(const char *);
int rl_parse_and_bind(const char *);
int rl_variable_bind(const char *, const char *);
void rl_stuff_char(int);
int rl_stuff_char(int);
int rl_add_defun(const char *, rl_command_func_t *, int);
HISTORY_STATE *history_get_history_state(void);
void rl_get_screen_size(int *, int *);
Expand All @@ -206,6 +222,10 @@ char **rl_completion_matches(const char *, rl_compentry_func_t *);
void rl_forced_update_display(void);
int rl_set_prompt(const char *);
int rl_on_new_line(void);
void rl_reset_after_signal(void);
void rl_echo_signal_char(int);
int rl_crlf(void);
int rl_ding(void);

/*
* The following are not implemented
Expand All @@ -219,6 +239,10 @@ int rl_bind_key_in_map(int, rl_command_func_t *, Keymap);
void rl_cleanup_after_signal(void);
void rl_free_line_state(void);
int rl_set_keyboard_input_timeout(int);
int rl_abort(int, int);
int rl_set_keymap_name(const char *, Keymap);
histdata_t free_history_entry(HIST_ENTRY *);
void _rl_erase_entire_line(void);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 657a11e

Please sign in to comment.