annotate src/strftime.c @ 3250:2b8bb4938bb4

[xemacs-hg @ 2006-02-21 11:33:41 by stephent] Commit syntax-cache fixes. <87oe11ne10.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Tue, 21 Feb 2006 11:33:46 +0000
parents 3d8143fc88e1
children 0a63e5de7bdc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* strftime - custom formatting of date and/or time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1989, 1991, 1992 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 along with this program; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 /* Synched up with: FSF 19.30. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
21 /* This file has been ... uhhhhh ... Mule-ized. Yeah.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
22
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
23 (Everything here is external format. This is DANGEROUS and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
24 data-lossy, but fixing it is too much of a bother now.) --ben */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
25
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /* Note: this version of strftime lacks locale support,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 but it is standalone.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 Performs `%' substitutions similar to those in printf. Except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 where noted, substituted fields have a fixed size; numeric fields are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 padded if necessary. Padding is with zeros by default; for fields
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 that display a single number, padding can be changed or inhibited by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 following the `%' with one of the modifiers described below. Unknown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 field specifiers are copied as normal characters. All other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 characters are copied to the output without change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 Supports a superset of the ANSI C field specifiers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 Literal character fields:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 % %
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 n newline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 t tab
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 Numeric modifiers (a nonstandard extension):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 - do not pad the field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 _ pad the field with spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 Time fields:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 %H hour (00..23)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 %I hour (01..12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 %k hour ( 0..23)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 %l hour ( 1..12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 %M minute (00..59)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 %p locale's AM or PM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 %r time, 12-hour (hh:mm:ss [AP]M)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 %R time, 24-hour (hh:mm)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 %s time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 %S second (00..61)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 %T time, 24-hour (hh:mm:ss)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 %X locale's time representation (%H:%M:%S)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 %Z time zone (EDT), or nothing if no time zone is determinable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 Date fields:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 %a locale's abbreviated weekday name (Sun..Sat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 %A locale's full weekday name, variable length (Sunday..Saturday)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 %b locale's abbreviated month name (Jan..Dec)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 %B locale's full month name, variable length (January..December)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 %c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 %C century (00..99)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 %d day of month (01..31)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 %e day of month ( 1..31)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 %D date (mm/dd/yy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 %h same as %b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 %j day of year (001..366)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 %m month (01..12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 %U week number of year with Sunday as first day of week (00..53)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 %w day of week (0..6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 %W week number of year with Monday as first day of week (00..53)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 %x locale's date representation (mm/dd/yy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 %y last two digits of year (00..99)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 %Y year (1970...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 David MacKenzie <djm@gnu.ai.mit.edu> */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #if defined(TM_IN_SYS_TIME) || (!defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #include <sys/time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 #include <time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 #ifndef STDC_HEADERS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 time_t mktime ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
102 #if defined(WIN32_NATIVE) || defined(CYGWIN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 #include <time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 #if defined(HAVE_TZNAME)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 extern char *tzname[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
108 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #define strftime emacs_strftime
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 /* Types of padding for numbers in date and time. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 enum padding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 none, blank, zero
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
120 static char const* const days[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
125 static char const * const months[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 "January", "February", "March", "April", "May", "June",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 "July", "August", "September", "October", "November", "December"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 /* Add character C to STRING and increment LENGTH,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 unless LENGTH would exceed MAX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #define add_char(c) do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 if (length + 1 <= max) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 string[length++] = (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 /* Add a 2 digit number to STRING, padding if specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 Return the number of characters added, up to MAX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 add_num2 (char *string, int num, int max, enum padding pad)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 int top = num / 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 int length = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 if (top == 0 && pad == blank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 add_char (' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 else if (top != 0 || pad == zero)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 add_char (top + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 add_char (num % 10 + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 return length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 /* Add a 3 digit number to STRING, padding if specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 Return the number of characters added, up to MAX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 add_num3 (char *string, int num, int max, enum padding pad)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 int top = num / 100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 int mid = (num - top * 100) / 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 int length = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 if (top == 0 && pad == blank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 add_char (' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 else if (top != 0 || pad == zero)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 add_char (top + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 if (mid == 0 && top == 0 && pad == blank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 add_char (' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 else if (mid != 0 || top != 0 || pad == zero)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 add_char (mid + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 add_char (num % 10 + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 return length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 /* Like strncpy except return the number of characters copied. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
182 add_str (char *to, const char *from, int max)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 for (i = 0; from[i] && i <= max; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 to[i] = from[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 return i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 add_num_time_t (char *string, int max, time_t num)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 /* This buffer is large enough to hold the character representation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (including the trailing NUL) of any unsigned decimal quantity
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 whose binary representation fits in 128 bits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 char buf[40];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 if (sizeof (num) > 16)
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 793
diff changeset
200 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 sprintf (buf, "%lu", (unsigned long) num);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
202 return add_str (string, buf, max);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 /* Return the week in the year of the time in TM, with the weeks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 starting on Sundays. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
209 sun_week (const struct tm *tm)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 int dl;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 /* Set `dl' to the day in the year of the last day of the week previous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 to the one containing the day specified in TM. If the day specified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 in TM is in the first week of the year, `dl' will be negative or 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 Otherwise, calculate the number of complete weeks before our week
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (dl / 7) and add any partial week at the start of the year (dl % 7). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 dl = tm->tm_yday - tm->tm_wday;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 /* Return the week in the year of the time in TM, with the weeks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 starting on Mondays. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
226 mon_week (const struct tm *tm)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 int dl, wday;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 if (tm->tm_wday == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 wday = 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 wday = tm->tm_wday - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 dl = tm->tm_yday - wday;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 #if !defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
239 char *zone_name (const struct tm *tp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
241 zone_name (const struct tm *tp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 char *timezone ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 struct timeval tv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 struct timezone tz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 gettimeofday (&tv, &tz);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 return timezone (tz.tz_minuteswest, tp->tm_isdst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 /* Format the time given in TM according to FORMAT, and put the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 results in STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 Return the number of characters (not including terminating null)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 that were put into STRING, or 0 if the length would have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 exceeded MAX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
258 size_t strftime (char *string, size_t max, const char *format,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
259 const struct tm *tm);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 size_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
262 strftime (char *string, size_t max, const char *format, const struct tm *tm)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 enum padding pad; /* Type of padding to apply. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 size_t length = 0; /* Characters put in STRING so far. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 for (; *format && length < max; ++format)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 if (*format != '%')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 add_char (*format);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 ++format;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 /* Modifiers: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 if (*format == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 pad = none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 ++format;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 else if (*format == '_')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 pad = blank;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 ++format;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 pad = zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 switch (*format)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 /* Literal character fields: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 case '%':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 add_char ('%');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 case 'n':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 add_char ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 case 't':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 add_char ('\t');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 add_char (*format);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 /* Time fields: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 case 'H':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 case 'k':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 add_num2 (&string[length], tm->tm_hour, max - length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 *format == 'H' ? pad : blank);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 case 'I':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 case 'l':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 int hour12;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 if (tm->tm_hour == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 hour12 = 12;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 else if (tm->tm_hour > 12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 hour12 = tm->tm_hour - 12;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 hour12 = tm->tm_hour;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 add_num2 (&string[length], hour12, max - length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 *format == 'I' ? pad : blank);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 case 'M':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 add_num2 (&string[length], tm->tm_min, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 case 'p':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 if (tm->tm_hour < 12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 add_char ('A');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 add_char ('P');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 add_char ('M');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 case 'r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 strftime (&string[length], max - length, "%I:%M:%S %p", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 case 'R':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 strftime (&string[length], max - length, "%H:%M", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 case 's':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 struct tm writable_tm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 writable_tm = *tm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 length += add_num_time_t (&string[length], max - length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 mktime (&writable_tm));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 case 'S':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 add_num2 (&string[length], tm->tm_sec, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 case 'T':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 strftime (&string[length], max - length, "%H:%M:%S", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 case 'X':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 strftime (&string[length], max - length, "%H:%M:%S", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 case 'Z':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 #ifdef HAVE_TM_ZONE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 length += add_str (&string[length], tm->tm_zone, max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 #ifdef HAVE_TZNAME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 if (tm->tm_isdst && tzname[1] && *tzname[1])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 length += add_str (&string[length], tzname[1], max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 length += add_str (&string[length], tzname[0], max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 length += add_str (&string[length], zone_name (tm), max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 /* Date fields: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 case 'a':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 add_char (days[tm->tm_wday][0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 add_char (days[tm->tm_wday][1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 add_char (days[tm->tm_wday][2]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 case 'A':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 add_str (&string[length], days[tm->tm_wday], max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 case 'b':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 case 'h':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 add_char (months[tm->tm_mon][0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 add_char (months[tm->tm_mon][1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 add_char (months[tm->tm_mon][2]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 case 'B':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 add_str (&string[length], months[tm->tm_mon], max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 case 'c':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 strftime (&string[length], max - length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 "%a %b %d %H:%M:%S %Z %Y", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 case 'C':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 add_num2 (&string[length], (tm->tm_year + 1900) / 100,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 case 'd':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 add_num2 (&string[length], tm->tm_mday, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 case 'e':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 add_num2 (&string[length], tm->tm_mday, max - length, blank);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 case 'D':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 strftime (&string[length], max - length, "%m/%d/%y", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 case 'j':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 add_num3 (&string[length], tm->tm_yday + 1, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 case 'm':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 add_num2 (&string[length], tm->tm_mon + 1, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 case 'U':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 add_num2 (&string[length], sun_week (tm), max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 case 'w':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 add_char (tm->tm_wday + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 case 'W':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 add_num2 (&string[length], mon_week (tm), max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 case 'x':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 strftime (&string[length], max - length, "%m/%d/%y", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 case 'y':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 add_num2 (&string[length], tm->tm_year % 100,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 case 'Y':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 add_char ((tm->tm_year + 1900) / 1000 + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 add_num3 (&string[length],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (1900 + tm->tm_year) % 1000, max - length, zero);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 add_char (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 return length - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 }