annotate lib/strftime.c @ 18069:1c6c8e9218c9

time_rz: port better to MinGW Don't change tzname, as this makes MinGW dump core (Bug#21020). Instead, store the tzname copy in the struct tm_zone object. Problem reported by Eli Zaretskii in: http://bugs.gnu.org/21020#48 * lib/strftime.c [!_LIBC]: * lib/time_rz.c: Include time-internal.h. * lib/strftime.c (strftime_case_) [!HAVE_TM_ZONE]: Infer the zone name from *TZ rather than from TZNAME, doable because *TZ now has a tzname_copy member. * lib/time-internal.h: New file, with contents taken from lib/time_rz.c. It's separate because strftime.c now accesses struct tm_zone members. (struct tm_zone) [HAVE_TZNAME && !HAVE_TM_ZONE]: New member tzname_copy. * lib/time_rz.c (struct tm_zone): Move to time-internal.h. (tzalloc) [HAVE_TZNAME && !HAVE_TM_ZONE]: Initialize tzname_copy member. (save_abbr) [HAVE_TZNAME && !HAVE_TM_ZONE]: Save abbreviation in tzname_copy member. (revert_tz) [HAVE_TZNAME]: Remove no-longer-needed tzname saving. (restore_tzname): Remove; no longer needed. All calls removed. * modules/time_rz (Files): Add lib/time-internal.h.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 27 Jul 2015 16:41:17 -0700
parents 0295f80643fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17646
diff changeset
1 /* Copyright (C) 1991-2001, 2003-2007, 2009-2015 Free Software Foundation, Inc.
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
2
1058
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
3 NOTE: The canonical source of this file is maintained with the GNU C Library.
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
4 Bugs can be reported to bug-glibc@prep.ai.mit.edu.
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
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
d82316ffe803 Switch from LGPL to GPL.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4318
diff changeset
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
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
10
1058
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
11 This program is distributed in the hope that it will be useful,
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
4422
d82316ffe803 Switch from LGPL to GPL.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4318
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d82316ffe803 Switch from LGPL to GPL.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4318
diff changeset
14 GNU General Public License for more details.
782
70c419102365 Fix copyright.
Jim Meyering <jim@meyering.net>
parents: 726
diff changeset
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
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
18
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
19 #ifdef _LIBC
794
8d2567244c18 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 782
diff changeset
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
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
22 # define HAVE_TM_ZONE 1
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
23 # define HAVE_TZNAME 1
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
24 # define HAVE_TZSET 1
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
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
23f0d14f8cdc avoid misc. warnings
Jim Meyering <meyering@redhat.com>
parents: 11043
diff changeset
30 # else
23f0d14f8cdc avoid misc. warnings
Jim Meyering <meyering@redhat.com>
parents: 11043
diff changeset
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
18069
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
33 # include "time-internal.h"
125
539738c0b6c2 merge with 1.8.1d
Jim Meyering <jim@meyering.net>
parents: 101
diff changeset
34 #endif
539738c0b6c2 merge with 1.8.1d
Jim Meyering <jim@meyering.net>
parents: 101
diff changeset
35
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
36 #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
37 #include <time.h>
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
38
9626
def4f669ceac Fix problem with getdate on mingw32 reported by Simon Josefsson
Paul Eggert <eggert@cs.ucla.edu>
parents: 9309
diff changeset
39 #if HAVE_TZNAME && !HAVE_DECL_TZNAME
801
da8cea3a8036 [HAVE_TZNAME]: Declare tzname.
Jim Meyering <jim@meyering.net>
parents: 797
diff changeset
40 extern char *tzname[];
da8cea3a8036 [HAVE_TZNAME]: Declare tzname.
Jim Meyering <jim@meyering.net>
parents: 797
diff changeset
41 #endif
da8cea3a8036 [HAVE_TZNAME]: Declare tzname.
Jim Meyering <jim@meyering.net>
parents: 797
diff changeset
42
16358
a712776b11ce maint: spelling fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 16235
diff changeset
43 /* 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51
c6bc5712a6a9 strftime: remove dependencies on multibyte modules
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
52 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
53 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
54 it. */
c6bc5712a6a9 strftime: remove dependencies on multibyte modules
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
55 #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
56 # 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
57 #endif
3dd9bde3c382 Revisit the condition when to use multibyte parsing in strftime.
Bruno Haible <bruno@clisp.org>
parents: 11042
diff changeset
58 #define DO_MULTIBYTE (! MULTIBYTE_IS_FORMAT_SAFE)
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
59
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
60 #if DO_MULTIBYTE
10990
7e8a454e9758 strftime: avoid compilation failure on Solaris 2.6
Jim Meyering <meyering@redhat.com>
parents: 9626
diff changeset
61 # include <wchar.h>
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
62 static const mbstate_t mbstate_zero;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
63 #endif
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
64
4693
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
65 #include <limits.h>
5690
e44b4f85ad9b Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
66 #include <stdbool.h>
4693
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
67 #include <stddef.h>
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
68 #include <stdlib.h>
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
69 #include <string.h>
176
Jim Meyering <jim@meyering.net>
parents: 125
diff changeset
70
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
71 #ifdef COMPILE_WIDE
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
72 # include <endian.h>
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
73 # define CHAR_T wchar_t
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
74 # define UCHAR_T unsigned int
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
75 # define L_(Str) L##Str
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
76 # define NLW(Sym) _NL_W##Sym
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
77
2845
d5bcf4bb7938 Merge in changes from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 2430
diff changeset
78 # 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
79 # define STRLEN(s) __wcslen (s)
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
80
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
81 #else
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
82 # define CHAR_T char
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
83 # define UCHAR_T unsigned char
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
84 # define L_(Str) Str
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
85 # define NLW(Sym) Sym
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
86
4693
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
87 # 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
88 # define STRLEN(s) strlen (s)
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
89
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
90 #endif
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
91
5414
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5402
diff changeset
92 /* 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
93 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
94 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
95 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
96 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
97
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5402
diff changeset
98 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
99 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
100 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
101 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
102 #define SHR(a, b) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
103 (-1 >> 1 == -1 \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
104 ? (a) >> (b) \
5414
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5402
diff changeset
105 : (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
106
5775
73ab05626d30 Propagate intprops.h comment fixes to mktime.c and strftime.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5714
diff changeset
107 /* 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
108 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
109 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
110 if needed. */
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
111 #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
112 ((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
113
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
114 #define TM_YEAR_BASE 1900
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
115
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
116 #ifndef __isleap
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
117 /* 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
118 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
119 # define __isleap(year) \
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
120 ((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
121 #endif
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
122
672
d4a380613840 Update from GNU libc -- this adds back %z and %s
Jim Meyering <jim@meyering.net>
parents: 668
diff changeset
123
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
124 #ifdef _LIBC
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
125 # define mktime_z(tz, tm) mktime (tm)
816
ef7796f30b31 another new version ...
Jim Meyering <jim@meyering.net>
parents: 813
diff changeset
126 # define tzname __tzname
ef7796f30b31 another new version ...
Jim Meyering <jim@meyering.net>
parents: 813
diff changeset
127 # 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
128 #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
129
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
130 #ifndef FPRINTFTIME
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
131 # define FPRINTFTIME 0
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
132 #endif
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
133
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
134 #if FPRINTFTIME
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
135 # 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
136 # 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
137 #else
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
138 # 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
139 # 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
140 #endif
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
141
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
142 #if FPRINTFTIME
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
143 # 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
144 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
145 # 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
146 # 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
147 #elif defined COMPILE_WIDE
4693
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
148 # define memset_space(P, Len) (wmemset (P, L' ', Len), (P) += (Len))
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
149 # define memset_zero(P, Len) (wmemset (P, L'0', Len), (P) += (Len))
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
150 #else
4693
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
151 # define memset_space(P, Len) (memset (P, ' ', Len), (P) += (Len))
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
152 # define memset_zero(P, Len) (memset (P, '0', Len), (P) += (Len))
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
153 #endif
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
154
7524
066fb9a1e386 * lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7455
diff changeset
155 #if FPRINTFTIME
066fb9a1e386 * lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7455
diff changeset
156 # define advance(P, N)
066fb9a1e386 * lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7455
diff changeset
157 #else
066fb9a1e386 * lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7455
diff changeset
158 # define advance(P, N) ((P) += (N))
066fb9a1e386 * lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7455
diff changeset
159 #endif
066fb9a1e386 * lib/strftime.c (advance): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7455
diff changeset
160
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
161 #define add(n, f) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
162 do \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
163 { \
14443
fa909c29c50e strftime: don't assume a byte count fits in 'int'
Paul Eggert <eggert@cs.ucla.edu>
parents: 14177
diff changeset
164 size_t _n = (n); \
14445
e0be175bb753 strftime: fix a bug in yesterday's change
Jim Meyering <meyering@redhat.com>
parents: 14443
diff changeset
165 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
166 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
167 if (_incr >= maxsize - i) \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
168 return 0; \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
169 if (p) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
170 { \
14445
e0be175bb753 strftime: fix a bug in yesterday's change
Jim Meyering <meyering@redhat.com>
parents: 14443
diff changeset
171 if (digits == 0 && _n < _w) \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
172 { \
14443
fa909c29c50e strftime: don't assume a byte count fits in 'int'
Paul Eggert <eggert@cs.ucla.edu>
parents: 14177
diff changeset
173 size_t _delta = width - _n; \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
174 if (pad == L_('0')) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
175 memset_zero (p, _delta); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
176 else \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
177 memset_space (p, _delta); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
178 } \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
179 f; \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
180 advance (p, _n); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
181 } \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
182 i += _incr; \
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
183 } while (0)
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
184
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
185 #if FPRINTFTIME
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
186 # 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
187 #else
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
188 # 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
189 #endif
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
190
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
191 #if FPRINTFTIME
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
192 # define cpy(n, s) \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
193 add ((n), \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
194 do \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
195 { \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
196 if (to_lowcase) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
197 fwrite_lowcase (p, (s), _n); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
198 else if (to_uppcase) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
199 fwrite_uppcase (p, (s), _n); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
200 else \
17270
8b492e35b987 fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents: 17266
diff changeset
201 { \
8b492e35b987 fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents: 17266
diff changeset
202 /* 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
203 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
204 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
205 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
206 not require this. */ \
8b492e35b987 fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents: 17266
diff changeset
207 fwrite (s, _n, 1, p); \
8b492e35b987 fprintftime: bring back and reword fwrite comment
Paul Eggert <eggert@cs.ucla.edu>
parents: 17266
diff changeset
208 } \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
209 } \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
210 while (0) \
12206
5b7b0b8645f1 fprintftime: wrap macro code argument in "do {...} while(0)"
Jim Meyering <meyering@redhat.com>
parents: 12205
diff changeset
211 )
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
212 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
213 # define cpy(n, s) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
214 add ((n), \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
215 if (to_lowcase) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
216 memcpy_lowcase (p, (s), _n LOCALE_ARG); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
217 else if (to_uppcase) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
218 memcpy_uppcase (p, (s), _n LOCALE_ARG); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
219 else \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
220 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
221 #endif
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
222
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
223 #ifdef COMPILE_WIDE
4297
30aa99ec2725 (widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents: 4296
diff changeset
224 # ifndef USE_IN_EXTENDED_LOCALE_MODEL
30aa99ec2725 (widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents: 4296
diff changeset
225 # undef __mbsrtowcs_l
30aa99ec2725 (widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents: 4296
diff changeset
226 # 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
227 # endif
30aa99ec2725 (widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents: 4296
diff changeset
228 # define widen(os, ws, l) \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
229 { \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
230 mbstate_t __st; \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
231 const char *__s = os; \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
232 memset (&__st, '\0', sizeof (__st)); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
233 l = __mbsrtowcs_l (NULL, &__s, 0, &__st, loc); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
234 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
235 (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
236 }
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
237 #endif
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
238
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
239
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
240 #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
241 /* 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
242 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
243 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
244 macro. */
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
245 # define strftime __strftime_l
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
246 # define wcsftime __wcsftime_l
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
247 # undef _NL_CURRENT
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
248 # define _NL_CURRENT(category, item) \
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
249 (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
250 # define LOCALE_ARG , loc
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
251 # 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
252 # define HELPER_LOCALE_ARG , current
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
253 #else
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
254 # define LOCALE_PARAM_PROTO
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
255 # define LOCALE_ARG
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
256 # ifdef _LIBC
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
257 # 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
258 # else
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
259 # define HELPER_LOCALE_ARG
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
260 # endif
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
261 #endif
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
262
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
263 #ifdef COMPILE_WIDE
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
264 # 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
265 # 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
266 # 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
267 # else
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
268 # 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
269 # 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
270 # endif
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
271 #else
6932
6aeb4d6c28d9 * lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6893
diff changeset
272 # ifdef USE_IN_EXTENDED_LOCALE_MODEL
6aeb4d6c28d9 * lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6893
diff changeset
273 # define TOUPPER(Ch, L) __toupper_l (Ch, L)
6aeb4d6c28d9 * lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6893
diff changeset
274 # 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
275 # else
6932
6aeb4d6c28d9 * lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6893
diff changeset
276 # define TOUPPER(Ch, L) toupper (Ch)
6aeb4d6c28d9 * lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6893
diff changeset
277 # define TOLOWER(Ch, L) tolower (Ch)
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
278 # endif
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
279 #endif
16235
18a38c9615f0 In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
280 /* We don't use 'isdigit' here since the locale dependent
819
2e3ead41ade2 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 817
diff changeset
281 interpretation is not what we want here. We only need to accept
2e3ead41ade2 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 817
diff changeset
282 the arabic digits in the ASCII range. One day there is perhaps a
2e3ead41ade2 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 817
diff changeset
283 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
284 #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
285
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
286 #if FPRINTFTIME
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
287 static void
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
288 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
289 {
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
290 while (len-- > 0)
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
291 {
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
292 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
293 ++src;
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
294 }
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
295 }
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
296
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_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
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 (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
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 #else
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
307 static CHAR_T *
4693
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
308 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
309 size_t len LOCALE_PARAM_PROTO)
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
310 {
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
311 while (len-- > 0)
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
312 dest[len] = TOLOWER ((UCHAR_T) src[len], loc);
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
313 return dest;
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
314 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
315
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
316 static CHAR_T *
4693
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
317 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
318 size_t len LOCALE_PARAM_PROTO)
816
ef7796f30b31 another new version ...
Jim Meyering <jim@meyering.net>
parents: 813
diff changeset
319 {
ef7796f30b31 another new version ...
Jim Meyering <jim@meyering.net>
parents: 813
diff changeset
320 while (len-- > 0)
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
321 dest[len] = TOUPPER ((UCHAR_T) src[len], loc);
816
ef7796f30b31 another new version ...
Jim Meyering <jim@meyering.net>
parents: 813
diff changeset
322 return dest;
ef7796f30b31 another new version ...
Jim Meyering <jim@meyering.net>
parents: 813
diff changeset
323 }
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
324 #endif
816
ef7796f30b31 another new version ...
Jim Meyering <jim@meyering.net>
parents: 813
diff changeset
325
1058
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
326
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
327 #if ! HAVE_TM_GMTOFF
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
328 /* Yield the difference between *A and *B,
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
329 measured in seconds, ignoring leap seconds. */
1058
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
330 # define tm_diff ftime_tm_diff
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
331 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
332 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
333 {
794
8d2567244c18 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 782
diff changeset
334 /* Compute intervening leap days correctly even if year is negative.
8d2567244c18 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 782
diff changeset
335 Take care to avoid int overflow in leap day calculations,
8d2567244c18 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 782
diff changeset
336 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
337 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
338 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
794
8d2567244c18 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 782
diff changeset
339 int a100 = a4 / 25 - (a4 % 25 < 0);
8d2567244c18 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 782
diff changeset
340 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
341 int a400 = SHR (a100, 2);
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5402
diff changeset
342 int b400 = SHR (b100, 2);
794
8d2567244c18 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 782
diff changeset
343 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
8d2567244c18 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 782
diff changeset
344 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
345 int days = (365 * years + intervening_leap_days
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
346 + (a->tm_yday - b->tm_yday));
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
347 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
348 + (a->tm_min - b->tm_min))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
349 + (a->tm_sec - b->tm_sec));
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
350 }
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
351 #endif /* ! HAVE_TM_GMTOFF */
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
352
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
353
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
354
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
355 /* 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
356 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
357 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
358 be as small as YDAY_MINIMUM. */
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
359 #define ISO_WEEK_START_WDAY 1 /* Monday */
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
360 #define ISO_WEEK1_WDAY 4 /* Thursday */
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
361 #define YDAY_MINIMUM (-366)
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
362 #ifdef __GNUC__
1058
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
363 __inline__
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
364 #endif
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
365 static int
4693
490ea9ec1ffb Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4621
diff changeset
366 iso_week_days (int yday, int wday)
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
367 {
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
368 /* 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
369 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
370 return (yday
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
371 - (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
372 + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY);
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
373 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
374
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
375
3261
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
376 /* When compiling this file, GNU applications can #define my_strftime
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
377 to a symbol (typically nstrftime) to get an extended strftime with
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
378 extra arguments TZ and NS. */
3261
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
379
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
380 #if FPRINTFTIME
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
381 # undef my_strftime
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
382 # define my_strftime fprintftime
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
383 #endif
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
384
3261
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
385 #ifdef my_strftime
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
386 # undef HAVE_TZSET
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
387 # define extra_args , tz, ns
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
388 # define extra_args_spec , timezone_t tz, int ns
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
389 #else
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
390 # if defined COMPILE_WIDE
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
391 # define my_strftime wcsftime
4297
30aa99ec2725 (widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents: 4296
diff changeset
392 # 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
393 # else
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
394 # define my_strftime strftime
4297
30aa99ec2725 (widen) [COMPILE_WIDE]: Merge nearly-identical definitions.
Jim Meyering <jim@meyering.net>
parents: 4296
diff changeset
395 # 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
396 # endif
3261
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
397 # define extra_args
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
398 # 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
399 /* We don't have this information in general. */
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
400 # define tz 1
3261
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
401 # define ns 0
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
402 #endif
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
403
860
68da68da125e (_strftime_copytm): New function, to work around Solaris 2.5 tzset bug.
Jim Meyering <jim@meyering.net>
parents: 829
diff changeset
404
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
405 /* 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
406 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
407 static size_t
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
408 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
409 STRFTIME_ARG (size_t maxsize)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
410 const CHAR_T *format,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
411 const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO)
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
412 {
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
413 #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
414 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
415 #endif
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
416 #if FPRINTFTIME
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
417 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
418 #endif
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
419
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
420 int hour12 = tp->tm_hour;
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
421 #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
422 /* 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
423 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
424 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
425 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
426 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
427 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
428 # define a_wkday \
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
429 ((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
430 # define f_wkday \
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
431 ((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
432 # define a_month \
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
433 ((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
434 # define f_month \
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
435 ((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
436 # define ampm \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
437 ((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
438 ? 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
439
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
440 # define aw_len STRLEN (a_wkday)
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
441 # define am_len STRLEN (a_month)
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
442 # define ap_len STRLEN (ampm)
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
443 #endif
18069
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
444 #if HAVE_TZNAME
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
445 char **tzname_vec = tzname;
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
446 #endif
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
447 const char *zone;
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
448 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
449 STREAM_OR_CHAR_T *p = s;
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
450 const CHAR_T *f;
2993
9231fb44e77d (my_strftime): Do not invoke mbrlen with a
Jim Meyering <jim@meyering.net>
parents: 2923
diff changeset
451 #if DO_MULTIBYTE && !defined COMPILE_WIDE
9231fb44e77d (my_strftime): Do not invoke mbrlen with a
Jim Meyering <jim@meyering.net>
parents: 2923
diff changeset
452 const char *format_end = NULL;
9231fb44e77d (my_strftime): Do not invoke mbrlen with a
Jim Meyering <jim@meyering.net>
parents: 2923
diff changeset
453 #endif
582
3ec26150a8d6 (mon_week_ISO): New function to implement new %V format.
Jim Meyering <jim@meyering.net>
parents: 581
diff changeset
454
5960
2a0d593683dc Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
455 #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
456 /* 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
457 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
458 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
459 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
460 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
461 tp = &copy;
2a0d593683dc Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
462 #endif
2a0d593683dc Remove the dependency of the strftime module on the tzset module.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
463
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
464 zone = NULL;
1058
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
465 #if HAVE_TM_ZONE
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
466 /* The POSIX test suite assumes that setting
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
467 the environment variable TZ to a new value before calling strftime()
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
468 will influence the result (the %Z format) even if the information in
1058
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
469 TP is computed with a totally different time zone.
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
470 This is bogus: though POSIX allows bad behavior like this,
8c9ee29f3de0 update from FSF
Jim Meyering <jim@meyering.net>
parents: 930
diff changeset
471 POSIX does not require it. Do the right thing instead. */
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
472 zone = (const char *) tp->tm_zone;
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
473 #endif
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
474 #if HAVE_TZNAME
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
475 if (!tz)
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
476 {
72809df6189a Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents: 1532
diff changeset
477 if (! (zone && *zone))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
478 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
479 }
72809df6189a Don't invoke localtime_r or gmtime_r unless it's the GNU C
Jim Meyering <jim@meyering.net>
parents: 1532
diff changeset
480 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
481 {
18069
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
482 # if !HAVE_TM_ZONE
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
483 /* Infer the zone name from *TZ instead of from TZNAME. */
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
484 tzname_vec = tz->tzname_copy;
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
485 # endif
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
486 /* 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
487 though strftime called tzset. */
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
488 # 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
489 tzset ();
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
490 # 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
491 }
18067
0295f80643fc strftime: fix newly-introduced bug on Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents: 18060
diff changeset
492 /* The tzset() call might have changed the value. */
0295f80643fc strftime: fix newly-introduced bug on Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents: 18060
diff changeset
493 if (!(zone && *zone) && tp->tm_isdst >= 0)
18069
1c6c8e9218c9 time_rz: port better to MinGW
Paul Eggert <eggert@cs.ucla.edu>
parents: 18067
diff changeset
494 zone = tzname_vec[tp->tm_isdst != 0];
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
495 #endif
18067
0295f80643fc strftime: fix newly-introduced bug on Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents: 18060
diff changeset
496 if (! zone)
0295f80643fc strftime: fix newly-introduced bug on Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents: 18060
diff changeset
497 zone = "";
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
498
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
499 if (hour12 > 12)
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
500 hour12 -= 12;
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
501 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
502 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
503 hour12 = 12;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
504
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
505 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
506 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
507 int pad = 0; /* Padding for number ('-', '_', or 0). */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
508 int modifier; /* Field modifier ('E', 'O', or 0). */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
509 int digits = 0; /* Max digits for numeric format. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
510 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
511 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
512 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
513 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
514 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
515 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
516 CHAR_T sign_char;
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
517 CHAR_T *bufp;
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
518 CHAR_T buf[1
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
519 + 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
520 + (sizeof (int) < sizeof (time_t)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
521 ? INT_STRLEN_BOUND (time_t)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
522 : INT_STRLEN_BOUND (int))];
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
523 int width = -1;
5690
e44b4f85ad9b Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
524 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
525 bool to_uppcase = upcase;
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
526 size_t colons;
5690
e44b4f85ad9b Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
527 bool change_case = false;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
528 int format_char;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
529
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
530 #if DO_MULTIBYTE && !defined COMPILE_WIDE
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
531 switch (*f)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
532 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
533 case L_('%'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
534 break;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
535
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
536 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
537 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
538 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
539 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
540 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
541 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
542 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
543 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
544 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
545 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
546 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
547 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
548 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
549 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
550 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
551 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
552 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
553 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
554 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
555 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
556 case L_('~'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
557 /* 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
558 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
559 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
560 not be analyzed further. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
561 add1 (*f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
562 continue;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
563
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
564 default:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
565 /* 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
566 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
567 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
568 mbstate_t mbstate = mbstate_zero;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
569 size_t len = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
570 size_t fsize;
2993
9231fb44e77d (my_strftime): Do not invoke mbrlen with a
Jim Meyering <jim@meyering.net>
parents: 2923
diff changeset
571
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
572 if (! format_end)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
573 format_end = f + strlen (f) + 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
574 fsize = format_end - f;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
575
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
576 do
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
577 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
578 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
579
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
580 if (bytes == 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
581 break;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
582
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
583 if (bytes == (size_t) -2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
584 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
585 len += strlen (f + len);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
586 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
587 }
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
588
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
589 if (bytes == (size_t) -1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
590 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
591 len++;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
592 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
593 }
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
594
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
595 len += bytes;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
596 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
597 while (! mbsinit (&mbstate));
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
598
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
599 cpy (len, f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
600 f += len - 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
601 continue;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
602 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
603 }
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
604
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
605 #else /* ! DO_MULTIBYTE */
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
606
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
607 /* 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
608 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
609 or this is the wide character version. */
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
610 if (*f != L_('%'))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
611 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
612 add1 (*f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
613 continue;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
614 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
615
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
616 #endif /* ! DO_MULTIBYTE */
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
617
829
ab038dc4414d update from GNU libc
Jim Meyering <jim@meyering.net>
parents: 819
diff changeset
618 /* Check for flags that can modify a format. */
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
619 while (1)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
620 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
621 switch (*++f)
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 /* This influences the number formats. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
624 case L_('_'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
625 case L_('-'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
626 case L_('0'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
627 pad = *f;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
628 continue;
816
ef7796f30b31 another new version ...
Jim Meyering <jim@meyering.net>
parents: 813
diff changeset
629
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
630 /* This changes textual output. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
631 case L_('^'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
632 to_uppcase = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
633 continue;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
634 case L_('#'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
635 change_case = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
636 continue;
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
637
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
638 default:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
639 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
640 }
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 }
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
643
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
644 /* As a GNU extension we allow to specify the field width. */
819
2e3ead41ade2 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 817
diff changeset
645 if (ISDIGIT (*f))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
646 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
647 width = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
648 do
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
649 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
650 if (width > INT_MAX / 10
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
651 || (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
652 /* Avoid overflow. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
653 width = INT_MAX;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
654 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
655 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
656 width *= 10;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
657 width += *f - L_('0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
658 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
659 ++f;
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 while (ISDIGIT (*f));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
662 }
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
663
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
664 /* Check for modifiers. */
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
665 switch (*f)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
666 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
667 case L_('E'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
668 case L_('O'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
669 modifier = *f++;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
670 break;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
671
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
672 default:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
673 modifier = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
674 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
675 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
676
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
677 /* Now do the specified format. */
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
678 format_char = *f;
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
679 switch (format_char)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
680 {
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
681 #define DO_NUMBER(d, v) \
17646
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
682 do \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
683 { \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
684 digits = d; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
685 number_value = v; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
686 goto do_number; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
687 } \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
688 while (0)
5690
e44b4f85ad9b Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
689 #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
690 do \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
691 { \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
692 digits = d; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
693 negative_number = negative; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
694 u_number_value = v; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
695 goto do_signed_number; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
696 } \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
697 while (0)
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
698
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
699 /* The mask is not what you might think.
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
700 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
701 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
702 #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
703 do \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
704 { \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
705 digits = d; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
706 negative_number = negative; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
707 tz_colon_mask = mask; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
708 u_number_value = v; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
709 goto do_tz_offset; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
710 } \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
711 while (0)
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
712 #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
713 do \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
714 { \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
715 digits = d; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
716 number_value = v; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
717 goto do_number_spacepad; \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
718 } \
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
719 while (0)
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
720
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
721 case L_('%'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
722 if (modifier != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
723 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
724 add1 (*f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
725 break;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
726
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
727 case L_('a'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
728 if (modifier != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
729 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
730 if (change_case)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
731 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
732 to_uppcase = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
733 to_lowcase = false;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
734 }
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
735 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
736 cpy (aw_len, a_wkday);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
737 break;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
738 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
739 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
740 #endif
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
741
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
742 case 'A':
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
743 if (modifier != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
744 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
745 if (change_case)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
746 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
747 to_uppcase = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
748 to_lowcase = false;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
749 }
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
750 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
751 cpy (STRLEN (f_wkday), f_wkday);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
752 break;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
753 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
754 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
755 #endif
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
756
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
757 case L_('b'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
758 case L_('h'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
759 if (change_case)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
760 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
761 to_uppcase = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
762 to_lowcase = false;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
763 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
764 if (modifier != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
765 goto bad_format;
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
766 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
767 cpy (am_len, a_month);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
768 break;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
769 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
770 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
771 #endif
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
772
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
773 case L_('B'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
774 if (modifier != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
775 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
776 if (change_case)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
777 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
778 to_uppcase = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
779 to_lowcase = false;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
780 }
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
781 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
782 cpy (STRLEN (f_month), f_month);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
783 break;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
784 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
785 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
786 #endif
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
787
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
788 case L_('c'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
789 if (modifier == L_('O'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
790 goto bad_format;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
791 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
792 if (! (modifier == 'E'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
793 && (*(subfmt =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
794 (const CHAR_T *) _NL_CURRENT (LC_TIME,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
795 NLW(ERA_D_T_FMT)))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
796 != '\0')))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
797 subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_T_FMT));
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
798 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
799 goto underlying_strftime;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
800 #endif
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
801
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
802 subformat:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
803 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
804 size_t len = strftime_case_ (to_uppcase,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
805 NULL, STRFTIME_ARG ((size_t) -1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
806 subfmt,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
807 tp extra_args LOCALE_ARG);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
808 add (len, strftime_case_ (to_uppcase, p,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
809 STRFTIME_ARG (maxsize - i)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
810 subfmt,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
811 tp extra_args LOCALE_ARG));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
812 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
813 break;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
814
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
815 #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
816 underlying_strftime:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
817 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
818 /* The relevant information is available only via the
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
819 underlying strftime implementation, so use that. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
820 char ufmt[5];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
821 char *u = ufmt;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
822 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
823 size_t len;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
824 /* 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
825 In some cases, config.h contains something like
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
826 "#define strftime rpl_strftime". */
2378
524f131fc113 (my_strftime): Make sure we call the system
Jim Meyering <jim@meyering.net>
parents: 2082
diff changeset
827 # ifdef strftime
524f131fc113 (my_strftime): Make sure we call the system
Jim Meyering <jim@meyering.net>
parents: 2082
diff changeset
828 # undef strftime
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
829 size_t strftime ();
2378
524f131fc113 (my_strftime): Make sure we call the system
Jim Meyering <jim@meyering.net>
parents: 2082
diff changeset
830 # endif
524f131fc113 (my_strftime): Make sure we call the system
Jim Meyering <jim@meyering.net>
parents: 2082
diff changeset
831
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
832 /* The space helps distinguish strftime failure from empty
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
833 output. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
834 *u++ = ' ';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
835 *u++ = '%';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
836 if (modifier != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
837 *u++ = modifier;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
838 *u++ = format_char;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
839 *u = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
840 len = strftime (ubuf, sizeof ubuf, ufmt, tp);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
841 if (len != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
842 cpy (len - 1, ubuf + 1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
843 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
844 break;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
845 #endif
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
846
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
847 case L_('C'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
848 if (modifier == L_('O'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
849 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
850 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
851 {
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
852 #if HAVE_STRUCT_ERA_ENTRY
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
853 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
854 if (era)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
855 {
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
856 # ifdef COMPILE_WIDE
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
857 size_t len = __wcslen (era->era_wname);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
858 cpy (len, era->era_wname);
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
859 # else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
860 size_t len = strlen (era->era_name);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
861 cpy (len, era->era_name);
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
862 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
863 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
864 }
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
865 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
866 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
867 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
868 }
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
869
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
870 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
871 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
872 century -= tp->tm_year % 100 < 0 && 0 < century;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
873 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
874 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
875
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
876 case L_('x'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
877 if (modifier == L_('O'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
878 goto bad_format;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
879 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
880 if (! (modifier == L_('E')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
881 && (*(subfmt =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
882 (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
883 != L_('\0'))))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
884 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
885 goto subformat;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
886 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
887 goto underlying_strftime;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
888 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
889 case L_('D'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
890 if (modifier != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
891 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
892 subfmt = L_("%m/%d/%y");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
893 goto subformat;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
894
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
895 case L_('d'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
896 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
897 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
898
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
899 DO_NUMBER (2, tp->tm_mday);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
900
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
901 case L_('e'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
902 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
903 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
904
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
905 DO_NUMBER_SPACEPAD (2, tp->tm_mday);
176
Jim Meyering <jim@meyering.net>
parents: 125
diff changeset
906
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
907 /* 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
908 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
909
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
910 do_tz_offset:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
911 always_output_a_sign = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
912 goto do_number_body;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
913
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
914 do_number_spacepad:
16235
18a38c9615f0 In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
915 /* 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
916 if (pad != L_('0') && pad != L_('-'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
917 pad = L_('_');
176
Jim Meyering <jim@meyering.net>
parents: 125
diff changeset
918
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
919 do_number:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
920 /* Format NUMBER_VALUE according to the MODIFIER flag. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
921 negative_number = number_value < 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
922 u_number_value = number_value;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
923
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
924 do_signed_number:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
925 always_output_a_sign = false;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
926 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
927
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
928 do_number_body:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
929 /* 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
930 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
931 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
932 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
933 negating it. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
934 if (modifier == L_('O') && !negative_number)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
935 {
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
936 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
937 /* Get the locale specific alternate representation of
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
938 the number. If none exist NULL is returned. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
939 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
940 HELPER_LOCALE_ARG);
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
941
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
942 if (cp != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
943 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
944 size_t digitlen = STRLEN (cp);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
945 if (digitlen != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
946 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
947 cpy (digitlen, cp);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
948 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
949 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
950 }
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
951 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
952 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
953 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
954 }
5690
e44b4f85ad9b Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
955
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
956 bufp = buf + sizeof (buf) / sizeof (buf[0]);
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
957
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
958 if (negative_number)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
959 u_number_value = - u_number_value;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
960
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
961 do
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
962 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
963 if (tz_colon_mask & 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
964 *--bufp = ':';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
965 tz_colon_mask >>= 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
966 *--bufp = u_number_value % 10 + L_('0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
967 u_number_value /= 10;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
968 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
969 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
970
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
971 do_number_sign_and_padding:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
972 if (digits < width)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
973 digits = width;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
974
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
975 sign_char = (negative_number ? L_('-')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
976 : always_output_a_sign ? L_('+')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
977 : 0);
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
978
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
979 if (pad == L_('-'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
980 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
981 if (sign_char)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
982 add1 (sign_char);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
983 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
984 else
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 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
987 - bufp) - !!sign_char;
546
baaeb11e50e5 (add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents: 307
diff changeset
988
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
989 if (padding > 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
990 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
991 if (pad == L_('_'))
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 ((size_t) padding >= maxsize - i)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
994 return 0;
4298
374bfdd48d05 From GNU libc.
Jim Meyering <jim@meyering.net>
parents: 4297
diff changeset
995
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
996 if (p)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
997 memset_space (p, padding);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
998 i += padding;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
999 width = width > padding ? width - padding : 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1000 if (sign_char)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1001 add1 (sign_char);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1002 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1003 else
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 if ((size_t) digits >= maxsize - i)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1006 return 0;
4298
374bfdd48d05 From GNU libc.
Jim Meyering <jim@meyering.net>
parents: 4297
diff changeset
1007
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1008 if (sign_char)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1009 add1 (sign_char);
4298
374bfdd48d05 From GNU libc.
Jim Meyering <jim@meyering.net>
parents: 4297
diff changeset
1010
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1011 if (p)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1012 memset_zero (p, padding);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1013 i += padding;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1014 width = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1015 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1016 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1017 else
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 if (sign_char)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1020 add1 (sign_char);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1021 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1022 }
546
baaeb11e50e5 (add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents: 307
diff changeset
1023
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1024 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
1025 break;
546
baaeb11e50e5 (add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents: 307
diff changeset
1026
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1027 case L_('F'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1028 if (modifier != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1029 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1030 subfmt = L_("%Y-%m-%d");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1031 goto subformat;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1032
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1033 case L_('H'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1034 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1035 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1036
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1037 DO_NUMBER (2, tp->tm_hour);
546
baaeb11e50e5 (add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents: 307
diff changeset
1038
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1039 case L_('I'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1040 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1041 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1042
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1043 DO_NUMBER (2, hour12);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1044
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1045 case L_('k'): /* GNU extension. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1046 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1047 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1048
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1049 DO_NUMBER_SPACEPAD (2, tp->tm_hour);
546
baaeb11e50e5 (add_num_tz): New function.
Jim Meyering <jim@meyering.net>
parents: 307
diff changeset
1050
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1051 case L_('l'): /* GNU extension. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1052 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1053 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1054
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1055 DO_NUMBER_SPACEPAD (2, hour12);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1056
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1057 case L_('j'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1058 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1059 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1060
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1061 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
1062
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1063 case L_('M'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1064 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1065 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1066
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1067 DO_NUMBER (2, tp->tm_min);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1068
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1069 case L_('m'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1070 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1071 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1072
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1073 DO_SIGNED_NUMBER (2, tp->tm_mon < -1, tp->tm_mon + 1U);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1074
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
1075 #ifndef _LIBC
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1076 case L_('N'): /* GNU extension. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1077 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1078 goto bad_format;
3261
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
1079
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1080 number_value = ns;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1081 if (width == -1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1082 width = 9;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1083 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1084 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1085 /* 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
1086 int j;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1087 for (j = width; j < 9; j++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1088 number_value /= 10;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1089 }
3261
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
1090
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1091 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
1092 #endif
3261
de5ef6b00dd9 (my_strftime):
Jim Meyering <jim@meyering.net>
parents: 3181
diff changeset
1093
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1094 case L_('n'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1095 add1 (L_('\n'));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1096 break;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1097
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1098 case L_('P'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1099 to_lowcase = true;
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
1100 #ifndef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1101 format_char = L_('p');
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1102 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1103 /* FALLTHROUGH */
813
7d01ef99f1b8 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 804
diff changeset
1104
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1105 case L_('p'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1106 if (change_case)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1107 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1108 to_uppcase = false;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1109 to_lowcase = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1110 }
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
1111 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1112 cpy (ap_len, ampm);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1113 break;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1114 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1115 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1116 #endif
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1117
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1118 case L_('R'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1119 subfmt = L_("%H:%M");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1120 goto subformat;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1121
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1122 case L_('r'):
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
1123 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1124 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
1125 NLW(T_FMT_AMPM)))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1126 == L_('\0'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1127 subfmt = L_("%I:%M:%S %p");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1128 goto subformat;
6893
b56d9038d586 From Derek R. Price:
Jim Meyering <jim@meyering.net>
parents: 6505
diff changeset
1129 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1130 goto underlying_strftime;
4558
e7c388835e7c Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4422
diff changeset
1131 #endif
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1132
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1133 case L_('S'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1134 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1135 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1136
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1137 DO_NUMBER (2, tp->tm_sec);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1138
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1139 case L_('s'): /* GNU extension. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1140 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1141 struct tm ltm;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1142 time_t t;
726
8867c987f8cf (strftime): Accommodate the broken C compiler
Jim Meyering <jim@meyering.net>
parents: 691
diff changeset
1143
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1144 ltm = *tp;
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1145 t = mktime_z (tz, &ltm);
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1146
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1147 /* 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
1148 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
1149
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1150 bufp = buf + sizeof (buf) / sizeof (buf[0]);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1151 negative_number = t < 0;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1152
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1153 do
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1154 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1155 int d = t % 10;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1156 t /= 10;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1157 *--bufp = (negative_number ? -d : d) + L_('0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1158 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1159 while (t != 0);
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1160
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1161 digits = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1162 always_output_a_sign = false;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1163 goto do_number_sign_and_padding;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1164 }
672
d4a380613840 Update from GNU libc -- this adds back %z and %s
Jim Meyering <jim@meyering.net>
parents: 668
diff changeset
1165
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1166 case L_('X'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1167 if (modifier == L_('O'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1168 goto bad_format;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1169 #ifdef _NL_CURRENT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1170 if (! (modifier == L_('E')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1171 && (*(subfmt =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1172 (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
1173 != L_('\0'))))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1174 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
1175 goto subformat;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1176 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1177 goto underlying_strftime;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1178 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1179 case L_('T'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1180 subfmt = L_("%H:%M:%S");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1181 goto subformat;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1182
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1183 case L_('t'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1184 add1 (L_('\t'));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1185 break;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1186
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1187 case L_('u'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1188 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
1189
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1190 case L_('U'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1191 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1192 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1193
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1194 DO_NUMBER (2, (tp->tm_yday - tp->tm_wday + 7) / 7);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1195
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1196 case L_('V'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1197 case L_('g'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1198 case L_('G'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1199 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1200 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1201 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1202 /* 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
1203 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
1204 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
1205 overflow. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1206 int year = (tp->tm_year
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1207 + (tp->tm_year < 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1208 ? TM_YEAR_BASE % 400
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1209 : TM_YEAR_BASE % 400 - 400));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1210 int year_adjust = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1211 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
1212
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1213 if (days < 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1214 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1215 /* This ISO week belongs to the previous year. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1216 year_adjust = -1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1217 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
1218 tp->tm_wday);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1219 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1220 else
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 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
1223 tp->tm_wday);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1224 if (0 <= d)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1225 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1226 /* This ISO week belongs to the next year. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1227 year_adjust = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1228 days = d;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1229 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1230 }
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1231
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1232 switch (*f)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1233 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1234 case L_('g'):
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 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
1237 DO_NUMBER (2, (0 <= yy
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1238 ? yy
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1239 : tp->tm_year < -TM_YEAR_BASE - year_adjust
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 : yy + 100));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1242 }
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1243
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1244 case L_('G'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1245 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
1246 (tp->tm_year + (unsigned int) TM_YEAR_BASE
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1247 + year_adjust));
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1248
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1249 default:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1250 DO_NUMBER (2, days / 7 + 1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1251 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1252 }
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1253
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1254 case L_('W'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1255 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1256 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1257
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1258 DO_NUMBER (2, (tp->tm_yday - (tp->tm_wday - 1 + 7) % 7 + 7) / 7);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1259
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1260 case L_('w'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1261 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1262 goto bad_format;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1263
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1264 DO_NUMBER (1, tp->tm_wday);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1265
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1266 case L_('Y'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1267 if (modifier == 'E')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1268 {
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1269 #if HAVE_STRUCT_ERA_ENTRY
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1270 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
1271 if (era)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1272 {
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
1273 # ifdef COMPILE_WIDE
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1274 subfmt = era->era_wformat;
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
1275 # else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1276 subfmt = era->era_format;
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
1277 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1278 goto subformat;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1279 }
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1280 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1281 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1282 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1283 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1284 if (modifier == L_('O'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1285 goto bad_format;
17646
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
1286
0a7fbe4650ff strftime: wrap macros in "do {...} while(0)"
Bernhard Voelker <mail@bernhard-voelker.de>
parents: 17587
diff changeset
1287 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
1288 tp->tm_year + (unsigned int) TM_YEAR_BASE);
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1289
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1290 case L_('y'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1291 if (modifier == L_('E'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1292 {
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1293 #if HAVE_STRUCT_ERA_ENTRY
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1294 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
1295 if (era)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1296 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1297 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
1298 DO_NUMBER (1, (era->offset
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1299 + delta * era->absolute_direction));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1300 }
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1301 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1302 goto underlying_strftime;
1109
0a4438f607ff Update from FSF.
Jim Meyering <jim@meyering.net>
parents: 1058
diff changeset
1303 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1304 }
5690
e44b4f85ad9b Include <stdbool.h>. Use bool where appropriate,
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
1305
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1306 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1307 int yy = tp->tm_year % 100;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1308 if (yy < 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1309 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
1310 DO_NUMBER (2, yy);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1311 }
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1312
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1313 case L_('Z'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1314 if (change_case)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1315 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1316 to_uppcase = false;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1317 to_lowcase = true;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1318 }
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
1319
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
1320 #ifdef COMPILE_WIDE
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1321 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1322 /* 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
1323 to transform it first. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1324 wchar_t *wczone;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1325 size_t len;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1326 widen (zone, wczone, len);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1327 cpy (len, wczone);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1328 }
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
1329 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1330 cpy (strlen (zone), zone);
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
1331 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1332 break;
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1333
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1334 case L_(':'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1335 /* :, ::, and ::: are valid only just before 'z'.
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1336 :::: etc. are rejected later. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1337 for (colons = 1; f[colons] == L_(':'); colons++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1338 continue;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1339 if (f[colons] != L_('z'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1340 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1341 f += colons;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1342 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
1343
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1344 case L_('z'):
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1345 colons = 0;
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1346
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1347 do_z_conversion:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1348 if (tp->tm_isdst < 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1349 break;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1350
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1351 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1352 int diff;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1353 int hour_diff;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1354 int min_diff;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1355 int sec_diff;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1356 #if HAVE_TM_GMTOFF
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1357 diff = tp->tm_gmtoff;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1358 #else
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1359 if (!tz)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1360 diff = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1361 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1362 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1363 struct tm gtm;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1364 struct tm ltm;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1365 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
1366
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1367 ltm = *tp;
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1368 lt = mktime_z (tz, &ltm);
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
1369
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1370 if (lt == (time_t) -1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1371 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1372 /* 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
1373 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
1374 occurred. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1375 struct tm tm;
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1376
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1377 if (! localtime_rz (tz, &lt, &tm)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1378 || ((ltm.tm_sec ^ tm.tm_sec)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1379 | (ltm.tm_min ^ tm.tm_min)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1380 | (ltm.tm_hour ^ tm.tm_hour)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1381 | (ltm.tm_mday ^ tm.tm_mday)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1382 | (ltm.tm_mon ^ tm.tm_mon)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1383 | (ltm.tm_year ^ tm.tm_year)))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1384 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1385 }
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
1386
18060
ea0b31e02258 fprintftime, strftime: use timezone_t args
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1387 if (! localtime_rz (0, &lt, &gtm))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1388 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
1389
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1390 diff = tm_diff (&ltm, &gtm);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1391 }
691
6813ffe12e6a (strftime): New version, from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 687
diff changeset
1392 #endif
672
d4a380613840 Update from GNU libc -- this adds back %z and %s
Jim Meyering <jim@meyering.net>
parents: 668
diff changeset
1393
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1394 hour_diff = diff / 60 / 60;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1395 min_diff = diff / 60 % 60;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1396 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
1397
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1398 switch (colons)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1399 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1400 case 0: /* +hhmm */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1401 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
1402
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1403 case 1: tz_hh_mm: /* +hh:mm */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1404 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
1405
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1406 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
1407 DO_TZ_OFFSET (9, diff < 0, 024,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1408 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
1409
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1410 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
1411 if (sec_diff != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1412 goto tz_hh_mm_ss;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1413 if (min_diff != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1414 goto tz_hh_mm;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1415 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
1416
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1417 default:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1418 goto bad_format;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1419 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1420 }
672
d4a380613840 Update from GNU libc -- this adds back %z and %s
Jim Meyering <jim@meyering.net>
parents: 668
diff changeset
1421
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1422 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
1423 --f;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1424 /* Fall through. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1425 default:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1426 /* Unknown format; output the format, including the '%',
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1427 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
1428 multibyte string has been misparsed. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1429 bad_format:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1430 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1431 int flen;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1432 for (flen = 1; f[1 - flen] != L_('%'); flen++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1433 continue;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1434 cpy (flen, &f[1 - flen]);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1435 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1436 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1437 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1438 }
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1439
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1440 #if ! FPRINTFTIME
1775
96099c7ba283 Update from master source in libc, removing %f.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
1441 if (p && maxsize != 0)
2082
35c2c4e86de2 Sync with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2060
diff changeset
1442 *p = L_('\0');
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1443 #endif
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1444
604
e54f6bf3d960 Update from GNU libc.
Jim Meyering <jim@meyering.net>
parents: 582
diff changeset
1445 return i;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1446 }
6273
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1447
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1448 /* 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
1449 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
1450 (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
1451 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
1452 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
1453 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
1454 size_t
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1455 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
1456 const CHAR_T *format,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12257
diff changeset
1457 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
1458 {
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1459 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
1460 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
1461 }
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1462
52428341346b * strftime.c (my_strftime): Rewrite the previous change slightly,
Paul Eggert <eggert@cs.ucla.edu>
parents: 6062
diff changeset
1463 #if defined _LIBC && ! FPRINTFTIME
4296
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
1464 libc_hidden_def (my_strftime)
2da9db9c7ef8 (my_strftime): Merge in locale-related changes from libc.
Jim Meyering <jim@meyering.net>
parents: 3670
diff changeset
1465 #endif