Sun Mar 4 21:14:57 2012 UTC ()
don't use __link_set_* stuff for locale implementation.
patch reviewed by matt@, thanks.


(tnozaki)
diff -r1.9 -r1.10 src/lib/libc/citrus/citrus_lc_ctype.c
diff -r1.4 -r1.5 src/lib/libc/citrus/citrus_lc_messages.c
diff -r1.4 -r1.5 src/lib/libc/citrus/citrus_lc_monetary.c
diff -r1.4 -r1.5 src/lib/libc/citrus/citrus_lc_numeric.c
diff -r1.5 -r1.6 src/lib/libc/citrus/citrus_lc_time.c
diff -r1.2 -r1.3 src/lib/libc/locale/dummy_lc_collate.c
diff -r1.2 -r1.3 src/lib/libc/locale/dummy_lc_template.h
diff -r1.2 -r1.3 src/lib/libc/locale/generic_lc_template_decl.h
diff -r1.3 -r1.4 src/lib/libc/locale/generic_lc_all.c
diff -r1.3 -r1.4 src/lib/libc/locale/nb_lc_template.h
diff -r1.3 -r0 src/lib/libc/locale/generic_lc_template.h
diff -r1.59 -r1.60 src/lib/libc/locale/setlocale.c
diff -r1.7 -r1.8 src/lib/libc/locale/setlocale_local.h

cvs diff -r1.9 -r1.10 src/lib/libc/citrus/citrus_lc_ctype.c (switch to unified diff)

--- src/lib/libc/citrus/citrus_lc_ctype.c 2010/06/19 13:26:51 1.9
+++ src/lib/libc/citrus/citrus_lc_ctype.c 2012/03/04 21:14:55 1.10
@@ -1,133 +1,132 @@ @@ -1,133 +1,132 @@
1/* $NetBSD: citrus_lc_ctype.c,v 1.9 2010/06/19 13:26:51 tnozaki Exp $ */ 1/* $NetBSD: citrus_lc_ctype.c,v 1.10 2012/03/04 21:14:55 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: citrus_lc_ctype.c,v 1.9 2010/06/19 13:26:51 tnozaki Exp $"); 31__RCSID("$NetBSD: citrus_lc_ctype.c,v 1.10 2012/03/04 21:14:55 tnozaki Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include "reentrant.h" 34#include "reentrant.h"
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/ctype_bits.h> 36#include <sys/ctype_bits.h>
37#include <sys/queue.h> 37#include <sys/queue.h>
38#include <assert.h> 38#include <assert.h>
39#include <errno.h> 39#include <errno.h>
40#include <langinfo.h> 40#include <langinfo.h>
41#include <limits.h> 41#include <limits.h>
42#define __SETLOCALE_SOURCE__ 42#define __SETLOCALE_SOURCE__
43#include <locale.h> 43#include <locale.h>
44#include <stddef.h> 44#include <stddef.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48#include <wchar.h> 48#include <wchar.h>
49 49
50#include "setlocale_local.h" 50#include "setlocale_local.h"
51 51
52#include "citrus_namespace.h" 52#include "citrus_namespace.h"
53#include "citrus_bcs.h" 53#include "citrus_bcs.h"
54#include "citrus_region.h" 54#include "citrus_region.h"
55#include "citrus_lookup.h" 55#include "citrus_lookup.h"
56#include "citrus_aliasname_local.h" 56#include "citrus_aliasname_local.h"
57#include "citrus_module.h" 57#include "citrus_module.h"
58#include "citrus_ctype.h" 58#include "citrus_ctype.h"
59#include "citrus_mmap.h" 59#include "citrus_mmap.h"
60 60
61#include "runetype_local.h" 61#include "runetype_local.h"
62#include "multibyte.h" 62#include "multibyte.h"
63 63
64/* 64/*
65 * macro required by all template headers 65 * macro required by all template headers
66 */ 66 */
67#define _PREFIX(name) __CONCAT(_citrus_LC_CTYPE_, name) 67#define _PREFIX(name) __CONCAT(_citrus_LC_CTYPE_, name)
68 68
69/* 69/*
70 * macro required by nb_lc_template(_decl).h 70 * macro required by nb_lc_template(_decl).h
71 */ 71 */
72#define _CATEGORY_TYPE _RuneLocale 72#define _CATEGORY_TYPE _RuneLocale
73 73
74#include "nb_lc_template_decl.h" 74#include "nb_lc_template_decl.h"
75 75
76static int 76static int
77_citrus_LC_CTYPE_create_impl(const char * __restrict root, 77_citrus_LC_CTYPE_create_impl(const char * __restrict root,
78 const char * __restrict name, _RuneLocale ** __restrict pdata) 78 const char * __restrict name, _RuneLocale ** __restrict pdata)
79{ 79{
80 char path[PATH_MAX + 1]; 80 char path[PATH_MAX + 1];
81 int ret; 81 int ret;
82 struct _region r; 82 struct _region r;
83 83
84 _DIAGASSERT(root != NULL); 84 _DIAGASSERT(root != NULL);
85 _DIAGASSERT(name != NULL); 85 _DIAGASSERT(name != NULL);
86 _DIAGASSERT(pdata != NULL); 86 _DIAGASSERT(pdata != NULL);
87 87
88 snprintf(path, sizeof(path), 88 snprintf(path, sizeof(path),
89 "%s/%s/LC_CTYPE", root, name); 89 "%s/%s/LC_CTYPE", root, name);
90 ret = _citrus_map_file(&r, path); 90 ret = _citrus_map_file(&r, path);
91 if (!ret) { 91 if (!ret) {
92 ret = _rune_load((const char *)r.r_head, r.r_size, pdata); 92 ret = _rune_load((const char *)r.r_head, r.r_size, pdata);
93 _citrus_unmap_file(&r); 93 _citrus_unmap_file(&r);
94 } 94 }
95 return ret; 95 return ret;
96} 96}
97 97
98static __inline void 98static __inline void
99_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache, 99_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache,
100 _RuneLocale * __restrict data) 100 _RuneLocale * __restrict data)
101{ 101{
102 _DIAGASSERT(cache != NULL); 102 _DIAGASSERT(cache != NULL);
103 _DIAGASSERT(cache->items != NULL); 103 _DIAGASSERT(cache->items != NULL);
104 _DIAGASSERT(data != NULL); 104 _DIAGASSERT(data != NULL);
105 105
106 cache->ctype_tab = data->rl_ctype_tab; 106 cache->ctype_tab = data->rl_ctype_tab;
107 cache->tolower_tab = data->rl_tolower_tab; 107 cache->tolower_tab = data->rl_tolower_tab;
108 cache->toupper_tab = data->rl_toupper_tab; 108 cache->toupper_tab = data->rl_toupper_tab;
109 cache->mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype); 109 cache->mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype);
110 cache->items[(size_t)CODESET] = data->rl_codeset; 110 cache->items[(size_t)CODESET] = data->rl_codeset;
111} 111}
112 112
113static __inline void 113static __inline void
114_PREFIX(fixup)(_RuneLocale *data) 114_PREFIX(fixup)(_RuneLocale *data)
115{ 115{
116 _DIAGASSERT(data != NULL); 116 _DIAGASSERT(data != NULL);
117 117
118 __mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype); 118 __mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype);
119 _ctype_ = data->rl_ctype_tab; 119 _ctype_ = data->rl_ctype_tab;
120 _tolower_tab_ = data->rl_tolower_tab; 120 _tolower_tab_ = data->rl_tolower_tab;
121 _toupper_tab_ = data->rl_toupper_tab; 121 _toupper_tab_ = data->rl_toupper_tab;
122 _CurrentRuneLocale = data; 122 _CurrentRuneLocale = data;
123} 123}
124 124
125/* 125/*
126 * macro required by nb_lc_template.h 126 * macro required by nb_lc_template.h
127 */ 127 */
128#define _CATEGORY_ID LC_CTYPE 128#define _CATEGORY_ID LC_CTYPE
129#define _CATEGORY_NAME "LC_CTYPE" 129#define _CATEGORY_NAME "LC_CTYPE"
130#define _CATEGORY_DEFAULT _DefaultRuneLocale 130#define _CATEGORY_DEFAULT _DefaultRuneLocale
131 131
132#include "nb_lc_template.h" 132#include "nb_lc_template.h"
133_LOCALE_CATEGORY_ENTRY(_citrus_LC_CTYPE_); 

cvs diff -r1.4 -r1.5 src/lib/libc/citrus/citrus_lc_messages.c (switch to unified diff)

--- src/lib/libc/citrus/citrus_lc_messages.c 2010/06/13 04:14:57 1.4
+++ src/lib/libc/citrus/citrus_lc_messages.c 2012/03/04 21:14:55 1.5
@@ -1,163 +1,162 @@ @@ -1,163 +1,162 @@
1/* $NetBSD: citrus_lc_messages.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $ */ 1/* $NetBSD: citrus_lc_messages.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: citrus_lc_messages.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $"); 31__RCSID("$NetBSD: citrus_lc_messages.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include "namespace.h" 34#include "namespace.h"
35#include "reentrant.h" 35#include "reentrant.h"
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/localedef.h> 37#include <sys/localedef.h>
38#include <sys/queue.h> 38#include <sys/queue.h>
39#include <assert.h> 39#include <assert.h>
40#include <errno.h> 40#include <errno.h>
41#include <langinfo.h> 41#include <langinfo.h>
42#include <limits.h> 42#include <limits.h>
43#define __SETLOCALE_SOURCE__ 43#define __SETLOCALE_SOURCE__
44#include <locale.h> 44#include <locale.h>
45#include <stddef.h> 45#include <stddef.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "setlocale_local.h" 50#include "setlocale_local.h"
51 51
52#include "citrus_namespace.h" 52#include "citrus_namespace.h"
53#include "citrus_types.h" 53#include "citrus_types.h"
54#include "citrus_bcs.h" 54#include "citrus_bcs.h"
55#include "citrus_region.h" 55#include "citrus_region.h"
56#include "citrus_lookup.h" 56#include "citrus_lookup.h"
57#include "citrus_aliasname_local.h" 57#include "citrus_aliasname_local.h"
58#include "citrus_module.h" 58#include "citrus_module.h"
59#include "citrus_mmap.h" 59#include "citrus_mmap.h"
60#include "citrus_hash.h" 60#include "citrus_hash.h"
61#include "citrus_db.h" 61#include "citrus_db.h"
62#include "citrus_db_hash.h" 62#include "citrus_db_hash.h"
63#include "citrus_memstream.h" 63#include "citrus_memstream.h"
64#include "runetype_local.h" 64#include "runetype_local.h"
65 65
66/* 66/*
67 * macro required by all template headers 67 * macro required by all template headers
68 */ 68 */
69#define _PREFIX(name) __CONCAT(_citrus_LC_MESSAGES_, name) 69#define _PREFIX(name) __CONCAT(_citrus_LC_MESSAGES_, name)
70 70
71#include "nb_lc_messages_misc.h" 71#include "nb_lc_messages_misc.h"
72#include "citrus_lc_template_decl.h" 72#include "citrus_lc_template_decl.h"
73 73
74static __inline void 74static __inline void
75_citrus_LC_MESSAGES_uninit(_MessagesLocale *data) 75_citrus_LC_MESSAGES_uninit(_MessagesLocale *data)
76{ 76{
77 free(__UNCONST(data->yesexpr)); 77 free(__UNCONST(data->yesexpr));
78 free(__UNCONST(data->noexpr)); 78 free(__UNCONST(data->noexpr));
79 free(__UNCONST(data->yesstr)); 79 free(__UNCONST(data->yesstr));
80 free(__UNCONST(data->nostr)); 80 free(__UNCONST(data->nostr));
81} 81}
82 82
83#include "citrus_lc_messages.h" 83#include "citrus_lc_messages.h"
84 84
85struct _citrus_LC_MESSAGES_key { 85struct _citrus_LC_MESSAGES_key {
86 const char *name; 86 const char *name;
87 size_t offset; 87 size_t offset;
88}; 88};
89 89
90#define OFFSET(field) (offsetof(_MessagesLocale, field)) 90#define OFFSET(field) (offsetof(_MessagesLocale, field))
91static const struct _citrus_LC_MESSAGES_key keys[] = { 91static const struct _citrus_LC_MESSAGES_key keys[] = {
92 { _CITRUS_LC_MESSAGES_SYM_YESEXPR, OFFSET(yesexpr) }, 92 { _CITRUS_LC_MESSAGES_SYM_YESEXPR, OFFSET(yesexpr) },
93 { _CITRUS_LC_MESSAGES_SYM_NOEXPR, OFFSET(noexpr ) }, 93 { _CITRUS_LC_MESSAGES_SYM_NOEXPR, OFFSET(noexpr ) },
94 { _CITRUS_LC_MESSAGES_SYM_YESSTR, OFFSET(yesstr ) }, 94 { _CITRUS_LC_MESSAGES_SYM_YESSTR, OFFSET(yesstr ) },
95 { _CITRUS_LC_MESSAGES_SYM_NOSTR, OFFSET(nostr ) }, 95 { _CITRUS_LC_MESSAGES_SYM_NOSTR, OFFSET(nostr ) },
96 { NULL, 0 } 96 { NULL, 0 }
97}; 97};
98 98
99static __inline int 99static __inline int
100_citrus_LC_MESSAGES_init_normal(_MessagesLocale * __restrict data, 100_citrus_LC_MESSAGES_init_normal(_MessagesLocale * __restrict data,
101 struct _citrus_db * __restrict db) 101 struct _citrus_db * __restrict db)
102{ 102{
103 const struct _citrus_LC_MESSAGES_key *key; 103 const struct _citrus_LC_MESSAGES_key *key;
104 char **p; 104 char **p;
105 const char *s; 105 const char *s;
106 106
107 _DIAGASSERT(data != NULL); 107 _DIAGASSERT(data != NULL);
108 _DIAGASSERT(db != NULL); 108 _DIAGASSERT(db != NULL);
109 109
110 memset(data, 0, sizeof(*data)); 110 memset(data, 0, sizeof(*data));
111 for (key = &keys[0]; key->name != NULL; ++key) { 111 for (key = &keys[0]; key->name != NULL; ++key) {
112 if (_db_lookupstr_by_s(db, key->name, &s, NULL)) 112 if (_db_lookupstr_by_s(db, key->name, &s, NULL))
113 goto fatal; 113 goto fatal;
114 p = (char **)(void *) 114 p = (char **)(void *)
115 (((char *)(void *)data) + key->offset); 115 (((char *)(void *)data) + key->offset);
116 *p = strdup(s); 116 *p = strdup(s);
117 if (*p == NULL) 117 if (*p == NULL)
118 goto fatal; 118 goto fatal;
119 } 119 }
120 return 0; 120 return 0;
121 121
122fatal: 122fatal:
123 _citrus_LC_MESSAGES_uninit(data); 123 _citrus_LC_MESSAGES_uninit(data);
124 return EFTYPE; 124 return EFTYPE;
125} 125}
126 126
127static __inline int 127static __inline int
128_citrus_LC_MESSAGES_init_fallback(_MessagesLocale * __restrict data, 128_citrus_LC_MESSAGES_init_fallback(_MessagesLocale * __restrict data,
129 struct _memstream * __restrict ms) 129 struct _memstream * __restrict ms)
130{ 130{
131 const struct _citrus_LC_MESSAGES_key *key; 131 const struct _citrus_LC_MESSAGES_key *key;
132 char **p; 132 char **p;
133 const char *s; 133 const char *s;
134 size_t n; 134 size_t n;
135 135
136 _DIAGASSERT(data != NULL); 136 _DIAGASSERT(data != NULL);
137 _DIAGASSERT(ms != NULL); 137 _DIAGASSERT(ms != NULL);
138 138
139 memset(data, 0, sizeof(*data)); 139 memset(data, 0, sizeof(*data));
140 for (key = &keys[0]; key->name != NULL; ++key) { 140 for (key = &keys[0]; key->name != NULL; ++key) {
141 if ((s = _memstream_getln(ms, &n)) == NULL) 141 if ((s = _memstream_getln(ms, &n)) == NULL)
142 goto fatal; 142 goto fatal;
143 p = (char **)(void *) 143 p = (char **)(void *)
144 (((char *)(void *)data) + key->offset); 144 (((char *)(void *)data) + key->offset);
145 *p = strndup(s, n - 1); 145 *p = strndup(s, n - 1);
146 if (*p == NULL) 146 if (*p == NULL)
147 goto fatal; 147 goto fatal;
148 } 148 }
149 return 0; 149 return 0;
150 150
151fatal: 151fatal:
152 _citrus_LC_MESSAGES_uninit(data); 152 _citrus_LC_MESSAGES_uninit(data);
153 return EFTYPE; 153 return EFTYPE;
154} 154}
155 155
156/* 156/*
157 * macro required by citrus_lc_template.h 157 * macro required by citrus_lc_template.h
158 */ 158 */
159#define _CATEGORY_DB "LC_MESSAGES/SYS_LC_MESSAGES" 159#define _CATEGORY_DB "LC_MESSAGES/SYS_LC_MESSAGES"
160#define _CATEGORY_MAGIC _CITRUS_LC_MESSAGES_MAGIC_1 160#define _CATEGORY_MAGIC _CITRUS_LC_MESSAGES_MAGIC_1
161 161
162#include "citrus_lc_template.h" 162#include "citrus_lc_template.h"
163_LOCALE_CATEGORY_ENTRY(_citrus_LC_MESSAGES_); 

