Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libedit From Ingo Schwartze:
details: https://anonhg.NetBSD.org/src/rev/460fe609e42a
branches: trunk
changeset: 343553:460fe609e42a
user: christos <christos%NetBSD.org@localhost>
date: Sun Feb 14 14:47:48 2016 +0000
description:
>From Ingo Schwartze:
Next step: Remove #ifdef'ing in read_char(), in the same style
as we did for setlocale(3) in el.c.
A few remarks are required to explain the choices made.
* On first sight, handling mbrtowc(3) seems a bit less trivial
than handling setlocale(3) because its prototype uses the data
type mbstate_t from <wchar.h>. However, it turns out that
"histedit.h" already includes <wchar.h> unconditionally (i don't
like headers including other headers, but that ship has sailed,
people are by now certainly used to the fact that including
"histedit.h" doesn't require including <wchar.h> before), and
"histedit.h" is of course included all over the place. So from
that perspective, there is no problem with using mbrtowc(3)
unconditionally ever for !WIDECHAR.
* However, <wchar.h> also defines the mbrtowc(3) prototype,
so we cannot just #define mbrtowc away, or including the header
will break. It would also be a bad idea to porovide a local
implementation of mbrtowc() and hope that it overrides the one
in libc. Besides, the required prototype is subtly different:
While mbrtowc(3) takes "wchar_t *" as its first argument, we
need a function that takes "Char *". So unfortunately, we have
to keep a ct_mbrtowc #define, at least until we can maybe get
rid of "Char *" in the more remote future.
* After getting rid of the #else clause in read_char(), we can
pull "return 1;" into the default: clause. After that, we can
get rid of the ugly "goto again_lastbyte;" and just "break;".
As a bonus, that also gets rid of the ugly CONSTCOND.
* While here, delete the unused ct_mbtowc() from chartype.h.
diffstat:
lib/libedit/chartype.c | 18 ++++++++++++++++--
lib/libedit/chartype.h | 6 ++----
lib/libedit/read.c | 20 +++++++-------------
3 files changed, 25 insertions(+), 19 deletions(-)
diffs (123 lines):
diff -r 01ff2de28fef -r 460fe609e42a lib/libedit/chartype.c
--- a/lib/libedit/chartype.c Sun Feb 14 10:56:22 2016 +0000
+++ b/lib/libedit/chartype.c Sun Feb 14 14:47:48 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.c,v 1.13 2016/02/11 19:21:04 christos Exp $ */
+/* $NetBSD: chartype.c,v 1.14 2016/02/14 14:47:48 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.13 2016/02/11 19:21:04 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.14 2016/02/14 14:47:48 christos Exp $");
#endif /* not lint && not SCCSID */
#include "el.h"
#include <stdlib.h>
@@ -210,6 +210,20 @@
}
return l;
}
+
+#else
+
+size_t
+ct_mbrtowc(char *wc, const char *s, size_t n,
+ void *mbs __attribute((__unused__))) {
+ if (s == NULL)
+ return 0;
+ if (n == 0)
+ return (size_t)-2;
+ if (wc != NULL)
+ *wc = *s;
+ return *s != '\0';
+}
#endif
protected const Char *
diff -r 01ff2de28fef -r 460fe609e42a lib/libedit/chartype.h
--- a/lib/libedit/chartype.h Sun Feb 14 10:56:22 2016 +0000
+++ b/lib/libedit/chartype.h Sun Feb 14 14:47:48 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.h,v 1.17 2016/02/11 19:10:18 christos Exp $ */
+/* $NetBSD: chartype.h,v 1.18 2016/02/14 14:47:48 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -60,7 +60,6 @@
#warning Build environment does not support non-BMP characters
#endif
-#define ct_mbtowc mbtowc
#define ct_mbrtowc mbrtowc
#define ct_wctomb wctomb
#define ct_wctomb_reset wctomb(0,0)
@@ -115,8 +114,7 @@
#else /* NARROW */
-#define ct_mbtowc error
-#define ct_mbrtowc error
+size_t ct_mbrtowc(char *, const char *, size_t, void *);
#define ct_wctomb error
#define ct_wctomb_reset
#define ct_wcstombs(a, b, c) (strncpy(a, b, c), strlen(a))
diff -r 01ff2de28fef -r 460fe609e42a lib/libedit/read.c
--- a/lib/libedit/read.c Sun Feb 14 10:56:22 2016 +0000
+++ b/lib/libedit/read.c Sun Feb 14 14:47:48 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.76 2016/02/12 15:36:08 christos Exp $ */
+/* $NetBSD: read.c,v 1.77 2016/02/14 14:47:48 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.76 2016/02/12 15:36:08 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.77 2016/02/14 14:47:48 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -337,10 +337,9 @@
return 0;
}
-#ifdef WIDECHAR
- do {
+ for (;;) {
mbstate_t mbs;
-again_lastbyte:
+
++cbp;
/* This only works because UTF8 is stateless */
memset(&mbs, 0, sizeof(mbs));
@@ -353,7 +352,7 @@
*/
cbuf[0] = cbuf[cbp - 1];
cbp = 0;
- goto again_lastbyte;
+ break;
} else {
/* Invalid byte, discard it. */
cbp = 0;
@@ -375,14 +374,9 @@
goto again;
default:
/* Valid character, process it. */
- break;
+ return 1;
}
- } while (/*CONSTCOND*/0);
-#else
- *cp = (Char)(unsigned char)cbuf[0];
-#endif
-
- return 1;
+ }
}
/* read_pop():
Home |
Main Index |
Thread Index |
Old Index