bug-gnulib
[Top][All Lists]
Advanced

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

wcwidth: move replacement function to lib/wcwidth.c


From: Bruno Haible
Subject: wcwidth: move replacement function to lib/wcwidth.c
Date: Sat, 7 Jul 2007 21:30:10 +0200
User-agent: KMail/1.5.4

The wcwidth.h currently defines the wcwidth replacement inline; this causes
an include of <wctype.h> inside <wchar.h> which makes it hard to move
wcwidth.h into <wchar.h>. So, first, move that out to a separate file.

2007-07-07  Bruno Haible  <address@hidden>

        * 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.

============================== lib/wcwidth.c ===============================
/* 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;
}
============================================================================
*** modules/wcwidth     16 Jan 2007 16:31:23 -0000      1.6
--- modules/wcwidth     7 Jul 2007 19:21:37 -0000
***************
*** 3,8 ****
--- 3,9 ----
  
  Files:
  lib/wcwidth.h
+ lib/wcwidth.c
  m4/wcwidth.m4
  m4/wchar_t.m4
  m4/wint_t.m4
***************
*** 15,21 ****
  gl_FUNC_WCWIDTH
  
  Makefile.am:
- lib_SOURCES += wcwidth.h
  
  Include:
  "wcwidth.h"
--- 16,21 ----
*** m4/wcwidth.m4       16 Jan 2007 16:31:23 -0000      1.9
--- m4/wcwidth.m4       7 Jul 2007 19:21:37 -0000
***************
*** 1,4 ****
! # wcwidth.m4 serial 8
  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,
--- 1,4 ----
! # 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,30 ****
  #include <stdio.h>
  #include <time.h>
  #include <wchar.h>
! ])])
--- 27,35 ----
  #include <stdio.h>
  #include <time.h>
  #include <wchar.h>
! ])
! 
!   if test $ac_cv_func_wcwidth = no; then
!     AC_LIBOBJ([wcwidth])
!   fi
! ])
*** lib/wcwidth.h       16 Jan 2007 16:31:23 -0000      1.8
--- lib/wcwidth.h       7 Jul 2007 19:21:37 -0000
***************
*** 23,44 ****
  /* 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;
! }
  
  #  elif !HAVE_DECL_WCWIDTH
  
--- 23,37 ----
  /* Get wcwidth if available, along with wchar_t.  */
  # include <wchar.h>
  
  # ifndef HAVE_DECL_WCWIDTH
  "this configure-time declaration test was not run"
  # endif
  # ifndef wcwidth
  #  if !HAVE_WCWIDTH
  
! /* Defined by gnulib.  */
! #   define wcwidth rpl_wcwidth
! extern int wcwidth (wchar_t);
  
  #  elif !HAVE_DECL_WCWIDTH
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]