cvs diff -r1.4 -r1.5 src/lib/libc/citrus/citrus_lc_monetary.c (switch to unified diff)

--- src/lib/libc/citrus/citrus_lc_monetary.c 2010/06/13 04:14:57 1.4
+++ src/lib/libc/citrus/citrus_lc_monetary.c 2012/03/04 21:14:55 1.5
@@ -1,220 +1,219 @@ @@ -1,220 +1,219 @@
1/* $NetBSD: citrus_lc_monetary.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $ */ 1/* $NetBSD: citrus_lc_monetary.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: citrus_lc_monetary.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $"); 31__RCSID("$NetBSD: citrus_lc_monetary.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include "namespace.h" 34#include "namespace.h"
35#include "reentrant.h" 35#include "reentrant.h"
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/localedef.h> 37#include <sys/localedef.h>
38#include <sys/queue.h> 38#include <sys/queue.h>
39#include <assert.h> 39#include <assert.h>
40#include <errno.h> 40#include <errno.h>
41#include <langinfo.h> 41#include <langinfo.h>
42#include <limits.h> 42#include <limits.h>
43#define __SETLOCALE_SOURCE__ 43#define __SETLOCALE_SOURCE__
44#include <locale.h> 44#include <locale.h>
45#include <stddef.h> 45#include <stddef.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "setlocale_local.h" 50#include "setlocale_local.h"
51 51
52#include "citrus_namespace.h" 52#include "citrus_namespace.h"
53#include "citrus_types.h" 53#include "citrus_types.h"
54#include "citrus_bcs.h" 54#include "citrus_bcs.h"
55#include "citrus_region.h" 55#include "citrus_region.h"
56#include "citrus_lookup.h" 56#include "citrus_lookup.h"
57#include "citrus_aliasname_local.h" 57#include "citrus_aliasname_local.h"
58#include "citrus_module.h" 58#include "citrus_module.h"
59#include "citrus_mmap.h" 59#include "citrus_mmap.h"
60#include "citrus_hash.h" 60#include "citrus_hash.h"
61#include "citrus_db.h" 61#include "citrus_db.h"
62#include "citrus_db_hash.h" 62#include "citrus_db_hash.h"
63#include "citrus_memstream.h" 63#include "citrus_memstream.h"
64#include "runetype_local.h" 64#include "runetype_local.h"
65 65
66#include "fix_grouping.h" 66#include "fix_grouping.h"
67#include "citrus_fix_grouping.h" 67#include "citrus_fix_grouping.h"
68 68
69/* 69/*
70 * macro required by all template headers 70 * macro required by all template headers
71 */ 71 */
72#define _PREFIX(name) __CONCAT(_citrus_LC_MONETARY_, name) 72#define _PREFIX(name) __CONCAT(_citrus_LC_MONETARY_, name)
73 73
74#include "nb_lc_monetary_misc.h" 74#include "nb_lc_monetary_misc.h"
75#include "citrus_lc_template_decl.h" 75#include "citrus_lc_template_decl.h"
76 76
77static __inline void 77static __inline void
78_citrus_LC_MONETARY_uninit(_MonetaryLocale *data) 78_citrus_LC_MONETARY_uninit(_MonetaryLocale *data)
79{ 79{
80 _DIAGASSERT(data != NULL); 80 _DIAGASSERT(data != NULL);
81 81
82 free(__UNCONST(data->int_curr_symbol)); 82 free(__UNCONST(data->int_curr_symbol));
83 free(__UNCONST(data->currency_symbol)); 83 free(__UNCONST(data->currency_symbol));
84 free(__UNCONST(data->mon_decimal_point)); 84 free(__UNCONST(data->mon_decimal_point));
85 free(__UNCONST(data->mon_thousands_sep)); 85 free(__UNCONST(data->mon_thousands_sep));
86 free(__UNCONST(data->mon_grouping)); 86 free(__UNCONST(data->mon_grouping));
87 free(__UNCONST(data->positive_sign)); 87 free(__UNCONST(data->positive_sign));
88 free(__UNCONST(data->negative_sign)); 88 free(__UNCONST(data->negative_sign));
89} 89}
90 90
91#include "citrus_lc_monetary.h" 91#include "citrus_lc_monetary.h"
92 92
93struct _citrus_LC_MONETARY_key { 93struct _citrus_LC_MONETARY_key {
94 const char *name; 94 const char *name;
95 size_t offset; 95 size_t offset;
96}; 96};
97 97
98#define OFFSET(field) (offsetof(_MonetaryLocale, field)) 98#define OFFSET(field) (offsetof(_MonetaryLocale, field))
99static const struct _citrus_LC_MONETARY_key keys_string[] = { 99static const struct _citrus_LC_MONETARY_key keys_string[] = {
100 { _CITRUS_LC_MONETARY_SYM_INT_CURR_SYMBOL, OFFSET(int_curr_symbol ) }, 100 { _CITRUS_LC_MONETARY_SYM_INT_CURR_SYMBOL, OFFSET(int_curr_symbol ) },
101 { _CITRUS_LC_MONETARY_SYM_CURRENCY_SYMBOL, OFFSET(currency_symbol ) }, 101 { _CITRUS_LC_MONETARY_SYM_CURRENCY_SYMBOL, OFFSET(currency_symbol ) },
102 { _CITRUS_LC_MONETARY_SYM_MON_DECIMAL_POINT, OFFSET(mon_decimal_point ) }, 102 { _CITRUS_LC_MONETARY_SYM_MON_DECIMAL_POINT, OFFSET(mon_decimal_point ) },
103 { _CITRUS_LC_MONETARY_SYM_MON_THOUSANDS_SEP, OFFSET(mon_thousands_sep ) }, 103 { _CITRUS_LC_MONETARY_SYM_MON_THOUSANDS_SEP, OFFSET(mon_thousands_sep ) },
104 { _CITRUS_LC_MONETARY_SYM_MON_GROUPING, OFFSET(mon_grouping ) }, 104 { _CITRUS_LC_MONETARY_SYM_MON_GROUPING, OFFSET(mon_grouping ) },
105 { _CITRUS_LC_MONETARY_SYM_POSITIVE_SIGN, OFFSET(positive_sign ) }, 105 { _CITRUS_LC_MONETARY_SYM_POSITIVE_SIGN, OFFSET(positive_sign ) },
106 { _CITRUS_LC_MONETARY_SYM_NEGATIVE_SIGN, OFFSET(negative_sign ) }, 106 { _CITRUS_LC_MONETARY_SYM_NEGATIVE_SIGN, OFFSET(negative_sign ) },
107 { NULL, (size_t)0 } 107 { NULL, (size_t)0 }
108}; 108};
109static const struct _citrus_LC_MONETARY_key keys_char[] = { 109static const struct _citrus_LC_MONETARY_key keys_char[] = {
110 { _CITRUS_LC_MONETARY_SYM_INT_FRAC_DIGITS, OFFSET(int_frac_digits ) }, 110 { _CITRUS_LC_MONETARY_SYM_INT_FRAC_DIGITS, OFFSET(int_frac_digits ) },
111 { _CITRUS_LC_MONETARY_SYM_FRAC_DIGITS, OFFSET(frac_digits ) }, 111 { _CITRUS_LC_MONETARY_SYM_FRAC_DIGITS, OFFSET(frac_digits ) },
112 { _CITRUS_LC_MONETARY_SYM_P_CS_PRECEDES, OFFSET(p_cs_precedes ) }, 112 { _CITRUS_LC_MONETARY_SYM_P_CS_PRECEDES, OFFSET(p_cs_precedes ) },
113 { _CITRUS_LC_MONETARY_SYM_P_SEP_BY_SPACE, OFFSET(p_sep_by_space ) }, 113 { _CITRUS_LC_MONETARY_SYM_P_SEP_BY_SPACE, OFFSET(p_sep_by_space ) },
114 { _CITRUS_LC_MONETARY_SYM_N_CS_PRECEDES, OFFSET(n_cs_precedes ) }, 114 { _CITRUS_LC_MONETARY_SYM_N_CS_PRECEDES, OFFSET(n_cs_precedes ) },
115 { _CITRUS_LC_MONETARY_SYM_N_SEP_BY_SPACE, OFFSET(n_sep_by_space ) }, 115 { _CITRUS_LC_MONETARY_SYM_N_SEP_BY_SPACE, OFFSET(n_sep_by_space ) },
116 { _CITRUS_LC_MONETARY_SYM_P_SIGN_POSN, OFFSET(p_sign_posn ) }, 116 { _CITRUS_LC_MONETARY_SYM_P_SIGN_POSN, OFFSET(p_sign_posn ) },
117 { _CITRUS_LC_MONETARY_SYM_N_SIGN_POSN, OFFSET(n_sign_posn ) }, 117 { _CITRUS_LC_MONETARY_SYM_N_SIGN_POSN, OFFSET(n_sign_posn ) },
118 { _CITRUS_LC_MONETARY_SYM_INT_P_CS_PRECEDES, OFFSET(int_p_cs_precedes ) }, 118 { _CITRUS_LC_MONETARY_SYM_INT_P_CS_PRECEDES, OFFSET(int_p_cs_precedes ) },
119 { _CITRUS_LC_MONETARY_SYM_INT_N_CS_PRECEDES, OFFSET(int_n_cs_precedes ) }, 119 { _CITRUS_LC_MONETARY_SYM_INT_N_CS_PRECEDES, OFFSET(int_n_cs_precedes ) },
120 { _CITRUS_LC_MONETARY_SYM_INT_P_SEP_BY_SPACE, OFFSET(int_p_sep_by_space) }, 120 { _CITRUS_LC_MONETARY_SYM_INT_P_SEP_BY_SPACE, OFFSET(int_p_sep_by_space) },
121 { _CITRUS_LC_MONETARY_SYM_INT_N_SEP_BY_SPACE, OFFSET(int_n_sep_by_space) }, 121 { _CITRUS_LC_MONETARY_SYM_INT_N_SEP_BY_SPACE, OFFSET(int_n_sep_by_space) },
122 { _CITRUS_LC_MONETARY_SYM_INT_P_SIGN_POSN, OFFSET(int_p_sign_posn ) }, 122 { _CITRUS_LC_MONETARY_SYM_INT_P_SIGN_POSN, OFFSET(int_p_sign_posn ) },
123 { _CITRUS_LC_MONETARY_SYM_INT_N_SIGN_POSN, OFFSET(int_n_sign_posn ) }, 123 { _CITRUS_LC_MONETARY_SYM_INT_N_SIGN_POSN, OFFSET(int_n_sign_posn ) },
124 { NULL, (size_t)0 } 124 { NULL, (size_t)0 }
125}; 125};
126 126
127static __inline int 127static __inline int
128_citrus_LC_MONETARY_init_normal(_MonetaryLocale * __restrict data, 128_citrus_LC_MONETARY_init_normal(_MonetaryLocale * __restrict data,
129 struct _citrus_db * __restrict db) 129 struct _citrus_db * __restrict db)
130{ 130{
131 const struct _citrus_LC_MONETARY_key *key; 131 const struct _citrus_LC_MONETARY_key *key;
132 char **p_string, *p_char; 132 char **p_string, *p_char;
133 const char *s; 133 const char *s;
134 uint8_t u8; 134 uint8_t u8;
135 135
136 _DIAGASSERT(data != NULL); 136 _DIAGASSERT(data != NULL);
137 _DIAGASSERT(db != NULL); 137 _DIAGASSERT(db != NULL);
138 138
139 memset(data, 0, sizeof(*data)); 139 memset(data, 0, sizeof(*data));
140 for (key = &keys_string[0]; key->name != NULL; ++key) { 140 for (key = &keys_string[0]; key->name != NULL; ++key) {
141 if (_db_lookupstr_by_s(db, key->name, &s, NULL)) 141 if (_db_lookupstr_by_s(db, key->name, &s, NULL))
142 goto fatal; 142 goto fatal;
143 p_string = (char **)(void *) 143 p_string = (char **)(void *)
144 (((char *)(void *)data) + key->offset); 144 (((char *)(void *)data) + key->offset);
145 *p_string = strdup(s); 145 *p_string = strdup(s);
146 if (*p_string == NULL) 146 if (*p_string == NULL)
147 goto fatal; 147 goto fatal;
148 } 148 }
149 for (key = &keys_char[0]; key->name != NULL; ++key) { 149 for (key = &keys_char[0]; key->name != NULL; ++key) {
150 if (_db_lookup8_by_s(db, key->name, &u8, NULL)) 150 if (_db_lookup8_by_s(db, key->name, &u8, NULL))
151 goto fatal; 151 goto fatal;
152 p_char = ((char *)(void *)data) + key->offset; 152 p_char = ((char *)(void *)data) + key->offset;
153 *p_char = (char)(unsigned char)u8; 153 *p_char = (char)(unsigned char)u8;
154 } 154 }
155 _CITRUS_FIXUP_CHAR_MAX_MD(data->mon_grouping); 155 _CITRUS_FIXUP_CHAR_MAX_MD(data->mon_grouping);
156 156
157 return 0; 157 return 0;
158 158
159fatal: 159fatal:
160 _citrus_LC_MONETARY_uninit(data); 160 _citrus_LC_MONETARY_uninit(data);
161 return EFTYPE; 161 return EFTYPE;
162} 162}
163 163
164static __inline int 164static __inline int
165_citrus_LC_MONETARY_init_fallback(_MonetaryLocale * __restrict data, 165_citrus_LC_MONETARY_init_fallback(_MonetaryLocale * __restrict data,
166 struct _memstream * __restrict ms) 166 struct _memstream * __restrict ms)
167{ 167{
168 const struct _citrus_LC_MONETARY_key *key; 168 const struct _citrus_LC_MONETARY_key *key;
169 char **p_string, *p_char; 169 char **p_string, *p_char;
170 const char *s; 170 const char *s;
171 size_t n; 171 size_t n;
172 char *t; 172 char *t;
173 long int l; 173 long int l;
174 174
175 _DIAGASSERT(data != NULL); 175 _DIAGASSERT(data != NULL);
176 _DIAGASSERT(ms != NULL); 176 _DIAGASSERT(ms != NULL);
177 177
178 memset(data, 0, sizeof(*data)); 178 memset(data, 0, sizeof(*data));
179 for (key = &keys_string[0]; key->name != NULL; ++key) { 179 for (key = &keys_string[0]; key->name != NULL; ++key) {
180 if ((s = _memstream_getln(ms, &n)) == NULL) 180 if ((s = _memstream_getln(ms, &n)) == NULL)
181 goto fatal; 181 goto fatal;
182 p_string = (char **)(void *) 182 p_string = (char **)(void *)
183 (((char *)(void *)data) + key->offset); 183 (((char *)(void *)data) + key->offset);
184 *p_string = strndup(s, n - 1); 184 *p_string = strndup(s, n - 1);
185 if (*p_string == NULL) 185 if (*p_string == NULL)
186 goto fatal; 186 goto fatal;
187 } 187 }
188 for (key = &keys_char[0]; key->name != NULL; ++key) { 188 for (key = &keys_char[0]; key->name != NULL; ++key) {
189 if ((s = _memstream_getln(ms, &n)) == NULL) 189 if ((s = _memstream_getln(ms, &n)) == NULL)
190 goto fatal; 190 goto fatal;
191 t = strndup(s, n - 1); 191 t = strndup(s, n - 1);
192 if (t == NULL) 192 if (t == NULL)
193 goto fatal; 193 goto fatal;
194 s = (const char *)t; 194 s = (const char *)t;
195 l = _bcs_strtol(s, &t, 0); 195 l = _bcs_strtol(s, &t, 0);
196 if (s == t || l < 0 || l > 0x7fL) { 196 if (s == t || l < 0 || l > 0x7fL) {
197 free(t); 197 free(t);
198 goto fatal; 198 goto fatal;
199 } 199 }
200 free(t); 200 free(t);
201 p_char = ((char *)(void *)data) + key->offset; 201 p_char = ((char *)(void *)data) + key->offset;
202 *p_char = (char)(l & 0x7fL); 202 *p_char = (char)(l & 0x7fL);
203 } 203 }
204 data->mon_grouping = 204 data->mon_grouping =
205 __fix_locale_grouping_str(data->mon_grouping); 205 __fix_locale_grouping_str(data->mon_grouping);
206 return 0; 206 return 0;
207 207
208fatal: 208fatal:
209 _citrus_LC_MONETARY_uninit(data); 209 _citrus_LC_MONETARY_uninit(data);
210 return EFTYPE; 210 return EFTYPE;
211} 211}
212 212
213/* 213/*
214 * macro required by citrus_lc_template.h 214 * macro required by citrus_lc_template.h
215 */ 215 */
216#define _CATEGORY_DB "LC_MONETARY" 216#define _CATEGORY_DB "LC_MONETARY"
217#define _CATEGORY_MAGIC _CITRUS_LC_MONETARY_MAGIC_1 217#define _CATEGORY_MAGIC _CITRUS_LC_MONETARY_MAGIC_1
218 218
219#include "citrus_lc_template.h" 219#include "citrus_lc_template.h"
220_LOCALE_CATEGORY_ENTRY(_citrus_LC_MONETARY_); 

