Module Name: src Committed By: christos Date: Mon Apr 11 16:06:53 UTC 2016
Modified Files: src/lib/libedit: chartype.c chartype.h history.c tokenizer.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/lib/libedit/chartype.c \ src/lib/libedit/tokenizer.c cvs rdiff -u -r1.29 -r1.30 src/lib/libedit/chartype.h cvs rdiff -u -r1.55 -r1.56 src/lib/libedit/history.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.26 src/lib/libedit/chartype.c:1.27 --- src/lib/libedit/chartype.c:1.26 Sun Apr 10 20:50:13 2016 +++ src/lib/libedit/chartype.c Mon Apr 11 12:06:52 2016 @@ -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 @@ __RCSID("$NetBSD: chartype.c,v 1.26 2016 #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 @@ ct_conv_cbuff_resize(ct_buffer_t *conv, return 0; } -protected int +private int ct_conv_wbuff_resize(ct_buffer_t *conv, size_t wsize) { void *p; Index: src/lib/libedit/tokenizer.c diff -u src/lib/libedit/tokenizer.c:1.26 src/lib/libedit/tokenizer.c:1.27 --- src/lib/libedit/tokenizer.c:1.26 Sun Apr 10 20:50:13 2016 +++ src/lib/libedit/tokenizer.c Mon Apr 11 12:06:52 2016 @@ -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 @@ __RCSID("$NetBSD: tokenizer.c,v 1.26 201 #include <string.h> #include "histedit.h" -#include "chartype.h" typedef enum { Q_none, Q_single, Q_double, Q_one, Q_doubleone Index: src/lib/libedit/chartype.h diff -u src/lib/libedit/chartype.h:1.29 src/lib/libedit/chartype.h:1.30 --- src/lib/libedit/chartype.h:1.29 Sun Apr 10 20:50:13 2016 +++ src/lib/libedit/chartype.h Mon Apr 11 12:06:52 2016 @@ -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 @@ typedef struct ct_buffer_t { 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 @@ public wchar_t *ct_decode_string(const c * 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 @@ protected const wchar_t *ct_visual_strin #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 */ Index: src/lib/libedit/history.c diff -u src/lib/libedit/history.c:1.55 src/lib/libedit/history.c:1.56 --- src/lib/libedit/history.c:1.55 Sun Apr 10 20:50:13 2016 +++ src/lib/libedit/history.c Mon Apr 11 12:06:52 2016 @@ -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 @@ __RCSID("$NetBSD: history.c,v 1.55 2016/ static const char hist_cookie[] = "_HiStOrY_V2_\n"; #include "histedit.h" -#include "chartype.h" #ifdef NARROWCHAR @@ -70,8 +69,11 @@ static const char hist_cookie[] = "_HiSt #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