]>
sourceware.org Git - glibc.git/blob - locale/lc-time.c
1 /* Define current locale data for LC_TIME category.
2 Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <bits/libc-lock.h>
26 #include "localeinfo.h"
28 _NL_CURRENT_DEFINE (LC_TIME
);
30 /* Some of the functions here must not be used while setlocale is called. */
31 __libc_lock_define (extern, __libc_setlocale_lock
)
34 static int era_initialized
;
35 static struct era_entry
**eras
;
36 static const void **eras_nf
;
37 static size_t num_eras
;
39 #define ERAS_NF(cnt, category) \
40 *(eras_nf + ERA_NAME_FORMAT_MEMBERS * (cnt) + (category))
42 static int alt_digits_initialized
;
43 static const char **alt_digits
;
46 static int walt_digits_initialized
;
47 static const wchar_t **walt_digits
;
51 _nl_postload_time (void)
53 /* Prepare lazy initialization of `era' and `alt_digits' array. */
55 alt_digits_initialized
= 0;
56 walt_digits_initialized
= 0;
65 if (era_initialized
== 0)
67 size_t new_num_eras
= _NL_CURRENT_WORD (LC_TIME
,
68 _NL_TIME_ERA_NUM_ENTRIES
);
70 if (new_num_eras
== 0)
85 if (num_eras
!= new_num_eras
)
88 new_num_eras
* sizeof (struct era_entry
*));
89 eras_nf
= realloc (eras_nf
,
90 new_num_eras
* sizeof (void *)
91 * ERA_NAME_FORMAT_MEMBERS
);
94 if (eras
== NULL
|| eras_nf
== NULL
)
102 const char *ptr
= _NL_CURRENT (LC_TIME
, _NL_TIME_ERA_ENTRIES
);
103 num_eras
= new_num_eras
;
105 for (cnt
= 0; cnt
< num_eras
; ++cnt
)
107 eras
[cnt
] = (struct era_entry
*) ptr
;
109 /* Skip numeric values. */
110 ptr
+= sizeof (struct era_entry
);
112 /* Set and skip era name. */
113 ERAS_NF (cnt
, ERA_M_NAME
) = (void *) ptr
;
114 ptr
= strchr (ptr
, '\0') + 1;
116 /* Set and skip era format. */
117 ERAS_NF (cnt
, ERA_M_FORMAT
) = (void *) ptr
;
118 ptr
= strchr (ptr
, '\0') + 1;
120 ptr
+= 3 - (((ptr
- (const char *) eras
[cnt
]) + 3) & 3);
122 /* Set and skip wide era name. */
123 ERAS_NF (cnt
, ERA_W_NAME
) = (void *) ptr
;
124 ptr
= (char *) (wcschr ((wchar_t *) ptr
, '\0') + 1);
126 /* Set and skip wide era format. */
127 ERAS_NF (cnt
, ERA_W_FORMAT
) = (void *) ptr
;
128 ptr
= (char *) (wcschr ((wchar_t *) ptr
, '\0') + 1);
139 _nl_get_era_entry (const struct tm
*tp
)
141 struct era_entry
*result
;
144 __libc_lock_lock (__libc_setlocale_lock
);
148 /* Now compare date with the available eras. */
149 for (cnt
= 0; cnt
< num_eras
; ++cnt
)
150 if ((eras
[cnt
]->start_date
[0] < tp
->tm_year
151 || (eras
[cnt
]->start_date
[0] == tp
->tm_year
152 && (eras
[cnt
]->start_date
[1] < tp
->tm_mon
153 || (eras
[cnt
]->start_date
[1] == tp
->tm_mon
154 && eras
[cnt
]->start_date
[2] <= tp
->tm_mday
))))
155 && (eras
[cnt
]->stop_date
[0] > tp
->tm_year
156 || (eras
[cnt
]->stop_date
[0] == tp
->tm_year
157 && (eras
[cnt
]->stop_date
[1] > tp
->tm_mon
158 || (eras
[cnt
]->stop_date
[1] == tp
->tm_mon
159 && eras
[cnt
]->stop_date
[2] >= tp
->tm_mday
)))))
162 result
= cnt
< num_eras
? eras
[cnt
] : NULL
;
164 __libc_lock_unlock (__libc_setlocale_lock
);
171 _nl_get_era_nf_entry (int cnt
, int category
)
175 __libc_lock_lock (__libc_setlocale_lock
);
182 result
= ERAS_NF (cnt
, category
);
184 __libc_lock_unlock (__libc_setlocale_lock
);
191 _nl_get_era_year_offset (int cnt
, int val
)
193 __libc_lock_lock (__libc_setlocale_lock
);
201 val
-= eras
[cnt
]->offset
;
204 val
> (eras
[cnt
]->stop_date
[0] - eras
[cnt
]->start_date
[0]))
208 __libc_lock_unlock (__libc_setlocale_lock
);
215 _nl_get_era_year_start (int cnt
)
219 __libc_lock_lock (__libc_setlocale_lock
);
223 result
= eras
[cnt
]->start_date
[0];
225 __libc_lock_unlock (__libc_setlocale_lock
);
232 _nl_get_alt_digit (unsigned int number
)
236 __libc_lock_lock (__libc_setlocale_lock
);
238 if (alt_digits_initialized
== 0)
240 alt_digits_initialized
= 1;
242 if (alt_digits
== NULL
)
243 alt_digits
= malloc (100 * sizeof (const char *));
245 if (alt_digits
!= NULL
)
247 const char *ptr
= _NL_CURRENT (LC_TIME
, ALT_DIGITS
);
250 if (alt_digits
!= NULL
)
251 for (cnt
= 0; cnt
< 100; ++cnt
)
253 alt_digits
[cnt
] = ptr
;
255 /* Skip digit format. */
256 ptr
= strchr (ptr
, '\0') + 1;
261 result
= alt_digits
!= NULL
&& number
< 100 ? alt_digits
[number
] : NULL
;
263 __libc_lock_unlock (__libc_setlocale_lock
);
270 _nl_get_walt_digit (unsigned int number
)
272 const wchar_t *result
;
274 __libc_lock_lock (__libc_setlocale_lock
);
276 if (walt_digits_initialized
== 0)
278 walt_digits_initialized
= 1;
280 if (walt_digits
== NULL
)
281 walt_digits
= malloc (100 * sizeof (const uint32_t *));
283 if (walt_digits
!= NULL
)
285 const wchar_t *ptr
= _NL_CURRENT_WSTR (LC_TIME
, _NL_WALT_DIGITS
);
288 for (cnt
= 0; cnt
< 100; ++cnt
)
290 walt_digits
[cnt
] = ptr
;
292 /* Skip digit format. */
293 ptr
= wcschr (ptr
, L
'\0') + 1;
298 result
= walt_digits
!= NULL
&& number
< 100 ? walt_digits
[number
] : NULL
;
300 __libc_lock_unlock (__libc_setlocale_lock
);
302 return (wchar_t *) result
;
This page took 0.054054 seconds and 5 git commands to generate.