Mercurial > emacs
annotate src/strftime.c @ 17756:0000a992fd24
(help-with-tutorial): Fix a bug of handling non-English
tutorial file.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 12 May 1997 06:56:21 +0000 |
parents | 8f3dcea869f5 |
children | 2ef01cc793bf |
rev | line source |
---|---|
17502
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
2 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
3 NOTE: The canonical source of this file is maintained with the GNU C Library. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
4 Bugs can be reported to bug-glibc@prep.ai.mit.edu. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
5 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
6 This program is free software; you can redistribute it and/or modify it |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
7 under the terms of the GNU General Public License as published by the |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
8 Free Software Foundation; either version 2, or (at your option) any |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
9 later version. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
10 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
11 This program is distributed in the hope that it will be useful, |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
14 GNU General Public License for more details. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
15 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
17 along with this program; if not, write to the Free Software |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
19 USA. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
20 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
21 #ifdef HAVE_CONFIG_H |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
22 # include <config.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
23 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
24 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
25 #ifdef _LIBC |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
26 # define HAVE_LIMITS_H 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
27 # define HAVE_MBLEN 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
28 # define HAVE_MBRLEN 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
29 # define HAVE_STRUCT_ERA_ENTRY 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
30 # define HAVE_TM_GMTOFF 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
31 # define HAVE_TM_ZONE 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
32 # define HAVE_TZNAME 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
33 # define HAVE_TZSET 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
34 # define MULTIBYTE_IS_FORMAT_SAFE 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
35 # define STDC_HEADERS 1 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
36 # include <ansidecl.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
37 # include "../locale/localeinfo.h" |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
38 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
39 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
40 #include <ctype.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
41 #include <sys/types.h> /* Some systems define `time_t' here. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
42 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
43 #ifdef TIME_WITH_SYS_TIME |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
44 # include <sys/time.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
45 # include <time.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
46 #else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
47 # ifdef HAVE_SYS_TIME_H |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
48 # include <sys/time.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
49 # else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
50 # include <time.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
51 # endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
52 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
53 #if HAVE_TZNAME |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
54 extern char *tzname[]; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
55 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
56 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
57 /* Do multibyte processing if multibytes are supported, unless |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
58 multibyte sequences are safe in formats. Multibyte sequences are |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
59 safe if they cannot contain byte sequences that look like format |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
60 conversion specifications. The GNU C Library uses UTF8 multibyte |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
61 encoding, which is safe for formats, but strftime.c can be used |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
62 with other C libraries that use unsafe encodings. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
63 #define DO_MULTIBYTE (HAVE_MBLEN && ! MULTIBYTE_IS_FORMAT_SAFE) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
64 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
65 #if DO_MULTIBYTE |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
66 # if HAVE_MBRLEN |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
67 # include <wchar.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
68 # else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
69 /* Simulate mbrlen with mblen as best we can. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
70 # define mbstate_t int |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
71 # define mbrlen(s, n, ps) mblen (s, n) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
72 # define mbsinit(ps) (*(ps) == 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
73 # endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
74 static const mbstate_t mbstate_zero; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
75 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
76 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
77 #if HAVE_LIMITS_H |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
78 # include <limits.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
79 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
80 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
81 #if STDC_HEADERS |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
82 # include <stddef.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
83 # include <stdlib.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
84 # include <string.h> |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
85 #else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
86 # define memcpy(d, s, n) bcopy ((s), (d), (n)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
87 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
88 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
89 #ifndef __P |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
90 # if defined (__GNUC__) || (defined (__STDC__) && __STDC__) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
91 # define __P(args) args |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
92 # else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
93 # define __P(args) () |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
94 # endif /* GCC. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
95 #endif /* Not __P. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
96 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
97 #ifndef PTR |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
98 # ifdef __STDC__ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
99 # define PTR void * |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
100 # else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
101 # define PTR char * |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
102 # endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
103 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
104 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
105 #ifndef CHAR_BIT |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
106 # define CHAR_BIT 8 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
107 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
108 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
109 #ifndef NULL |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
110 # define NULL 0 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
111 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
112 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
113 #define TYPE_SIGNED(t) ((t) -1 < 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
114 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
115 /* Bound on length of the string representing an integer value of type t. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
116 Subtract one for the sign bit if t is signed; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
117 302 / 1000 is log10 (2) rounded up; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
118 add one for integer division truncation; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
119 add one more for a minus sign if t is signed. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
120 #define INT_STRLEN_BOUND(t) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
121 ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 100 + 1 + TYPE_SIGNED (t)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
122 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
123 #define TM_YEAR_BASE 1900 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
124 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
125 #ifndef __isleap |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
126 /* Nonzero if YEAR is a leap year (every 4 years, |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
127 except every 100th isn't, and every 400th is). */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
128 # define __isleap(year) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
129 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
130 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
131 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
132 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
133 #ifdef _LIBC |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
134 # define gmtime_r __gmtime_r |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
135 # define localtime_r __localtime_r |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
136 extern int __tz_compute __P ((time_t timer, const struct tm *tm)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
137 # define tzname __tzname |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
138 # define tzset __tzset |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
139 #else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
140 # if ! HAVE_LOCALTIME_R |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
141 # if ! HAVE_TM_GMTOFF |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
142 /* Approximate gmtime_r as best we can in its absence. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
143 # define gmtime_r my_gmtime_r |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
144 static struct tm *gmtime_r __P ((const time_t *, struct tm *)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
145 static struct tm * |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
146 gmtime_r (t, tp) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
147 const time_t *t; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
148 struct tm *tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
149 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
150 struct tm *l = gmtime (t); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
151 if (! l) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
152 return 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
153 *tp = *l; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
154 return tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
155 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
156 # endif /* ! HAVE_TM_GMTOFF */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
157 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
158 /* Approximate localtime_r as best we can in its absence. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
159 # define localtime_r my_localtime_r |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
160 static struct tm *localtime_r __P ((const time_t *, struct tm *)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
161 static struct tm * |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
162 localtime_r (t, tp) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
163 const time_t *t; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
164 struct tm *tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
165 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
166 struct tm *l = localtime (t); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
167 if (! l) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
168 return 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
169 *tp = *l; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
170 return tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
171 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
172 # endif /* ! HAVE_LOCALTIME_R */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
173 #endif /* ! defined (_LIBC) */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
174 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
175 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
176 #if !defined (memset) && !defined (HAVE_MEMSET) && !defined (_LIBC) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
177 /* Some systems lack the `memset' function and we don't want to |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
178 introduce additional dependencies. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
179 static const char spaces[16] = " "; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
180 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
181 # define memset_space(P, Len) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
182 do { \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
183 int _len = (Len); \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
184 \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
185 do \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
186 { \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
187 int _this = _len > 16 ? 16 : _len; \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
188 memcpy ((P), spaces, _this); \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
189 (P) += _this; \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
190 _len -= _this; \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
191 } \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
192 while (_len > 0); \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
193 } while (0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
194 #else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
195 # define memset_space(P, Len) (memset ((P), ' ', (Len)), (P) += (Len)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
196 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
197 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
198 #define add(n, f) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
199 do \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
200 { \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
201 int _n = (n); \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
202 int _delta = width - _n; \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
203 int _incr = _n + (_delta > 0 ? _delta : 0); \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
204 if (i + _incr >= maxsize) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
205 return 0; \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
206 if (p) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
207 { \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
208 if (_delta > 0) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
209 memset_space (p, _delta); \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
210 f; \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
211 p += _n; \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
212 } \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
213 i += _incr; \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
214 } while (0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
215 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
216 #define cpy(n, s) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
217 add ((n), \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
218 if (to_lowcase) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
219 memcpy_lowcase (p, (s), _n); \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
220 else if (to_uppcase) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
221 memcpy_uppcase (p, (s), _n); \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
222 else \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
223 memcpy ((PTR) p, (PTR) (s), _n)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
224 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
225 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
226 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
227 #ifdef _LIBC |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
228 # define TOUPPER(Ch) toupper (Ch) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
229 # define TOLOWER(Ch) tolower (Ch) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
230 #else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
231 # define TOUPPER(Ch) (islower (Ch) ? toupper (Ch) : (Ch)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
232 # define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
233 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
234 /* We don't use `isdigit' here since the locale dependent |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
235 interpretation is not what we want here. We only need to accept |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
236 the arabic digits in the ASCII range. One day there is perhaps a |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
237 more reliable way to accept other sets of digits. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
238 #define ISDIGIT(Ch) ((unsigned int) (Ch) - '0' <= 9) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
239 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
240 static char *memcpy_lowcase __P ((char *dest, const char *src, size_t len)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
241 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
242 static char * |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
243 memcpy_lowcase (dest, src, len) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
244 char *dest; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
245 const char *src; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
246 size_t len; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
247 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
248 while (len-- > 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
249 dest[len] = TOLOWER (src[len]); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
250 return dest; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
251 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
252 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
253 static char *memcpy_uppcase __P ((char *dest, const char *src, size_t len)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
254 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
255 static char * |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
256 memcpy_uppcase (dest, src, len) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
257 char *dest; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
258 const char *src; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
259 size_t len; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
260 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
261 while (len-- > 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
262 dest[len] = TOUPPER (src[len]); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
263 return dest; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
264 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
265 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
266 #if ! HAVE_TM_GMTOFF |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
267 /* Yield the difference between *A and *B, |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
268 measured in seconds, ignoring leap seconds. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
269 static int tm_diff __P ((const struct tm *, const struct tm *)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
270 static int |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
271 tm_diff (a, b) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
272 const struct tm *a; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
273 const struct tm *b; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
274 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
275 /* Compute intervening leap days correctly even if year is negative. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
276 Take care to avoid int overflow in leap day calculations, |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
277 but it's OK to assume that A and B are close to each other. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
278 int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
279 int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
280 int a100 = a4 / 25 - (a4 % 25 < 0); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
281 int b100 = b4 / 25 - (b4 % 25 < 0); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
282 int a400 = a100 >> 2; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
283 int b400 = b100 >> 2; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
284 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
285 int years = a->tm_year - b->tm_year; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
286 int days = (365 * years + intervening_leap_days |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
287 + (a->tm_yday - b->tm_yday)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
288 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
289 + (a->tm_min - b->tm_min)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
290 + (a->tm_sec - b->tm_sec)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
291 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
292 #endif /* ! HAVE_TM_GMTOFF */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
293 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
294 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
295 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
296 /* The number of days from the first day of the first ISO week of this |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
297 year to the year day YDAY with week day WDAY. ISO weeks start on |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
298 Monday; the first ISO week has the year's first Thursday. YDAY may |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
299 be as small as YDAY_MINIMUM. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
300 #define ISO_WEEK_START_WDAY 1 /* Monday */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
301 #define ISO_WEEK1_WDAY 4 /* Thursday */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
302 #define YDAY_MINIMUM (-366) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
303 static int iso_week_days __P ((int, int)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
304 #ifdef __GNUC__ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
305 inline |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
306 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
307 static int |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
308 iso_week_days (yday, wday) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
309 int yday; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
310 int wday; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
311 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
312 /* Add enough to the first operand of % to make it nonnegative. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
313 int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
314 return (yday |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
315 - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
316 + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
317 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
318 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
319 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
320 #ifndef _NL_CURRENT |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
321 static char const weekday_name[][10] = |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
322 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
323 "Sunday", "Monday", "Tuesday", "Wednesday", |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
324 "Thursday", "Friday", "Saturday" |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
325 }; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
326 static char const month_name[][10] = |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
327 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
328 "January", "February", "March", "April", "May", "June", |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
329 "July", "August", "September", "October", "November", "December" |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
330 }; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
331 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
332 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
333 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
334 #if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
335 /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
336 Work around this bug by copying *tp before it might be munged. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
337 size_t _strftime_copytm __P ((char *, size_t, const char *, |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
338 const struct tm *)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
339 size_t |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
340 strftime (s, maxsize, format, tp) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
341 char *s; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
342 size_t maxsize; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
343 const char *format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
344 const struct tm *tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
345 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
346 struct tm tmcopy; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
347 tmcopy = *tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
348 return _strftime_copytm (s, maxsize, format, &tmcopy); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
349 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
350 # ifdef strftime |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
351 # undef strftime |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
352 # endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
353 # define strftime(S, Maxsize, Format, Tp) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
354 _strftime_copytm (S, Maxsize, Format, Tp) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
355 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
356 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
357 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
358 /* Write information from TP into S according to the format |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
359 string FORMAT, writing no more that MAXSIZE characters |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
360 (including the terminating '\0') and returning number of |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
361 characters written. If S is NULL, nothing will be written |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
362 anywhere, so to determine how many characters would be |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
363 written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
364 size_t |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
365 strftime (s, maxsize, format, tp) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
366 char *s; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
367 size_t maxsize; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
368 const char *format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
369 const struct tm *tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
370 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
371 int hour12 = tp->tm_hour; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
372 #ifdef _NL_CURRENT |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
373 const char *const a_wkday = _NL_CURRENT (LC_TIME, ABDAY_1 + tp->tm_wday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
374 const char *const f_wkday = _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
375 const char *const a_month = _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
376 const char *const f_month = _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
377 const char *const ampm = _NL_CURRENT (LC_TIME, |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
378 hour12 > 11 ? PM_STR : AM_STR); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
379 size_t aw_len = strlen (a_wkday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
380 size_t am_len = strlen (a_month); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
381 size_t ap_len = strlen (ampm); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
382 #else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
383 const char *const f_wkday = weekday_name[tp->tm_wday]; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
384 const char *const f_month = month_name[tp->tm_mon]; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
385 const char *const a_wkday = f_wkday; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
386 const char *const a_month = f_month; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
387 const char *const ampm = "AMPM" + 2 * (hour12 > 11); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
388 size_t aw_len = 3; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
389 size_t am_len = 3; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
390 size_t ap_len = 2; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
391 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
392 size_t wkday_len = strlen (f_wkday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
393 size_t month_len = strlen (f_month); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
394 const char *zone; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
395 size_t zonelen; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
396 size_t i = 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
397 char *p = s; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
398 const char *f; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
399 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
400 zone = NULL; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
401 #if !defined _LIBC && HAVE_TM_ZONE |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
402 /* XXX We have some problems here. First, the string pointed to by |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
403 tm_zone is dynamically allocated while loading the zone data. But |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
404 when another zone is loaded since the information in TP were |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
405 computed this would be a stale pointer. |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
406 The second problem is the POSIX test suite which assumes setting |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
407 the environment variable TZ to a new value before calling strftime() |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
408 will influence the result (the %Z format) even if the information in |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
409 TP is computed with a totally different time zone. --drepper@gnu */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
410 zone = (const char *) tp->tm_zone; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
411 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
412 #if HAVE_TZNAME |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
413 /* POSIX.1 8.1.1 requires that whenever strftime() is called, the |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
414 time zone names contained in the external variable `tzname' shall |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
415 be set as if the tzset() function had been called. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
416 # if HAVE_TZSET |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
417 tzset (); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
418 # endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
419 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
420 if (!(zone && *zone) && tp->tm_isdst >= 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
421 zone = tzname[tp->tm_isdst]; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
422 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
423 if (! zone) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
424 zone = ""; /* POSIX.2 requires the empty string here. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
425 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
426 zonelen = strlen (zone); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
427 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
428 if (hour12 > 12) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
429 hour12 -= 12; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
430 else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
431 if (hour12 == 0) hour12 = 12; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
432 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
433 for (f = format; *f != '\0'; ++f) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
434 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
435 int pad; /* Padding for number ('-', '_', or 0). */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
436 int modifier; /* Field modifier ('E', 'O', or 0). */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
437 int digits; /* Max digits for numeric format. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
438 int number_value; /* Numeric value to be printed. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
439 int negative_number; /* 1 if the number is negative. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
440 const char *subfmt; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
441 char *bufp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
442 char buf[1 + (sizeof (int) < sizeof (time_t) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
443 ? INT_STRLEN_BOUND (time_t) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
444 : INT_STRLEN_BOUND (int))]; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
445 int width = -1; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
446 int to_lowcase = 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
447 int to_uppcase = 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
448 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
449 #if DO_MULTIBYTE |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
450 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
451 switch (*f) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
452 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
453 case '%': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
454 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
455 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
456 case '\a': case '\b': case '\t': case '\n': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
457 case '\v': case '\f': case '\r': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
458 case ' ': case '!': case '"': case '#': case '&': case'\'': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
459 case '(': case ')': case '*': case '+': case ',': case '-': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
460 case '.': case '/': case '0': case '1': case '2': case '3': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
461 case '4': case '5': case '6': case '7': case '8': case '9': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
462 case ':': case ';': case '<': case '=': case '>': case '?': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
463 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
464 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
465 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
466 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
467 case 'Y': case 'Z': case '[': case'\\': case ']': case '^': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
468 case '_': case 'a': case 'b': case 'c': case 'd': case 'e': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
469 case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
470 case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
471 case 'r': case 's': case 't': case 'u': case 'v': case 'w': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
472 case 'x': case 'y': case 'z': case '{': case '|': case '}': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
473 case '~': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
474 /* The C Standard requires these 98 characters (plus '%') to |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
475 be in the basic execution character set. None of these |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
476 characters can start a multibyte sequence, so they need |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
477 not be analyzed further. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
478 add (1, *p = *f); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
479 continue; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
480 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
481 default: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
482 /* Copy this multibyte sequence until we reach its end, find |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
483 an error, or come back to the initial shift state. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
484 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
485 mbstate_t mbstate = mbstate_zero; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
486 size_t len = 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
487 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
488 do |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
489 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
490 size_t bytes = mbrlen (f + len, (size_t) -1, &mbstate); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
491 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
492 if (bytes == 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
493 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
494 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
495 if (bytes == (size_t) -2 || bytes == (size_t) -1) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
496 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
497 len++; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
498 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
499 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
500 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
501 len += bytes; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
502 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
503 while (! mbsinit (&mbstate)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
504 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
505 cpy (len, f); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
506 continue; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
507 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
508 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
509 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
510 #else /* ! DO_MULTIBYTE */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
511 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
512 /* Either multibyte encodings are not supported, or they are |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
513 safe for formats, so any non-'%' byte can be copied through. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
514 if (*f != '%') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
515 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
516 add (1, *p = *f); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
517 continue; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
518 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
519 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
520 #endif /* ! DO_MULTIBYTE */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
521 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
522 /* Check for flags that can modify a format. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
523 pad = 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
524 while (1) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
525 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
526 switch (*++f) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
527 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
528 /* This influences the number formats. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
529 case '_': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
530 case '-': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
531 case '0': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
532 pad = *f; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
533 continue; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
534 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
535 /* This changes textual output. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
536 case '^': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
537 to_uppcase = 1; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
538 continue; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
539 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
540 default: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
541 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
542 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
543 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
544 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
545 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
546 /* As a GNU extension we allow to specify the field width. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
547 if (ISDIGIT (*f)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
548 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
549 width = 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
550 do |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
551 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
552 width *= 10; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
553 width += *f - '0'; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
554 ++f; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
555 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
556 while (ISDIGIT (*f)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
557 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
558 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
559 /* Check for modifiers. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
560 switch (*f) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
561 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
562 case 'E': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
563 case 'O': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
564 modifier = *f++; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
565 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
566 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
567 default: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
568 modifier = 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
569 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
570 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
571 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
572 /* Now do the specified format. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
573 switch (*f) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
574 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
575 #define DO_NUMBER(d, v) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
576 digits = d; number_value = v; goto do_number |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
577 #define DO_NUMBER_SPACEPAD(d, v) \ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
578 digits = d; number_value = v; goto do_number_spacepad |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
579 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
580 case '%': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
581 if (modifier != 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
582 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
583 add (1, *p = *f); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
584 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
585 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
586 case 'a': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
587 if (modifier != 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
588 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
589 cpy (aw_len, a_wkday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
590 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
591 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
592 case 'A': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
593 if (modifier != 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
594 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
595 cpy (wkday_len, f_wkday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
596 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
597 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
598 case 'b': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
599 case 'h': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
600 if (modifier != 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
601 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
602 cpy (am_len, a_month); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
603 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
604 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
605 case 'B': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
606 if (modifier != 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
607 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
608 cpy (month_len, f_month); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
609 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
610 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
611 case 'c': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
612 if (modifier == 'O') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
613 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
614 #ifdef _NL_CURRENT |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
615 if (! (modifier == 'E' |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
616 && *(subfmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT)) != '\0')) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
617 subfmt = _NL_CURRENT (LC_TIME, D_T_FMT); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
618 #else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
619 subfmt = "%a %b %e %H:%M:%S %Y"; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
620 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
621 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
622 subformat: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
623 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
624 char *old_start = p; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
625 size_t len = strftime (NULL, maxsize - i, subfmt, tp); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
626 if (len == 0 && *subfmt) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
627 return 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
628 add (len, strftime (p, maxsize - i, subfmt, tp)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
629 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
630 if (to_uppcase) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
631 while (old_start < p) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
632 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
633 *old_start = TOUPPER (*old_start); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
634 ++old_start; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
635 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
636 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
637 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
638 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
639 case 'C': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
640 if (modifier == 'O') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
641 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
642 #if HAVE_STRUCT_ERA_ENTRY |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
643 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
644 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
645 struct era_entry *era = _nl_get_era_entry (tp); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
646 if (era) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
647 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
648 size_t len = strlen (era->name_fmt); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
649 cpy (len, era->name_fmt); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
650 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
651 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
652 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
653 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
654 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
655 int year = tp->tm_year + TM_YEAR_BASE; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
656 DO_NUMBER (1, year / 100 - (year % 100 < 0)); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
657 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
658 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
659 case 'x': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
660 if (modifier == 'O') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
661 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
662 #ifdef _NL_CURRENT |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
663 if (! (modifier == 'E' |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
664 && *(subfmt = _NL_CURRENT (LC_TIME, ERA_D_FMT)) != '\0')) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
665 subfmt = _NL_CURRENT (LC_TIME, D_FMT); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
666 goto subformat; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
667 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
668 /* Fall through. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
669 case 'D': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
670 if (modifier != 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
671 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
672 subfmt = "%m/%d/%y"; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
673 goto subformat; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
674 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
675 case 'd': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
676 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
677 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
678 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
679 DO_NUMBER (2, tp->tm_mday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
680 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
681 case 'e': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
682 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
683 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
684 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
685 DO_NUMBER_SPACEPAD (2, tp->tm_mday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
686 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
687 /* All numeric formats set DIGITS and NUMBER_VALUE and then |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
688 jump to one of these two labels. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
689 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
690 do_number_spacepad: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
691 /* Force `_' flag unless overwritten by `0' flag. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
692 if (pad != '0') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
693 pad = '_'; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
694 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
695 do_number: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
696 /* Format the number according to the MODIFIER flag. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
697 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
698 #ifdef _NL_CURRENT |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
699 if (modifier == 'O' && 0 <= number_value) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
700 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
701 /* Get the locale specific alternate representation of |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
702 the number NUMBER_VALUE. If none exist NULL is returned. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
703 const char *cp = _nl_get_alt_digit (number_value); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
704 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
705 if (cp != NULL) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
706 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
707 size_t digitlen = strlen (cp); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
708 if (digitlen != 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
709 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
710 cpy (digitlen, cp); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
711 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
712 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
713 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
714 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
715 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
716 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
717 unsigned int u = number_value; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
718 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
719 bufp = buf + sizeof (buf); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
720 negative_number = number_value < 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
721 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
722 if (negative_number) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
723 u = -u; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
724 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
725 do |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
726 *--bufp = u % 10 + '0'; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
727 while ((u /= 10) != 0); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
728 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
729 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
730 do_number_sign_and_padding: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
731 if (negative_number) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
732 *--bufp = '-'; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
733 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
734 if (pad != '-') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
735 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
736 int padding = digits - (buf + sizeof (buf) - bufp); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
737 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
738 if (pad == '_') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
739 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
740 while (0 < padding--) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
741 *--bufp = ' '; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
742 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
743 else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
744 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
745 bufp += negative_number; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
746 while (0 < padding--) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
747 *--bufp = '0'; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
748 if (negative_number) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
749 *--bufp = '-'; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
750 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
751 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
752 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
753 cpy (buf + sizeof (buf) - bufp, bufp); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
754 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
755 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
756 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
757 case 'H': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
758 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
759 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
760 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
761 DO_NUMBER (2, tp->tm_hour); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
762 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
763 case 'I': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
764 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
765 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
766 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
767 DO_NUMBER (2, hour12); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
768 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
769 case 'k': /* GNU extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
770 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
771 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
772 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
773 DO_NUMBER_SPACEPAD (2, tp->tm_hour); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
774 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
775 case 'l': /* GNU extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
776 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
777 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
778 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
779 DO_NUMBER_SPACEPAD (2, hour12); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
780 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
781 case 'j': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
782 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
783 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
784 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
785 DO_NUMBER (3, 1 + tp->tm_yday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
786 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
787 case 'M': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
788 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
789 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
790 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
791 DO_NUMBER (2, tp->tm_min); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
792 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
793 case 'm': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
794 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
795 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
796 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
797 DO_NUMBER (2, tp->tm_mon + 1); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
798 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
799 case 'n': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
800 add (1, *p = '\n'); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
801 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
802 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
803 case 'P': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
804 to_lowcase = 1; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
805 /* FALLTHROUGH */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
806 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
807 case 'p': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
808 cpy (ap_len, ampm); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
809 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
810 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
811 case 'R': /* GNU extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
812 subfmt = "%H:%M"; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
813 goto subformat; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
814 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
815 case 'r': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
816 #ifdef _NL_CURRENT |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
817 if (*(subfmt = _NL_CURRENT (LC_TIME, T_FMT_AMPM)) == '\0') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
818 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
819 subfmt = "%I:%M:%S %p"; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
820 goto subformat; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
821 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
822 case 'S': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
823 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
824 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
825 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
826 DO_NUMBER (2, tp->tm_sec); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
827 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
828 case 's': /* GNU extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
829 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
830 struct tm ltm; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
831 time_t t; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
832 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
833 ltm = *tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
834 t = mktime (<m); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
835 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
836 /* Generate string value for T using time_t arithmetic; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
837 this works even if sizeof (long) < sizeof (time_t). */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
838 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
839 bufp = buf + sizeof (buf); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
840 negative_number = t < 0; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
841 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
842 do |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
843 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
844 int d = t % 10; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
845 t /= 10; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
846 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
847 if (negative_number) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
848 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
849 d = -d; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
850 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
851 /* Adjust if division truncates to minus infinity. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
852 if (0 < -1 % 10 && d < 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
853 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
854 t++; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
855 d += 10; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
856 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
857 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
858 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
859 *--bufp = d + '0'; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
860 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
861 while (t != 0); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
862 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
863 digits = 1; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
864 goto do_number_sign_and_padding; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
865 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
866 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
867 case 'X': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
868 if (modifier == 'O') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
869 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
870 #ifdef _NL_CURRENT |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
871 if (! (modifier == 'E' |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
872 && *(subfmt = _NL_CURRENT (LC_TIME, ERA_T_FMT)) != '\0')) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
873 subfmt = _NL_CURRENT (LC_TIME, T_FMT); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
874 goto subformat; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
875 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
876 /* Fall through. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
877 case 'T': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
878 subfmt = "%H:%M:%S"; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
879 goto subformat; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
880 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
881 case 't': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
882 add (1, *p = '\t'); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
883 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
884 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
885 case 'u': /* POSIX.2 extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
886 DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
887 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
888 case 'U': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
889 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
890 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
891 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
892 DO_NUMBER (2, (tp->tm_yday - tp->tm_wday + 7) / 7); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
893 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
894 case 'V': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
895 case 'g': /* GNU extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
896 case 'G': /* GNU extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
897 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
898 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
899 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
900 int year = tp->tm_year + TM_YEAR_BASE; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
901 int days = iso_week_days (tp->tm_yday, tp->tm_wday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
902 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
903 if (days < 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
904 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
905 /* This ISO week belongs to the previous year. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
906 year--; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
907 days = iso_week_days (tp->tm_yday + (365 + __isleap (year)), |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
908 tp->tm_wday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
909 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
910 else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
911 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
912 int d = iso_week_days (tp->tm_yday - (365 + __isleap (year)), |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
913 tp->tm_wday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
914 if (0 <= d) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
915 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
916 /* This ISO week belongs to the next year. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
917 year++; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
918 days = d; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
919 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
920 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
921 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
922 switch (*f) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
923 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
924 case 'g': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
925 DO_NUMBER (2, (year % 100 + 100) % 100); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
926 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
927 case 'G': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
928 DO_NUMBER (1, year); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
929 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
930 default: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
931 DO_NUMBER (2, days / 7 + 1); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
932 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
933 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
934 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
935 case 'W': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
936 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
937 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
938 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
939 DO_NUMBER (2, (tp->tm_yday - (tp->tm_wday - 1 + 7) % 7 + 7) / 7); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
940 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
941 case 'w': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
942 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
943 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
944 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
945 DO_NUMBER (1, tp->tm_wday); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
946 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
947 case 'Y': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
948 #if HAVE_STRUCT_ERA_ENTRY |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
949 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
950 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
951 struct era_entry *era = _nl_get_era_entry (tp); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
952 if (era) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
953 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
954 subfmt = strchr (era->name_fmt, '\0') + 1; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
955 goto subformat; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
956 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
957 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
958 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
959 if (modifier == 'O') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
960 goto bad_format; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
961 else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
962 DO_NUMBER (1, tp->tm_year + TM_YEAR_BASE); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
963 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
964 case 'y': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
965 #if HAVE_STRUCT_ERA_ENTRY |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
966 if (modifier == 'E') |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
967 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
968 struct era_entry *era = _nl_get_era_entry (tp); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
969 if (era) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
970 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
971 int delta = tp->tm_year - era->start_date[0]; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
972 DO_NUMBER (1, (era->offset |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
973 + (era->direction == '-' ? -delta : delta))); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
974 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
975 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
976 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
977 DO_NUMBER (2, (tp->tm_year % 100 + 100) % 100); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
978 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
979 case 'Z': |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
980 cpy (zonelen, zone); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
981 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
982 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
983 case 'z': /* GNU extension. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
984 if (tp->tm_isdst < 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
985 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
986 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
987 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
988 int diff; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
989 #if HAVE_TM_GMTOFF |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
990 diff = tp->tm_gmtoff; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
991 #else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
992 struct tm gtm; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
993 struct tm ltm; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
994 time_t lt; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
995 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
996 ltm = *tp; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
997 lt = mktime (<m); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
998 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
999 if (lt == (time_t) -1) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1000 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1001 /* mktime returns -1 for errors, but -1 is also a |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1002 valid time_t value. Check whether an error really |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1003 occurred. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1004 struct tm tm; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1005 localtime_r (<, &tm); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1006 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1007 if ((ltm.tm_sec ^ tm.tm_sec) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1008 | (ltm.tm_min ^ tm.tm_min) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1009 | (ltm.tm_hour ^ tm.tm_hour) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1010 | (ltm.tm_mday ^ tm.tm_mday) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1011 | (ltm.tm_mon ^ tm.tm_mon) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1012 | (ltm.tm_year ^ tm.tm_year)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1013 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1014 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1015 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1016 if (! gmtime_r (<, >m)) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1017 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1018 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1019 diff = tm_diff (<m, >m); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1020 #endif |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1021 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1022 if (diff < 0) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1023 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1024 add (1, *p = '-'); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1025 diff = -diff; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1026 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1027 else |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1028 add (1, *p = '+'); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1029 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1030 diff /= 60; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1031 DO_NUMBER (4, (diff / 60) * 100 + diff % 60); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1032 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1033 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1034 case '\0': /* GNU extension: % at end of format. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1035 --f; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1036 /* Fall through. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1037 default: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1038 /* Unknown format; output the format, including the '%', |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1039 since this is most likely the right thing to do if a |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1040 multibyte string has been misparsed. */ |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1041 bad_format: |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1042 { |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1043 int flen; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1044 for (flen = 1; f[1 - flen] != '%'; flen++) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1045 continue; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1046 cpy (flen, &f[1 - flen]); |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1047 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1048 break; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1049 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1050 } |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1051 |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1052 if (p) |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1053 *p = '\0'; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1054 return i; |
8f3dcea869f5
automatically generated from GPLed version
Paul Eggert <eggert@twinsun.com>
parents:
diff
changeset
|
1055 } |