Provide wcwidth replacement in separate file wcwidth.c.
authorBruno Haible <bruno@clisp.org>
Sat, 7 Jul 2007 19:27:06 +0000 (19:27 +0000)
committerBruno Haible <bruno@clisp.org>
Sat, 7 Jul 2007 19:27:06 +0000 (19:27 +0000)
ChangeLog
lib/wcwidth.c [new file with mode: 0644]
lib/wcwidth.h
m4/wcwidth.m4
modules/wcwidth

index 97abc4006aed11de87213746723f0e6837d7441d..35979ff7d16c5730ad5f4012961660be8ea81f41 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-07-07  Bruno Haible  <bruno@clisp.org>
+
+       * 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  <bruno@clisp.org>
 
        * MODULES.html.sh (Unicode string functions): Add the new modules.
diff --git a/lib/wcwidth.c b/lib/wcwidth.c
new file mode 100644 (file)
index 0000000..6317083
--- /dev/null
@@ -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 <config.h>
+
+/* Specification.  */
+#include "wcwidth.h"
+
+/* Get iswprint.  */
+#include <wctype.h>
+
+int
+rpl_wcwidth (wchar_t wc)
+{
+  return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
+}
index 8ed5ff8c919f50aea88e76ce914d500731da044f..8294458084bc710728041027b7e4d936ed4b5576 100644 (file)
 /* Get wcwidth if available, along with wchar_t.  */
 # include <wchar.h>
 
-/* Get iswprint.  */
-# include <wctype.h>
-
 # 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
 
index b4834991a5576744dacad930a292bcf6a18f7812..ddf86f8d730b207ae0802dd8d9f098f3bac36581 100644 (file)
@@ -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 <stdio.h>
 #include <time.h>
 #include <wchar.h>
-])])
+])
+
+  if test $ac_cv_func_wcwidth = no; then
+    AC_LIBOBJ([wcwidth])
+  fi
+])
index 9ace5c137535d9227e403c477a792a9d56d6dd62..a10d34a5fbad0a738b9e22061df2a48293e33f7f 100644 (file)
@@ -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"