cvs diff -r1.4 -r1.5 src/lib/libc/citrus/citrus_lc_numeric.c (switch to unified diff)

--- src/lib/libc/citrus/citrus_lc_numeric.c 2010/06/13 04:14:57 1.4
+++ src/lib/libc/citrus/citrus_lc_numeric.c 2012/03/04 21:14:55 1.5
@@ -1,169 +1,168 @@ @@ -1,169 +1,168 @@
1/* $NetBSD: citrus_lc_numeric.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $ */ 1/* $NetBSD: citrus_lc_numeric.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: citrus_lc_numeric.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $"); 31__RCSID("$NetBSD: citrus_lc_numeric.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include "namespace.h" 34#include "namespace.h"
35#include "reentrant.h" 35#include "reentrant.h"
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/localedef.h> 37#include <sys/localedef.h>
38#include <sys/queue.h> 38#include <sys/queue.h>
39#include <assert.h> 39#include <assert.h>
40#include <errno.h> 40#include <errno.h>
41#include <langinfo.h> 41#include <langinfo.h>
42#include <limits.h> 42#include <limits.h>
43#define __SETLOCALE_SOURCE__ 43#define __SETLOCALE_SOURCE__
44#include <locale.h> 44#include <locale.h>
45#include <stddef.h> 45#include <stddef.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "setlocale_local.h" 50#include "setlocale_local.h"
51 51
52#include "citrus_namespace.h" 52#include "citrus_namespace.h"
53#include "citrus_types.h" 53#include "citrus_types.h"
54#include "citrus_bcs.h" 54#include "citrus_bcs.h"
55#include "citrus_region.h" 55#include "citrus_region.h"
56#include "citrus_lookup.h" 56#include "citrus_lookup.h"
57#include "citrus_aliasname_local.h" 57#include "citrus_aliasname_local.h"
58#include "citrus_module.h" 58#include "citrus_module.h"
59#include "citrus_mmap.h" 59#include "citrus_mmap.h"
60#include "citrus_hash.h" 60#include "citrus_hash.h"
61#include "citrus_db.h" 61#include "citrus_db.h"
62#include "citrus_db_hash.h" 62#include "citrus_db_hash.h"
63#include "citrus_memstream.h" 63#include "citrus_memstream.h"
64#include "runetype_local.h" 64#include "runetype_local.h"
65 65
66#include "fix_grouping.h" 66#include "fix_grouping.h"
67#include "citrus_fix_grouping.h" 67#include "citrus_fix_grouping.h"
68 68
69/* 69/*
70 * macro required by all template headers 70 * macro required by all template headers
71 */ 71 */
72#define _PREFIX(name) __CONCAT(_citrus_LC_NUMERIC_, name) 72#define _PREFIX(name) __CONCAT(_citrus_LC_NUMERIC_, name)
73 73
74#include "nb_lc_numeric_misc.h" 74#include "nb_lc_numeric_misc.h"
75#include "citrus_lc_template_decl.h" 75#include "citrus_lc_template_decl.h"
76 76
77static __inline void 77static __inline void
78_citrus_LC_NUMERIC_uninit(_NumericLocale *data) 78_citrus_LC_NUMERIC_uninit(_NumericLocale *data)
79{ 79{
80 free(__UNCONST(data->decimal_point)); 80 free(__UNCONST(data->decimal_point));
81 free(__UNCONST(data->thousands_sep)); 81 free(__UNCONST(data->thousands_sep));
82 free(__UNCONST(data->grouping)); 82 free(__UNCONST(data->grouping));
83} 83}
84 84
85#include "citrus_lc_numeric.h" 85#include "citrus_lc_numeric.h"
86 86
87struct _citrus_LC_NUMERIC_key { 87struct _citrus_LC_NUMERIC_key {
88 const char *name; 88 const char *name;
89 size_t offset; 89 size_t offset;
90}; 90};
91 91
92#define OFFSET(field) (offsetof(_NumericLocale, field)) 92#define OFFSET(field) (offsetof(_NumericLocale, field))
93static const struct _citrus_LC_NUMERIC_key keys[] = { 93static const struct _citrus_LC_NUMERIC_key keys[] = {
94 { _CITRUS_LC_NUMERIC_SYM_DECIMAL_POINT, OFFSET(decimal_point) }, 94 { _CITRUS_LC_NUMERIC_SYM_DECIMAL_POINT, OFFSET(decimal_point) },
95 { _CITRUS_LC_NUMERIC_SYM_THOUSANDS_SEP, OFFSET(thousands_sep) }, 95 { _CITRUS_LC_NUMERIC_SYM_THOUSANDS_SEP, OFFSET(thousands_sep) },
96 { _CITRUS_LC_NUMERIC_SYM_GROUPING, OFFSET(grouping ) }, 96 { _CITRUS_LC_NUMERIC_SYM_GROUPING, OFFSET(grouping ) },
97 { NULL, 0 } 97 { NULL, 0 }
98}; 98};
99 99
100static __inline int 100static __inline int
101_citrus_LC_NUMERIC_init_normal(_NumericLocale * __restrict data, 101_citrus_LC_NUMERIC_init_normal(_NumericLocale * __restrict data,
102 struct _citrus_db * __restrict db) 102 struct _citrus_db * __restrict db)
103{ 103{
104 const struct _citrus_LC_NUMERIC_key *key; 104 const struct _citrus_LC_NUMERIC_key *key;
105 char **p; 105 char **p;
106 const char *s; 106 const char *s;
107 107
108 _DIAGASSERT(data != NULL); 108 _DIAGASSERT(data != NULL);
109 _DIAGASSERT(db != NULL); 109 _DIAGASSERT(db != NULL);
110 110
111 memset(data, 0, sizeof(*data)); 111 memset(data, 0, sizeof(*data));
112 for (key = &keys[0]; key->name != NULL; ++key) { 112 for (key = &keys[0]; key->name != NULL; ++key) {
113 if (_db_lookupstr_by_s(db, key->name, &s, NULL)) 113 if (_db_lookupstr_by_s(db, key->name, &s, NULL))
114 goto fatal; 114 goto fatal;
115 p = (char **)(void *) 115 p = (char **)(void *)
116 (((char *)(void *)data) + key->offset); 116 (((char *)(void *)data) + key->offset);
117 *p = strdup(s); 117 *p = strdup(s);
118 if (*p == NULL) 118 if (*p == NULL)
119 goto fatal; 119 goto fatal;
120 } 120 }
121 _CITRUS_FIXUP_CHAR_MAX_MD(data->grouping); 121 _CITRUS_FIXUP_CHAR_MAX_MD(data->grouping);
122 122
123 return 0; 123 return 0;
124 124
125fatal: 125fatal:
126 _citrus_LC_NUMERIC_uninit(data); 126 _citrus_LC_NUMERIC_uninit(data);
127 return EFTYPE; 127 return EFTYPE;
128} 128}
129 129
130static __inline int 130static __inline int
131_citrus_LC_NUMERIC_init_fallback(_NumericLocale * __restrict data, 131_citrus_LC_NUMERIC_init_fallback(_NumericLocale * __restrict data,
132 struct _memstream * __restrict ms) 132 struct _memstream * __restrict ms)
133{ 133{
134 const struct _citrus_LC_NUMERIC_key *key; 134 const struct _citrus_LC_NUMERIC_key *key;
135 char **p; 135 char **p;
136 const char *s; 136 const char *s;
137 size_t n; 137 size_t n;
138 138
139 _DIAGASSERT(data != NULL); 139 _DIAGASSERT(data != NULL);
140 _DIAGASSERT(ms != NULL); 140 _DIAGASSERT(ms != NULL);
141 141
142 memset(data, 0, sizeof(*data)); 142 memset(data, 0, sizeof(*data));
143 for (key = &keys[0]; key->name != NULL; ++key) { 143 for (key = &keys[0]; key->name != NULL; ++key) {
144 if ((s = _memstream_getln(ms, &n)) == NULL) 144 if ((s = _memstream_getln(ms, &n)) == NULL)
145 goto fatal; 145 goto fatal;
146 p = (char **)(void *) 146 p = (char **)(void *)
147 (((char *)(void *)data) + key->offset); 147 (((char *)(void *)data) + key->offset);
148 *p = strndup(s, n - 1); 148 *p = strndup(s, n - 1);
149 if (*p == NULL) 149 if (*p == NULL)
150 goto fatal; 150 goto fatal;
151 } 151 }
152 data->grouping = 152 data->grouping =
153 __fix_locale_grouping_str(data->grouping); 153 __fix_locale_grouping_str(data->grouping);
154 154
155 return 0; 155 return 0;
156 156
157fatal: 157fatal:
158 _citrus_LC_NUMERIC_uninit(data); 158 _citrus_LC_NUMERIC_uninit(data);
159 return EFTYPE; 159 return EFTYPE;
160} 160}
161 161
162/* 162/*
163 * macro required by citrus_lc_template.h 163 * macro required by citrus_lc_template.h
164 */ 164 */
165#define _CATEGORY_DB "LC_NUMERIC" 165#define _CATEGORY_DB "LC_NUMERIC"
166#define _CATEGORY_MAGIC _CITRUS_LC_NUMERIC_MAGIC_1 166#define _CATEGORY_MAGIC _CITRUS_LC_NUMERIC_MAGIC_1
167 167
168#include "citrus_lc_template.h" 168#include "citrus_lc_template.h"
169_LOCALE_CATEGORY_ENTRY(_citrus_LC_NUMERIC_); 

