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