annotate strptime.c @ 168:808dabf5a88e libavformat

* First round of AV sync fixes. * -r now does the right thing. * frame rate and frame sizes now share same abbv. table and you can do -r ntsc as well as -s ntsc
author romansh
date Sat, 12 Jul 2003 07:37:05 +0000
parents 05318cf2e886
children 89a78842f6c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /* Convert a string representation of time to a time value.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 This file is part of the GNU C Library.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 The GNU C Library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 modify it under the terms of the GNU Library General Public License as
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 published by the Free Software Foundation; either version 2 of the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 The GNU C Library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 Library General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 You should have received a copy of the GNU Library General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 /* XXX This version of the implementation is not really complete.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 Some of the fields cannot add information alone. But if seeing
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 some of them in the same format (such as year, week and weekday)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 this is enough information for determining the date. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 # include "config.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 #include <ctype.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #include <limits.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 #include <string.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 #include <time.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 #ifdef _LIBC
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 # include "../locale/localeinfo.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 #include "strptime.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 #ifndef __P
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 # if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 # define __P(args) args
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 # else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 # define __P(args) ()
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 # endif /* GCC. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 #endif /* Not __P. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 #if ! HAVE_LOCALTIME_R && ! defined localtime_r
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 # ifdef _LIBC
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 # define localtime_r __localtime_r
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 # else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 /* Approximate localtime_r as best we can in its absence. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 # define localtime_r my_localtime_r
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 static struct tm *localtime_r __P ((const time_t *, struct tm *));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 static struct tm *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 localtime_r (t, tp)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 const time_t *t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 struct tm *tp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 struct tm *l = localtime (t);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 if (! l)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 *tp = *l;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 return tp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 # endif /* ! _LIBC */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 #endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 #define match_char(ch1, ch2) if (ch1 != ch2) return NULL
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 #if defined __GNUC__ && __GNUC__ >= 2
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 # define match_string(cs1, s2) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 ({ size_t len = strlen (cs1); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 int result = strncasecmp ((cs1), (s2), len) == 0; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 if (result) (s2) += len; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 result; })
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 /* Oh come on. Get a reasonable compiler. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 # define match_string(cs1, s2) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 (strncasecmp ((cs1), (s2), strlen (cs1)) ? 0 : ((s2) += strlen (cs1), 1))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 /* We intentionally do not use isdigit() for testing because this will
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 lead to problems with the wide character version. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 #define get_number(from, to, n) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 do { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 int __n = n; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 val = 0; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 while (*rp == ' ') \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 ++rp; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 if (*rp < '0' || *rp > '9') \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 return NULL; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 do { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 val *= 10; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 val += *rp++ - '0'; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 } while (--__n > 0 && val * 10 <= to && *rp >= '0' && *rp <= '9'); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 if (val < from || val > to) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 return NULL; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 } while (0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 # define get_alt_number(from, to, n) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 ({ \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 __label__ do_normal; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 if (*decided != raw) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 const char *alts = _NL_CURRENT (LC_TIME, ALT_DIGITS); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 int __n = n; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 int any = 0; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 while (*rp == ' ') \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 ++rp; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 val = 0; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 do { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 val *= 10; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 while (*alts != '\0') \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 size_t len = strlen (alts); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 if (strncasecmp (alts, rp, len) == 0) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 alts += len + 1; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 ++val; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 } \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 if (*alts == '\0') \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 if (*decided == not && ! any) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 goto do_normal; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 /* If we haven't read anything it's an error. */ \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 if (! any) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 return NULL; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 /* Correct the premature multiplication. */ \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 val /= 10; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 } \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 else \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 *decided = loc; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 } while (--__n > 0 && val * 10 <= to); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 if (val < from || val > to) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 return NULL; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 } \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 else \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 do_normal: \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 get_number (from, to, n); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 } \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 0; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 })
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 # define get_alt_number(from, to, n) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 /* We don't have the alternate representation. */ \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 get_number(from, to, n)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 #define recursive(new_fmt) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 (*(new_fmt) != '\0' \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 && (rp = strptime_internal (rp, (new_fmt), tm, decided, era_cnt)) != NULL)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 #ifdef _LIBC
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 /* This is defined in locale/C-time.c in the GNU libc. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 extern const struct locale_data _nl_C_LC_TIME;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 extern const unsigned short int __mon_yday[2][13];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 # define weekday_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (DAY_1)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 # define ab_weekday_name \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 # define month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (MON_1)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 # define ab_month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 # define HERE_D_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_T_FMT)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 # define HERE_D_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_FMT)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 # define HERE_AM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (AM_STR)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 # define HERE_PM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (PM_STR)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 # define HERE_T_FMT_AMPM \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (T_FMT_AMPM)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 # define HERE_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (T_FMT)].string)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 # define strncasecmp(s1, s2, n) __strncasecmp (s1, s2, n)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 static char const weekday_name[][10] =
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 "Sunday", "Monday", "Tuesday", "Wednesday",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 "Thursday", "Friday", "Saturday"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 static char const ab_weekday_name[][4] =
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 static char const month_name[][10] =
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 "January", "February", "March", "April", "May", "June",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 "July", "August", "September", "October", "November", "December"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 static char const ab_month_name[][4] =
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 # define HERE_D_T_FMT "%a %b %e %H:%M:%S %Y"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 # define HERE_D_FMT "%m/%d/%y"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 # define HERE_AM_STR "AM"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 # define HERE_PM_STR "PM"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 # define HERE_T_FMT_AMPM "%I:%M:%S %p"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 # define HERE_T_FMT "%H:%M:%S"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 const unsigned short int __mon_yday[2][13] =
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 /* Normal years. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 /* Leap years. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 /* Status of lookup: do we use the locale data or the raw data? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 enum locale_status { not, loc, raw };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 #ifndef __isleap
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 /* Nonzero if YEAR is a leap year (every 4 years,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 except every 100th isn't, and every 400th is). */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 # define __isleap(year) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 /* Compute the day of the week. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 static void
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 day_of_the_week (struct tm *tm)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 /* We know that January 1st 1970 was a Thursday (= 4). Compute the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 the difference between this data in the one on TM and so determine
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 the weekday. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 int wday = (-473
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 + (365 * (tm->tm_year - 70))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 + (corr_year / 4)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 + (((corr_year / 4) / 25) / 4)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 + __mon_yday[0][tm->tm_mon]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 + tm->tm_mday - 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 tm->tm_wday = ((wday % 7) + 7) % 7;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 /* Compute the day of the year. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 static void
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 day_of_the_year (struct tm *tm)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 tm->tm_yday = (__mon_yday[__isleap (1900 + tm->tm_year)][tm->tm_mon]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 + (tm->tm_mday - 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 static char *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 #ifdef _LIBC
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 internal_function
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 strptime_internal __P ((const char *rp, const char *fmt, struct tm *tm,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 enum locale_status *decided, int era_cnt));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 static char *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 #ifdef _LIBC
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 internal_function
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 strptime_internal (rp, fmt, tm, decided, era_cnt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 const char *rp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 const char *fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 struct tm *tm;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 enum locale_status *decided;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 int era_cnt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 const char *rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 int cnt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 size_t val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 int have_I, is_pm;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 int century, want_century;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 int want_era;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 int have_wday, want_xday;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 int have_yday;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 int have_mon, have_mday;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 size_t num_eras;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 struct era_entry *era;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 have_I = is_pm = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 century = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 want_century = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 want_era = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 era = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 have_wday = want_xday = have_yday = have_mon = have_mday = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 while (*fmt != '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 /* A white space in the format string matches 0 more or white
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 space in the input string. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 if (isspace (*fmt))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 while (isspace (*rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 ++rp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 ++fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 /* Any character but `%' must be matched by the same character
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 in the iput string. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 if (*fmt != '%')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 match_char (*fmt++, *rp++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 ++fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 #ifndef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 /* We need this for handling the `E' modifier. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 start_over:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 /* Make back up of current processing pointer. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 rp_backup = rp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 switch (*fmt++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 case '%':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 /* Match the `%' character itself. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 match_char ('%', *rp++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 case 'a':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 case 'A':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 /* Match day of week. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 for (cnt = 0; cnt < 7; ++cnt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 if (*decided !=raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 if (match_string (_NL_CURRENT (LC_TIME, DAY_1 + cnt), rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 if (*decided == not
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 && strcmp (_NL_CURRENT (LC_TIME, DAY_1 + cnt),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 weekday_name[cnt]))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 if (match_string (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 if (*decided == not
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 && strcmp (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 ab_weekday_name[cnt]))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 if (*decided != loc
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 && (match_string (weekday_name[cnt], rp)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 || match_string (ab_weekday_name[cnt], rp)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 if (cnt == 7)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 /* Does not match a weekday name. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 tm->tm_wday = cnt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 have_wday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 case 'b':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 case 'B':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 case 'h':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 /* Match month name. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 for (cnt = 0; cnt < 12; ++cnt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 if (*decided !=raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 if (*decided == not
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 && strcmp (_NL_CURRENT (LC_TIME, MON_1 + cnt),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 month_name[cnt]))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 if (match_string (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 if (*decided == not
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 && strcmp (_NL_CURRENT (LC_TIME, ABMON_1 + cnt),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 ab_month_name[cnt]))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 if (match_string (month_name[cnt], rp)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 || match_string (ab_month_name[cnt], rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 if (cnt == 12)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 /* Does not match a month name. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 tm->tm_mon = cnt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 case 'c':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 /* Match locale's date and time format. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 if (!recursive (_NL_CURRENT (LC_TIME, D_T_FMT)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 rp = rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 if (*decided == not &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 strcmp (_NL_CURRENT (LC_TIME, D_T_FMT), HERE_D_T_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 if (!recursive (HERE_D_T_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 case 'C':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 /* Match century number. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 match_century:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 get_number (0, 99, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 century = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 case 'd':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 case 'e':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 /* Match day of month. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 get_number (1, 31, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 tm->tm_mday = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 have_mday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 case 'F':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 if (!recursive ("%Y-%m-%d"))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 case 'x':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 if (!recursive (_NL_CURRENT (LC_TIME, D_FMT)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 rp = rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 if (*decided == not
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 && strcmp (_NL_CURRENT (LC_TIME, D_FMT), HERE_D_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 /* Fall through. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 case 'D':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 /* Match standard day format. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 if (!recursive (HERE_D_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 case 'k':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 case 'H':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 /* Match hour in 24-hour clock. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 get_number (0, 23, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 tm->tm_hour = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 have_I = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 case 'I':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 /* Match hour in 12-hour clock. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 get_number (1, 12, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 tm->tm_hour = val % 12;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 have_I = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 case 'j':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 /* Match day number of year. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 get_number (1, 366, 3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 tm->tm_yday = val - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 have_yday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 case 'm':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 /* Match number of month. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 get_number (1, 12, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 tm->tm_mon = val - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 have_mon = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 case 'M':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 /* Match minute. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 get_number (0, 59, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 tm->tm_min = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 case 'n':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 case 't':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 /* Match any white space. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 while (isspace (*rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 ++rp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 case 'p':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 /* Match locale's equivalent of AM/PM. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 if (match_string (_NL_CURRENT (LC_TIME, AM_STR), rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 if (strcmp (_NL_CURRENT (LC_TIME, AM_STR), HERE_AM_STR))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 if (match_string (_NL_CURRENT (LC_TIME, PM_STR), rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 if (strcmp (_NL_CURRENT (LC_TIME, PM_STR), HERE_PM_STR))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 is_pm = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 if (!match_string (HERE_AM_STR, rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540 if (match_string (HERE_PM_STR, rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 is_pm = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 case 'r':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 if (!recursive (_NL_CURRENT (LC_TIME, T_FMT_AMPM)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 rp = rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 if (*decided == not &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 strcmp (_NL_CURRENT (LC_TIME, T_FMT_AMPM),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 HERE_T_FMT_AMPM))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 if (!recursive (HERE_T_FMT_AMPM))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570 case 'R':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 if (!recursive ("%H:%M"))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 case 's':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 /* The number of seconds may be very high so we cannot use
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 the `get_number' macro. Instead read the number
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 character for character and construct the result while
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 doing this. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 time_t secs = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 if (*rp < '0' || *rp > '9')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 /* We need at least one digit. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 do
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 secs *= 10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 secs += *rp++ - '0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 while (*rp >= '0' && *rp <= '9');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 if (localtime_r (&secs, tm) == NULL)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 /* Error in function. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 case 'S':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 get_number (0, 61, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 tm->tm_sec = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 case 'X':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 if (!recursive (_NL_CURRENT (LC_TIME, T_FMT)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 rp = rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 if (strcmp (_NL_CURRENT (LC_TIME, T_FMT), HERE_T_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 /* Fall through. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 case 'T':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 if (!recursive (HERE_T_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 case 'u':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 get_number (1, 7, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 tm->tm_wday = val % 7;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 have_wday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 case 'g':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 get_number (0, 99, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 /* XXX This cannot determine any field in TM. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 case 'G':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 if (*rp < '0' || *rp > '9')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638 /* XXX Ignore the number since we would need some more
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 information to compute a real date. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 do
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 ++rp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 while (*rp >= '0' && *rp <= '9');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 case 'U':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 case 'V':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646 case 'W':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 get_number (0, 53, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 /* XXX This cannot determine any field in TM without some
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 information. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 case 'w':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 /* Match number of weekday. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653 get_number (0, 6, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 tm->tm_wday = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 have_wday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 case 'y':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 match_year_in_century:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 /* Match year within century. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 get_number (0, 99, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 /* The "Year 2000: The Millennium Rollover" paper suggests that
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 values in the range 69-99 refer to the twentieth century. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 tm->tm_year = val >= 69 ? val : val + 100;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 /* Indicate that we want to use the century, if specified. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 want_century = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 case 'Y':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 /* Match year including century number. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 get_number (0, 9999, 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 tm->tm_year = val - 1900;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 want_century = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 case 'Z':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 /* XXX How to handle this? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 case 'E':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 switch (*fmt++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
684 case 'c':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 /* Match locale's alternate date and time format. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 if (*fmt == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691 fmt = _NL_CURRENT (LC_TIME, D_T_FMT);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 if (!recursive (fmt))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 rp = rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 if (strcmp (fmt, HERE_D_T_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 /* The C locale has no era information, so use the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 normal representation. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 if (!recursive (HERE_D_T_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 case 'C':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 if (era_cnt >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 era = _nl_select_era_entry (era_cnt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 if (match_string (era->era_name, rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731 num_eras = _NL_CURRENT_WORD (LC_TIME,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732 _NL_TIME_ERA_NUM_ENTRIES);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 for (era_cnt = 0; era_cnt < (int) num_eras;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734 ++era_cnt, rp = rp_backup)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736 era = _nl_select_era_entry (era_cnt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737 if (match_string (era->era_name, rp))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
740 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 if (era_cnt == (int) num_eras)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 era_cnt = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 /* The C locale has no era information, so use the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 normal representation. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 goto match_century;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 case 'y':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 if (*decided == raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 goto match_year_in_century;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 get_number(0, 9999, 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 tm->tm_year = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 want_era = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 case 'Y':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 num_eras = _NL_CURRENT_WORD (LC_TIME,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771 _NL_TIME_ERA_NUM_ENTRIES);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 for (era_cnt = 0; era_cnt < (int) num_eras;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 ++era_cnt, rp = rp_backup)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 era = _nl_select_era_entry (era_cnt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 if (recursive (era->era_format))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
778 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
779 if (era_cnt == (int) num_eras)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781 era_cnt = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 rp = rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 era_cnt = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 get_number (0, 9999, 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797 tm->tm_year = val - 1900;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 want_century = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 case 'x':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_FMT);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 if (*fmt == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 fmt = _NL_CURRENT (LC_TIME, D_FMT);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
808
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 if (!recursive (fmt))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
810 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 rp = rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
817 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
818 if (strcmp (fmt, HERE_D_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
823 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
824 if (!recursive (HERE_D_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827 case 'X':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
828 if (*decided != raw)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
829 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
830 const char *fmt = _NL_CURRENT (LC_TIME, ERA_T_FMT);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
831
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
832 if (*fmt == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833 fmt = _NL_CURRENT (LC_TIME, T_FMT);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 if (!recursive (fmt))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
836 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 if (*decided == loc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 rp = rp_backup;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
844 if (strcmp (fmt, HERE_T_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 *decided = loc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
848 *decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 if (!recursive (HERE_T_FMT))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
853 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
856 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858 /* We have no information about the era format. Just use
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 the normal format. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 if (*fmt != 'c' && *fmt != 'C' && *fmt != 'y' && *fmt != 'Y'
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861 && *fmt != 'x' && *fmt != 'X')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 /* This is an illegal format. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
864
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
865 goto start_over;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
866 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 case 'O':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
868 switch (*fmt++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
869 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870 case 'd':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871 case 'e':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 /* Match day of month using alternate numeric symbols. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
873 get_alt_number (1, 31, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 tm->tm_mday = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875 have_mday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 case 'H':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 /* Match hour in 24-hour clock using alternate numeric
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880 symbols. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881 get_alt_number (0, 23, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 tm->tm_hour = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 have_I = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885 case 'I':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886 /* Match hour in 12-hour clock using alternate numeric
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 symbols. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888 get_alt_number (1, 12, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 tm->tm_hour = val - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 have_I = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892 case 'm':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
893 /* Match month using alternate numeric symbols. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 get_alt_number (1, 12, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 tm->tm_mon = val - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 have_mon = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899 case 'M':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 /* Match minutes using alternate numeric symbols. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901 get_alt_number (0, 59, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902 tm->tm_min = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
903 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
904 case 'S':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 /* Match seconds using alternate numeric symbols. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 get_alt_number (0, 61, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
907 tm->tm_sec = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909 case 'U':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910 case 'V':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 case 'W':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 get_alt_number (0, 53, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 /* XXX This cannot determine any field in TM without
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
914 further information. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
915 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 case 'w':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917 /* Match number of weekday using alternate numeric symbols. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918 get_alt_number (0, 6, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
919 tm->tm_wday = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
920 have_wday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
921 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
922 case 'y':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 /* Match year within century using alternate numeric symbols. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
924 get_alt_number (0, 99, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
925 tm->tm_year = val >= 69 ? val : val + 100;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
926 want_xday = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
927 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
928 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
929 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
930 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
931 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
932 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
933 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
934 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
935 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
936
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
937 if (have_I && is_pm)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
938 tm->tm_hour += 12;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
939
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
940 if (century != -1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
941 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
942 if (want_century)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
943 tm->tm_year = tm->tm_year % 100 + (century - 19) * 100;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
944 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
945 /* Only the century, but not the year. Strange, but so be it. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
946 tm->tm_year = (century - 19) * 100;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
947 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
948
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
949 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
950 if (era_cnt != -1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
951 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
952 era = _nl_select_era_entry(era_cnt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
953 if (want_era)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
954 tm->tm_year = (era->start_date[0]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
955 + ((tm->tm_year - era->offset)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
956 * era->absolute_direction));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
957 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
958 /* Era start year assumed. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
959 tm->tm_year = era->start_date[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
960 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
961 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
962 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
963 if (want_era)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
964 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
965
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
966 if (want_xday && !have_wday)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
967 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
968 if ( !(have_mon && have_mday) && have_yday)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
969 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
970 /* We don't have tm_mon and/or tm_mday, compute them. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
971 int t_mon = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
972 while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= tm->tm_yday)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
973 t_mon++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
974 if (!have_mon)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
975 tm->tm_mon = t_mon - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
976 if (!have_mday)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
977 tm->tm_mday =
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
978 (tm->tm_yday
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
979 - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
980 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
981 day_of_the_week (tm);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
982 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
983 if (want_xday && !have_yday)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
984 day_of_the_year (tm);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
985
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
986 return (char *) rp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
987 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
988
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
989
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
990 char *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
991 strptime (buf, format, tm)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
992 const char *buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
993 const char *format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
994 struct tm *tm;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
995 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
996 enum locale_status decided;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
997
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
998 #ifdef _NL_CURRENT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
999 decided = not;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1000 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1001 decided = raw;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1002 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1003 return strptime_internal (buf, format, tm, &decided, -1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1004 }