cvs diff -r1.5 -r1.6 src/lib/libc/citrus/citrus_lc_time.c (switch to unified diff)

--- src/lib/libc/citrus/citrus_lc_time.c 2010/06/13 04:14:57 1.5
+++ src/lib/libc/citrus/citrus_lc_time.c 2012/03/04 21:14:55 1.6
@@ -1,214 +1,213 @@ @@ -1,214 +1,213 @@
1/* $NetBSD: citrus_lc_time.c,v 1.5 2010/06/13 04:14:57 tnozaki Exp $ */ 1/* $NetBSD: citrus_lc_time.c,v 1.6 2012/03/04 21:14:55 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: citrus_lc_time.c,v 1.5 2010/06/13 04:14:57 tnozaki Exp $"); 31__RCSID("$NetBSD: citrus_lc_time.c,v 1.6 2012/03/04 21:14:55 tnozaki Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include "namespace.h" 34#include "namespace.h"
35#include "reentrant.h" 35#include "reentrant.h"
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/localedef.h> 37#include <sys/localedef.h>
38#include <sys/queue.h> 38#include <sys/queue.h>
39#include <assert.h> 39#include <assert.h>
40#include <errno.h> 40#include <errno.h>
41#include <langinfo.h> 41#include <langinfo.h>
42#include <limits.h> 42#include <limits.h>
43#define __SETLOCALE_SOURCE__ 43#define __SETLOCALE_SOURCE__
44#include <locale.h> 44#include <locale.h>
45#include <stddef.h> 45#include <stddef.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "setlocale_local.h" 50#include "setlocale_local.h"
51 51
52#include "citrus_namespace.h" 52#include "citrus_namespace.h"
53#include "citrus_types.h" 53#include "citrus_types.h"
54#include "citrus_bcs.h" 54#include "citrus_bcs.h"
55#include "citrus_region.h" 55#include "citrus_region.h"
56#include "citrus_lookup.h" 56#include "citrus_lookup.h"
57#include "citrus_aliasname_local.h" 57#include "citrus_aliasname_local.h"
58#include "citrus_module.h" 58#include "citrus_module.h"
59#include "citrus_mmap.h" 59#include "citrus_mmap.h"
60#include "citrus_hash.h" 60#include "citrus_hash.h"
61#include "citrus_db.h" 61#include "citrus_db.h"
62#include "citrus_db_hash.h" 62#include "citrus_db_hash.h"
63#include "citrus_memstream.h" 63#include "citrus_memstream.h"
64#include "runetype_local.h" 64#include "runetype_local.h"
65 65
66/* 66/*
67 * macro required by all template headers 67 * macro required by all template headers
68 */ 68 */
69#define _PREFIX(name) __CONCAT(_citrus_LC_TIME_, name) 69#define _PREFIX(name) __CONCAT(_citrus_LC_TIME_, name)
70 70
71#include "nb_lc_time_misc.h" 71#include "nb_lc_time_misc.h"
72#include "citrus_lc_template_decl.h" 72#include "citrus_lc_template_decl.h"
73 73
74static __inline void 74static __inline void
75_citrus_LC_TIME_uninit(_TimeLocale *data) 75_citrus_LC_TIME_uninit(_TimeLocale *data)
76{ 76{
77 size_t i, j; 77 size_t i, j;
78 78
79 _DIAGASSERT(data != NULL); 79 _DIAGASSERT(data != NULL);
80 80
81 for (i = ABDAY_IDX(ABDAY_1), j = ABDAY_IDX(ABDAY_7); i <= j; ++i) 81 for (i = ABDAY_IDX(ABDAY_1), j = ABDAY_IDX(ABDAY_7); i <= j; ++i)
82 free(__UNCONST(data->abday[i])); 82 free(__UNCONST(data->abday[i]));
83 for (i = DAY_IDX(DAY_1), j = DAY_IDX(DAY_7); i <= j; ++i) 83 for (i = DAY_IDX(DAY_1), j = DAY_IDX(DAY_7); i <= j; ++i)
84 free(__UNCONST(data->day[i])); 84 free(__UNCONST(data->day[i]));
85 for (i = ABMON_IDX(ABMON_1), j = ABMON_IDX(ABMON_12); i <= j; ++i) 85 for (i = ABMON_IDX(ABMON_1), j = ABMON_IDX(ABMON_12); i <= j; ++i)
86 free(__UNCONST(data->abmon[i])); 86 free(__UNCONST(data->abmon[i]));
87 for (i = MON_IDX(MON_1), j = MON_IDX(MON_12); i <= j; ++i) 87 for (i = MON_IDX(MON_1), j = MON_IDX(MON_12); i <= j; ++i)
88 free(__UNCONST(data->mon[i])); 88 free(__UNCONST(data->mon[i]));
89 for (i = AM_PM_IDX(AM_STR), j = AM_PM_IDX(PM_STR); i <= j; ++i) 89 for (i = AM_PM_IDX(AM_STR), j = AM_PM_IDX(PM_STR); i <= j; ++i)
90 free(__UNCONST(data->am_pm[i])); 90 free(__UNCONST(data->am_pm[i]));
91 free(__UNCONST(data->d_t_fmt)); 91 free(__UNCONST(data->d_t_fmt));
92 free(__UNCONST(data->d_fmt)); 92 free(__UNCONST(data->d_fmt));
93 free(__UNCONST(data->t_fmt)); 93 free(__UNCONST(data->t_fmt));
94 free(__UNCONST(data->t_fmt_ampm)); 94 free(__UNCONST(data->t_fmt_ampm));
95} 95}
96 96
97#include "citrus_lc_time.h" 97#include "citrus_lc_time.h"
98 98
99struct _citrus_LC_TIME_key { 99struct _citrus_LC_TIME_key {
100 const char *name; 100 const char *name;
101 size_t offset; 101 size_t offset;
102}; 102};
103 103
104#define OFFSET(field) offsetof(_TimeLocale, field) 104#define OFFSET(field) offsetof(_TimeLocale, field)
105static const struct _citrus_LC_TIME_key keys[] = { 105static const struct _citrus_LC_TIME_key keys[] = {
106 { _CITRUS_LC_TIME_SYM_ABDAY_1, OFFSET(abday[ABDAY_IDX(ABDAY_1)] ) }, 106 { _CITRUS_LC_TIME_SYM_ABDAY_1, OFFSET(abday[ABDAY_IDX(ABDAY_1)] ) },
107 { _CITRUS_LC_TIME_SYM_ABDAY_2, OFFSET(abday[ABDAY_IDX(ABDAY_2)] ) }, 107 { _CITRUS_LC_TIME_SYM_ABDAY_2, OFFSET(abday[ABDAY_IDX(ABDAY_2)] ) },
108 { _CITRUS_LC_TIME_SYM_ABDAY_3, OFFSET(abday[ABDAY_IDX(ABDAY_3)] ) }, 108 { _CITRUS_LC_TIME_SYM_ABDAY_3, OFFSET(abday[ABDAY_IDX(ABDAY_3)] ) },
109 { _CITRUS_LC_TIME_SYM_ABDAY_4, OFFSET(abday[ABDAY_IDX(ABDAY_4)] ) }, 109 { _CITRUS_LC_TIME_SYM_ABDAY_4, OFFSET(abday[ABDAY_IDX(ABDAY_4)] ) },
110 { _CITRUS_LC_TIME_SYM_ABDAY_5, OFFSET(abday[ABDAY_IDX(ABDAY_5)] ) }, 110 { _CITRUS_LC_TIME_SYM_ABDAY_5, OFFSET(abday[ABDAY_IDX(ABDAY_5)] ) },
111 { _CITRUS_LC_TIME_SYM_ABDAY_6, OFFSET(abday[ABDAY_IDX(ABDAY_6)] ) }, 111 { _CITRUS_LC_TIME_SYM_ABDAY_6, OFFSET(abday[ABDAY_IDX(ABDAY_6)] ) },
112 { _CITRUS_LC_TIME_SYM_ABDAY_7, OFFSET(abday[ABDAY_IDX(ABDAY_7)] ) }, 112 { _CITRUS_LC_TIME_SYM_ABDAY_7, OFFSET(abday[ABDAY_IDX(ABDAY_7)] ) },
113 { _CITRUS_LC_TIME_SYM_DAY_1, OFFSET(day[DAY_IDX(DAY_1)] ) }, 113 { _CITRUS_LC_TIME_SYM_DAY_1, OFFSET(day[DAY_IDX(DAY_1)] ) },
114 { _CITRUS_LC_TIME_SYM_DAY_2, OFFSET(day[DAY_IDX(DAY_2)] ) }, 114 { _CITRUS_LC_TIME_SYM_DAY_2, OFFSET(day[DAY_IDX(DAY_2)] ) },
115 { _CITRUS_LC_TIME_SYM_DAY_3, OFFSET(day[DAY_IDX(DAY_3)] ) }, 115 { _CITRUS_LC_TIME_SYM_DAY_3, OFFSET(day[DAY_IDX(DAY_3)] ) },
116 { _CITRUS_LC_TIME_SYM_DAY_4, OFFSET(day[DAY_IDX(DAY_4)] ) }, 116 { _CITRUS_LC_TIME_SYM_DAY_4, OFFSET(day[DAY_IDX(DAY_4)] ) },
117 { _CITRUS_LC_TIME_SYM_DAY_5, OFFSET(day[DAY_IDX(DAY_5)] ) }, 117 { _CITRUS_LC_TIME_SYM_DAY_5, OFFSET(day[DAY_IDX(DAY_5)] ) },
118 { _CITRUS_LC_TIME_SYM_DAY_6, OFFSET(day[DAY_IDX(DAY_6)] ) }, 118 { _CITRUS_LC_TIME_SYM_DAY_6, OFFSET(day[DAY_IDX(DAY_6)] ) },
119 { _CITRUS_LC_TIME_SYM_DAY_7, OFFSET(day[DAY_IDX(DAY_7)] ) }, 119 { _CITRUS_LC_TIME_SYM_DAY_7, OFFSET(day[DAY_IDX(DAY_7)] ) },
120 { _CITRUS_LC_TIME_SYM_ABMON_1, OFFSET(abmon[ABMON_IDX(ABMON_1)] ) }, 120 { _CITRUS_LC_TIME_SYM_ABMON_1, OFFSET(abmon[ABMON_IDX(ABMON_1)] ) },
121 { _CITRUS_LC_TIME_SYM_ABMON_2, OFFSET(abmon[ABMON_IDX(ABMON_2)] ) }, 121 { _CITRUS_LC_TIME_SYM_ABMON_2, OFFSET(abmon[ABMON_IDX(ABMON_2)] ) },
122 { _CITRUS_LC_TIME_SYM_ABMON_3, OFFSET(abmon[ABMON_IDX(ABMON_3)] ) }, 122 { _CITRUS_LC_TIME_SYM_ABMON_3, OFFSET(abmon[ABMON_IDX(ABMON_3)] ) },
123 { _CITRUS_LC_TIME_SYM_ABMON_4, OFFSET(abmon[ABMON_IDX(ABMON_4)] ) }, 123 { _CITRUS_LC_TIME_SYM_ABMON_4, OFFSET(abmon[ABMON_IDX(ABMON_4)] ) },
124 { _CITRUS_LC_TIME_SYM_ABMON_5, OFFSET(abmon[ABMON_IDX(ABMON_5)] ) }, 124 { _CITRUS_LC_TIME_SYM_ABMON_5, OFFSET(abmon[ABMON_IDX(ABMON_5)] ) },
125 { _CITRUS_LC_TIME_SYM_ABMON_6, OFFSET(abmon[ABMON_IDX(ABMON_6)] ) }, 125 { _CITRUS_LC_TIME_SYM_ABMON_6, OFFSET(abmon[ABMON_IDX(ABMON_6)] ) },
126 { _CITRUS_LC_TIME_SYM_ABMON_7, OFFSET(abmon[ABMON_IDX(ABMON_7)] ) }, 126 { _CITRUS_LC_TIME_SYM_ABMON_7, OFFSET(abmon[ABMON_IDX(ABMON_7)] ) },
127 { _CITRUS_LC_TIME_SYM_ABMON_8, OFFSET(abmon[ABMON_IDX(ABMON_8)] ) }, 127 { _CITRUS_LC_TIME_SYM_ABMON_8, OFFSET(abmon[ABMON_IDX(ABMON_8)] ) },
128 { _CITRUS_LC_TIME_SYM_ABMON_9, OFFSET(abmon[ABMON_IDX(ABMON_9)] ) }, 128 { _CITRUS_LC_TIME_SYM_ABMON_9, OFFSET(abmon[ABMON_IDX(ABMON_9)] ) },
129 { _CITRUS_LC_TIME_SYM_ABMON_10, OFFSET(abmon[ABMON_IDX(ABMON_10)]) }, 129 { _CITRUS_LC_TIME_SYM_ABMON_10, OFFSET(abmon[ABMON_IDX(ABMON_10)]) },
130 { _CITRUS_LC_TIME_SYM_ABMON_11, OFFSET(abmon[ABMON_IDX(ABMON_11)]) }, 130 { _CITRUS_LC_TIME_SYM_ABMON_11, OFFSET(abmon[ABMON_IDX(ABMON_11)]) },
131 { _CITRUS_LC_TIME_SYM_ABMON_12, OFFSET(abmon[ABMON_IDX(ABMON_12)]) }, 131 { _CITRUS_LC_TIME_SYM_ABMON_12, OFFSET(abmon[ABMON_IDX(ABMON_12)]) },
132 { _CITRUS_LC_TIME_SYM_MON_1, OFFSET(mon[MON_IDX(MON_1)] ) }, 132 { _CITRUS_LC_TIME_SYM_MON_1, OFFSET(mon[MON_IDX(MON_1)] ) },
133 { _CITRUS_LC_TIME_SYM_MON_2, OFFSET(mon[MON_IDX(MON_2)] ) }, 133 { _CITRUS_LC_TIME_SYM_MON_2, OFFSET(mon[MON_IDX(MON_2)] ) },
134 { _CITRUS_LC_TIME_SYM_MON_3, OFFSET(mon[MON_IDX(MON_3)] ) }, 134 { _CITRUS_LC_TIME_SYM_MON_3, OFFSET(mon[MON_IDX(MON_3)] ) },
135 { _CITRUS_LC_TIME_SYM_MON_4, OFFSET(mon[MON_IDX(MON_4)] ) }, 135 { _CITRUS_LC_TIME_SYM_MON_4, OFFSET(mon[MON_IDX(MON_4)] ) },
136 { _CITRUS_LC_TIME_SYM_MON_5, OFFSET(mon[MON_IDX(MON_5)] ) }, 136 { _CITRUS_LC_TIME_SYM_MON_5, OFFSET(mon[MON_IDX(MON_5)] ) },
137 { _CITRUS_LC_TIME_SYM_MON_6, OFFSET(mon[MON_IDX(MON_6)] ) }, 137 { _CITRUS_LC_TIME_SYM_MON_6, OFFSET(mon[MON_IDX(MON_6)] ) },
138 { _CITRUS_LC_TIME_SYM_MON_7, OFFSET(mon[MON_IDX(MON_7)] ) }, 138 { _CITRUS_LC_TIME_SYM_MON_7, OFFSET(mon[MON_IDX(MON_7)] ) },
139 { _CITRUS_LC_TIME_SYM_MON_8, OFFSET(mon[MON_IDX(MON_8)] ) }, 139 { _CITRUS_LC_TIME_SYM_MON_8, OFFSET(mon[MON_IDX(MON_8)] ) },
140 { _CITRUS_LC_TIME_SYM_MON_9, OFFSET(mon[MON_IDX(MON_9)] ) }, 140 { _CITRUS_LC_TIME_SYM_MON_9, OFFSET(mon[MON_IDX(MON_9)] ) },
141 { _CITRUS_LC_TIME_SYM_MON_10, OFFSET(mon[MON_IDX(MON_10)] ) }, 141 { _CITRUS_LC_TIME_SYM_MON_10, OFFSET(mon[MON_IDX(MON_10)] ) },
142 { _CITRUS_LC_TIME_SYM_MON_11, OFFSET(mon[MON_IDX(MON_11)] ) }, 142 { _CITRUS_LC_TIME_SYM_MON_11, OFFSET(mon[MON_IDX(MON_11)] ) },
143 { _CITRUS_LC_TIME_SYM_MON_12, OFFSET(mon[MON_IDX(MON_12)] ) }, 143 { _CITRUS_LC_TIME_SYM_MON_12, OFFSET(mon[MON_IDX(MON_12)] ) },
144 { _CITRUS_LC_TIME_SYM_AM_STR, OFFSET(am_pm[AM_PM_IDX(AM_STR)] ) }, 144 { _CITRUS_LC_TIME_SYM_AM_STR, OFFSET(am_pm[AM_PM_IDX(AM_STR)] ) },
145 { _CITRUS_LC_TIME_SYM_PM_STR, OFFSET(am_pm[AM_PM_IDX(PM_STR)] ) }, 145 { _CITRUS_LC_TIME_SYM_PM_STR, OFFSET(am_pm[AM_PM_IDX(PM_STR)] ) },
146 { _CITRUS_LC_TIME_SYM_D_T_FMT, OFFSET(d_t_fmt ) }, 146 { _CITRUS_LC_TIME_SYM_D_T_FMT, OFFSET(d_t_fmt ) },
147 { _CITRUS_LC_TIME_SYM_D_FMT, OFFSET(d_fmt ) }, 147 { _CITRUS_LC_TIME_SYM_D_FMT, OFFSET(d_fmt ) },
148 { _CITRUS_LC_TIME_SYM_T_FMT, OFFSET(t_fmt ) }, 148 { _CITRUS_LC_TIME_SYM_T_FMT, OFFSET(t_fmt ) },
149 { _CITRUS_LC_TIME_SYM_T_FMT_AMPM, OFFSET(t_fmt_ampm ) }, 149 { _CITRUS_LC_TIME_SYM_T_FMT_AMPM, OFFSET(t_fmt_ampm ) },
150 { NULL, 0 } 150 { NULL, 0 }
151}; 151};
152 152
153static __inline int 153static __inline int
154_citrus_LC_TIME_init_normal(_TimeLocale * __restrict data, 154_citrus_LC_TIME_init_normal(_TimeLocale * __restrict data,
155 struct _citrus_db * __restrict db) 155 struct _citrus_db * __restrict db)
156{ 156{
157 const struct _citrus_LC_TIME_key *key; 157 const struct _citrus_LC_TIME_key *key;
158 char **p; 158 char **p;
159 const char *s; 159 const char *s;
160 160
161 _DIAGASSERT(data != NULL); 161 _DIAGASSERT(data != NULL);
162 _DIAGASSERT(db != NULL); 162 _DIAGASSERT(db != NULL);
163 163
164 memset(data, 0, sizeof(*data)); 164 memset(data, 0, sizeof(*data));
165 for (key = &keys[0]; key->name != NULL; ++key) { 165 for (key = &keys[0]; key->name != NULL; ++key) {
166 if (_db_lookupstr_by_s(db, key->name, &s, NULL)) 166 if (_db_lookupstr_by_s(db, key->name, &s, NULL))
167 goto fatal; 167 goto fatal;
168 p = (char **)(void *) 168 p = (char **)(void *)
169 (((char *)(void *)data) + key->offset); 169 (((char *)(void *)data) + key->offset);
170 *p = strdup(s); 170 *p = strdup(s);
171 if (*p == NULL) 171 if (*p == NULL)
172 goto fatal; 172 goto fatal;
173 } 173 }
174 return 0; 174 return 0;
175 175
176fatal: 176fatal:
177 _citrus_LC_TIME_uninit(data); 177 _citrus_LC_TIME_uninit(data);
178 return EFTYPE; 178 return EFTYPE;
179} 179}
180 180
181static __inline int 181static __inline int
182_citrus_LC_TIME_init_fallback(_TimeLocale * __restrict data, 182_citrus_LC_TIME_init_fallback(_TimeLocale * __restrict data,
183 struct _memstream * __restrict ms) 183 struct _memstream * __restrict ms)
184{ 184{
185 const struct _citrus_LC_TIME_key *key; 185 const struct _citrus_LC_TIME_key *key;
186 char **p; 186 char **p;
187 const char *s; 187 const char *s;
188 size_t n; 188 size_t n;
189 189
190 memset(data, 0, sizeof(*data)); 190 memset(data, 0, sizeof(*data));
191 for (key = &keys[0]; key->name != NULL; ++key) { 191 for (key = &keys[0]; key->name != NULL; ++key) {
192 if ((s = _memstream_getln(ms, &n)) == NULL) 192 if ((s = _memstream_getln(ms, &n)) == NULL)
193 goto fatal; 193 goto fatal;
194 p = (char **)(void *) 194 p = (char **)(void *)
195 (((char *)(void *)data) + key->offset); 195 (((char *)(void *)data) + key->offset);
196 *p = strndup(s, n - 1); 196 *p = strndup(s, n - 1);
197 if (*p == NULL) 197 if (*p == NULL)
198 goto fatal; 198 goto fatal;
199 } 199 }
200 return 0; 200 return 0;
201 201
202fatal: 202fatal:
203 _citrus_LC_TIME_uninit(data); 203 _citrus_LC_TIME_uninit(data);
204 return EFTYPE; 204 return EFTYPE;
205} 205}
206 206
207/* 207/*
208 * macro required by citrus_lc_template.h 208 * macro required by citrus_lc_template.h
209 */ 209 */
210#define _CATEGORY_DB "LC_TIME" 210#define _CATEGORY_DB "LC_TIME"
211#define _CATEGORY_MAGIC _CITRUS_LC_TIME_MAGIC_1 211#define _CATEGORY_MAGIC _CITRUS_LC_TIME_MAGIC_1
212 212
213#include "citrus_lc_template.h" 213#include "citrus_lc_template.h"
214_LOCALE_CATEGORY_ENTRY(_citrus_LC_TIME_); 

