annotate cutils.c @ 470:334e08488ad1 libavformat

correctly interleave packets during encoding dts/pts fixed for streamcopy dont use coded_frame->key_frame hack in muxers, use AVPacket.flags instead
author michael
date Sat, 29 May 2004 18:50:31 +0000
parents 9f4f4ca9f7b5
children ad72189eec07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Various simple utilities for ffmpeg system
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #if !defined(CONFIG_NOCUTILS)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 * set to the next character in 'str' after the prefix.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 * @param str input string
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 * @param val prefix to test
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 * @param ptr updated after the prefix in str in there is a match
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 * @return TRUE if there is a match
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 int strstart(const char *str, const char *val, const char **ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 const char *p, *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 p = str;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 q = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 while (*q != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 if (*p != *q)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 q++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 if (ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 *ptr = p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 * Return TRUE if val is a prefix of str (case independent). If it
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 * returns TRUE, ptr is set to the next character in 'str' after the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 * prefix.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 * @param str input string
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 * @param val prefix to test
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 * @param ptr updated after the prefix in str in there is a match
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 * @return TRUE if there is a match */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 int stristart(const char *str, const char *val, const char **ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 const char *p, *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 p = str;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 q = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 while (*q != '\0') {
64
b0e0eb595e29 * static,const,compiler warning cleanup
kabi
parents: 0
diff changeset
62 if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q))
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 q++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 if (ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 *ptr = p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 * Copy the string str to buf. If str length is bigger than buf_size -
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 * 1 then it is clamped to buf_size - 1.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 * NOTE: this function does what strncpy should have done to be
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 * useful. NEVER use strncpy.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 * @param buf destination buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 * @param buf_size size of destination buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 * @param str source string
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 void pstrcpy(char *buf, int buf_size, const char *str)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 char *q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 if (buf_size <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 c = *str++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 if (c == 0 || q >= buf + buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 /* strcat and truncate. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 char *pstrcat(char *buf, int buf_size, const char *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 len = strlen(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 if (len < buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 pstrcpy(buf + len, buf_size - len, s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 return buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 #endif
151
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
110
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
111 /* add one element to a dynamic array */
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
112 void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem)
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
113 {
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
114 int nb, nb_alloc;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
115 unsigned long *tab;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
116
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
117 nb = *nb_ptr;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
118 tab = *tab_ptr;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
119 if ((nb & (nb - 1)) == 0) {
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
120 if (nb == 0)
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
121 nb_alloc = 1;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
122 else
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
123 nb_alloc = nb * 2;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
124 tab = av_realloc(tab, nb_alloc * sizeof(unsigned long));
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
125 *tab_ptr = tab;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
126 }
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
127 tab[nb++] = elem;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
128 *nb_ptr = nb;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
129 }
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
130
230
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
131 time_t mktimegm(struct tm *tm)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
132 {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
133 time_t t;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
134
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
135 int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
136
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
137 if (m < 3) {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
138 m += 12;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
139 y--;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
140 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
141
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
142 t = 86400 *
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
143 (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
144
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
145 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
146
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
147 return t;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
148 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
149
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
150 /* get a positive number between n_min and n_max, for a maximum length
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
151 of len_max. Return -1 if error. */
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
152 static int date_get_num(const char **pp,
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
153 int n_min, int n_max, int len_max)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
154 {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
155 int i, val, c;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
156 const char *p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
157
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
158 p = *pp;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
159 val = 0;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
160 for(i = 0; i < len_max; i++) {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
161 c = *p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
162 if (!isdigit(c))
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
163 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
164 val = (val * 10) + c - '0';
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
165 p++;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
166 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
167 /* no number read ? */
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
168 if (p == *pp)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
169 return -1;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
170 if (val < n_min || val > n_max)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
171 return -1;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
172 *pp = p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
173 return val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
174 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
175
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
176 /* small strptime for ffmpeg */
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
177 const char *small_strptime(const char *p, const char *fmt,
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
178 struct tm *dt)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
179 {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
180 int c, val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
181
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
182 for(;;) {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
183 c = *fmt++;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
184 if (c == '\0') {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
185 return p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
186 } else if (c == '%') {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
187 c = *fmt++;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
188 switch(c) {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
189 case 'H':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
190 val = date_get_num(&p, 0, 23, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
191 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
192 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
193 dt->tm_hour = val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
194 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
195 case 'M':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
196 val = date_get_num(&p, 0, 59, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
197 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
198 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
199 dt->tm_min = val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
200 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
201 case 'S':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
202 val = date_get_num(&p, 0, 59, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
203 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
204 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
205 dt->tm_sec = val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
206 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
207 case 'Y':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
208 val = date_get_num(&p, 0, 9999, 4);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
209 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
210 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
211 dt->tm_year = val - 1900;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
212 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
213 case 'm':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
214 val = date_get_num(&p, 1, 12, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
215 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
216 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
217 dt->tm_mon = val - 1;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
218 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
219 case 'd':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
220 val = date_get_num(&p, 1, 31, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
221 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
222 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
223 dt->tm_mday = val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
224 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
225 case '%':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
226 goto match;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
227 default:
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
228 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
229 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
230 } else {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
231 match:
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
232 if (c != *p)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
233 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
234 p++;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
235 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
236 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
237 return p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
238 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
239