Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/strftime.c @ 17646:0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
* lib/strftime.c (DO_NUMBER): Wrap multi-statement code block of
this macro in "do {...} while(0)" to prevent false use as a
single statement, e.g., in an un-braced "{}" else-block.
(DO_SIGNED_NUMBER, DO_TZ_OFFSET, DO_NUMBER_SPACEPAD): Likewise.
(strftime_case_): Remove 'else' after 'goto' - which was the
only non-fatal, un-braced use of one of the above macros.
Spotted by coverity (NESTING_INDENT_MISMATCH).
author | Bernhard Voelker <mail@bernhard-voelker.de> |
---|---|
date | Wed, 26 Mar 2014 02:45:58 +0100 |
parents | 344018b6e5d7 |
children | ab58d4870664 |
rev | line source |
---|---|
17587 | 1 /* Copyright (C) 1991-2001, 2003-2007, 2009-2014 Free Software Foundation, Inc. |
9 | 2 |
1058 | 3 NOTE: The canonical source of this file is maintained with the GNU C Library. |
4 Bugs can be reported to bug-glibc@prep.ai.mit.edu. | |
9 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify |
4422 | 7 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
8 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
9 (at your option) any later version. |
9 | 10 |
1058 | 11 This program is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4422 | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | |
782 | 15 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
9 | 18 |
604 | 19 #ifdef _LIBC |
794 | 20 # define HAVE_STRUCT_ERA_ENTRY 1 |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
21 # define HAVE_TM_GMTOFF 1 |
604 | 22 # define HAVE_TM_ZONE 1 |
813 | 23 # define HAVE_TZNAME 1 |
24 # define HAVE_TZSET 1 | |
604 | 25 # include "../locale/localeinfo.h" |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6932
diff
changeset
|
26 #else |
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6932
diff
changeset
|
27 # include <config.h> |
7455
8d41d3f68c28
Don't include <config.h> twice; this doesn't work in some cases,
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
28 # if FPRINTFTIME |
8d41d3f68c28
Don't include <config.h> twice; this doesn't work in some cases,
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
29 # include "fprintftime.h" |
11110 | 30 # else |
31 # include "strftime.h" | |
7455
8d41d3f68c28
Don't include <config.h> twice; this doesn't work in some cases,
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
32 # endif |
125 | 33 #endif |
34 | |
813 | 35 #include <ctype.h> |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7888
diff
changeset
|
36 #include <time.h> |
604 | 37 |
9626
def4f669ceac
Fix problem with getdate on mingw32 reported by Simon Josefsson
Paul Eggert <eggert@cs.ucla.edu>
parents:
9309
diff
changeset
|
38 #if HAVE_TZNAME && !HAVE_DECL_TZNAME |
801
da8cea3a8036
[HAVE_TZNAME]: Declare tzname.
Jim Meyering <jim@meyering.net>
parents:
797
diff
changeset
|
39 extern char *tzname[]; |
da8cea3a8036
[HAVE_TZNAME]: Declare tzname.
Jim Meyering <jim@meyering.net>
parents:
797
diff
changeset
|
40 #endif |
da8cea3a8036
[HAVE_TZNAME]: Declare tzname.
Jim Meyering <jim@meyering.net>
parents:
797
diff
changeset
|
41 |
16358 | 42 /* Do multibyte processing if multibyte encodings are supported, unless |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
43 multibyte sequences are safe in formats. Multibyte sequences are |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
44 safe if they cannot contain byte sequences that look like format |
11043
3dd9bde3c382
Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents:
11042
diff
changeset
|
45 conversion specifications. The multibyte encodings used by the |
3dd9bde3c382
Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents:
11042
diff
changeset
|
46 C library on the various platforms (UTF-8, GB2312, GBK, CP936, |
3dd9bde3c382
Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents:
11042
diff
changeset
|
47 GB18030, EUC-TW, BIG5, BIG5-HKSCS, CP950, EUC-JP, EUC-KR, CP949, |
3dd9bde3c382
Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents:
11042
diff
changeset
|
48 SHIFT_JIS, CP932, JOHAB) are safe for formats, because the byte '%' |
3dd9bde3c382
Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents:
11042
diff
changeset
|
49 cannot occur in a multibyte character except in the first byte. |
14177
c6bc5712a6a9
strftime: remove dependencies on multibyte modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
50 |
c6bc5712a6a9
strftime: remove dependencies on multibyte modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
51 The DEC-HANYU encoding used on OSF/1 is not safe for formats, but |
c6bc5712a6a9
strftime: remove dependencies on multibyte modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
52 this encoding has never been seen in real-life use, so we ignore |
c6bc5712a6a9
strftime: remove dependencies on multibyte modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
53 it. */ |
c6bc5712a6a9
strftime: remove dependencies on multibyte modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
54 #if !(defined __osf__ && 0) |
11043
3dd9bde3c382
Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents:
11042
diff
changeset
|
55 # define MULTIBYTE_IS_FORMAT_SAFE 1 |
3dd9bde3c382
Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents:
11042
diff
changeset
|
56 #endif |
3dd9bde3c382
Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents:
11042
diff
changeset
|
57 #define DO_MULTIBYTE (! MULTIBYTE_IS_FORMAT_SAFE) |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
58 |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
59 #if DO_MULTIBYTE |
10990
7e8a454e9758
strftime: avoid compilation failure on Solaris 2.6
Jim Meyering <meyering@redhat.com>
parents:
9626
diff
changeset
|
60 # include <wchar.h> |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
61 static const mbstate_t mbstate_zero; |
604 | 62 #endif |
63 | |
4693 | 64 #include <limits.h> |
5690
e44b4f85ad9b
Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5414
diff
changeset
|
65 #include <stdbool.h> |
4693 | 66 #include <stddef.h> |
67 #include <stdlib.h> | |
68 #include <string.h> | |
176 | 69 |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
70 #ifdef COMPILE_WIDE |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
71 # include <endian.h> |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
72 # define CHAR_T wchar_t |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
73 # define UCHAR_T unsigned int |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
74 # define L_(Str) L##Str |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
75 # define NLW(Sym) _NL_W##Sym |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
76 |
2845
d5bcf4bb7938
Merge in changes from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
2430
diff
changeset
|
77 # define MEMCPY(d, s, n) __wmemcpy (d, s, n) |
d5bcf4bb7938
Merge in changes from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
2430
diff
changeset
|
78 # define STRLEN(s) __wcslen (s) |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
79 |
1109 | 80 #else |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
81 # define CHAR_T char |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
82 # define UCHAR_T unsigned char |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
83 # define L_(Str) Str |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
84 # define NLW(Sym) Sym |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
85 |
4693 | 86 # define MEMCPY(d, s, n) memcpy (d, s, n) |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
87 # define STRLEN(s) strlen (s) |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
88 |
1109 | 89 #endif |
90 | |
5414
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
91 /* Shift A right by B bits portably, by dividing A by 2**B and |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
92 truncating towards minus infinity. A and B should be free of side |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
93 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
94 INT_BITS is the number of useful bits in an int. GNU code can |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
95 assume that INT_BITS is at least 32. |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
96 |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
97 ISO C99 says that A >> B is implementation-defined if A < 0. Some |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
98 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
99 right in the usual way when A < 0, so SHR falls back on division if |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
100 ordinary A >> B doesn't seem to be the usual signed shift. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
101 #define SHR(a, b) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
102 (-1 >> 1 == -1 \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
103 ? (a) >> (b) \ |
5414
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
104 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
105 |
5775
73ab05626d30
Propagate intprops.h comment fixes to mktime.c and strftime.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5714
diff
changeset
|
106 /* Bound on length of the string representing an integer type or expression T. |
5691
ec62790f0938
Factor int-properties macros into a single file, except for
Paul Eggert <eggert@cs.ucla.edu>
parents:
5690
diff
changeset
|
107 Subtract 1 for the sign bit if t is signed; log10 (2.0) < 146/485; |
ec62790f0938
Factor int-properties macros into a single file, except for
Paul Eggert <eggert@cs.ucla.edu>
parents:
5690
diff
changeset
|
108 add 1 for integer division truncation; add 1 more for a minus sign |
ec62790f0938
Factor int-properties macros into a single file, except for
Paul Eggert <eggert@cs.ucla.edu>
parents:
5690
diff
changeset
|
109 if needed. */ |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
110 #define INT_STRLEN_BOUND(t) \ |
5691
ec62790f0938
Factor int-properties macros into a single file, except for
Paul Eggert <eggert@cs.ucla.edu>
parents:
5690
diff
changeset
|
111 ((sizeof (t) * CHAR_BIT - 1) * 146 / 485 + 2) |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
112 |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
113 #define TM_YEAR_BASE 1900 |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
114 |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
115 #ifndef __isleap |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
116 /* Nonzero if YEAR is a leap year (every 4 years, |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
117 except every 100th isn't, and every 400th is). */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
118 # define __isleap(year) \ |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
119 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
120 #endif |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
121 |
672
d4a380613840
Update from GNU libc -- this adds back %z and %s
Jim Meyering <jim@meyering.net>
parents:
668
diff
changeset
|
122 |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
123 #ifdef _LIBC |
816 | 124 # define tzname __tzname |
125 # define tzset __tzset | |
4621
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
126 #endif |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
127 |
4621
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
128 #if !HAVE_TM_GMTOFF |
8146
b31580167c2b
New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
7897
diff
changeset
|
129 /* Portable standalone applications should supply a "time.h" that |
4621
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
130 declares a POSIX-compliant localtime_r, for the benefit of older |
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
131 implementations that lack localtime_r or have a nonstandard one. |
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
132 See the gnulib time_r module for one way to implement this. */ |
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
133 # undef __gmtime_r |
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
134 # undef __localtime_r |
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
135 # define __gmtime_r gmtime_r |
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
136 # define __localtime_r localtime_r |
3d28ad4e18e2
Add time_r module. Change timegm, mktime, and strftime to use localtime_r
Paul Eggert <eggert@cs.ucla.edu>
parents:
4558
diff
changeset
|
137 #endif |
9 | 138 |
139 | |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
140 #ifndef FPRINTFTIME |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
141 # define FPRINTFTIME 0 |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
142 #endif |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
143 |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
144 #if FPRINTFTIME |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
145 # define STREAM_OR_CHAR_T FILE |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
146 # define STRFTIME_ARG(x) /* empty */ |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
147 #else |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
148 # define STREAM_OR_CHAR_T CHAR_T |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
149 # define STRFTIME_ARG(x) x, |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
150 #endif |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
151 |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
152 #if FPRINTFTIME |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
153 # define memset_byte(P, Len, Byte) \ |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
154 do { size_t _i; for (_i = 0; _i < Len; _i++) fputc (Byte, P); } while (0) |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
155 # define memset_space(P, Len) memset_byte (P, Len, ' ') |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
156 # define memset_zero(P, Len) memset_byte (P, Len, '0') |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
157 #elif defined COMPILE_WIDE |
4693 | 158 # define memset_space(P, Len) (wmemset (P, L' ', Len), (P) += (Len)) |
159 # define memset_zero(P, Len) (wmemset (P, L'0', Len), (P) += (Len)) | |
813 | 160 #else |
4693 | 161 # define memset_space(P, Len) (memset (P, ' ', Len), (P) += (Len)) |
162 # define memset_zero(P, Len) (memset (P, '0', Len), (P) += (Len)) | |
813 | 163 #endif |
164 | |
7524
066fb9a1e386
* lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7455
diff
changeset
|
165 #if FPRINTFTIME |
066fb9a1e386
* lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7455
diff
changeset
|
166 # define advance(P, N) |
066fb9a1e386
* lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7455
diff
changeset
|
167 #else |
066fb9a1e386
* lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7455
diff
changeset
|
168 # define advance(P, N) ((P) += (N)) |
066fb9a1e386
* lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7455
diff
changeset
|
169 #endif |
066fb9a1e386
* lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7455
diff
changeset
|
170 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
171 #define add(n, f) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
172 do \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
173 { \ |
14443
fa909c29c50e
strftime: don't assume a byte count fits in 'int'
Paul Eggert <eggert@cs.ucla.edu>
parents:
14177
diff
changeset
|
174 size_t _n = (n); \ |
14445
e0be175bb753
strftime: fix a bug in yesterday's change
Jim Meyering <meyering@redhat.com>
parents:
14443
diff
changeset
|
175 size_t _w = (width < 0 ? 0 : width); \ |
e0be175bb753
strftime: fix a bug in yesterday's change
Jim Meyering <meyering@redhat.com>
parents:
14443
diff
changeset
|
176 size_t _incr = _n < _w ? _w : _n; \ |
14443
fa909c29c50e
strftime: don't assume a byte count fits in 'int'
Paul Eggert <eggert@cs.ucla.edu>
parents:
14177
diff
changeset
|
177 if (_incr >= maxsize - i) \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
178 return 0; \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
179 if (p) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
180 { \ |
14445
e0be175bb753
strftime: fix a bug in yesterday's change
Jim Meyering <meyering@redhat.com>
parents:
14443
diff
changeset
|
181 if (digits == 0 && _n < _w) \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
182 { \ |
14443
fa909c29c50e
strftime: don't assume a byte count fits in 'int'
Paul Eggert <eggert@cs.ucla.edu>
parents:
14177
diff
changeset
|
183 size_t _delta = width - _n; \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
184 if (pad == L_('0')) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
185 memset_zero (p, _delta); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
186 else \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
187 memset_space (p, _delta); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
188 } \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
189 f; \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
190 advance (p, _n); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
191 } \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
192 i += _incr; \ |
604 | 193 } while (0) |
813 | 194 |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
195 #if FPRINTFTIME |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
196 # define add1(C) add (1, fputc (C, p)) |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
197 #else |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
198 # define add1(C) add (1, *p = C) |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
199 #endif |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
200 |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
201 #if FPRINTFTIME |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
202 # define cpy(n, s) \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
203 add ((n), \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
204 do \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
205 { \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
206 if (to_lowcase) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
207 fwrite_lowcase (p, (s), _n); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
208 else if (to_uppcase) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
209 fwrite_uppcase (p, (s), _n); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
210 else \ |
17270
8b492e35b987
fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents:
17266
diff
changeset
|
211 { \ |
8b492e35b987
fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents:
17266
diff
changeset
|
212 /* Ignore the value of fwrite. The caller can determine whether \ |
17279
ba79ea8176b5
Fix misspellings of "occurred".
Paul Eggert <eggert@cs.ucla.edu>
parents:
17270
diff
changeset
|
213 an error occurred by inspecting ferror (P). All known fwrite \ |
17270
8b492e35b987
fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents:
17266
diff
changeset
|
214 implementations set the stream's error indicator when they \ |
8b492e35b987
fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents:
17266
diff
changeset
|
215 fail due to ENOMEM etc., even though C11 and POSIX.1-2008 do \ |
8b492e35b987
fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents:
17266
diff
changeset
|
216 not require this. */ \ |
8b492e35b987
fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents:
17266
diff
changeset
|
217 fwrite (s, _n, 1, p); \ |
8b492e35b987
fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents:
17266
diff
changeset
|
218 } \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
219 } \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
220 while (0) \ |
12206
5b7b0b8645f1
fprintftime: wrap macro code argument in "do {...} while(0)"
Jim Meyering <meyering@redhat.com>
parents:
12205
diff
changeset
|
221 ) |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
222 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
223 # define cpy(n, s) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
224 add ((n), \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
225 if (to_lowcase) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
226 memcpy_lowcase (p, (s), _n LOCALE_ARG); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
227 else if (to_uppcase) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
228 memcpy_uppcase (p, (s), _n LOCALE_ARG); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
229 else \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
230 MEMCPY ((void *) p, (void const *) (s), _n)) |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
231 #endif |
813 | 232 |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
233 #ifdef COMPILE_WIDE |
4297
30aa99ec2725
(widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents:
4296
diff
changeset
|
234 # ifndef USE_IN_EXTENDED_LOCALE_MODEL |
30aa99ec2725
(widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents:
4296
diff
changeset
|
235 # undef __mbsrtowcs_l |
30aa99ec2725
(widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents:
4296
diff
changeset
|
236 # define __mbsrtowcs_l(d, s, l, st, loc) __mbsrtowcs (d, s, l, st) |
30aa99ec2725
(widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents:
4296
diff
changeset
|
237 # endif |
30aa99ec2725
(widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents:
4296
diff
changeset
|
238 # define widen(os, ws, l) \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
239 { \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
240 mbstate_t __st; \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
241 const char *__s = os; \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
242 memset (&__st, '\0', sizeof (__st)); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
243 l = __mbsrtowcs_l (NULL, &__s, 0, &__st, loc); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
244 ws = (wchar_t *) alloca ((l + 1) * sizeof (wchar_t)); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
245 (void) __mbsrtowcs_l (ws, &__s, l, &__st, loc); \ |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
246 } |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
247 #endif |
813 | 248 |
249 | |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
250 #if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
251 /* We use this code also for the extended locale handling where the |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
252 function gets as an additional argument the locale which has to be |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
253 used. To access the values we have to redefine the _NL_CURRENT |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
254 macro. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
255 # define strftime __strftime_l |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
256 # define wcsftime __wcsftime_l |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
257 # undef _NL_CURRENT |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
258 # define _NL_CURRENT(category, item) \ |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
259 (current->values[_NL_ITEM_INDEX (item)].string) |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
260 # define LOCALE_ARG , loc |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
261 # define LOCALE_PARAM_PROTO , __locale_t loc |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
262 # define HELPER_LOCALE_ARG , current |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
263 #else |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
264 # define LOCALE_PARAM_PROTO |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
265 # define LOCALE_ARG |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
266 # ifdef _LIBC |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
267 # define HELPER_LOCALE_ARG , _NL_CURRENT_DATA (LC_TIME) |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
268 # else |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
269 # define HELPER_LOCALE_ARG |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
270 # endif |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
271 #endif |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
272 |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
273 #ifdef COMPILE_WIDE |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
274 # ifdef USE_IN_EXTENDED_LOCALE_MODEL |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
275 # define TOUPPER(Ch, L) __towupper_l (Ch, L) |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
276 # define TOLOWER(Ch, L) __towlower_l (Ch, L) |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
277 # else |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
278 # define TOUPPER(Ch, L) towupper (Ch) |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
279 # define TOLOWER(Ch, L) towlower (Ch) |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
280 # endif |
813 | 281 #else |
6932
6aeb4d6c28d9
* lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6893
diff
changeset
|
282 # ifdef USE_IN_EXTENDED_LOCALE_MODEL |
6aeb4d6c28d9
* lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6893
diff
changeset
|
283 # define TOUPPER(Ch, L) __toupper_l (Ch, L) |
6aeb4d6c28d9
* lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6893
diff
changeset
|
284 # define TOLOWER(Ch, L) __tolower_l (Ch, L) |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
285 # else |
6932
6aeb4d6c28d9
* lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6893
diff
changeset
|
286 # define TOUPPER(Ch, L) toupper (Ch) |
6aeb4d6c28d9
* lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6893
diff
changeset
|
287 # define TOLOWER(Ch, L) tolower (Ch) |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
288 # endif |
813 | 289 #endif |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
290 /* We don't use 'isdigit' here since the locale dependent |
819 | 291 interpretation is not what we want here. We only need to accept |
292 the arabic digits in the ASCII range. One day there is perhaps a | |
293 more reliable way to accept other sets of digits. */ | |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
294 #define ISDIGIT(Ch) ((unsigned int) (Ch) - L_('0') <= 9) |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
295 |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
296 #if FPRINTFTIME |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
297 static void |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
298 fwrite_lowcase (FILE *fp, const CHAR_T *src, size_t len) |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
299 { |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
300 while (len-- > 0) |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
301 { |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
302 fputc (TOLOWER ((UCHAR_T) *src, loc), fp); |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
303 ++src; |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
304 } |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
305 } |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
306 |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
307 static void |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
308 fwrite_uppcase (FILE *fp, const CHAR_T *src, size_t len) |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
309 { |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
310 while (len-- > 0) |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
311 { |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
312 fputc (TOUPPER ((UCHAR_T) *src, loc), fp); |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
313 ++src; |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
314 } |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
315 } |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
316 #else |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
317 static CHAR_T * |
4693 | 318 memcpy_lowcase (CHAR_T *dest, const CHAR_T *src, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
319 size_t len LOCALE_PARAM_PROTO) |
813 | 320 { |
321 while (len-- > 0) | |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
322 dest[len] = TOLOWER ((UCHAR_T) src[len], loc); |
813 | 323 return dest; |
324 } | |
9 | 325 |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
326 static CHAR_T * |
4693 | 327 memcpy_uppcase (CHAR_T *dest, const CHAR_T *src, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
328 size_t len LOCALE_PARAM_PROTO) |
816 | 329 { |
330 while (len-- > 0) | |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
331 dest[len] = TOUPPER ((UCHAR_T) src[len], loc); |
816 | 332 return dest; |
333 } | |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
334 #endif |
816 | 335 |
1058 | 336 |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
337 #if ! HAVE_TM_GMTOFF |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
338 /* Yield the difference between *A and *B, |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
339 measured in seconds, ignoring leap seconds. */ |
1058 | 340 # define tm_diff ftime_tm_diff |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
341 static int |
4759
27c6099e6a9f
* strftime.c (tm_diff) [! HAVE_TM_GMTOFF]: Fix arg typo in previous patch.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4693
diff
changeset
|
342 tm_diff (const struct tm *a, const struct tm *b) |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
343 { |
794 | 344 /* Compute intervening leap days correctly even if year is negative. |
345 Take care to avoid int overflow in leap day calculations, | |
346 but it's OK to assume that A and B are close to each other. */ | |
5414
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
347 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3); |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
348 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3); |
794 | 349 int a100 = a4 / 25 - (a4 % 25 < 0); |
350 int b100 = b4 / 25 - (b4 % 25 < 0); | |
5414
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
351 int a400 = SHR (a100, 2); |
1b5e702ecdd1
(SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents:
5402
diff
changeset
|
352 int b400 = SHR (b100, 2); |
794 | 353 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); |
354 int years = a->tm_year - b->tm_year; | |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
355 int days = (365 * years + intervening_leap_days |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
356 + (a->tm_yday - b->tm_yday)); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
357 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
358 + (a->tm_min - b->tm_min)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
359 + (a->tm_sec - b->tm_sec)); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
360 } |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
361 #endif /* ! HAVE_TM_GMTOFF */ |
9 | 362 |
604 | 363 |
9 | 364 |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
365 /* The number of days from the first day of the first ISO week of this |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
366 year to the year day YDAY with week day WDAY. ISO weeks start on |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
367 Monday; the first ISO week has the year's first Thursday. YDAY may |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
368 be as small as YDAY_MINIMUM. */ |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
369 #define ISO_WEEK_START_WDAY 1 /* Monday */ |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
370 #define ISO_WEEK1_WDAY 4 /* Thursday */ |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
371 #define YDAY_MINIMUM (-366) |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
372 #ifdef __GNUC__ |
1058 | 373 __inline__ |
604 | 374 #endif |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
375 static int |
4693 | 376 iso_week_days (int yday, int wday) |
604 | 377 { |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
378 /* Add enough to the first operand of % to make it nonnegative. */ |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
379 int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7; |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
380 return (yday |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
381 - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
382 + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
383 } |
9 | 384 |
385 | |
3261 | 386 /* When compiling this file, GNU applications can #define my_strftime |
387 to a symbol (typically nstrftime) to get an extended strftime with | |
388 extra arguments UT and NS. Emacs is a special case for now, but | |
389 this Emacs-specific code can be removed once Emacs's config.h | |
390 defines my_strftime. */ | |
391 #if defined emacs && !defined my_strftime | |
392 # define my_strftime nstrftime | |
393 #endif | |
394 | |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
395 #if FPRINTFTIME |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
396 # undef my_strftime |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
397 # define my_strftime fprintftime |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
398 #endif |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
399 |
3261 | 400 #ifdef my_strftime |
401 # define extra_args , ut, ns | |
4693 | 402 # define extra_args_spec , int ut, int ns |
1109 | 403 #else |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
404 # if defined COMPILE_WIDE |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
405 # define my_strftime wcsftime |
4297
30aa99ec2725
(widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents:
4296
diff
changeset
|
406 # define nl_get_alt_digit _nl_get_walt_digit |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
407 # else |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
408 # define my_strftime strftime |
4297
30aa99ec2725
(widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents:
4296
diff
changeset
|
409 # define nl_get_alt_digit _nl_get_alt_digit |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
410 # endif |
3261 | 411 # define extra_args |
412 # define extra_args_spec | |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
413 /* We don't have this information in general. */ |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
414 # define ut 0 |
3261 | 415 # define ns 0 |
1109 | 416 #endif |
417 | |
860
68da68da125e
(_strftime_copytm): New function, to work around Solaris 2.5 tzset bug.
Jim Meyering <jim@meyering.net>
parents:
829
diff
changeset
|
418 |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
419 /* Just like my_strftime, below, but with one more parameter, UPCASE, |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
420 to indicate that the result should be converted to upper case. */ |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
421 static size_t |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
422 strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
423 STRFTIME_ARG (size_t maxsize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
424 const CHAR_T *format, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
425 const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO) |
604 | 426 { |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
427 #if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
428 struct locale_data *const current = loc->__locales[LC_TIME]; |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
429 #endif |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
430 #if FPRINTFTIME |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
431 size_t maxsize = (size_t) -1; |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
432 #endif |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
433 |
604 | 434 int hour12 = tp->tm_hour; |
435 #ifdef _NL_CURRENT | |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
436 /* We cannot make the following values variables since we must delay |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
437 the evaluation of these values until really needed since some |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
438 expressions might not be valid in every situation. The 'struct tm' |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
439 might be generated by a strptime() call that initialized |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
440 only a few elements. Dereference the pointers only if the format |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
441 requires this. Then it is ok to fail if the pointers are invalid. */ |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
442 # define a_wkday \ |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
443 ((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(ABDAY_1) + tp->tm_wday)) |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
444 # define f_wkday \ |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
445 ((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(DAY_1) + tp->tm_wday)) |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
446 # define a_month \ |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
447 ((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(ABMON_1) + tp->tm_mon)) |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
448 # define f_month \ |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
449 ((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(MON_1) + tp->tm_mon)) |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
450 # define ampm \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
451 ((const CHAR_T *) _NL_CURRENT (LC_TIME, tp->tm_hour > 11 \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
452 ? NLW(PM_STR) : NLW(AM_STR))) |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
453 |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
454 # define aw_len STRLEN (a_wkday) |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
455 # define am_len STRLEN (a_month) |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
456 # define ap_len STRLEN (ampm) |
604 | 457 #endif |
458 const char *zone; | |
813 | 459 size_t i = 0; |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
460 STREAM_OR_CHAR_T *p = s; |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
461 const CHAR_T *f; |
2993
9231fb44e77d
(my_strftime): Do not invoke mbrlen with a
Jim Meyering <jim@meyering.net>
parents:
2923
diff
changeset
|
462 #if DO_MULTIBYTE && !defined COMPILE_WIDE |
9231fb44e77d
(my_strftime): Do not invoke mbrlen with a
Jim Meyering <jim@meyering.net>
parents:
2923
diff
changeset
|
463 const char *format_end = NULL; |
9231fb44e77d
(my_strftime): Do not invoke mbrlen with a
Jim Meyering <jim@meyering.net>
parents:
2923
diff
changeset
|
464 #endif |
582
3ec26150a8d6
(mon_week_ISO): New function to implement new %V format.
Jim Meyering <jim@meyering.net>
parents:
581
diff
changeset
|
465 |
5960
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
466 #if ! defined _LIBC && ! HAVE_RUN_TZSET_TEST |
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
467 /* Solaris 2.5.x and 2.6 tzset sometimes modify the storage returned |
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
468 by localtime. On such systems, we must either use the tzset and |
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
469 localtime wrappers to work around the bug (which sets |
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
470 HAVE_RUN_TZSET_TEST) or make a copy of the structure. */ |
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
471 struct tm copy = *tp; |
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
472 tp = © |
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
473 #endif |
2a0d593683dc
Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
474 |
813 | 475 zone = NULL; |
1058 | 476 #if HAVE_TM_ZONE |
477 /* The POSIX test suite assumes that setting | |
813 | 478 the environment variable TZ to a new value before calling strftime() |
479 will influence the result (the %Z format) even if the information in | |
1058 | 480 TP is computed with a totally different time zone. |
481 This is bogus: though POSIX allows bad behavior like this, | |
482 POSIX does not require it. Do the right thing instead. */ | |
604 | 483 zone = (const char *) tp->tm_zone; |
484 #endif | |
485 #if HAVE_TZNAME | |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
486 if (ut) |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
487 { |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
488 if (! (zone && *zone)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
489 zone = "GMT"; |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
490 } |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
491 else |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
492 { |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
493 /* POSIX.1 requires that local time zone information be used as |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
494 though strftime called tzset. */ |
813 | 495 # if HAVE_TZSET |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
496 tzset (); |
813 | 497 # endif |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
498 } |
604 | 499 #endif |
500 | |
501 if (hour12 > 12) | |
502 hour12 -= 12; | |
503 else | |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
504 if (hour12 == 0) |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
505 hour12 = 12; |
604 | 506 |
507 for (f = format; *f != '\0'; ++f) | |
582
3ec26150a8d6
(mon_week_ISO): New function to implement new %V format.
Jim Meyering <jim@meyering.net>
parents:
581
diff
changeset
|
508 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
509 int pad = 0; /* Padding for number ('-', '_', or 0). */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
510 int modifier; /* Field modifier ('E', 'O', or 0). */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
511 int digits = 0; /* Max digits for numeric format. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
512 int number_value; /* Numeric value to be printed. */ |
5690
e44b4f85ad9b
Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5414
diff
changeset
|
513 unsigned int u_number_value; /* (unsigned int) number_value. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
514 bool negative_number; /* The number is negative. */ |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
515 bool always_output_a_sign; /* +/- should always be output. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
516 int tz_colon_mask; /* Bitmask of where ':' should appear. */ |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
517 const CHAR_T *subfmt; |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
518 CHAR_T sign_char; |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
519 CHAR_T *bufp; |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
520 CHAR_T buf[1 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
521 + 2 /* for the two colons in a %::z or %:::z time zone */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
522 + (sizeof (int) < sizeof (time_t) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
523 ? INT_STRLEN_BOUND (time_t) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
524 : INT_STRLEN_BOUND (int))]; |
813 | 525 int width = -1; |
5690
e44b4f85ad9b
Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5414
diff
changeset
|
526 bool to_lowcase = false; |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
527 bool to_uppcase = upcase; |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
528 size_t colons; |
5690
e44b4f85ad9b
Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5414
diff
changeset
|
529 bool change_case = false; |
1109 | 530 int format_char; |
9 | 531 |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
532 #if DO_MULTIBYTE && !defined COMPILE_WIDE |
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
533 switch (*f) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
534 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
535 case L_('%'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
536 break; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
537 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
538 case L_('\b'): case L_('\t'): case L_('\n'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
539 case L_('\v'): case L_('\f'): case L_('\r'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
540 case L_(' '): case L_('!'): case L_('"'): case L_('#'): case L_('&'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
541 case L_('\''): case L_('('): case L_(')'): case L_('*'): case L_('+'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
542 case L_(','): case L_('-'): case L_('.'): case L_('/'): case L_('0'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
543 case L_('1'): case L_('2'): case L_('3'): case L_('4'): case L_('5'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
544 case L_('6'): case L_('7'): case L_('8'): case L_('9'): case L_(':'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
545 case L_(';'): case L_('<'): case L_('='): case L_('>'): case L_('?'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
546 case L_('A'): case L_('B'): case L_('C'): case L_('D'): case L_('E'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
547 case L_('F'): case L_('G'): case L_('H'): case L_('I'): case L_('J'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
548 case L_('K'): case L_('L'): case L_('M'): case L_('N'): case L_('O'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
549 case L_('P'): case L_('Q'): case L_('R'): case L_('S'): case L_('T'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
550 case L_('U'): case L_('V'): case L_('W'): case L_('X'): case L_('Y'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
551 case L_('Z'): case L_('['): case L_('\\'): case L_(']'): case L_('^'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
552 case L_('_'): case L_('a'): case L_('b'): case L_('c'): case L_('d'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
553 case L_('e'): case L_('f'): case L_('g'): case L_('h'): case L_('i'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
554 case L_('j'): case L_('k'): case L_('l'): case L_('m'): case L_('n'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
555 case L_('o'): case L_('p'): case L_('q'): case L_('r'): case L_('s'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
556 case L_('t'): case L_('u'): case L_('v'): case L_('w'): case L_('x'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
557 case L_('y'): case L_('z'): case L_('{'): case L_('|'): case L_('}'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
558 case L_('~'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
559 /* The C Standard requires these 98 characters (plus '%') to |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
560 be in the basic execution character set. None of these |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
561 characters can start a multibyte sequence, so they need |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
562 not be analyzed further. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
563 add1 (*f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
564 continue; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
565 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
566 default: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
567 /* Copy this multibyte sequence until we reach its end, find |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
568 an error, or come back to the initial shift state. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
569 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
570 mbstate_t mbstate = mbstate_zero; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
571 size_t len = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
572 size_t fsize; |
2993
9231fb44e77d
(my_strftime): Do not invoke mbrlen with a
Jim Meyering <jim@meyering.net>
parents:
2923
diff
changeset
|
573 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
574 if (! format_end) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
575 format_end = f + strlen (f) + 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
576 fsize = format_end - f; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
577 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
578 do |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
579 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
580 size_t bytes = mbrlen (f + len, fsize - len, &mbstate); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
581 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
582 if (bytes == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
583 break; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
584 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
585 if (bytes == (size_t) -2) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
586 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
587 len += strlen (f + len); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
588 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
589 } |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
590 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
591 if (bytes == (size_t) -1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
592 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
593 len++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
594 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
595 } |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
596 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
597 len += bytes; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
598 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
599 while (! mbsinit (&mbstate)); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
600 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
601 cpy (len, f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
602 f += len - 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
603 continue; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
604 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
605 } |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
606 |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
607 #else /* ! DO_MULTIBYTE */ |
9 | 608 |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
609 /* Either multibyte encodings are not supported, they are |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
610 safe for formats, so any non-'%' byte can be copied through, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
611 or this is the wide character version. */ |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
612 if (*f != L_('%')) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
613 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
614 add1 (*f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
615 continue; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
616 } |
9 | 617 |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
618 #endif /* ! DO_MULTIBYTE */ |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
619 |
829 | 620 /* Check for flags that can modify a format. */ |
813 | 621 while (1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
622 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
623 switch (*++f) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
624 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
625 /* This influences the number formats. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
626 case L_('_'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
627 case L_('-'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
628 case L_('0'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
629 pad = *f; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
630 continue; |
816 | 631 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
632 /* This changes textual output. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
633 case L_('^'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
634 to_uppcase = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
635 continue; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
636 case L_('#'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
637 change_case = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
638 continue; |
813 | 639 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
640 default: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
641 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
642 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
643 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
644 } |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
645 |
813 | 646 /* As a GNU extension we allow to specify the field width. */ |
819 | 647 if (ISDIGIT (*f)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
648 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
649 width = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
650 do |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
651 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
652 if (width > INT_MAX / 10 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
653 || (width == INT_MAX / 10 && *f - L_('0') > INT_MAX % 10)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
654 /* Avoid overflow. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
655 width = INT_MAX; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
656 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
657 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
658 width *= 10; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
659 width += *f - L_('0'); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
660 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
661 ++f; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
662 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
663 while (ISDIGIT (*f)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
664 } |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
665 |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
666 /* Check for modifiers. */ |
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
667 switch (*f) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
668 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
669 case L_('E'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
670 case L_('O'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
671 modifier = *f++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
672 break; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
673 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
674 default: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
675 modifier = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
676 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
677 } |
9 | 678 |
604 | 679 /* Now do the specified format. */ |
1109 | 680 format_char = *f; |
681 switch (format_char) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
682 { |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
683 #define DO_NUMBER(d, v) \ |
17646
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
684 do \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
685 { \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
686 digits = d; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
687 number_value = v; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
688 goto do_number; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
689 } \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
690 while (0) |
5690
e44b4f85ad9b
Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5414
diff
changeset
|
691 #define DO_SIGNED_NUMBER(d, negative, v) \ |
17646
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
692 do \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
693 { \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
694 digits = d; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
695 negative_number = negative; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
696 u_number_value = v; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
697 goto do_signed_number; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
698 } \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
699 while (0) |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
700 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
701 /* The mask is not what you might think. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
702 When the ordinal i'th bit is set, insert a colon |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
703 before the i'th digit of the time zone representation. */ |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
704 #define DO_TZ_OFFSET(d, negative, mask, v) \ |
17646
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
705 do \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
706 { \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
707 digits = d; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
708 negative_number = negative; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
709 tz_colon_mask = mask; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
710 u_number_value = v; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
711 goto do_tz_offset; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
712 } \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
713 while (0) |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
714 #define DO_NUMBER_SPACEPAD(d, v) \ |
17646
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
715 do \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
716 { \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
717 digits = d; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
718 number_value = v; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
719 goto do_number_spacepad; \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
720 } \ |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
721 while (0) |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
722 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
723 case L_('%'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
724 if (modifier != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
725 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
726 add1 (*f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
727 break; |
604 | 728 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
729 case L_('a'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
730 if (modifier != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
731 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
732 if (change_case) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
733 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
734 to_uppcase = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
735 to_lowcase = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
736 } |
6893 | 737 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
738 cpy (aw_len, a_wkday); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
739 break; |
1109 | 740 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
741 goto underlying_strftime; |
1109 | 742 #endif |
604 | 743 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
744 case 'A': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
745 if (modifier != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
746 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
747 if (change_case) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
748 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
749 to_uppcase = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
750 to_lowcase = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
751 } |
6893 | 752 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
753 cpy (STRLEN (f_wkday), f_wkday); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
754 break; |
1109 | 755 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
756 goto underlying_strftime; |
1109 | 757 #endif |
604 | 758 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
759 case L_('b'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
760 case L_('h'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
761 if (change_case) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
762 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
763 to_uppcase = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
764 to_lowcase = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
765 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
766 if (modifier != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
767 goto bad_format; |
6893 | 768 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
769 cpy (am_len, a_month); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
770 break; |
1109 | 771 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
772 goto underlying_strftime; |
1109 | 773 #endif |
604 | 774 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
775 case L_('B'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
776 if (modifier != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
777 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
778 if (change_case) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
779 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
780 to_uppcase = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
781 to_lowcase = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
782 } |
6893 | 783 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
784 cpy (STRLEN (f_month), f_month); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
785 break; |
1109 | 786 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
787 goto underlying_strftime; |
1109 | 788 #endif |
9 | 789 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
790 case L_('c'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
791 if (modifier == L_('O')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
792 goto bad_format; |
604 | 793 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
794 if (! (modifier == 'E' |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
795 && (*(subfmt = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
796 (const CHAR_T *) _NL_CURRENT (LC_TIME, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
797 NLW(ERA_D_T_FMT))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
798 != '\0'))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
799 subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_T_FMT)); |
604 | 800 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
801 goto underlying_strftime; |
604 | 802 #endif |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
803 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
804 subformat: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
805 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
806 size_t len = strftime_case_ (to_uppcase, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
807 NULL, STRFTIME_ARG ((size_t) -1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
808 subfmt, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
809 tp extra_args LOCALE_ARG); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
810 add (len, strftime_case_ (to_uppcase, p, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
811 STRFTIME_ARG (maxsize - i) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
812 subfmt, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
813 tp extra_args LOCALE_ARG)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
814 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
815 break; |
604 | 816 |
6893 | 817 #if !(defined _NL_CURRENT && HAVE_STRUCT_ERA_ENTRY) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
818 underlying_strftime: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
819 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
820 /* The relevant information is available only via the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
821 underlying strftime implementation, so use that. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
822 char ufmt[5]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
823 char *u = ufmt; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
824 char ubuf[1024]; /* enough for any single format in practice */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
825 size_t len; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
826 /* Make sure we're calling the actual underlying strftime. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
827 In some cases, config.h contains something like |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
828 "#define strftime rpl_strftime". */ |
2378
524f131fc113
(my_strftime): Make sure we call the system
Jim Meyering <jim@meyering.net>
parents:
2082
diff
changeset
|
829 # ifdef strftime |
524f131fc113
(my_strftime): Make sure we call the system
Jim Meyering <jim@meyering.net>
parents:
2082
diff
changeset
|
830 # undef strftime |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
831 size_t strftime (); |
2378
524f131fc113
(my_strftime): Make sure we call the system
Jim Meyering <jim@meyering.net>
parents:
2082
diff
changeset
|
832 # endif |
524f131fc113
(my_strftime): Make sure we call the system
Jim Meyering <jim@meyering.net>
parents:
2082
diff
changeset
|
833 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
834 /* The space helps distinguish strftime failure from empty |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
835 output. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
836 *u++ = ' '; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
837 *u++ = '%'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
838 if (modifier != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
839 *u++ = modifier; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
840 *u++ = format_char; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
841 *u = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
842 len = strftime (ubuf, sizeof ubuf, ufmt, tp); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
843 if (len != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
844 cpy (len - 1, ubuf + 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
845 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
846 break; |
1109 | 847 #endif |
848 | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
849 case L_('C'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
850 if (modifier == L_('O')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
851 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
852 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
853 { |
1109 | 854 #if HAVE_STRUCT_ERA_ENTRY |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
855 struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
856 if (era) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
857 { |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
858 # ifdef COMPILE_WIDE |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
859 size_t len = __wcslen (era->era_wname); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
860 cpy (len, era->era_wname); |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
861 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
862 size_t len = strlen (era->era_name); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
863 cpy (len, era->era_name); |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
864 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
865 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
866 } |
1109 | 867 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
868 goto underlying_strftime; |
1109 | 869 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
870 } |
1109 | 871 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
872 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
873 int century = tp->tm_year / 100 + TM_YEAR_BASE / 100; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
874 century -= tp->tm_year % 100 < 0 && 0 < century; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
875 DO_SIGNED_NUMBER (2, tp->tm_year < - TM_YEAR_BASE, century); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
876 } |
9 | 877 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
878 case L_('x'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
879 if (modifier == L_('O')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
880 goto bad_format; |
604 | 881 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
882 if (! (modifier == L_('E') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
883 && (*(subfmt = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
884 (const CHAR_T *)_NL_CURRENT (LC_TIME, NLW(ERA_D_FMT))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
885 != L_('\0')))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
886 subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_FMT)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
887 goto subformat; |
1109 | 888 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
889 goto underlying_strftime; |
604 | 890 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
891 case L_('D'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
892 if (modifier != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
893 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
894 subfmt = L_("%m/%d/%y"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
895 goto subformat; |
604 | 896 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
897 case L_('d'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
898 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
899 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
900 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
901 DO_NUMBER (2, tp->tm_mday); |
604 | 902 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
903 case L_('e'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
904 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
905 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
906 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
907 DO_NUMBER_SPACEPAD (2, tp->tm_mday); |
176 | 908 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
909 /* All numeric formats set DIGITS and NUMBER_VALUE (or U_NUMBER_VALUE) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
910 and then jump to one of these labels. */ |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
911 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
912 do_tz_offset: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
913 always_output_a_sign = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
914 goto do_number_body; |
604 | 915 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
916 do_number_spacepad: |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
917 /* Force '_' flag unless overridden by '0' or '-' flag. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
918 if (pad != L_('0') && pad != L_('-')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
919 pad = L_('_'); |
176 | 920 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
921 do_number: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
922 /* Format NUMBER_VALUE according to the MODIFIER flag. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
923 negative_number = number_value < 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
924 u_number_value = number_value; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
925 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
926 do_signed_number: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
927 always_output_a_sign = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
928 tz_colon_mask = 0; |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
929 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
930 do_number_body: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
931 /* Format U_NUMBER_VALUE according to the MODIFIER flag. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
932 NEGATIVE_NUMBER is nonzero if the original number was |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
933 negative; in this case it was converted directly to |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
934 unsigned int (i.e., modulo (UINT_MAX + 1)) without |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
935 negating it. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
936 if (modifier == L_('O') && !negative_number) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
937 { |
1109 | 938 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
939 /* Get the locale specific alternate representation of |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
940 the number. If none exist NULL is returned. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
941 const CHAR_T *cp = nl_get_alt_digit (u_number_value |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
942 HELPER_LOCALE_ARG); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
943 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
944 if (cp != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
945 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
946 size_t digitlen = STRLEN (cp); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
947 if (digitlen != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
948 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
949 cpy (digitlen, cp); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
950 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
951 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
952 } |
1109 | 953 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
954 goto underlying_strftime; |
1109 | 955 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
956 } |
5690
e44b4f85ad9b
Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5414
diff
changeset
|
957 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
958 bufp = buf + sizeof (buf) / sizeof (buf[0]); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
959 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
960 if (negative_number) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
961 u_number_value = - u_number_value; |
604 | 962 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
963 do |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
964 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
965 if (tz_colon_mask & 1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
966 *--bufp = ':'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
967 tz_colon_mask >>= 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
968 *--bufp = u_number_value % 10 + L_('0'); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
969 u_number_value /= 10; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
970 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
971 while (u_number_value != 0 || tz_colon_mask != 0); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
972 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
973 do_number_sign_and_padding: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
974 if (digits < width) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
975 digits = width; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
976 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
977 sign_char = (negative_number ? L_('-') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
978 : always_output_a_sign ? L_('+') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
979 : 0); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
980 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
981 if (pad == L_('-')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
982 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
983 if (sign_char) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
984 add1 (sign_char); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
985 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
986 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
987 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
988 int padding = digits - (buf + (sizeof (buf) / sizeof (buf[0])) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
989 - bufp) - !!sign_char; |
546
baaeb11e50e5
(add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents:
307
diff
changeset
|
990 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
991 if (padding > 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
992 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
993 if (pad == L_('_')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
994 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
995 if ((size_t) padding >= maxsize - i) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
996 return 0; |
4298 | 997 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
998 if (p) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
999 memset_space (p, padding); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1000 i += padding; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1001 width = width > padding ? width - padding : 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1002 if (sign_char) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1003 add1 (sign_char); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1004 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1005 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1006 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1007 if ((size_t) digits >= maxsize - i) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1008 return 0; |
4298 | 1009 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1010 if (sign_char) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1011 add1 (sign_char); |
4298 | 1012 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1013 if (p) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1014 memset_zero (p, padding); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1015 i += padding; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1016 width = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1017 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1018 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1019 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1020 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1021 if (sign_char) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1022 add1 (sign_char); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1023 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1024 } |
546
baaeb11e50e5
(add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents:
307
diff
changeset
|
1025 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1026 cpy (buf + sizeof (buf) / sizeof (buf[0]) - bufp, bufp); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1027 break; |
546
baaeb11e50e5
(add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents:
307
diff
changeset
|
1028 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1029 case L_('F'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1030 if (modifier != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1031 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1032 subfmt = L_("%Y-%m-%d"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1033 goto subformat; |
604 | 1034 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1035 case L_('H'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1036 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1037 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1038 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1039 DO_NUMBER (2, tp->tm_hour); |
546
baaeb11e50e5
(add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents:
307
diff
changeset
|
1040 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1041 case L_('I'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1042 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1043 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1044 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1045 DO_NUMBER (2, hour12); |
604 | 1046 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1047 case L_('k'): /* GNU extension. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1048 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1049 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1050 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1051 DO_NUMBER_SPACEPAD (2, tp->tm_hour); |
546
baaeb11e50e5
(add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents:
307
diff
changeset
|
1052 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1053 case L_('l'): /* GNU extension. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1054 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1055 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1056 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1057 DO_NUMBER_SPACEPAD (2, hour12); |
604 | 1058 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1059 case L_('j'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1060 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1061 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1062 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1063 DO_SIGNED_NUMBER (3, tp->tm_yday < -1, tp->tm_yday + 1U); |
546
baaeb11e50e5
(add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents:
307
diff
changeset
|
1064 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1065 case L_('M'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1066 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1067 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1068 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1069 DO_NUMBER (2, tp->tm_min); |
604 | 1070 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1071 case L_('m'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1072 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1073 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1074 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1075 DO_SIGNED_NUMBER (2, tp->tm_mon < -1, tp->tm_mon + 1U); |
604 | 1076 |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
1077 #ifndef _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1078 case L_('N'): /* GNU extension. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1079 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1080 goto bad_format; |
3261 | 1081 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1082 number_value = ns; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1083 if (width == -1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1084 width = 9; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1085 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1086 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1087 /* Take an explicit width less than 9 as a precision. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1088 int j; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1089 for (j = width; j < 9; j++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1090 number_value /= 10; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1091 } |
3261 | 1092 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1093 DO_NUMBER (width, number_value); |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
1094 #endif |
3261 | 1095 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1096 case L_('n'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1097 add1 (L_('\n')); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1098 break; |
604 | 1099 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1100 case L_('P'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1101 to_lowcase = true; |
6893 | 1102 #ifndef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1103 format_char = L_('p'); |
1109 | 1104 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1105 /* FALLTHROUGH */ |
813 | 1106 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1107 case L_('p'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1108 if (change_case) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1109 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1110 to_uppcase = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1111 to_lowcase = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1112 } |
6893 | 1113 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1114 cpy (ap_len, ampm); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1115 break; |
1109 | 1116 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1117 goto underlying_strftime; |
1109 | 1118 #endif |
9 | 1119 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1120 case L_('R'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1121 subfmt = L_("%H:%M"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1122 goto subformat; |
604 | 1123 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1124 case L_('r'): |
6893 | 1125 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1126 if (*(subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1127 NLW(T_FMT_AMPM))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1128 == L_('\0')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1129 subfmt = L_("%I:%M:%S %p"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1130 goto subformat; |
6893 | 1131 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1132 goto underlying_strftime; |
4558 | 1133 #endif |
604 | 1134 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1135 case L_('S'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1136 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1137 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1138 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1139 DO_NUMBER (2, tp->tm_sec); |
604 | 1140 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1141 case L_('s'): /* GNU extension. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1142 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1143 struct tm ltm; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1144 time_t t; |
726
8867c987f8cf
(strftime): Accommodate the broken C compiler
Jim Meyering <jim@meyering.net>
parents:
691
diff
changeset
|
1145 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1146 ltm = *tp; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1147 t = mktime (<m); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1148 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1149 /* Generate string value for T using time_t arithmetic; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1150 this works even if sizeof (long) < sizeof (time_t). */ |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1151 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1152 bufp = buf + sizeof (buf) / sizeof (buf[0]); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1153 negative_number = t < 0; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1154 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1155 do |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1156 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1157 int d = t % 10; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1158 t /= 10; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1159 *--bufp = (negative_number ? -d : d) + L_('0'); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1160 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1161 while (t != 0); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1162 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1163 digits = 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1164 always_output_a_sign = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1165 goto do_number_sign_and_padding; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1166 } |
672
d4a380613840
Update from GNU libc -- this adds back %z and %s
Jim Meyering <jim@meyering.net>
parents:
668
diff
changeset
|
1167 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1168 case L_('X'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1169 if (modifier == L_('O')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1170 goto bad_format; |
604 | 1171 #ifdef _NL_CURRENT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1172 if (! (modifier == L_('E') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1173 && (*(subfmt = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1174 (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(ERA_T_FMT))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1175 != L_('\0')))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1176 subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(T_FMT)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1177 goto subformat; |
1109 | 1178 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1179 goto underlying_strftime; |
604 | 1180 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1181 case L_('T'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1182 subfmt = L_("%H:%M:%S"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1183 goto subformat; |
604 | 1184 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1185 case L_('t'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1186 add1 (L_('\t')); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1187 break; |
604 | 1188 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1189 case L_('u'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1190 DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1191 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1192 case L_('U'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1193 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1194 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1195 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1196 DO_NUMBER (2, (tp->tm_yday - tp->tm_wday + 7) / 7); |
604 | 1197 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1198 case L_('V'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1199 case L_('g'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1200 case L_('G'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1201 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1202 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1203 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1204 /* YEAR is a leap year if and only if (tp->tm_year + TM_YEAR_BASE) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1205 is a leap year, except that YEAR and YEAR - 1 both work |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1206 correctly even when (tp->tm_year + TM_YEAR_BASE) would |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1207 overflow. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1208 int year = (tp->tm_year |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1209 + (tp->tm_year < 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1210 ? TM_YEAR_BASE % 400 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1211 : TM_YEAR_BASE % 400 - 400)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1212 int year_adjust = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1213 int days = iso_week_days (tp->tm_yday, tp->tm_wday); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1214 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1215 if (days < 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1216 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1217 /* This ISO week belongs to the previous year. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1218 year_adjust = -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1219 days = iso_week_days (tp->tm_yday + (365 + __isleap (year - 1)), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1220 tp->tm_wday); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1221 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1222 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1223 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1224 int d = iso_week_days (tp->tm_yday - (365 + __isleap (year)), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1225 tp->tm_wday); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1226 if (0 <= d) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1227 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1228 /* This ISO week belongs to the next year. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1229 year_adjust = 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1230 days = d; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1231 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1232 } |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1233 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1234 switch (*f) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1235 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1236 case L_('g'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1237 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1238 int yy = (tp->tm_year % 100 + year_adjust) % 100; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1239 DO_NUMBER (2, (0 <= yy |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1240 ? yy |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1241 : tp->tm_year < -TM_YEAR_BASE - year_adjust |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1242 ? -yy |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1243 : yy + 100)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1244 } |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1245 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1246 case L_('G'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1247 DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE - year_adjust, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1248 (tp->tm_year + (unsigned int) TM_YEAR_BASE |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1249 + year_adjust)); |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1250 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1251 default: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1252 DO_NUMBER (2, days / 7 + 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1253 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1254 } |
604 | 1255 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1256 case L_('W'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1257 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1258 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1259 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1260 DO_NUMBER (2, (tp->tm_yday - (tp->tm_wday - 1 + 7) % 7 + 7) / 7); |
604 | 1261 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1262 case L_('w'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1263 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1264 goto bad_format; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1265 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1266 DO_NUMBER (1, tp->tm_wday); |
604 | 1267 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1268 case L_('Y'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1269 if (modifier == 'E') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1270 { |
1109 | 1271 #if HAVE_STRUCT_ERA_ENTRY |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1272 struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1273 if (era) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1274 { |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
1275 # ifdef COMPILE_WIDE |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1276 subfmt = era->era_wformat; |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
1277 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1278 subfmt = era->era_format; |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
1279 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1280 goto subformat; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1281 } |
1109 | 1282 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1283 goto underlying_strftime; |
1109 | 1284 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1285 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1286 if (modifier == L_('O')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1287 goto bad_format; |
17646
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
1288 |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
1289 DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE, |
0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents:
17587
diff
changeset
|
1290 tp->tm_year + (unsigned int) TM_YEAR_BASE); |
604 | 1291 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1292 case L_('y'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1293 if (modifier == L_('E')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1294 { |
1109 | 1295 #if HAVE_STRUCT_ERA_ENTRY |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1296 struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1297 if (era) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1298 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1299 int delta = tp->tm_year - era->start_date[0]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1300 DO_NUMBER (1, (era->offset |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1301 + delta * era->absolute_direction)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1302 } |
1109 | 1303 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1304 goto underlying_strftime; |
1109 | 1305 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1306 } |
5690
e44b4f85ad9b
Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5414
diff
changeset
|
1307 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1308 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1309 int yy = tp->tm_year % 100; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1310 if (yy < 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1311 yy = tp->tm_year < - TM_YEAR_BASE ? -yy : yy + 100; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1312 DO_NUMBER (2, yy); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1313 } |
604 | 1314 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1315 case L_('Z'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1316 if (change_case) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1317 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1318 to_uppcase = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1319 to_lowcase = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1320 } |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1321 |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1322 #if HAVE_TZNAME |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1323 /* The tzset() call might have changed the value. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1324 if (!(zone && *zone) && tp->tm_isdst >= 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1325 zone = tzname[tp->tm_isdst != 0]; |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1326 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1327 if (! zone) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1328 zone = ""; |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1329 |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
1330 #ifdef COMPILE_WIDE |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1331 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1332 /* The zone string is always given in multibyte form. We have |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1333 to transform it first. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1334 wchar_t *wczone; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1335 size_t len; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1336 widen (zone, wczone, len); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1337 cpy (len, wczone); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1338 } |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
1339 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1340 cpy (strlen (zone), zone); |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
1341 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1342 break; |
604 | 1343 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1344 case L_(':'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1345 /* :, ::, and ::: are valid only just before 'z'. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1346 :::: etc. are rejected later. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1347 for (colons = 1; f[colons] == L_(':'); colons++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1348 continue; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1349 if (f[colons] != L_('z')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1350 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1351 f += colons; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1352 goto do_z_conversion; |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1353 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1354 case L_('z'): |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1355 colons = 0; |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1356 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1357 do_z_conversion: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1358 if (tp->tm_isdst < 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1359 break; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1360 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1361 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1362 int diff; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1363 int hour_diff; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1364 int min_diff; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1365 int sec_diff; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1366 #if HAVE_TM_GMTOFF |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1367 diff = tp->tm_gmtoff; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1368 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1369 if (ut) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1370 diff = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1371 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1372 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1373 struct tm gtm; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1374 struct tm ltm; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1375 time_t lt; |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1376 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1377 ltm = *tp; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1378 lt = mktime (<m); |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1379 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1380 if (lt == (time_t) -1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1381 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1382 /* mktime returns -1 for errors, but -1 is also a |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1383 valid time_t value. Check whether an error really |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1384 occurred. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1385 struct tm tm; |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1386 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1387 if (! __localtime_r (<, &tm) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1388 || ((ltm.tm_sec ^ tm.tm_sec) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1389 | (ltm.tm_min ^ tm.tm_min) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1390 | (ltm.tm_hour ^ tm.tm_hour) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1391 | (ltm.tm_mday ^ tm.tm_mday) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1392 | (ltm.tm_mon ^ tm.tm_mon) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1393 | (ltm.tm_year ^ tm.tm_year))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1394 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1395 } |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1396 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1397 if (! __gmtime_r (<, >m)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1398 break; |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1399 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1400 diff = tm_diff (<m, >m); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1401 } |
691
6813ffe12e6a
(strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents:
687
diff
changeset
|
1402 #endif |
672
d4a380613840
Update from GNU libc -- this adds back %z and %s
Jim Meyering <jim@meyering.net>
parents:
668
diff
changeset
|
1403 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1404 hour_diff = diff / 60 / 60; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1405 min_diff = diff / 60 % 60; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1406 sec_diff = diff % 60; |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1407 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1408 switch (colons) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1409 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1410 case 0: /* +hhmm */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1411 DO_TZ_OFFSET (5, diff < 0, 0, hour_diff * 100 + min_diff); |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1412 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1413 case 1: tz_hh_mm: /* +hh:mm */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1414 DO_TZ_OFFSET (6, diff < 0, 04, hour_diff * 100 + min_diff); |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1415 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1416 case 2: tz_hh_mm_ss: /* +hh:mm:ss */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1417 DO_TZ_OFFSET (9, diff < 0, 024, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1418 hour_diff * 10000 + min_diff * 100 + sec_diff); |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1419 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1420 case 3: /* +hh if possible, else +hh:mm, else +hh:mm:ss */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1421 if (sec_diff != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1422 goto tz_hh_mm_ss; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1423 if (min_diff != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1424 goto tz_hh_mm; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1425 DO_TZ_OFFSET (3, diff < 0, 0, hour_diff); |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1426 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1427 default: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1428 goto bad_format; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1429 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1430 } |
672
d4a380613840
Update from GNU libc -- this adds back %z and %s
Jim Meyering <jim@meyering.net>
parents:
668
diff
changeset
|
1431 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1432 case L_('\0'): /* GNU extension: % at end of format. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1433 --f; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1434 /* Fall through. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1435 default: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1436 /* Unknown format; output the format, including the '%', |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1437 since this is most likely the right thing to do if a |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1438 multibyte string has been misparsed. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1439 bad_format: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1440 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1441 int flen; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1442 for (flen = 1; f[1 - flen] != L_('%'); flen++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1443 continue; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1444 cpy (flen, &f[1 - flen]); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1445 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1446 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1447 } |
9 | 1448 } |
604 | 1449 |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1450 #if ! FPRINTFTIME |
1775
96099c7ba283
Update from master source in libc, removing %f.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
1451 if (p && maxsize != 0) |
2082
35c2c4e86de2
Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents:
2060
diff
changeset
|
1452 *p = L_('\0'); |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1453 #endif |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1454 |
604 | 1455 return i; |
9 | 1456 } |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1457 |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1458 /* Write information from TP into S according to the format |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1459 string FORMAT, writing no more that MAXSIZE characters |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1460 (including the terminating '\0') and returning number of |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1461 characters written. If S is NULL, nothing will be written |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1462 anywhere, so to determine how many characters would be |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1463 written, use NULL for S and (size_t) -1 for MAXSIZE. */ |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1464 size_t |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1465 my_strftime (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1466 const CHAR_T *format, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1467 const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO) |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1468 { |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1469 return strftime_case_ (false, s, STRFTIME_ARG (maxsize) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1470 format, tp extra_args LOCALE_ARG); |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1471 } |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1472 |
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1473 #if defined _LIBC && ! FPRINTFTIME |
4296
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
1474 libc_hidden_def (my_strftime) |
2da9db9c7ef8
(my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents:
3670
diff
changeset
|
1475 #endif |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1476 |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1477 |
6273
52428341346b
* strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents:
6062
diff
changeset
|
1478 #if defined emacs && ! FPRINTFTIME |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1479 /* For Emacs we have a separate interface which corresponds to the normal |
3261 | 1480 strftime function plus the ut argument, but without the ns argument. */ |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1481 size_t |
4693 | 1482 emacs_strftimeu (char *s, size_t maxsize, const char *format, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12257
diff
changeset
|
1483 const struct tm *tp, int ut) |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1484 { |
3261 | 1485 return my_strftime (s, maxsize, format, tp, ut, 0); |
1535
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1486 } |
72809df6189a
Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents:
1532
diff
changeset
|
1487 #endif |