cvs diff -r1.2 -r1.3 src/lib/libc/locale/dummy_lc_collate.c (switch to unified diff)

--- src/lib/libc/locale/dummy_lc_collate.c 2009/01/11 02:46:28 1.2
+++ src/lib/libc/locale/dummy_lc_collate.c 2012/03/04 21:14:56 1.3
@@ -1,54 +1,53 @@ @@ -1,54 +1,53 @@
1/* $NetBSD: dummy_lc_collate.c,v 1.2 2009/01/11 02:46:28 christos Exp $ */ 1/* $NetBSD: dummy_lc_collate.c,v 1.3 2012/03/04 21:14:56 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: dummy_lc_collate.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); 31__RCSID("$NetBSD: dummy_lc_collate.c,v 1.3 2012/03/04 21:14:56 tnozaki Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <assert.h> 35#include <assert.h>
36#include <langinfo.h> 36#include <langinfo.h>
37#define __SETLOCALE_SOURCE__ 37#define __SETLOCALE_SOURCE__
38#include <locale.h> 38#include <locale.h>
39#include <stdlib.h> 39#include <stdlib.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <string.h> 41#include <string.h>
42 42
43#include "setlocale_local.h" 43#include "setlocale_local.h"
44 44
45/* 45/*
46 * macro required by dummy_lc_template.h 46 * macro required by dummy_lc_template.h
47 */ 47 */
48#define _PREFIX(name) __CONCAT(_dummy_LC_COLLATE_,name) 48#define _PREFIX(name) __CONCAT(_dummy_LC_COLLATE_,name)
49 49
50#define _CATEGORY_ID LC_COLLATE 50#define _CATEGORY_ID LC_COLLATE
51#define _CATEGORY_NAME "LC_COLLATE" 51#define _CATEGORY_NAME "LC_COLLATE"
52 52
53#include "dummy_lc_template.h" 53#include "dummy_lc_template.h"
54_LOCALE_CATEGORY_ENTRY(_dummy_LC_COLLATE_); 

