From 2b3817550022a9a5c9cd89f4e5a3a77381ac328c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 7 Jul 2007 19:27:06 +0000 Subject: [PATCH] Provide wcwidth replacement in separate file wcwidth.c. --- ChangeLog | 10 ++++++++++ lib/wcwidth.c | 30 ++++++++++++++++++++++++++++++ lib/wcwidth.h | 13 +++---------- m4/wcwidth.m4 | 9 +++++++-- modules/wcwidth | 2 +- 5 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 lib/wcwidth.c diff --git a/ChangeLog b/ChangeLog index 97abc4006a..35979ff7d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-07-07 Bruno Haible + + * lib/wcwidth.c: New file, extracted from lib/wcwidth.h. + * lib/wcwidth.h: Don't include wctype.h. Replace inline function + definition with an external declaration. + * m4/wcwidth.m4 (gl_FUNC_WCWIDTH): Use wcwidth.c when wcwidth is not + defined as a function. + * modules/wcwidth (Files): Add lib/wcwidth.c. + (Makefile.am): Remove redundant statement. + 2007-07-07 Bruno Haible * MODULES.html.sh (Unicode string functions): Add the new modules. diff --git a/lib/wcwidth.c b/lib/wcwidth.c new file mode 100644 index 0000000000..6317083435 --- /dev/null +++ b/lib/wcwidth.c @@ -0,0 +1,30 @@ +/* Determine the number of screen columns needed for a character. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "wcwidth.h" + +/* Get iswprint. */ +#include + +int +rpl_wcwidth (wchar_t wc) +{ + return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; +} diff --git a/lib/wcwidth.h b/lib/wcwidth.h index 8ed5ff8c91..8294458084 100644 --- a/lib/wcwidth.h +++ b/lib/wcwidth.h @@ -23,22 +23,15 @@ /* Get wcwidth if available, along with wchar_t. */ # include -/* Get iswprint. */ -# include - # ifndef HAVE_DECL_WCWIDTH "this configure-time declaration test was not run" # endif # ifndef wcwidth # if !HAVE_WCWIDTH -/* wcwidth doesn't exist, so assume all printable characters have - width 1. */ -static inline int -wcwidth (wchar_t wc) -{ - return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; -} +/* Defined by gnulib. */ +# define wcwidth rpl_wcwidth +extern int wcwidth (wchar_t); # elif !HAVE_DECL_WCWIDTH diff --git a/m4/wcwidth.m4 b/m4/wcwidth.m4 index b4834991a5..ddf86f8d73 100644 --- a/m4/wcwidth.m4 +++ b/m4/wcwidth.m4 @@ -1,4 +1,4 @@ -# wcwidth.m4 serial 8 +# wcwidth.m4 serial 9 dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -27,4 +27,9 @@ AC_DEFUN([gl_FUNC_WCWIDTH], #include #include #include -])]) +]) + + if test $ac_cv_func_wcwidth = no; then + AC_LIBOBJ([wcwidth]) + fi +]) diff --git a/modules/wcwidth b/modules/wcwidth index 9ace5c1375..a10d34a5fb 100644 --- a/modules/wcwidth +++ b/modules/wcwidth @@ -3,6 +3,7 @@ Determine the number of screen columns needed for a character. Files: lib/wcwidth.h +lib/wcwidth.c m4/wcwidth.m4 m4/wchar_t.m4 m4/wint_t.m4 @@ -15,7 +16,6 @@ configure.ac: gl_FUNC_WCWIDTH Makefile.am: -lib_SOURCES += wcwidth.h Include: "wcwidth.h" -- 2.30.2