This patch series adds support for the <uchar.h> header file. The functions mbrtoc32 and c32rtomb to come...
I don't plan to implement mbrtoc16 and c16rtomb, because the only use I can see for them is to support programs which assume Windows-style UTF-16 encoding in wide characters on POSIX systems, which is silly. 2019-12-31 Bruno Haible <[email protected]> uchar: Add C++ tests. * tests/test-uchar-c++.cc: New file. * tests/test-uchar-c++2.cc: New file. * modules/uchar-c++-tests: New file. uchar: Add tests. * tests/test-uchar.c: New file. * modules/uchar-tests: New file. uchar: New module. * lib/uchar.in.h: New file. * m4/uchar.m4: New file. * modules/uchar: New file. * doc/posix-headers/uchar.texi: Mention the new module.
>From 610da39dbe01509af66bde383cac228d03b736c6 Mon Sep 17 00:00:00 2001 From: Bruno Haible <[email protected]> Date: Tue, 31 Dec 2019 19:35:48 +0100 Subject: [PATCH 1/3] uchar: New module. * lib/uchar.in.h: New file. * m4/uchar.m4: New file. * modules/uchar: New file. * doc/posix-headers/uchar.texi: Mention the new module. --- ChangeLog | 8 +++++++ doc/posix-headers/uchar.texi | 8 +++---- lib/uchar.in.h | 54 ++++++++++++++++++++++++++++++++++++++++++++ m4/uchar.m4 | 19 ++++++++++++++++ modules/uchar | 40 ++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 lib/uchar.in.h create mode 100644 m4/uchar.m4 create mode 100644 modules/uchar diff --git a/ChangeLog b/ChangeLog index 6f6e619..7d4c550 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-12-31 Bruno Haible <[email protected]> + + uchar: New module. + * lib/uchar.in.h: New file. + * m4/uchar.m4: New file. + * modules/uchar: New file. + * doc/posix-headers/uchar.texi: Mention the new module. + 2019-12-30 Jim Meyering <[email protected]> localeinfo: ->simple would be wrong for LC_ALL=C diff --git a/doc/posix-headers/uchar.texi b/doc/posix-headers/uchar.texi index 7662a79..3907732 100644 --- a/doc/posix-headers/uchar.texi +++ b/doc/posix-headers/uchar.texi @@ -5,15 +5,15 @@ Defines the types @code{char16_t}, @code{char32_t} and declares the functions @code{mbrtoc16}, @code{c16rtomb}, @code{mbrtoc32}, @code{c32rtomb}. -Gnulib module: --- +Gnulib module: uchar Portability problems fixed by Gnulib: @itemize +@item +This header file is missing on many non-glibc platforms: +glibc 2.15, Mac OS X 10.5, FreeBSD 6.4, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin, mingw, MSVC 9. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This header file is missing on many non-glibc platforms: -glibc 2.15, Mac OS X 10.5, FreeBSD 6.4, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin, mingw, MSVC 9. @end itemize diff --git a/lib/uchar.in.h b/lib/uchar.in.h new file mode 100644 index 0000000..2870bae --- /dev/null +++ b/lib/uchar.in.h @@ -0,0 +1,54 @@ +/* <uchar.h> substitute - 16-bit and 32-bit wide character types. + Copyright (C) 2019 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 3 of the License, 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, see <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <[email protected]>, 2019. */ + +/* + * ISO C 11 <uchar.h> for platforms that lack it. + */ + +#ifndef _@GUARD_PREFIX@_UCHAR_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if @HAVE_UCHAR_H@ +# @INCLUDE_NEXT@ @NEXT_UCHAR_H@ +#endif + +/* Get uint_least16_t, uint_least32_t. */ +#include <stdint.h> + +/* Get mbstate_t, size_t. */ +#include <wchar.h> + +#if !@HAVE_UCHAR_H@ + +/* A 16-bit variant of wchar_t. + Note: This type does *NOT* denote UTF-16 units. (Only on platforms + on which __STDC_UTF_16__ is defined.) */ +typedef uint_least16_t char16_t; + +/* A 32-bit variant of wchar_t. + Note: This type does *NOT* denote UTF-32 code points. (Only on platforms + on which __STDC_UTF_32__ is defined.) */ +typedef uint_least32_t char32_t; + +#endif + +#endif /* _@GUARD_PREFIX@_UCHAR_H */ diff --git a/m4/uchar.m4 b/m4/uchar.m4 new file mode 100644 index 0000000..ca6a21f --- /dev/null +++ b/m4/uchar.m4 @@ -0,0 +1,19 @@ +# uchar.m4 serial 1 +dnl Copyright (C) 2019 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. +dnl Prepare the overridden <uchar.h>. + +AC_DEFUN_ONCE([gl_UCHAR_H], +[ + gl_CHECK_NEXT_HEADERS([uchar.h]) + if test $ac_cv_header_uchar_h = yes; then + HAVE_UCHAR_H=1 + else + HAVE_UCHAR_H=0 + fi + AC_SUBST([HAVE_UCHAR_H]) +]) diff --git a/modules/uchar b/modules/uchar new file mode 100644 index 0000000..48ed448 --- /dev/null +++ b/modules/uchar @@ -0,0 +1,40 @@ +Description: +A GNU-like <uchar.h>. + +Files: +lib/uchar.in.h +m4/uchar.m4 + +Depends-on: +include_next +stdint +wchar + +configure.ac: +gl_UCHAR_H + +Makefile.am: +BUILT_SOURCES += uchar.h + +uchar.h: uchar.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \ + -e 's/@''HAVE_UCHAR_H''@/$(HAVE_UCHAR_H)/g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_UCHAR_H''@|$(NEXT_UCHAR_H)|g' \ + < $(srcdir)/uchar.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += uchar.h uchar.h-t + +Include: +<uchar.h> + +License: +LGPLv2+ + +Maintainer: +all -- 2.7.4
>From d3e19d84d753ee5298701ffc5c872fd47577d653 Mon Sep 17 00:00:00 2001 From: Bruno Haible <[email protected]> Date: Tue, 31 Dec 2019 19:37:01 +0100 Subject: [PATCH 2/3] uchar: Add tests. * tests/test-uchar.c: New file. * modules/uchar-tests: New file. --- ChangeLog | 4 ++++ modules/uchar-tests | 12 ++++++++++++ tests/test-uchar.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 modules/uchar-tests create mode 100644 tests/test-uchar.c diff --git a/ChangeLog b/ChangeLog index 7d4c550..6d501b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2019-12-31 Bruno Haible <[email protected]> + uchar: Add tests. + * tests/test-uchar.c: New file. + * modules/uchar-tests: New file. + uchar: New module. * lib/uchar.in.h: New file. * m4/uchar.m4: New file. diff --git a/modules/uchar-tests b/modules/uchar-tests new file mode 100644 index 0000000..2dab718 --- /dev/null +++ b/modules/uchar-tests @@ -0,0 +1,12 @@ +Files: +tests/test-uchar.c + +Depends-on: +verify +uchar-c++-tests + +configure.ac: + +Makefile.am: +TESTS += test-uchar +check_PROGRAMS += test-uchar diff --git a/tests/test-uchar.c b/tests/test-uchar.c new file mode 100644 index 0000000..0301619 --- /dev/null +++ b/tests/test-uchar.c @@ -0,0 +1,42 @@ +/* Test of <uchar.h> substitute. + Copyright (C) 2019 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 3 of the License, 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, see <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <[email protected]>, 2019. */ + +#include <config.h> + +#include <uchar.h> + +#include "verify.h" + +/* Check that the types are defined. */ +mbstate_t a = { 0 }; +size_t b = 5; +char16_t c = 'x'; +char32_t d = 'y'; + +/* Check that char16_t and char32_t are unsigned types. */ +verify ((char16_t)(-1) >= 0); +verify ((char32_t)(-1) >= 0); + +/* Check that char32_t is at least 31 bits wide. */ +verify ((char32_t)0x7FFFFFFF != (char32_t)0x3FFFFFFF); + +int +main (void) +{ + return 0; +} -- 2.7.4
>From 87b59dc7b4017eefe7bc8dbb3b035a05b42db765 Mon Sep 17 00:00:00 2001 From: Bruno Haible <[email protected]> Date: Tue, 31 Dec 2019 19:38:50 +0100 Subject: [PATCH 3/3] uchar: Add C++ tests. * tests/test-uchar-c++.cc: New file. * tests/test-uchar-c++2.cc: New file. * modules/uchar-c++-tests: New file. --- ChangeLog | 5 +++++ modules/uchar-c++-tests | 18 ++++++++++++++++++ tests/test-uchar-c++.cc | 28 ++++++++++++++++++++++++++++ tests/test-uchar-c++2.cc | 24 ++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 modules/uchar-c++-tests create mode 100644 tests/test-uchar-c++.cc create mode 100644 tests/test-uchar-c++2.cc diff --git a/ChangeLog b/ChangeLog index 6d501b8..f503efe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2019-12-31 Bruno Haible <[email protected]> + uchar: Add C++ tests. + * tests/test-uchar-c++.cc: New file. + * tests/test-uchar-c++2.cc: New file. + * modules/uchar-c++-tests: New file. + uchar: Add tests. * tests/test-uchar.c: New file. * modules/uchar-tests: New file. diff --git a/modules/uchar-c++-tests b/modules/uchar-c++-tests new file mode 100644 index 0000000..8fb7463 --- /dev/null +++ b/modules/uchar-c++-tests @@ -0,0 +1,18 @@ +Files: +tests/test-uchar-c++.cc +tests/test-uchar-c++2.cc + +Status: +c++-test + +Depends-on: +ansi-c++-opt + +configure.ac: + +Makefile.am: +if ANSICXX +TESTS += test-uchar-c++ +check_PROGRAMS += test-uchar-c++ +test_uchar_c___SOURCES = test-uchar-c++.cc test-uchar-c++2.cc +endif diff --git a/tests/test-uchar-c++.cc b/tests/test-uchar-c++.cc new file mode 100644 index 0000000..9b5d8eb --- /dev/null +++ b/tests/test-uchar-c++.cc @@ -0,0 +1,28 @@ +/* Test of <uchar.h> substitute in C++ mode. + Copyright (C) 2019 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 3 of the License, 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, see <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <[email protected]>, 2019. */ + +#define GNULIB_NAMESPACE gnulib +#include <config.h> + +#include <uchar.h> + + +int +main () +{ +} diff --git a/tests/test-uchar-c++2.cc b/tests/test-uchar-c++2.cc new file mode 100644 index 0000000..80a5d44 --- /dev/null +++ b/tests/test-uchar-c++2.cc @@ -0,0 +1,24 @@ +/* Test of <uchar.h> substitute in C++ mode. + Copyright (C) 2019 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 3 of the License, 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, see <https://www.gnu.org/licenses/>. */ + +#define GNULIB_NAMESPACE gnulib +#include <config.h> + +#if __cplusplus >= 201103 + +# include <cuchar> + +#endif -- 2.7.4
