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