cvs diff -r1.2 -r1.3 src/lib/libc/locale/dummy_lc_template.h (switch to unified diff)

--- src/lib/libc/locale/dummy_lc_template.h 2009/01/11 02:46:28 1.2
+++ src/lib/libc/locale/dummy_lc_template.h 2012/03/04 21:14:56 1.3
@@ -1,56 +1,54 @@ @@ -1,56 +1,54 @@
1/* $NetBSD: dummy_lc_template.h,v 1.2 2009/01/11 02:46:28 christos Exp $ */ 1/* $NetBSD: dummy_lc_template.h,v 1.3 2012/03/04 21:14:56 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#ifndef _DUMMY_LC_TEMPLATE_H_ 29#ifndef _DUMMY_LC_TEMPLATE_H_
30#define _DUMMY_LC_TEMPLATE_H_ 30#define _DUMMY_LC_TEMPLATE_H_
31 31
32#include "generic_lc_template_decl.h" 32#include "generic_lc_template_decl.h"
33 33
34static const char * 34const char *
35_PREFIX(setlocale)(const char * __restrict name, 35_PREFIX(setlocale)(const char * __restrict name,
36 struct _locale_impl_t * __restrict locale) 36 struct _locale_impl_t * __restrict locale)
37{ 37{
38 if (name != NULL) { 38 if (name != NULL) {
39 if (*name == '\0') 39 if (*name == '\0')
40 name = _get_locale_env(_CATEGORY_NAME); 40 name = _get_locale_env(_CATEGORY_NAME);
41 if (strcmp(name, locale->part_name[(size_t)_CATEGORY_ID])) { 41 if (strcmp(name, locale->part_name[(size_t)_CATEGORY_ID])) {
42 if (!strcmp(_C_LOCALE, name)) 42 if (!strcmp(_C_LOCALE, name))
43 name = _C_LOCALE; 43 name = _C_LOCALE;
44 else if (!strcmp(_POSIX_LOCALE, name)) 44 else if (!strcmp(_POSIX_LOCALE, name))
45 name = _POSIX_LOCALE; 45 name = _POSIX_LOCALE;
46 else 46 else
47 return NULL; 47 return NULL;
48 locale->part_name[(size_t)_CATEGORY_ID] = name; 48 locale->part_name[(size_t)_CATEGORY_ID] = name;
49 } 49 }
50 } 50 }
51 return locale->part_name[(size_t)_CATEGORY_ID]; 51 return locale->part_name[(size_t)_CATEGORY_ID];
52} 52}
53 53
54#include "generic_lc_template.h" 
55 
56#endif /*_DUMMY_LC_TEMPLATE_H_*/ 54#endif /*_DUMMY_LC_TEMPLATE_H_*/

cvs diff -r1.2 -r1.3 src/lib/libc/locale/generic_lc_template_decl.h (switch to unified diff)

--- src/lib/libc/locale/generic_lc_template_decl.h 2009/01/11 02:46:28 1.2
+++ src/lib/libc/locale/generic_lc_template_decl.h 2012/03/04 21:14:56 1.3
@@ -1,35 +1,35 @@ @@ -1,35 +1,35 @@
1/* $NetBSD: generic_lc_template_decl.h,v 1.2 2009/01/11 02:46:28 christos Exp $ */ 1/* $NetBSD: generic_lc_template_decl.h,v 1.3 2012/03/04 21:14:56 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#ifndef _GENERIC_LC_TEMPLATE_DECL_H_ 29#ifndef _GENERIC_LC_TEMPLATE_DECL_H_
30#define _GENERIC_LC_TEMPLATE_DECL_H_ 30#define _GENERIC_LC_TEMPLATE_DECL_H_
31 31
32static const char * _PREFIX(setlocale)(const char * __restrict, 32const char * _PREFIX(setlocale)(const char * __restrict,
33 struct _locale_impl_t * __restrict); 33 struct _locale_impl_t * __restrict);
34 34
35#endif /*_GENERIC_LC_TEMPLATE_DECL_H_*/ 35#endif /*_GENERIC_LC_TEMPLATE_DECL_H_*/

cvs diff -r1.3 -r1.4 src/lib/libc/locale/generic_lc_all.c (switch to unified diff)

--- src/lib/libc/locale/generic_lc_all.c 2009/10/04 21:05:18 1.3
+++ src/lib/libc/locale/generic_lc_all.c 2012/03/04 21:14:56 1.4
@@ -1,124 +1,117 @@ @@ -1,124 +1,117 @@
1/* $NetBSD: generic_lc_all.c,v 1.3 2009/10/04 21:05:18 tnozaki Exp $ */ 1/* $NetBSD: generic_lc_all.c,v 1.4 2012/03/04 21:14:56 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: generic_lc_all.c,v 1.3 2009/10/04 21:05:18 tnozaki Exp $"); 31__RCSID("$NetBSD: generic_lc_all.c,v 1.4 2012/03/04 21:14:56 tnozaki Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <assert.h> 35#include <assert.h>
36#include <langinfo.h> 36#include <langinfo.h>
37#define __SETLOCALE_SOURCE__ 37#define __SETLOCALE_SOURCE__
38#include <locale.h> 38#include <locale.h>
39#include <stdio.h> 39#include <stdio.h>
40#include <stdlib.h> 40#include <stdlib.h>
41#include <string.h> 41#include <string.h>
42 42
43#include "setlocale_local.h" 43#include "setlocale_local.h"
44 44
45/* 45/*
46 * macro required by all template headers 46 * macro required by all template headers
47 */ 47 */
48#define _PREFIX(name) __CONCAT(_generic_LC_ALL_, name) 48#define _PREFIX(name) __CONCAT(_generic_LC_ALL_, name)
49 49
50#include "generic_lc_template_decl.h" 50#include "generic_lc_template_decl.h"
51 51
52const char * 52const char *
53_generic_LC_ALL_setlocale(const char * __restrict name, 53_generic_LC_ALL_setlocale(const char * __restrict name,
54 struct _locale_impl_t * __restrict locale) 54 struct _locale_impl_t * __restrict locale)
55{ 55{
56 _locale_category_t *l; 56 _locale_set_t sl;
57 char head[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)], *tail; 57 char head[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)], *tail;
58 const char *tokens[_LC_LAST], *s, *t; 58 const char *tokens[_LC_LAST], *s, *t;
59 int load_locale_success, i, j; 59 int load_locale_success, i, j;
60 60
61 l = _find_category(1); 61 sl = _find_category(1);
62 _DIAGASSERT(l != NULL); 62 _DIAGASSERT(sl != NULL);
63 load_locale_success = 0; 63 load_locale_success = 0;
64 if (name != NULL) { 64 if (name != NULL) {
65 strlcpy(&head[0], name, sizeof(head)); 65 strlcpy(&head[0], name, sizeof(head));
66 tokens[1] = &head[0]; 66 tokens[1] = &head[0];
67 tail = strchr(tokens[1], '/'); 67 tail = strchr(tokens[1], '/');
68 if (tail == NULL) { 68 if (tail == NULL) {
69 for (i = 2; i < _LC_LAST; ++i) 69 for (i = 2; i < _LC_LAST; ++i)
70 tokens[i] = tokens[1]; 70 tokens[i] = tokens[1];
71 } else { 71 } else {
72 *tail++ = '\0'; 72 *tail++ = '\0';
73 for (i = 2; i < _LC_LAST - 1; ++i) { 73 for (i = 2; i < _LC_LAST - 1; ++i) {
74 tokens[i] = (const char *)tail; 74 tokens[i] = (const char *)tail;
75 tail = strchr(tokens[i], '/'); 75 tail = strchr(tokens[i], '/');
76 if (tail == NULL) 76 if (tail == NULL)
77 return NULL; 77 return NULL;
78 *tail++ = '\0'; 78 *tail++ = '\0';
79 } 79 }
80 tokens[_LC_LAST - 1] = (const char *)tail; 80 tokens[_LC_LAST - 1] = (const char *)tail;
81 tail = strchr(tokens[i], '/'); 81 tail = strchr(tokens[i], '/');
82 if (tail != NULL) 82 if (tail != NULL)
83 return NULL; 83 return NULL;
84 } 84 }
85 if ((*l->setlocale)(tokens[1], locale) != NULL) 85 if ((*sl)(tokens[1], locale) != NULL)
86 load_locale_success = 1; 86 load_locale_success = 1;
87 } 87 }
88 s = (*l->setlocale)(NULL, locale); 88 s = (*sl)(NULL, locale);
89 _DIAGASSERT(s != NULL); 89 _DIAGASSERT(s != NULL);
90 strlcpy(&locale->query[0], s, sizeof(locale->query)); 90 strlcpy(&locale->query[0], s, sizeof(locale->query));
91 for (i = 2, j = 0; i < _LC_LAST; ++i) { 91 for (i = 2, j = 0; i < _LC_LAST; ++i) {
92 l = _find_category(i); 92 sl = _find_category(i);
93 _DIAGASSERT(l != NULL); 93 _DIAGASSERT(sl != NULL);
94 if (name != NULL) { 94 if (name != NULL) {
95 if ((*l->setlocale)(tokens[i], locale) != NULL) 95 if ((*sl)(tokens[i], locale) != NULL)
96 load_locale_success = 1; 96 load_locale_success = 1;
97 } 97 }
98 t = (*l->setlocale)(NULL, locale); 98 t = (*sl)(NULL, locale);
99 _DIAGASSERT(t != NULL); 99 _DIAGASSERT(t != NULL);
100 if (j == 0) { 100 if (j == 0) {
101 if (!strcmp(s, t)) 101 if (!strcmp(s, t))
102 continue; 102 continue;
103 for (j = 2; j < i; ++j) { 103 for (j = 2; j < i; ++j) {
104 strlcat(&locale->query[0], "/", 104 strlcat(&locale->query[0], "/",
105 sizeof(locale->query)); 105 sizeof(locale->query));
106 strlcat(&locale->query[0], s, 106 strlcat(&locale->query[0], s,
107 sizeof(locale->query)); 107 sizeof(locale->query));
108 } 108 }
109 } 109 }
110 strlcat(&locale->query[0], "/", sizeof(locale->query)); 110 strlcat(&locale->query[0], "/", sizeof(locale->query));
111 strlcat(&locale->query[0], t, sizeof(locale->query)); 111 strlcat(&locale->query[0], t, sizeof(locale->query));
112 } 112 }
113 if (name != NULL && !load_locale_success) 113 if (name != NULL && !load_locale_success)
114 return NULL; 114 return NULL;
115 return (const char *)&locale->query[0]; 115 return (const char *)&locale->query[0];
116} 116}
117 117
118/* 
119 * macro requrired by generic_lc_template.h 
120 */ 
121#define _CATEGORY_ID LC_ALL 
122 
123#include "generic_lc_template.h" 
124_LOCALE_CATEGORY_ENTRY(_generic_LC_ALL_); 

