From: Joerg Sonnenberger Date: Thu, 21 Apr 2005 16:36:35 +0000 (+0000) Subject: Complete Citrus import. Import message catalog implement from X-Git-Tag: v2.0.1~7777 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/32a7b49af5025caa26dc703952f47b39d046c9eb Complete Citrus import. Import message catalog implement from NetBSD. Remove external visible rune interface. Obtained-from: Project Citrus / NetBSD --- diff --git a/Makefile.inc1 b/Makefile.inc1 index af81a5a631..4d8d217706 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -1,6 +1,6 @@ # # $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $ -# $DragonFly: src/Makefile.inc1,v 1.63 2005/04/21 08:43:42 joerg Exp $ +# $DragonFly: src/Makefile.inc1,v 1.64 2005/04/21 16:36:34 joerg Exp $ # # Make command line options: # -DMAKE_KERBEROS5 to build Kerberos5 @@ -783,7 +783,7 @@ bootstrap-tools: usr.sbin/btxld usr.sbin/pwd_mkdb usr.sbin/zic usr.sbin/makewhatis \ gnu/usr.bin/gperf gnu/usr.bin/texinfo \ gnu/usr.bin/grep gnu/usr.bin/sort \ - usr.bin/gzip usr.bin/bzip2 + usr.bin/gzip usr.bin/bzip2 usr.bin/mkcsmapper usr.bin/mkesdb ${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ diff --git a/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_base.h b/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_base.h deleted file mode 100644 index f44a7c7b96..0000000000 --- a/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_base.h +++ /dev/null @@ -1,76 +0,0 @@ -// Locale support -*- C++ -*- - -// Copyright (C) 2000, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library 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 library 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 library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -// -// ISO C++ 14882: 22.1 Locales -// - -// Information as gleaned from /usr/include/ctype.h on FreeBSD 3.4, -// 4.0 and all versions of the CVS managed file at: -// :pserver:anoncvs@anoncvs.freebsd.org:/home/ncvs/src/include/ctype.h - - struct ctype_base - { - // Non-standard typedefs. - typedef const int* __to_type; - - // NB: Offsets into ctype::_M_table force a particular size - // on the mask type. Because of this, we don't use an enum. - typedef unsigned long mask; -#ifdef _CTYPE_S - // FreeBSD 4.0 uses this style of define. - static const mask upper = _CTYPE_U; - static const mask lower = _CTYPE_L; - static const mask alpha = _CTYPE_A; - static const mask digit = _CTYPE_D; - static const mask xdigit = _CTYPE_X; - static const mask space = _CTYPE_S; - static const mask print = _CTYPE_R; - static const mask graph = _CTYPE_A | _CTYPE_D | _CTYPE_P; - static const mask cntrl = _CTYPE_C; - static const mask punct = _CTYPE_P; - static const mask alnum = _CTYPE_A | _CTYPE_D; -#else - // Older versions, including Free BSD 3.4, use this style of define. - static const mask upper = _U; - static const mask lower = _L; - static const mask alpha = _A; - static const mask digit = _D; - static const mask xdigit = _X; - static const mask space = _S; - static const mask print = _R; - static const mask graph = _A | _D | _P; - static const mask cntrl = _C; - static const mask punct = _P; - static const mask alnum = _A | _D; -#endif - }; - - - diff --git a/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_inline.h b/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_inline.h deleted file mode 100644 index d69324ad57..0000000000 --- a/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_inline.h +++ /dev/null @@ -1,106 +0,0 @@ -// Locale support -*- C++ -*- - -// Copyright (C) 2000, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library 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 library 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 library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -// -// ISO C++ 14882: 22.1 Locales -// - -// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*) -// functions go in ctype.cc - - bool - ctype:: - is(mask __m, char __c) const - { - if (_M_table) - return _M_table[static_cast(__c)] & __m; - else - return __istype(__c, __m); - } - - const char* - ctype:: - is(const char* __low, const char* __high, mask* __vec) const - { - if (_M_table) - while (__low < __high) - *__vec++ = _M_table[static_cast(*__low++)]; - else - for (;__low < __high; ++__vec, ++__low) - { -#if defined (_CTYPE_S) || defined (__istype) - *__vec = __maskrune (*__low, upper | lower | alpha | digit | xdigit - | space | print | graph | cntrl | punct | alnum); -#else - mask __m = 0; - if (this->is(upper, *__low)) __m |= upper; - if (this->is(lower, *__low)) __m |= lower; - if (this->is(alpha, *__low)) __m |= alpha; - if (this->is(digit, *__low)) __m |= digit; - if (this->is(xdigit, *__low)) __m |= xdigit; - if (this->is(space, *__low)) __m |= space; - if (this->is(print, *__low)) __m |= print; - if (this->is(graph, *__low)) __m |= graph; - if (this->is(cntrl, *__low)) __m |= cntrl; - if (this->is(punct, *__low)) __m |= punct; - // Do not include explicit line for alnum mask since it is a - // pure composite of masks on FreeBSD. - *__vec = __m; -#endif - } - return __high; - } - - const char* - ctype:: - scan_is(mask __m, const char* __low, const char* __high) const - { - if (_M_table) - while (__low < __high - && !(_M_table[static_cast(*__low)] & __m)) - ++__low; - else - while (__low < __high && !this->is(__m, *__low)) - ++__low; - return __low; - } - - const char* - ctype:: - scan_not(mask __m, const char* __low, const char* __high) const - { - if (_M_table) - while (__low < __high - && (_M_table[static_cast(*__low)] & __m) != 0) - ++__low; - else - while (__low < __high && this->is(__m, *__low) != 0) - ++__low; - return __low; - } diff --git a/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_noninline.h b/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_noninline.h deleted file mode 100644 index ec5b575354..0000000000 --- a/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/ctype_noninline.h +++ /dev/null @@ -1,91 +0,0 @@ -// Locale support -*- C++ -*- - -// Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library 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 library 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 library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -// -// ISO C++ 14882: 22.1 Locales -// - -// Information as gleaned from /usr/include/ctype.h - - const ctype_base::mask* - ctype::classic_table() throw() - { return 0; } - - ctype::ctype(__c_locale, const mask* __table, bool __del, - size_t __refs) - : facet(__refs), _M_del(__table != 0 && __del), - _M_toupper(NULL), _M_tolower(NULL), - _M_table(__table ? __table : classic_table()) - { - memset(_M_widen, 0, sizeof(_M_widen)); - _M_widen_ok = 0; - memset(_M_narrow, 0, sizeof(_M_narrow)); - _M_narrow_ok = 0; - } - - ctype::ctype(const mask* __table, bool __del, size_t __refs) - : facet(__refs), _M_del(__table != 0 && __del), - _M_toupper(NULL), _M_tolower(NULL), - _M_table(__table ? __table : classic_table()) - { - memset(_M_widen, 0, sizeof(_M_widen)); - _M_widen_ok = 0; - memset(_M_narrow, 0, sizeof(_M_narrow)); - _M_narrow_ok = 0; - } - - char - ctype::do_toupper(char __c) const - { return ::toupper((int) __c); } - - const char* - ctype::do_toupper(char* __low, const char* __high) const - { - while (__low < __high) - { - *__low = ::toupper((int) *__low); - ++__low; - } - return __high; - } - - char - ctype::do_tolower(char __c) const - { return ::tolower((int) __c); } - - const char* - ctype::do_tolower(char* __low, const char* __high) const - { - while (__low < __high) - { - *__low = ::tolower((int) *__low); - ++__low; - } - return __high; - } diff --git a/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/os_defines.h b/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/os_defines.h deleted file mode 100644 index 1e46712902..0000000000 --- a/contrib/gcc-3.4/libstdc++-v3/config/os/bsd/freebsd/os_defines.h +++ /dev/null @@ -1,44 +0,0 @@ -// Specific definitions for BSD -*- C++ -*- - -// Copyright (C) 2000, 2002 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library 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 library 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 library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - - -#ifndef _GLIBCXX_OS_DEFINES -#define _GLIBCXX_OS_DEFINES 1 - -// System-specific #define, typedefs, corrections, etc, go here. This -// file will come before all others. - -#define _GLIBCXX_USE_C99_CHECK 1 -#define _GLIBCXX_USE_C99_DYNAMIC (!(__ISO_C_VISIBLE >= 1999)) -#define _GLIBCXX_USE_C99_LONG_LONG_CHECK 1 -#define _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC (_GLIBCXX_USE_C99_DYNAMIC || !defined __LONG_LONG_SUPPORTED) -#define _GLIBCXX_USE_C99_FLOAT_TRANSCENDENTALS_CHECK 1 -#define _GLIBCXX_USE_C99_FLOAT_TRANSCENDENTALS_DYNAMIC defined _XOPEN_SOURCE - -#endif diff --git a/gnu/lib/gcc34/libstdc++/Makefile b/gnu/lib/gcc34/libstdc++/Makefile index d275a51c92..1ddc30b220 100644 --- a/gnu/lib/gcc34/libstdc++/Makefile +++ b/gnu/lib/gcc34/libstdc++/Makefile @@ -1,4 +1,4 @@ -# $DragonFly: src/gnu/lib/gcc34/libstdc++/Makefile,v 1.2 2005/04/21 13:42:33 joerg Exp $ +# $DragonFly: src/gnu/lib/gcc34/libstdc++/Makefile,v 1.3 2005/04/21 16:36:34 joerg Exp $ .include "../Makefile.inc" @@ -48,6 +48,8 @@ SRCS+= codecvt_members.cc collate_members.cc ctype_members.cc SRCS+= messages_members.cc monetary_members.cc numeric_members.cc SRCS+= time_members.cc +SRCS+= ctype_noninline.h ctype_base.h os_defines.h + atomicity.cc: echo '#include "atomicity.h"' > ${.TARGET} @@ -157,12 +159,13 @@ STDHDRSDIR= ${INCLUDEDIR}/c++/3.4 # c++locale <- c_locale.h TARGETHDRS= io/basic_file_stdio.h io/c_io_stdio.h TARGETHDRS+= allocator/new_allocator_base.h -TARGETHDRS+= os/bsd/freebsd/ctype_inline.h os/bsd/freebsd/ctype_noninline.h -TARGETHDRS+= os/bsd/freebsd/os_defines.h os/bsd/freebsd/ctype_base.h +TARGETHDRS+= os/bsd/netbsd/ctype_inline.h +TARGETHDRS+= os/bsd/netbsd/os_defines.h TARGETHDRS+= locale/generic/messages_members.h locale/generic/time_members.h TARGETHDRS+= locale/generic/codecvt_specializations.h TARGETHDRS+= locale/generic/c_locale.h -TARGETHDRS:= ${TARGETHDRS:S;^;${SRCDIR}/config/;} +TARGETHDRS:= ${TARGETHDRS:S;^;${SRCDIR}/config/;} ctype_noninline.h \ + ctype_base.h os_defines.h TARGETHDRSNAME_c_io_stdio.h= c++io.h TARGETHDRSNAME_new_allocator_base.h= c++allocator.h @@ -207,6 +210,15 @@ gthr-default.h: ${GCCDIR}/gcc/gthr-posix.h -e 's,^#include "\(.*\)",#include ,g' \ < ${GCCDIR}/gcc/gthr-posix.h > gthr-default.h -CLEANFILES+= ${THRHDRS} +ctype_base.h: ${SRCDIR}/config/os/bsd/netbsd/ctype_base.h ctype_base.h.patch + patch -o ${.TARGET} -i ${.CURDIR}/ctype_base.h.patch ${SRCDIR}/config/os/bsd/netbsd/ctype_base.h + +ctype_noninline.h: ${SRCDIR}/config/os/bsd/netbsd/ctype_noninline.h ctype_noninline.h.patch + patch -o ${.TARGET} -i ${.CURDIR}/ctype_noninline.h.patch ${SRCDIR}/config/os/bsd/netbsd/ctype_noninline.h + +os_defines.h: ${SRCDIR}/config/os/bsd/netbsd/os_defines.h os_defines.h.patch + patch -o ${.TARGET} -i ${.CURDIR}/os_defines.h.patch ${SRCDIR}/config/os/bsd/netbsd/os_defines.h + +CLEANFILES+= ${THRHDRS} ctype_nonline.h ctype_base.h os_defines.h .include diff --git a/include/Makefile b/include/Makefile index 9c41a71e21..511a82525a 100644 --- a/include/Makefile +++ b/include/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 8.2 (Berkeley) 1/4/94 # $FreeBSD: src/include/Makefile,v 1.109.2.27 2003/01/24 05:12:29 sam Exp $ -# $DragonFly: src/include/Makefile,v 1.23 2005/02/11 23:20:58 joerg Exp $ +# $DragonFly: src/include/Makefile,v 1.24 2005/04/21 16:36:34 joerg Exp $ # # Doing a make install builds /usr/include # @@ -12,13 +12,13 @@ SUBDIR= arpa protocols rpc rpcsvc INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h ctype.h db.h \ dirent.h disktab.h \ dlfcn.h elf.h elf-hints.h err.h fnmatch.h fstab.h \ - fts.h getopt.h glob.h grp.h histedit.h ieeefp.h ifaddrs.h \ + fts.h getopt.h glob.h grp.h histedit.h iconv.h ieeefp.h ifaddrs.h \ iso646.h inttypes.h \ langinfo.h libgen.h limits.h link.h locale.h malloc.h memory.h \ mpool.h ndbm.h netdb.h nl_types.h nlist.h objformat.h \ paths.h pthread.h pthread_np.h pwd.h \ ranlib.h readpassphrase.h regex.h regexp.h resolv.h re_comp.h rmd160.h \ - rune.h runetype.h search.h setjmp.h sgtty.h \ + search.h setjmp.h sgtty.h \ signal.h stab.h stdarg.h stdbool.h stddef.h stdint.h stdio.h stdlib.h \ string.h stringlist.h strings.h struct.h sysexits.h tar.h time.h \ timers.h ttyent.h unistd.h ulimit.h utime.h utmp.h vis.h wchar.h \ diff --git a/include/ctype.h b/include/ctype.h index 0358333ee5..088299d40f 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -1,15 +1,15 @@ +/* $NetBSD: src/include/ctype.h,v 1.25 2003/10/22 15:51:18 kleink Exp $ */ +/* $DragonFly: src/include/ctype.h,v 1.6 2005/04/21 16:36:34 joerg Exp $ */ + /* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -18,11 +18,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -38,160 +34,93 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)ctype.h 8.4 (Berkeley) 1/21/94 - * $FreeBSD: src/include/ctype.h,v 1.16 2000/02/08 07:43:23 obrien Exp $ - * $DragonFly: src/include/ctype.h,v 1.5 2004/10/29 05:44:40 asmodai Exp $ + * @(#)ctype.h 5.3 (Berkeley) 4/3/91 */ #ifndef _CTYPE_H_ -#define _CTYPE_H_ +#define _CTYPE_H_ -#ifndef _SYS_STDINT_H_ -#include /* __ct_rune_t and friends */ -#endif +#include +#include -/* - * XXX brings massive namespace pollution (rune_t and struct - * member names). - */ -#include - -#define _CTYPE_A 0x00000100L /* Alpha */ -#define _CTYPE_C 0x00000200L /* Control */ -#define _CTYPE_D 0x00000400L /* Digit */ -#define _CTYPE_G 0x00000800L /* Graph */ -#define _CTYPE_L 0x00001000L /* Lower */ -#define _CTYPE_P 0x00002000L /* Punct */ -#define _CTYPE_S 0x00004000L /* Space */ -#define _CTYPE_U 0x00008000L /* Upper */ -#define _CTYPE_X 0x00010000L /* X digit */ -#define _CTYPE_B 0x00020000L /* Blank */ -#define _CTYPE_R 0x00040000L /* Print */ -#define _CTYPE_I 0x00080000L /* Ideogram */ -#define _CTYPE_T 0x00100000L /* Special */ -#define _CTYPE_Q 0x00200000L /* Phonogram */ -#define _CTYPE_SW0 0x20000000L /* 0 width character */ -#define _CTYPE_SW1 0x40000000L /* 1 width character */ -#define _CTYPE_SW2 0x80000000L /* 2 width character */ -#define _CTYPE_SW3 0xc0000000L /* 3 width character */ -#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */ -#define _CTYPE_SWS 30 /* Bits to shift to get width */ +#define _U 0x01 +#define _L 0x02 +#define _N 0x04 +#define _S 0x08 +#define _P 0x10 +#define _C 0x20 +#define _X 0x40 +#define _B 0x80 + +extern const __uint16_t *__libc_ctype_; +extern const __int16_t *__libc_tolower_tab_; +extern const __int16_t *__libc_toupper_tab_; __BEGIN_DECLS -int isalnum (int); -int isalpha (int); -int iscntrl (int); -int isdigit (int); -int isgraph (int); -int islower (int); -int isprint (int); -int ispunct (int); -int isspace (int); -int isupper (int); -int isxdigit (int); -int tolower (int); -int toupper (int); - -#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) -int digittoint (int); -int isascii (int); -int isblank (int); -int ishexnumber (int); -int isideogram (int); -int isnumber (int); -int isphonogram (int); -int isrune (int); -int isspecial (int); -int toascii (int); +int isalnum(int); +int isalpha(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); +int tolower(int); +int toupper(int); + +#if defined(__XSI_VISIBLE) +int isascii(int); +int toascii(int); +int _tolower(int); +int _toupper(int); #endif -__END_DECLS -#define __istype(c,f) (!!__maskrune((c),(f))) - -#define isalnum(c) __istype((c), _CTYPE_A|_CTYPE_D) -#define isalpha(c) __istype((c), _CTYPE_A) -#define iscntrl(c) __istype((c), _CTYPE_C) -#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */ -#define isgraph(c) __istype((c), _CTYPE_G) -#define islower(c) __istype((c), _CTYPE_L) -#define isprint(c) __istype((c), _CTYPE_R) -#define ispunct(c) __istype((c), _CTYPE_P) -#define isspace(c) __istype((c), _CTYPE_S) -#define isupper(c) __istype((c), _CTYPE_U) -#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */ -#define tolower(c) __tolower(c) -#define toupper(c) __toupper(c) - -#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) -#define digittoint(c) __maskrune((c), 0xFF) -#define isascii(c) (((c) & ~0x7F) == 0) -#define isblank(c) __istype((c), _CTYPE_B) -#define ishexnumber(c) __istype((c), _CTYPE_X) -#define isideogram(c) __istype((c), _CTYPE_I) -#define isnumber(c) __istype((c), _CTYPE_D) -#define isphonogram(c) __istype((c), _CTYPE_Q) -#define isrune(c) __istype((c), 0xFFFFFF00L) -#define isspecial(c) __istype((c), _CTYPE_T) -#define toascii(c) ((c) & 0x7F) +#if _ISO_C_VISIBLE >= 1999 || _POSIX_VISIBLE >= 200112L || \ + __XSI_VISIBLE >= 600 +int isblank(int); #endif - -__BEGIN_DECLS -unsigned long ___runetype (__ct_rune_t); -__ct_rune_t ___tolower (__ct_rune_t); -__ct_rune_t ___toupper (__ct_rune_t); __END_DECLS -/* - * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us - * to generate code for extern versions of all our inline functions. - */ -#ifdef _EXTERNALIZE_CTYPE_INLINES_ -#define _USE_CTYPE_INLINE_ -#define static -#define __inline +#define isdigit(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & _N)) +#define islower(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & _L)) +#define isspace(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & _S)) +#define ispunct(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & _P)) +#define isupper(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & _U)) +#define isalpha(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_U|_L))) +#define isxdigit(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_N|_X))) +#define isalnum(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_U|_L|_N))) +#define isprint(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_P|_U|_L|_N|_B))) +#define isgraph(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_P|_U|_L|_N))) +#define iscntrl(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & _C)) +#define tolower(c) ((int)((__libc_tolower_tab_ + 1)[(int)(c)])) +#define toupper(c) ((int)((__libc_toupper_tab_ + 1)[(int)(c)])) + +#if defined(__XSI_VISIBLE) +#define isascii(c) ((unsigned)(c) <= 0177) +#define toascii(c) ((c) & 0177) +#define _tolower(c) ((c) - 'A' + 'a') +#define _toupper(c) ((c) - 'a' + 'A') #endif -/* - * Use inline functions if we are allowed to and the compiler supports them. - */ -#if !defined(_DONT_USE_CTYPE_INLINE_) && \ - (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) -static __inline int -__maskrune(__ct_rune_t _c, unsigned long _f) -{ - return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : - _CurrentRuneLocale->runetype[_c]) & _f; -} - -static __inline int -__isctype(__ct_rune_t _c, unsigned long _f) -{ - return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : - !!(_DefaultRuneLocale.runetype[_c] & _f); -} - -static __inline __ct_rune_t -__toupper(__ct_rune_t _c) -{ - return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : - _CurrentRuneLocale->mapupper[_c]; -} - -static __inline __ct_rune_t -__tolower(__ct_rune_t _c) -{ - return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : - _CurrentRuneLocale->maplower[_c]; -} - -#else /* not using inlines */ +#if __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE >= 200112L || \ + __XSI_VISIBLE >= 600 +#define isblank(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & _B)) +#endif -__BEGIN_DECLS -int __maskrune (__ct_rune_t, unsigned long); -int __isctype (__ct_rune_t, unsigned long); -__ct_rune_t __toupper (__ct_rune_t); -__ct_rune_t __tolower (__ct_rune_t); -__END_DECLS -#endif /* using inlines */ +#ifdef _CTYPE_PRIVATE +#include /* for CHAR_BIT */ + +#define _CTYPE_NUM_CHARS (1 << CHAR_BIT) + +#define _CTYPE_ID "DFCTYPE" +#define _CTYPE_REV 3 + +extern const __uint16_t __libc_C_ctype_[]; +extern const __int16_t __libc_C_toupper_[]; +extern const __int16_t __libc_C_tolower_[]; +#endif #endif /* !_CTYPE_H_ */ diff --git a/include/locale.h b/include/locale.h index 298a407c8a..17a999a555 100644 --- a/include/locale.h +++ b/include/locale.h @@ -1,3 +1,6 @@ +/* $NetBSD: src/include/locale.h,v 1.13 2003/08/07 09:44:10 agc Exp $ */ +/* $DragonFly: src/include/locale.h,v 1.3 2005/04/21 16:36:34 joerg Exp $ */ + /* * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -10,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,23 +30,22 @@ * SUCH DAMAGE. * * @(#)locale.h 8.1 (Berkeley) 6/2/93 - * $DragonFly: src/include/locale.h,v 1.2 2003/11/14 01:01:43 dillon Exp $ */ #ifndef _LOCALE_H_ #define _LOCALE_H_ struct lconv { - char *decimal_point; - char *thousands_sep; - char *grouping; - char *int_curr_symbol; - char *currency_symbol; - char *mon_decimal_point; - char *mon_thousands_sep; - char *mon_grouping; - char *positive_sign; - char *negative_sign; + const char *decimal_point; + const char *thousands_sep; + const char *grouping; + const char *int_curr_symbol; + const char *currency_symbol; + const char *mon_decimal_point; + const char *mon_thousands_sep; + const char *mon_grouping; + const char *positive_sign; + const char *negative_sign; char int_frac_digits; char frac_digits; char p_cs_precedes; @@ -56,6 +54,12 @@ struct lconv { char n_sep_by_space; char p_sign_posn; char n_sign_posn; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; }; #ifndef NULL @@ -75,8 +79,8 @@ struct lconv { #include __BEGIN_DECLS -struct lconv *localeconv (void); -char *setlocale (int, const char *); +struct lconv *localeconv(void); +char *setlocale(int, const char *); __END_DECLS #endif /* _LOCALE_H_ */ diff --git a/include/nl_types.h b/include/nl_types.h index f52f06d595..6ac46069dc 100644 --- a/include/nl_types.h +++ b/include/nl_types.h @@ -1,52 +1,99 @@ -/* $FreeBSD: src/include/nl_types.h,v 1.7 1999/08/27 23:44:51 peter Exp $ */ -/* $DragonFly: src/include/nl_types.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ */ - -/*********************************************************** -Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that Alfalfa's name not be used in -advertising or publicity pertaining to distribution of the software -without specific, written prior permission. - -ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -If you make any modifications, bugfixes or other changes to this software -we'd appreciate it if you could send a copy to us so we can keep things -up-to-date. Many thanks. - Kee Hinckley - Alfalfa Software, Inc. - 267 Allston St., #3 - Cambridge, MA 02139 USA - nazgul@alfalfa.com - -******************************************************************/ +/* $NetBSD: src/include/nl_types.h,v 1.10 2001/12/06 23:04:06 wiz Exp $ */ +/* $DragonFly: src/include/nl_types.h,v 1.4 2005/04/21 16:36:34 joerg Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by J.T. Conklin. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef _NL_TYPES_H_ #define _NL_TYPES_H_ #include +#include + +#ifdef _NLS_PRIVATE +/* + * MESSAGE CATALOG FILE FORMAT. + * + * The NetBSD message catalog format is similar to the format used by + * Svr4 systems. The differences are: + * * fixed byte order (big endian) + * * fixed data field sizes + * + * A message catalog contains four data types: a catalog header, one + * or more set headers, one or more message headers, and one or more + * text strings. + */ + +#define _NLS_MAGIC 0xff88ff89 + +struct _nls_cat_hdr { + int32_t __magic; + int32_t __nsets; + int32_t __mem; + int32_t __msg_hdr_offset; + int32_t __msg_txt_offset; +} ; + +struct _nls_set_hdr { + int32_t __setno; /* set number: 0 < x <= NL_SETMAX */ + int32_t __nmsgs; /* number of messages in the set */ + int32_t __index; /* index of first msg_hdr in msg_hdr table */ +} ; + +struct _nls_msg_hdr { + int32_t __msgno; /* msg number: 0 < x <= NL_MSGMAX */ + int32_t __msglen; + int32_t __offset; +} ; + +#endif + +#define NL_SETD 1 +#define NL_CAT_LOCALE 1 -#define NL_SETD 0 -#define NL_CAT_LOCALE 1 +typedef struct __nl_cat_d { + void *__data; + __size_t __size; +} *nl_catd; -typedef int nl_item; -typedef void *nl_catd; +typedef long nl_item; __BEGIN_DECLS -extern nl_catd catopen (__const char *, int); -extern char *catgets (nl_catd, int, int, __const char *); -extern int catclose (nl_catd); +nl_catd catopen(const char *, int); +char *catgets(nl_catd, int, int, const char *); +int catclose(nl_catd); __END_DECLS #endif /* _NL_TYPES_H_ */ diff --git a/include/runetype.h b/include/runetype.h deleted file mode 100644 index e3eadd73b5..0000000000 --- a/include/runetype.h +++ /dev/null @@ -1,110 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)runetype.h 8.1 (Berkeley) 6/2/93 - * $FreeBSD: src/include/runetype.h,v 1.3.8.1 2002/08/08 02:42:29 imp Exp $ - * $DragonFly: src/include/Attic/runetype.h,v 1.5 2003/11/15 19:28:42 asmodai Exp $ - */ - -#ifndef _RUNETYPE_H_ -#define _RUNETYPE_H_ - -#include -#ifndef _SYS_STDINT_H_ -#include /* for __rune_t and friends */ -#endif - -#ifndef _RUNE_T_DECLARED -#define _RUNE_T_DECLARED -typedef __rune_t rune_t; -#endif -#ifndef __cplusplus -#ifndef _WCHAR_T_DECLARED -#define _WCHAR_T_DECLARED -typedef __wchar_t wchar_t; -#endif -#endif - -#define _CACHED_RUNES (1 <<8 ) /* Must be a power of 2 */ -#define _CRMASK (~(_CACHED_RUNES - 1)) - -/* - * The lower 8 bits of runetype[] contain the digit value of the rune. - */ -typedef struct { - rune_t min; /* First rune of the range */ - rune_t max; /* Last rune (inclusive) of the range */ - rune_t map; /* What first maps to in maps */ - unsigned long *types; /* Array of types in range */ -} _RuneEntry; - -typedef struct { - int nranges; /* Number of ranges stored */ - _RuneEntry *ranges; /* Pointer to the ranges */ -} _RuneRange; - -typedef struct { - char magic[8]; /* Magic saying what version we are */ - char encoding[32]; /* ASCII name of this encoding */ - - rune_t (*sgetrune) - (const char *, __size_t, char const **); - int (*sputrune) - (rune_t, char *, __size_t, char **); - rune_t invalid_rune; - - unsigned long runetype[_CACHED_RUNES]; - rune_t maplower[_CACHED_RUNES]; - rune_t mapupper[_CACHED_RUNES]; - - /* - * The following are to deal with Runes larger than _CACHED_RUNES - 1. - * Their data is actually contiguous with this structure so as to make - * it easier to read/write from/to disk. - */ - _RuneRange runetype_ext; - _RuneRange maplower_ext; - _RuneRange mapupper_ext; - - void *variable; /* Data which depends on the encoding */ - int variable_len; /* how long that data is */ -} _RuneLocale; - -#define _RUNE_MAGIC_1 "RuneMagi" /* Indicates version 0 of RuneLocale */ - -extern _RuneLocale _DefaultRuneLocale; -extern _RuneLocale *_CurrentRuneLocale; - -#endif /* !_RUNETYPE_H_ */ diff --git a/include/stdlib.h b/include/stdlib.h index dc1b37e43f..c2c35cbbbe 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -32,7 +32,7 @@ * * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 * $FreeBSD: src/include/stdlib.h,v 1.16.2.5 2002/12/13 01:34:00 tjr Exp $ - * $DragonFly: src/include/stdlib.h,v 1.9 2005/01/05 11:51:18 joerg Exp $ + * $DragonFly: src/include/stdlib.h,v 1.10 2005/04/21 16:36:34 joerg Exp $ */ #ifndef _STDLIB_H_ @@ -44,13 +44,6 @@ #include #endif -#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) -#ifndef _RUNE_T_DECLARED -#define _RUNE_T_DECLARED -typedef __rune_t rune_t; -#endif -#endif - #ifndef __cplusplus #ifndef _WCHAR_T_DECLARED #define _WCHAR_T_DECLARED diff --git a/include/wchar.h b/include/wchar.h index 05d5e1e808..2c90dce1a2 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -1,3 +1,6 @@ +/* $NetBSD: src/include/wchar.h,v 1.20 2004/05/08 21:57:05 kleink Exp $ */ +/* $DragonFly: src/include/wchar.h,v 1.6 2005/04/21 16:36:34 joerg Exp $ */ + /*- * Copyright (c)1999 Citrus Project, * All rights reserved. @@ -22,9 +25,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD: src/include/wchar.h,v 1.3.2.2 2002/08/08 02:42:29 imp Exp $ - * $DragonFly: src/include/wchar.h,v 1.5 2003/11/15 19:28:42 asmodai Exp $ */ /*- @@ -61,84 +61,133 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - * - * $NetBSD: wchar.h,v 1.8 2000/12/22 05:31:42 itojun Exp $ */ #ifndef _WCHAR_H_ #define _WCHAR_H_ -#include -#ifndef _SYS_STDINT_H_ -#include /* __wchar_t and friends */ -#endif +#include +/* XXX namespace pollution */ +#include + +#include /* for FILE* */ -#ifndef NULL -#define NULL 0 +#ifndef NULL +#define NULL 0 #endif #ifndef __cplusplus #ifndef _WCHAR_T_DECLARED -#define _WCHAR_T_DECLARED -typedef __wchar_t wchar_t; +#define _WCHAR_T_DECLARED +typedef __wchar_t wchar_t; #endif + +#ifndef WCHAR_MIN +#define WCHAR_MIN INT_MIN #endif -#ifndef _MBSTATE_T_DECLARED -#define _MBSTATE_T_DECLARED -typedef __mbstate_t mbstate_t; +#ifndef WCHAR_MAX +#define WCHAR_MAX INT_MAX #endif +#endif /* !__cplusplus */ #ifndef _WINT_T_DECLARED -#define _WINT_T_DECLARED -typedef __wint_t wint_t; +#define _WINT_T_DECLARED +typedef __wint_t wint_t; +#endif + +#ifndef WINT_MIN +#define WINT_MIN INT_MIN +#endif + +#ifndef WINT_MAX +#define WINT_MAX INT_MAX +#endif + +#ifndef _MBSTATE_T_DECLARED +#define _MBSTATE_T_DECLARED +typedef __mbstate_t mbstate_t; #endif #ifndef _SIZE_T_DECLARED #define _SIZE_T_DECLARED -typedef __size_t size_t; /* open group */ +typedef __size_t size_t; #endif #ifndef WEOF -#define WEOF ((wint_t)-1) +#define WEOF ((wint_t)(-1)) #endif __BEGIN_DECLS - -wchar_t *wcscat (wchar_t * __restrict, const wchar_t * __restrict); -wchar_t *wcschr (const wchar_t *, wchar_t); -int wcscmp (const wchar_t *, const wchar_t *); -wchar_t *wcscpy (wchar_t * __restrict, const wchar_t * __restrict); -size_t wcscspn (const wchar_t *, const wchar_t *); -size_t wcslen (const wchar_t *); -wchar_t *wcsncat (wchar_t * __restrict, const wchar_t * __restrict, - size_t); -int wcsncmp (const wchar_t *, const wchar_t *, size_t); -wchar_t *wcsncpy (wchar_t * __restrict , const wchar_t * __restrict, - size_t); -wchar_t *wcspbrk (const wchar_t *, const wchar_t *); -wchar_t *wcsrchr (const wchar_t *, wchar_t); -#if 0 -/* XXX: not implemented */ -size_t wcsrtombs (char * __restrict, const wchar_t ** __restrict, size_t, +wint_t btowc(int); +size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict); +size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, mbstate_t * __restrict); +int mbsinit(const mbstate_t *); +size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, + mbstate_t * __restrict); +size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); +wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict); +wchar_t *wcschr(const wchar_t *, wchar_t); +int wcscmp(const wchar_t *, const wchar_t *); +int wcscoll(const wchar_t *, const wchar_t *); +wchar_t *wcscpy(wchar_t * __restrict, const wchar_t * __restrict); +size_t wcscspn(const wchar_t *, const wchar_t *); +size_t wcslen(const wchar_t *); +wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict, size_t); +int wcsncmp(const wchar_t *, const wchar_t *, size_t); +wchar_t *wcsncpy(wchar_t * __restrict , const wchar_t * __restrict, size_t); +wchar_t *wcspbrk(const wchar_t *, const wchar_t *); +wchar_t *wcsrchr(const wchar_t *, wchar_t); +size_t wcsrtombs(char * __restrict, const wchar_t ** __restrict, size_t, + mbstate_t * __restrict); +size_t wcsspn(const wchar_t *, const wchar_t *); +wchar_t *wcsstr(const wchar_t *, const wchar_t *); +wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict, + wchar_t ** __restrict); +size_t wcsxfrm(wchar_t *, const wchar_t *, size_t); +wchar_t *wcswcs(const wchar_t *, const wchar_t *); +wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); +int wmemcmp(const wchar_t *, const wchar_t *, size_t); +wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); +wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); +wchar_t *wmemset(wchar_t *, wchar_t, size_t); + +size_t wcslcat(wchar_t *, const wchar_t *, size_t); +size_t wcslcpy(wchar_t *, const wchar_t *, size_t); +int wcswidth(const wchar_t *, size_t); +int wctob(wint_t); +int wcwidth(wchar_t); + +unsigned long wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, int); +long wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int); +double wcstod(const wchar_t * __restrict, wchar_t ** __restrict); + +#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) > 199901L || \ + defined(_NETBSD_SOURCE) +/* LONGLONG */ +long long wcstoll(const wchar_t * __restrict, wchar_t ** __restrict, int); +/* LONGLONG */ +unsigned long long wcstoull(const wchar_t * __restrict, + wchar_t ** __restrict, int); #endif -size_t wcsspn (const wchar_t *, const wchar_t *); -wchar_t *wcsstr (const wchar_t *, const wchar_t *); -wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); -int wmemcmp (const wchar_t *, const wchar_t *, size_t); -wchar_t *wmemcpy (wchar_t * __restrict, const wchar_t * __restrict, - size_t); -wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); -wchar_t *wmemset (wchar_t *, wchar_t, size_t); - -size_t wcslcat (wchar_t *, const wchar_t *, size_t); -size_t wcslcpy (wchar_t *, const wchar_t *, size_t); -#if 0 -/* XXX: not implemented */ -int wcswidth (const wchar_t *, size_t); -int wcwidth (wchar_t); -#endif + +wint_t ungetwc(wint_t, FILE *); +wint_t fgetwc(FILE *); +wchar_t *fgetws(wchar_t * __restrict, int, FILE * __restrict); +wint_t getwc(FILE *); +wint_t getwchar(void); +wint_t fputwc(wchar_t, FILE *); +int fputws(const wchar_t * __restrict, FILE * __restrict); +wint_t putwc(wchar_t, FILE *); +wint_t putwchar(wchar_t); + +int fwide(FILE *, int); __END_DECLS +#define getwc(f) fgetwc(f) +#define getwchar() getwc(stdin) +#define putwc(wc, f) fputwc((wc), (f)) +#define putwchar(wc) putwc((wc), stdout) + #endif /* !_WCHAR_H_ */ diff --git a/include/wctype.h b/include/wctype.h index f55ed1d029..13f3fd4419 100644 --- a/include/wctype.h +++ b/include/wctype.h @@ -1,3 +1,6 @@ +/* $NetBSD: src/include/wctype.h,v 1.5 2003/03/02 22:18:11 tshiozak Exp $ */ +/* $DragonFly: src/include/wctype.h,v 1.6 2005/04/21 16:36:34 joerg Exp $ */ + /*- * Copyright (c)1999 Citrus Project, * All rights reserved. @@ -24,24 +27,26 @@ * SUCH DAMAGE. * * citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp - * $NetBSD: wctype.h,v 1.3 2000/12/22 14:16:16 itojun Exp $ - * $FreeBSD: src/include/wctype.h,v 1.3.2.1 2001/07/11 23:48:38 obrien Exp $ - * $DragonFly: src/include/wctype.h,v 1.5 2003/11/15 19:28:42 asmodai Exp $ */ -#if 0 -/* XXX: not implemented */ #ifndef _WCTYPE_H_ #define _WCTYPE_H_ -#include -#ifndef _SYS_STDINT_H_ #include -#endif #ifndef _WINT_T_DECLARED -#define _WINT_T_DECLARED -typedef __wint_t wint_t; +#define _WINT_T_DECLARED +typedef __wint_t wint_t; +#endif + +#ifndef _WCTRANS_T_DECLARED +#define _WCTRANS_T_DECLARED +typedef __wctrans_t wctrans_t; +#endif + +#ifndef _WCTYPE_T_DECLARED +#define _WCTYPE_T_DECLARED +typedef __wctype_t wctype_t; #endif #ifndef WEOF @@ -49,21 +54,24 @@ typedef __wint_t wint_t; #endif __BEGIN_DECLS -int iswalnum (wint_t); -int iswalpha (wint_t); -int iswblank (wint_t); -int iswcntrl (wint_t); -int iswdigit (wint_t); -int iswgraph (wint_t); -int iswlower (wint_t); -int iswprint (wint_t); -int iswpunct (wint_t); -int iswspace (wint_t); -int iswupper (wint_t); -int iswxdigit (wint_t); -wint_t towlower (wint_t); -wint_t towupper (wint_t); +int iswalnum(wint_t); +int iswalpha(wint_t); +int iswblank(wint_t); +int iswcntrl(wint_t); +int iswdigit(wint_t); +int iswgraph(wint_t); +int iswlower(wint_t); +int iswprint(wint_t); +int iswpunct(wint_t); +int iswspace(wint_t); +int iswupper(wint_t); +int iswxdigit(wint_t); +int iswctype(wint_t, wctype_t); +wint_t towctrans(wint_t, wctrans_t); +wint_t towlower(wint_t); +wint_t towupper(wint_t); +wctrans_t wctrans(const char *); +wctype_t wctype(const char *); __END_DECLS #endif /* _WCTYPE_H_ */ -#endif diff --git a/lib/Makefile b/lib/Makefile index 6facafe7f9..eecbfabd5a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 8.1 (Berkeley) 6/4/93 # $FreeBSD: src/lib/Makefile,v 1.107.2.16 2002/10/10 19:24:35 kbyanc Exp $ -# $DragonFly: src/lib/Makefile,v 1.18 2005/04/20 21:06:05 joerg Exp $ +# $DragonFly: src/lib/Makefile,v 1.19 2005/04/21 16:36:34 joerg Exp $ # To satisfy shared library or ELF linkage when only the libraries being # built are visible: @@ -28,7 +28,7 @@ SUBDIR= ${_csu} csu/common libarchive libcom_err libcrypt msun libmd \ ${_libmilter} ${_libncp} libnetgraph libopie libpam \ libpcap libposix1e librpcsvc ${_libsm} ${_libsmb} ${_libsmdb} \ ${_libsmutil} libstand libtelnet libthread_xu libusbhid ${_libvgl} \ - libwrap libxpg4 liby libz + libwrap libxpg4 liby libz i18n_module _csu=csu/${MACHINE_ARCH} diff --git a/lib/libc/Makefile.inc b/lib/libc/Makefile.inc index 016bf4b223..06dc5c4383 100644 --- a/lib/libc/Makefile.inc +++ b/lib/libc/Makefile.inc @@ -1,5 +1,5 @@ # $FreeBSD: src/lib/libc/Makefile.inc,v 1.5 1999/08/27 23:58:06 peter Exp $ -# $DragonFly: src/lib/libc/Makefile.inc,v 1.3 2005/01/31 22:29:01 dillon Exp $ +# $DragonFly: src/lib/libc/Makefile.inc,v 1.4 2005/04/21 16:36:34 joerg Exp $ # # This file contains make rules that are shared by libc and libc_r. # @@ -20,10 +20,12 @@ WARNS=6 .include "${.CURDIR}/../libc/${MACHINE_ARCH}/Makefile.inc" .endif +.include "${.CURDIR}/../libc/citrus/Makefile.inc" .include "${.CURDIR}/../libc/db/Makefile.inc" .include "${.CURDIR}/../libc/compat-43/Makefile.inc" .include "${.CURDIR}/../libc/gen/Makefile.inc" .include "${.CURDIR}/../libc/gmon/Makefile.inc" +.include "${.CURDIR}/../libc/iconv/Makefile.inc" .include "${.CURDIR}/../libc/locale/Makefile.inc" .include "${.CURDIR}/../libc/net/Makefile.inc" .include "${.CURDIR}/../libc/nls/Makefile.inc" diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 522fbc3e0f..be0d6ad8a6 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,6 +1,6 @@ # @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # $FreeBSD: src/lib/libc/gen/Makefile.inc,v 1.62.2.19 2003/02/21 13:46:16 phantom Exp $ -# $DragonFly: src/lib/libc/gen/Makefile.inc,v 1.9 2005/03/13 19:18:29 joerg Exp $ +# $DragonFly: src/lib/libc/gen/Makefile.inc,v 1.10 2005/04/21 16:36:34 joerg Exp $ # machine-independent gen sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/gen ${.CURDIR}/../libc/gen @@ -8,7 +8,7 @@ SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ alarm.c arc4random.c assert.c basename.c \ clock.c closedir.c confstr.c \ - crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \ + crypt.c ctermid.c ctype.c daemon.c devname.c dirname.c disklabel.c \ dlfcn.c drand48.c erand48.c err.c errlst.c \ exec.c fmtcheck.c fnmatch.c fstab.c ftok.c fts.c getbootfile.c getbsize.c \ getcap.c getcwd.c getdomainname.c getgrent.c getgrouplist.c \ @@ -16,7 +16,7 @@ SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ getobjformat.c getosreldate.c getpagesize.c \ getpeereid.c getprogname.c getpwent.c getttyent.c \ getusershell.c getvfsbyname.c getvfsent.c glob.c \ - initgroups.c isatty.c jrand48.c lcong48.c \ + initgroups.c isascii.c isatty.c isctype.c jrand48.c lcong48.c \ lockf.c lrand48.c mrand48.c msgctl.c \ msgget.c msgrcv.c msgsnd.c nice.c \ nlist.c nrand48.c ntp_gettime.c opendir.c \ @@ -28,9 +28,9 @@ SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ shmat.c shmctl.c shmdt.c shmget.c siginterrupt.c siglist.c signal.c \ sigsetops.c sigwait.c sleep.c srand48.c stringlist.c strtofflags.c \ sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \ - syslog.c telldir.c termios.c time.c times.c timezone.c tls.c ttyname.c \ - ttyslot.c ualarm.c ulimit.c uname.c unvis.c usleep.c utime.c \ - valloc.c vis.c \ + syslog.c telldir.c termios.c time.c times.c timezone.c tls.c \ + tolower.c toupper.c ttyname.c ttyslot.c ualarm.c ulimit.c \ + uname.c unvis.c usleep.c utime.c valloc.c vis.c \ wait.c wait3.c waitpid.c # machine-dependent gen sources diff --git a/lib/libc/gen/isctype.c b/lib/libc/gen/isctype.c index e0bb20e517..a5de3e2173 100644 --- a/lib/libc/gen/isctype.c +++ b/lib/libc/gen/isctype.c @@ -1,15 +1,15 @@ +/* $NetBSD: src/lib/libc/gen/isctype.c,v 1.16 2003/08/07 16:42:52 agc Exp $ */ +/* $DragonFly: src/lib/libc/gen/isctype.c,v 1.3 2005/04/21 16:36:34 joerg Exp $ */ + /* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -18,11 +18,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -37,196 +33,105 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/isctype.c,v 1.7 2000/02/08 07:43:24 obrien Exp $ - * $DragonFly: src/lib/libc/gen/isctype.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ - * - * @(#)isctype.c 8.3 (Berkeley) 2/24/94 */ +#define _ANSI_LIBRARY #include -#undef digittoint -int -digittoint(c) - int c; -{ - return (__maskrune((c), 0xFF)); -} - #undef isalnum int -isalnum(c) - int c; +isalnum(int c) { - return (__istype((c), _CTYPE_A|_CTYPE_D)); + return((__libc_ctype_ + 1)[c] & (_U|_L|_N)); } #undef isalpha int -isalpha(c) - int c; +isalpha(int c) { - return (__istype((c), _CTYPE_A)); -} - -#undef isascii -int -isascii(c) - int c; -{ - return (((c) & ~0x7F) == 0); + return((__libc_ctype_ + 1)[c] & (_U|_L)); } #undef isblank int -isblank(c) - int c; +isblank(int c) { - return (__istype((c), _CTYPE_B)); + return((__libc_ctype_ + 1)[c] & _B); } #undef iscntrl int -iscntrl(c) - int c; +iscntrl(int c) { - return (__istype((c), _CTYPE_C)); + return((__libc_ctype_ + 1)[c] & _C); } #undef isdigit int -isdigit(c) - int c; +isdigit(int c) { - return (__isctype((c), _CTYPE_D)); + return((__libc_ctype_ + 1)[c] & _N); } #undef isgraph int -isgraph(c) - int c; -{ - return (__istype((c), _CTYPE_G)); -} - -#undef ishexnumber -int -ishexnumber(c) - int c; +isgraph(int c) { - return (__istype((c), _CTYPE_X)); -} - -#undef isideogram -int -isideogram(c) - int c; -{ - return (__istype((c), _CTYPE_I)); + return((__libc_ctype_ + 1)[c] & (_P|_U|_L|_N)); } #undef islower int -islower(c) - int c; +islower(int c) { - return (__istype((c), _CTYPE_L)); -} - -#undef isnumber -int -isnumber(c) - int c; -{ - return (__istype((c), _CTYPE_D)); -} - -#undef isphonogram -int -isphonogram(c) - int c; -{ - return (__istype((c), _CTYPE_Q)); + return((__libc_ctype_ + 1)[c] & _L); } #undef isprint int -isprint(c) - int c; +isprint(int c) { - return (__istype((c), _CTYPE_R)); + return((__libc_ctype_ + 1)[c] & (_P|_U|_L|_N|_B)); } #undef ispunct int -ispunct(c) - int c; -{ - return (__istype((c), _CTYPE_P)); -} - -#undef isrune -int -isrune(c) - int c; +ispunct(int c) { - return (__istype((c), 0xFFFFFF00L)); + return((__libc_ctype_ + 1)[c] & _P); } #undef isspace int -isspace(c) - int c; -{ - return (__istype((c), _CTYPE_S)); -} - -#undef isspecial -int -isspecial(c) - int c; +isspace(int c) { - return (__istype((c), _CTYPE_T)); + return((__libc_ctype_ + 1)[c] & _S); } #undef isupper int -isupper(c) - int c; +isupper(int c) { - return (__istype((c), _CTYPE_U)); + return((__libc_ctype_ + 1)[c] & _U); } #undef isxdigit int -isxdigit(c) - int c; +isxdigit(int c) { - return (__isctype((c), _CTYPE_X)); + return((__libc_ctype_ + 1)[c] & (_N|_X)); } -#undef toascii +#undef _toupper int -toascii(c) - int c; +_toupper(int c) { - return ((c) & 0x7F); + return(c - 'a' + 'A'); } -#undef tolower +#undef _tolower int -tolower(c) - int c; +_tolower(int c) { - return (__tolower(c)); + return(c - 'A' + 'a'); } - -#undef toupper -int -toupper(c) - int c; -{ - return (__toupper(c)); -} - diff --git a/lib/libc/gen/tolower.c b/lib/libc/gen/tolower.c new file mode 100644 index 0000000000..c70773c7ea --- /dev/null +++ b/lib/libc/gen/tolower.c @@ -0,0 +1,60 @@ +/* $NetBSD: src/lib/libc/gen/tolower_.c,v 1.9 2003/07/26 19:24:45 salo Exp $ */ +/* $DragonFly: src/lib/libc/gen/tolower.c,v 1.1 2005/04/21 16:36:34 joerg Exp $ */ + +/* + * Written by J.T. Conklin . + * Public domain. + */ + +#include +#include +#include + +#if EOF != -1 +#error "EOF != -1" +#endif + +const int16_t __libc_C_tolower_[1 + 256] = { + EOF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff +}; + +const int16_t *__libc_tolower_tab_ = __libc_C_tolower_; + +#undef tolower +int +tolower(int c) +{ + return((__libc_tolower_tab_ + 1)[c]); +} diff --git a/lib/libc/gen/toupper.c b/lib/libc/gen/toupper.c new file mode 100644 index 0000000000..df2423a82d --- /dev/null +++ b/lib/libc/gen/toupper.c @@ -0,0 +1,60 @@ +/* $NetBSD: src/lib/libc/gen/toupper_.c,v 1.9 2003/07/26 19:24:45 salo Exp $ */ +/* $DragonFly: src/lib/libc/gen/toupper.c,v 1.1 2005/04/21 16:36:34 joerg Exp $ */ + +/* + * Written by J.T. Conklin . + * Public domain. + */ + +#include +#include +#include + +#if EOF != -1 +#error "EOF != -1" +#endif + +const int16_t __libc_C_toupper_[1 + 256] = { + EOF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff +}; + +const int16_t *__libc_toupper_tab_ = __libc_C_toupper_; + +#undef toupper +int +toupper(int c) +{ + return((__libc_toupper_tab_ + 1)[c]); +} diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index 3d48120c11..b06483c5e6 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -1,25 +1,27 @@ -# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $FreeBSD: src/lib/libc/locale/Makefile.inc,v 1.16.2.5 2002/10/24 11:00:52 tjr Exp $ -# $DragonFly: src/lib/libc/locale/Makefile.inc,v 1.6 2005/03/13 19:18:29 joerg Exp $ +# $DragonFly: src/lib/libc/locale/Makefile.inc,v 1.7 2005/04/21 16:36:34 joerg Exp $ -# locale sources -.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/locale ${.CURDIR}/../libc/locale +.PATH: ${.CURDIR}/../libc/locale -SRCS+= ansi.c big5.c collate.c collcmp.c euc.c fix_grouping.c frune.c \ - gbk.c gb18030.c isctype.c \ - ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mbrune.c \ - mskanji.c nl_langinfo.c nomacros.c none.c rune.c \ - runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \ - tolower.c toupper.c utf2.c utf8.c +SRCS+= collate.c collcmp.c +SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.c +SRCS+= ctypeio.c localeconv.c nl_langinfo.c setlocale.c __mb_cur_max.c +SRCS+= wcscoll.c wcstod.c wcstol.c wcstoll.c wcstoimax.c wcstoul.c +SRCS+= wcstoumax.c wcsxfrm.c aliasname.c +SRCS+= ___runetype_mb.c _wctrans.c iswctype.c multibyte_c90.c +SRCS+= multibyte_amd1.c rune.c runeglue.c runetable.c setrunelocale.c + +CFLAGS+= -I${.CURDIR}/../libc/locale .if ${LIB} == "c" -MAN+= mbrune.3 multibyte.3 nl_langinfo.3 rune.3 setlocale.3 +MAN+= nl_langinfo.3 setlocale.3 +MAN+= btowc.3 iswalnum.3 iswctype.3 towlower.3 towctrans.3 mblen.3 mbrlen.3 +MAN+= mbrtowc.3 mbsinit.3 mbsrtowcs.3 mbstowcs.3 mbtowc.3 wcrtomb.3 +MAN+= wcsrtombs.3 wcstombs.3 wctob.3 wctomb.3 wctrans.3 wctype.3 -MLINKS+=mbrune.3 mbmb.3 mbrune.3 mbrrune.3 -MLINKS+=multibyte.3 mblen.3 multibyte.3 mbstowcs.3 multibyte.3 mbtowc.3 \ - multibyte.3 wcstombs.3 multibyte.3 wctomb.3 -MLINKS+=rune.3 fgetrune.3 rune.3 fputrune.3 rune.3 fungetrune.3 \ - rune.3 setinvalidrune.3 rune.3 setrunelocale.3 rune.3 sgetrune.3 \ - rune.3 sputrune.3 -MLINKS+=setlocale.3 localeconv.3 +MLINKS+=iswalnum.3 iswalpha.3 iswalnum.3 iswblank.3 +MLINKS+=iswalnum.3 iswcntrl.3 iswalnum.3 iswdigit.3 +MLINKS+=iswalnum.3 iswgraph.3 iswalnum.3 iswlower.3 +MLINKS+=iswalnum.3 iswprint.3 iswalnum.3 iswpunct.3 +MLINKS+=iswalnum.3 iswspace.3 iswalnum.3 iswupper.3 +MLINKS+=iswalnum.3 iswxdigit.3 towlower.3 towupper.3 .endif diff --git a/lib/libc/locale/_def_monetary.c b/lib/libc/locale/_def_monetary.c new file mode 100644 index 0000000000..fbed774c87 --- /dev/null +++ b/lib/libc/locale/_def_monetary.c @@ -0,0 +1,37 @@ +/* $NetBSD: src/lib/libc/locale/_def_monetary.c,v 1.7 2003/07/26 19:24:46 salo Exp $ */ +/* $DragonFly: src/lib/libc/locale/_def_monetary.c,v 1.1 2005/04/21 16:36:34 joerg Exp $ */ + +/* + * Written by J.T. Conklin . + * Public domain. + */ + +#include +#include +#include + +const _MonetaryLocale _DefaultMonetaryLocale = { + "", + "", + "", + "", + "", + "", + "", + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX, + (char)CHAR_MAX +}; + +const _MonetaryLocale *_CurrentMonetaryLocale = &_DefaultMonetaryLocale; diff --git a/lib/libc/locale/_def_time.c b/lib/libc/locale/_def_time.c index cb94ce4b6f..b4536252be 100644 --- a/lib/libc/locale/_def_time.c +++ b/lib/libc/locale/_def_time.c @@ -1,5 +1,5 @@ /* $NetBSD: src/lib/libc/locale/_def_time.c,v 1.7 2003/07/26 19:24:46 salo Exp $ */ -/* $DragonFly: src/lib/libc/locale/_def_time.c,v 1.1 2005/03/16 06:54:41 joerg Exp $ */ +/* $DragonFly: src/lib/libc/locale/_def_time.c,v 1.2 2005/04/21 16:36:34 joerg Exp $ */ /* * Written by J.T. Conklin . @@ -21,7 +21,8 @@ const _TimeLocale _DefaultTimeLocale = { "%a %b %e %H:%M:%S %Y", "%m/%d/%y", "%H:%M:%S", - "%I:%M:%S %p" + "%I:%M:%S %p", + "%a %b %e %H:%M:%S %Z %Y" }; const _TimeLocale *_CurrentTimeLocale = &_DefaultTimeLocale; diff --git a/lib/libc/locale/ansi.c b/lib/libc/locale/ansi.c deleted file mode 100644 index fe3b0c3cfe..0000000000 --- a/lib/libc/locale/ansi.c +++ /dev/null @@ -1,195 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ansi.c 8.1 (Berkeley) 6/27/93 - * $FreeBSD: src/lib/libc/locale/ansi.c,v 1.3.6.1 2003/04/05 08:28:24 tjr Exp $ - * $DragonFly: src/lib/libc/locale/Attic/ansi.c,v 1.2 2003/06/17 04:26:43 dillon Exp $ - */ - -#include -#include -#include -#include -#include - -int -mblen(s, n) - const char *s; - size_t n; -{ - char const *e; - - if (s == 0 || *s == 0) - return (0); /* No support for state dependent encodings. */ - - if (sgetrune(s, n, &e) == _INVALID_RUNE) - return (s - e); - return (e - s); -} - -int -mbtowc(pwc, s, n) - wchar_t *pwc; - const char *s; - size_t n; -{ - char const *e; - rune_t r; - - if (s == 0 || *s == 0) - return (0); /* No support for state dependent encodings. */ - - if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) - return (s - e); - if (pwc) - *pwc = r; - return (e - s); -} - -int -wctomb(s, wchar) - char *s; - wchar_t wchar; -{ - char *e; - - if (s == 0) - return (0); /* No support for state dependent encodings. */ - - if (wchar == 0) { - *s = 0; - return (1); - } - - sputrune(wchar, s, MB_CUR_MAX, &e); - return (e ? e - s : -1); -} - -size_t -mbstowcs(pwcs, s, n) - wchar_t *pwcs; - const char *s; - size_t n; -{ - const char *e; - int cnt; - rune_t r; - - if (s == NULL) { - errno = EINVAL; - return (-1); - } - - if (pwcs == NULL) { - /* Convert and count only, do not store. */ - cnt = 0; - while ((r = sgetrune(s, MB_LEN_MAX, &e)) != _INVALID_RUNE && - r != 0) { - s = e; - cnt++; - } - if (r == _INVALID_RUNE) { - errno = EILSEQ; - return (-1); - } - return (cnt); - } - - /* Convert, store and count characters. */ - cnt = 0; - while (n-- > 0) { - *pwcs = sgetrune(s, MB_LEN_MAX, &e); - if (*pwcs == _INVALID_RUNE) { - errno = EILSEQ; - return (-1); - } - if (*pwcs++ == L'\0') - break; - s = e; - ++cnt; - } - - return (cnt); -} - -size_t -wcstombs(s, pwcs, n) - char *s; - const wchar_t *pwcs; - size_t n; -{ - char buf[MB_LEN_MAX]; - char *e; - int cnt, nb; - - if (pwcs == NULL || n > INT_MAX) { - errno = EINVAL; - return (-1); - } - - cnt = 0; - - if (s == NULL) { - /* Convert and count only, do not store. */ - while (*pwcs != L'\0') { - if (sputrune(*pwcs++, buf, MB_LEN_MAX, &e) == 0) { - errno = EILSEQ; - return (-1); - } - cnt += e - buf; - } - return (cnt); - } - - /* Convert, store and count characters. */ - nb = n; - while (nb > 0) { - if (*pwcs == L'\0') { - *s = '\0'; - break; - } - if (sputrune(*pwcs++, s, nb, &e) == 0) { - errno = EILSEQ; - return (-1); - } - if (e == NULL) /* too long */ - return (cnt); - cnt += e - s; - nb -= e - s; - s = e; - } - - return (cnt); -} diff --git a/lib/libc/locale/big5.c b/lib/libc/locale/big5.c deleted file mode 100644 index e3cb8bccc1..0000000000 --- a/lib/libc/locale/big5.c +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/big5.c,v 1.3.2.2 2001/03/05 10:02:54 obrien Exp $ - * $DragonFly: src/lib/libc/locale/Attic/big5.c,v 1.4 2003/12/02 14:56:28 eirikn Exp $ - * - * @(#)big5.c 8.1 (Berkeley) 6/4/93 - */ - -#include -#include -#include - -rune_t _BIG5_sgetrune (const char *, size_t, char const **); -int _BIG5_sputrune (rune_t, char *, size_t, char **); - -int -_BIG5_init(rl) - _RuneLocale *rl; -{ - rl->sgetrune = _BIG5_sgetrune; - rl->sputrune = _BIG5_sputrune; - _CurrentRuneLocale = rl; - __mb_cur_max = 2; - return (0); -} - -static inline int -_big5_check(c) - u_int c; -{ - c &= 0xff; - return ((c >= 0xa1 && c <= 0xfe) ? 2 : 1); -} - -rune_t -_BIG5_sgetrune(string, n, result) - const char *string; - size_t n; - char const **result; -{ - rune_t rune = 0; - int len; - - if (n < 1 || (len = _big5_check(*string)) > n) { - if (result) - *result = string; - return (_INVALID_RUNE); - } - while (--len >= 0) - rune = (rune << 8) | ((u_int)(*string++) & 0xff); - if (result) - *result = string; - return rune; -} - -int -_BIG5_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - if (c & 0x8000) { - if (n >= 2) { - string[0] = (c >> 8) & 0xff; - string[1] = c & 0xff; - if (result) - *result = string + 2; - return (2); - } - } - else { - if (n >= 1) { - *string = c & 0xff; - if (result) - *result = string + 1; - return (1); - } - } - if (result) - *result = string; - return (0); - -} diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index 1d7fdbac00..adf90cd46e 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/locale/collate.c,v 1.21.2.4 2002/10/11 10:36:47 ache Exp $ - * $DragonFly: src/lib/libc/locale/collate.c,v 1.5 2005/03/09 18:52:21 joerg Exp $ + * $DragonFly: src/lib/libc/locale/collate.c,v 1.6 2005/04/21 16:36:34 joerg Exp $ */ #include "namespace.h" @@ -40,8 +40,11 @@ #include "un-namespace.h" #include "collate.h" -#include "setlocale.h" -#include "ldpart.h" + +#define ENCODING_LEN 31 +#define _LDP_LOADED 0 +#define _LDP_ERROR (-1) +#define _LDP_CACHE 1 int __collate_load_error = 1; int __collate_substitute_nontrivial; diff --git a/lib/libc/locale/euc.c b/lib/libc/locale/euc.c deleted file mode 100644 index 9461682729..0000000000 --- a/lib/libc/locale/euc.c +++ /dev/null @@ -1,217 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)euc.c 8.1 (Berkeley) 6/4/93 - * $FreeBSD: src/lib/libc/locale/euc.c,v 1.3.6.2 2002/08/12 11:17:37 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/euc.c,v 1.3 2003/12/02 14:56:28 eirikn Exp $ - */ - -#include - -#include -#include -#include - -rune_t _EUC_sgetrune(const char *, size_t, char const **); -int _EUC_sputrune(rune_t, char *, size_t, char **); - -typedef struct { - int count[4]; - rune_t bits[4]; - rune_t mask; -} _EucInfo; - -int -_EUC_init(rl) - _RuneLocale *rl; -{ - _EucInfo *ei; - int x, new__mb_cur_max; - char *v, *e; - - rl->sgetrune = _EUC_sgetrune; - rl->sputrune = _EUC_sputrune; - - if (rl->variable == NULL) - return (EFTYPE); - - v = (char *)rl->variable; - - while (*v == ' ' || *v == '\t') - ++v; - - if ((ei = malloc(sizeof(_EucInfo))) == NULL) - return (errno == 0 ? ENOMEM : errno); - - new__mb_cur_max = 0; - for (x = 0; x < 4; ++x) { - ei->count[x] = (int)strtol(v, &e, 0); - if (v == e || !(v = e)) { - free(ei); - return (EFTYPE); - } - if (new__mb_cur_max < ei->count[x]) - new__mb_cur_max = ei->count[x]; - while (*v == ' ' || *v == '\t') - ++v; - ei->bits[x] = (int)strtol(v, &e, 0); - if (v == e || !(v = e)) { - free(ei); - return (EFTYPE); - } - while (*v == ' ' || *v == '\t') - ++v; - } - ei->mask = (int)strtol(v, &e, 0); - if (v == e || !(v = e)) { - free(ei); - return (EFTYPE); - } - rl->variable = ei; - rl->variable_len = sizeof(_EucInfo); - _CurrentRuneLocale = rl; - __mb_cur_max = new__mb_cur_max; - return (0); -} - -#define CEI ((_EucInfo *)(_CurrentRuneLocale->variable)) - -#define _SS2 0x008e -#define _SS3 0x008f - -#define GR_BITS 0x80808080 /* XXX: to be fixed */ - -static inline int -_euc_set(c) - u_int c; -{ - c &= 0xff; - - return ((c & 0x80) ? c == _SS3 ? 3 : c == _SS2 ? 2 : 1 : 0); -} -rune_t -_EUC_sgetrune(string, n, result) - const char *string; - size_t n; - char const **result; -{ - rune_t rune = 0; - int len, set; - - if (n < 1 || (len = CEI->count[set = _euc_set(*string)]) > n) { - if (result) - *result = string; - return (_INVALID_RUNE); - } - switch (set) { - case 3: - case 2: - --len; - ++string; - /* FALLTHROUGH */ - case 1: - case 0: - while (len-- > 0) - rune = (rune << 8) | ((u_int)(*string++) & 0xff); - break; - } - if (result) - *result = string; - return ((rune & ~CEI->mask) | CEI->bits[set]); -} - -int -_EUC_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - rune_t m = c & CEI->mask; - rune_t nm = c & ~m; - int i, len; - - if (m == CEI->bits[1]) { -CodeSet1: - /* Codeset 1: The first byte must have 0x80 in it. */ - i = len = CEI->count[1]; - if (n >= len) { - if (result) - *result = string + len; - while (i-- > 0) - *string++ = (nm >> (i << 3)) | 0x80; - } else - if (result) - *result = (char *) 0; - } else { - if (m == CEI->bits[0]) { - i = len = CEI->count[0]; - if (n < len) { - if (result) - *result = NULL; - return (len); - } - } else - if (m == CEI->bits[2]) { - i = len = CEI->count[2]; - if (n < len) { - if (result) - *result = NULL; - return (len); - } - *string++ = _SS2; - --i; - /* SS2 designates G2 into GR */ - nm |= GR_BITS; - } else - if (m == CEI->bits[3]) { - i = len = CEI->count[3]; - if (n < len) { - if (result) - *result = NULL; - return (len); - } - *string++ = _SS3; - --i; - /* SS3 designates G3 into GR */ - nm |= GR_BITS; - } else - goto CodeSet1; /* Bletch */ - while (i-- > 0) - *string++ = (nm >> (i << 3)) & 0xff; - if (result) - *result = string; - } - return (len); -} diff --git a/lib/libc/locale/fix_grouping.c b/lib/libc/locale/fix_grouping.c deleted file mode 100644 index 0949b7e90d..0000000000 --- a/lib/libc/locale/fix_grouping.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/fix_grouping.c,v 1.6.2.1 2002/03/12 17:17:48 phantom Exp $ - * $DragonFly: src/lib/libc/locale/Attic/fix_grouping.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#include -#include -#include - -static const char nogrouping[] = { CHAR_MAX, '\0' }; - -/* - * "3;3;-1" -> "\003\003\177" - */ - -const char * -__fix_locale_grouping_str(const char *str) { - - char *src, *dst; - char n; - - if (str == NULL || *str == '\0') { - return nogrouping; - } - - for (src = (char*)str, dst = (char*)str; *src != '\0'; src++) { - - /* input string examples: "3;3", "3;2;-1" */ - if (*src == ';') - continue; - - if (*src == '-' && *(src+1) == '1') { - *dst++ = CHAR_MAX; - src++; - continue; - } - - if (!isdigit((unsigned char)*src)) { - /* broken grouping string */ - return nogrouping; - } - - /* assume all numbers <= 99 */ - n = *src - '0'; - if (isdigit((unsigned char)*(src+1))) { - src++; - n *= 10; - n += *src - '0'; - } - - *dst = n; - /* NOTE: assume all input started with "0" as 'no grouping' */ - if (*dst == '\0') - return (dst == (char*)str) ? nogrouping : str; - dst++; - } - *dst = '\0'; - return str; -} diff --git a/lib/libc/locale/gb18030.c b/lib/libc/locale/gb18030.c deleted file mode 100644 index f6bdd49f8b..0000000000 --- a/lib/libc/locale/gb18030.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2003 - * The Regents of the University of California. All rights reserved. - * - * This code is contributed to Robin Hu - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * $DragonFly: src/lib/libc/locale/Attic/gb18030.c,v 1.1 2003/12/01 23:29:25 drhodus Exp $ - */ - -#include - -#include -#include -#include -#include -#include - -rune_t _GB18030_sgetrune(const char *, size_t, char const **); -int _GB18030_sputrune(rune_t, char *, size_t, char **); - -int -_GB18030_init(rl) - _RuneLocale *rl; -{ - rl->sgetrune = _GB18030_sgetrune; - rl->sputrune = _GB18030_sputrune; - _CurrentRuneLocale = rl; - __mb_cur_max = 4; - return (0); -} - -static inline int -_gb18030_check_string(s_, n) - const char* s_; - int n; -{ - const unsigned char* s = s_; - if ((s[0]>=0x81&&s[0]<=0xfe)) { - if (n<2) goto bad_string; - if ((s[1]>=0x40&&s[1]<=0x7e)||(s[1]>=0x80&&s[1]<=0xfe)) - return 2; - if ((s[1]>=0x30&&s[1]<=0x39)) { - if (n<4) goto bad_string; - if ((s[2]>=0x81&&s[2]<=0xfe) && (s[3]>=0x30&&s[3]<=0x39)) - return 4; - else - goto bad_string; - } - } else { - return 1; - } - bad_string: - return -1; -} - -static inline int -_gb18030_check_rune(r) - rune_t r; -{ - if (r&0xff000000) { - return 4; - } - if (r&0xff00) { - return 2; - } - return 1; -} - -rune_t -_GB18030_sgetrune(string, n, result) - const char *string; - size_t n; - char const **result; -{ - rune_t rune = 0; - int len; - - len = _gb18030_check_string(string, n); - - if (len == -1) { - if (result) - *result = string; - return (_INVALID_RUNE); - } - - while (--len >= 0) - rune = (rune << 8) | ((u_int)(*string++) & 0xff); - - rune &= 0x7fffffff; - if (result) - *result = string; - return rune; -} - -int -_GB18030_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - int len; - len = _gb18030_check_rune(c); - - switch (len) { - case 1: - if (n >= 1) { - *string = c & 0xff; - if (result) - *result = string + 1; - return (1); - } - break; - case 2: - if (n >= 2) { - string[0] = (c >> 8) & 0xff; - string[1] = c & 0xff; - if (result) - *result = string + 2; - return (2); - } - break; - case 4: - if (n >= 4) { - string[0] = ((c >>24) & 0xff) | 0x80; - string[1] = (c >>16) & 0xff; - string[2] = (c >>8) & 0xff; - string[3] = c & 0xff; - if (result) - *result = string + 4; - return (4); - } - break; - default: - break; - } - if (result) - *result = string; - return (0); -} - diff --git a/lib/libc/locale/gbk.c b/lib/libc/locale/gbk.c deleted file mode 100644 index 1af6d9d928..0000000000 --- a/lib/libc/locale/gbk.c +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * $DragonFly: src/lib/libc/locale/Attic/gbk.c,v 1.2 2003/12/02 14:56:28 eirikn Exp $ - */ - -#include - -#include -#include -#include - -rune_t _GBK_sgetrune(const char *, size_t, char const **); -int _GBK_sputrune(rune_t, char *, size_t, char **); - -int -_GBK_init(rl) - _RuneLocale *rl; -{ - rl->sgetrune = _GBK_sgetrune; - rl->sputrune = _GBK_sputrune; - _CurrentRuneLocale = rl; - __mb_cur_max = 2; - return (0); -} - -static inline int -_gbk_check(c) - u_int c; -{ - c &= 0xff; - return ((c >= 0x80 && c <= 0xfe) ? 2 : 1); -} - -rune_t -_GBK_sgetrune(string, n, result) - const char *string; - size_t n; - char const **result; -{ - rune_t rune = 0; - int len; - - if (n < 1 || (len = _gbk_check(*string)) > n) { - if (result) - *result = string; - return (_INVALID_RUNE); - } - while (--len >= 0) - rune = (rune << 8) | ((u_int)(*string++) & 0xff); - if (result) - *result = string; - return rune; -} - -int -_GBK_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - if (c & 0x8000) { - if (n >= 2) { - string[0] = (c >> 8) & 0xff; - string[1] = c & 0xff; - if (result) - *result = string + 2; - return (2); - } - } - else { - if (n >= 1) { - *string = c & 0xff; - if (result) - *result = string + 1; - return (1); - } - } - if (result) - *result = string; - return (0); - -} - diff --git a/lib/libc/locale/isctype.c b/lib/libc/locale/isctype.c deleted file mode 100644 index 907a09efee..0000000000 --- a/lib/libc/locale/isctype.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/isctype.c,v 1.7 2000/02/08 07:43:24 obrien Exp $ - * $DragonFly: src/lib/libc/locale/Attic/isctype.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ - * - * @(#)isctype.c 8.3 (Berkeley) 2/24/94 - */ - -#include - -#undef digittoint -int -digittoint(c) - int c; -{ - return (__maskrune((c), 0xFF)); -} - -#undef isalnum -int -isalnum(c) - int c; -{ - return (__istype((c), _CTYPE_A|_CTYPE_D)); -} - -#undef isalpha -int -isalpha(c) - int c; -{ - return (__istype((c), _CTYPE_A)); -} - -#undef isascii -int -isascii(c) - int c; -{ - return (((c) & ~0x7F) == 0); -} - -#undef isblank -int -isblank(c) - int c; -{ - return (__istype((c), _CTYPE_B)); -} - -#undef iscntrl -int -iscntrl(c) - int c; -{ - return (__istype((c), _CTYPE_C)); -} - -#undef isdigit -int -isdigit(c) - int c; -{ - return (__isctype((c), _CTYPE_D)); -} - -#undef isgraph -int -isgraph(c) - int c; -{ - return (__istype((c), _CTYPE_G)); -} - -#undef ishexnumber -int -ishexnumber(c) - int c; -{ - return (__istype((c), _CTYPE_X)); -} - -#undef isideogram -int -isideogram(c) - int c; -{ - return (__istype((c), _CTYPE_I)); -} - -#undef islower -int -islower(c) - int c; -{ - return (__istype((c), _CTYPE_L)); -} - -#undef isnumber -int -isnumber(c) - int c; -{ - return (__istype((c), _CTYPE_D)); -} - -#undef isphonogram -int -isphonogram(c) - int c; -{ - return (__istype((c), _CTYPE_Q)); -} - -#undef isprint -int -isprint(c) - int c; -{ - return (__istype((c), _CTYPE_R)); -} - -#undef ispunct -int -ispunct(c) - int c; -{ - return (__istype((c), _CTYPE_P)); -} - -#undef isrune -int -isrune(c) - int c; -{ - return (__istype((c), 0xFFFFFF00L)); -} - -#undef isspace -int -isspace(c) - int c; -{ - return (__istype((c), _CTYPE_S)); -} - -#undef isspecial -int -isspecial(c) - int c; -{ - return (__istype((c), _CTYPE_T)); -} - -#undef isupper -int -isupper(c) - int c; -{ - return (__istype((c), _CTYPE_U)); -} - -#undef isxdigit -int -isxdigit(c) - int c; -{ - return (__isctype((c), _CTYPE_X)); -} - -#undef toascii -int -toascii(c) - int c; -{ - return ((c) & 0x7F); -} - -#undef tolower -int -tolower(c) - int c; -{ - return (__tolower(c)); -} - -#undef toupper -int -toupper(c) - int c; -{ - return (__toupper(c)); -} - diff --git a/lib/libc/locale/ldpart.c b/lib/libc/locale/ldpart.c deleted file mode 100644 index 0d110714b7..0000000000 --- a/lib/libc/locale/ldpart.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2000, 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/ldpart.c,v 1.7.2.3 2002/08/12 11:17:37 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/ldpart.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "setlocale.h" -#include "ldpart.h" - -static int split_lines(char *, const char *); - -int -__part_load_locale(const char *name, - int *using_locale, - char *locale_buf, - const char *category_filename, - int locale_buf_size_max, - int locale_buf_size_min, - const char **dst_localebuf) -{ - int saverr, fd, i, num_lines; - char *lbuf, *p; - const char *plim; - char filename[PATH_MAX]; - struct stat st; - size_t namesize, bufsize; - - /* 'name' must be already checked. */ - if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) { - *using_locale = 0; - return (_LDP_CACHE); - } - - /* - * If the locale name is the same as our cache, use the cache. - */ - if (locale_buf != NULL && strcmp(name, locale_buf) == 0) { - *using_locale = 1; - return (_LDP_CACHE); - } - - /* - * Slurp the locale file into the cache. - */ - namesize = strlen(name) + 1; - - /* 'PathLocale' must be already set & checked. */ - /* Range checking not needed, 'name' size is limited */ - strcpy(filename, _PathLocale); - strcat(filename, "/"); - strcat(filename, name); - strcat(filename, "/"); - strcat(filename, category_filename); - if ((fd = _open(filename, O_RDONLY)) < 0) - return (_LDP_ERROR); - if (_fstat(fd, &st) != 0) - goto bad_locale; - if (st.st_size <= 0) { - errno = EFTYPE; - goto bad_locale; - } - bufsize = namesize + st.st_size; - if ((lbuf = malloc(bufsize)) == NULL) { - errno = ENOMEM; - goto bad_locale; - } - (void)strcpy(lbuf, name); - p = lbuf + namesize; - plim = p + st.st_size; - if (_read(fd, p, (size_t) st.st_size) != st.st_size) - goto bad_lbuf; - /* - * Parse the locale file into localebuf. - */ - if (plim[-1] != '\n') { - errno = EFTYPE; - goto bad_lbuf; - } - num_lines = split_lines(p, plim); - if (num_lines >= locale_buf_size_max) - num_lines = locale_buf_size_max; - else if (num_lines >= locale_buf_size_min) - num_lines = locale_buf_size_min; - else { - errno = EFTYPE; - goto bad_lbuf; - } - (void)_close(fd); - /* - * Record the successful parse in the cache. - */ - if (locale_buf != NULL) - free(locale_buf); - locale_buf = lbuf; - for (p = locale_buf, i = 0; i < num_lines; i++) - dst_localebuf[i] = (p += strlen(p) + 1); - for (i = num_lines; i < locale_buf_size_max; i++) - dst_localebuf[i] = NULL; - *using_locale = 1; - - return (_LDP_LOADED); - -bad_lbuf: - saverr = errno; - free(lbuf); - errno = saverr; -bad_locale: - saverr = errno; - (void)_close(fd); - errno = saverr; - - return (_LDP_ERROR); -} - -static int -split_lines(char *p, const char *plim) -{ - int i; - - for (i = 0; p < plim; i++) { - p = strchr(p, '\n'); - *p++ = '\0'; - } - return (i); -} - diff --git a/lib/libc/locale/lmessages.c b/lib/libc/locale/lmessages.c deleted file mode 100644 index 575271b15c..0000000000 --- a/lib/libc/locale/lmessages.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/lmessages.c,v 1.9.2.2 2002/08/12 11:17:37 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/lmessages.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#include - -#include "lmessages.h" -#include "ldpart.h" - -#define LCMESSAGES_SIZE_FULL (sizeof(struct lc_messages_T) / sizeof(char *)) -#define LCMESSAGES_SIZE_MIN \ - (offsetof(struct lc_messages_T, yesstr) / sizeof(char *)) - -static char empty[] = ""; - -static const struct lc_messages_T _C_messages_locale = { - "^[yY]" , /* yesexpr */ - "^[nN]" , /* noexpr */ - "yes" , /* yesstr */ - "no" /* nostr */ -}; - -static struct lc_messages_T _messages_locale; -static int _messages_using_locale; -static char *_messages_locale_buf; - -int -__messages_load_locale(const char *name) -{ - int ret; - - ret = __part_load_locale(name, &_messages_using_locale, - _messages_locale_buf, "LC_MESSAGES", - LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN, - (const char **)&_messages_locale); - if (ret == _LDP_LOADED) { - if (_messages_locale.yesstr == NULL) - _messages_locale.yesstr = empty; - if (_messages_locale.nostr == NULL) - _messages_locale.nostr = empty; - } - return (ret); -} - -struct lc_messages_T * -__get_current_messages_locale(void) -{ - return (_messages_using_locale - ? &_messages_locale - : (struct lc_messages_T *)&_C_messages_locale); -} - -#ifdef LOCALE_DEBUG -void -msgdebug() { -printf( "yesexpr = %s\n" - "noexpr = %s\n" - "yesstr = %s\n" - "nostr = %s\n", - _messages_locale.yesexpr, - _messages_locale.noexpr, - _messages_locale.yesstr, - _messages_locale.nostr -); -} -#endif /* LOCALE_DEBUG */ diff --git a/lib/libc/locale/lmessages.h b/lib/libc/locale/lmessages.h deleted file mode 100644 index e46467ccee..0000000000 --- a/lib/libc/locale/lmessages.h +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * Copyright (c) 2000, 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/lmessages.h,v 1.3.2.1 2002/03/12 17:17:48 phantom Exp $ - * $DragonFly: src/lib/libc/locale/Attic/lmessages.h,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#ifndef _LMESSAGES_H_ -#define _LMESSAGES_H_ - -struct lc_messages_T { - const char *yesexpr; - const char *noexpr; - const char *yesstr; - const char *nostr; -}; - -struct lc_messages_T *__get_current_messages_locale(void); -int __messages_load_locale(const char *); - -#endif /* !_LMESSAGES_H_ */ diff --git a/lib/libc/locale/lmonetary.c b/lib/libc/locale/lmonetary.c deleted file mode 100644 index 259db5f7e1..0000000000 --- a/lib/libc/locale/lmonetary.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2000, 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/lmonetary.c,v 1.12.2.2 2002/08/12 11:17:37 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/lmonetary.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#include -#include -#include "lmonetary.h" -#include "ldpart.h" - -extern int __mlocale_changed; -extern const char * __fix_locale_grouping_str(const char *); - -#define LCMONETARY_SIZE (sizeof(struct lc_monetary_T) / sizeof(char *)) - -static char empty[] = ""; -static char numempty[] = { CHAR_MAX, '\0'}; - -static const struct lc_monetary_T _C_monetary_locale = { - empty, /* int_curr_symbol */ - empty, /* currency_symbol */ - empty, /* mon_decimal_point */ - empty, /* mon_thousands_sep */ - numempty, /* mon_grouping */ - empty, /* positive_sign */ - empty, /* negative_sign */ - numempty, /* int_frac_digits */ - numempty, /* frac_digits */ - numempty, /* p_cs_precedes */ - numempty, /* p_sep_by_space */ - numempty, /* n_cs_precedes */ - numempty, /* n_sep_by_space */ - numempty, /* p_sign_posn */ - numempty /* n_sign_posn */ -}; - -static struct lc_monetary_T _monetary_locale; -static int _monetary_using_locale; -static char *_monetary_locale_buf; - -static char -cnv(const char *str) -{ - int i = strtol(str, NULL, 10); - - if (i == -1) - i = CHAR_MAX; - return ((char)i); -} - -int -__monetary_load_locale(const char *name) -{ - int ret; - - ret = __part_load_locale(name, &_monetary_using_locale, - _monetary_locale_buf, "LC_MONETARY", - LCMONETARY_SIZE, LCMONETARY_SIZE, - (const char **)&_monetary_locale); - if (ret != _LDP_ERROR) - __mlocale_changed = 1; - if (ret == _LDP_LOADED) { - _monetary_locale.mon_grouping = - __fix_locale_grouping_str(_monetary_locale.mon_grouping); - -#define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \ - cnv(_monetary_locale.NAME)) - - M_ASSIGN_CHAR(int_frac_digits); - M_ASSIGN_CHAR(frac_digits); - M_ASSIGN_CHAR(p_cs_precedes); - M_ASSIGN_CHAR(p_sep_by_space); - M_ASSIGN_CHAR(n_cs_precedes); - M_ASSIGN_CHAR(n_sep_by_space); - M_ASSIGN_CHAR(p_sign_posn); - M_ASSIGN_CHAR(n_sign_posn); - } - return (ret); -} - -struct lc_monetary_T * -__get_current_monetary_locale(void) -{ - return (_monetary_using_locale - ? &_monetary_locale - : (struct lc_monetary_T *)&_C_monetary_locale); -} - -#ifdef LOCALE_DEBUG -void -monetdebug() { -printf( "int_curr_symbol = %s\n" - "currency_symbol = %s\n" - "mon_decimal_point = %s\n" - "mon_thousands_sep = %s\n" - "mon_grouping = %s\n" - "positive_sign = %s\n" - "negative_sign = %s\n" - "int_frac_digits = %d\n" - "frac_digits = %d\n" - "p_cs_precedes = %d\n" - "p_sep_by_space = %d\n" - "n_cs_precedes = %d\n" - "n_sep_by_space = %d\n" - "p_sign_posn = %d\n" - "n_sign_posn = %d\n", - _monetary_locale.int_curr_symbol, - _monetary_locale.currency_symbol, - _monetary_locale.mon_decimal_point, - _monetary_locale.mon_thousands_sep, - _monetary_locale.mon_grouping, - _monetary_locale.positive_sign, - _monetary_locale.negative_sign, - _monetary_locale.int_frac_digits[0], - _monetary_locale.frac_digits[0], - _monetary_locale.p_cs_precedes[0], - _monetary_locale.p_sep_by_space[0], - _monetary_locale.n_cs_precedes[0], - _monetary_locale.n_sep_by_space[0], - _monetary_locale.p_sign_posn[0], - _monetary_locale.n_sign_posn[0] -); -} -#endif /* LOCALE_DEBUG */ diff --git a/lib/libc/locale/lmonetary.h b/lib/libc/locale/lmonetary.h deleted file mode 100644 index ddc832d9c2..0000000000 --- a/lib/libc/locale/lmonetary.h +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright (c) 2000, 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/lmonetary.h,v 1.3.2.1 2002/03/12 17:17:48 phantom Exp $ - * $DragonFly: src/lib/libc/locale/Attic/lmonetary.h,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#ifndef _LMONETARY_H_ -#define _LMONETARY_H_ - -struct lc_monetary_T { - const char *int_curr_symbol; - const char *currency_symbol; - const char *mon_decimal_point; - const char *mon_thousands_sep; - const char *mon_grouping; - const char *positive_sign; - const char *negative_sign; - const char *int_frac_digits; - const char *frac_digits; - const char *p_cs_precedes; - const char *p_sep_by_space; - const char *n_cs_precedes; - const char *n_sep_by_space; - const char *p_sign_posn; - const char *n_sign_posn; -}; - -struct lc_monetary_T *__get_current_monetary_locale(void); -int __monetary_load_locale(const char *); - -#endif /* !_LMONETARY_H_ */ diff --git a/lib/libc/locale/lnumeric.c b/lib/libc/locale/lnumeric.c deleted file mode 100644 index 5b69d82e02..0000000000 --- a/lib/libc/locale/lnumeric.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2000, 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.10.2.2 2002/08/12 11:17:38 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/lnumeric.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#include -#include "lnumeric.h" -#include "ldpart.h" - -extern int __nlocale_changed; -extern const char *__fix_locale_grouping_str(const char *); - -#define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *)) - -static char numempty[] = { CHAR_MAX, '\0' }; - -static const struct lc_numeric_T _C_numeric_locale = { - ".", /* decimal_point */ - "", /* thousands_sep */ - numempty /* grouping */ -}; - -static struct lc_numeric_T _numeric_locale; -static int _numeric_using_locale; -static char *_numeric_locale_buf; - -int -__numeric_load_locale(const char *name) -{ - int ret; - - ret = __part_load_locale(name, &_numeric_using_locale, - _numeric_locale_buf, "LC_NUMERIC", - LCNUMERIC_SIZE, LCNUMERIC_SIZE, - (const char **)&_numeric_locale); - if (ret != _LDP_ERROR) - __nlocale_changed = 1; - if (ret == _LDP_LOADED) - _numeric_locale.grouping = - __fix_locale_grouping_str(_numeric_locale.grouping); - return (ret); -} - -struct lc_numeric_T * -__get_current_numeric_locale(void) -{ - return (_numeric_using_locale - ? &_numeric_locale - : (struct lc_numeric_T *)&_C_numeric_locale); -} - -#ifdef LOCALE_DEBUG -void -numericdebug(void) { -printf( "decimal_point = %s\n" - "thousands_sep = %s\n" - "grouping = %s\n", - _numeric_locale.decimal_point, - _numeric_locale.thousands_sep, - _numeric_locale.grouping -); -} -#endif /* LOCALE_DEBUG */ diff --git a/lib/libc/locale/lnumeric.h b/lib/libc/locale/lnumeric.h deleted file mode 100644 index 2ae37fa456..0000000000 --- a/lib/libc/locale/lnumeric.h +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * Copyright (c) 2000, 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/lnumeric.h,v 1.3.2.1 2002/03/12 17:17:48 phantom Exp $ - * $DragonFly: src/lib/libc/locale/Attic/lnumeric.h,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#ifndef _LNUMERIC_H_ -#define _LNUMERIC_H_ - -struct lc_numeric_T { - const char *decimal_point; - const char *thousands_sep; - const char *grouping; -}; - -struct lc_numeric_T *__get_current_numeric_locale(void); -int __numeric_load_locale(const char *); - -#endif /* !_LNUMERIC_H_ */ diff --git a/lib/libc/locale/localeconv.c b/lib/libc/locale/localeconv.c index 386640274b..0f23493ed1 100644 --- a/lib/libc/locale/localeconv.c +++ b/lib/libc/locale/localeconv.c @@ -1,51 +1,20 @@ +/* $NetBSD: src/lib/libc/locale/localeconv.c,v 1.12 2004/01/02 21:53:49 itojun Exp $ */ +/* $DragonFly: src/lib/libc/locale/localeconv.c,v 1.3 2005/04/21 16:36:34 joerg Exp $ */ + /* - * Copyright (c) 2001 Alexey Zelkin - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)localeconv.c 8.1 (Berkeley) 6/4/93 - * $FreeBSD: src/lib/libc/locale/localeconv.c,v 1.1.1.1.14.2 2002/03/12 17:17:48 phantom Exp $ - * $DragonFly: src/lib/libc/locale/localeconv.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * Written by J.T. Conklin . + * Public domain. */ +#include #include -#include "lmonetary.h" -#include "lnumeric.h" - + /* * The localeconv() function constructs a struct lconv from the current * monetary and numeric locales. * * Because localeconv() may be called many times (especially by library - * routines like printf() & strtod()), the approprate members of the + * routines like printf() & strtod()), the appropriate members of the * lconv structure are computed only when the monetary or numeric * locale has been changed. */ @@ -56,48 +25,54 @@ int __nlocale_changed = 1; * Return the current locale conversion. */ struct lconv * -localeconv() +localeconv(void) { - static struct lconv ret; - - if (__mlocale_changed) { - /* LC_MONETARY part */ - struct lc_monetary_T * mptr; - -#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME) -#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0]) - - mptr = __get_current_monetary_locale(); - M_ASSIGN_STR(int_curr_symbol); - M_ASSIGN_STR(currency_symbol); - M_ASSIGN_STR(mon_decimal_point); - M_ASSIGN_STR(mon_thousands_sep); - M_ASSIGN_STR(mon_grouping); - M_ASSIGN_STR(positive_sign); - M_ASSIGN_STR(negative_sign); - M_ASSIGN_CHAR(int_frac_digits); - M_ASSIGN_CHAR(frac_digits); - M_ASSIGN_CHAR(p_cs_precedes); - M_ASSIGN_CHAR(p_sep_by_space); - M_ASSIGN_CHAR(n_cs_precedes); - M_ASSIGN_CHAR(n_sep_by_space); - M_ASSIGN_CHAR(p_sign_posn); - M_ASSIGN_CHAR(n_sign_posn); - __mlocale_changed = 0; - } - - if (__nlocale_changed) { - /* LC_NUMERIC part */ - struct lc_numeric_T * nptr; + static struct lconv ret; -#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME) + if (__mlocale_changed) { + /* LC_MONETARY */ + ret.int_curr_symbol = _CurrentMonetaryLocale->int_curr_symbol; + ret.currency_symbol = _CurrentMonetaryLocale->currency_symbol; + ret.mon_decimal_point = + _CurrentMonetaryLocale->mon_decimal_point; + ret.mon_thousands_sep = + _CurrentMonetaryLocale->mon_thousands_sep; + ret.mon_grouping = _CurrentMonetaryLocale->mon_grouping; + ret.positive_sign = _CurrentMonetaryLocale->positive_sign; + ret.negative_sign = _CurrentMonetaryLocale->negative_sign; + ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits; + ret.frac_digits = _CurrentMonetaryLocale->frac_digits; + ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes; + ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space; + ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes; + ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space; + ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn; + ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn; + ret.int_p_cs_precedes = + _CurrentMonetaryLocale->int_p_cs_precedes; + ret.int_n_cs_precedes = + _CurrentMonetaryLocale->int_n_cs_precedes; + ret.int_p_sep_by_space = + _CurrentMonetaryLocale->int_p_sep_by_space; + ret.int_n_sep_by_space = + _CurrentMonetaryLocale->int_n_sep_by_space; + ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn; + ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn; + __mlocale_changed = 0; + } - nptr = __get_current_numeric_locale(); - N_ASSIGN_STR(decimal_point); - N_ASSIGN_STR(thousands_sep); - N_ASSIGN_STR(grouping); - __nlocale_changed = 0; - } + if (__nlocale_changed) { + /* LC_NUMERIC */ + /* LINTED const castaway */ + ret.decimal_point = + (char *)_CurrentNumericLocale->decimal_point; + /* LINTED const castaway */ + ret.thousands_sep = + (char *)_CurrentNumericLocale->thousands_sep; + /* LINTED const castaway */ + ret.grouping = (char *) _CurrentNumericLocale->grouping; + __nlocale_changed = 0; + } - return (&ret); + return(&ret); } diff --git a/lib/libc/locale/mbrune.3 b/lib/libc/locale/mbrune.3 deleted file mode 100644 index e7c61a3eb2..0000000000 --- a/lib/libc/locale/mbrune.3 +++ /dev/null @@ -1,161 +0,0 @@ -.\" Copyright (c) 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Paul Borman at Krystal Technologies. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)mbrune.3 8.2 (Berkeley) 4/19/94 -.\" $FreeBSD: src/lib/libc/locale/mbrune.3,v 1.6.2.4 2001/12/14 18:33:54 ru Exp $ -.\" $DragonFly: src/lib/libc/locale/Attic/mbrune.3,v 1.3 2005/03/24 12:48:04 swildner Exp $ -.\" -.Dd April 19, 1994 -.Dt MBRUNE 3 -.Os -.Sh NAME -.Nm mbrune , -.Nm mbrrune , -.Nm mbmb -.Nd multibyte rune support for C -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In rune.h -.Ft char * -.Fn mbrune "const char *string" "rune_t rune" -.Ft char * -.Fn mbrrune "const char *string" "rune_t rune" -.Ft char * -.Fn mbmb "const char *string" "char *pattern" -.Sh DESCRIPTION -These routines provide the corresponding functionality of -.Fn strchr , -.Fn strrchr -and -.Fn strstr -for multibyte strings. -.Pp -The -.Fn mbrune -function locates the first occurrence of -.Fn rune -in the string pointed to by -.Ar string . -The terminating -.Dv NUL -character is considered part of the string. -If -.Fa rune -is -.Ql \e0 , -.Fn mbrune -locates the terminating -.Ql \e0 . -.Pp -The -.Fn mbrrune -function -locates the last occurrence of -.Fa rune -in the string -.Fa string . -If -.Fa rune -is -.Ql \e0 , -.Fn mbrune -locates the terminating -.Ql \e0 . -.Pp -The -.Fn mbmb -function locates the first occurrence of the null-terminated string -.Fa pattern -in the null-terminated string -.Fa string . -If -.Fa pattern -is the empty string, -.Fn mbmb -returns -.Fa string ; -if -.Fa pattern -occurs nowhere in -.Fa string , -.Fn mbmb -returns -.Dv NULL ; -otherwise -.Fn mbmb -returns a pointer to the first character of the first occurrence of -.Fa pattern . -.Sh RETURN VALUES -The function -.Fn mbrune -returns a pointer to the located character, or -.Dv NULL -if the character does not appear in the string. -.Pp -The -.Fn mbrrune -function -returns a pointer to the character, or -.Dv NULL -if the character does not appear in the string. -.Pp -The -.Fn mbmb -function -returns a pointer to the -.Fa pattern , -or -.Dv NULL -if the -.Fa pattern -does not appear in the string. -.Sh "SEE ALSO -.Xr mbrune 3 , -.Xr rune 3 , -.Xr setlocale 3 , -.Xr euc 5 , -.Xr utf2 5 -.Sh HISTORY -The -.Fn mbrune , -.Fn mbrrune , -and -.Fn mbmb -functions -first appeared in Plan 9 from Bell Labs as -.Fn utfrune , -.Fn utfrrune , -and -.Fn utfutf . diff --git a/lib/libc/locale/mbrune.c b/lib/libc/locale/mbrune.c deleted file mode 100644 index 6b231e0c71..0000000000 --- a/lib/libc/locale/mbrune.c +++ /dev/null @@ -1,110 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mbrune.c 8.1 (Berkeley) 6/27/93 - */ - -#include -#include -#include -#include - -char * -mbrune(string, c) - const char *string; - rune_t c; -{ - char const *result; - rune_t r; - - while ((r = sgetrune(string, MB_LEN_MAX, &result))) { - if (r == c) - return ((char *)string); - string = result == string ? string + 1 : result; - } - - return (c == *string ? (char *)string : NULL); -} - -char * -mbrrune(string, c) - const char *string; - rune_t c; -{ - const char *last = 0; - char const *result; - rune_t r; - - while ((r = sgetrune(string, MB_LEN_MAX, &result))) { - if (r == c) - last = string; - string = result == string ? string + 1 : result; - } - return (c == *string ? (char *)string : (char *)last); -} - -char * -mbmb(string, pattern) - const char *string; - char *pattern; -{ - rune_t first, r; - size_t plen, slen; - char const *result; - - plen = strlen(pattern); - slen = strlen(string); - if (plen > slen) - return (0); - - first = sgetrune(pattern, plen, &result); - if (result == string) - return (0); - - while (slen >= plen && (r = sgetrune(string, slen, &result))) { - if (r == first) { - if (strncmp(string, pattern, slen) == 0) - return ((char *) string); - } - if (result == string) { - --slen; - ++string; - } else { - slen -= result - string; - string = result; - } - } - return (0); -} diff --git a/lib/libc/locale/mskanji.c b/lib/libc/locale/mskanji.c deleted file mode 100644 index c8046ae6f2..0000000000 --- a/lib/libc/locale/mskanji.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * ja_JP.SJIS locale table for BSD4.4/rune - * version 1.0 - * (C) Sin'ichiro MIYATANI / Phase One, Inc - * May 12, 1995 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Phase One, Inc. - * 4. The name of Phase One, Inc. may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/mskanji.c,v 1.2.8.2 2001/03/05 10:22:45 obrien Exp $ - * $DragonFly: src/lib/libc/locale/Attic/mskanji.c,v 1.4 2003/12/02 14:56:28 eirikn Exp $ - * - * @(#)mskanji.c 1.0 (Phase One) 5/5/95 - */ - -#include - -#include -#include - -rune_t _MSKanji_sgetrune (const char *, size_t, char const **); -int _MSKanji_sputrune (rune_t, char *, size_t, char **); - -int -_MSKanji_init(rl) - _RuneLocale *rl; -{ - rl->sgetrune = _MSKanji_sgetrune; - rl->sputrune = _MSKanji_sputrune; - - _CurrentRuneLocale = rl; - __mb_cur_max = 2; - return (0); -} - -rune_t -_MSKanji_sgetrune(string, n, result) - const char *string; - size_t n; - char const **result; -{ - rune_t rune = 0; - - if (n < 1 ) { - rune = _INVALID_RUNE; - } else { - rune = *( string++ ) & 0xff; - if ( ( rune > 0x80 && rune < 0xa0 ) - || ( rune >= 0xe0 && rune < 0xfa ) ) { - if ( n < 2 ) { - rune = (rune_t)_INVALID_RUNE; - --string; - } else { - rune = ( rune << 8 ) | ( *( string++ ) & 0xff ); - } - } - } - if (result) *result = string; - return rune; -} - -int -_MSKanji_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - int len, i; - - len = ( c > 0x100 ) ? 2 : 1; - if ( n < len ) { - if ( result ) *result = (char *) 0; - } else { - if ( result ) *result = string + len; - for ( i = len; i-- > 0; ) { - *( string++ ) = c >> ( i << 3 ); - } - } - return len; -} diff --git a/lib/libc/locale/multibyte.3 b/lib/libc/locale/multibyte.3 deleted file mode 100644 index f710d256ee..0000000000 --- a/lib/libc/locale/multibyte.3 +++ /dev/null @@ -1,246 +0,0 @@ -.\" Copyright (c) 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Donn Seeley of BSDI. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)multibyte.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/locale/multibyte.3,v 1.6.2.5 2001/12/14 18:33:54 ru Exp $ -.\" $DragonFly: src/lib/libc/locale/Attic/multibyte.3,v 1.3 2005/03/24 12:48:04 swildner Exp $ -.\" -.Dd June 4, 1993 -.Dt MULTIBYTE 3 -.Os -.Sh NAME -.Nm mblen , -.Nm mbstowcs , -.Nm mbtowc , -.Nm wcstombs , -.Nm wctomb -.Nd multibyte character support for C -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In stdlib.h -.Ft int -.Fn mblen "const char *mbchar" "size_t nbytes" -.Ft size_t -.Fn mbstowcs "wchar_t *wcstring" "const char *mbstring" "size_t nwchars" -.Ft int -.Fn mbtowc "wchar_t *wcharp" "const char *mbchar" "size_t nbytes" -.Ft size_t -.Fn wcstombs "char *mbstring" "const wchar_t *wcstring" "size_t nbytes" -.Ft int -.Fn wctomb "char *mbchar" "wchar_t wchar" -.Sh DESCRIPTION -The basic elements of some written natural languages such as Chinese -cannot be represented uniquely with single C -.Va char Ns s . -The C standard supports two different ways of dealing with -extended natural language encodings, -.Em wide -characters and -.Em multibyte -characters. -Wide characters are an internal representation -which allows each basic element to map -to a single object of type -.Va wchar_t . -Multibyte characters are used for input and output -and code each basic element as a sequence of C -.Va char Ns s . -Individual basic elements may map into one or more -(up to -.Dv MB_CHAR_MAX ) -bytes in a multibyte character. -.Pp -The current locale -.Pq Xr setlocale 3 -governs the interpretation of wide and multibyte characters. -The locale category -.Dv LC_CTYPE -specifically controls this interpretation. -The -.Va wchar_t -type is wide enough to hold the largest value -in the wide character representations for all locales. -.Pp -Multibyte strings may contain -.Sq shift -indicators to switch to and from -particular modes within the given representation. -If explicit bytes are used to signal shifting, -these are not recognized as separate characters -but are lumped with a neighboring character. -There is always a distinguished -.Sq initial -shift state. -The -.Fn mbstowcs -and -.Fn wcstombs -functions assume that multibyte strings are interpreted -starting from the initial shift state. -The -.Fn mblen , -.Fn mbtowc -and -.Fn wctomb -functions maintain static shift state internally. -A call with a null -.Fa mbchar -pointer returns nonzero if the current locale requires shift states, -zero otherwise; -if shift states are required, the shift state is reset to the initial state. -The internal shift states are undefined after a call to -.Fn setlocale -with the -.Dv LC_CTYPE -or -.Dv LC_ALL -categories. -.Pp -For convenience in processing, -the wide character with value 0 -(the null wide character) -is recognized as the wide character string terminator, -and the character with value 0 -(the null byte) -is recognized as the multibyte character string terminator. -Null bytes are not permitted within multibyte characters. -.Pp -The -.Fn mblen -function computes the length in bytes -of a multibyte character -.Fa mbchar . -Up to -.Fa nbytes -bytes are examined. -.Pp -The -.Fn mbtowc -function converts a multibyte character -.Fa mbchar -into a wide character and stores the result -in the object pointed to by -.Fa wcharp . -Up to -.Fa nbytes -bytes are examined. -.Pp -The -.Fn wctomb -function converts a wide character -.Fa wchar -into a multibyte character and stores -the result in -.Fa mbchar . -The object pointed to by -.Fa mbchar -must be large enough to accommodate the multibyte character. -.Pp -The -.Fn mbstowcs -function converts a multibyte character string -.Fa mbstring -into a wide character string -.Fa wcstring . -No more than -.Fa nwchars -wide characters are stored. -A terminating null wide character is appended if there is room. -.Pp -The -.Fn wcstombs -function converts a wide character string -.Fa wcstring -into a multibyte character string -.Fa mbstring . -Up to -.Fa nbytes -bytes are stored in -.Fa mbstring . -Partial multibyte characters at the end of the string are not stored. -The multibyte character string is null terminated if there is room. -.Sh "RETURN VALUES -If multibyte characters are not supported in the current locale, -all of these functions will return \-1 if characters can be processed, -otherwise 0. -.Pp -If -.Fa mbchar -is -.Dv NULL , -the -.Fn mblen , -.Fn mbtowc -and -.Fn wctomb -functions return nonzero if shift states are supported, -zero otherwise. -If -.Fa mbchar -is valid, -then these functions return -the number of bytes processed in -.Fa mbchar , -or \-1 if no multibyte character -could be recognized or converted. -.Pp -The -.Fn mbstowcs -function returns the number of wide characters converted, -not counting any terminating null wide character. -The -.Fn wcstombs -function returns the number of bytes converted, -not counting any terminating null byte. -If any invalid multibyte characters are encountered, -both functions return \-1. -.Sh "SEE ALSO -.Xr mbrune 3 , -.Xr rune 3 , -.Xr setlocale 3 , -.Xr euc 5 , -.Xr utf2 5 -.Sh STANDARDS -The -.Fn mblen , -.Fn mbstowcs , -.Fn mbtowc , -.Fn wcstombs -and -.Fn wctomb -functions conform to -.St -isoC . -.Sh BUGS -The current implementation does not support shift states. diff --git a/lib/libc/locale/nl_langinfo.c b/lib/libc/locale/nl_langinfo.c index e53c22361c..784fdca16a 100644 --- a/lib/libc/locale/nl_langinfo.c +++ b/lib/libc/locale/nl_langinfo.c @@ -1,204 +1,121 @@ -/*- - * Copyright (c) 2001 Alexey Zelkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/nl_langinfo.c,v 1.13.2.3 2002/03/12 17:23:24 phantom Exp $ - * $DragonFly: src/lib/libc/locale/nl_langinfo.c,v 1.3 2005/04/21 07:28:59 joerg Exp $ +/* $NetBSD: src/lib/libc/locale/nl_langinfo.c,v 1.10 2004/07/21 20:27:46 tshiozak Exp $ */ +/* $DragonFly: src/lib/libc/locale/nl_langinfo.c,v 1.4 2005/04/21 16:36:34 joerg Exp $ */ + +/* + * Written by J.T. Conklin . + * Public domain. */ -#include +#include #include -#include -#include -#include - -#include "../stdtime/timelocal.h" -#include "lnumeric.h" -#include "lmonetary.h" -#include "lmessages.h" - -#define TRANSITION_PERIOD_HACK - -#define _REL(BASE) ((int)item-BASE) +#include +#include +#include "rune.h" +#include "runetype.h" char * -nl_langinfo(nl_item item) { - - char *ret, *s, *cs; - static char *csym = NULL; -#ifdef TRANSITION_PERIOD_HACK - static char *cset = NULL; -#endif /* TRANSITION_PERIOD_HACK */ - - switch (item) { - case CODESET: - ret = ""; - if ((s = setlocale(LC_CTYPE, NULL)) != NULL) { - if ((cs = strchr(s, '.')) != NULL) { - ret = cs + 1; -#ifdef TRANSITION_PERIOD_HACK - if (strncmp(ret, "ISO_", 4) == 0) { - int slen = strlen(ret); +nl_langinfo(nl_item item) +{ + const char *s; - if ((cset = reallocf(cset, slen)) != NULL) { - strcpy(cset, "ISO"); - strcat(cset, ret + 4); - ret = cset; - } else - ret = ""; - } else if (strcmp(ret, "EUC") == 0) { - if (strncmp(s, "ja_JP", 5) == 0) - ret = "eucJP"; - else if (strncmp(s, "ko_KR", 5) == 0) - ret = "eucKR"; - else if (strncmp(s, "zh_CN", 5) == 0) - ret = "eucCN"; - } else if (strcmp(ret, "ASCII") == 0) - ret = "US-ASCII"; -#endif /* TRANSITION_PERIOD_HACK */ - } else if (strcmp(s, "C") == 0 || - strcmp(s, "POSIX") == 0 -#ifdef TRANSITION_PERIOD_HACK - || strstr(s, "ASCII") != NULL -#endif /* TRANSITION_PERIOD_HACK */ - ) - ret = "US-ASCII"; - } - break; + switch (item) { case D_T_FMT: - ret = (char *) __get_current_time_locale()->c_fmt; - break; + s = _CurrentTimeLocale->d_t_fmt; + break; case D_FMT: - ret = (char *) __get_current_time_locale()->x_fmt; + s = _CurrentTimeLocale->d_fmt; break; case T_FMT: - ret = (char *) __get_current_time_locale()->X_fmt; + s = _CurrentTimeLocale->t_fmt; break; case T_FMT_AMPM: - ret = (char *) __get_current_time_locale()->ampm_fmt; + s = _CurrentTimeLocale->t_fmt_ampm; break; case AM_STR: - ret = (char *) __get_current_time_locale()->am; - break; case PM_STR: - ret = (char *) __get_current_time_locale()->pm; - break; - case DAY_1: case DAY_2: case DAY_3: - case DAY_4: case DAY_5: case DAY_6: case DAY_7: - ret = (char*) __get_current_time_locale()->weekday[_REL(DAY_1)]; - break; - case ABDAY_1: case ABDAY_2: case ABDAY_3: - case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7: - ret = (char*) __get_current_time_locale()->wday[_REL(ABDAY_1)]; - break; - case MON_1: case MON_2: case MON_3: case MON_4: - case MON_5: case MON_6: case MON_7: case MON_8: - case MON_9: case MON_10: case MON_11: case MON_12: - ret = (char*) __get_current_time_locale()->month[_REL(MON_1)]; - break; - case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: - case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8: - case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12: - ret = (char*) __get_current_time_locale()->mon[_REL(ABMON_1)]; - break; - case ERA: - /* XXX: need to be implemented */ - ret = ""; - break; - case ERA_D_FMT: - /* XXX: need to be implemented */ - ret = ""; - break; - case ERA_D_T_FMT: - /* XXX: need to be implemented */ - ret = ""; - break; - case ERA_T_FMT: - /* XXX: need to be implemented */ - ret = ""; - break; - case ALT_DIGITS: - /* XXX: need to be implemented */ - ret = ""; + s = _CurrentTimeLocale->am_pm[(size_t)(item - AM_STR)]; + break; + case DAY_1: + case DAY_2: + case DAY_3: + case DAY_4: + case DAY_5: + case DAY_6: + case DAY_7: + s = _CurrentTimeLocale->day[(size_t)(item - DAY_1)]; + break; + case ABDAY_1: + case ABDAY_2: + case ABDAY_3: + case ABDAY_4: + case ABDAY_5: + case ABDAY_6: + case ABDAY_7: + s = _CurrentTimeLocale->abday[(size_t)(item - ABDAY_1)]; + break; + case MON_1: + case MON_2: + case MON_3: + case MON_4: + case MON_5: + case MON_6: + case MON_7: + case MON_8: + case MON_9: + case MON_10: + case MON_11: + case MON_12: + s = _CurrentTimeLocale->mon[(size_t)(item - MON_1)]; + break; + case ABMON_1: + case ABMON_2: + case ABMON_3: + case ABMON_4: + case ABMON_5: + case ABMON_6: + case ABMON_7: + case ABMON_8: + case ABMON_9: + case ABMON_10: + case ABMON_11: + case ABMON_12: + s = _CurrentTimeLocale->abmon[(size_t)(item - ABMON_1)]; break; case RADIXCHAR: - ret = (char*) __get_current_numeric_locale()->decimal_point; + s = _CurrentNumericLocale->decimal_point; break; case THOUSEP: - ret = (char*) __get_current_numeric_locale()->thousands_sep; + s = _CurrentNumericLocale->thousands_sep; + break; + case YESSTR: + s = _CurrentMessagesLocale->yesstr; break; case YESEXPR: - ret = (char*) __get_current_messages_locale()->yesexpr; + s = _CurrentMessagesLocale->yesexpr; + break; + case NOSTR: + s = _CurrentMessagesLocale->nostr; break; case NOEXPR: - ret = (char*) __get_current_messages_locale()->noexpr; - break; - /* - * All items marked with LEGACY are available, but not recomended - * by SUSv2 to be used in portable applications since they're subject - * to remove in future specification editions - */ - case YESSTR: /* LEGACY */ - ret = (char*) __get_current_messages_locale()->yesstr; - break; - case NOSTR: /* LEGACY */ - ret = (char*) __get_current_messages_locale()->nostr; - break; - case CRNCYSTR: - ret = ""; - cs = (char*) __get_current_monetary_locale()->currency_symbol; - if (*cs != '\0') { - char pos = localeconv()->p_cs_precedes; - - if (pos == localeconv()->n_cs_precedes) { - char psn = '\0'; - - if (pos == CHAR_MAX) { - if (strcmp(cs, __get_current_monetary_locale()->mon_decimal_point) == 0) - psn = '.'; - } else - psn = pos ? '-' : '+'; - if (psn != '\0') { - int clen = strlen(cs); - - if ((csym = reallocf(csym, clen + 2)) != NULL) { - *csym = psn; - strcpy(csym + 1, cs); - ret = csym; - } - } - } - } - break; - case D_MD_ORDER: /* local extension */ - ret = (char *) __get_current_time_locale()->md_order; + s = _CurrentMessagesLocale->noexpr; + break; + case CRNCYSTR: /* XXX */ + s = ""; + break; + case CODESET: + s = _CurrentRuneLocale->rl_codeset; + if (!s) + s = ""; break; case _DATE_FMT: /* local extension */ - ret = (char *) __get_current_time_locale()->date_fmt; + s = _CurrentTimeLocale->date_fmt; break; default: - ret = ""; - } - return (ret); + s = ""; + break; + } + + /* The return value should be really const, but the interface says OW */ + /* LINTED const castaway. */ + return((char *) s); } diff --git a/lib/libc/locale/nomacros.c b/lib/libc/locale/nomacros.c deleted file mode 100644 index 45c0db7b27..0000000000 --- a/lib/libc/locale/nomacros.c +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Tell to generate extern versions of all its inline - * functions. The extern versions get called if the system doesn't - * support inlines or the user defines _DONT_USE_CTYPE_INLINE_ - * before including . - */ -#define _EXTERNALIZE_CTYPE_INLINES_ - -#include diff --git a/lib/libc/locale/none.c b/lib/libc/locale/none.c deleted file mode 100644 index fba1ec56d6..0000000000 --- a/lib/libc/locale/none.c +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/none.c,v 1.2.8.1 2001/03/05 10:25:03 obrien Exp $ - * $DragonFly: src/lib/libc/locale/Attic/none.c,v 1.3 2003/11/12 20:21:24 eirikn Exp $ - * - * @(#)none.c 8.1 (Berkeley) 6/4/93 - */ - -#include -#include -#include -#include - -rune_t _none_sgetrune (const char *, size_t, char const **); -int _none_sputrune (rune_t, char *, size_t, char **); - -int -_none_init(rl) - _RuneLocale *rl; -{ - rl->sgetrune = _none_sgetrune; - rl->sputrune = _none_sputrune; - _CurrentRuneLocale = rl; - __mb_cur_max = 1; - return(0); -} - -rune_t -_none_sgetrune(string, n, result) - const char *string; - size_t n; - char const **result; -{ - if (n < 1) { - if (result) - *result = string; - return(_INVALID_RUNE); - } - if (result) - *result = string + 1; - return(*string & 0xff); -} - -int -_none_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - if (n >= 1) { - if (string) - *string = c; - if (result) - *result = string + 1; - } else if (result) - *result = (char *)0; - return(1); -} diff --git a/lib/libc/locale/rune.3 b/lib/libc/locale/rune.3 deleted file mode 100644 index b767d1f173..0000000000 --- a/lib/libc/locale/rune.3 +++ /dev/null @@ -1,275 +0,0 @@ -.\" Copyright (c) 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Paul Borman at Krystal Technologies. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)rune.3 8.2 (Berkeley) 12/11/93 -.\" $FreeBSD: src/lib/libc/locale/rune.3,v 1.10.2.7 2002/08/07 06:24:14 ache Exp $ -.\" $DragonFly: src/lib/libc/locale/Attic/rune.3,v 1.3 2005/03/24 12:48:04 swildner Exp $ -.\" -.Dd December 11, 1993 -.Dt RUNE 3 -.Os -.Sh NAME -.Nm setrunelocale , -.Nm setinvalidrune , -.Nm sgetrune , -.Nm sputrune , -.Nm fgetrune , -.Nm fungetrune , -.Nm fputrune -.Nd rune support for C -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In rune.h -.In errno.h -.Ft int -.Fn setrunelocale "char *locale" -.Ft void -.Fn setinvalidrune "rune_t rune" -.Ft rune_t -.Fn sgetrune "const char *string" "size_t n" "char const **result" -.Ft int -.Fn sputrune "rune_t rune" "char *string" "size_t n" "char **result" -.Pp -.In stdio.h -.Ft long -.Fn fgetrune "FILE *stream" -.Ft int -.Fn fungetrune "rune_t rune" "FILE *stream" -.Ft int -.Fn fputrune "rune_t rune" "FILE *stream" -.Sh DESCRIPTION -The -.Fn setrunelocale -controls the type of encoding used to represent runes as multibyte strings -as well as the properties of the runes as defined in -.Aq Pa ctype.h . -The -.Fa locale -argument indicates which locale to load. -If the locale is successfully loaded, -.Dv 0 -is returned, otherwise an errno value is returned to indicate the -type of error. -.Pp -The -.Fn setinvalidrune -function sets the value of the global value -.Dv _INVALID_RUNE -to be -.Fa rune . -.Pp -The -.Fn sgetrune -function tries to read a single multibyte character from -.Fa string , -which is at most -.Fa n -bytes long. -If -.Fn sgetrune -is successful, the rune is returned. -If -.Fa result -is not -.Dv NULL , -.Fa *result -will point to the first byte which was not converted in -.Fa string . -If the first -.Fa n -bytes of -.Fa string -do not describe a full multibyte character, -.Dv _INVALID_RUNE -is returned and -.Fa *result -will point to -.Fa string . -If there is an encoding error at the start of -.Fa string , -.Dv _INVALID_RUNE -is returned and -.Fa *result -will point to the second character of -.Fa string . -.Pp -the -.Fn sputrune -function tries to encode -.Fa rune -as a multibyte string and store it at -.Fa string , -but no more than -.Fa n -bytes will be stored. -If -.Fa result -is not -.Dv NULL , -.Fa *result -will be set to point to the first byte in string following the new -multibyte character. -If -.Fa string -is -.Dv NULL , -.Fa *result -will point to -.Dv "(char *)0 +" -.Fa x , -where -.Fa x -is the number of bytes that would be needed to store the multibyte value. -If the multibyte character would consist of more than -.Fa n -bytes and -.Fa result -is not -.Dv NULL , -.Fa *result -will be set to -.Dv NULL . -In all cases, -.Fn sputrune -will return the number of bytes which would be needed to store -.Fa rune -as a multibyte character. -.Pp -The -.Fn fgetrune -function operates the same as -.Fn sgetrune -with the exception that it attempts to read enough bytes from -.Fa stream -to decode a single rune. It returns either -.Dv EOF -on end of file, -.Dv _INVALID_RUNE -on an encoding error, or the rune decoded if all went well. -.Pp -The -.Fn fungetrune -function pushes the multibyte encoding, as provided by -.Fn sputrune , -of -.Fa rune -onto -.Fa stream -such that the next -.Fn fgetrune -call will return -.Fa rune . -It returns -.Dv EOF -if it fails and -.Dv 0 -on success. -.Pp -The -.Fn fputrune -function writes the multibyte encoding of -.Fa rune , -as provided by -.Fn sputrune , -onto -.Fa stream . -It returns -.Dv EOF -on failure and -.Dv 0 -on success. -.Sh RETURN VALUES -The -.Fn setrunelocale -function returns one of the following values: -.Bl -tag -width Er -.It Er 0 -.Fn setrunelocale -was successful. -.It Bq Er EINVAL -.Fa locale -name was incorrect. -.It Bq Er ENOENT -The locale could not be found. -.It Bq Er EFTYPE -The file found was not a valid file. -.El -.Pp -The -.Fn sgetrune -function either returns the rune read or -.Dv _INVALID_RUNE . -The -.Fn sputrune -function returns the number of bytes needed to store -.Fa rune -as a multibyte string. -.Sh FILES -.Bl -tag -width /usr/share/locale/locale/LC_CTYPE -compact -.It Pa $PATH_LOCALE/ Ns Em locale Ns /LC_CTYPE -.It Pa /usr/share/locale/ Ns Em locale Ns /LC_CTYPE -binary LC_CTYPE file for the locale -.Em locale . -.El -.Sh SEE ALSO -.Xr mbrune 3 , -.Xr setlocale 3 , -.Xr euc 5 , -.Xr utf2 5 -.Sh NOTES -The ANSI C type -.Em wchar_t -is the same as -.Em rune_t . -.Em Rune_t -was chosen to accent the purposeful choice of not basing the -system with the ANSI C -primitives, which were, shall we say, less aesthetic. -.Sh HISTORY -These functions first appeared in -.Bx 4.4 . -.Pp -The -.Fn setrunelocale -function and the other non-ANSI rune functions were inspired by -.Sy "Plan 9 from Bell Labs" -as a much more sane alternative to the ANSI multibyte and -wide character support. -.\"They were conceived at the San Diego 1993 Summer USENIX conference by -.\"Paul Borman of Krystal Technologies, Keith Bostic of CSRG and Andrew Hume -.\"of Bell Labs. -.Pp -All of the ANSI multibyte and wide character -support functions are built using the rune functions. diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index 951fd4681b..9de061e206 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -1,3 +1,32 @@ +/* $NetBSD: src/lib/libc/locale/rune.c,v 1.26 2004/05/09 11:26:33 kleink Exp $ */ +/* $DragonFly: src/lib/libc/locale/rune.c,v 1.4 2005/04/21 16:36:34 joerg Exp $ + +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -13,11 +42,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -32,163 +57,421 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)rune.c 8.1 (Berkeley) 6/4/93 - * $FreeBSD: src/lib/libc/locale/rune.c,v 1.5.8.2 2002/08/12 11:17:38 ache Exp $ - * $DragonFly: src/lib/libc/locale/rune.c,v 1.3 2005/01/31 22:29:31 dillon Exp $ */ -#include "namespace.h" -#include +#include +#include +#include #include -#include #include -#include #include -#include -#include -#include "un-namespace.h" +#include +#include -_RuneLocale * -_Read_RuneMagi(fp) - FILE *fp; +#include + +#include "../citrus/citrus_module.h" +#include "../citrus/citrus_ctype.h" +#include "rune.h" +#include "rune_local.h" + +static int readrange(_RuneLocale *, _RuneRange *, _FileRuneRange *, + void *, FILE *); +static void _freeentry(_RuneRange *); +static void _wctype_init(_RuneLocale *rl); + +static int +readrange(_RuneLocale *rl, _RuneRange *rr, _FileRuneRange *frr, void *lastp, + FILE *fp) { - char *data; - void *lastp; - _RuneLocale *rl; - _RuneEntry *rr; - struct stat sb; - int x, saverr; + uint32_t i; + _RuneEntry *re; + _FileRuneEntry fre; + + _DIAGASSERT(rl != NULL); + _DIAGASSERT(rr != NULL); + _DIAGASSERT(frr != NULL); + _DIAGASSERT(lastp != NULL); + _DIAGASSERT(fp != NULL); - if (_fstat(fileno(fp), &sb) < 0) - return (NULL); + re = (_RuneEntry *)rl->rl_variable; - if (sb.st_size < sizeof(_RuneLocale)) { - errno = EFTYPE; - return (NULL); + rr->rr_nranges = ntohl(frr->frr_nranges); + if (rr->rr_nranges == 0) { + rr->rr_rune_ranges = NULL; + return(0); } - if ((data = malloc(sb.st_size)) == NULL) - return (NULL); + rr->rr_rune_ranges = re; + for (i = 0; i < rr->rr_nranges; i++) { + if (fread(&fre, sizeof(fre), 1, fp) != 1) + return(-1); - errno = 0; - rewind(fp); /* Someone might have read the magic number once already */ - if (errno) { - saverr = errno; - free(data); - errno = saverr; - return (NULL); - } + re->re_min = ntohl((uint32_t)fre.fre_min); + re->re_max = ntohl((uint32_t)fre.fre_max); + re->re_map = ntohl((uint32_t)fre.fre_map); + re++; - if (fread(data, sb.st_size, 1, fp) != 1) { - saverr = errno; - free(data); - errno = saverr; - return (NULL); + if ((void *)re > lastp) + return(-1); } + rl->rl_variable = re; + return(0); +} - rl = (_RuneLocale *)data; - lastp = data + sb.st_size; +static int +readentry(_RuneRange *rr, FILE *fp) +{ + _RuneEntry *re; + size_t l, i, j; + int error; - rl->variable = rl + 1; + _DIAGASSERT(rr != NULL); + _DIAGASSERT(fp != NULL); - if (memcmp(rl->magic, _RUNE_MAGIC_1, sizeof(rl->magic))) { - free(data); - errno = EFTYPE; - return (NULL); + re = rr->rr_rune_ranges; + for (i = 0; i < rr->rr_nranges; i++) { + if (re[i].re_map != 0) { + re[i].re_rune_types = NULL; + continue; + } + + l = re[i].re_max - re[i].re_min + 1; + re[i].re_rune_types = malloc(l * sizeof(_RuneType)); + if (!re[i].re_rune_types) { + error = ENOMEM; + goto fail; + } + memset(re[i].re_rune_types, 0, l * sizeof(_RuneType)); + + if (fread(re[i].re_rune_types, sizeof(_RuneType), l, fp) != l) + goto fail2; + + for (j = 0; j < l; j++) + re[i].re_rune_types[j] = ntohl(re[i].re_rune_types[j]); } + return(0); - rl->invalid_rune = ntohl(rl->invalid_rune); - rl->variable_len = ntohl(rl->variable_len); - rl->runetype_ext.nranges = ntohl(rl->runetype_ext.nranges); - rl->maplower_ext.nranges = ntohl(rl->maplower_ext.nranges); - rl->mapupper_ext.nranges = ntohl(rl->mapupper_ext.nranges); +fail: + for (j = 0; j < i; j++) { + free(re[j].re_rune_types); + re[j].re_rune_types = NULL; + } + return(error); - for (x = 0; x < _CACHED_RUNES; ++x) { - rl->runetype[x] = ntohl(rl->runetype[x]); - rl->maplower[x] = ntohl(rl->maplower[x]); - rl->mapupper[x] = ntohl(rl->mapupper[x]); +fail2: + for (j = 0; j <= i; j++) { + free(re[j].re_rune_types); + re[j].re_rune_types = NULL; } + return(errno); +} + +/* XXX: temporary implementation */ +static void +find_codeset(_RuneLocale *rl) +{ + char *top, *codeset, *tail, *ep; - rl->runetype_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->runetype_ext.ranges + rl->runetype_ext.nranges; - if (rl->variable > lastp) { - free(data); - errno = EFTYPE; - return (NULL); + /* end of rl_variable region */ + ep = (char *)rl->rl_variable; + ep += rl->rl_variable_len; + rl->rl_codeset = NULL; + if (!(top = strstr(rl->rl_variable, _RUNE_CODESET))) + return; + tail = strpbrk(top, " \t"); + codeset = top + sizeof(_RUNE_CODESET) - 1; + if (tail) { + *top = *tail; + *tail = '\0'; + rl->rl_codeset = strdup(codeset); + strlcpy(top + 1, tail + 1, (unsigned)(ep - (top + 1))); + } else { + *top = '\0'; + rl->rl_codeset = strdup(codeset); } +} + +static void +_freeentry(_RuneRange *rr) +{ + _RuneEntry *re; + uint32_t i; - rl->maplower_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->maplower_ext.ranges + rl->maplower_ext.nranges; - if (rl->variable > lastp) { - free(data); - errno = EFTYPE; - return (NULL); + _DIAGASSERT(rr != NULL); + + re = rr->rr_rune_ranges; + for (i = 0; i < rr->rr_nranges; i++) { + if (re[i].re_rune_types) + free(re[i].re_rune_types); + re[i].re_rune_types = NULL; } +} + +void +_wctype_init(_RuneLocale *rl) +{ + memcpy(&rl->rl_wctype, &_DefaultRuneLocale.rl_wctype, + sizeof(rl->rl_wctype)); +} + + +_RuneLocale * +_Read_RuneMagi(FILE *fp) +{ + /* file */ + _FileRuneLocale frl; + /* host data */ + char *hostdata; + size_t hostdatalen; + void *lastp; + _RuneLocale *rl; + struct stat sb; + int x; + + _DIAGASSERT(fp != NULL); + + if (fstat(fileno(fp), &sb) < 0) + return(NULL); + + if (sb.st_size < sizeof(_FileRuneLocale)) + return(NULL); + /* XXX more validation? */ + + /* Someone might have read the magic number once already */ + rewind(fp); + + if (fread(&frl, sizeof(frl), 1, fp) != 1) + return(NULL); + if (memcmp(frl.frl_magic, _RUNE_MAGIC_1, sizeof(frl.frl_magic))) + return(NULL); + + hostdatalen = sizeof(*rl) + ntohl((u_int32_t)frl.frl_variable_len) + + ntohl(frl.frl_runetype_ext.frr_nranges) * sizeof(_RuneEntry) + + ntohl(frl.frl_maplower_ext.frr_nranges) * sizeof(_RuneEntry) + + ntohl(frl.frl_mapupper_ext.frr_nranges) * sizeof(_RuneEntry); - rl->mapupper_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->mapupper_ext.ranges + rl->mapupper_ext.nranges; - if (rl->variable > lastp) { - free(data); - errno = EFTYPE; - return (NULL); + if ((hostdata = malloc(hostdatalen)) == NULL) + return(NULL); + memset(hostdata, 0, hostdatalen); + lastp = hostdata + hostdatalen; + + rl = (_RuneLocale *)(void *)hostdata; + rl->rl_variable = rl + 1; + + memcpy(rl->rl_magic, frl.frl_magic, sizeof(rl->rl_magic)); + memcpy(rl->rl_encoding, frl.frl_encoding, sizeof(rl->rl_encoding)); + + rl->rl_invalid_rune = ntohl((u_int32_t)frl.frl_invalid_rune); + rl->rl_variable_len = ntohl((u_int32_t)frl.frl_variable_len); + + for (x = 0; x < _CACHED_RUNES; ++x) { + rl->rl_runetype[x] = ntohl(frl.frl_runetype[x]); + + /* XXX assumes rune_t = u_int32_t */ + rl->rl_maplower[x] = ntohl((uint32_t)frl.frl_maplower[x]); + rl->rl_mapupper[x] = ntohl((uint32_t)frl.frl_mapupper[x]); } - for (x = 0; x < rl->runetype_ext.nranges; ++x) { - rr = rl->runetype_ext.ranges; + if (readrange(rl, &rl->rl_runetype_ext, &frl.frl_runetype_ext, + lastp, fp)) { + free(hostdata); + return(NULL); + } + if (readrange(rl, &rl->rl_maplower_ext, &frl.frl_maplower_ext, + lastp, fp)) { + free(hostdata); + return(NULL); + } + if (readrange(rl, &rl->rl_mapupper_ext, &frl.frl_mapupper_ext, + lastp, fp)) { + free(hostdata); + return(NULL); + } - rr[x].min = ntohl(rr[x].min); - rr[x].max = ntohl(rr[x].max); - if ((rr[x].map = ntohl(rr[x].map)) == 0) { - int len = rr[x].max - rr[x].min + 1; - rr[x].types = rl->variable; - rl->variable = rr[x].types + len; - if (rl->variable > lastp) { - free(data); - errno = EFTYPE; - return (NULL); - } - while (len-- > 0) - rr[x].types[len] = ntohl(rr[x].types[len]); - } else - rr[x].types = 0; + if (readentry(&rl->rl_runetype_ext, fp) != 0) { + free(hostdata); + return(NULL); } - for (x = 0; x < rl->maplower_ext.nranges; ++x) { - rr = rl->maplower_ext.ranges; + if ((uint8_t *)rl->rl_variable + rl->rl_variable_len > + (uint8_t *)lastp) { + _freeentry(&rl->rl_runetype_ext); + free(hostdata); + return(NULL); + } + if (rl->rl_variable_len == 0) + rl->rl_variable = NULL; + else if (fread(rl->rl_variable, rl->rl_variable_len, 1, fp) != 1) { + _freeentry(&rl->rl_runetype_ext); + free(hostdata); + return(NULL); + } + find_codeset(rl); + _wctype_init(rl); - rr[x].min = ntohl(rr[x].min); - rr[x].max = ntohl(rr[x].max); - rr[x].map = ntohl(rr[x].map); + /* error if we have junk at the tail */ + if (ftell(fp) != sb.st_size) { + _freeentry(&rl->rl_runetype_ext); + free(hostdata); + return(NULL); } - for (x = 0; x < rl->mapupper_ext.nranges; ++x) { - rr = rl->mapupper_ext.ranges; + return(rl); +} + +void +_NukeRune(_RuneLocale *rl) +{ + _DIAGASSERT(rl != NULL); - rr[x].min = ntohl(rr[x].min); - rr[x].max = ntohl(rr[x].max); - rr[x].map = ntohl(rr[x].map); + if (rl != &_DefaultRuneLocale) { + _freeentry(&rl->rl_runetype_ext); + if (rl->rl_codeset != NULL) + free(rl->rl_codeset); + if (rl->rl_citrus_ctype) + _citrus_ctype_close(rl->rl_citrus_ctype); + free(rl); } - if (((char *)rl->variable) + rl->variable_len > (char *)lastp) { - free(data); - errno = EFTYPE; - return (NULL); +} + +/* + * read in old LC_CTYPE declaration file, convert into runelocale info + */ +#define _CTYPE_PRIVATE +#include +#include + +_RuneLocale * +_Read_CTypeAsRune(fp) + FILE *fp; +{ + char id[sizeof(_CTYPE_ID) - 1]; + uint32_t i, len; + uint16_t *new_ctype = NULL; + int16_t *new_toupper = NULL, *new_tolower = NULL; + /* host data */ + char *hostdata = NULL; + size_t hostdatalen; + _RuneLocale *rl; + struct stat sb; + int x; + + _DIAGASSERT(fp != NULL); + + if (fstat(fileno(fp), &sb) < 0) + return(NULL); + + if (sb.st_size < sizeof(id)) + return(NULL); + /* XXX more validation? */ + + /* Someone might have read the magic number once already */ + rewind(fp); + + if (fread(id, sizeof(id), 1, fp) != 1) + goto bad; + if (memcmp(id, _CTYPE_ID, sizeof(id)) != 0) + goto bad; + + if (fread(&i, sizeof(uint32_t), 1, fp) != 1) + goto bad; + if ((i = ntohl(i)) != _CTYPE_REV) + goto bad; + + if (fread(&len, sizeof(uint32_t), 1, fp) != 1) + goto bad; + if ((len = ntohl(len)) != _CTYPE_NUM_CHARS) + goto bad; + + if ((new_ctype = malloc(sizeof(uint8_t) * (1 + len))) == NULL || + (new_toupper = malloc(sizeof(int16_t) * (1 + len))) == NULL || + (new_tolower = malloc(sizeof(int16_t) * (1 + len))) == NULL) + goto bad; + new_ctype[0] = 0; + if (fread(&new_ctype[1], sizeof(uint8_t), len, fp) != len) + goto bad; + new_toupper[0] = EOF; + if (fread(&new_toupper[1], sizeof(int16_t), len, fp) != len) + goto bad; + new_tolower[0] = EOF; + if (fread(&new_tolower[1], sizeof(int16_t), len, fp) != len) + goto bad; + + hostdatalen = sizeof(*rl); + + if ((hostdata = malloc(hostdatalen)) == NULL) + goto bad; + memset(hostdata, 0, hostdatalen); + rl = (_RuneLocale *)(void *)hostdata; + rl->rl_variable = NULL; + + memcpy(rl->rl_magic, _RUNE_MAGIC_1, sizeof(rl->rl_magic)); + memcpy(rl->rl_encoding, "NONE", 4); + + rl->rl_invalid_rune = _DefaultRuneLocale.rl_invalid_rune; /*XXX*/ + rl->rl_variable_len = 0; + + for (x = 0; x < _CACHED_RUNES; ++x) { + if ((uint32_t) x > len) + continue; + + /* + * TWEAKS! + * - _X and _CTYPE_X have negligible difference in meaning. + * - we don't set digit value, fearing that it would be + * too much of hardcoding. we may need to revisit it. + */ + + if (new_ctype[1 + x] & _U) + rl->rl_runetype[x] |= _CTYPE_U; + if (new_ctype[1 + x] & _L) + rl->rl_runetype[x] |= _CTYPE_L; + if (new_ctype[1 + x] & _N) + rl->rl_runetype[x] |= _CTYPE_D; + if (new_ctype[1 + x] & _S) + rl->rl_runetype[x] |= _CTYPE_S; + if (new_ctype[1 + x] & _P) + rl->rl_runetype[x] |= _CTYPE_P; + if (new_ctype[1 + x] & _C) + rl->rl_runetype[x] |= _CTYPE_C; + /* derived flag bits, duplicate of ctype.h */ + if (new_ctype[1 + x] & (_U | _L)) + rl->rl_runetype[x] |= _CTYPE_A; + if (new_ctype[1 + x] & (_N | _X)) + rl->rl_runetype[x] |= _CTYPE_X; + if (new_ctype[1 + x] & (_P|_U|_L|_N)) + rl->rl_runetype[x] |= _CTYPE_G; + if (new_ctype[1 + x] & _B) + rl->rl_runetype[x] |= _CTYPE_B; + if ((new_ctype[1 + x] & (_P|_U|_L|_N|_B)) || x == ' ') + rl->rl_runetype[x] |= (_CTYPE_R | _CTYPE_SW1); + + /* XXX may fail on non-8bit encoding only */ + rl->rl_mapupper[x] = ntohs(new_toupper[1 + x]); + rl->rl_maplower[x] = ntohs(new_tolower[1 + x]); } + _wctype_init(rl); + /* - * Go out and zero pointers that should be zero. + * __runetable_to_netbsd_ctype() will be called from + * setlocale.c:loadlocale(), and fill old ctype table. */ - if (!rl->variable_len) - rl->variable = 0; - - if (!rl->runetype_ext.nranges) - rl->runetype_ext.ranges = 0; - - if (!rl->maplower_ext.nranges) - rl->maplower_ext.ranges = 0; - if (!rl->mapupper_ext.nranges) - rl->mapupper_ext.ranges = 0; + free(new_ctype); + free(new_toupper); + free(new_tolower); + return(rl); - return (rl); +bad: + if (new_ctype) + free(new_ctype); + if (new_toupper) + free(new_toupper); + if (new_tolower) + free(new_tolower); + if (hostdata) + free(hostdata); + return(NULL); } diff --git a/include/rune.h b/lib/libc/locale/rune.h similarity index 50% rename from include/rune.h rename to lib/libc/locale/rune.h index 3701bb7da2..c101e1847d 100644 --- a/include/rune.h +++ b/lib/libc/locale/rune.h @@ -1,3 +1,6 @@ +/* $NetBSD: src/lib/libc/locale/rune.h,v 1.9 2003/08/07 16:43:04 agc Exp $ */ +/* $DragonFly: src/lib/libc/locale/rune.h,v 1.1 2005/04/21 16:36:34 joerg Exp $ */ + /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -13,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -34,34 +33,66 @@ * SUCH DAMAGE. * * @(#)rune.h 8.1 (Berkeley) 6/27/93 - * $DragonFly: src/include/Attic/rune.h,v 1.2 2003/11/14 01:01:43 dillon Exp $ */ #ifndef _RUNE_H_ #define _RUNE_H_ -#include #include +#include +#include "runetype.h" -#define _PATH_LOCALE "/usr/share/locale" +/* + * map _RTYPE_x to _CTYPE_x + * + * XXX: these should be defined in ctype.h and used in isxxx macros. + * (note: current isxxx macros use "old" NetBSD masks and + * _CTYPE_x are not public.) + */ +#define _CTYPE_A _RUNETYPE_A +#define _CTYPE_C _RUNETYPE_C +#define _CTYPE_D _RUNETYPE_D +#define _CTYPE_G _RUNETYPE_G +#define _CTYPE_L _RUNETYPE_L +#define _CTYPE_P _RUNETYPE_P +#define _CTYPE_S _RUNETYPE_S +#define _CTYPE_U _RUNETYPE_U +#define _CTYPE_X _RUNETYPE_X +#define _CTYPE_B _RUNETYPE_B +#define _CTYPE_R _RUNETYPE_R +#define _CTYPE_I _RUNETYPE_I +#define _CTYPE_T _RUNETYPE_T +#define _CTYPE_Q _RUNETYPE_Q +#define _CTYPE_SWM _RUNETYPE_SWM +#define _CTYPE_SWS _RUNETYPE_SWS +#define _CTYPE_SW0 _RUNETYPE_SW0 +#define _CTYPE_SW1 _RUNETYPE_SW1 +#define _CTYPE_SW2 _RUNETYPE_SW2 +#define _CTYPE_SW3 _RUNETYPE_SW3 -#define _INVALID_RUNE _CurrentRuneLocale->invalid_rune +/* + * Other namespace conversion. + */ -#define __sgetrune _CurrentRuneLocale->sgetrune -#define __sputrune _CurrentRuneLocale->sputrune +#define rune_t __nbrune_t +#define _RUNE_ISCACHED _NB_RUNE_ISCACHED +#define _CACHED_RUNES _NB_CACHED_RUNES +#define _DEFAULT_INVALID_RUNE _NB_DEFAULT_INVALID_RUNE +#define _RuneEntry _NBRuneEntry +#define _RuneRange _NBRuneRange +#define _RuneLocale _NBRuneLocale +#define _RUNE_MAGIC_1 _NB_RUNE_MAGIC_1 +#define _RUNE_MODULE_1 _NB_RUNE_MODULE_1 +#define _RUNE_CODESET _NB_RUNE_CODESET -#define sgetrune(s, n, r) (*__sgetrune)((s), (n), (r)) -#define sputrune(c, s, n, r) (*__sputrune)((c), (s), (n), (r)) +/* + * global variables + */ +extern size_t __mb_len_max_runtime; +#define __MB_LEN_MAX_RUNTIME __mb_len_max_runtime -__BEGIN_DECLS -char *mbrune (const char *, rune_t); -char *mbrrune (const char *, rune_t); -char *mbmb (const char *, char *); -long fgetrune (FILE *); -int fputrune (rune_t, FILE *); -int fungetrune (rune_t, FILE *); -int setrunelocale (char *); -void setinvalidrune (rune_t); -__END_DECLS +extern _RuneLocale _DefaultRuneLocale; +extern _RuneLocale *_CurrentRuneLocale; +extern const char *_PathLocale; #endif /*! _RUNE_H_ */ diff --git a/lib/libc/locale/ldpart.h b/lib/libc/locale/rune_local.h similarity index 63% rename from lib/libc/locale/ldpart.h rename to lib/libc/locale/rune_local.h index 561e4c70bf..bd9b364d41 100644 --- a/lib/libc/locale/ldpart.h +++ b/lib/libc/locale/rune_local.h @@ -1,5 +1,8 @@ +/* $NetBSD: src/lib/libc/locale/rune_local.h,v 1.7 2003/03/02 22:18:15 tshiozak Exp $ */ +/* $DragonFly: src/lib/libc/locale/rune_local.h,v 1.1 2005/04/21 16:36:34 joerg Exp $ */ + /*- - * Copyright (c) 2000, 2001 Alexey Zelkin + * Copyright (c) 2000 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,19 +25,31 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/ldpart.h,v 1.4.2.2 2002/08/12 11:17:37 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/ldpart.h,v 1.2 2003/06/17 04:26:44 dillon Exp $ */ -#ifndef _LDPART_H_ -#define _LDPART_H_ +#ifndef _RUNE_LOCAL_H_ +#define _RUNE_LOCAL_H_ + +/* rune.c */ +_RuneLocale *_Read_RuneMagi(FILE *fp); +_RuneLocale *_Read_CTypeAsRune(FILE *fp); +void _NukeRune(_RuneLocale *); + +/* setrunelocale.c */ +int _xpg4_setrunelocale(const char *); +_RuneLocale *_findrunelocale(char *); +int _newrunelocale(char *); + +/* runeglue.c */ +int __runetable_to_netbsd_ctype(const char *); + +/* ___runetype_mb.c */ +_RuneType ___runetype_mb(wint_t); -#define _LDP_LOADED 0 -#define _LDP_ERROR (-1) -#define _LDP_CACHE 1 +/* ___tolower_mb.c */ +wint_t ___tolower_mb(wint_t); -int __part_load_locale(const char *, int*, char *, const char *, - int, int, const char **); +/* ___toupper_mb.c */ +wint_t ___toupper_mb(wint_t); -#endif /* !_LDPART_H_ */ +#endif diff --git a/lib/libc/locale/runetype.c b/lib/libc/locale/runetype.c deleted file mode 100644 index 1ddb880a21..0000000000 --- a/lib/libc/locale/runetype.c +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/runetype.c,v 1.5.8.1 2000/06/04 21:47:39 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/runetype.c,v 1.3 2003/11/09 02:34:01 dillon Exp $ - */ - -#include -#include - -unsigned long -___runetype(__ct_rune_t c) -{ - int x; - _RuneRange *rr = &_CurrentRuneLocale->runetype_ext; - _RuneEntry *re = rr->ranges; - - if (c < 0 || c == EOF) - return(0L); - - for (x = 0; x < rr->nranges; ++x, ++re) { - if (c < re->min) - return(0L); - if (c <= re->max) { - if (re->types) - return(re->types[c - re->min]); - else - return(re->map); - } - } - - return(0L); -} diff --git a/lib/libc/locale/runetype.h b/lib/libc/locale/runetype.h new file mode 100644 index 0000000000..9019fd9eda --- /dev/null +++ b/lib/libc/locale/runetype.h @@ -0,0 +1,221 @@ +/* $NetBSD: src/lib/libc/locale/runetype.h,v 1.18 2003/08/07 16:43:04 agc Exp $ */ +/* $DragonFly: src/lib/libc/locale/runetype.h,v 1.1 2005/04/21 16:36:34 joerg Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)runetype.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _NB_RUNETYPE_H_ +#define _NB_RUNETYPE_H_ + +#include + +#ifndef UINT32_C +/* assumes sizeof(unsigned int)>=4 */ +#define UINT32_C(c) ((uint32_t)(c##U)) +#endif + +typedef uint32_t __nbrune_t; +typedef uint64_t __runepad_t; + +#define _NB_CACHED_RUNES (1 << 8) /* Must be a power of 2 */ +#define _NB_RUNE_ISCACHED(c) ((c) >= 0 && (c) < _CACHED_RUNES) + +#define _NB_DEFAULT_INVALID_RUNE ((__nbrune_t)(-3)) + +/* + * The lower 8 bits of runetype[] contain the digit value of the rune. + */ +typedef uint32_t _RuneType; +#define _RUNETYPE_A UINT32_C(0x00000100) /* Alpha */ +#define _RUNETYPE_C UINT32_C(0x00000200) /* Control */ +#define _RUNETYPE_D UINT32_C(0x00000400) /* Digit */ +#define _RUNETYPE_G UINT32_C(0x00000800) /* Graph */ +#define _RUNETYPE_L UINT32_C(0x00001000) /* Lower */ +#define _RUNETYPE_P UINT32_C(0x00002000) /* Punct */ +#define _RUNETYPE_S UINT32_C(0x00004000) /* Space */ +#define _RUNETYPE_U UINT32_C(0x00008000) /* Upper */ +#define _RUNETYPE_X UINT32_C(0x00010000) /* X digit */ +#define _RUNETYPE_B UINT32_C(0x00020000) /* Blank */ +#define _RUNETYPE_R UINT32_C(0x00040000) /* Print */ +#define _RUNETYPE_I UINT32_C(0x00080000) /* Ideogram */ +#define _RUNETYPE_T UINT32_C(0x00100000) /* Special */ +#define _RUNETYPE_Q UINT32_C(0x00200000) /* Phonogram */ +#define _RUNETYPE_SWM UINT32_C(0xc0000000)/* Mask to get screen width data */ +#define _RUNETYPE_SWS 30 /* Bits to shift to get width */ +#define _RUNETYPE_SW0 UINT32_C(0x00000000) /* 0 width character */ +#define _RUNETYPE_SW1 UINT32_C(0x40000000) /* 1 width character */ +#define _RUNETYPE_SW2 UINT32_C(0x80000000) /* 2 width character */ +#define _RUNETYPE_SW3 UINT32_C(0xc0000000) /* 3 width character */ + + +/* + * rune file format. network endian. + */ +typedef struct { + int32_t fre_min; /* First rune of the range */ + int32_t fre_max; /* Last rune (inclusive) of the range */ + int32_t fre_map; /* What first maps to in maps */ + uint32_t fre_pad1; /* backward compatibility */ + __runepad_t fre_pad2; /* backward compatibility */ +} __packed _FileRuneEntry; + + +typedef struct { + uint32_t frr_nranges; /* Number of ranges stored */ + uint32_t frr_pad1; /* backward compatibility */ + __runepad_t frr_pad2; /* backward compatibility */ +} __packed _FileRuneRange; + + +typedef struct { + char frl_magic[8]; /* Magic saying what version we are */ + char frl_encoding[32];/* ASCII name of this encoding */ + + __runepad_t frl_pad1; /* backward compatibility */ + __runepad_t frl_pad2; /* backward compatibility */ + int32_t frl_invalid_rune; + uint32_t frl_pad3; /* backward compatibility */ + + _RuneType frl_runetype[_NB_CACHED_RUNES]; + int32_t frl_maplower[_NB_CACHED_RUNES]; + int32_t frl_mapupper[_NB_CACHED_RUNES]; + + /* + * The following are to deal with Runes larger than _CACHED_RUNES - 1. + * Their data is actually contiguous with this structure so as to make + * it easier to read/write from/to disk. + */ + _FileRuneRange frl_runetype_ext; + _FileRuneRange frl_maplower_ext; + _FileRuneRange frl_mapupper_ext; + + __runepad_t frl_pad4; /* backward compatibility */ + int32_t frl_variable_len;/* how long that data is */ + uint32_t frl_pad5; /* backward compatibility */ + + /* variable size data follows */ +} __packed _FileRuneLocale; + + +/* + * expanded rune locale declaration. local to the host. host endian. + */ +typedef struct { + __nbrune_t re_min; /* First rune of the range */ + __nbrune_t re_max; /* Last rune (inclusive) of the range */ + __nbrune_t re_map; /* What first maps to in maps */ + _RuneType *re_rune_types; /* Array of types in range */ +} _NBRuneEntry; + + +typedef struct { + uint32_t rr_nranges; /* Number of ranges stored */ + _NBRuneEntry *rr_rune_ranges; +} _NBRuneRange; + + +/* + * wctrans stuffs. + */ +typedef struct _WCTransEntry { + const char *te_name; + __nbrune_t *te_cached; + _NBRuneRange *te_extmap; +} _WCTransEntry; +#define _WCTRANS_INDEX_LOWER 0 +#define _WCTRANS_INDEX_UPPER 1 +#define _WCTRANS_NINDEXES 2 + +/* + * wctype stuffs. + */ +typedef struct _WCTypeEntry { + const char *te_name; + _RuneType te_mask; +} _WCTypeEntry; +#define _WCTYPE_INDEX_ALNUM 0 +#define _WCTYPE_INDEX_ALPHA 1 +#define _WCTYPE_INDEX_BLANK 2 +#define _WCTYPE_INDEX_CNTRL 3 +#define _WCTYPE_INDEX_DIGIT 4 +#define _WCTYPE_INDEX_GRAPH 5 +#define _WCTYPE_INDEX_LOWER 6 +#define _WCTYPE_INDEX_PRINT 7 +#define _WCTYPE_INDEX_PUNCT 8 +#define _WCTYPE_INDEX_SPACE 9 +#define _WCTYPE_INDEX_UPPER 10 +#define _WCTYPE_INDEX_XDIGIT 11 +#define _WCTYPE_NINDEXES 12 + +/* + * ctype stuffs + */ + +typedef struct _NBRuneLocale { + /* + * copied from _FileRuneLocale + */ + char rl_magic[8]; /* Magic saying what version we are */ + char rl_encoding[32];/* ASCII name of this encoding */ + __nbrune_t rl_invalid_rune; + _RuneType rl_runetype[_NB_CACHED_RUNES]; + __nbrune_t rl_maplower[_NB_CACHED_RUNES]; + __nbrune_t rl_mapupper[_NB_CACHED_RUNES]; + _NBRuneRange rl_runetype_ext; + _NBRuneRange rl_maplower_ext; + _NBRuneRange rl_mapupper_ext; + + void *rl_variable; + size_t rl_variable_len; + + /* + * the following portion is generated on the fly + */ + char *rl_codeset; + struct _citrus_ctype_rec *rl_citrus_ctype; + _WCTransEntry rl_wctrans[_WCTRANS_NINDEXES]; + _WCTypeEntry rl_wctype[_WCTYPE_NINDEXES]; +} _NBRuneLocale; + + +/* magic number for LC_CTYPE (rune)locale declaration */ +#define _NB_RUNE_MAGIC_1 "RuneCT10" /* Indicates version 0 of RuneLocale */ + +/* magic string for dynamic link module - type should be like "LC_CTYPE" */ +#define _NB_RUNE_MODULE_1(type) "RuneModule10." type + +/* codeset tag */ +#define _NB_RUNE_CODESET "CODESET=" + +#endif /* !_NB_RUNETYPE_H_ */ diff --git a/lib/libc/locale/setinvalidrune.c b/lib/libc/locale/setinvalidrune.c deleted file mode 100644 index 45a2a47ea7..0000000000 --- a/lib/libc/locale/setinvalidrune.c +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -void -setinvalidrune(ir) - rune_t ir; -{ - _INVALID_RUNE = ir; -} diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 9b870021b4..0ce6c90384 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -1,5 +1,7 @@ +/* $NetBSD: src/lib/libc/locale/setlocale.c,v 1.47 2004/07/21 20:27:46 tshiozak Exp $ */ +/* $DragonFly: src/lib/libc/locale/setlocale.c,v 1.3 2005/04/21 16:36:34 joerg Exp $ */ + /* - * Copyright (c) 1996 - 2002 FreeBSD Project * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -14,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,290 +31,354 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)setlocale.c 8.1 (Berkeley) 7/4/93 - * $FreeBSD: src/lib/libc/locale/setlocale.c,v 1.25.2.8 2002/08/12 11:17:38 ache Exp $ - * $DragonFly: src/lib/libc/locale/setlocale.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ */ +#define _CTYPE_PRIVATE + #include +#include #include -#include +#include +#include #include #include -#include +#include +#include #include #include #include #include "collate.h" -#include "lmonetary.h" /* for __monetary_load_locale() */ -#include "lnumeric.h" /* for __numeric_load_locale() */ -#include "lmessages.h" /* for __messages_load_locale() */ -#include "setlocale.h" -#include "ldpart.h" -#include "../stdtime/timelocal.h" /* for __time_load_locale() */ +#include "rune.h" +#include "rune_local.h" -/* - * Category names for getenv() - */ -static char *categories[_LC_LAST] = { - "LC_ALL", - "LC_COLLATE", - "LC_CTYPE", - "LC_MONETARY", - "LC_NUMERIC", - "LC_TIME", - "LC_MESSAGES", +#include "../citrus/citrus_namespace.h" +#include "../citrus/citrus_region.h" +#include "../citrus/citrus_lookup.h" +#include "../citrus/citrus_bcs.h" + +#define _LOCALE_ALIAS_NAME "locale.alias" +#define _LOCALE_SYM_FORCE "/force" + +static char *currentlocale(void); +static void revert_to_default(int); +static int force_locale_enable(int); +static int load_locale_sub(int, const char *, int); +static char *loadlocale(int); +static const char *__get_locale_env(int); + +static void revert_collate(void); +static int load_ctype(const char *); +static void revert_ctype(void); +static int load_messages(const char *); + +static const struct { + const char *name; + int (*load_function)(const char *); + void (*revert_function)(void); +} categories[] = { + { "LC_ALL", NULL, NULL }, + { "LC_COLLATE", __collate_load_tables, revert_collate }, + { "LC_CTYPE", load_ctype, revert_ctype }, + { "LC_MONETARY", NULL, NULL }, + { "LC_NUMERIC", NULL, NULL }, + { "LC_TIME", NULL, NULL }, + { "LC_MESSAGES", load_messages, NULL } }; /* * Current locales for each category */ -static char current_categories[_LC_LAST][ENCODING_LEN + 1] = { - "C", - "C", - "C", - "C", - "C", - "C", - "C", +static char current_categories[_LC_LAST][32] = { + "C", + "C", + "C", + "C", + "C", + "C", + "C" }; /* * The locales we are going to try and load */ -static char new_categories[_LC_LAST][ENCODING_LEN + 1]; -static char saved_categories[_LC_LAST][ENCODING_LEN + 1]; +static char new_categories[_LC_LAST][32]; -static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)]; +static char current_locale_string[_LC_LAST * 33]; +const char *_PathLocale; -static char *currentlocale(void); -static int wrap_setrunelocale(const char *); -static char *loadlocale(int); +static int +load_ctype(const char *locale) +{ + if (_xpg4_setrunelocale(locale)) + return(-1); + if (__runetable_to_netbsd_ctype(locale)) { + /* very unfortunate, but need to go to "C" locale */ + revert_ctype(); + return(-1); + } + + return(0); +} + +static void +revert_ctype(void) +{ + _xpg4_setrunelocale("C"); + __runetable_to_netbsd_ctype("C"); +} + +static void +revert_collate(void) +{ + __collate_load_tables("C"); +} + +static int +load_messages(const char *locale) +{ + char name[PATH_MAX]; + struct stat st; + + /* + * XXX we don't have LC_MESSAGES support yet, + * but catopen may use the value of LC_MESSAGES category. + * so return successfully if locale directory is present. + */ + snprintf(name, sizeof(name), "%s/%s", _PathLocale, locale); + + if (stat(name, &st) < 0) + return(-1); + if (!S_ISDIR(st.st_mode)) + return(-1); + return(0); +} char * -setlocale(category, locale) - int category; - const char *locale; +setlocale(int category, const char *locale) { - int i, j, len, saverr; - char *env, *r; + int i, loadlocale_success; + size_t len; + const char *env, *r; - if (category < LC_ALL || category >= _LC_LAST) { - errno = EINVAL; - return (NULL); - } + __mb_len_max_runtime = 32; + + if (issetugid() || + (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE")))) + _PathLocale = _PATH_LOCALE; + + if (category < 0 || category >= (int)__arysize(categories)) + return(NULL); if (locale == NULL) - return (category != LC_ALL ? + return(category ? current_categories[category] : currentlocale()); /* * Default to the current locale for everything. */ for (i = 1; i < _LC_LAST; ++i) - (void)strcpy(new_categories[i], current_categories[i]); + strlcpy(new_categories[i], current_categories[i], + sizeof(new_categories[i])); /* * Now go fill up new_categories from the locale argument */ - if (!*locale) { - env = getenv("LC_ALL"); - - if (category != LC_ALL && (env == NULL || !*env)) - env = getenv(categories[category]); - - if (env == NULL || !*env) - env = getenv("LANG"); - - if (env == NULL || !*env) - env = "C"; - - if (strlen(env) > ENCODING_LEN) { - errno = EINVAL; - return (NULL); - } - (void)strcpy(new_categories[category], env); - + if (*locale == '\0') { if (category == LC_ALL) { for (i = 1; i < _LC_LAST; ++i) { - if ((env = getenv(categories[i])) == NULL || - !*env) - env = new_categories[LC_ALL]; - else if (strlen(env) > ENCODING_LEN) { - errno = EINVAL; - return (NULL); - } - (void)strcpy(new_categories[i], env); + env = __get_locale_env(i); + strlcpy(new_categories[i], env, + sizeof(new_categories[i])); } } - } else if (category != LC_ALL) { - if (strlen(locale) > ENCODING_LEN) { - errno = EINVAL; - return (NULL); + else { + env = __get_locale_env(category); + strlcpy(new_categories[category], env, + sizeof(new_categories[category])); } - (void)strcpy(new_categories[category], locale); + } else if (category) { + strlcpy(new_categories[category], locale, + sizeof(new_categories[category])); } else { - if ((r = strchr(locale, '/')) == NULL) { - if (strlen(locale) > ENCODING_LEN) { - errno = EINVAL; - return (NULL); + if ((r = strchr(locale, '/')) == 0) { + for (i = 1; i < _LC_LAST; ++i) { + strlcpy(new_categories[i], locale, + sizeof(new_categories[i])); } - for (i = 1; i < _LC_LAST; ++i) - (void)strcpy(new_categories[i], locale); } else { - for (i = 1; r[1] == '/'; ++r) - ; - if (!r[1]) { - errno = EINVAL; - return (NULL); /* Hmm, just slashes... */ - } - do { - if (i == _LC_LAST) - break; /* Too many slashes... */ - if ((len = r - locale) > ENCODING_LEN) { - errno = EINVAL; - return (NULL); - } - (void)strlcpy(new_categories[i], locale, - len + 1); - i++; - locale = r; - while (*locale == '/') - ++locale; - while (*++r && *r != '/') - ; - } while (*locale); - while (i < _LC_LAST) { - (void)strcpy(new_categories[i], - new_categories[i-1]); - i++; + for (i = 1;;) { + _DIAGASSERT(*r == '/' || *r == 0); + _DIAGASSERT(*locale != 0); + if (*locale == '/') + return(NULL); /* invalid format. */ + len = r - locale; + if (len + 1 > sizeof(new_categories[i])) + return(NULL); /* too long */ + memcpy(new_categories[i], locale, len); + new_categories[i][len] = '\0'; + if (*r == 0) + break; + _DIAGASSERT(*r == '/'); + if (*(locale = ++r) == 0) + /* slash followed by NUL */ + return(NULL); + /* skip until NUL or '/' */ + while (*r && *r != '/') + r++; + if (++i == _LC_LAST) + return(NULL); /* too many slashes. */ } + if (i + 1 != _LC_LAST) + return(NULL); /* too few slashes. */ } } - if (category != LC_ALL) - return (loadlocale(category)); + if (category) + return(loadlocale(category)); + loadlocale_success = 0; for (i = 1; i < _LC_LAST; ++i) { - (void)strcpy(saved_categories[i], current_categories[i]); - if (loadlocale(i) == NULL) { - saverr = errno; - for (j = 1; j < i; j++) { - (void)strcpy(new_categories[j], - saved_categories[j]); - if (loadlocale(j) == NULL) { - (void)strcpy(new_categories[j], "C"); - (void)loadlocale(j); - } - } - errno = saverr; - return (NULL); - } + if (loadlocale(i) != NULL) + loadlocale_success = 1; } - return (currentlocale()); + + /* + * If all categories failed, return NULL; we don't need to back + * changes off, since none happened. + */ + if (!loadlocale_success) + return(NULL); + + return(currentlocale()); } static char * -currentlocale() +currentlocale(void) { int i; - (void)strcpy(current_locale_string, current_categories[1]); + strlcpy(current_locale_string, current_categories[1], + sizeof(current_locale_string)); for (i = 2; i < _LC_LAST; ++i) if (strcmp(current_categories[1], current_categories[i])) { - for (i = 2; i < _LC_LAST; ++i) { - (void)strcat(current_locale_string, "/"); - (void)strcat(current_locale_string, - current_categories[i]); - } + snprintf(current_locale_string, + sizeof(current_locale_string), "%s/%s/%s/%s/%s/%s", + current_categories[1], current_categories[2], + current_categories[3], current_categories[4], + current_categories[5], current_categories[6]); break; } - return (current_locale_string); + return(current_locale_string); +} + +static void +revert_to_default(int category) +{ + _DIAGASSERT(category >= 0 && category < _LC_LAST); + + if (categories[category].revert_function != NULL) + categories[category].revert_function(); } static int -wrap_setrunelocale(const char *locale) +force_locale_enable(int category) { - int ret = setrunelocale((char *)locale); + revert_to_default(category); - if (ret != 0) { - errno = ret; - return (_LDP_ERROR); - } - return (_LDP_LOADED); + return(0); } -static char * -loadlocale(category) - int category; +static int +load_locale_sub(int category, const char *locname, int isspecial) { - char *new = new_categories[category]; - char *old = current_categories[category]; - int (*func)(const char *); - - if ((new[0] == '.' && - (new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) || - strchr(new, '/') != NULL) { - errno = EINVAL; - return (NULL); - } + char name[PATH_MAX]; - if (_PathLocale == NULL) { - char *p = getenv("PATH_LOCALE"); - - if (p != NULL -#ifndef __NETBSD_SYSCALLS - && !issetugid() -#endif - ) { - if (strlen(p) + 1/*"/"*/ + ENCODING_LEN + - 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX) { - errno = ENAMETOOLONG; - return (NULL); - } - _PathLocale = strdup(p); - if (_PathLocale == NULL) { - errno = ENOMEM; - return (NULL); - } - } else - _PathLocale = _PATH_LOCALE; + /* check for the default locales */ + if (!strcmp(new_categories[category], "C") || + !strcmp(new_categories[category], "POSIX")) { + revert_to_default(category); + return(0); } - switch (category) { - case LC_CTYPE: - func = wrap_setrunelocale; - break; - case LC_COLLATE: - func = __collate_load_tables; - break; - case LC_TIME: - func = __time_load_locale; - break; - case LC_NUMERIC: - func = __numeric_load_locale; - break; - case LC_MONETARY: - func = __monetary_load_locale; - break; - case LC_MESSAGES: - func = __messages_load_locale; - break; - default: - errno = EINVAL; - return (NULL); - } + /* check whether special symbol */ + if (isspecial && _bcs_strcasecmp(locname, _LOCALE_SYM_FORCE) == 0) + return(force_locale_enable(category)); - if (strcmp(new, old) == 0) - return (old); + /* sanity check */ + if (strchr(locname, '/') != NULL) + return(-1); - if (func(new) != _LDP_ERROR) { - (void)strcpy(old, new); - return (old); - } + snprintf(name, sizeof(name), "%s/%s/%s", _PathLocale, locname, + categories[category].name); - return (NULL); + if (category > 0 && category < (int)__arysize(categories) && + categories[category].load_function != NULL) + return(categories[category].load_function(locname)); + + return(0); +} + +static char * +loadlocale(int category) +{ + char aliaspath[PATH_MAX], loccat[PATH_MAX], buf[PATH_MAX]; + const char *alias; + + _DIAGASSERT(0 < category && category < __arysize(categories)); + + if (strcmp(new_categories[category], current_categories[category]) == 0) + return(current_categories[category]); + + /* (1) non-aliased file */ + if (!load_locale_sub(category, new_categories[category], 0)) + goto success; + + /* (2) lookup locname/catname type alias */ + snprintf(aliaspath, sizeof(aliaspath), "%s/" _LOCALE_ALIAS_NAME, + _PathLocale); + snprintf(loccat, sizeof(loccat), "%s/%s", new_categories[category], + categories[category].name); + alias = _lookup_alias(aliaspath, loccat, buf, sizeof(buf), + _LOOKUP_CASE_SENSITIVE); + if (!load_locale_sub(category, alias, 1)) + goto success; + + /* (3) lookup locname type alias */ + alias = _lookup_alias(aliaspath, new_categories[category], + buf, sizeof(buf), _LOOKUP_CASE_SENSITIVE); + if (!load_locale_sub(category, alias, 1)) + goto success; + + return(NULL); + +success: + strlcpy(current_categories[category], new_categories[category], + sizeof(current_categories[category])); + return(current_categories[category]); } +static const char * +__get_locale_env(int category) +{ + const char *env; + + _DIAGASSERT(category != LC_ALL); + + /* 1. check LC_ALL. */ + env = getenv(categories[0].name); + + /* 2. check LC_* */ + if (env == NULL || *env == '\0') + env = getenv(categories[category].name); + + /* 3. check LANG */ + if (env == NULL || *env == '\0') + env = getenv("LANG"); + + /* 4. if none is set, fall to "C" */ + if (env == NULL || *env == '\0' || strchr(env, '/')) + env = "C"; + + return(env); +} diff --git a/lib/libc/locale/setlocale.h b/lib/libc/locale/setlocale.h deleted file mode 100644 index f3b2a22eb7..0000000000 --- a/lib/libc/locale/setlocale.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _SETLOCALE_H -#define _SETLOCALE_H -/* - * Copyright (C) 1997 by Andrey A. Chernov, Moscow, Russia. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#define ENCODING_LEN 31 -#define CATEGORY_LEN 11 - -extern char *_PathLocale; - -#endif /* SETLOCALE_H */ diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c index a676ba6ff1..540d2a7cc7 100644 --- a/lib/libc/locale/setrunelocale.c +++ b/lib/libc/locale/setrunelocale.c @@ -1,3 +1,68 @@ +/* $NetBSD: src/lib/libc/locale/setrunelocale.c,v 1.14 2003/08/07 16:43:07 agc Exp $ */ +/* $DragonFly: src/lib/libc/locale/setrunelocale.c,v 1.5 2005/04/21 16:36:34 joerg Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -13,11 +78,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -32,134 +93,133 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.14.6.4 2002/10/24 11:00:52 tjr Exp $ - * $DragonFly: src/lib/libc/locale/setrunelocale.c,v 1.4 2003/12/01 23:38:23 drhodus Exp $ */ -#include +#include #include #include -#include +#include +#include #include #include +#include #include -#include "setlocale.h" - -extern int _none_init(_RuneLocale *); -extern int _UTF2_init(_RuneLocale *); -extern int _UTF8_init(_RuneLocale *); -extern int _EUC_init(_RuneLocale *); -extern int _GB18030_init(_RuneLocale *); -extern int _GBK_init(_RuneLocale *); -extern int _BIG5_init(_RuneLocale *); -extern int _MSKanji_init(_RuneLocale *); -extern _RuneLocale *_Read_RuneMagi(FILE *); +#include +#include "../citrus/citrus_module.h" +#include "../citrus/citrus_ctype.h" +#include "rune.h" +#include "rune_local.h" +#include "multibyte.h" + +struct localetable { + char path[PATH_MAX]; + _RuneLocale *runelocale; + struct localetable *next; +}; +static struct localetable *localetable_head; + +_RuneLocale * +_findrunelocale(char *path) +{ + struct localetable *lt; + + _DIAGASSERT(path != NULL); + + /* ones which we have seen already */ + for (lt = localetable_head; lt; lt = lt->next) { + if (strcmp(path, lt->path) == 0) + return(lt->runelocale); + } + + return(NULL); +} int -setrunelocale(char *encoding) +_newrunelocale(char *path) { + struct localetable *lt; FILE *fp; - char name[PATH_MAX]; _RuneLocale *rl; - int saverr, ret; - static char ctype_encoding[ENCODING_LEN + 1]; - static _RuneLocale *CachedRuneLocale; - static int Cached__mb_cur_max; - - if (!encoding || !*encoding || strlen(encoding) > ENCODING_LEN || - (encoding[0] == '.' && - (encoding[1] == '\0' || - (encoding[1] == '.' && encoding[2] == '\0'))) || - strchr(encoding, '/') != NULL) - return (EINVAL); - - /* - * The "C" and "POSIX" locale are always here. - */ - if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) { - _CurrentRuneLocale = &_DefaultRuneLocale; - __mb_cur_max = 1; - return (0); - } + int ret; - /* - * If the locale name is the same as our cache, use the cache. - */ - if (CachedRuneLocale != NULL && - strcmp(encoding, ctype_encoding) == 0) { - _CurrentRuneLocale = CachedRuneLocale; - __mb_cur_max = Cached__mb_cur_max; - return (0); - } + /* path may be NULL (actually, it's checked below) */ + + if (path == NULL || strlen(path) + 1 > sizeof(lt->path)) + return(EFAULT); + + rl = _findrunelocale(path); + if (rl) + return(0); - /* - * Slurp the locale file into the cache. - */ - if (_PathLocale == NULL) { - char *p = getenv("PATH_LOCALE"); - - if (p != NULL -#ifndef __NETBSD_SYSCALLS - && !issetugid() -#endif - ) { - if (strlen(p) + 1/*"/"*/ + ENCODING_LEN + - 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX) - return (ENAMETOOLONG); - _PathLocale = strdup(p); - if (_PathLocale == NULL) - return (errno == 0 ? ENOMEM : errno); - } else - _PathLocale = _PATH_LOCALE; + if ((fp = fopen(path, "r")) == NULL) + return(ENOENT); + + if ((rl = _Read_RuneMagi(fp)) != NULL) + goto found; + /* necessary for backward compatibility */ + if ((rl = _Read_CTypeAsRune(fp)) != NULL) + goto found; + + fclose(fp); + return(EFTYPE); + +found: + fclose(fp); + + rl->rl_citrus_ctype = NULL; + ret = _citrus_ctype_open(&rl->rl_citrus_ctype, rl->rl_encoding, + rl->rl_variable, rl->rl_variable_len, + _PRIVSIZE); + if (ret) { + _NukeRune(rl); + return(ret); + } + if (__MB_LEN_MAX_RUNTIME < + _citrus_ctype_get_mb_cur_max(rl->rl_citrus_ctype)) { + _NukeRune(rl); + return(EINVAL); } - /* Range checking not needed, encoding length already checked above */ - (void) strcpy(name, _PathLocale); - (void) strcat(name, "/"); - (void) strcat(name, encoding); - (void) strcat(name, "/LC_CTYPE"); - - if ((fp = fopen(name, "r")) == NULL) - return (errno == 0 ? ENOENT : errno); - - if ((rl = _Read_RuneMagi(fp)) == NULL) { - saverr = (errno == 0 ? EFTYPE : errno); - (void)fclose(fp); - return (saverr); + + /* register it */ + lt = malloc(sizeof(struct localetable)); + if (lt == NULL) { + _NukeRune(rl); + return(ENOMEM); } - (void)fclose(fp); - - if (strcmp(rl->encoding, "NONE") == 0) - ret = _none_init(rl); - else if (strcmp(rl->encoding, "UTF2") == 0) - ret = _UTF2_init(rl); - else if (strcmp(rl->encoding, "UTF-8") == 0) - ret = _UTF8_init(rl); - else if (strcmp(rl->encoding, "EUC") == 0) - ret = _EUC_init(rl); - else if (strcmp(rl->encoding, "GB18030") == 0) - ret = _GB18030_init(rl); - else if (strcmp(rl->encoding, "GBK") == 0) - ret = _GBK_init(rl); - else if (strcmp(rl->encoding, "BIG5") == 0) - ret = _BIG5_init(rl); - else if (strcmp(rl->encoding, "MSKanji") == 0) - ret = _MSKanji_init(rl); - else - ret = EFTYPE; - if (ret == 0) { - if (CachedRuneLocale != NULL) { - /* See euc.c */ - if (strcmp(CachedRuneLocale->encoding, "EUC") == 0) - free(CachedRuneLocale->variable); - free(CachedRuneLocale); - } - CachedRuneLocale = _CurrentRuneLocale; - Cached__mb_cur_max = __mb_cur_max; - (void)strcpy(ctype_encoding, encoding); - } else - free(rl); - - return (ret); + strlcpy(lt->path, path, sizeof(lt->path)); + lt->runelocale = rl; + lt->next = localetable_head; + localetable_head = lt; + + return(0); } +int +_xpg4_setrunelocale(const char *encoding) +{ + char path[PATH_MAX]; + _RuneLocale *rl; + int error; + + _DIAGASSERT(encoding != NULL); + + if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) { + rl = &_DefaultRuneLocale; + goto found; + } + + snprintf(path, sizeof(path), "%s/%s/LC_CTYPE", _PathLocale, encoding); + + error = _newrunelocale(path); + if (error) + return(error); + rl = _findrunelocale(path); + if (!rl) + return(ENOENT); + +found: + _CurrentRuneLocale = rl; + __mb_cur_max = _citrus_ctype_get_mb_cur_max(rl->rl_citrus_ctype); + + return(0); +} diff --git a/lib/libc/locale/table.c b/lib/libc/locale/table.c deleted file mode 100644 index 430473e307..0000000000 --- a/lib/libc/locale/table.c +++ /dev/null @@ -1,258 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/table.c,v 1.13.2.1 2000/06/04 21:47:39 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/table.c,v 1.4 2003/11/12 20:21:24 eirikn Exp $ - * - * @(#)table.c 8.1 (Berkeley) 6/27/93 - */ - -#include -#include -#include - -extern rune_t _none_sgetrune (const char *, size_t, char const **); -extern int _none_sputrune (rune_t, char *, size_t, char **); -extern int _none_init (char *, char **); - -_RuneLocale _DefaultRuneLocale = { - _RUNE_MAGIC_1, - "NONE", - _none_sgetrune, - _none_sputrune, - 0xFFFD, - - { /*00*/ _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - /*08*/ _CTYPE_C, - _CTYPE_C|_CTYPE_S|_CTYPE_B, - _CTYPE_C|_CTYPE_S, - _CTYPE_C|_CTYPE_S, - _CTYPE_C|_CTYPE_S, - _CTYPE_C|_CTYPE_S, - _CTYPE_C, - _CTYPE_C, - /*10*/ _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - /*18*/ _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - _CTYPE_C, - /*20*/ _CTYPE_S|_CTYPE_B|_CTYPE_R, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - /*28*/ _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - /*30*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|0, - _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|1, - _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|2, - _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|3, - _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|4, - _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|5, - _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|6, - _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|7, - /*38*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|8, - _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|9, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - /*40*/ _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|10, - _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|11, - _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|12, - _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|13, - _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|14, - _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|15, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - /*48*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - /*50*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - /*58*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - /*60*/ _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|10, - _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|11, - _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|12, - _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|13, - _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|14, - _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|15, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - /*68*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - /*70*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - /*78*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_P|_CTYPE_R|_CTYPE_G, - _CTYPE_C, - }, - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, - }, - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 'A', 'B', 'C', 'D', 'E', 'F', 'G', - 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', - 'X', 'Y', 'Z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G', - 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', - 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, - }, -}; - -_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale; - -int __mb_cur_max = 1; - -char *_PathLocale; diff --git a/lib/libc/locale/tolower.c b/lib/libc/locale/tolower.c deleted file mode 100644 index 17324bc79d..0000000000 --- a/lib/libc/locale/tolower.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/tolower.c,v 1.5.8.1 2000/06/04 21:47:39 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/tolower.c,v 1.3 2003/11/09 02:34:01 dillon Exp $ - */ - -#include -#include -#ifndef _SYS_STDINT_H_ -#include -#endif - -__ct_rune_t -___tolower(__ct_rune_t c) -{ - int x; - _RuneRange *rr = &_CurrentRuneLocale->maplower_ext; - _RuneEntry *re = rr->ranges; - - if (c < 0 || c == EOF) - return(c); - - for (x = 0; x < rr->nranges; ++x, ++re) { - if (c < re->min) - return(c); - if (c <= re->max) - return(re->map + c - re->min); - } - - return(c); -} diff --git a/lib/libc/locale/toupper.c b/lib/libc/locale/toupper.c deleted file mode 100644 index 2eff49fa1c..0000000000 --- a/lib/libc/locale/toupper.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/toupper.c,v 1.5.8.1 2000/06/04 21:47:39 ache Exp $ - * $DragonFly: src/lib/libc/locale/Attic/toupper.c,v 1.3 2003/11/09 02:34:01 dillon Exp $ - */ - -#include -#include -#ifndef _SYS_STDINT_H_ -#include -#endif - -__ct_rune_t -___toupper(__ct_rune_t c) -{ - int x; - _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext; - _RuneEntry *re = rr->ranges; - - if (c < 0 || c == EOF) - return(c); - - for (x = 0; x < rr->nranges; ++x, ++re) { - if (c < re->min) - return(c); - if (c <= re->max) - return(re->map + c - re->min); - } - - return(c); -} diff --git a/lib/libc/locale/utf2.c b/lib/libc/locale/utf2.c deleted file mode 100644 index 052f039876..0000000000 --- a/lib/libc/locale/utf2.c +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/utf2.c,v 1.3.2.2 2001/03/05 10:27:18 obrien Exp $ - * $DragonFly: src/lib/libc/locale/Attic/utf2.c,v 1.3 2003/11/12 20:21:24 eirikn Exp $ - * - * @(#)utf2.c 8.1 (Berkeley) 6/4/93 - */ - -#include -#include -#include -#include - -rune_t _UTF2_sgetrune (const char *, size_t, char const **); -int _UTF2_sputrune (rune_t, char *, size_t, char **); - -static int _utf_count[16] = { - 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 2, 2, 3, 0, -}; - -int -_UTF2_init(rl) - _RuneLocale *rl; -{ - rl->sgetrune = _UTF2_sgetrune; - rl->sputrune = _UTF2_sputrune; - _CurrentRuneLocale = rl; - __mb_cur_max = 3; - return (0); -} - -rune_t -_UTF2_sgetrune(string, n, result) - const char *string; - size_t n; - char const **result; -{ - int c; - - if (n < 1 || (c = _utf_count[(*string >> 4) & 0xf]) > n) { - if (result) - *result = string; - return (_INVALID_RUNE); - } - switch (c) { - case 1: - if (result) - *result = string + 1; - return (*string & 0xff); - case 2: - if ((string[1] & 0xC0) != 0x80) - goto encoding_error; - if (result) - *result = string + 2; - return (((string[0] & 0x1F) << 6) | (string[1] & 0x3F)); - case 3: - if ((string[1] & 0xC0) != 0x80 || (string[2] & 0xC0) != 0x80) - goto encoding_error; - if (result) - *result = string + 3; - return (((string[0] & 0x1F) << 12) | ((string[1] & 0x3F) << 6) - | (string[2] & 0x3F)); - default: -encoding_error: if (result) - *result = string + 1; - return (_INVALID_RUNE); - } -} - -int -_UTF2_sputrune(c, string, n, result) - rune_t c; - char *string, **result; - size_t n; -{ - if (c & 0xF800) { - if (n >= 3) { - if (string) { - string[0] = 0xE0 | ((c >> 12) & 0x0F); - string[1] = 0x80 | ((c >> 6) & 0x3F); - string[2] = 0x80 | ((c) & 0x3F); - } - if (result) - *result = string + 3; - } else - if (result) - *result = NULL; - - return (3); - } else - if (c & 0x0780) { - if (n >= 2) { - if (string) { - string[0] = 0xC0 | ((c >> 6) & 0x1F); - string[1] = 0x80 | ((c) & 0x3F); - } - if (result) - *result = string + 2; - } else - if (result) - *result = NULL; - return (2); - } else { - if (n >= 1) { - if (string) - string[0] = c; - if (result) - *result = string + 1; - } else - if (result) - *result = NULL; - return (1); - } -} diff --git a/lib/libc/locale/utf8.c b/lib/libc/locale/utf8.c deleted file mode 100644 index 8fb3bde5c8..0000000000 --- a/lib/libc/locale/utf8.c +++ /dev/null @@ -1,204 +0,0 @@ -/*- - * Copyright (c) 2002 Tim J. Robbins - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/locale/utf8.c,v 1.1.2.1 2002/10/24 11:00:52 tjr Exp $ - * $DragonFly: src/lib/libc/locale/Attic/utf8.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ - */ - -#include -#include -#include -#include - -rune_t _UTF8_sgetrune(const char *, size_t, char const **); -int _UTF8_sputrune(rune_t, char *, size_t, char **); - -int -_UTF8_init(_RuneLocale *rl) -{ - - rl->sgetrune = _UTF8_sgetrune; - rl->sputrune = _UTF8_sputrune; - _CurrentRuneLocale = rl; - __mb_cur_max = 6; - - return (0); -} - -rune_t -_UTF8_sgetrune(const char *string, size_t n, const char **result) -{ - int ch, len, mask, siglen; - rune_t lbound, wch; - - if (n < 1) { - if (result != NULL) - *result = string; - return (_INVALID_RUNE); - } - - /* - * Determine the number of octets that make up this character from - * the first octet, and a mask that extracts the interesting bits of - * the first octet. - * - * We also specify a lower bound for the character code to detect - * redundant, non-"shortest form" encodings. For example, the - * sequence C0 80 is _not_ a legal representation of the null - * character. This enforces a 1-to-1 mapping between character - * codes and their multibyte representations. - */ - ch = (unsigned char)*string; - if ((ch & 0x80) == 0) { - mask = 0x7f; - len = 1; - lbound = 0; - } else if ((ch & 0xe0) == 0xc0) { - mask = 0x1f; - len = 2; - lbound = 0x80; - } else if ((ch & 0xf0) == 0xe0) { - mask = 0x0f; - len = 3; - lbound = 0x800; - } else if ((ch & 0xf8) == 0xf0) { - mask = 0x07; - len = 4; - lbound = 0x10000; - } else if ((ch & 0xfc) == 0xf8) { - mask = 0x03; - len = 5; - lbound = 0x200000; - } else if ((ch & 0xfc) == 0xfc) { - mask = 0x01; - len = 6; - lbound = 0x4000000; - } else { - /* - * Malformed input; input is not UTF-8. - */ - if (result != NULL) - *result = string + 1; - return (_INVALID_RUNE); - } - - if (n < len) { - /* - * Truncated or partial input. - */ - if (result != NULL) - *result = string; - return (_INVALID_RUNE); - } - - /* - * Decode the octet sequence representing the character in chunks - * of 6 bits, most significant first. - */ - wch = (unsigned char)*string++ & mask; - while (--len != 0) { - if ((*string & 0xc0) != 0x80) { - /* - * Malformed input; bad characters in the middle - * of a character. - */ - wch = _INVALID_RUNE; - if (result != NULL) - *result = string + 1; - return (_INVALID_RUNE); - } - wch <<= 6; - wch |= *string++ & 0x3f; - } - if (wch != _INVALID_RUNE && wch < lbound) - /* - * Malformed input; redundant encoding. - */ - wch = _INVALID_RUNE; - if (result != NULL) - *result = string; - return (wch); -} - -int -_UTF8_sputrune(rune_t c, char *string, size_t n, char **result) -{ - unsigned char lead; - int i, len; - - /* - * Determine the number of octets needed to represent this character. - * We always output the shortest sequence possible. Also specify the - * first few bits of the first octet, which contains the information - * about the sequence length. - */ - if ((c & ~0x7f) == 0) { - lead = 0; - len = 1; - } else if ((c & ~0x7ff) == 0) { - lead = 0xc0; - len = 2; - } else if ((c & ~0xffff) == 0) { - lead = 0xe0; - len = 3; - } else if ((c & ~0x1fffff) == 0) { - lead = 0xf0; - len = 4; - } else if ((c & ~0x3ffffff) == 0) { - lead = 0xf8; - len = 5; - } else if ((c & ~0x7fffffff) == 0) { - lead = 0xfc; - len = 6; - } else { - /* - * Wide character code is out of range. - */ - if (result != NULL) - *result = NULL; - return (0); - } - - if (n < len) { - if (result != NULL) - *result = NULL; - } else { - /* - * Output the octets representing the character in chunks - * of 6 bits, least significant last. The first octet is - * a special case because it contains the sequence length - * information. - */ - for (i = len - 1; i > 0; i--) { - string[i] = (c & 0x3f) | 0x80; - c >>= 6; - } - *string = (c & 0xff) | lead; - if (result != NULL) - *result = string + len; - } - - return (len); -} diff --git a/lib/libc/nls/Makefile.inc b/lib/libc/nls/Makefile.inc index 79b9ba8d28..c3745ebbd4 100644 --- a/lib/libc/nls/Makefile.inc +++ b/lib/libc/nls/Makefile.inc @@ -1,10 +1,11 @@ # from $NetBSD: Makefile.inc,v 1.7 1995/02/27 13:06:20 cgd Exp $ # $FreeBSD: src/lib/libc/nls/Makefile.inc,v 1.5.2.2 2001/04/25 10:04:07 ru Exp $ -# $DragonFly: src/lib/libc/nls/Makefile.inc,v 1.2 2003/06/17 04:26:44 dillon Exp $ +# $DragonFly: src/lib/libc/nls/Makefile.inc,v 1.3 2005/04/21 16:36:34 joerg Exp $ +.PATH: ${.CURDIR}/../libc/iconv .PATH: ${.CURDIR}/../libc/nls -SRCS+= msgcat.c +SRCS+= catclose.c catgets.c catopen.c .if ${LIB} == "c" MAN+= catclose.3 catgets.3 catopen.3 diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c deleted file mode 100644 index c0226e67d8..0000000000 --- a/lib/libc/nls/msgcat.c +++ /dev/null @@ -1,504 +0,0 @@ -/*********************************************************** -Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that Alfalfa's name not be used in -advertising or publicity pertaining to distribution of the software -without specific, written prior permission. - -ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -If you make any modifications, bugfixes or other changes to this software -we'd appreciate it if you could send a copy to us so we can keep things -up-to-date. Many thanks. - Kee Hinckley - Alfalfa Software, Inc. - 267 Allston St., #3 - Cambridge, MA 02139 USA - nazgul@alfalfa.com - -******************************************************************/ -/* - * $FreeBSD: src/lib/libc/nls/msgcat.c,v 1.21.2.6 2002/08/12 11:23:54 ache Exp $ - * $DragonFly: src/lib/libc/nls/Attic/msgcat.c,v 1.4 2005/01/31 22:29:36 dillon Exp $ - */ - -/* - * We need a better way of handling errors than printing text. I need - * to add an error handling routine. - */ - -#include "namespace.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "un-namespace.h" - -#include "msgcat.h" -#include "../locale/setlocale.h" /* for ENCODING_LEN */ - -#define _DEFAULT_NLS_PATH "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L" - -#define TRUE 1 -#define FALSE 0 - -#define NLERR ((nl_catd) -1) -#define NLRETERR(errc) { errno = errc; return (NLERR); } - -static nl_catd loadCat(); -static int loadSet(); -static void __nls_free_resources(); - -nl_catd -catopen(name, type) - const char *name; - int type; -{ - int spcleft, saverr; - char path[PATH_MAX]; - char *nlspath, *lang, *base, *cptr, *pathP, *tmpptr; - char *cptr1, *plang, *pter, *pcode; - struct stat sbuf; - - if (name == NULL || *name == '\0') - NLRETERR(EINVAL); - - /* is it absolute path ? if yes, load immediately */ - if (strchr(name, '/') != NULL) - return (loadCat(name)); - - if (type == NL_CAT_LOCALE) - lang = setlocale(LC_MESSAGES, NULL); - else - lang = getenv("LANG"); - - if (lang == NULL || *lang == '\0' || strlen(lang) > ENCODING_LEN || - (lang[0] == '.' && - (lang[1] == '\0' || (lang[1] == '.' && lang[2] == '\0'))) || - strchr(lang, '/') != NULL) - lang = "C"; - - if ((plang = cptr1 = strdup(lang)) == NULL) { - errno = ENOMEM; - return (NLERR); - } - if ((cptr = strchr(cptr1, '@')) != NULL) - *cptr = '\0'; - pter = pcode = ""; - if ((cptr = strchr(cptr1, '_')) != NULL) { - *cptr++ = '\0'; - pter = cptr1 = cptr; - } - if ((cptr = strchr(cptr1, '.')) != NULL) { - *cptr++ = '\0'; - pcode = cptr; - } - - if ((nlspath = getenv("NLSPATH")) == NULL -#ifndef __NETBSD_SYSCALLS - || issetugid() -#endif - ) - nlspath = _DEFAULT_NLS_PATH; - - if ((base = cptr = strdup(nlspath)) == NULL) { - free(plang); - errno = ENOMEM; - return (NLERR); - } - - while ((nlspath = strsep(&cptr, ":")) != NULL) { - pathP = path; - if (*nlspath) { - for (; *nlspath; ++nlspath) { - if (*nlspath == '%') { - switch (*(nlspath + 1)) { - case 'l': - tmpptr = plang; - break; - case 't': - tmpptr = pter; - break; - case 'c': - tmpptr = pcode; - break; - case 'L': - tmpptr = lang; - break; - case 'N': - tmpptr = (char *)name; - break; - case '%': - ++nlspath; - /* fallthrough */ - default: - if (pathP - path >= - sizeof(path) - 1) - goto too_long; - *(pathP++) = *nlspath; - continue; - } - ++nlspath; - put_tmpptr: - spcleft = sizeof(path) - - (pathP - path) - 1; - if (strlcpy(pathP, tmpptr, spcleft) >= - spcleft) { - too_long: - free(plang); - free(base); - NLRETERR(ENAMETOOLONG); - } - pathP += strlen(tmpptr); - } else { - if (pathP - path >= sizeof(path) - 1) - goto too_long; - *(pathP++) = *nlspath; - } - } - *pathP = '\0'; - if (stat(path, &sbuf) == 0) { - free(plang); - free(base); - return (loadCat(path)); - } - } else { - tmpptr = (char *)name; - --nlspath; - goto put_tmpptr; - } - } - free(plang); - free(base); - NLRETERR(ENOENT); -} - -/* - * We've got an odd situation here. The odds are real good that the - * number we are looking for is almost the same as the index. We could - * use the index, check the difference and do something intelligent, but - * I haven't quite figured out what's intelligent. - * - * Here's a start. - * Take an id N. If there are > N items in the list, then N cannot - * be more than N items from the start, since otherwise there would - * have to be duplicate items. So we can safely set the top to N+1 - * (after taking into account that ids start at 1, and arrays at 0) - * - * Let's say we are at position P, and we are looking for N, but have - * V. If N > V, then the furthest away that N could be is - * P + (N-V). So we can safely set hi to P+(N-V)+1. For example: - * We are looking for 10, but have 8 - * 8 ? ? ? ? - * >=9 >=10 >=11 - * - */ - -#define LOOKUP(PARENT, CHILD, ID, NUM, SET) { \ - lo = 0; \ - if (ID - 1 < PARENT->NUM) { \ - cur = ID - 1; \ - hi = ID; \ - } else { \ - hi = PARENT->NUM; \ - cur = (hi - lo) / 2; \ - } \ - while (TRUE) { \ - CHILD = PARENT->SET + cur; \ - if (CHILD->ID == ID) \ - break; \ - if (CHILD->ID < ID) { \ - lo = cur + 1; \ - if (hi > cur + (ID - CHILD->ID) + 1) \ - hi = cur + (ID - CHILD->ID) + 1; \ - dir = 1; \ - } else { \ - hi = cur; \ - dir = -1; \ - } \ - if (lo >= hi) \ - return (NULL); \ - if (hi - lo == 1) \ - cur += dir; \ - else \ - cur += ((hi - lo) / 2) * dir; \ - } \ -} - -static MCSetT * -MCGetSet(cat, setId) - MCCatT *cat; - int setId; -{ - MCSetT *set; - long lo, hi, cur, dir; - - if (cat == NULL || setId <= 0) - return (NULL); - LOOKUP(cat, set, setId, numSets, sets); - if (set->invalid && loadSet(cat, set) <= 0) - return (NULL); - return (set); -} - -static MCMsgT * -MCGetMsg(set, msgId) - MCSetT *set; - int msgId; -{ - MCMsgT *msg; - long lo, hi, cur, dir; - - if (set == NULL || set->invalid || msgId <= 0) - return (NULL); - LOOKUP(set, msg, msgId, numMsgs, u.msgs); - return (msg); -} - -char * -catgets(catd, setId, msgId, dflt) - nl_catd catd; - int setId; - int msgId; - const char *dflt; -{ - MCMsgT *msg; - MCCatT *cat = (MCCatT *)catd; - const char *cptr; - - if (catd == NULL || catd == NLERR) - return ((char *)dflt); - msg = MCGetMsg(MCGetSet(cat, setId), msgId); - if (msg != NULL) - cptr = msg->msg.str; - else - cptr = dflt; - return ((char *)cptr); -} - -int -catclose(catd) - nl_catd catd; -{ - MCCatT *cat = (MCCatT *)catd; - - if (catd == NULL || catd == NLERR) { - errno = EBADF; - return (-1); - } -#if 0 - if (cat->loadType != MCLoadAll) -#endif - (void)fclose(cat->fp); - __nls_free_resources(cat, cat->numSets); - free(cat); - return (0); -} - -/* - * Internal routines - */ - -/* Note that only malloc failures are allowed to return an error */ -static char *_errowner = "Message Catalog System"; - -#define CORRUPT() { \ - (void)fclose(cat->fp); \ - (void)fprintf(stderr, "%s: corrupt file.", _errowner); \ - free(cat); \ - NLRETERR(EFTYPE); \ -} - -#define NOSPACE() { \ - (void)fclose(cat->fp); \ - (void)fprintf(stderr, "%s: no more memory.", _errowner); \ - free(cat); \ - errno = ENOMEM; \ - return (NLERR); \ -} - -static void -__nls_free_resources(cat, i) - MCCatT *cat; - int i; -{ - MCSetT *set; - int j; - - for (j = 0; j < i; j++) { - set = cat->sets + j; - if (!set->invalid) { - free(set->data.str); - free(set->u.msgs); - } - } - free(cat->sets); -} - -static nl_catd -loadCat(catpath) - const char *catpath; -{ - MCHeaderT header; - MCCatT *cat; - MCSetT *set; - long i; - off_t nextSet; - int saverr; - - if ((cat = (MCCatT *)malloc(sizeof(MCCatT))) == NULL) { - errno = ENOMEM; - return (NLERR); - } - cat->loadType = MCLoadBySet; - - if ((cat->fp = fopen(catpath, "r")) == NULL) { - saverr = errno; - free(cat); - errno = saverr; - return (NLERR); - } - (void)_fcntl(fileno(cat->fp), F_SETFD, FD_CLOEXEC); - - if (fread(&header, sizeof(header), 1, cat->fp) != 1 || - strncmp(header.magic, MCMagic, MCMagicLen) != 0) - CORRUPT(); - - if (header.majorVer != MCMajorVer) { - (void)fclose(cat->fp); - free(cat); - (void)fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", - _errowner, catpath, header.majorVer, MCMajorVer); - NLRETERR(EFTYPE); - } - if (header.numSets <= 0) { - (void)fclose(cat->fp); - free(cat); - (void)fprintf(stderr, "%s: %s has %ld sets!\n", - _errowner, catpath, header.numSets); - NLRETERR(EFTYPE); - } - - cat->numSets = header.numSets; - if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * header.numSets)) == - NULL) - NOSPACE(); - - nextSet = header.firstSet; - for (i = 0; i < cat->numSets; ++i) { - if (fseeko(cat->fp, nextSet, SEEK_SET) == -1) { - __nls_free_resources(cat, i); - CORRUPT(); - } - - /* read in the set header */ - set = cat->sets + i; - if (fread(set, sizeof(*set), 1, cat->fp) != 1) { - __nls_free_resources(cat, i); - CORRUPT(); - } - - /* if it's invalid, skip over it (and backup 'i') */ - if (set->invalid) { - --i; - nextSet = set->nextSet; - continue; - } -#if 0 - if (cat->loadType == MCLoadAll) { - int res; - - if ((res = loadSet(cat, set)) <= 0) { - __nls_free_resources(cat, i); - if (res < 0) - NOSPACE(); - CORRUPT(); - } - } else -#endif - set->invalid = TRUE; - nextSet = set->nextSet; - } -#if 0 - if (cat->loadType == MCLoadAll) { - (void)fclose(cat->fp); - cat->fp = NULL; - } -#endif - return ((nl_catd) cat); -} - -static int -loadSet(cat, set) - MCCatT *cat; - MCSetT *set; -{ - MCMsgT *msg; - int i; - int saverr; - - /* Get the data */ - if (fseeko(cat->fp, set->data.off, SEEK_SET) == -1) - return (0); - if ((set->data.str = malloc(set->dataLen)) == NULL) { - errno = ENOMEM; - return (-1); - } - if (fread(set->data.str, set->dataLen, 1, cat->fp) != 1) { - saverr = errno; - free(set->data.str); - errno = saverr; - return (0); - } - - /* Get the messages */ - if (fseeko(cat->fp, set->u.firstMsg, SEEK_SET) == -1) { - saverr = errno; - free(set->data.str); - errno = saverr; - return (0); - } - if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * set->numMsgs)) == - NULL) { - free(set->data.str); - errno = ENOMEM; - return (-1); - } - - for (i = 0; i < set->numMsgs; ++i) { - msg = set->u.msgs + i; - if (fread(msg, sizeof(*msg), 1, cat->fp) != 1) { - saverr = errno; - free(set->u.msgs); - free(set->data.str); - errno = saverr; - return (0); - } - if (msg->invalid) { - --i; - continue; - } - msg->msg.str = (char *)(set->data.str + msg->msg.off); - } - set->invalid = FALSE; - return (1); -} diff --git a/lib/libc/nls/msgcat.h b/lib/libc/nls/msgcat.h deleted file mode 100644 index 6c81014fd3..0000000000 --- a/lib/libc/nls/msgcat.h +++ /dev/null @@ -1,156 +0,0 @@ -/* $FreeBSD: src/lib/libc/nls/msgcat.h,v 1.6.2.1 2000/09/07 16:46:33 ache Exp $ */ -/* $DragonFly: src/lib/libc/nls/Attic/msgcat.h,v 1.2 2003/06/17 04:26:44 dillon Exp $ */ - -#ifndef _MSGCAT_H_ -#define _MSGCAT_H_ - - -/*********************************************************** -Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that Alfalfa's name not be used in -advertising or publicity pertaining to distribution of the software -without specific, written prior permission. - -ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -If you make any modifications, bugfixes or other changes to this software -we'd appreciate it if you could send a copy to us so we can keep things -up-to-date. Many thanks. - Kee Hinckley - Alfalfa Software, Inc. - 267 Allston St., #3 - Cambridge, MA 02139 USA - nazgul@alfalfa.com - -******************************************************************/ - - -#include - -/* - * On disk data structures - */ - -/* For or'd constants */ -#define MCMakeId(s,m) (unsigned long) ( ((unsigned short)s << (sizeof(short)*8)) \ - | (unsigned short)m ) -#define MCSetId(id) (unsigned int) ( id >> (sizeof(short) * 8) ) -#define MCMsgId(id) (unsigned int) ( (id << (sizeof(short) * 8)) \ - >> (sizeof(short) * 8) ) -#define MCMagicLen 8 -#define MCMagic "*nazgul*" -#define MCLastMsg 0 -#define MCLastSet 0 - -#define MCMajorVer 1L -#define MCMinorVer 0 - -/* - * Critical note here. Sets and Messages *MUST* be stored in ascending - * order. There are stored that way (by specification) in the original - * data file, however in the process of merging in new stuff you might - * mix that up. Don't! The catget stuff does a binary search and will - * totally lose it if these aren't in order (not contiguous mind you, just - * in order. If this turns out to be a major problem this could be enhanced - * by adding a 'sorted' flag to the db, and sorting msgs and sets at load - * time if things aren't sorted, but I'd like not to have to do that. - */ - -/* - * I have tried here to define data structures which can be used - * while the catalog is on disk, and at runtime. - * This is rather dangerous of course, but I think it can be done without - * overly increasing the memory usage, and it makes loading and storing - * somewhat simpler and less prone to accidents. I have also tried to - * define on disk data structures which can be updated in place, so that - * with a very large catalog (e.g. all system errors) you don't have to - * load everything in memory in order to add or update one set. With - * this in mind there are "invalid" flags which allow items to be - * invalidated and thus not loaded at runtime. Note however that although - * I pay attention to these when I load the DB, I do not currently use - * them in gencat (it just reads everything into memory), so there is - * no guarantee that this will all work. - */ - -/* These should be publicly available */ - -#define MCLoadBySet 0 /* Load entire sets as they are used */ -#define MCLoadAll 1 /* Load entire DB on catopen */ - -/* - * MCOffsetT - Union to handle both disk and runtime pointers - */ -typedef union { - off_t off; - char *str; - void *ptr; - struct _MCMsgT *msg; - struct _MCSetT *set; -} MCOffsetT; - -/* - * MCMsgT - Message structure (disk and runtime) - */ -typedef struct _MCMsgT { - long msgId; /* Id of this message */ - MCOffsetT msg; /* Relative offset on disk or pointer in memory */ - long invalid; /* Valid on disk, loaded in memory */ -} MCMsgT; - -/* - * MCSetT - Set structure (disk and runtime) - */ -typedef struct _MCSetT { - long setId; /* Id of this set */ - off_t nextSet; /* Offset of next set on disk */ - union { - off_t firstMsg; /* Offset to first Msg (while on disk) */ - MCMsgT *msgs; /* Pointer to array of msgs (in mem, loaded) */ - } u; - MCOffsetT data; /* Offset to data, or pointer to data */ - long dataLen; /* Length of data area on disk */ - long numMsgs; /* Number of messages */ - long invalid; /* Valid on disk, loaded in memory */ -} MCSetT; - -/* - * MCCatT - Runtime catalog pointer - */ -typedef struct { - long loadType; /* How to load the messages (see MSLoadType) */ - FILE *fp; /* File descriptor of catalog (if load-on-demand) */ - long numSets; /* Number of sets */ - MCSetT *sets; /* Pointer to the sets */ - off_t firstSet; /* Offset of first set on disk */ -} MCCatT; - -/* - * MCHeaderT - Disk file header - */ -typedef struct { - char magic[MCMagicLen]; /* Magic cookie "*nazgul*" */ - long majorVer; /* ++ on incompatible changes */ - long minorVer; /* ++ on compatible changes */ - long flags; /* Informational flags */ - long numSets; /* Number of valid Sets */ - off_t firstSet; /* Offset of first set on disk */ -} MCHeaderT; - -/* Some flags */ -#define MC68KByteOrder 0x01 -#define MCn86ByteOrder 0x02 - -#endif /* !_MSGCAT_H_ */ diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index c24906687e..561a570fe1 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -35,7 +35,7 @@ * * @(#)vfprintf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.34 2001/12/13 19:45:41 phantom Exp $ - * $DragonFly: src/lib/libc/stdio/vfprintf.c,v 1.7 2005/02/14 23:15:51 cpressey Exp $ + * $DragonFly: src/lib/libc/stdio/vfprintf.c,v 1.8 2005/04/21 16:36:35 joerg Exp $ */ /* @@ -403,7 +403,7 @@ __vfprintf(FILE *fp, const char *fmt0, va_list ap) char thousands_sep; /* locale specific thousands separator */ const char *grouping; /* locale specific numeric grouping rules */ #ifdef FLOATING_POINT - char *decimal_point; /* locale specific decimal point */ + const char *decimal_point; /* locale specific decimal point */ char softsign; /* temporary negative sign for floats */ double _double; /* double precision arguments %[eEfgG] */ int expt; /* integer value of exponent */ @@ -445,7 +445,7 @@ __vfprintf(FILE *fp, const char *fmt0, va_list ap) * BEWARE, these `goto error' on error, and PAD uses `n'. */ #define PRINT(ptr, len) { \ - iovp->iov_base = (ptr); \ + iovp->iov_base = __DECONST(void *, ptr); \ iovp->iov_len = (len); \ uio.uio_resid += (len); \ iovp++; \ diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index ff73dbefb0..0da546f37c 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -35,10 +35,11 @@ * * @(#)vfscanf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/vfscanf.c,v 1.35 2004/01/31 23:16:09 das Exp $ - * $DragonFly: src/lib/libc/stdio/vfscanf.c,v 1.6 2005/01/31 22:29:40 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/vfscanf.c,v 1.7 2005/04/21 16:36:35 joerg Exp $ */ #include "namespace.h" +#include #include #include #include diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c index d688b73ba6..c97d63eefe 100644 --- a/lib/libc/stdlib/getopt_long.c +++ b/lib/libc/stdlib/getopt_long.c @@ -1,5 +1,5 @@ /* $NetBSD: getopt_long.c,v 1.16 2003/10/27 00:12:42 lukem Exp $ */ -/* $DragonFly: src/lib/libc/stdlib/getopt_long.c,v 1.12 2005/03/14 14:26:16 joerg Exp $ */ +/* $DragonFly: src/lib/libc/stdlib/getopt_long.c,v 1.13 2005/04/21 16:36:35 joerg Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -193,9 +193,10 @@ start: return -1; } place = nargv[optind]; - if ((*place == '-') && (place[1] == '\0')) + if ((*place == '-') && (place[1] == '\0') && long_support == 0) return -1; - if ((*place != '-')) { + if ((*place != '-') || + ((*place == '-') && (place[1] == '\0') && long_support != 0)) { /* found non-option */ place = EMSG; if (IN_ORDER) { diff --git a/lib/libc/stdtime/Makefile.inc b/lib/libc/stdtime/Makefile.inc index ad6f9fd861..4e7ba291a3 100644 --- a/lib/libc/stdtime/Makefile.inc +++ b/lib/libc/stdtime/Makefile.inc @@ -1,10 +1,10 @@ # Makefile.inc,v 1.2 1994/09/13 21:26:01 wollman Exp # $FreeBSD: src/lib/libc/stdtime/Makefile.inc,v 1.9.2.3 2003/05/23 23:44:27 keramida Exp $ -# $DragonFly: src/lib/libc/stdtime/Makefile.inc,v 1.2 2003/06/17 04:26:46 dillon Exp $ +# $DragonFly: src/lib/libc/stdtime/Makefile.inc,v 1.3 2005/04/21 16:36:35 joerg Exp $ .PATH: ${.CURDIR}/../libc/stdtime ${.CURDIR}/../locale -SRCS+= asctime.c difftime.c localtime.c strftime.c strptime.c timelocal.c +SRCS+= asctime.c difftime.c localtime.c strftime.c strptime.c .if ${LIB} == "c" MAN+= ctime.3 strftime.3 strptime.3 time2posix.3 diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index 98dac67a58..3186aee4ba 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -1,51 +1,108 @@ +/* $NetBSD: src/lib/libc/time/strftime.c,v 1.16 2004/05/12 23:03:11 kleink Exp $ */ +/* $DragonFly: src/lib/libc/stdtime/strftime.c,v 1.5 2005/04/21 16:36:35 joerg Exp $ */ + /* - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * @(#)strftime.c 7.38 - * $FreeBSD: src/lib/libc/stdtime/strftime.c,v 1.25.2.4 2002/03/12 17:24:54 phantom Exp $ - * $DragonFly: src/lib/libc/stdtime/strftime.c,v 1.4 2005/03/16 07:22:07 joerg Exp $ - */ +** Based on the UCB version with the ID appearing below. +** This is ANSIish only when "multibyte character == plain character". +*/ -#include "namespace.h" -#include "private.h" +/* +** We don't use these extensions in strftime operation even when +** supported by the local tzcode configuration. A strictly +** conforming C application may leave them in undefined state. +*/ -#ifndef LIBC_SCCS -#ifndef lint -static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89"; -#endif /* !defined lint */ -#endif /* !defined LIBC_SCCS */ +#ifdef _LIBC +#undef TM_ZONE +#undef TM_GMTOFF +#endif -#include "tzfile.h" +/* +** Copyright (c) 1989, 1993 +** The Regents of the University of California. All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. All advertising materials mentioning features or use of this software +** must display the following acknowledgement: +** This product includes software developed by the University of +** California, Berkeley and its contributors. +** 4. Neither the name of the University nor the names of its contributors +** may be used to endorse or promote products derived from this software +** without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +** ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +** SUCH DAMAGE. +*/ + +#include #include -#include -#include "un-namespace.h" -#include "timelocal.h" +#include +#include + +#include "private.h" +#include "tzfile.h" + +#define Locale _CurrentTimeLocale static char * _add(const char *, char *, const char *); static char * _conv(int, const char *, char *, const char *); -static char * _fmt(const char *, const struct tm *, char *, const char *); +static char * _fmt(const char *, const struct tm *, char *, + const char *, int *); + +#define NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU + +#ifndef YEAR_2000_NAME +#define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS" +#endif /* !defined YEAR_2000_NAME */ + + +#define IN_NONE 0 +#define IN_SOME 1 +#define IN_THIS 2 +#define IN_ALL 3 size_t -strftime(char *const s, const size_t maxsize, const char * const format, +strftime(char * const s, const size_t maxsize, const char * const format, const struct tm * const t) { - char *p; + char * p; + int warn; tzset(); - p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize); + warn = IN_NONE; + p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn); +#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU + if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) { + (void) fprintf(stderr, "\n"); + if (format == NULL) + (void) fprintf(stderr, "NULL strftime format "); + else (void) fprintf(stderr, "strftime format \"%s\" ", + format); + (void) fprintf(stderr, "yields only two digits of years in "); + if (warn == IN_SOME) + (void) fprintf(stderr, "some locales"); + else if (warn == IN_THIS) + (void) fprintf(stderr, "the current locale"); + else (void) fprintf(stderr, "all locales"); + (void) fprintf(stderr, "\n"); + } +#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */ if (p == s + maxsize) return 0; *p = '\0'; @@ -54,40 +111,38 @@ strftime(char *const s, const size_t maxsize, const char * const format, static char * _fmt(const char *format, const struct tm * const t, char *pt, - const char * const ptlim) + const char * const ptlim, int * warnp) { - int Ealternative, Oalternative; - struct lc_time_T *tptr = __get_current_time_locale(); - for ( ; *format; ++format) { if (*format == '%') { - Ealternative = 0; - Oalternative = 0; label: switch (*++format) { case '\0': --format; break; case 'A': - pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ? - "?" : tptr->weekday[t->tm_wday], + pt = _add((t->tm_wday < 0 || + t->tm_wday >= DAYSPERWEEK) ? + "?" : Locale->day[t->tm_wday], pt, ptlim); continue; case 'a': - pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ? - "?" : tptr->wday[t->tm_wday], + pt = _add((t->tm_wday < 0 || + t->tm_wday >= DAYSPERWEEK) ? + "?" : Locale->abday[t->tm_wday], pt, ptlim); continue; case 'B': - pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ? - "?" : (Oalternative ? tptr->alt_month : - tptr->month)[t->tm_mon], + pt = _add((t->tm_mon < 0 || + t->tm_mon >= MONSPERYEAR) ? + "?" : Locale->mon[t->tm_mon], pt, ptlim); continue; case 'b': case 'h': - pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ? - "?" : tptr->mon[t->tm_mon], + pt = _add((t->tm_mon < 0 || + t->tm_mon >= MONSPERYEAR) ? + "?" : Locale->abmon[t->tm_mon], pt, ptlim); continue; case 'C': @@ -102,43 +157,39 @@ label: "%02d", pt, ptlim); continue; case 'c': - pt = _fmt(tptr->c_fmt, t, pt, ptlim); + { + int warn2 = IN_SOME; + + pt = _fmt(Locale->d_t_fmt, t, pt, ptlim, warnp); + if (warn2 == IN_ALL) + warn2 = IN_THIS; + if (warn2 > *warnp) + *warnp = warn2; + } continue; case 'D': - pt = _fmt("%m/%d/%y", t, pt, ptlim); + pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp); continue; case 'd': pt = _conv(t->tm_mday, "%02d", pt, ptlim); continue; case 'E': - if (Ealternative || Oalternative) - break; - Ealternative++; - goto label; case 'O': /* - ** POSIX locale extensions, a la - ** Arnold Robbins' strftime version 3.0. + ** C99 locale modifiers. ** The sequences - ** %Ec %EC %Ex %EX %Ey %EY + ** %Ec %EC %Ex %EX %Ey %EY ** %Od %oe %OH %OI %Om %OM ** %OS %Ou %OU %OV %Ow %OW %Oy ** are supposed to provide alternate ** representations. - ** (ado, 1993-05-24) - ** - ** FreeBSD extensions - ** %OB %Ef %EF */ - if (Ealternative || Oalternative) - break; - Oalternative++; goto label; case 'e': pt = _conv(t->tm_mday, "%2d", pt, ptlim); continue; case 'F': - pt = _fmt("%Y-%m-%d", t, pt, ptlim); + pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp); continue; case 'H': pt = _conv(t->tm_hour, "%02d", pt, ptlim); @@ -196,16 +247,16 @@ label: pt = _add("\n", pt, ptlim); continue; case 'p': - pt = _add((t->tm_hour >= 12) ? - tptr->pm : - tptr->am, + pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ? + Locale->am_pm[1] : + Locale->am_pm[0], pt, ptlim); continue; case 'R': - pt = _fmt("%H:%M", t, pt, ptlim); + pt = _fmt("%H:%M", t, pt, ptlim, warnp); continue; case 'r': - pt = _fmt(tptr->ampm_fmt, t, pt, ptlim); + pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp); continue; case 'S': pt = _conv(t->tm_sec, "%02d", pt, ptlim); @@ -219,6 +270,7 @@ label: tm = *t; mkt = mktime(&tm); + /* CONSTCOND */ if (TYPE_SIGNED(time_t)) (void) sprintf(buf, "%ld", (long) mkt); @@ -228,13 +280,14 @@ label: } continue; case 'T': - pt = _fmt("%H:%M:%S", t, pt, ptlim); + pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp); continue; case 't': pt = _add("\t", pt, ptlim); continue; case 'U': - pt = _conv((t->tm_yday + 7 - t->tm_wday) / 7, + pt = _conv((t->tm_yday + DAYSPERWEEK - + t->tm_wday) / DAYSPERWEEK, "%02d", pt, ptlim); continue; case 'u': @@ -244,7 +297,8 @@ label: ** [1 (Monday) - 7]" ** (ado, 1993-05-24) */ - pt = _conv((t->tm_wday == 0) ? 7 : t->tm_wday, + pt = _conv((t->tm_wday == 0) ? + DAYSPERWEEK : t->tm_wday, "%d", pt, ptlim); continue; case 'V': /* ISO 8601 week number */ @@ -326,6 +380,7 @@ label: pt = _conv(w, "%02d", pt, ptlim); else if (*format == 'g') { + *warnp = IN_ALL; pt = _conv(year % 100, "%02d", pt, ptlim); } else pt = _conv(year, "%04d", @@ -338,24 +393,34 @@ label: ** "date as dd-bbb-YYYY" ** (ado, 1993-05-24) */ - pt = _fmt("%e-%b-%Y", t, pt, ptlim); + pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp); continue; case 'W': - pt = _conv((t->tm_yday + 7 - + pt = _conv((t->tm_yday + DAYSPERWEEK - (t->tm_wday ? - (t->tm_wday - 1) : 6)) / 7, + (t->tm_wday - 1) : + (DAYSPERWEEK - 1))) / DAYSPERWEEK, "%02d", pt, ptlim); continue; case 'w': pt = _conv(t->tm_wday, "%d", pt, ptlim); continue; case 'X': - pt = _fmt(tptr->X_fmt, t, pt, ptlim); + pt = _fmt(Locale->t_fmt, t, pt, ptlim, warnp); continue; case 'x': - pt = _fmt(tptr->x_fmt, t, pt, ptlim); + { + int warn2 = IN_SOME; + + pt = _fmt(Locale->d_fmt, t, pt, ptlim, &warn2); + if (warn2 == IN_ALL) + warn2 = IN_THIS; + if (warn2 > *warnp) + *warnp = warn2; + } continue; case 'y': + *warnp = IN_ALL; pt = _conv((t->tm_year + TM_YEAR_BASE) % 100, "%02d", pt, ptlim); continue; @@ -364,39 +429,112 @@ label: pt, ptlim); continue; case 'Z': - if (t->tm_zone != NULL) - pt = _add(t->tm_zone, pt, ptlim); +#ifdef TM_ZONE + if (t->TM_ZONE != NULL) + pt = _add(t->TM_ZONE, pt, ptlim); else - if (t->tm_isdst == 0 || t->tm_isdst == 1) { - pt = _add(tzname[t->tm_isdst], +#endif /* defined TM_ZONE */ + if (t->tm_isdst >= 0) + pt = _add(tzname[t->tm_isdst != 0], pt, ptlim); - } else pt = _add("?", pt, ptlim); + /* + ** C99 says that %Z must be replaced by the + ** empty string if the time zone is not + ** determinable. + */ continue; case 'z': { - long absoff; - if (t->tm_gmtoff >= 0) { - absoff = t->tm_gmtoff; - pt = _add("+", pt, ptlim); - } else { - absoff = -t->tm_gmtoff; - pt = _add("-", pt, ptlim); - } - pt = _conv(absoff / 3600, "%02d", - pt, ptlim); - pt = _conv((absoff % 3600) / 60, "%02d", - pt, ptlim); - }; + int diff; + char const * sign; + + if (t->tm_isdst < 0) + continue; +#ifdef TM_GMTOFF + diff = (int)t->TM_GMTOFF; +#else /* !defined TM_GMTOFF */ + /* + ** C99 says that the UTC offset must + ** be computed by looking only at + ** tm_isdst. This requirement is + ** incorrect, since it means the code + ** must rely on magic (in this case + ** altzone and timezone), and the + ** magic might not have the correct + ** offset. Doing things correctly is + ** tricky and requires disobeying C99; + ** see GNU C strftime for details. + ** For now, punt and conform to the + ** standard, even though it's incorrect. + ** + ** C99 says that %z must be replaced by the + ** empty string if the time zone is not + ** determinable, so output nothing if the + ** appropriate variables are not available. + */ +#ifndef STD_INSPIRED + if (t->tm_isdst == 0) +#ifdef USG_COMPAT + diff = -timezone; +#else /* !defined USG_COMPAT */ + continue; +#endif /* !defined USG_COMPAT */ + else +#ifdef ALTZONE + diff = -altzone; +#else /* !defined ALTZONE */ + continue; +#endif /* !defined ALTZONE */ +#else /* defined STD_INSPIRED */ + { + struct tm tmp; + time_t lct, gct; + + /* + ** Get calendar time from t + ** being treated as local. + */ + tmp = *t; /* mktime discards const */ + lct = mktime(&tmp); + + if (lct == (time_t)-1) + continue; + + /* + ** Get calendar time from t + ** being treated as GMT. + **/ + tmp = *t; /* mktime discards const */ + gct = timegm(&tmp); + + if (gct == (time_t)-1) + continue; + + /* LINTED difference will fit int */ + diff = (intmax_t)gct - (intmax_t)lct; + } +#endif /* defined STD_INSPIRED */ +#endif /* !defined TM_GMTOFF */ + if (diff < 0) { + sign = "-"; + diff = -diff; + } else sign = "+"; + pt = _add(sign, pt, ptlim); + diff /= 60; + pt = _conv((diff/60)*100 + diff%60, + "%04d", pt, ptlim); + } continue; case '+': - pt = _fmt(tptr->date_fmt, t, pt, ptlim); + pt = _fmt(Locale->d_t_fmt, t, pt, ptlim, + warnp); continue; case '%': /* - * X311J/88-090 (4.12.3.5): if conversion char is - * undefined, behavior is undefined. Print out the - * character itself as printf(3) also does. - */ + ** X311J/88-090 (4.12.3.5): if conversion char is + ** undefined, behavior is undefined. Print out the + ** character itself as printf(3) also does. + */ default: break; } diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index 1fa4dbbc7f..41f6050dac 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -1,31 +1,11 @@ -/* - * Powerdog Industries kindly requests feedback from anyone modifying - * this function: +/* $NetBSD: src/lib/libc/time/strptime.c,v 1.22 2000/12/20 20:56:34 christos Exp $ */ +/* $DragonFly: src/lib/libc/stdtime/strptime.c,v 1.4 2005/04/21 16:36:35 joerg Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. * - * Date: Thu, 05 Jun 1997 23:17:17 -0400 - * From: Kevin Ruddy - * To: James FitzGibbon - * Subject: Re: Use of your strptime(3) code (fwd) - * - * The reason for the "no mod" clause was so that modifications would - * come back and we could integrate them and reissue so that a wider - * audience could use it (thereby spreading the wealth). This has - * made it possible to get strptime to work on many operating systems. - * I'm not sure why that's "plain unacceptable" to the FreeBSD team. - * - * Anyway, you can change it to "with or without modification" as - * you see fit. Enjoy. - * - * Kevin Ruddy - * Powerdog Industries, Inc. - * - * @(#) Copyright (c) 1994 Powerdog Industries. All rights reserved. - * @(#)strptime.c 0.1 (Powerdog) 94/03/27 - * $FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.17.2.3 2002/03/12 17:24:54 phantom Exp $ - * $DragonFly: src/lib/libc/stdtime/strptime.c,v 1.3 2005/01/31 22:29:44 dillon Exp $ - */ -/* - * Copyright (c) 1994 Powerdog Industries. All rights reserved. + * This code was contributed to The NetBSD Foundation by Klaus Klein. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,501 +13,380 @@ * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgement: - * This product includes software developed by Powerdog Industries. - * 4. The name of Powerdog Industries may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE POWERDOG INDUSTRIES BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ -#include "namespace.h" -#include +#include #include -#include -#include +#include #include -#include -#include "un-namespace.h" -#include "libc_private.h" -#include "timelocal.h" +#include +#include "private.h" +#include "tzfile.h" -static char * _strptime(const char *, const char *, struct tm *); +#define _ctloc(x) (_CurrentTimeLocale->x) -static pthread_mutex_t gotgmt_mutex = PTHREAD_MUTEX_INITIALIZER; -static int got_GMT; +/* + * We do not implement alternate representations. However, we always + * check whether a given modifier is allowed for a certain conversion. + */ +#define ALT_E 0x01 +#define ALT_O 0x02 +#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); } -#define asizeof(a) (sizeof (a) / sizeof ((a)[0])) +static int conv_num __P((const unsigned char **, int *, int, int)); -static char * -_strptime(const char *buf, const char *fmt, struct tm *tm) +char * +strptime(const char *buf, const char *fmt, struct tm *tm) { - char c; - const char *ptr; - int i, - len; - int Ealternative, Oalternative; - struct lc_time_T *tptr = __get_current_time_locale(); - - ptr = fmt; - while (*ptr != 0) { - if (*buf == 0) - break; + unsigned char c; + const unsigned char *bp; + size_t len = 0; + int alt_format, i, split_year = 0; + + bp = (const u_char *)buf; - c = *ptr++; + while ((c = *fmt) != '\0') { + /* Clear `alternate' modifier prior to new conversion. */ + alt_format = 0; - if (c != '%') { - if (isspace((unsigned char)c)) - while (*buf != 0 && isspace((unsigned char)*buf)) - buf++; - else if (c != *buf++) - return 0; + /* Eat up white-space. */ + if (isspace(c)) { + while (isspace(*bp)) + bp++; + + fmt++; continue; } + + if ((c = *fmt++) != '%') + goto literal; - Ealternative = 0; - Oalternative = 0; -label: - c = *ptr++; - switch (c) { - case 0: - case '%': - if (*buf++ != '%') - return 0; - break; - case '+': - buf = _strptime(buf, tptr->date_fmt, tm); - if (buf == 0) - return 0; +again: switch (c = *fmt++) { + case '%': /* "%%" is converted to "%". */ +literal: + if (c != *bp++) + return (0); break; - case 'C': - if (!isdigit((unsigned char)*buf)) - return 0; - - /* XXX This will break for 3-digit centuries. */ - len = 2; - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { - i *= 10; - i += *buf - '0'; - len--; - } - if (i < 19) - return 0; - - tm->tm_year = i * 100 - 1900; + /* + * "Alternative" modifiers. Just set the appropriate flag + * and start over again. + */ + case 'E': /* "%E?" alternative conversion modifier. */ + LEGAL_ALT(0); + alt_format |= ALT_E; + goto again; + + case 'O': /* "%O?" alternative conversion modifier. */ + LEGAL_ALT(0); + alt_format |= ALT_O; + goto again; + + /* + * "Complex" conversion rules, implemented through recursion. + */ + case 'c': /* Date and time, using the locale's format. */ + LEGAL_ALT(ALT_E); + if (!(bp = (const u_char *)strptime((const char *)bp, + _ctloc(d_t_fmt), tm))) + return (0); break; - case 'c': - buf = _strptime(buf, tptr->c_fmt, tm); - if (buf == 0) - return 0; + case 'D': /* The date as "%m/%d/%y". */ + LEGAL_ALT(0); + if (!(bp = (const u_char *) strptime((const char *)bp, + "%m/%d/%y", tm))) + return (0); break; - case 'D': - buf = _strptime(buf, "%m/%d/%y", tm); - if (buf == 0) - return 0; + case 'R': /* The time as "%H:%M". */ + LEGAL_ALT(0); + if (!(bp = (const u_char *)strptime((const char *)bp, + "%H:%M", tm))) + return (0); break; - case 'E': - if (Ealternative || Oalternative) - break; - Ealternative++; - goto label; - - case 'O': - if (Ealternative || Oalternative) - break; - Oalternative++; - goto label; - - case 'F': - buf = _strptime(buf, "%Y-%m-%d", tm); - if (buf == 0) - return 0; + case 'r': /* The time in 12-hour clock representation. */ + LEGAL_ALT(0); + if (!(bp = (const u_char *)strptime((const char *)bp, + _ctloc(t_fmt_ampm), tm))) + return (0); break; - case 'R': - buf = _strptime(buf, "%H:%M", tm); - if (buf == 0) - return 0; + case 'T': /* The time as "%H:%M:%S". */ + LEGAL_ALT(0); + if (!(bp = (const u_char *)strptime((const char *)bp, + "%H:%M:%S", tm))) + return (0); break; - case 'r': - buf = _strptime(buf, tptr->ampm_fmt, tm); - if (buf == 0) - return 0; + case 'X': /* The time, using the locale's format. */ + LEGAL_ALT(ALT_E); + if (!(bp = (const u_char *)strptime((const char *)bp, + _ctloc(t_fmt), tm))) + return (0); break; - case 'T': - buf = _strptime(buf, "%H:%M:%S", tm); - if (buf == 0) - return 0; + case 'x': /* The date, using the locale's format. */ + LEGAL_ALT(ALT_E); + if (!(bp = (const u_char *)strptime((const char *)bp, + _ctloc(d_fmt), tm))) + return (0); break; - case 'X': - buf = _strptime(buf, tptr->X_fmt, tm); - if (buf == 0) - return 0; - break; + /* + * "Elementary" conversion rules. + */ + case 'A': /* The day of week, using the locale's form. */ + case 'a': + LEGAL_ALT(0); + for (i = 0; i < 7; i++) { + /* Full name. */ + len = strlen(_ctloc(day[i])); + if (strncasecmp(_ctloc(day[i]), + (const char *)bp, len) == 0) + break; + + /* Abbreviated name. */ + len = strlen(_ctloc(abday[i])); + if (strncasecmp(_ctloc(abday[i]), + (const char *)bp, len) == 0) + break; + } - case 'x': - buf = _strptime(buf, tptr->x_fmt, tm); - if (buf == 0) - return 0; + /* Nothing matched. */ + if (i == 7) + return (0); + + tm->tm_wday = i; + bp += len; break; - case 'j': - if (!isdigit((unsigned char)*buf)) - return 0; + case 'B': /* The month, using the locale's form. */ + case 'b': + case 'h': + LEGAL_ALT(0); + for (i = 0; i < 12; i++) { + /* Full name. */ + len = strlen(_ctloc(mon[i])); + if (strncasecmp(_ctloc(mon[i]), + (const char *)bp, len) == 0) + break; - len = 3; - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { - i *= 10; - i += *buf - '0'; - len--; + /* Abbreviated name. */ + len = strlen(_ctloc(abmon[i])); + if (strncasecmp(_ctloc(abmon[i]), + (const char *)bp, len) == 0) + break; } - if (i < 1 || i > 366) - return 0; - - tm->tm_yday = i - 1; - break; - case 'M': - case 'S': - if (*buf == 0 || isspace((unsigned char)*buf)) - break; + /* Nothing matched. */ + if (i == 12) + return (0); - if (!isdigit((unsigned char)*buf)) - return 0; + tm->tm_mon = i; + bp += len; + break; - len = 2; - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { - i *= 10; - i += *buf - '0'; - len--; - } + case 'C': /* The century number. */ + LEGAL_ALT(ALT_E); + if (!(conv_num(&bp, &i, 0, 99))) + return (0); - if (c == 'M') { - if (i > 59) - return 0; - tm->tm_min = i; + if (split_year) { + tm->tm_year = (tm->tm_year % 100) + (i * 100); } else { - if (i > 60) - return 0; - tm->tm_sec = i; + tm->tm_year = i * 100; + split_year = 1; } + break; - if (*buf != 0 && isspace((unsigned char)*buf)) - while (*ptr != 0 && !isspace((unsigned char)*ptr)) - ptr++; + case 'd': /* The day of month. */ + case 'e': + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) + return (0); break; + case 'k': /* The hour (24-hour clock representation). */ + LEGAL_ALT(0); + /* FALLTHROUGH */ case 'H': + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) + return (0); + break; + + case 'l': /* The hour (12-hour clock representation). */ + LEGAL_ALT(0); + /* FALLTHROUGH */ case 'I': - case 'k': - case 'l': - /* - * Of these, %l is the only specifier explicitly - * documented as not being zero-padded. However, - * there is no harm in allowing zero-padding. - * - * XXX The %l specifier may gobble one too many - * digits if used incorrectly. - */ - if (!isdigit((unsigned char)*buf)) - return 0; - - len = 2; - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { - i *= 10; - i += *buf - '0'; - len--; - } - if (c == 'H' || c == 'k') { - if (i > 23) - return 0; - } else if (i > 12) - return 0; + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) + return (0); + if (tm->tm_hour == 12) + tm->tm_hour = 0; + break; - tm->tm_hour = i; + case 'j': /* The day of year. */ + LEGAL_ALT(0); + if (!(conv_num(&bp, &i, 1, 366))) + return (0); + tm->tm_yday = i - 1; + break; - if (*buf != 0 && isspace((unsigned char)*buf)) - while (*ptr != 0 && !isspace((unsigned char)*ptr)) - ptr++; + case 'M': /* The minute. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_min, 0, 59))) + return (0); break; - case 'p': - /* - * XXX This is bogus if parsed before hour-related - * specifiers. - */ - len = strlen(tptr->am); - if (strncasecmp(buf, tptr->am, len) == 0) { - if (tm->tm_hour > 12) - return 0; - if (tm->tm_hour == 12) - tm->tm_hour = 0; - buf += len; + case 'm': /* The month. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &i, 1, 12))) + return (0); + tm->tm_mon = i - 1; + break; + + case 'p': /* The locale's equivalent of AM/PM. */ + LEGAL_ALT(0); + /* AM? */ + if (strcasecmp(_ctloc(am_pm[0]), + (const char *)bp) == 0) { + if (tm->tm_hour > 11) + return (0); + + bp += strlen(_ctloc(am_pm[0])); break; } - - len = strlen(tptr->pm); - if (strncasecmp(buf, tptr->pm, len) == 0) { - if (tm->tm_hour > 12) - return 0; - if (tm->tm_hour != 12) - tm->tm_hour += 12; - buf += len; + /* PM? */ + else if (strcasecmp(_ctloc(am_pm[1]), + (const char *)bp) == 0) { + if (tm->tm_hour > 11) + return (0); + + tm->tm_hour += 12; + bp += strlen(_ctloc(am_pm[1])); break; } - return 0; + /* Nothing matched. */ + return (0); - case 'A': - case 'a': - for (i = 0; i < asizeof(tptr->weekday); i++) { - len = strlen(tptr->weekday[i]); - if (strncasecmp(buf, tptr->weekday[i], - len) == 0) - break; - len = strlen(tptr->wday[i]); - if (strncasecmp(buf, tptr->wday[i], - len) == 0) - break; - } - if (i == asizeof(tptr->weekday)) - return 0; - - tm->tm_wday = i; - buf += len; + case 'S': /* The seconds. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) + return (0); break; - case 'U': - case 'W': + case 'U': /* The week of year, beginning on sunday. */ + case 'W': /* The week of year, beginning on monday. */ + LEGAL_ALT(ALT_O); /* * XXX This is bogus, as we can not assume any valid * information present in the tm structure at this * point to calculate a real value, so just check the * range for now. */ - if (!isdigit((unsigned char)*buf)) - return 0; - - len = 2; - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { - i *= 10; - i += *buf - '0'; - len--; - } - if (i > 53) - return 0; - - if (*buf != 0 && isspace((unsigned char)*buf)) - while (*ptr != 0 && !isspace((unsigned char)*ptr)) - ptr++; + if (!(conv_num(&bp, &i, 0, 53))) + return (0); + break; + + case 'w': /* The day of week, beginning on sunday. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) + return (0); break; - case 'w': - if (!isdigit((unsigned char)*buf)) - return 0; - - i = *buf - '0'; - if (i > 6) - return 0; - - tm->tm_wday = i; + case 'Y': /* The year. */ + LEGAL_ALT(ALT_E); + if (!(conv_num(&bp, &i, 0, 9999))) + return (0); - if (*buf != 0 && isspace((unsigned char)*buf)) - while (*ptr != 0 && !isspace((unsigned char)*ptr)) - ptr++; + tm->tm_year = i - TM_YEAR_BASE; break; - case 'd': - case 'e': - /* - * The %e specifier is explicitly documented as not - * being zero-padded but there is no harm in allowing - * such padding. - * - * XXX The %e specifier may gobble one too many - * digits if used incorrectly. - */ - if (!isdigit((unsigned char)*buf)) - return 0; - - len = 2; - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { - i *= 10; - i += *buf - '0'; - len--; - } - if (i > 31) - return 0; - - tm->tm_mday = i; - - if (*buf != 0 && isspace((unsigned char)*buf)) - while (*ptr != 0 && !isspace((unsigned char)*ptr)) - ptr++; - break; + case 'y': /* The year within 100 years of the epoch. */ + LEGAL_ALT(ALT_E | ALT_O); + if (!(conv_num(&bp, &i, 0, 99))) + return (0); - case 'B': - case 'b': - case 'h': - for (i = 0; i < asizeof(tptr->month); i++) { - if (Oalternative) { - if (c == 'B') { - len = strlen(tptr->alt_month[i]); - if (strncasecmp(buf, - tptr->alt_month[i], - len) == 0) - break; - } - } else { - len = strlen(tptr->month[i]); - if (strncasecmp(buf, tptr->month[i], - len) == 0) - break; - len = strlen(tptr->mon[i]); - if (strncasecmp(buf, tptr->mon[i], - len) == 0) - break; - } + if (split_year) { + tm->tm_year = ((tm->tm_year / 100) * 100) + i; + break; } - if (i == asizeof(tptr->month)) - return 0; - - tm->tm_mon = i; - buf += len; + split_year = 1; + if (i <= 68) + tm->tm_year = i + 2000 - TM_YEAR_BASE; + else + tm->tm_year = i + 1900 - TM_YEAR_BASE; break; - case 'm': - if (!isdigit((unsigned char)*buf)) - return 0; - - len = 2; - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { - i *= 10; - i += *buf - '0'; - len--; - } - if (i < 1 || i > 12) - return 0; - - tm->tm_mon = i - 1; - - if (*buf != 0 && isspace((unsigned char)*buf)) - while (*ptr != 0 && !isspace((unsigned char)*ptr)) - ptr++; + /* + * Miscellaneous conversions. + */ + case 'n': /* Any kind of white-space. */ + case 't': + LEGAL_ALT(0); + while (isspace(*bp)) + bp++; break; - case 's': - { - char *cp; - time_t t; - - t = strtol(buf, &cp, 10); - if (t == LONG_MAX) - return 0; - buf = cp; - gmtime_r(&t, tm); - got_GMT = 1; - } - break; - case 'Y': - case 'y': - if (*buf == 0 || isspace((unsigned char)*buf)) - break; + default: /* Unknown/unsupported conversion. */ + return (0); + } - if (!isdigit((unsigned char)*buf)) - return 0; - len = (c == 'Y') ? 4 : 2; - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { - i *= 10; - i += *buf - '0'; - len--; - } - if (c == 'Y') - i -= 1900; - if (c == 'y' && i < 69) - i += 100; - if (i < 0) - return 0; - - tm->tm_year = i; - - if (*buf != 0 && isspace((unsigned char)*buf)) - while (*ptr != 0 && !isspace((unsigned char)*ptr)) - ptr++; - break; - - case 'Z': - { - const char *cp; - char *zonestr; - - for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) {/*empty*/} - if (cp - buf) { - zonestr = alloca(cp - buf + 1); - strncpy(zonestr, buf, cp - buf); - zonestr[cp - buf] = '\0'; - tzset(); - if (0 == strcmp(zonestr, "GMT")) { - got_GMT = 1; - } else if (0 == strcmp(zonestr, tzname[0])) { - tm->tm_isdst = 0; - } else if (0 == strcmp(zonestr, tzname[1])) { - tm->tm_isdst = 1; - } else { - return 0; - } - buf += cp - buf; - } - } - break; - } } - return (char *)buf; + + /* LINTED functional specification */ + return ((char *)bp); } -char * -strptime(const char *buf, const char *fmt, struct tm *tm) +static int +conv_num(const unsigned char **buf, int *dest, int llim, int ulim) { - char *ret; + int result = 0; + /* The limit also determines the number of valid digits. */ + int rulim = ulim; - if (__isthreaded) - _pthread_mutex_lock(&gotgmt_mutex); - got_GMT = 0; - ret = _strptime(buf, fmt, tm); - if (ret && got_GMT) { - time_t t = timegm(tm); - localtime_r(&t, tm); - got_GMT = 0; - } + if (**buf < '0' || **buf > '9') + return (0); + + do { + result *= 10; + result += *(*buf)++ - '0'; + rulim /= 10; + } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9'); + + if (result < llim || result > ulim) + return (0); - if (__isthreaded) - _pthread_mutex_unlock(&gotgmt_mutex); - return ret; + *dest = result; + return (1); } diff --git a/lib/libc/stdtime/timelocal.c b/lib/libc/stdtime/timelocal.c index afe07afa3b..639eb2a9b9 100644 --- a/lib/libc/stdtime/timelocal.c +++ b/lib/libc/stdtime/timelocal.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.8.2.4 2002/08/12 11:20:24 ache Exp $ - * $DragonFly: src/lib/libc/stdtime/timelocal.c,v 1.3 2005/01/31 22:29:44 dillon Exp $ + * $DragonFly: src/lib/libc/stdtime/timelocal.c,v 1.4 2005/04/21 16:36:35 joerg Exp $ */ #include "namespace.h" @@ -33,7 +33,6 @@ #include #include "un-namespace.h" -#include "ldpart.h" #include "timelocal.h" static struct lc_time_T _time_locale; diff --git a/share/Makefile b/share/Makefile index e097632762..a8c7052554 100644 --- a/share/Makefile +++ b/share/Makefile @@ -1,10 +1,10 @@ # @(#)Makefile 8.1 (Berkeley) 6/5/93 # $FreeBSD: src/share/Makefile,v 1.22.2.4 2002/03/12 17:13:32 phantom Exp $ -# $DragonFly: src/share/Makefile,v 1.3 2005/03/13 18:05:53 joerg Exp $ +# $DragonFly: src/share/Makefile,v 1.4 2005/04/21 16:36:35 joerg Exp $ # Do not include `info' in the SUBDIR list, it is handled separately. -SUBDIR= colldef dict examples man me misc mk mklocale monetdef \ +SUBDIR= colldef dict examples i18n locale man me misc mk monetdef \ msgdef numericdef skel syscons tabset termcap timedef zoneinfo .if !defined(NO_I4B) diff --git a/share/mk/bsd.nls.mk b/share/mk/bsd.nls.mk index 2820daec90..3f626888a0 100644 --- a/share/mk/bsd.nls.mk +++ b/share/mk/bsd.nls.mk @@ -1,5 +1,5 @@ # $FreeBSD: src/share/mk/bsd.nls.mk,v 1.11 2005/02/27 16:36:54 phantom Exp $ -# $DragonFly: src/share/mk/bsd.nls.mk,v 1.2 2005/04/12 23:35:37 okumoto Exp $ +# $DragonFly: src/share/mk/bsd.nls.mk,v 1.3 2005/04/21 16:36:35 joerg Exp $ # # This include file handles building and installing Native # Language Support (NLS) catalogs @@ -26,7 +26,7 @@ .error bsd.nls.mk cannot be included directly. .endif -GENCAT?= gencat -new +GENCAT?= gencat .SUFFIXES: .cat .msg diff --git a/share/nls/Makefile b/share/nls/Makefile new file mode 100644 index 0000000000..e8178a86e3 --- /dev/null +++ b/share/nls/Makefile @@ -0,0 +1,7 @@ +# $DragonFly: src/share/nls/Makefile,v 1.1 2005/04/21 16:36:35 joerg Exp $ + +NOOBJ= nobj +FILES= nls.alias +FILESDIR= /usr/share/nls + +.include diff --git a/share/nls/nls.alias b/share/nls/nls.alias new file mode 100644 index 0000000000..4450bacc25 --- /dev/null +++ b/share/nls/nls.alias @@ -0,0 +1,75 @@ +# $NetBSD: src/share/nls/nls.alias,v 1.3 2003/04/14 05:21:51 salo Exp $ +# $DragonFly: src/share/nls/nls.alias,v 1.1 2005/04/21 16:36:35 joerg Exp $ +# +# This file defines aliase names of nls catalogs. +# Syntax is similar to X11's locale.alias. +# (The first word is an alias name and the second +# one is nls catalog name.) + +ca_ES.ISO8859-1 ca +ca_ES.ISO8859-15 ca +cs_CZ.ISO8859-2 cs +#da_DK.ISO8859-1 da +#da_DK.ISO8859-15 da +de_AT.ISO8859-1 de +de_AT.ISO8859-15 de +de_CH.ISO8859-1 de +de_CH.ISO8859-15 de +de_DE.ISO8859-1 de +de_DE.ISO8859-15 de +#en_AU.ISO8859-1 en +#en_AU.ISO8859-15 en +#en_CA.ISO8859-1 en +#en_CA.ISO8859-15 en +#en_GB.ISO8859-1 en +#en_GB.ISO8859-15 en +#en_US.ISO8859-1 en +#en_US.ISO8859-15 en +#en_US.UTF-8 en +es_ES.ISO8859-1 es +es_ES.ISO8859-15 es +fi_FI.ISO8859-1 fi +fi_FI.ISO8859-15 fi +fr_BE.ISO8859-1 fr +fr_BE.ISO8859-15 fr +fr_CA.ISO8859-1 fr +fr_CA.ISO8859-15 fr +fr_CH.ISO8859-1 fr +fr_CH.ISO8859-15 fr +fr_FR.ISO8859-1 fr +fr_FR.ISO8859-15 fr +#hr_HR.ISO8859-2 hr +#hu_HU.ISO8859-2 hu +#is_IS.ISO8859-1 is +#is_IS.ISO8859-15 is +#it_CH.ISO8859-1 it +#it_CH.ISO8859-15 it +#it_IT.ISO8859-1 it +#it_IT.ISO8859-15 it +#ja_JP.ISO2022-JP ja +#ja_JP.ISO2022-JP2 ja +#ja_JP.SJIS ja +#ja_JP.ct ja +#ja_JP.eucJP ja +#ko_KR.eucKR ko +#lt_LT.ISO8859-4 lt +nl_BE.ISO8859-1 nl +nl_BE.ISO8859-15 nl +nl_NL.ISO8859-1 nl +nl_NL.ISO8859-15 nl +no_NO.ISO8859-1 no +no_NO.ISO8859-15 no +pl_PL.ISO8859-2 pl +#pt_PT.ISO8859-1 pt +#pt_PT.ISO8859-15 pt +#ru_RU.CP866 ru +#ru_RU.ISO8859-5 ru +#ru_RU.KOI8-R ru +#sl_SI.ISO8859-2 sl +sk_SK.ISO8859-2 sk +sv_SE.ISO8859-1 sv +sv_SE.ISO8859-15 sv +#uk_UA.KOI8-U uk +#zh_CN.eucCN zh +#zh_TW.Big5 zh +#zh_TW.eucTW zh diff --git a/sys/cpu/i386/include/stdint.h b/sys/cpu/i386/include/stdint.h index 2aa442f7c0..78905cd592 100644 --- a/sys/cpu/i386/include/stdint.h +++ b/sys/cpu/i386/include/stdint.h @@ -36,7 +36,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/_stdint.h,v 1.1 2002/07/29 17:41:07 mike Exp $ - * $DragonFly: src/sys/cpu/i386/include/stdint.h,v 1.1 2003/11/09 02:22:35 dillon Exp $ + * $DragonFly: src/sys/cpu/i386/include/stdint.h,v 1.2 2005/04/21 16:36:35 joerg Exp $ */ #ifndef _MACHINE_STDINT_H_ @@ -67,15 +67,6 @@ typedef long long __int64_t; typedef unsigned long long __uint64_t; #endif -/* - * mbstate_t is an opaque object to keep conversion state, during multibyte - * stream conversions. The content must not be referenced by user programs. - */ -typedef union { - char __mbstate8[128]; - __int64_t _mbstateL; /* for alignment */ -} __mbstate_t; - /* * Standard type definitions. */ diff --git a/sys/i386/include/stdint.h b/sys/i386/include/stdint.h index bfd8e8ec95..9d07afe47f 100644 --- a/sys/i386/include/stdint.h +++ b/sys/i386/include/stdint.h @@ -36,7 +36,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/_stdint.h,v 1.1 2002/07/29 17:41:07 mike Exp $ - * $DragonFly: src/sys/i386/include/Attic/stdint.h,v 1.1 2003/11/09 02:22:35 dillon Exp $ + * $DragonFly: src/sys/i386/include/Attic/stdint.h,v 1.2 2005/04/21 16:36:35 joerg Exp $ */ #ifndef _MACHINE_STDINT_H_ @@ -67,15 +67,6 @@ typedef long long __int64_t; typedef unsigned long long __uint64_t; #endif -/* - * mbstate_t is an opaque object to keep conversion state, during multibyte - * stream conversions. The content must not be referenced by user programs. - */ -typedef union { - char __mbstate8[128]; - __int64_t _mbstateL; /* for alignment */ -} __mbstate_t; - /* * Standard type definitions. */ diff --git a/sys/sys/localedef.h b/sys/sys/localedef.h index f17b0cd2be..9599ee7d00 100644 --- a/sys/sys/localedef.h +++ b/sys/sys/localedef.h @@ -1,5 +1,5 @@ /* $NetBSD: src/sys/sys/localedef.h,v 1.6 2002/11/19 09:53:16 junyoung Exp $ */ -/* $DragonFly: src/sys/sys/localedef.h,v 1.1 2005/03/16 06:42:34 joerg Exp $ */ +/* $DragonFly: src/sys/sys/localedef.h,v 1.2 2005/04/21 16:36:35 joerg Exp $ */ /* * Copyright (c) 1994 Winning Strategies, Inc. @@ -94,6 +94,7 @@ typedef struct { const char *d_fmt; const char *t_fmt; const char *t_fmt_ampm; + const char *date_fmt; } _TimeLocale; extern const _TimeLocale *_CurrentTimeLocale; diff --git a/sys/sys/stdint.h b/sys/sys/stdint.h index be5c837cae..7defe7dad6 100644 --- a/sys/sys/stdint.h +++ b/sys/sys/stdint.h @@ -1,7 +1,7 @@ /* * This file is in the public domain. * $FreeBSD: src/sys/sys/inttypes.h,v 1.2 1999/08/28 00:51:47 peter Exp $ - * $DragonFly: src/sys/sys/stdint.h,v 1.2 2003/11/19 00:42:30 dillon Exp $ + * $DragonFly: src/sys/sys/stdint.h,v 1.3 2005/04/21 16:36:35 joerg Exp $ * * Note: since portions of these header files can be included with various * other combinations of defines, we cannot surround the whole header file @@ -14,30 +14,37 @@ #ifndef _SYS_STDINT_H_ #define _SYS_STDINT_H_ -typedef int __ct_rune_t; -typedef __ct_rune_t __rune_t; +/* + * wchar_t and rune_t have to be of the same type. rune_t is meant + * for internal use only. + * + * wchar_t, wint_t and rune_t are signed, to allow EOF (-1) to naturally + * assigned. + * + * ANSI specifies ``int'' as argument for the is*() and to*() routines. + * Keeping wchar_t and rune_t as ``int'' instead of the more natural + * ``long'' helps ANSI conformance. ISO 10646 will most likely end up + * as 31 bit standard and all supported architectures have + * sizeof(int) >= 4. + */ #ifndef __cplusplus -typedef __ct_rune_t __wchar_t; +typedef int __wchar_t; #endif -typedef __ct_rune_t __wint_t; +typedef int __wint_t; +typedef int __rune_t; +typedef void *__wctrans_t; +typedef void *__wctype_t; + +/* + * mbstate_t is an opaque object to keep conversion state, during multibyte + * stream conversions. The content must not be referenced by user programs. + */ +typedef union { + __uint8_t __mbstate8[128]; + __int64_t __mbstateL; /* for alignment */ +} __mbstate_t; + typedef __int64_t __off_t; typedef __int32_t __pid_t; #endif /* SYS_STDINT_H */ - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) -#ifndef _SYS_STDINT_H_STDC_LIMIT_MACROS_ -#define _SYS_STDINT_H_STDC_LIMIT_MACROS_ - -#ifndef WCHAR_MIN /* Also possibly defined in */ -/* Limits of wchar_t. */ -#define WCHAR_MIN INT32_MIN -#define WCHAR_MAX INT32_MAX - -/* Limits of wint_t. */ -#define WINT_MIN INT32_MIN -#define WINT_MAX INT32_MAX -#endif - -#endif /* STDINT_H_STDC_LIMIT_MACROS */ -#endif /* STDC_LIMIT_MACROS */ diff --git a/usr.bin/Makefile b/usr.bin/Makefile index d586bb829d..0bb7fcfe7c 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -1,6 +1,6 @@ # From: @(#)Makefile 8.3 (Berkeley) 1/7/94 # $FreeBSD: src/usr.bin/Makefile,v 1.144.2.17 2003/01/04 17:17:07 obrien Exp $ -# $DragonFly: src/usr.bin/Makefile,v 1.28 2005/03/08 01:54:59 hmp Exp $ +# $DragonFly: src/usr.bin/Makefile,v 1.29 2005/04/21 16:36:35 joerg Exp $ # XXX MISSING: deroff diction graph learn plot # spell spline struct xsend @@ -68,6 +68,7 @@ SUBDIR= alias \ gzip \ head \ hexdump \ + iconv \ id \ indent \ ipcrm \ diff --git a/usr.bin/gencat/Makefile b/usr.bin/gencat/Makefile index ce9514063b..45270403c8 100644 --- a/usr.bin/gencat/Makefile +++ b/usr.bin/gencat/Makefile @@ -1,9 +1,15 @@ # $FreeBSD: src/usr.bin/gencat/Makefile,v 1.5 1999/08/28 01:01:40 peter Exp $ -# $DragonFly: src/usr.bin/gencat/Makefile,v 1.2 2003/06/17 04:29:27 dillon Exp $ +# $DragonFly: src/usr.bin/gencat/Makefile,v 1.3 2005/04/21 16:36:35 joerg Exp $ PROG= gencat -SRCS= gencat.c genlib.c +SRCS= gencat.c -CFLAGS+= -I${.CURDIR}/../../lib/libc/nls +.if defined(BOOTSTRAPPING) +nl_types.h: ../../include/nl_types.h + cp ${.CURDIR}/../../include/nl_types.h ${.TARGET} +SRCS+= nl_types.h +CFLAGS+= -I${.OBJDIR} +CLEANFILES+= nl_types.h +.endif .include diff --git a/usr.bin/gencat/gencat.1 b/usr.bin/gencat/gencat.1 index 1290036ca5..3dd828659a 100644 --- a/usr.bin/gencat/gencat.1 +++ b/usr.bin/gencat/gencat.1 @@ -1,178 +1,112 @@ -.\" $OpenBSD: gencat.1,v 1.3 1997/06/11 15:39:54 kstailey Exp $ +.\" $NetBSD: src/usr.bin/gencat/gencat.1,v 1.8 2003/05/02 08:35:42 gmcgarry Exp $ +.\" $DragonFly: src/usr.bin/gencat/gencat.1,v 1.3 2005/04/21 16:36:35 joerg Exp $ .\" -.\" Copyright (c) 1997 Ken Stailey +.\" Written by Kee Hinckley .\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD: src/usr.bin/gencat/gencat.1,v 1.4.2.5 2001/12/14 15:53:30 ru Exp $ -.\" $DragonFly: src/usr.bin/gencat/gencat.1,v 1.2 2003/06/17 04:29:27 dillon Exp $ -.\" -.Dd June 11, 1997 -.Dt GENCAT 1 +.Dd April 29, 1999 .Os +.Dt GENCAT 1 .Sh NAME .Nm gencat -.Nd NLS catalog compiler +.Nd generates a Native Language Support (NLS) message catalog file .Sh SYNOPSIS .Nm -.Ar "output-file" -.Ar "input-files..." +.Op Fl \&? +.Ar catalog-file +.Ar message-file +.Op Ar message-file ... .Sh DESCRIPTION The .Nm -utility merges the text NLS input files -.Ar "input-files..." -into a formatted message catalog file -.Ar "output-file" . -The file -.Ar "output-file" -will be created if it does not already exist. If -.Ar "output-file" -does exist, its messages will be included in the new -.Ar "output-file" . -If set and message numbers collide, the new message text defined in -.Ar "input-files..." -will replace the old message text currently contained in -.Ar "output-file" . -.Sh INPUT FILES -The format of a message text source file is defined below. Note that -the fields of a message text source line are separated by a single space -character: any other space characters are considered to be part of the -field contents. +command reads one or more files containing message strings that will +be displayed using the +.Xr catgets 3 +library call. +From these files it generates a message catalog which +is loaded dynamically by the Native Language Support (NLS) library at run time. .Pp -.Bl -tag -width 3n -.It Li $set Ar n comment -This line specifies the set identifier of the following messages until -the next -.Li $set -or end-of-file appears. The argument -.Ar n -is the set identifier which is defined as a number in the range -[1, (NL_SETMAX)]. Set identifiers must occur in ascending order within -a single source file, but need not be contiguous. Any string following -a space following the set identifier is treated as a comment. If no -.Li $set -directive is specified in a given source file, all messages will -be located in the default message set NL_SETD. -.It Li $del Ar n comment -This line deletes messages from set -.Ar n -from a message catalog. The -.Ar n -specifies a set number. Any string following a space following the set -number is treated as a comment. -.It Li $ Ar comment -A line beginning with -.Li $ -followed by a space is treated as a comment. -.It Ar m message-text -A message line consists of a message identifier -.Ar m -in the range [1, (NL_MSGMAX)]. The -.Ar message-text -is stored in the message catalog with the set identifier specified by -the last -.Li $set -directive, and the message identifier -.Ar m . -If the -.Ar message-text -is empty, and there is a space character following the message identifier, -an empty string is stored in the message catalog. If the -.Ar message-text -is empty, and if there is no space character following the message -identifier, then the existing message in the current set with the -specified message identifier is deleted from the catalog. Message -identifiers must be in ascending order within a single set, but -need not be contiguous. The -.Ar message-text -length must be in the range [0, (NL_TEXTMAX)]. -.It Li $quote Ar c -This line specifies an optional quote character -.Ar c -which can be used to surround -.Ar message-text -so that trailing space or empty messages are visible in message -source files. By default, or if an empty -.Li $quote -directive is specified, no quoting of -.Ar message-text -will be recognized. -.El +The message description files are text files in the format described below. .Pp -Empty lines in message source files are ignored. The effect of lines -beginning with any character other than those described above is -undefined. +The message catalog file is a binary file. +If it already exists, it will be truncated when +.Nm +is run. .Pp -Text strings can contain the following special characters and escape -sequences. In addition, if a quote character is defined, it may be -escaped as well to embed a literal quote character. +Error messages are grouped into sets, and a program can load a +particular set depending on which type, or language, of messages +is desired. .Pp -.Bl -tag -width "\eooo" -offset indent -compact -.It Li \en -line feed -.It Li \et -horizontal tab -.It Li \ev -vertical tab -.It Li \eb -backspace -.It Li \er -carriage return -.It Li \ef -form feed -.It Li \e\e -backslash -.It Li \eooo -octal number in the range [000, 377] -.El +The +.Fl \&? +option flag prints the usage message. +.Sh MESSAGE FILE FORMAT +Empty lines and leading blanks are ignored. +.Bl -tag -width "NN message" +.It Em "$set NN" +Determines the set to be used for all subsequent messages. +.Ar "NN" +is an integer greater than 0. +.It Em "$delset NN" +Removes a set from the catalog. +.Ar "NN" +is an integer greater than 0. +.Pp +If a set was created earlier in the +current file, or in a file previously read by the +.Nm +command, this command will remove it. +.It Em "$quote C" +Sets a quote character to be used around the messages. +.Ar "C" +may be any character other than white space. .Pp -A backslash character immediately before the end of the line in a file -is used to continue the line onto the next line, e.g.: +If this is specified, then messages must begin and end with the +quote character. +By default no quote character is used. +If none is specified, then the current quote character is unset. +This is useful when messages must contain leading white space. +.It Em "NN message" +Defines a message. +.Ar "NN" +is an integer greater than 0. .Pp -.Dl 1 This line is continued \e -.Dl on this line. +The message is read until the end of the line or a quote character (if one is +specified). +If no message is provided, the message with the number +.Ar "NN" +is removed from the catalog. +If no "set" has been created, this command generates an error. +.El .Pp -If the character following the backslash is not one of those specified, -the backslash is ignored. -.Sh DIAGNOSTICS -.Ex -std +Messages may contain any characters, however the "\\" +is special as an escape character, where the following instances +are allowed: +.Pp +.Bd -literal -offset indent +\&\\\\ Generates a single backslash. +\&\\n Generates a newline (as defined by the C compiler). +\&\\t Generates a tab (as defined by the C compiler). +\&\\v Generates a vertical tab (as defined by the C compiler). +\&\\b Generates a backspace (as defined by the C compiler). +\&\\r Generates a carriage return (as defined by the C compiler). +\&\\f Generates a form feed (as defined by the C compiler). +\&\\NNN Generates the character corresponding to the specified + octal number. +\&\\EOL A backslash at the end of line continues the message onto + the next line. +\&\\quote A backslash preceding the current quote character generates + the quote character. +.Ed .Sh SEE ALSO .Xr catclose 3 , .Xr catgets 3 , -.Xr catopen 3 -.Sh STANDARDS -The -.Nm -utility is compliant with the -.St -xpg4 -standard. +.Xr catopen 3 , +.Xr nls 7 .Sh AUTHORS -.An -nosplit -This manual page was originally written by -.An Ken Stailey -and later revised by -.An Terry Lambert . -.Sh BUGS -A message catalog file created from a blank input file cannot be revised; -it must be deleted and recreated. +The Native Language Support (NLS) message catalog facility was +contributed by +.An J.T. Conklin +.Aq jtc@NetBSD.org . +This page was written by +.An Kee Hinckley +.Aq nazgul@somewhere.com . diff --git a/usr.bin/gencat/gencat.c b/usr.bin/gencat/gencat.c index afda5aecab..99ae51ca3b 100644 --- a/usr.bin/gencat/gencat.c +++ b/usr.bin/gencat/gencat.c @@ -1,5 +1,41 @@ -/* $FreeBSD: src/usr.bin/gencat/gencat.c,v 1.5.2.1 2001/12/17 12:09:35 phantom Exp $ */ -/* $DragonFly: src/usr.bin/gencat/gencat.c,v 1.2 2003/06/17 04:29:27 dillon Exp $ */ +/* $NetBSD: src/usr.bin/gencat/gencat.c,v 1.19 2004/01/05 23:23:34 jmmv Exp $ */ +/* $DragonFly: src/usr.bin/gencat/gencat.c,v 1.3 2005/04/21 16:36:35 joerg Exp $ */ + +/* + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by J.T. Conklin. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ /*********************************************************** Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts. @@ -34,167 +70,752 @@ up-to-date. Many thanks. ******************************************************************/ #include -#include -#include +#include + +#include + +#include #include +#include +#include #include #include #include #include -#include "gencat.h" -/* - * The spec says the syntax is "gencat catfile msgfile...". - * We extend it to: - * gencat [-lang C|C++|ANSIC] catfile msgfile [-h ]... - * Flags are order dependant, we'll take whatever lang was most recently chosen - * and use it to generate the next header file. The header files are generated - * at the point in the command line they are listed. Thus the sequence: - * gencat -lang C foo.cat foo.mcs -h foo.h -lang C++ bar.mcs -h bar.H - * will put constants from foo.mcs into foo.h and constants from bar.mcs into - * bar.h. Constants are not saved in the catalog file, so nothing will come - * from that, even if things have been defined before. The constants in foo.h - * will be in C syntax, in bar.H in C++ syntax. - */ +#define _NLS_PRIVATE +#include -static void writeIfChanged(char *, int, int); +#ifndef NL_SETMAX +#define NL_SETMAX 255 +#endif +#ifndef NL_MSGMAX +#define NL_MSGMAX 2048 +#endif -static void -usage(void) +struct _msgT { + long msgId; + char *str; + LIST_ENTRY(_msgT) entries; +}; + +struct _setT { + long setId; + LIST_HEAD(msghead, _msgT) msghead; + LIST_ENTRY(_setT) entries; +}; + +LIST_HEAD(sethead, _setT) sethead; +static struct _setT *curSet; + +static char *curline = NULL; +static long lineno = 0; + +static char *cskip(char *); +static void error(char *, char *); +static void nomem(void); +static char *getline(int); +static char *getmsg(int, char *, char); +static void warning(char *, char *); +static char *wskip(char *); +static char *xstrdup(const char *); +static void *xmalloc(size_t); +static void *xrealloc(void *, size_t); + +void MCParse __P((int fd)); +void MCReadCat __P((int fd)); +void MCWriteCat __P((int fd)); +void MCDelMsg __P((int msgId)); +void MCAddMsg __P((int msgId, const char *msg)); +void MCAddSet __P((int setId)); +void MCDelSet __P((int setId)); +int main __P((int, char **)); +void usage __P((void)); + + +void +usage() { - fprintf(stderr, "usage: gencat [-new] [-or] [-lang C|C++|ANSIC]\n" - " catfile msgfile [-h ]...\n"); - exit(1); + fprintf(stderr, "usage: %s catfile msgfile ...\n", getprogname()); + exit(1); } int -main(int argc, char *argv[]) -{ - int ofd, ifd, i; - char *catfile = NULL; - char *input = NULL; - int lang = MCLangC; - int new = FALSE; - int orConsts = FALSE; - - for (i = 1; i < argc; ++i) { - if (argv[i][0] == '-') { - if (strcmp(argv[i], "-lang") == 0) { - ++i; - if (strcmp(argv[i], "C") == 0) lang = MCLangC; - else if (strcmp(argv[i], "C++") == 0) lang = MCLangCPlusPlus; - else if (strcmp(argv[i], "ANSIC") == 0) lang = MCLangANSIC; - else { - errx(1, "unrecognized language: %s", argv[i]); +main(argc, argv) + int argc; + char *argv[]; +{ + int ofd, ifd; + char *catfile = NULL; + int c; + + while ((c = getopt(argc, argv, "")) != -1) { + switch (c) { + case '?': + default: + usage(); + /* NOTREACHED */ } - } else if (strcmp(argv[i], "-h") == 0) { - if (!input) - errx(1, "can't write to a header before reading something"); - ++i; - writeIfChanged(argv[i], lang, orConsts); - } else if (strcmp(argv[i], "-new") == 0) { - if (catfile) - errx(1, "you must specify -new before the catalog file name"); - new = TRUE; - } else if (strcmp(argv[i], "-or") == 0) { - orConsts = ~orConsts; - } else { + } + argc -= optind; + argv += optind; + + if (argc < 2) { usage(); - } - } else { - if (!catfile) { - catfile = argv[i]; - if (new) { - if ((ofd = open(catfile, O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) - errx(1, "unable to create a new %s", catfile); - } else if ((ofd = open(catfile, O_RDONLY)) < 0) { - if ((ofd = open(catfile, O_WRONLY|O_CREAT, 0666)) < 0) - errx(1, "unable to create %s", catfile); - } else { - MCReadCat(ofd); - close(ofd); - if ((ofd = open(catfile, O_WRONLY|O_TRUNC)) < 0) - errx(1, "unable to truncate %s", catfile); - } - } else { - input = argv[i]; - if ((ifd = open(input, O_RDONLY)) < 0) - errx(1, "unable to read %s", input); + /* NOTREACHED */ + } + catfile = *argv++; + + for (; *argv; argv++) { + if ((ifd = open(*argv, O_RDONLY)) < 0) + err(1, "Unable to read %s", *argv); MCParse(ifd); close(ifd); - } } - } - if (catfile) { + + if ((ofd = open(catfile, O_WRONLY | O_TRUNC | O_CREAT, 0666)) < 0) + err(1, "Unable to create a new %s", catfile); MCWriteCat(ofd); exit(0); - } else { - usage(); - } - return 0; } static void -writeIfChanged(char *fname, int lang, int orConsts) -{ - char tmpname[32]; - char buf[BUFSIZ], tbuf[BUFSIZ], *cptr, *tptr; - int fd, tfd; - int diff = FALSE; - int len, tlen; - struct stat sbuf; - - /* If it doesn't exist, just create it */ - if (stat(fname, &sbuf)) { - if ((fd = open(fname, O_WRONLY|O_CREAT, 0666)) < 0) - errx(1, "unable to create header file %s", fname); - MCWriteConst(fd, lang, orConsts); - close(fd); - return; - } - - /* If it does exist, create a temp file for now */ - sprintf(tmpname, "/tmp/gencat.%d", (int) getpid()); - if ((tfd = open(tmpname, O_RDWR|O_CREAT, 0666)) < 0) - errx(1, "unable to open temporary file: %s", tmpname); - unlink(tmpname); - - /* Write to the temp file and rewind */ - MCWriteConst(tfd, lang, orConsts); - - /* Open the real header file */ - if ((fd = open(fname, O_RDONLY)) < 0) - errx(1, "unable to read header file: %s", fname); - - /* Backup to the start of the temp file */ - if (lseek(tfd, (off_t)0, L_SET) < 0) - errx(1, "unable to seek in tempfile: %s", tmpname); - - /* Now compare them */ - while ((tlen = read(tfd, tbuf, BUFSIZ)) > 0) { - if ((len = read(fd, buf, BUFSIZ)) != tlen) { - diff = TRUE; - goto done; - } - for (cptr = buf, tptr = tbuf; cptr < buf+len; ++cptr, ++tptr) { - if (*tptr != *cptr) { - diff = TRUE; - goto done; - } - } - } -done: - if (diff) { - if (lseek(tfd, (off_t)0, L_SET) < 0) - errx(1, "unable to seek in tempfile: %s", tmpname); - close(fd); - if ((fd = open(fname, O_WRONLY|O_TRUNC)) < 0) - errx(1, "unable to truncate header file: %s", fname); - while ((len = read(tfd, buf, BUFSIZ)) > 0) { - if (write(fd, buf, (size_t)len) != len) - warnx("error writing to header file: %s", fname); - } - } - close(fd); - close(tfd); +warning(cptr, msg) + char *cptr; + char *msg; +{ + fprintf(stderr, "%s: %s on line %ld\n", getprogname(), msg, lineno); + fprintf(stderr, "%s\n", curline); + if (cptr) { + char *tptr; + for (tptr = curline; tptr < cptr; ++tptr) + putc(' ', stderr); + fprintf(stderr, "^\n"); + } +} + +static void +error(cptr, msg) + char *cptr; + char *msg; +{ + warning(cptr, msg); + exit(1); +} + +#if 0 /* XXX unused */ +static void +corrupt() +{ + error(NULL, "corrupt message catalog"); +} +#endif + +static void +nomem() +{ + error(NULL, "out of memory"); +} + +static void * +xmalloc(len) + size_t len; +{ + void *p; + + if ((p = malloc(len)) == NULL) + nomem(); + return (p); +} + +static void * +xrealloc(ptr, size) + void *ptr; + size_t size; +{ + if ((ptr = realloc(ptr, size)) == NULL) + nomem(); + return (ptr); +} + +static char * +xstrdup(str) + const char *str; +{ + char *nstr; + + if ((nstr = strdup(str)) == NULL) + nomem(); + return (nstr); +} + +static char * +getline(fd) + int fd; +{ + static long curlen = BUFSIZ; + static char buf[BUFSIZ], *bptr = buf, *bend = buf; + char *cptr, *cend; + long buflen; + + if (!curline) { + curline = xmalloc(curlen); + } + ++lineno; + + cptr = curline; + cend = curline + curlen; + for (;;) { + for (; bptr < bend && cptr < cend; ++cptr, ++bptr) { + if (*bptr == '\n') { + *cptr = '\0'; + ++bptr; + return (curline); + } else + *cptr = *bptr; + } + if (cptr == cend) { + cptr = curline = xrealloc(curline, curlen *= 2); + cend = curline + curlen; + } + if (bptr == bend) { + buflen = read(fd, buf, BUFSIZ); + if (buflen <= 0) { + if (cptr > curline) { + *cptr = '\0'; + return (curline); + } + return (NULL); + } + bend = buf + buflen; + bptr = buf; + } + } +} + +static char * +wskip(cptr) + char *cptr; +{ + if (!*cptr || !isspace((unsigned char) *cptr)) { + warning(cptr, "expected a space"); + return (cptr); + } + while (*cptr && isspace((unsigned char) *cptr)) + ++cptr; + return (cptr); +} + +static char * +cskip(cptr) + char *cptr; +{ + if (!*cptr || isspace((unsigned char) *cptr)) { + warning(cptr, "wasn't expecting a space"); + return (cptr); + } + while (*cptr && !isspace((unsigned char) *cptr)) + ++cptr; + return (cptr); +} + +static char * +getmsg(fd, cptr, quote) + int fd; + char *cptr; + char quote; +{ + static char *msg = NULL; + static long msglen = 0; + long clen, i; + char *tptr; + + if (quote && *cptr == quote) { + ++cptr; + } + + clen = strlen(cptr) + 1; + if (clen > msglen) { + if (msglen) + msg = xrealloc(msg, clen); + else + msg = xmalloc(clen); + msglen = clen; + } + tptr = msg; + + while (*cptr) { + if (quote && *cptr == quote) { + char *tmp; + tmp = cptr + 1; + if (*tmp && (!isspace((unsigned char) *tmp) || *wskip(tmp))) { + warning(cptr, "unexpected quote character, ignoring"); + *tptr++ = *cptr++; + } else { + *cptr = '\0'; + } + } else + if (*cptr == '\\') { + ++cptr; + switch (*cptr) { + case '\0': + cptr = getline(fd); + if (!cptr) + error(NULL, "premature end of file"); + msglen += strlen(cptr); + i = tptr - msg; + msg = xrealloc(msg, msglen); + tptr = msg + i; + break; + case 'n': + *tptr++ = '\n'; + ++cptr; + break; + case 't': + *tptr++ = '\t'; + ++cptr; + break; + case 'v': + *tptr++ = '\v'; + ++cptr; + break; + case 'b': + *tptr++ = '\b'; + ++cptr; + break; + case 'r': + *tptr++ = '\r'; + ++cptr; + break; + case 'f': + *tptr++ = '\f'; + ++cptr; + break; + case '\\': + *tptr++ = '\\'; + ++cptr; + break; + default: + if (quote && *cptr == quote) { + *tptr++ = *cptr++; + } else if (isdigit((unsigned char) *cptr)) { + *tptr = 0; + for (i = 0; i < 3; ++i) { + if (!isdigit((unsigned char) *cptr)) + break; + if (*cptr > '7') + warning(cptr, "octal number greater than 7?!"); + *tptr *= 8; + *tptr += (*cptr - '0'); + ++cptr; + } + } else { + warning(cptr, "unrecognized escape sequence"); + } + break; + } + } else { + *tptr++ = *cptr++; + } + } + *tptr = '\0'; + return (msg); +} + +void +MCParse(fd) + int fd; +{ + char *cptr, *str; + int setid, msgid = 0; + char quote = 0; + + /* XXX: init sethead? */ + + while ((cptr = getline(fd))) { + if (*cptr == '$') { + ++cptr; + if (strncmp(cptr, "set", 3) == 0) { + cptr += 3; + cptr = wskip(cptr); + setid = atoi(cptr); + MCAddSet(setid); + msgid = 0; + } else if (strncmp(cptr, "delset", 6) == 0) { + cptr += 6; + cptr = wskip(cptr); + setid = atoi(cptr); + MCDelSet(setid); + } else if (strncmp(cptr, "quote", 5) == 0) { + cptr += 5; + if (!*cptr) + quote = 0; + else { + cptr = wskip(cptr); + if (!*cptr) + quote = 0; + else + quote = *cptr; + } + } else if (isspace((unsigned char) *cptr)) { + ; + } else { + if (*cptr) { + cptr = wskip(cptr); + if (*cptr) + warning(cptr, "unrecognized line"); + } + } + } else { + /* + * First check for (and eat) empty lines.... + */ + if (!*cptr) + continue; + /* + * We have a digit? Start of a message. Else, + * syntax error. + */ + if (isdigit((unsigned char) *cptr)) { + msgid = atoi(cptr); + cptr = cskip(cptr); + cptr = wskip(cptr); + /* if (*cptr) ++cptr; */ + } else { + warning(cptr, "neither blank line nor start of a message id"); + continue; + } + /* + * If we have a message ID, but no message, + * then this means "delete this message id + * from the catalog". + */ + if (!*cptr) { + MCDelMsg(msgid); + } else { + str = getmsg(fd, cptr, quote); + MCAddMsg(msgid, str); + } + } + } +} + +void +MCReadCat(fd) + int fd; +{ +#if 0 + MCHeaderT mcHead; + MCMsgT mcMsg; + MCSetT mcSet; + msgT *msg; + setT *set; + int i; + char *data; + + /* XXX init sethead? */ + + if (read(fd, &mcHead, sizeof(mcHead)) != sizeof(mcHead)) + corrupt(); + if (strncmp(mcHead.magic, MCMagic, MCMagicLen) != 0) + corrupt(); + if (mcHead.majorVer != MCMajorVer) + error(NULL, "unrecognized catalog version"); + if ((mcHead.flags & MCGetByteOrder()) == 0) + error(NULL, "wrong byte order"); + + if (lseek(fd, mcHead.firstSet, SEEK_SET) == -1) + corrupt(); + + for (;;) { + if (read(fd, &mcSet, sizeof(mcSet)) != sizeof(mcSet)) + corrupt(); + if (mcSet.invalid) + continue; + + set = xmalloc(sizeof(setT)); + memset(set, '\0', sizeof(*set)); + if (cat->first) { + cat->last->next = set; + set->prev = cat->last; + cat->last = set; + } else + cat->first = cat->last = set; + + set->setId = mcSet.setId; + + /* Get the data */ + if (mcSet.dataLen) { + data = xmalloc(mcSet.dataLen); + if (lseek(fd, mcSet.data.off, SEEK_SET) == -1) + corrupt(); + if (read(fd, data, mcSet.dataLen) != mcSet.dataLen) + corrupt(); + if (lseek(fd, mcSet.u.firstMsg, SEEK_SET) == -1) + corrupt(); + + for (i = 0; i < mcSet.numMsgs; ++i) { + if (read(fd, &mcMsg, sizeof(mcMsg)) != sizeof(mcMsg)) + corrupt(); + if (mcMsg.invalid) { + --i; + continue; + } + msg = xmalloc(sizeof(msgT)); + memset(msg, '\0', sizeof(*msg)); + if (set->first) { + set->last->next = msg; + msg->prev = set->last; + set->last = msg; + } else + set->first = set->last = msg; + + msg->msgId = mcMsg.msgId; + msg->str = xstrdup((char *) (data + mcMsg.msg.off)); + } + free(data); + } + if (!mcSet.nextSet) + break; + if (lseek(fd, mcSet.nextSet, SEEK_SET) == -1) + corrupt(); + } +#endif +} + +/* + * Write message catalog. + * + * The message catalog is first converted from its internal to its + * external representation in a chunk of memory allocated for this + * purpose. Then the completed catalog is written. This approach + * avoids additional housekeeping variables and/or a lot of seeks + * that would otherwise be required. + */ +void +MCWriteCat(fd) + int fd; +{ + int nsets; /* number of sets */ + int nmsgs; /* number of msgs */ + int string_size; /* total size of string pool */ + int msgcat_size; /* total size of message catalog */ + void *msgcat; /* message catalog data */ + struct _nls_cat_hdr *cat_hdr; + struct _nls_set_hdr *set_hdr; + struct _nls_msg_hdr *msg_hdr; + char *strings; + struct _setT *set; + struct _msgT *msg; + int msg_index; + int msg_offset; + + /* determine number of sets, number of messages, and size of the + * string pool */ + nsets = 0; + nmsgs = 0; + string_size = 0; + + for (set = sethead.lh_first; set != NULL; + set = set->entries.le_next) { + nsets++; + + for (msg = set->msghead.lh_first; msg != NULL; + msg = msg->entries.le_next) { + nmsgs++; + string_size += strlen(msg->str) + 1; + } + } + +#ifdef DEBUG + printf("number of sets: %d\n", nsets); + printf("number of msgs: %d\n", nmsgs); + printf("string pool size: %d\n", string_size); +#endif + + /* determine size and then allocate buffer for constructing external + * message catalog representation */ + msgcat_size = sizeof(struct _nls_cat_hdr) + + (nsets * sizeof(struct _nls_set_hdr)) + + (nmsgs * sizeof(struct _nls_msg_hdr)) + + string_size; + + msgcat = xmalloc(msgcat_size); + memset(msgcat, '\0', msgcat_size); + + /* fill in msg catalog header */ + cat_hdr = (struct _nls_cat_hdr *) msgcat; + cat_hdr->__magic = htonl(_NLS_MAGIC); + cat_hdr->__nsets = htonl(nsets); + cat_hdr->__mem = htonl(msgcat_size - sizeof(struct _nls_cat_hdr)); + cat_hdr->__msg_hdr_offset = + htonl(nsets * sizeof(struct _nls_set_hdr)); + cat_hdr->__msg_txt_offset = + htonl(nsets * sizeof(struct _nls_set_hdr) + + nmsgs * sizeof(struct _nls_msg_hdr)); + + /* compute offsets for set & msg header tables and string pool */ + set_hdr = (struct _nls_set_hdr *) ((char *) msgcat + + sizeof(struct _nls_cat_hdr)); + msg_hdr = (struct _nls_msg_hdr *) ((char *) msgcat + + sizeof(struct _nls_cat_hdr) + + nsets * sizeof(struct _nls_set_hdr)); + strings = (char *) msgcat + + sizeof(struct _nls_cat_hdr) + + nsets * sizeof(struct _nls_set_hdr) + + nmsgs * sizeof(struct _nls_msg_hdr); + + msg_index = 0; + msg_offset = 0; + for (set = sethead.lh_first; set != NULL; + set = set->entries.le_next) { + + nmsgs = 0; + for (msg = set->msghead.lh_first; msg != NULL; + msg = msg->entries.le_next) { + int msg_len = strlen(msg->str) + 1; + + msg_hdr->__msgno = htonl(msg->msgId); + msg_hdr->__msglen = htonl(msg_len); + msg_hdr->__offset = htonl(msg_offset); + + memcpy(strings, msg->str, msg_len); + strings += msg_len; + msg_offset += msg_len; + + nmsgs++; + msg_hdr++; + } + + set_hdr->__setno = htonl(set->setId); + set_hdr->__nmsgs = htonl(nmsgs); + set_hdr->__index = htonl(msg_index); + msg_index += nmsgs; + set_hdr++; + } + + /* write out catalog. XXX: should this be done in small chunks? */ + write(fd, msgcat, msgcat_size); +} + +void +MCAddSet(setId) + int setId; +{ + struct _setT *p, *q; + + if (setId <= 0) { + error(NULL, "setId's must be greater than zero"); + /* NOTREACHED */ + } + if (setId > NL_SETMAX) { + error(NULL, "setId exceeds limit"); + /* NOTREACHED */ + } + + p = sethead.lh_first; + q = NULL; + for (; p != NULL && p->setId < setId; q = p, p = p->entries.le_next); + + if (p && p->setId == setId) { + ; + } else { + p = xmalloc(sizeof(struct _setT)); + memset(p, '\0', sizeof(struct _setT)); + LIST_INIT(&p->msghead); + + p->setId = setId; + + if (q == NULL) { + LIST_INSERT_HEAD(&sethead, p, entries); + } else { + LIST_INSERT_AFTER(q, p, entries); + } + } + + curSet = p; +} + +void +MCAddMsg(msgId, str) + int msgId; + const char *str; +{ + struct _msgT *p, *q; + + if (!curSet) + error(NULL, "can't specify a message when no set exists"); + + if (msgId <= 0) { + error(NULL, "msgId's must be greater than zero"); + /* NOTREACHED */ + } + if (msgId > NL_MSGMAX) { + error(NULL, "msgID exceeds limit"); + /* NOTREACHED */ + } + + p = curSet->msghead.lh_first; + q = NULL; + for (; p != NULL && p->msgId < msgId; q = p, p = p->entries.le_next); + + if (p && p->msgId == msgId) { + free(p->str); + } else { + p = xmalloc(sizeof(struct _msgT)); + memset(p, '\0', sizeof(struct _msgT)); + + if (q == NULL) { + LIST_INSERT_HEAD(&curSet->msghead, p, entries); + } else { + LIST_INSERT_AFTER(q, p, entries); + } + } + + p->msgId = msgId; + p->str = xstrdup(str); +} + +void +MCDelSet(setId) + int setId; +{ + struct _setT *set; + struct _msgT *msg; + + set = sethead.lh_first; + for (; set != NULL && set->setId < setId; set = set->entries.le_next); + + if (set && set->setId == setId) { + + msg = set->msghead.lh_first; + while (msg) { + free(msg->str); + LIST_REMOVE(msg, entries); + } + + LIST_REMOVE(set, entries); + return; + } + warning(NULL, "specified set doesn't exist"); +} + +void +MCDelMsg(msgId) + int msgId; +{ + struct _msgT *msg; + + if (!curSet) + error(NULL, "you can't delete a message before defining the set"); + + msg = curSet->msghead.lh_first; + for (; msg != NULL && msg->msgId < msgId; msg = msg->entries.le_next); + + if (msg && msg->msgId == msgId) { + free(msg->str); + LIST_REMOVE(msg, entries); + return; + } + warning(NULL, "specified msg doesn't exist"); } diff --git a/usr.bin/gencat/gencat.h b/usr.bin/gencat/gencat.h deleted file mode 100644 index 5af4c09d6a..0000000000 --- a/usr.bin/gencat/gencat.h +++ /dev/null @@ -1,88 +0,0 @@ -/* $FreeBSD: src/usr.bin/gencat/gencat.h,v 1.2.12.1 2001/12/17 12:09:35 phantom Exp $ */ -/* $DragonFly: src/usr.bin/gencat/Attic/gencat.h,v 1.2 2003/06/17 04:29:27 dillon Exp $ */ - -#ifndef GENCAT_H -#define GENCAT_H - -/*********************************************************** -Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that Alfalfa's name not be used in -advertising or publicity pertaining to distribution of the software -without specific, written prior permission. - -ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -If you make any modifications, bugfixes or other changes to this software -we'd appreciate it if you could send a copy to us so we can keep things -up-to-date. Many thanks. - Kee Hinckley - Alfalfa Software, Inc. - 267 Allston St., #3 - Cambridge, MA 02139 USA - nazgul@alfalfa.com - -******************************************************************/ - -/* - * $set n comment - * My extension: If the comment begins with # treat the next string - * as a constant identifier. - * $delset n comment - * n goes from 1 to NL_SETMAX - * Deletes a set from the MC - * $ comment - * My extension: If comment begins with # treat the next string as - * a constant identifier for the next message. - * m message-text - * m goes from 1 to NL_MSGMAX - * If message-text is empty, and a space or tab is present, put - * empty string in catalog. - * If message-text is empty, delete the message. - * Length of text is 0 to NL_TEXTMAX - * My extension: If '#' is used instead of a number, the number - * is generated automatically. A # followed by anything is an empty message. - * $quote c - * Optional quote character which can suround message-text to - * show where spaces are. - * - * Escape Characters - * \n (newline), \t (horiz tab), \v (vert tab), \b (backspace), - * \r (carriage return), \f (formfeed), \\ (backslash), \ddd (bitpattern - * in octal). - * Also, \ at end of line is a continuation. - * - */ - -#define MCLangC 0 -#define MCLangCPlusPlus 1 -#define MCLangANSIC 2 - -#define MAXTOKEN 1024 - -#define TRUE 1 -#define FALSE 0 - -extern void MCAddSet(int, char *); -extern void MCDelSet(int); -extern void MCAddMsg(int, const char *, char *); -extern void MCDelMsg(int); -extern void MCParse(int); -extern void MCReadCat(int); -extern void MCWriteConst(int, int, int); -extern void MCWriteCat(int); -extern long MCGetByteOrder(void); - -#endif /* GENCAT_H */ diff --git a/usr.bin/gencat/genlib.c b/usr.bin/gencat/genlib.c deleted file mode 100644 index c11f482572..0000000000 --- a/usr.bin/gencat/genlib.c +++ /dev/null @@ -1,806 +0,0 @@ -/* $FreeBSD: src/usr.bin/gencat/genlib.c,v 1.8.6.3 2002/02/19 13:21:16 phantom Exp $ */ -/* $DragonFly: src/usr.bin/gencat/Attic/genlib.c,v 1.2 2003/06/17 04:29:27 dillon Exp $ */ - -/*********************************************************** -Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that Alfalfa's name not be used in -advertising or publicity pertaining to distribution of the software -without specific, written prior permission. - -ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -If you make any modifications, bugfixes or other changes to this software -we'd appreciate it if you could send a copy to us so we can keep things -up-to-date. Many thanks. - Kee Hinckley - Alfalfa Software, Inc. - 267 Allston St., #3 - Cambridge, MA 02139 USA - nazgul@alfalfa.com - -******************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "msgcat.h" -#include "gencat.h" - -static char *curline = NULL; -static long lineno = 0; - -static void -warning(char *cptr, const char *msg) -{ - warnx("%s on line %ld\n%s", msg, lineno, (curline == NULL ? "" : curline) ); - if (cptr) { - char *tptr; - for (tptr = curline; tptr < cptr; ++tptr) putc(' ', stderr); - fprintf(stderr, "^\n"); - } -} - -static void -error(char *cptr, const char *msg) -{ - warning(cptr, msg); - exit(1); -} - -static void -corrupt(void) { - error(NULL, "corrupt message catalog"); -} - -static void -nomem(void) { - error(NULL, "out of memory"); -} - -static char * -getline(int fd) -{ - static size_t curlen = BUFSIZ; - static char buf[BUFSIZ], *bptr = buf, *bend = buf; - char *cptr, *cend; - long buflen; - - if (!curline) { - curline = (char *) malloc(curlen); - if (!curline) nomem(); - } - ++lineno; - - cptr = curline; - cend = curline + curlen; - while (TRUE) { - for (; bptr < bend && cptr < cend; ++cptr, ++bptr) { - if (*bptr == '\n') { - *cptr = '\0'; - ++bptr; - return(curline); - } else *cptr = *bptr; - } - if (bptr == bend) { - buflen = read(fd, buf, BUFSIZ); - if (buflen <= 0) { - if (cptr > curline) { - *cptr = '\0'; - return(curline); - } - return(NULL); - } - bend = buf + buflen; - bptr = buf; - } - if (cptr == cend) { - cptr = curline = (char *) realloc(curline, curlen *= 2); - cend = curline + curlen; - } - } -} - -static char * -token(char *cptr) -{ - static char tok[MAXTOKEN+1]; - char *tptr = tok; - - while (*cptr && isspace((unsigned char)*cptr)) ++cptr; - while (*cptr && !isspace((unsigned char)*cptr)) *tptr++ = *cptr++; - *tptr = '\0'; - return(tok); -} - -static char * -wskip(char *cptr) -{ - if (!*cptr || !isspace((unsigned char)*cptr)) { - warning(cptr, "expected a space"); - return(cptr); - } - while (*cptr && isspace((unsigned char)*cptr)) ++cptr; - return(cptr); -} - -static char * -cskip(char *cptr) -{ - if (!*cptr || isspace((unsigned char)*cptr)) { - warning(cptr, "wasn't expecting a space"); - return(cptr); - } - while (*cptr && !isspace((unsigned char)*cptr)) ++cptr; - return(cptr); -} - -static char * -getmsg(int fd, char *cptr, char quote) -{ - static char *msg = NULL; - static size_t msglen = 0; - size_t clen, i; - char *tptr; - int needq; - - if (quote && *cptr == quote) { - needq = TRUE; - ++cptr; - } else needq = FALSE; - - clen = strlen(cptr) + 1; - if (clen > msglen) { - if (msglen) msg = (char *) realloc(msg, clen); - else msg = (char *) malloc(clen); - msglen = clen; - } - tptr = msg; - - while (*cptr) { - if (quote && *cptr == quote) { - char *tmp; - tmp = cptr+1; - if (*tmp && (!isspace((unsigned char)*tmp) || *wskip(tmp))) { - warning(cptr, "unexpected quote character, ignoring"); - *tptr++ = *cptr++; - } else { - *cptr = '\0'; - } - } else if (*cptr == '\\') { - ++cptr; - switch (*cptr) { - case '\0': - cptr = getline(fd); - if (!cptr) error(NULL, "premature end of file"); - msglen += strlen(cptr); - i = tptr - msg; - msg = (char *) realloc(msg, msglen); - tptr = msg + i; - break; - -#define CASEOF(CS, CH) \ - case CS: \ - *tptr++ = CH; \ - ++cptr; \ - break; - - CASEOF('n', '\n') - CASEOF('t', '\t') - CASEOF('v', '\v') - CASEOF('b', '\b') - CASEOF('r', '\r') - CASEOF('f', '\f') - CASEOF('"', '"') - CASEOF('\'', '\'') - CASEOF('\\', '\\') - - default: - if (isdigit((unsigned char)*cptr)) { - *tptr = 0; - for (i = 0; i < 3; ++i) { - if (!isdigit((unsigned char)*cptr)) break; - if (*cptr > '7') warning(cptr, "octal number greater than 7?!"); - *tptr *= 8; - *tptr += (*cptr - '0'); - ++cptr; - } - ++tptr; - } else { - warning(cptr, "unrecognized escape sequence"); - } - } - } else { - *tptr++ = *cptr++; - } - } - *tptr = '\0'; - return(msg); -} - -static char * -dupstr(const char *ostr) -{ - char *nstr; - - nstr = strdup(ostr); - if (!nstr) error(NULL, "unable to allocate storage"); - return(nstr); -} - -/* - * The Global Stuff - */ - -typedef struct _msgT { - long msgId; - char *str; - char *hconst; - long offset; - struct _msgT *prev, *next; -} msgT; - -typedef struct _setT { - long setId; - char *hconst; - msgT *first, *last; - struct _setT *prev, *next; -} setT; - -typedef struct { - setT *first, *last; -} catT; - -static setT *curSet; -static catT *cat; - -/* - * Find the current byte order. There are of course some others, but - * this will do for now. Note that all we care about is "long". - */ -long -MCGetByteOrder(void) { - long l = 0x00010203; - char *cptr = (char *) &l; - - if (cptr[0] == 0 && cptr[1] == 1 && cptr[2] == 2 && cptr[3] == 3) - return MC68KByteOrder; - else return MCn86ByteOrder; -} - -void -MCParse(int fd) -{ - char *cptr, *str; - int setid, msgid = 0; - char hconst[MAXTOKEN+1]; - char quote = 0; - - if (!cat) { - cat = (catT *) malloc(sizeof(catT)); - if (!cat) nomem(); - bzero(cat, sizeof(catT)); - } - - hconst[0] = '\0'; - - while ((cptr = getline(fd)) != NULL) { - if (*cptr == '$') { - ++cptr; - if (strncmp(cptr, "set", 3) == 0) { - cptr += 3; - cptr = wskip(cptr); - setid = atoi(cptr); - cptr = cskip(cptr); - if (*cptr) cptr = wskip(cptr); - if (*cptr == '#') { - ++cptr; - MCAddSet(setid, token(cptr)); - } else MCAddSet(setid, NULL); - msgid = 0; - } else if (strncmp(cptr, "delset", 6) == 0) { - cptr += 6; - cptr = wskip(cptr); - setid = atoi(cptr); - MCDelSet(setid); - } else if (strncmp(cptr, "quote", 5) == 0) { - cptr += 5; - if (!*cptr) quote = 0; - else { - cptr = wskip(cptr); - if (!*cptr) quote = 0; - else quote = *cptr; - } - } else if (isspace((unsigned char)*cptr)) { - cptr = wskip(cptr); - if (*cptr == '#') { - ++cptr; - strcpy(hconst, token(cptr)); - } - } else { - if (*cptr) { - cptr = wskip(cptr); - if (*cptr) warning(cptr, "unrecognized line"); - } - } - } else { - if (isdigit((unsigned char)*cptr) || *cptr == '#') { - if (*cptr == '#') { - ++msgid; - ++cptr; - if (!*cptr) { - MCAddMsg(msgid, "", hconst); - hconst[0] = '\0'; - continue; - } - if (!isspace((unsigned char)*cptr)) warning(cptr, "expected a space"); - ++cptr; - if (!*cptr) { - MCAddMsg(msgid, "", hconst); - hconst[0] = '\0'; - continue; - } - } else { - msgid = atoi(cptr); - cptr = cskip(cptr); - cptr = wskip(cptr); - /* if (*cptr) ++cptr; */ - } - if (!*cptr) MCDelMsg(msgid); - else { - str = getmsg(fd, cptr, quote); - MCAddMsg(msgid, str, hconst); - hconst[0] = '\0'; - } - } - } - } -} - -void -MCReadCat(int fd) -{ - MCHeaderT mcHead; - MCMsgT mcMsg; - MCSetT mcSet; - msgT *msg; - setT *set; - int i; - char *data; - - cat = (catT *) malloc(sizeof(catT)); - if (!cat) nomem(); - bzero(cat, sizeof(catT)); - - if (read(fd, &mcHead, sizeof(mcHead)) != sizeof(mcHead)) corrupt(); - if (strncmp(mcHead.magic, MCMagic, MCMagicLen) != 0) corrupt(); - if (mcHead.majorVer != MCMajorVer) error(NULL, "unrecognized catalog version"); - if ((mcHead.flags & MCGetByteOrder()) == 0) error(NULL, "wrong byte order"); - - if (lseek(fd, mcHead.firstSet, L_SET) == -1) corrupt(); - - while (TRUE) { - if (read(fd, &mcSet, sizeof(mcSet)) != sizeof(mcSet)) corrupt(); - if (mcSet.invalid) continue; - - set = (setT *) malloc(sizeof(setT)); - if (!set) nomem(); - bzero(set, sizeof(*set)); - if (cat->first) { - cat->last->next = set; - set->prev = cat->last; - cat->last = set; - } else cat->first = cat->last = set; - - set->setId = mcSet.setId; - - /* Get the data */ - if (mcSet.dataLen) { - data = (char *) malloc((size_t)mcSet.dataLen); - if (!data) nomem(); - if (lseek(fd, mcSet.data.off, L_SET) == -1) corrupt(); - if (read(fd, data, (size_t)mcSet.dataLen) != mcSet.dataLen) corrupt(); - if (lseek(fd, mcSet.u.firstMsg, L_SET) == -1) corrupt(); - - for (i = 0; i < mcSet.numMsgs; ++i) { - if (read(fd, &mcMsg, sizeof(mcMsg)) != sizeof(mcMsg)) corrupt(); - if (mcMsg.invalid) { - --i; - continue; - } - - msg = (msgT *) malloc(sizeof(msgT)); - if (!msg) nomem(); - bzero(msg, sizeof(*msg)); - if (set->first) { - set->last->next = msg; - msg->prev = set->last; - set->last = msg; - } else set->first = set->last = msg; - - msg->msgId = mcMsg.msgId; - msg->str = dupstr((char *) (data + mcMsg.msg.off)); - } - free(data); - } - if (!mcSet.nextSet) break; - if (lseek(fd, mcSet.nextSet, L_SET) == -1) corrupt(); - } -} - - -static void -printS(int fd, const char *str) -{ - write(fd, str, strlen(str)); -} - -static void -printL(int fd, long l) -{ - char buf[32]; - sprintf(buf, "%ld", l); - write(fd, buf, strlen(buf)); -} - -static void -printLX(int fd, long l) -{ - char buf[32]; - sprintf(buf, "%lx", l); - write(fd, buf, strlen(buf)); -} - -static void -genconst(int fd, int type, char *setConst, char *msgConst, long val) -{ - switch (type) { - case MCLangC: - if (!msgConst) { - printS(fd, "\n#define "); - printS(fd, setConst); - printS(fd, "Set"); - } else { - printS(fd, "#define "); - printS(fd, setConst); - printS(fd, msgConst); - } - printS(fd, "\t0x"); - printLX(fd, val); - printS(fd, "\n"); - break; - case MCLangCPlusPlus: - case MCLangANSIC: - if (!msgConst) { - printS(fd, "\nconst long "); - printS(fd, setConst); - printS(fd, "Set"); - } else { - printS(fd, "const long "); - printS(fd, setConst); - printS(fd, msgConst); - } - printS(fd, "\t= "); - printL(fd, val); - printS(fd, ";\n"); - break; - default: - error(NULL, "not a recognized (programming) language type"); - } -} - -void -MCWriteConst(int fd, int type, int orConsts) -{ - msgT *msg; - setT *set; - long id; - - if (orConsts && (type == MCLangC || type == MCLangCPlusPlus || type == MCLangANSIC)) { - printS(fd, "/* Use these Macros to compose and decompose setId's and msgId's */\n"); - printS(fd, "#ifndef MCMakeId\n"); - printS(fd, "# define MCMakeId(s,m)\t(unsigned long)(((unsigned short)s<<(sizeof(short)*8))\\\n"); - printS(fd, "\t\t\t\t\t|(unsigned short)m)\n"); - printS(fd, "# define MCSetId(id)\t(unsigned int) (id >> (sizeof(short) * 8))\n"); - printS(fd, "# define MCMsgId(id)\t(unsigned int) ((id << (sizeof(short) * 8))\\\n"); - printS(fd, "\t\t\t\t\t>> (sizeof(short) * 8))\n"); - printS(fd, "#endif\n"); - } - - for (set = cat->first; set; set = set->next) { - if (set->hconst) genconst(fd, type, set->hconst, NULL, set->setId); - - for (msg = set->first; msg; msg = msg->next) { - if (msg->hconst) { - if (orConsts) id = MCMakeId(set->setId, msg->msgId); - else id = msg->msgId; - genconst(fd, type, set->hconst, msg->hconst, id); - free(msg->hconst); - msg->hconst = NULL; - } - } - if (set->hconst) { - free(set->hconst); - set->hconst = NULL; - } - } -} - -void -MCWriteCat(int fd) -{ - MCHeaderT mcHead; - int cnt; - setT *set; - msgT *msg; - MCSetT mcSet; - MCMsgT mcMsg; - off_t pos; - - bcopy(MCMagic, mcHead.magic, MCMagicLen); - mcHead.majorVer = MCMajorVer; - mcHead.minorVer = MCMinorVer; - mcHead.flags = MCGetByteOrder(); - mcHead.firstSet = 0; /* We'll be back to set this in a minute */ - - if (cat == NULL) - error(NULL, "cannot write empty catalog set"); - - for (cnt = 0, set = cat->first; set; set = set->next) ++cnt; - mcHead.numSets = cnt; - - lseek(fd, (off_t)0L, L_SET); - write(fd, &mcHead, sizeof(mcHead)); - mcHead.firstSet = lseek(fd, (off_t)0L, L_INCR); - lseek(fd, (off_t)0L, L_SET); - write(fd, &mcHead, sizeof(mcHead)); - - for (set = cat->first; set; set = set->next) { - bzero(&mcSet, sizeof(mcSet)); - - mcSet.setId = set->setId; - mcSet.invalid = FALSE; - - /* The rest we'll have to come back and change in a moment */ - pos = lseek(fd, (off_t)0L, L_INCR); - write(fd, &mcSet, sizeof(mcSet)); - - /* Now write all the string data */ - mcSet.data.off = lseek(fd, (off_t)0L, L_INCR); - cnt = 0; - for (msg = set->first; msg; msg = msg->next) { - msg->offset = lseek(fd, (off_t)0L, L_INCR) - mcSet.data.off; - mcSet.dataLen += write(fd, msg->str, strlen(msg->str) + 1); - ++cnt; - } - mcSet.u.firstMsg = lseek(fd, (off_t)0L, L_INCR); - mcSet.numMsgs = cnt; - - /* Now write the message headers */ - for (msg = set->first; msg; msg = msg->next) { - mcMsg.msgId = msg->msgId; - mcMsg.msg.off = msg->offset; - mcMsg.invalid = FALSE; - write(fd, &mcMsg, sizeof(mcMsg)); - } - - /* Go back and fix things up */ - - if (set == cat->last) { - mcSet.nextSet = 0; - lseek(fd, pos, L_SET); - write(fd, &mcSet, sizeof(mcSet)); - } else { - mcSet.nextSet = lseek(fd, (off_t)0L, L_INCR); - lseek(fd, pos, L_SET); - write(fd, &mcSet, sizeof(mcSet)); - lseek(fd, mcSet.nextSet, L_SET); - } - } -} - -void -MCAddSet(int setId, char *hconst) -{ - setT *set; - - if (setId <= 0) { - error(NULL, "setId's must be greater than zero"); - return; - } - - if (hconst && !*hconst) hconst = NULL; - for (set = cat->first; set; set = set->next) { - if (set->setId == setId) { - if (set->hconst && hconst) free(set->hconst); - set->hconst = NULL; - break; - } else if (set->setId > setId) { - setT *newSet; - - newSet = (setT *) malloc(sizeof(setT)); - if (!newSet) nomem(); - bzero(newSet, sizeof(setT)); - newSet->prev = set->prev; - newSet->next = set; - if (set->prev) set->prev->next = newSet; - else cat->first = newSet; - set->prev = newSet; - set = newSet; - break; - } - } - if (!set) { - set = (setT *) malloc(sizeof(setT)); - if (!set) nomem(); - bzero(set, sizeof(setT)); - - if (cat->first) { - set->prev = cat->last; - set->next = NULL; - cat->last->next = set; - cat->last = set; - } else { - set->prev = set->next = NULL; - cat->first = cat->last = set; - } - } - set->setId = setId; - if (hconst) set->hconst = dupstr(hconst); - curSet = set; -} - -void -MCAddMsg(int msgId, const char *str, char *hconst) -{ - msgT *msg; - - if (!curSet) - error(NULL, "can't specify a message when no set exists"); - - if (msgId <= 0) { - error(NULL, "msgId's must be greater than zero"); - return; - } - - if (hconst && !*hconst) hconst = NULL; - for (msg = curSet->first; msg; msg = msg->next) { - if (msg->msgId == msgId) { - if (msg->hconst && hconst) free(msg->hconst); - if (msg->str) free(msg->str); - msg->hconst = msg->str = NULL; - break; - } else if (msg->msgId > msgId) { - msgT *newMsg; - - newMsg = (msgT *) malloc(sizeof(msgT)); - if (!newMsg) nomem(); - bzero(newMsg, sizeof(msgT)); - newMsg->prev = msg->prev; - newMsg->next = msg; - if (msg->prev) msg->prev->next = newMsg; - else curSet->first = newMsg; - msg->prev = newMsg; - msg = newMsg; - break; - } - } - if (!msg) { - msg = (msgT *) malloc(sizeof(msgT)); - if (!msg) nomem(); - bzero(msg, sizeof(msgT)); - - if (curSet->first) { - msg->prev = curSet->last; - msg->next = NULL; - curSet->last->next = msg; - curSet->last = msg; - } else { - msg->prev = msg->next = NULL; - curSet->first = curSet->last = msg; - } - } - msg->msgId = msgId; - if (hconst) msg->hconst = dupstr(hconst); - msg->str = dupstr(str); -} - -void -MCDelSet(int setId) -{ - setT *set; - msgT *msg; - - for (set = cat->first; set; set = set->next) { - if (set->setId == setId) { - for (msg = set->first; msg; msg = msg->next) { - if (msg->hconst) free(msg->hconst); - if (msg->str) free(msg->str); - free(msg); - } - if (set->hconst) free(set->hconst); - - if (set->prev) set->prev->next = set->next; - else cat->first = set->next; - - if (set->next) set->next->prev = set->prev; - else cat->last = set->prev; - - free(set); - return; - } else if (set->setId > setId) break; - } - warning(NULL, "specified set doesn't exist"); -} - -void -MCDelMsg(int msgId) -{ - msgT *msg; - - if (!curSet) - error(NULL, "you can't delete a message before defining the set"); - - for (msg = curSet->first; msg; msg = msg->next) { - if (msg->msgId == msgId) { - if (msg->hconst) free(msg->hconst); - if (msg->str) free(msg->str); - - if (msg->prev) msg->prev->next = msg->next; - else curSet->first = msg->next; - - if (msg->next) msg->next->prev = msg->prev; - else curSet->last = msg->prev; - - free(msg); - return; - } else if (msg->msgId > msgId) break; - } - warning(NULL, "specified msg doesn't exist"); -} - -#if 0 /* this function is unsed and looks like debug thing */ - -void -MCDumpcat(fp) -FILE *fp; -{ - msgT *msg; - setT *set; - - if (!cat) - errx(1, "no catalog open"); - - for (set = cat->first; set; set = set->next) { - fprintf(fp, "$set %ld", set->setId); - if (set->hconst) - fprintf(fp, " # %s", set->hconst); - fprintf(fp, "\n\n"); - - for (msg = set->first; msg; msg = msg->next) { - if (msg->hconst) - fprintf(fp, "# %s\n", msg->hconst); - fprintf(fp, "%ld\t%s\n", msg->msgId, msg->str); - } - fprintf(fp, "\n"); - } - -} -#endif /* 0 */ diff --git a/usr.bin/mklocale/Makefile b/usr.bin/mklocale/Makefile index 63e3f33672..215a705be6 100644 --- a/usr.bin/mklocale/Makefile +++ b/usr.bin/mklocale/Makefile @@ -1,17 +1,11 @@ # @(#)Makefile 8.1 (Berkeley) 6/7/93 # $FreeBSD: src/usr.bin/mklocale/Makefile,v 1.21.2.2 2001/04/25 11:29:28 ru Exp $ -# $DragonFly: src/usr.bin/mklocale/Makefile,v 1.3 2005/04/18 07:43:45 joerg Exp $ +# $DragonFly: src/usr.bin/mklocale/Makefile,v 1.4 2005/04/21 16:36:35 joerg Exp $ -PROG= mklocale -SRCS= yacc.y lex.l y.tab.h -CFLAGS+= -I. -I${.CURDIR} - -SRCS+= runetype.h ctype.h -CLEANFILES+= runetype.h ctype.h - -runetype.h: ${.CURDIR}/../../include/runetype.h - cp ${.ALLSRC} ${.TARGET} -ctype.h: ${.CURDIR}/../../include/ctype.h - grep '#define._CTYPE_' ${.ALLSRC} > ${.TARGET} +PROG= mklocale +SRCS= yacc.y lex.l +CFLAGS+=-I. -I${.CURDIR} -I${.CURDIR}/../../lib/libc +YFLAGS= -d +WARNS?= 6 .include diff --git a/usr.bin/mklocale/extern.h b/usr.bin/mklocale/extern.h deleted file mode 100644 index 3bd7c467b4..0000000000 --- a/usr.bin/mklocale/extern.h +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/usr.bin/mklocale/extern.h,v 1.1.2.1 2002/10/23 17:18:39 ache Exp $ - * $DragonFly: src/usr.bin/mklocale/Attic/extern.h,v 1.2 2003/06/17 04:29:29 dillon Exp $ - */ - -int yylex(void); -int yyparse(void); diff --git a/usr.bin/mklocale/ldef.h b/usr.bin/mklocale/ldef.h index 1e9f2c48bb..8ad765c4f9 100644 --- a/usr.bin/mklocale/ldef.h +++ b/usr.bin/mklocale/ldef.h @@ -1,3 +1,5 @@ +/* $NetBSD: src/usr.bin/mklocale/ldef.h,v 1.4 2003/08/07 11:15:14 agc Exp $ */ + /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -13,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -34,23 +32,23 @@ * SUCH DAMAGE. * * @(#)ldef.h 8.1 (Berkeley) 6/6/93 - * $DragonFly: src/usr.bin/mklocale/ldef.h,v 1.2 2005/04/18 07:43:45 joerg Exp $ + * $DragonFly: src/usr.bin/mklocale/ldef.h,v 1.3 2005/04/21 16:36:35 joerg Exp $ */ -#include "runetype.h" +#include "locale/runetype.h" /* * This should look a LOT like a _RuneEntry */ typedef struct rune_list { - rune_t min; - rune_t max; - rune_t map; - unsigned long *types; + __nbrune_t min; + __nbrune_t max; + __nbrune_t map; + u_int32_t *types; struct rune_list *next; } rune_list; typedef struct rune_map { - unsigned long map[_CACHED_RUNES]; + u_int32_t map[_NB_CACHED_RUNES]; rune_list *root; } rune_map; diff --git a/usr.bin/mklocale/lex.l b/usr.bin/mklocale/lex.l index e210d25e20..39e876b732 100644 --- a/usr.bin/mklocale/lex.l +++ b/usr.bin/mklocale/lex.l @@ -1,3 +1,6 @@ +/* $NetBSD: src/usr.bin/mklocale/lex.l,v 1.13 2003/10/27 00:12:43 lukem Exp $ */ +/* $DragonFly: src/usr.bin/mklocale/lex.l,v 1.6 2005/04/21 16:36:35 joerg Exp $ */ + %{ /*- * Copyright (c) 1993 @@ -14,11 +17,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,29 +32,17 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)lex.l 8.1 (Berkeley) 6/6/93 - * $FreeBSD: src/usr.bin/mklocale/lex.l,v 1.5 2000/02/08 07:43:26 obrien Exp $ - * $DragonFly: src/usr.bin/mklocale/lex.l,v 1.5 2004/10/30 18:46:07 dillon Exp $ */ -#include #include #include +#include +#include "locale/runetype.h" #include "ldef.h" -#include "y.tab.h" - -/* - * Bootstrapping - */ -#ifndef _CTYPE_SW0 -#define _CTYPE_SW0 0 -#define _CTYPE_SW1 0 -#define _CTYPE_SW2 0 -#define _CTYPE_SW3 0 -#endif +#include "yacc.h" +int yylex(void); %} ODIGIT [0-7] @@ -82,58 +69,51 @@ W [\t\n\r ] '\\v' { yylval.rune = '\v'; return(RUNE); } -0x{XDIGIT}+ { yylval.rune = strtol(yytext, 0, 16); +0x{XDIGIT}+ { yylval.rune = strtoul(yytext, 0, 16); return(RUNE); } -0{ODIGIT}+ { yylval.rune = strtol(yytext, 0, 8); +0{ODIGIT}+ { yylval.rune = strtoul(yytext, 0, 8); return(RUNE); } -{DIGIT}+ { yylval.rune = strtol(yytext, 0, 10); +{DIGIT}+ { yylval.rune = strtoul(yytext, 0, 10); return(RUNE); } MAPLOWER { return(MAPLOWER); } MAPUPPER { return(MAPUPPER); } TODIGIT { return(DIGITMAP); } +INVALID { return(INVALID); } -ALPHA { yylval.i = _CTYPE_A|_CTYPE_R|_CTYPE_G; +ALPHA { yylval.i = _RUNETYPE_A|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -CONTROL { yylval.i = _CTYPE_C; +CONTROL { yylval.i = _RUNETYPE_C; return(LIST); } -DIGIT { yylval.i = _CTYPE_D|_CTYPE_R|_CTYPE_G; +DIGIT { yylval.i = _RUNETYPE_D|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -GRAPH { yylval.i = _CTYPE_G|_CTYPE_R; +GRAPH { yylval.i = _RUNETYPE_G|_RUNETYPE_R; return(LIST); } -LOWER { yylval.i = _CTYPE_L|_CTYPE_R|_CTYPE_G; +LOWER { yylval.i = _RUNETYPE_L|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -PUNCT { yylval.i = _CTYPE_P|_CTYPE_R|_CTYPE_G; +PUNCT { yylval.i = _RUNETYPE_P|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -SPACE { yylval.i = _CTYPE_S; +SPACE { yylval.i = _RUNETYPE_S; return(LIST); } -UPPER { yylval.i = _CTYPE_U|_CTYPE_R|_CTYPE_G; +UPPER { yylval.i = _RUNETYPE_U|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -XDIGIT { yylval.i = _CTYPE_X|_CTYPE_R|_CTYPE_G; +XDIGIT { yylval.i = _RUNETYPE_X|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -BLANK { yylval.i = _CTYPE_B; +BLANK { yylval.i = _RUNETYPE_B; return(LIST); } -PRINT { yylval.i = _CTYPE_R; +PRINT { yylval.i = _RUNETYPE_R; return(LIST); } -IDEOGRAM { yylval.i = _CTYPE_I|_CTYPE_R|_CTYPE_G; +IDEOGRAM { yylval.i = _RUNETYPE_I|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -SPECIAL { yylval.i = _CTYPE_T|_CTYPE_R|_CTYPE_G; +SPECIAL { yylval.i = _RUNETYPE_T|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -PHONOGRAM { yylval.i = _CTYPE_Q|_CTYPE_R|_CTYPE_G; +PHONOGRAM { yylval.i = _RUNETYPE_Q|_RUNETYPE_R|_RUNETYPE_G; return(LIST); } -SWIDTH0 { yylval.i = _CTYPE_SW0; - if (yylval.i) return(LIST); - printf("Lex is skipping '%s'\n", yytext); } -SWIDTH1 { yylval.i = _CTYPE_SW1; - if (yylval.i) return(LIST); - printf("Lex is skipping '%s'\n", yytext); } -SWIDTH2 { yylval.i = _CTYPE_SW2; - if (yylval.i) return(LIST); - printf("Lex is skipping '%s'\n", yytext); } -SWIDTH3 { yylval.i = _CTYPE_SW3; - if (yylval.i) return(LIST); - printf("Lex is skipping '%s'\n", yytext); } +SWIDTH0 { yylval.i = _RUNETYPE_SW0; return(LIST); } +SWIDTH1 { yylval.i = _RUNETYPE_SW1; return(LIST); } +SWIDTH2 { yylval.i = _RUNETYPE_SW2; return(LIST); } +SWIDTH3 { yylval.i = _RUNETYPE_SW3; return(LIST); } VARIABLE[\t ] { static char vbuf[1024]; char *v = vbuf; @@ -147,6 +127,8 @@ VARIABLE[\t ] { static char vbuf[1024]; return(VARIABLE); } +CHARSET { return(CHARSET); } + ENCODING { return(ENCODING); } \".*\" { char *e = yytext + 1; diff --git a/usr.bin/mklocale/mklocale.1 b/usr.bin/mklocale/mklocale.1 index 8c901b6210..399ddb2c14 100644 --- a/usr.bin/mklocale/mklocale.1 +++ b/usr.bin/mklocale/mklocale.1 @@ -1,3 +1,7 @@ +.\" $NetBSD: src/usr.bin/mklocale/mklocale.1,v 1.13 2004/01/24 17:03:26 wiz Exp $ +.\" FreeBSD: src/usr.bin/mklocale/mklocale.1,v 1.6 1999/09/20 09:15:21 phantom Exp +.\" $DragonFly: src/usr.bin/mklocale/mklocale.1,v 1.5 2005/04/21 16:36:35 joerg Exp $ +.\" .\" Copyright (c) 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" @@ -12,11 +16,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" @@ -33,44 +33,45 @@ .\" SUCH DAMAGE. .\" .\" @(#)mklocale.1 8.2 (Berkeley) 4/18/94 -.\" $FreeBSD: src/usr.bin/mklocale/mklocale.1,v 1.7.2.5 2003/02/24 23:04:39 trhodes Exp $ -.\" $DragonFly: src/usr.bin/mklocale/mklocale.1,v 1.4 2005/03/24 12:48:04 swildner Exp $ .\" -.Dd August 21, 2004 +.Dd April 18, 1994 .Dt MKLOCALE 1 .Os .Sh NAME .Nm mklocale .Nd make LC_CTYPE locale files .Sh SYNOPSIS -.Nm +.Nm mklocale .Op Fl d -.Ar "< src-file" -.Ar "> language/LC_CTYPE" -.Nm +\*[Lt] +.Ar src-file +\*[Gt] +.Ar language/LC_CTYPE +.Nm mklocale .Op Fl d .Fl o .Ar language/LC_CTYPE .Ar src-file .Sh DESCRIPTION The -.Nm -utility reads a +.Nm mklocale +utility reads an .Dv LC_CTYPE -source file from standard input and produces a +source file from standard input and produces an .Dv LC_CTYPE binary file on standard output suitable for placement in -.Pa /usr/share/locale/ Ns Ar language Ns Pa /LC_CTYPE . +.Pa /usr/share/locale/\*[Lt]language\*[Gt]/LC_CTYPE . .Pp The format of .Ar src-file is quite simple. It consists of a series of lines which start with a keyword and have -associated data following. C style comments are used +associated data following. +C style comments are used to place comments in the file. .Pp Following options are available: -.Bl -tag -width indent +.Bl -tag -width XXX .It Fl d Turns on debugging messages. .It Fl o @@ -80,12 +81,12 @@ Specify output file. Besides the keywords which will be listed below, the following are valid tokens in .Ar src-file : -.Bl -tag -width ".Ar literal" +.Bl -tag -width literal .It Dv RUNE A .Dv RUNE may be any of the following: -.Bl -tag -width ".Ar 0x[0-9a-z]*" +.Bl -tag -width 0x[0-9a-z]* .It Ar 'x' The ASCII character .Ar x . @@ -120,11 +121,13 @@ or Used to indicate ranges. .It Ar literal The follow characters are taken literally: -.Bl -tag -width ".Dv <\|\|(\|\|[" -.It Dv "<\|(\|[" -Used to start a mapping. All are equivalent. -.It Dv ">\|\^)\|]" -Used to end a mapping. All are equivalent. +.Bl -tag -width "\*[Lt]\|\|(\|\|[" +.It Dv "\*[Lt]\|(\|[" +Used to start a mapping. +All are equivalent. +.It Dv "\*[Gt]\|\^)\|]" +Used to end a mapping. +All are equivalent. .It Dv : Used as a delimiter in mappings. .El @@ -143,42 +146,13 @@ No translation and the default. .It Dv UTF2 .Dv "Universal character set Transformation Format" adopted from -.Tn "Plan 9 from Bell Labs" . -This is the preferred encoding. +.Nm "Plan 9 from Bell Labs" . .It Dv EUC .Dv EUC encoding as used by several vendors of .Ux systems. -.It Dv GB18030 -PRC national standard for encoding of Chinese text. -.It Dv GB2312 -Older PRC national standard for encoding Chinese text. -.It Dv GBK -A widely used encoding method for Chinese text, -backwards compatible with GB\ 2312-1980. -.It Dv MSKanji -The method of encoding Japanese used by Microsoft, -loosely based on JIS. -Also known as -.Dq "Shift JIS" -and -.Dq SJIS . -.It Dv NONE -No translation and the default. -.It Dv UTF2 -(obsolete) -.Dq "Universal character set Transformation Format" -adopted from -.Tn "Plan 9 from Bell Labs" . -.It Dv UTF-8 -The -.Dv UTF-8 -transformation format of -.Tn ISO -10646 -as defined by RFC 2279. .El .It Dv VARIABLE This keyword must be followed by a single tab or space character, @@ -189,16 +163,20 @@ encoding requires variable data. See .Xr euc 5 for further details. +.It Dv INVALID +A single +.Dv RUNE .El .Pp The following keywords may appear multiple times and have the following format for data: -.Bl -tag -width ".Dv " -offset indent -.It Dv +.in +.5i +.Bl -tag -width "XXRUNE1 THRU RUNEn : RUNE2XX" +.It Aq Dv RUNE1 RUNE2 .Dv RUNE1 is mapped to .Dv RUNE2 . -.It Dv +.It Aq Dv RUNE1 THRU RUNEn : RUNE2 Runes .Dv RUNE1 through @@ -209,7 +187,8 @@ through .Dv RUNE2 + n-1. .El -.Bl -tag -width ".Dv PHONOGRAM" +.in -.5i +.Bl -tag -width PHONOGRAM .It Dv MAPLOWER Defines the tolower mappings. .Dv RUNE2 @@ -223,18 +202,17 @@ is the upper case representation of .It Dv TODIGIT Defines a map from runes to their digit value. .Dv RUNE2 -is the integer value represented by +is the integer value represented by .Dv RUNE1 . For example, the ASCII character -.Ql 0 +.Sq 0 would map to the decimal value 0. -Only values up to 255 -are allowed. +Only values up to 255 are allowed. .El .Pp The following keywords may appear multiple times and have the following format for data: -.Bl -tag -width ".Dv RUNE1 THRU RUNEn" -offset indent +.Bl -tag -width "RUNE1 THRU RUNEn" .It Dv RUNE This rune has the property defined by the keyword. .It Dv "RUNE1 THRU RUNEn" @@ -244,64 +222,61 @@ and .Dv RUNEn have the property defined by the keyword. .El -.Bl -tag -width ".Dv PHONOGRAM" +.Bl -tag -width PHONOGRAM .It Dv ALPHA -Defines runes which are alphabetic, printable and graphic. +Defines runes which are alphabetic, printable, and graphic. .It Dv CONTROL Defines runes which are control characters. .It Dv DIGIT -Defines runes which are decimal digits, printable and graphic. +Defines runes which are decimal digits, printable, and graphic. .It Dv GRAPH Defines runes which are graphic and printable. .It Dv LOWER -Defines runes which are lower case, printable and graphic. +Defines runes which are lower case, printable, and graphic. .It Dv PUNCT -Defines runes which are punctuation, printable and graphic. +Defines runes which are punctuation, printable, and graphic. .It Dv SPACE Defines runes which are spaces. .It Dv UPPER -Defines runes which are upper case, printable and graphic. +Defines runes which are upper case, printable, and graphic. .It Dv XDIGIT -Defines runes which are hexadecimal digits, printable and graphic. +Defines runes which are hexadecimal digits, printable, and graphic. .It Dv BLANK Defines runes which are blank. .It Dv PRINT Defines runes which are printable. .It Dv IDEOGRAM -Defines runes which are ideograms, printable and graphic. +Defines runes which are ideograms, printable, and graphic. .It Dv SPECIAL -Defines runes which are special characters, printable and graphic. +Defines runes which are special characters, printable, and graphic. .It Dv PHONOGRAM -Defines runes which are phonograms, printable and graphic. -.It Dv SWIDTH0 -Defines runes with display width 0. -.It Dv SWIDTH1 -Defines runes with display width 1. -.It Dv SWIDTH2 -Defines runes with display width 2. -.It Dv SWIDTH3 -Defines runes with display width 3. +Defines runes which are phonograms, printable, and graphic. +.It Dv SWIDTHn +Defines runes with specific glyph width. +.Ar n +takes 0 to 3. +.It Dv CHARSET +Controls character set for subsequent runes. +.\" To support +.\" .Xr iso2022 4 +.\" locale definitions. .El -.Pp -If no display width explicitly defined, width 1 assumed -for printable runes by default. .Sh SEE ALSO -.Xr colldef 1 , +.\"Xr colldef 1 , .Xr setlocale 3 , -.Xr wcwidth 3 , -.Xr big5 5 , -.Xr euc 5 , -.Xr gb18030 5 , -.Xr gb2312 5 , -.Xr gbk 5 , -.Xr mskanji 5 , -.Xr utf8 5 -.Sh BUGS -The -.Nm -utility is overly simplistic. +.\" .Xr euc 4 , +.\" .Xr utf8 4 +.Xr nls 7 .Sh HISTORY The -.Nm +.Nm mklocale utility first appeared in .Bx 4.4 . +.Sh BUGS +The +.Nm mklocale +utility is overly simplistic. +.Pp +We should switch to +.Nm localedef +and its file format, which is more standard. diff --git a/usr.bin/mklocale/yacc.y b/usr.bin/mklocale/yacc.y index a729ae96d4..b179b77dba 100644 --- a/usr.bin/mklocale/yacc.y +++ b/usr.bin/mklocale/yacc.y @@ -1,3 +1,6 @@ +/* $NetBSD: src/usr.bin/mklocale/yacc.y,v 1.24 2004/01/05 23:23:36 jmmv Exp $ */ +/* $DragonFly: src/usr.bin/mklocale/yacc.y,v 1.7 2005/04/21 16:36:35 joerg Exp $ */ + %{ /*- * Copyright (c) 1993 @@ -14,11 +17,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,16 +32,12 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)yacc.y 8.1 (Berkeley) 6/6/93 - * $FreeBSD: src/usr.bin/mklocale/yacc.y,v 1.6.2.3 2003/06/03 21:15:48 ache Exp $ - * $DragonFly: src/usr.bin/mklocale/yacc.y,v 1.6 2005/04/18 17:42:15 joerg Exp $ */ #include -#include -#include +#include /* Needed for htonl on POSIX systems. */ +#include #include #include #include @@ -50,35 +45,40 @@ #include #include -#include "ctype.h" -#include "runetype.h" +#include "locale/runetype.h" #include "ldef.h" -#include "extern.h" - -static void *xmalloc(unsigned int sz); -static unsigned long *xlalloc(unsigned int sz); -void yyerror(const char *s); -static unsigned long *xrelalloc(unsigned long *old, unsigned int sz); -static void dump_tables(void); -static void cleanout(void); const char *locale_file = ""; -rune_map maplower = { { 0 }, NULL }; -rune_map mapupper = { { 0 }, NULL }; -rune_map types = { { 0 }, NULL }; - -_RuneLocale new_locale = { "", "", NULL, NULL, 0, {}, {}, {}, - {0, NULL}, {0, NULL}, {0, NULL}, NULL, 0 }; - -void set_map(rune_map *, rune_list *, unsigned long); -void set_digitmap(rune_map *, rune_list *); -void add_map(rune_map *, rune_list *, unsigned long); +rune_map maplower = { { 0, }, NULL }; +rune_map mapupper = { { 0, }, NULL }; +rune_map types = { { 0, }, NULL }; + +_NBRuneLocale new_locale; + +__nbrune_t charsetbits = (__nbrune_t)0x00000000; +#if 0 +__nbrune_t charsetmask = (__nbrune_t)0x0000007f; +#endif +__nbrune_t charsetmask = (__nbrune_t)0xffffffff; + +void set_map(rune_map *, rune_list *, uint32_t); +void set_digitmap(rune_map *, rune_list *); +void add_map(rune_map *, rune_list *, uint32_t); + +int main(int, char *[]); +int yyerror(const char *s); +void *xmalloc(unsigned int sz); +uint32_t *xlalloc(unsigned int sz); +uint32_t *xrelalloc(uint32_t *old, unsigned int sz); +void dump_tables(void); +int yyparse(void); +extern int yylex(void); %} %union { - rune_t rune; + __nbrune_t rune; int i; char *str; @@ -94,7 +94,9 @@ void add_map(rune_map *, rune_list *, unsigned long); %token DIGITMAP %token LIST %token VARIABLE +%token CHARSET %token ENCODING +%token INVALID %token STRING %type list @@ -113,22 +115,49 @@ table : entry ; entry : ENCODING STRING - { if (strcmp($2, "NONE") && - strcmp($2, "UTF2") && - strcmp($2, "UTF-8") && - strcmp($2, "EUC") && - strcmp($2, "GBK") && - strcmp($2, "GB18030") && - strcmp($2, "GB2312") && - strcmp($2, "BIG5") && - strcmp($2, "MSKanji")) - warnx("ENCODING %s is not supported by libc", $2); - strncpy(new_locale.encoding, $2, sizeof(new_locale.encoding)); } + { strncpy(new_locale.rl_encoding, $2, sizeof(new_locale.rl_encoding)); } | VARIABLE - { new_locale.variable_len = strlen($1) + 1; - new_locale.variable = malloc(new_locale.variable_len); - strcpy((char *)new_locale.variable, $1); + { new_locale.rl_variable_len = strlen($1) + 1; + new_locale.rl_variable = strdup($1); + } + | CHARSET RUNE + { charsetbits = $2; charsetmask = 0x0000007f; } + | CHARSET RUNE RUNE + { charsetbits = $2; charsetmask = $3; } + | CHARSET STRING + { int final = $2[strlen($2) - 1] & 0x7f; + charsetbits = final << 24; + if ($2[0] == '$') { + charsetmask = 0x00007f7f; + if (strchr(",-./", $2[1])) + charsetbits |= 0x80; + if (0xd0 <= final && final <= 0xdf) + charsetmask |= 0x007f0000; + } else { + charsetmask = 0x0000007f; + if (strchr(",-./", $2[0])) + charsetbits |= 0x80; + if (strlen($2) == 2 && $2[0] == '!') + charsetbits |= ((0x80 | $2[0]) << 16); + } + + /* + * special rules + */ + if (charsetbits == ('B' << 24) + && charsetmask == 0x0000007f) { + /*ASCII: 94B*/ + charsetbits = 0; + charsetmask = 0x0000007f; + } else if (charsetbits == (('A' << 24) | 0x80) + && charsetmask == 0x0000007f) { + /*Latin1: 96A*/ + charsetbits = 0x80; + charsetmask = 0x0000007f; + } } + | INVALID RUNE + { new_locale.rl_invalid_rune = $2; } | LIST list { set_map(&types, $2, $1); } | MAPLOWER map @@ -142,29 +171,29 @@ entry : ENCODING STRING list : RUNE { $$ = (rune_list *)malloc(sizeof(rune_list)); - $$->min = $1; - $$->max = $1; + $$->min = ($1 & charsetmask) | charsetbits; + $$->max = ($1 & charsetmask) | charsetbits; $$->next = 0; } | RUNE THRU RUNE { $$ = (rune_list *)malloc(sizeof(rune_list)); - $$->min = $1; - $$->max = $3; + $$->min = ($1 & charsetmask) | charsetbits; + $$->max = ($3 & charsetmask) | charsetbits; $$->next = 0; } | list RUNE { $$ = (rune_list *)malloc(sizeof(rune_list)); - $$->min = $2; - $$->max = $2; + $$->min = ($2 & charsetmask) | charsetbits; + $$->max = ($2 & charsetmask) | charsetbits; $$->next = $1; } | list RUNE THRU RUNE { $$ = (rune_list *)malloc(sizeof(rune_list)); - $$->min = $2; - $$->max = $4; + $$->min = ($2 & charsetmask) | charsetbits; + $$->max = ($4 & charsetmask) | charsetbits; $$->next = $1; } ; @@ -172,57 +201,46 @@ list : RUNE map : LBRK RUNE RUNE RBRK { $$ = (rune_list *)malloc(sizeof(rune_list)); - $$->min = $2; - $$->max = $2; + $$->min = ($2 & charsetmask) | charsetbits; + $$->max = ($2 & charsetmask) | charsetbits; $$->map = $3; $$->next = 0; } | map LBRK RUNE RUNE RBRK { $$ = (rune_list *)malloc(sizeof(rune_list)); - $$->min = $3; - $$->max = $3; + $$->min = ($3 & charsetmask) | charsetbits; + $$->max = ($3 & charsetmask) | charsetbits; $$->map = $4; $$->next = $1; } | LBRK RUNE THRU RUNE ':' RUNE RBRK { $$ = (rune_list *)malloc(sizeof(rune_list)); - $$->min = $2; - $$->max = $4; + $$->min = ($2 & charsetmask) | charsetbits; + $$->max = ($4 & charsetmask) | charsetbits; $$->map = $6; $$->next = 0; } | map LBRK RUNE THRU RUNE ':' RUNE RBRK { $$ = (rune_list *)malloc(sizeof(rune_list)); - $$->min = $3; - $$->max = $5; + $$->min = ($3 & charsetmask) | charsetbits; + $$->max = ($5 & charsetmask) | charsetbits; $$->map = $7; $$->next = $1; } ; %% -int debug; -FILE *fp; - -static void -cleanout(void) -{ - if (fp != NULL) - unlink(locale_file); -} +int debug = 0; +FILE *ofile; int main(int ac, char *av[]) { int x; - extern char *optarg; - extern int optind; - fp = stdout; - while ((x = getopt(ac, av, "do:")) != EOF) { switch(x) { case 'd': @@ -230,11 +248,8 @@ main(int ac, char *av[]) break; case 'o': locale_file = optarg; - if ((fp = fopen(locale_file, "w")) == 0) { - perror(locale_file); - exit(1); - } - atexit(cleanout); + if ((ofile = fopen(locale_file, "w")) == 0) + err(1, "unable to open output file %s", locale_file); break; default: usage: @@ -247,76 +262,70 @@ main(int ac, char *av[]) case 0: break; case 1: - if (freopen(av[optind], "r", stdin) == 0) { - perror(av[optind]); - exit(1); - } + if (freopen(av[optind], "r", stdin) == 0) + err(1, "unable to open input file %s", av[optind]); break; default: goto usage; } - for (x = 0; x < _CACHED_RUNES; ++x) { + for (x = 0; x < _NB_CACHED_RUNES; ++x) { mapupper.map[x] = x; maplower.map[x] = x; } - memcpy(new_locale.magic, _RUNE_MAGIC_1, sizeof(new_locale.magic)); + new_locale.rl_invalid_rune = _NB_DEFAULT_INVALID_RUNE; + memcpy(new_locale.rl_magic, _NB_RUNE_MAGIC_1, sizeof(new_locale.rl_magic)); yyparse(); - return(0); + return 0; } -void -yyerror(s) - const char *s; +int +yyerror(const char *s) { fprintf(stderr, "%s\n", s); + + return 0; } -static void * -xmalloc(sz) - unsigned int sz; +void * +xmalloc(unsigned int sz) { void *r = malloc(sz); if (!r) { perror("xmalloc"); - exit(1); + abort(); } return(r); } -static unsigned long * -xlalloc(sz) - unsigned int sz; +uint32_t * +xlalloc(unsigned int sz) { - unsigned long *r = (unsigned long *)malloc(sz * sizeof(unsigned long)); + uint32_t *r = (uint32_t *)malloc(sz * sizeof(uint32_t)); if (!r) { perror("xlalloc"); - exit(1); + abort(); } return(r); } -static unsigned long * -xrelalloc(old, sz) - unsigned long *old; - unsigned int sz; +uint32_t * +xrelalloc(uint32_t *old, unsigned int sz) { - unsigned long *r = (unsigned long *)realloc((char *)old, - sz * sizeof(unsigned long)); + uint32_t *r = (uint32_t *)realloc((char *)old, sz * sizeof(uint32_t)); if (!r) { perror("xrelalloc"); - exit(1); + abort(); } return(r); } void -set_map(map, list, flag) - rune_map *map; - rune_list *list; - unsigned long flag; +set_map(rune_map *map, rune_list *list, uint32_t flag) { + list->map &= charsetmask; + list->map |= charsetbits; while (list) { rune_list *nlist = list->next; add_map(map, list, flag); @@ -325,11 +334,9 @@ set_map(map, list, flag) } void -set_digitmap(map, list) - rune_map *map; - rune_list *list; +set_digitmap(rune_map *map, rune_list *list) { - rune_t i; + __nbrune_t i; while (list) { rune_list *nlist = list->next; @@ -347,17 +354,14 @@ set_digitmap(map, list) } void -add_map(map, list, flag) - rune_map *map; - rune_list *list; - unsigned long flag; +add_map(rune_map *map, rune_list *list, uint32_t flag) { - rune_t i; + __nbrune_t i; rune_list *lr = 0; rune_list *r; - rune_t run; + __nbrune_t run; - while (list->min < _CACHED_RUNES && list->min <= list->max) { + while (list->min < _NB_CACHED_RUNES && list->min <= list->max) { if (flag) map->map[list->min++] |= flag; else @@ -555,11 +559,16 @@ add_map(map, list, flag) } } -static void -dump_tables() +void +dump_tables(void) { - int x, first_d, curr_d; + int n; + __nbrune_t x; rune_list *list; + _FileRuneLocale file_new_locale; + FILE *fp = (ofile ? ofile : stdout); + + memset(&file_new_locale, 0, sizeof(file_new_locale)); /* * See if we can compress some of the istype arrays @@ -567,41 +576,19 @@ dump_tables() for(list = types.root; list; list = list->next) { list->map = list->types[0]; for (x = 1; x < list->max - list->min + 1; ++x) { - if ((rune_t)list->types[x] != list->map) { + if (list->types[x] != list->map) { list->map = 0; break; } } } - first_d = -1; - for (x = 0; x < _CACHED_RUNES; ++x) { - unsigned long r = types.map[x]; - - if (r & _CTYPE_D) { - if (first_d < 0) - first_d = curr_d = x; - else if (x != curr_d + 1) { - fprintf(stderr, "Error: DIGIT range is not contiguous\n"); - exit(1); - } else if (x - first_d > 9) { - fprintf(stderr, "Error: DIGIT range is too big\n"); - exit(1); - } else - curr_d++; - if (!(r & _CTYPE_X)) { - fprintf(stderr, "Error: DIGIT range is not a subset of XDIGIT range\n"); - exit(1); - } - } - } - if (first_d < 0) { - fprintf(stderr, "Error: no DIGIT range defined in the single byte area\n"); - exit(1); - } else if (curr_d - first_d < 9) { - fprintf(stderr, "Error: DIGIT range is too small in the single byte area\n"); - exit(1); - } + memcpy(&file_new_locale.frl_magic, new_locale.rl_magic, + sizeof(file_new_locale.frl_magic)); + memcpy(&file_new_locale.frl_encoding, new_locale.rl_encoding, + sizeof(file_new_locale.frl_encoding)); + + file_new_locale.frl_invalid_rune = htonl(new_locale.rl_invalid_rune); /* * Fill in our tables. Do this in network order so that @@ -609,10 +596,10 @@ dump_tables() * (Machines like Crays cannot share with little machines due to * word size. Sigh. We tried.) */ - for (x = 0; x < _CACHED_RUNES; ++x) { - new_locale.runetype[x] = htonl(types.map[x]); - new_locale.maplower[x] = htonl(maplower.map[x]); - new_locale.mapupper[x] = htonl(mapupper.map[x]); + for (x = 0; x < _NB_CACHED_RUNES; ++x) { + file_new_locale.frl_runetype[x] = htonl(types.map[x]); + file_new_locale.frl_maplower[x] = htonl(maplower.map[x]); + file_new_locale.frl_mapupper[x] = htonl(mapupper.map[x]); } /* @@ -621,28 +608,31 @@ dump_tables() list = types.root; while (list) { - new_locale.runetype_ext.nranges++; + new_locale.rl_runetype_ext.rr_nranges++; list = list->next; } - new_locale.runetype_ext.nranges = htonl(new_locale.runetype_ext.nranges); + file_new_locale.frl_runetype_ext.frr_nranges = + htonl(new_locale.rl_runetype_ext.rr_nranges); list = maplower.root; while (list) { - new_locale.maplower_ext.nranges++; + new_locale.rl_maplower_ext.rr_nranges++; list = list->next; } - new_locale.maplower_ext.nranges = htonl(new_locale.maplower_ext.nranges); + file_new_locale.frl_maplower_ext.frr_nranges = + htonl(new_locale.rl_maplower_ext.rr_nranges); list = mapupper.root; while (list) { - new_locale.mapupper_ext.nranges++; + new_locale.rl_mapupper_ext.rr_nranges++; list = list->next; } - new_locale.mapupper_ext.nranges = htonl(new_locale.mapupper_ext.nranges); + file_new_locale.frl_mapupper_ext.frr_nranges = + htonl(new_locale.rl_mapupper_ext.rr_nranges); - new_locale.variable_len = htonl(new_locale.variable_len); + file_new_locale.frl_variable_len = htonl(new_locale.rl_variable_len); /* * Okay, we are now ready to write the new locale file. @@ -651,115 +641,89 @@ dump_tables() /* * PART 1: The _RuneLocale structure */ - if (fwrite((char *)&new_locale, sizeof(new_locale), 1, fp) != 1) { - perror(locale_file); - exit(1); - } + if (fwrite((char *)&file_new_locale, sizeof(file_new_locale), 1, fp) != 1) + err(1, "writing _RuneLocale to %s", locale_file); /* * PART 2: The runetype_ext structures (not the actual tables) */ - list = types.root; + for (list = types.root, n = 0; list != NULL; list = list->next, n++) { + _FileRuneEntry re; - while (list) { - _RuneEntry re; - - re.min = htonl(list->min); - re.max = htonl(list->max); - re.map = htonl(list->map); - - if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) { - perror(locale_file); - exit(1); - } + memset(&re, 0, sizeof(re)); + re.fre_min = htonl(list->min); + re.fre_max = htonl(list->max); + re.fre_map = htonl(list->map); - list = list->next; + if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) + err(1, "writing runetype_ext #%d to %s", n, locale_file); } /* * PART 3: The maplower_ext structures */ - list = maplower.root; - - while (list) { - _RuneEntry re; + for (list = maplower.root, n = 0; list != NULL; list = list->next, n++) { + _FileRuneEntry re; - re.min = htonl(list->min); - re.max = htonl(list->max); - re.map = htonl(list->map); - - if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) { - perror(locale_file); - exit(1); - } + memset(&re, 0, sizeof(re)); + re.fre_min = htonl(list->min); + re.fre_max = htonl(list->max); + re.fre_map = htonl(list->map); - list = list->next; + if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) + err(1, "writing maplower_ext #%d to %s", n, locale_file); } /* * PART 4: The mapupper_ext structures */ - list = mapupper.root; - - while (list) { - _RuneEntry re; + for (list = mapupper.root, n = 0; list != NULL; list = list->next, n++) { + _FileRuneEntry re; - re.min = htonl(list->min); - re.max = htonl(list->max); - re.map = htonl(list->map); + memset(&re, 0, sizeof(re)); + re.fre_min = htonl(list->min); + re.fre_max = htonl(list->max); + re.fre_map = htonl(list->map); - if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) { - perror(locale_file); - exit(1); - } - - list = list->next; + if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) + err(1, "writing mapupper_ext #%d to %s", n, locale_file); } /* * PART 5: The runetype_ext tables */ - list = types.root; - - while (list) { + for (list = types.root, n = 0; list != NULL; list = list->next, n++) { for (x = 0; x < list->max - list->min + 1; ++x) list->types[x] = htonl(list->types[x]); if (!list->map) { if (fwrite((char *)list->types, - (list->max - list->min + 1) * sizeof(unsigned long), - 1, fp) != 1) { - perror(locale_file); - exit(1); - } + (list->max - list->min + 1) * sizeof(uint32_t), + 1, fp) != 1) + err(1, "writing runetype_ext table #%d to %s", n, locale_file); } - list = list->next; } /* * PART 5: And finally the variable data */ - if (fwrite((char *)new_locale.variable, - ntohl(new_locale.variable_len), 1, fp) != 1) { - perror(locale_file); - exit(1); - } - if (fclose(fp) != 0) { - perror(locale_file); - exit(1); - } - fp = NULL; + if (new_locale.rl_variable_len != 0 && + fwrite((char *)new_locale.rl_variable, + new_locale.rl_variable_len, 1, fp) != 1) + err(1, "writing variable data to %s", locale_file); + fclose(fp); if (!debug) return; - if (new_locale.encoding[0]) - fprintf(stderr, "ENCODING %s\n", new_locale.encoding); - if (new_locale.variable) - fprintf(stderr, "VARIABLE %s\n", (char *)new_locale.variable); + if (new_locale.rl_encoding[0]) + fprintf(stderr, "ENCODING %s\n", new_locale.rl_encoding); + if (new_locale.rl_variable) + fprintf(stderr, "VARIABLE %s\n", + (char *)new_locale.rl_variable); fprintf(stderr, "\nMAPLOWER:\n\n"); - for (x = 0; x < _CACHED_RUNES; ++x) { + for (x = 0; x < _NB_CACHED_RUNES; ++x) { if (isprint(maplower.map[x])) fprintf(stderr, " '%c'", (int)maplower.map[x]); else if (maplower.map[x]) - fprintf(stderr, "%04lx", maplower.map[x]); + fprintf(stderr, "%04x", maplower.map[x]); else fprintf(stderr, "%4x", 0); if ((x & 0xf) == 0xf) @@ -774,11 +738,11 @@ dump_tables() fprintf(stderr, "\nMAPUPPER:\n\n"); - for (x = 0; x < _CACHED_RUNES; ++x) { + for (x = 0; x < _NB_CACHED_RUNES; ++x) { if (isprint(mapupper.map[x])) fprintf(stderr, " '%c'", (int)mapupper.map[x]); else if (mapupper.map[x]) - fprintf(stderr, "%04lx", mapupper.map[x]); + fprintf(stderr, "%04x", mapupper.map[x]); else fprintf(stderr, "%4x", 0); if ((x & 0xf) == 0xf) @@ -794,95 +758,95 @@ dump_tables() fprintf(stderr, "\nTYPES:\n\n"); - for (x = 0; x < _CACHED_RUNES; ++x) { - unsigned long r = types.map[x]; + for (x = 0; x < _NB_CACHED_RUNES; ++x) { + uint32_t r = types.map[x]; if (r) { if (isprint(x)) - fprintf(stderr, " '%c': %2d", x, (int)(r & 0xff)); + fprintf(stderr, " '%c':%2d", x, (int)(r & 0xff)); else - fprintf(stderr, "%04x: %2d", x, (int)(r & 0xff)); - - fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : ""); + fprintf(stderr, "%04x:%2d", x, (int)(r & 0xff)); + + fprintf(stderr, " %4s", (r & _RUNETYPE_A) ? "alph" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_C) ? "ctrl" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_D) ? "dig" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_G) ? "graf" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_L) ? "low" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_P) ? "punc" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_S) ? "spac" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_U) ? "upp" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_X) ? "xdig" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_B) ? "blnk" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_R) ? "prnt" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_I) ? "ideo" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_T) ? "spec" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_Q) ? "phon" : ""); fprintf(stderr, "\n"); } } for (list = types.root; list; list = list->next) { if (list->map && list->min + 3 < list->max) { - unsigned long r = list->map; - - fprintf(stderr, "%04lx: %2d", - (unsigned long)list->min, (int)(r & 0xff)); - - fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : ""); + uint32_t r = list->map; + + fprintf(stderr, "%04x:%2d", list->min, r & 0xff); + + fprintf(stderr, " %4s", (r & _RUNETYPE_A) ? "alph" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_C) ? "ctrl" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_D) ? "dig" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_G) ? "graf" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_L) ? "low" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_P) ? "punc" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_S) ? "spac" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_U) ? "upp" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_X) ? "xdig" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_B) ? "blnk" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_R) ? "prnt" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_I) ? "ideo" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_T) ? "spec" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_Q) ? "phon" : ""); fprintf(stderr, "\n...\n"); - fprintf(stderr, "%04lx: %2d", - (unsigned long)list->max, (int)(r & 0xff)); - - fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : ""); + fprintf(stderr, "%04x:%2d", list->max, r & 0xff); + + fprintf(stderr, " %4s", (r & _RUNETYPE_A) ? "alph" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_C) ? "ctrl" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_D) ? "dig" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_G) ? "graf" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_L) ? "low" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_P) ? "punc" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_S) ? "spac" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_U) ? "upp" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_X) ? "xdig" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_B) ? "blnk" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_R) ? "prnt" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_I) ? "ideo" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_T) ? "spec" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_Q) ? "phon" : ""); + fprintf(stderr, " %1u", (unsigned)((r & _RUNETYPE_SWM)>>_RUNETYPE_SWS)); fprintf(stderr, "\n"); } else for (x = list->min; x <= list->max; ++x) { - unsigned long r = ntohl(list->types[x - list->min]); + uint32_t r = ntohl(list->types[x - list->min]); if (r) { - fprintf(stderr, "%04x: %2d", x, (int)(r & 0xff)); - - fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : ""); - fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : ""); + fprintf(stderr, "%04x:%2d", x, (int)(r & 0xff)); + + fprintf(stderr, " %4s", (r & _RUNETYPE_A) ? "alph" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_C) ? "ctrl" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_D) ? "dig" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_G) ? "graf" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_L) ? "low" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_P) ? "punc" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_S) ? "spac" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_U) ? "upp" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_X) ? "xdig" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_B) ? "blnk" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_R) ? "prnt" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_I) ? "ideo" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_T) ? "spec" : ""); + fprintf(stderr, " %4s", (r & _RUNETYPE_Q) ? "phon" : ""); + fprintf(stderr, " %1u", (unsigned)((r & _RUNETYPE_SWM)>>_RUNETYPE_SWS)); fprintf(stderr, "\n"); } }