Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit chartype cleanups from Ingo Schwarze:



details:   https://anonhg.NetBSD.org/src/rev/d7096e86b400
branches:  trunk
changeset: 344698:d7096e86b400
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Apr 11 16:06:52 2016 +0000

description:
chartype cleanups from Ingo Schwarze:

 - The file tokenizer.c no longer uses chartype.h,
   so don't include the header.

 - The dummy definitions of ct_{de,en}code_string() for the
   NARROWCHAR case are only used in history.c, so move them there.

 - Now the whole content of chartype.h is for the wide character
   case only.  So remove the NARROWCHAR ifdef and include the
   header only in the wide character case.

 - In chartype.h, move ct_encode_char() below the comment explaining it.

 - No more need for underscores before ct_{de,en}code_string().

 - Make the conversion buffer resize functions private.
   They are only called from the decoding and encoding functions
   inside chartype.c, and no need can possibly arise to call them
   from anywhere else.

diffstat:

 lib/libedit/chartype.c  |  11 +++++++----
 lib/libedit/chartype.h  |  21 +++------------------
 lib/libedit/history.c   |   8 +++++---
 lib/libedit/tokenizer.c |   5 ++---
 4 files changed, 17 insertions(+), 28 deletions(-)

diffs (164 lines):

diff -r 3447959691ea -r d7096e86b400 lib/libedit/chartype.c
--- a/lib/libedit/chartype.c    Mon Apr 11 15:30:18 2016 +0000
+++ b/lib/libedit/chartype.c    Mon Apr 11 16:06:52 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chartype.c,v 1.26 2016/04/11 00:50:13 christos Exp $   */
+/*     $NetBSD: chartype.c,v 1.27 2016/04/11 16:06:52 christos Exp $   */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.26 2016/04/11 00:50:13 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.27 2016/04/11 16:06:52 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <ctype.h>
@@ -42,7 +42,10 @@
 
 #define CT_BUFSIZ ((size_t)1024)
 
-protected int
+private int ct_conv_cbuff_resize(ct_buffer_t *, size_t);
+private int ct_conv_wbuff_resize(ct_buffer_t *, size_t);
+
+private int
 ct_conv_cbuff_resize(ct_buffer_t *conv, size_t csize)
 {
        void *p;
@@ -63,7 +66,7 @@
        return 0;
 }
 
-protected int
+private int
 ct_conv_wbuff_resize(ct_buffer_t *conv, size_t wsize)
 {
        void *p;
diff -r 3447959691ea -r d7096e86b400 lib/libedit/chartype.h
--- a/lib/libedit/chartype.h    Mon Apr 11 15:30:18 2016 +0000
+++ b/lib/libedit/chartype.h    Mon Apr 11 16:06:52 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chartype.h,v 1.29 2016/04/11 00:50:13 christos Exp $   */
+/*     $NetBSD: chartype.h,v 1.30 2016/04/11 16:06:52 christos Exp $   */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -29,8 +29,6 @@
 #ifndef _h_chartype_f
 #define _h_chartype_f
 
-#ifndef NARROWCHAR
-
 /* Ideally we should also test the value of the define to see if it
  * supports non-BMP code points without requiring UTF-16, but nothing
  * seems to actually advertise this properly, despite Unicode 3.1 having
@@ -61,11 +59,9 @@
         size_t  wsize;
 } ct_buffer_t;
 
-#define ct_encode_string __ct_encode_string
 /* Encode a wide-character string and return the UTF-8 encoded result. */
 public char *ct_encode_string(const wchar_t *, ct_buffer_t *);
 
-#define ct_decode_string __ct_decode_string
 /* Decode a (multi)?byte string and return the wide-character string result. */
 public wchar_t *ct_decode_string(const char *, ct_buffer_t *);
 
@@ -73,21 +69,11 @@
  * The pointer returned must be free()d when done. */
 protected wchar_t **ct_decode_argv(int, const char *[],  ct_buffer_t *);
 
-/* Resizes the conversion buffer(s) if needed. */
-protected int ct_conv_cbuff_resize(ct_buffer_t *, size_t);
-protected int ct_conv_wbuff_resize(ct_buffer_t *, size_t);
-protected ssize_t ct_encode_char(char *, size_t, wchar_t);
-protected size_t ct_enc_width(wchar_t);
-
-#else
-#define        ct_encode_string(s, b)  (s)
-#define ct_decode_string(s, b) (s)
-#endif
-
-#ifndef NARROWCHAR
 /* Encode a characted into the destination buffer, provided there is sufficent
  * buffer space available. Returns the number of bytes used up (zero if the
  * character cannot be encoded, -1 if there was not enough space available). */
+protected ssize_t ct_encode_char(char *, size_t, wchar_t);
+protected size_t ct_enc_width(wchar_t);
 
 /* The maximum buffer size to hold the most unwieldly visual representation,
  * in this case \U+nnnnn. */
@@ -124,6 +110,5 @@
 #define CHTYPE_NONPRINT     (-4)
 /* classification of character c, as one of the above defines */
 protected int ct_chr_class(wchar_t c);
-#endif
 
 #endif /* _chartype_f */
diff -r 3447959691ea -r d7096e86b400 lib/libedit/history.c
--- a/lib/libedit/history.c     Mon Apr 11 15:30:18 2016 +0000
+++ b/lib/libedit/history.c     Mon Apr 11 16:06:52 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: history.c,v 1.55 2016/04/11 00:50:13 christos Exp $    */
+/*     $NetBSD: history.c,v 1.56 2016/04/11 16:06:52 christos Exp $    */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)history.c  8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: history.c,v 1.55 2016/04/11 00:50:13 christos Exp $");
+__RCSID("$NetBSD: history.c,v 1.56 2016/04/11 16:06:52 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -53,7 +53,6 @@
 static const char hist_cookie[] = "_HiStOrY_V2_\n";
 
 #include "histedit.h"
-#include "chartype.h"
 
 
 #ifdef NARROWCHAR
@@ -70,8 +69,11 @@
 #define        Strncmp(d, s, n)        strncmp(d, s, n)
 #define        Strncpy(d, s, n)        strncpy(d, s, n)
 #define        Strncat(d, s, n)        strncat(d, s, n)
+#define        ct_decode_string(s, b)  (s)
+#define        ct_encode_string(s, b)  (s)
 
 #else
+#include "chartype.h"
 
 #define        Char                    wchar_t
 #define        FUN(prefix, rest)       prefix ## _w ## rest
diff -r 3447959691ea -r d7096e86b400 lib/libedit/tokenizer.c
--- a/lib/libedit/tokenizer.c   Mon Apr 11 15:30:18 2016 +0000
+++ b/lib/libedit/tokenizer.c   Mon Apr 11 16:06:52 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tokenizer.c,v 1.26 2016/04/11 00:50:13 christos Exp $  */
+/*     $NetBSD: tokenizer.c,v 1.27 2016/04/11 16:06:52 christos Exp $  */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)tokenizer.c        8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: tokenizer.c,v 1.26 2016/04/11 00:50:13 christos Exp $");
+__RCSID("$NetBSD: tokenizer.c,v 1.27 2016/04/11 16:06:52 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -49,7 +49,6 @@
 #include <string.h>
 
 #include "histedit.h"
-#include "chartype.h"
 
 typedef enum {
        Q_none, Q_single, Q_double, Q_one, Q_doubleone



Home | Main Index | Thread Index | Old Index