cvs diff -r1.3 -r1.4 src/lib/libc/locale/nb_lc_template.h (switch to unified diff)

--- src/lib/libc/locale/nb_lc_template.h 2010/05/22 13:15:59 1.3
+++ src/lib/libc/locale/nb_lc_template.h 2012/03/04 21:14:56 1.4
@@ -1,248 +1,246 @@ @@ -1,248 +1,246 @@
1/* $NetBSD: nb_lc_template.h,v 1.3 2010/05/22 13:15:59 tnozaki Exp $ */ 1/* $NetBSD: nb_lc_template.h,v 1.4 2012/03/04 21:14:56 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)1999, 2008 Citrus Project, 4 * Copyright (c)1999, 2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/*- 29/*-
30 * Copyright (c) 1998 The NetBSD Foundation, Inc. 30 * Copyright (c) 1998 The NetBSD Foundation, Inc.
31 * All rights reserved. 31 * All rights reserved.
32 * 32 *
33 * This code is derived from software contributed to The NetBSD Foundation 33 * This code is derived from software contributed to The NetBSD Foundation
34 * by Paul Kranenburg. 34 * by Paul Kranenburg.
35 * 35 *
36 * Redistribution and use in source and binary forms, with or without 36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions 37 * modification, are permitted provided that the following conditions
38 * are met: 38 * are met:
39 * 1. Redistributions of source code must retain the above copyright 39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer. 40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright 41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the 42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution. 43 * documentation and/or other materials provided with the distribution.
44 * 44 *
45 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 45 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
46 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
47 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 47 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 48 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
49 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 49 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55 * POSSIBILITY OF SUCH DAMAGE. 55 * POSSIBILITY OF SUCH DAMAGE.
56 */ 56 */
57 57
58/*- 58/*-
59 * Copyright (c) 1993 59 * Copyright (c) 1993
60 * The Regents of the University of California. All rights reserved. 60 * The Regents of the University of California. All rights reserved.
61 * 61 *
62 * This code is derived from software contributed to Berkeley by 62 * This code is derived from software contributed to Berkeley by
63 * Paul Borman at Krystal Technologies. 63 * Paul Borman at Krystal Technologies.
64 * 64 *
65 * Redistribution and use in source and binary forms, with or without 65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions 66 * modification, are permitted provided that the following conditions
67 * are met: 67 * are met:
68 * 1. Redistributions of source code must retain the above copyright 68 * 1. Redistributions of source code must retain the above copyright
69 * notice, this list of conditions and the following disclaimer. 69 * notice, this list of conditions and the following disclaimer.
70 * 2. Redistributions in binary form must reproduce the above copyright 70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in the 71 * notice, this list of conditions and the following disclaimer in the
72 * documentation and/or other materials provided with the distribution. 72 * documentation and/or other materials provided with the distribution.
73 * 3. Neither the name of the University nor the names of its contributors 73 * 3. Neither the name of the University nor the names of its contributors
74 * may be used to endorse or promote products derived from this software 74 * may be used to endorse or promote products derived from this software
75 * without specific prior written permission. 75 * without specific prior written permission.
76 * 76 *
77 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 77 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
78 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 78 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
79 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 79 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
80 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 80 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
87 * SUCH DAMAGE. 87 * SUCH DAMAGE.
88 */ 88 */
89 89
90#ifndef _NB_LC_TEMPLATE_H_ 90#ifndef _NB_LC_TEMPLATE_H_
91#define _NB_LC_TEMPLATE_H_ 91#define _NB_LC_TEMPLATE_H_
92 92
93#define _nb_part_t _PREFIX(part_t) 93#define _nb_part_t _PREFIX(part_t)
94#define _nb_part_cache _PREFIX(part_cache) 94#define _nb_part_cache _PREFIX(part_cache)
95#define _nb_default_c _PREFIX(default_c) 95#define _nb_default_c _PREFIX(default_c)
96#define _nb_default_posix _PREFIX(default_posix) 96#define _nb_default_posix _PREFIX(default_posix)
97#define _nb_mutex _PREFIX(mutex) 97#define _nb_mutex _PREFIX(mutex)
98 98
99typedef struct _nb_part_t { 99typedef struct _nb_part_t {
100 char name[_LOCALENAME_LEN_MAX]; 100 char name[_LOCALENAME_LEN_MAX];
101 _CATEGORY_TYPE *impl; 101 _CATEGORY_TYPE *impl;
102 SIMPLEQ_ENTRY(_nb_part_t) entry; 102 SIMPLEQ_ENTRY(_nb_part_t) entry;
103} _nb_part_t; 103} _nb_part_t;
104 104
105static SIMPLEQ_HEAD(, _nb_part_t) _nb_part_cache = 105static SIMPLEQ_HEAD(, _nb_part_t) _nb_part_cache =
106 SIMPLEQ_HEAD_INITIALIZER(_nb_part_cache); 106 SIMPLEQ_HEAD_INITIALIZER(_nb_part_cache);
107 107
108static const _nb_part_t _nb_default_c = { 108static const _nb_part_t _nb_default_c = {
109 _C_LOCALE, 109 _C_LOCALE,
110 __UNCONST(&_CATEGORY_DEFAULT), 110 __UNCONST(&_CATEGORY_DEFAULT),
111 { NULL }, 111 { NULL },
112}; 112};
113 113
114static const _nb_part_t _nb_default_posix = { 114static const _nb_part_t _nb_default_posix = {
115 _POSIX_LOCALE, 115 _POSIX_LOCALE,
116 __UNCONST(&_CATEGORY_DEFAULT), 116 __UNCONST(&_CATEGORY_DEFAULT),
117 { NULL }, 117 { NULL },
118}; 118};
119 119
120#ifdef _REENTRANT 120#ifdef _REENTRANT
121static mutex_t _nb_mutex = MUTEX_INITIALIZER; 121static mutex_t _nb_mutex = MUTEX_INITIALIZER;
122#endif 122#endif
123 123
124static int 124static int
125_PREFIX(load_sub)(const char * __restrict name, const char * __restrict real, 125_PREFIX(load_sub)(const char * __restrict name, const char * __restrict real,
126 _nb_part_t ** __restrict part, int force) 126 _nb_part_t ** __restrict part, int force)
127{ 127{
128 _nb_part_t *p, *q; 128 _nb_part_t *p, *q;
129 int ret; 129 int ret;
130 130
131 _DIAGASSERT(name != NULL); 131 _DIAGASSERT(name != NULL);
132 _DIAGASSERT(part != NULL); 132 _DIAGASSERT(part != NULL);
133 133
134 if (!strcmp(_C_LOCALE, name)) { 134 if (!strcmp(_C_LOCALE, name)) {
135 p = __UNCONST(&_nb_default_c); 135 p = __UNCONST(&_nb_default_c);
136 } else if (!strcmp(_POSIX_LOCALE, name)) { 136 } else if (!strcmp(_POSIX_LOCALE, name)) {
137 p = __UNCONST(&_nb_default_posix); 137 p = __UNCONST(&_nb_default_posix);
138 } else { 138 } else {
139 SIMPLEQ_FOREACH(p, &_nb_part_cache, entry) { 139 SIMPLEQ_FOREACH(p, &_nb_part_cache, entry) {
140 if (!strcmp((const char *)&p->name[0], name)) 140 if (!strcmp((const char *)&p->name[0], name))
141 goto found; 141 goto found;
142 } 142 }
143 p = malloc(sizeof(*p)); 143 p = malloc(sizeof(*p));
144 if (p == NULL) 144 if (p == NULL)
145 return ENOMEM; 145 return ENOMEM;
146 if (force) { 146 if (force) {
147 p->impl = __UNCONST(&_CATEGORY_DEFAULT); 147 p->impl = __UNCONST(&_CATEGORY_DEFAULT);
148 } else { 148 } else {
149 _DIAGASSERT(_PathLocale != NULL); 149 _DIAGASSERT(_PathLocale != NULL);
150 ret = _PREFIX(create_impl)((const char *)_PathLocale, 150 ret = _PREFIX(create_impl)((const char *)_PathLocale,
151 name, &p->impl); 151 name, &p->impl);
152 if (ret) { 152 if (ret) {
153 free(p); 153 free(p);
154 return ret; 154 return ret;
155 } 155 }
156 } 156 }
157 strlcpy(&p->name[0], name, sizeof(p->name)); 157 strlcpy(&p->name[0], name, sizeof(p->name));
158 SIMPLEQ_INSERT_TAIL(&_nb_part_cache, p, entry); 158 SIMPLEQ_INSERT_TAIL(&_nb_part_cache, p, entry);
159 } 159 }
160found: 160found:
161 if (real != NULL) { 161 if (real != NULL) {
162 q = malloc(sizeof(*q)); 162 q = malloc(sizeof(*q));
163 if (q == NULL) 163 if (q == NULL)
164 return ENOMEM; 164 return ENOMEM;
165 strlcpy(&q->name[0], real, sizeof(p->name)); 165 strlcpy(&q->name[0], real, sizeof(p->name));
166 q->impl = p->impl; 166 q->impl = p->impl;
167 SIMPLEQ_INSERT_TAIL(&_nb_part_cache, q, entry); 167 SIMPLEQ_INSERT_TAIL(&_nb_part_cache, q, entry);
168 p = q; 168 p = q;
169 } 169 }
170 *part = p; 170 *part = p;
171 return 0; 171 return 0;
172} 172}
173 173
174static __inline int 174static __inline int
175_PREFIX(load)(const char * __restrict name, 175_PREFIX(load)(const char * __restrict name,
176 _nb_part_t ** __restrict part) 176 _nb_part_t ** __restrict part)
177{ 177{
178 int ret, force; 178 int ret, force;
179 char path[PATH_MAX + 1], loccat[PATH_MAX + 1], buf[PATH_MAX + 1]; 179 char path[PATH_MAX + 1], loccat[PATH_MAX + 1], buf[PATH_MAX + 1];
180 const char *aliaspath, *alias; 180 const char *aliaspath, *alias;
181 181
182#define _LOAD_SUB_ALIAS(key) \ 182#define _LOAD_SUB_ALIAS(key) \
183do { \ 183do { \
184 alias = __unaliasname(aliaspath, key, &buf[0], sizeof(buf)); \ 184 alias = __unaliasname(aliaspath, key, &buf[0], sizeof(buf)); \
185 if (alias != NULL) { \ 185 if (alias != NULL) { \
186 ret = (force = !__isforcemapping(alias)) \ 186 ret = (force = !__isforcemapping(alias)) \
187 ? _PREFIX(load_sub)(name, NULL, part, force) \ 187 ? _PREFIX(load_sub)(name, NULL, part, force) \
188 : _PREFIX(load_sub)(alias, name, part, force); \ 188 : _PREFIX(load_sub)(alias, name, part, force); \
189 _DIAGASSERT(!ret || !force); \ 189 _DIAGASSERT(!ret || !force); \
190 goto done; \ 190 goto done; \
191 } \ 191 } \
192} while (/*CONSTCOND*/0) 192} while (/*CONSTCOND*/0)
193 193
194 /* (1) non-aliased file */ 194 /* (1) non-aliased file */
195 mutex_lock(&_nb_mutex); 195 mutex_lock(&_nb_mutex);
196 ret = _PREFIX(load_sub)(name, NULL, part, 0); 196 ret = _PREFIX(load_sub)(name, NULL, part, 0);
197 if (ret != ENOENT) 197 if (ret != ENOENT)
198 goto done; 198 goto done;
199 199
200 /* (2) lookup locname/catname type alias */ 200 /* (2) lookup locname/catname type alias */
201 _DIAGASSERT(_PathLocale != NULL); 201 _DIAGASSERT(_PathLocale != NULL);
202 snprintf(&path[0], sizeof(path), 202 snprintf(&path[0], sizeof(path),
203 "%s/" _LOCALE_ALIAS_NAME, _PathLocale); 203 "%s/" _LOCALE_ALIAS_NAME, _PathLocale);
204 aliaspath = (const char *)&path[0]; 204 aliaspath = (const char *)&path[0];
205 snprintf(&loccat[0], sizeof(loccat), 205 snprintf(&loccat[0], sizeof(loccat),
206 "%s/" _CATEGORY_NAME, name); 206 "%s/" _CATEGORY_NAME, name);
207 _LOAD_SUB_ALIAS((const char *)&loccat[0]); 207 _LOAD_SUB_ALIAS((const char *)&loccat[0]);
208 208
209 /* (3) lookup locname type alias */ 209 /* (3) lookup locname type alias */
210 _LOAD_SUB_ALIAS(name); 210 _LOAD_SUB_ALIAS(name);
211 211
212done: 212done:
213 mutex_unlock(&_nb_mutex); 213 mutex_unlock(&_nb_mutex);
214 return ret; 214 return ret;
215} 215}
216 216
217static const char * 217const char *
218_PREFIX(setlocale)(const char * __restrict name, 218_PREFIX(setlocale)(const char * __restrict name,
219 struct _locale_impl_t * __restrict locale) 219 struct _locale_impl_t * __restrict locale)
220{ 220{
221 _nb_part_t *part; 221 _nb_part_t *part;
222 222
223 /* name may be NULL */ 223 /* name may be NULL */
224 _DIAGASSERT(locale != NULL); 224 _DIAGASSERT(locale != NULL);
225 225
226 if (name != NULL) { 226 if (name != NULL) {
227 if (*name == '\0') 227 if (*name == '\0')
228 name = _get_locale_env(_CATEGORY_NAME); 228 name = _get_locale_env(_CATEGORY_NAME);
229 _DIAGASSERT(name != NULL); 229 _DIAGASSERT(name != NULL);
230 _DIAGASSERT(locale->part_name[(size_t)_CATEGORY_ID] != NULL); 230 _DIAGASSERT(locale->part_name[(size_t)_CATEGORY_ID] != NULL);
231 if (strcmp(name, locale->part_name[(size_t)_CATEGORY_ID])) { 231 if (strcmp(name, locale->part_name[(size_t)_CATEGORY_ID])) {
232 if (_PREFIX(load)(name, &part)) 232 if (_PREFIX(load)(name, &part))
233 return NULL; 233 return NULL;
234 locale->part_name[(size_t)_CATEGORY_ID] 234 locale->part_name[(size_t)_CATEGORY_ID]
235 = &part->name[0]; 235 = &part->name[0];
236 locale->part_impl[(size_t)_CATEGORY_ID] 236 locale->part_impl[(size_t)_CATEGORY_ID]
237 = part->impl; 237 = part->impl;
238 _PREFIX(build_cache)(locale->cache, part->impl); 238 _PREFIX(build_cache)(locale->cache, part->impl);
239 if (locale == &_global_locale) 239 if (locale == &_global_locale)
240 _PREFIX(fixup)(part->impl); 240 _PREFIX(fixup)(part->impl);
241 } 241 }
242 } 242 }
243 return locale->part_name[(size_t)_CATEGORY_ID]; 243 return locale->part_name[(size_t)_CATEGORY_ID];
244} 244}
245 245
246#include "generic_lc_template.h" 
247 
248#endif /*_NB_LC_TEMPLATE_H_*/ 246#endif /*_NB_LC_TEMPLATE_H_*/

