Module Name: src
Committed By: christos
Date: Wed Feb 24 17:13:22 UTC 2016
Modified Files:
src/lib/libedit: chartype.c chartype.h el.c el.h eln.c read.c read.h
readline.c
Log Message:
Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libedit/chartype.c
cvs rdiff -u -r1.21 -r1.22 src/lib/libedit/chartype.h
cvs rdiff -u -r1.82 -r1.83 src/lib/libedit/el.c
cvs rdiff -u -r1.33 -r1.34 src/lib/libedit/el.h
cvs rdiff -u -r1.26 -r1.27 src/lib/libedit/eln.c
cvs rdiff -u -r1.83 -r1.84 src/lib/libedit/read.c
cvs rdiff -u -r1.8 -r1.9 src/lib/libedit/read.h
cvs rdiff -u -r1.125 -r1.126 src/lib/libedit/readline.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/chartype.c
diff -u src/lib/libedit/chartype.c:1.20 src/lib/libedit/chartype.c:1.21
--- src/lib/libedit/chartype.c:1.20 Wed Feb 24 09:25:38 2016
+++ src/lib/libedit/chartype.c Wed Feb 24 12:13:22 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.c,v 1.20 2016/02/24 14:25:38 christos Exp $ */
+/* $NetBSD: chartype.c,v 1.21 2016/02/24 17:13:22 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.20 2016/02/24 14:25:38 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.21 2016/02/24 17:13:22 christos Exp $");
#endif /* not lint && not SCCSID */
#include <ctype.h>
@@ -219,7 +219,7 @@ ct_encode_char(char *dst, size_t len, Ch
size_t
/*ARGSUSED*/
-ct_mbrtowc(char *wc, const char *s, size_t n,
+ct_mbrtowc(wchar_t *wc, const char *s, size_t n,
void *mbs __attribute__((__unused__))) {
if (s == NULL)
return 0;
Index: src/lib/libedit/chartype.h
diff -u src/lib/libedit/chartype.h:1.21 src/lib/libedit/chartype.h:1.22
--- src/lib/libedit/chartype.h:1.21 Wed Feb 17 14:47:49 2016
+++ src/lib/libedit/chartype.h Wed Feb 24 12:13:22 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.h,v 1.21 2016/02/17 19:47:49 christos Exp $ */
+/* $NetBSD: chartype.h,v 1.22 2016/02/24 17:13:22 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -113,7 +113,7 @@ Width(wchar_t c)
#else /* NARROW */
-size_t ct_mbrtowc(char *, const char *, size_t, void *);
+size_t ct_mbrtowc(wchar_t *, const char *, size_t, void *);
#define ct_wctob(w) ((int)(w))
#define ct_wctomb error
#define ct_wctomb_reset
Index: src/lib/libedit/el.c
diff -u src/lib/libedit/el.c:1.82 src/lib/libedit/el.c:1.83
--- src/lib/libedit/el.c:1.82 Wed Feb 17 14:47:49 2016
+++ src/lib/libedit/el.c Wed Feb 24 12:13:22 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: el.c,v 1.82 2016/02/17 19:47:49 christos Exp $ */
+/* $NetBSD: el.c,v 1.83 2016/02/24 17:13:22 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.82 2016/02/17 19:47:49 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.83 2016/02/24 17:13:22 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -308,7 +308,6 @@ FUN(el,set)(EditLine *el, int op, ...)
{
el_rfunc_t rc = va_arg(ap, el_rfunc_t);
rv = el_read_setfn(el, rc);
- el->el_flags &= ~NARROW_READ;
break;
}
Index: src/lib/libedit/el.h
diff -u src/lib/libedit/el.h:1.33 src/lib/libedit/el.h:1.34
--- src/lib/libedit/el.h:1.33 Wed Feb 17 14:47:49 2016
+++ src/lib/libedit/el.h Wed Feb 24 12:13:22 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: el.h,v 1.33 2016/02/17 19:47:49 christos Exp $ */
+/* $NetBSD: el.h,v 1.34 2016/02/24 17:13:22 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -57,7 +57,6 @@
#define UNBUFFERED 0x08
#define CHARSET_IS_UTF8 0x10
#define NARROW_HISTORY 0x40
-#define NARROW_READ 0x80
typedef unsigned char el_action_t; /* Index to command array */
Index: src/lib/libedit/eln.c
diff -u src/lib/libedit/eln.c:1.26 src/lib/libedit/eln.c:1.27
--- src/lib/libedit/eln.c:1.26 Wed Feb 24 09:25:38 2016
+++ src/lib/libedit/eln.c Wed Feb 24 12:13:22 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: eln.c,v 1.26 2016/02/24 14:25:38 christos Exp $ */
+/* $NetBSD: eln.c,v 1.27 2016/02/24 17:13:22 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: eln.c,v 1.26 2016/02/24 14:25:38 christos Exp $");
+__RCSID("$NetBSD: eln.c,v 1.27 2016/02/24 17:13:22 christos Exp $");
#endif /* not lint && not SCCSID */
#include <errno.h>
@@ -247,10 +247,8 @@ el_set(EditLine *el, int op, ...)
break;
}
- /* XXX: do we need to change el_rfunc_t? */
case EL_GETCFN: /* el_rfunc_t */
ret = el_wset(el, op, va_arg(ap, el_rfunc_t));
- el->el_flags |= NARROW_READ;
break;
case EL_CLIENTDATA: /* void * */
@@ -344,7 +342,6 @@ el_get(EditLine *el, int op, ...)
break;
}
- /* XXX: do we need to change el_rfunc_t? */
case EL_GETCFN: /* el_rfunc_t */
ret = el_wget(el, op, va_arg(ap, el_rfunc_t *));
break;
Index: src/lib/libedit/read.c
diff -u src/lib/libedit/read.c:1.83 src/lib/libedit/read.c:1.84
--- src/lib/libedit/read.c:1.83 Wed Feb 24 09:25:38 2016
+++ src/lib/libedit/read.c Wed Feb 24 12:13:22 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.83 2016/02/24 14:25:38 christos Exp $ */
+/* $NetBSD: read.c,v 1.84 2016/02/24 17:13:22 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: read.c,v 1.83 2016/02/24 14:25:38 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.84 2016/02/24 17:13:22 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -59,7 +59,7 @@ __RCSID("$NetBSD: read.c,v 1.83 2016/02/
private int read__fixio(int, int);
private int read_preread(EditLine *);
-private int read_char(EditLine *, Char *);
+private int read_char(EditLine *, wchar_t *);
private int read_getcmd(EditLine *, el_action_t *, Char *);
private void read_pop(c_macro_t *);
@@ -304,7 +304,7 @@ read_getcmd(EditLine *el, el_action_t *c
* Read a character from the tty.
*/
private int
-read_char(EditLine *el, Char *cp)
+read_char(EditLine *el, wchar_t *cp)
{
ssize_t num_read;
int tried = 0;
@@ -331,14 +331,14 @@ read_char(EditLine *el, Char *cp)
tried = 1;
} else {
errno = e;
- *cp = '\0';
+ *cp = L'\0';
return -1;
}
}
/* Test for EOF */
if (num_read == 0) {
- *cp = '\0';
+ *cp = L'\0';
return 0;
}
@@ -372,7 +372,7 @@ read_char(EditLine *el, Char *cp)
if ((el->el_flags & CHARSET_IS_UTF8) == 0 ||
cbp >= MB_LEN_MAX) {
errno = EILSEQ;
- *cp = '\0';
+ *cp = L'\0';
return -1;
}
/* Incomplete sequence, read another byte. */
@@ -407,7 +407,6 @@ el_wgetc(EditLine *el, wchar_t *cp)
{
int num_read;
c_macro_t *ma = &el->el_chared.c_macro;
- Char cp_temp;
terminal__flush(el);
for (;;) {
@@ -443,14 +442,9 @@ el_wgetc(EditLine *el, wchar_t *cp)
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Reading a character\n");
#endif /* DEBUG_READ */
- num_read = (*el->el_read.read_char)(el, &cp_temp);
+ num_read = (*el->el_read.read_char)(el, cp);
if (num_read < 0)
el->el_errno = errno;
- *cp = cp_temp;
-#ifdef WIDECHAR
- if (el->el_flags & NARROW_READ)
- *cp = *(char *)(void *)cp;
-#endif
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Got it %lc\n", *cp);
#endif /* DEBUG_READ */
@@ -493,6 +487,7 @@ FUN(el,gets)(EditLine *el, int *nread)
int retval;
el_action_t cmdnum = 0;
int num; /* how many chars we have read at NL */
+ wchar_t wc;
Char ch, *cp;
int crlf = 0;
int nrb;
@@ -508,7 +503,8 @@ FUN(el,gets)(EditLine *el, int *nread)
size_t idx;
cp = el->el_line.buffer;
- while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
+ while ((num = (*el->el_read.read_char)(el, &wc)) == 1) {
+ *cp = (Char)wc;
/* make sure there is space for next character */
if (cp + 1 >= el->el_line.limit) {
idx = (size_t)(cp - el->el_line.buffer);
@@ -560,7 +556,8 @@ FUN(el,gets)(EditLine *el, int *nread)
terminal__flush(el);
- while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
+ while ((num = (*el->el_read.read_char)(el, &wc)) == 1) {
+ *cp = (Char)wc;
/* make sure there is space next character */
if (cp + 1 >= el->el_line.limit) {
idx = (size_t)(cp - el->el_line.buffer);
Index: src/lib/libedit/read.h
diff -u src/lib/libedit/read.h:1.8 src/lib/libedit/read.h:1.9
--- src/lib/libedit/read.h:1.8 Wed Feb 17 14:47:49 2016
+++ src/lib/libedit/read.h Wed Feb 24 12:13:22 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: read.h,v 1.8 2016/02/17 19:47:49 christos Exp $ */
+/* $NetBSD: read.h,v 1.9 2016/02/24 17:13:22 christos Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#ifndef _h_el_read
#define _h_el_read
-typedef int (*el_rfunc_t)(EditLine *, Char *);
+typedef int (*el_rfunc_t)(EditLine *, wchar_t *);
typedef struct el_read_t {
el_rfunc_t read_char; /* Function to read a character */
Index: src/lib/libedit/readline.c
diff -u src/lib/libedit/readline.c:1.125 src/lib/libedit/readline.c:1.126
--- src/lib/libedit/readline.c:1.125 Wed Feb 17 14:47:49 2016
+++ src/lib/libedit/readline.c Wed Feb 24 12:13:22 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.125 2016/02/17 19:47:49 christos Exp $ */
+/* $NetBSD: readline.c,v 1.126 2016/02/24 17:13:22 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.125 2016/02/17 19:47:49 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.126 2016/02/24 17:13:22 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -166,13 +166,13 @@ static jmp_buf topbuf;
static unsigned char _el_rl_complete(EditLine *, int);
static unsigned char _el_rl_tstp(EditLine *, int);
static char *_get_prompt(EditLine *);
-static int _getc_function(EditLine *, char *);
+static int _getc_function(EditLine *, wchar_t *);
static HIST_ENTRY *_move_history(int);
static int _history_expand_command(const char *, size_t, size_t,
char **);
static char *_rl_compat_sub(const char *, const char *,
const char *, int);
-static int _rl_event_read_char(EditLine *, char *);
+static int _rl_event_read_char(EditLine *, wchar_t *);
static void _rl_update_pos(void);
@@ -209,14 +209,14 @@ _move_history(int op)
*/
static int
/*ARGSUSED*/
-_getc_function(EditLine *el __attribute__((__unused__)), char *c)
+_getc_function(EditLine *el __attribute__((__unused__)), wchar_t *c)
{
int i;
i = (*rl_getc_function)(NULL);
if (i == -1)
return 0;
- *c = (char)i;
+ *c = (wchar_t)i;
return 1;
}
@@ -2099,12 +2099,14 @@ rl_stuff_char(int c)
}
static int
-_rl_event_read_char(EditLine *el, char *cp)
+_rl_event_read_char(EditLine *el, wchar_t *wc)
{
+ char ch;
int n;
ssize_t num_read = 0;
- *cp = '\0';
+ ch = '\0';
+ *wc = L'\0';
while (rl_event_hook) {
(*rl_event_hook)();
@@ -2113,7 +2115,7 @@ _rl_event_read_char(EditLine *el, char *
if (ioctl(el->el_infd, FIONREAD, &n) < 0)
return -1;
if (n)
- num_read = read(el->el_infd, cp, (size_t)1);
+ num_read = read(el->el_infd, &ch, (size_t)1);
else
num_read = 0;
#elif defined(F_SETFL) && defined(O_NDELAY)
@@ -2121,12 +2123,12 @@ _rl_event_read_char(EditLine *el, char *
return -1;
if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0)
return -1;
- num_read = read(el->el_infd, cp, 1);
+ num_read = read(el->el_infd, &ch, 1);
if (fcntl(el->el_infd, F_SETFL, n))
return -1;
#else
/* not non-blocking, but what you gonna do? */
- num_read = read(el->el_infd, cp, 1);
+ num_read = read(el->el_infd, &ch, 1);
return -1;
#endif
@@ -2138,6 +2140,7 @@ _rl_event_read_char(EditLine *el, char *
}
if (!rl_event_hook)
el_set(el, EL_GETCFN, EL_BUILTIN_GETCFN);
+ *wc = (wchar_t)ch;
return (int)num_read;
}