File Deleted: src/lib/libc/locale/Attic/generic_lc_template.h

cvs diff -r1.59 -r1.60 src/lib/libc/locale/setlocale.c (switch to unified diff)

--- src/lib/libc/locale/setlocale.c 2012/01/20 16:31:30 1.59
+++ src/lib/libc/locale/setlocale.c 2012/03/04 21:14:56 1.60
@@ -1,125 +1,110 @@ @@ -1,125 +1,110 @@
1/* $NetBSD: setlocale.c,v 1.59 2012/01/20 16:31:30 joerg Exp $ */ 1/* $NetBSD: setlocale.c,v 1.60 2012/03/04 21:14:56 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: setlocale.c,v 1.59 2012/01/20 16:31:30 joerg Exp $"); 31__RCSID("$NetBSD: setlocale.c,v 1.60 2012/03/04 21:14:56 tnozaki Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <locale.h> 35#include <locale.h>
36#include <limits.h> 36#include <limits.h>
37#include <paths.h> 37#include <paths.h>
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40#include <unistd.h> 40#include <unistd.h>
41 41
42#include "setlocale_local.h" 42#include "setlocale_local.h"
43 43
44const char *_PathLocale = NULL; 44const char *_PathLocale = NULL;
45 45
46__link_set_decl(all_categories, _locale_category_t); 46static _locale_set_t all_categories[_LC_LAST] = {
 47 [LC_ALL ] = &_generic_LC_ALL_setlocale,
 48 [LC_COLLATE ] = &_dummy_LC_COLLATE_setlocale,
 49 [LC_CTYPE ] = &_citrus_LC_CTYPE_setlocale,
 50 [LC_MONETARY] = &_citrus_LC_MONETARY_setlocale,
 51 [LC_NUMERIC ] = &_citrus_LC_NUMERIC_setlocale,
 52 [LC_TIME ] = &_citrus_LC_TIME_setlocale,
 53 [LC_MESSAGES] = &_citrus_LC_MESSAGES_setlocale,
 54};
47 55
48extern const _locale_category_t _generic_LC_ALL_desc; 56_locale_set_t
49extern const _locale_category_t _dummy_LC_COLLATE_desc; 
50extern const _locale_category_t _citrus_LC_CTYPE_desc; 
51extern const _locale_category_t _citrus_LC_MONETARY_desc; 
52extern const _locale_category_t _citrus_LC_NUMERIC_desc; 
53extern const _locale_category_t _citrus_LC_TIME_desc; 
54extern const _locale_category_t _citrus_LC_MESSAGES_desc; 
55 
56__link_set_add_data(all_categories, _generic_LC_ALL_desc); 
57__link_set_add_data(all_categories, _dummy_LC_COLLATE_desc); 
58__link_set_add_data(all_categories, _citrus_LC_CTYPE_desc); 
59__link_set_add_data(all_categories, _citrus_LC_MONETARY_desc); 
60__link_set_add_data(all_categories, _citrus_LC_NUMERIC_desc); 
61__link_set_add_data(all_categories, _citrus_LC_TIME_desc); 
62__link_set_add_data(all_categories, _citrus_LC_MESSAGES_desc); 
63 
64_locale_category_t * 
65_find_category(int category) 57_find_category(int category)
66{ 58{
67 _locale_category_t * const *p; 59 if (category >= LC_ALL && category < _LC_LAST)
68 60 return all_categories[category];
69 __link_set_foreach(p, all_categories) { 
70 if ((*p)->category == category) 
71 return *p; 
72 } 
73 return NULL; 61 return NULL;
74} 62}
75 63
76const char * 64const char *
77_get_locale_env(const char *category) 65_get_locale_env(const char *category)
78{ 66{
79 const char *name; 67 const char *name;
80 68
81 /* 1. check LC_ALL */ 69 /* 1. check LC_ALL */
82 name = (const char *)getenv("LC_ALL"); 70 name = (const char *)getenv("LC_ALL");
83 if (name == NULL || *name == '\0') { 71 if (name == NULL || *name == '\0') {
84 /* 2. check LC_* */ 72 /* 2. check LC_* */
85 name = (const char *)getenv(category); 73 name = (const char *)getenv(category);
86 if (name == NULL || *name == '\0') { 74 if (name == NULL || *name == '\0') {
87 /* 3. check LANG */ 75 /* 3. check LANG */
88 name = getenv("LANG"); 76 name = getenv("LANG");
89 } 77 }
90 } 78 }
91 if (name == NULL || *name == '\0' || strchr(name, '/')) 79 if (name == NULL || *name == '\0' || strchr(name, '/'))
92 /* 4. if none is set, fall to "C" */ 80 /* 4. if none is set, fall to "C" */
93 name = _C_LOCALE; 81 name = _C_LOCALE;
94 return name; 82 return name;
95} 83}
96 84
97char * 85char *
98__setlocale(int category, const char *name) 86__setlocale(int category, const char *name)
99{ 87{
100 _locale_category_t *l; 88 _locale_set_t sl;
101 struct _locale_impl_t *impl; 89 struct _locale_impl_t *impl;
102 90
103 if (category >= LC_ALL && category < _LC_LAST) { 91 sl = _find_category(category);
104 l = _find_category(category); 92 if (sl == NULL)
105 if (l != NULL) { 93 return NULL;
106 if (issetugid() || ((_PathLocale == NULL && 94 if (issetugid() || ((_PathLocale == NULL &&
107 (_PathLocale = getenv("PATH_LOCALE")) == NULL) || 95 (_PathLocale = getenv("PATH_LOCALE")) == NULL) ||
108 *_PathLocale == '\0')) 96 *_PathLocale == '\0'))
109 _PathLocale = _PATH_LOCALE; 97 _PathLocale = _PATH_LOCALE;
110 impl = *_current_locale(); 98 impl = *_current_locale();
111 return __UNCONST((*l->setlocale)(name, impl)); 99 return __UNCONST((*sl)(name, impl));
112 } 
113 } 
114 return NULL; 
115} 100}
116 101
117char * 102char *
118setlocale(int category, const char *locale) 103setlocale(int category, const char *locale)
119{ 104{
120 105
121 /* locale may be NULL */ 106 /* locale may be NULL */
122 107
123 __mb_len_max_runtime = MB_LEN_MAX; 108 __mb_len_max_runtime = MB_LEN_MAX;
124 return __setlocale(category, locale); 109 return __setlocale(category, locale);
125} 110}

cvs diff -r1.7 -r1.8 src/lib/libc/locale/setlocale_local.h (switch to unified diff)

--- src/lib/libc/locale/setlocale_local.h 2010/06/07 13:52:30 1.7
+++ src/lib/libc/locale/setlocale_local.h 2012/03/04 21:14:57 1.8
@@ -1,83 +1,92 @@ @@ -1,83 +1,92 @@
1/* $NetBSD: setlocale_local.h,v 1.7 2010/06/07 13:52:30 tnozaki Exp $ */ 1/* $NetBSD: setlocale_local.h,v 1.8 2012/03/04 21:14:57 tnozaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2008 Citrus Project, 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#ifndef _SETLOCALE_LOCAL_H_ 29#ifndef _SETLOCALE_LOCAL_H_
30#define _SETLOCALE_LOCAL_H_ 30#define _SETLOCALE_LOCAL_H_
31 31
32#define _LOCALENAME_LEN_MAX 33 32#define _LOCALENAME_LEN_MAX 33
33 33
34#define _C_LOCALE "C" 34#define _C_LOCALE "C"
35#define _POSIX_LOCALE "POSIX" 35#define _POSIX_LOCALE "POSIX"
36 36
37extern const char *_PathLocale; 37extern const char *_PathLocale;
38#define _LOCALE_ALIAS_NAME "locale.alias" 38#define _LOCALE_ALIAS_NAME "locale.alias"
39 39
40typedef void *_locale_part_t; 40typedef void *_locale_part_t;
41 41
42struct _locale_cache_t { 42struct _locale_cache_t {
43 const unsigned char *ctype_tab; 43 const unsigned char *ctype_tab;
44 const short *tolower_tab; 44 const short *tolower_tab;
45 const short *toupper_tab; 45 const short *toupper_tab;
46 size_t mb_cur_max; 46 size_t mb_cur_max;
47 struct lconv *ldata; 47 struct lconv *ldata;
48 const char **items; 48 const char **items;
49}; 49};
50 50
51struct _locale_impl_t { 51struct _locale_impl_t {
52 struct _locale_cache_t *cache; 52 struct _locale_cache_t *cache;
53 char query[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)]; 53 char query[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)];
54 const char *part_name[_LC_LAST]; 54 const char *part_name[_LC_LAST];
55 _locale_part_t part_impl[_LC_LAST]; 55 _locale_part_t part_impl[_LC_LAST];
56}; 56};
57 57
58typedef const char *(*_locale_set_t)(const char * __restrict, 58typedef const char *(*_locale_set_t)(const char * __restrict,
59 struct _locale_impl_t * __restrict); 59 struct _locale_impl_t * __restrict);
60 60
61typedef struct { 
62 const char* name; 
63 int category; 
64 _locale_set_t setlocale; 
65} _locale_category_t; 
66 
67__BEGIN_DECLS 61__BEGIN_DECLS
68_locale_category_t *_find_category(int); 62_locale_set_t _find_category(int);
69const char *_get_locale_env(const char *); 63const char *_get_locale_env(const char *);
70struct _locale_impl_t **_current_locale(void); 64struct _locale_impl_t **_current_locale(void);
71char *__setlocale(int, const char *); 65char *__setlocale(int, const char *);
 66
 67const char *_generic_LC_ALL_setlocale(
 68 const char * __restrict, struct _locale_impl_t * __restrict);
 69const char *_dummy_LC_COLLATE_setlocale(
 70 const char * __restrict, struct _locale_impl_t * __restrict);
 71const char *_citrus_LC_CTYPE_setlocale(
 72 const char * __restrict, struct _locale_impl_t * __restrict);
 73const char *_citrus_LC_MONETARY_setlocale(
 74 const char * __restrict, struct _locale_impl_t * __restrict);
 75const char *_citrus_LC_NUMERIC_setlocale(
 76 const char * __restrict, struct _locale_impl_t * __restrict);
 77const char *_citrus_LC_TIME_setlocale(
 78 const char * __restrict, struct _locale_impl_t * __restrict);
 79const char *_citrus_LC_MESSAGES_setlocale(
 80 const char * __restrict, struct _locale_impl_t * __restrict);
72__END_DECLS 81__END_DECLS
73 82
74static __inline struct _locale_cache_t * 83static __inline struct _locale_cache_t *
75_current_cache(void) 84_current_cache(void)
76{ 85{
77 return (*_current_locale())->cache; 86 return (*_current_locale())->cache;
78} 87}
79 88
80extern struct _locale_impl_t _global_locale; 89extern struct _locale_impl_t _global_locale;
81extern size_t __mb_len_max_runtime; 90extern size_t __mb_len_max_runtime;
82 91
83#endif /*_SETLOCALE_LOCAL_H_*/ 92#endif /*_SETLOCALE_LOCAL_H_*/