annotate cutils.c @ 187:2fa5e94ba716 libavformat

add av_new_stream() usage
author bellard
date Fri, 08 Aug 2003 17:52:30 +0000
parents ec4d9190d3b1
children b0771ae979e3
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 #include <ctype.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #if !defined(CONFIG_NOCUTILS)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 * set to the next character in 'str' after the prefix.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 * @param str input string
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 * @param val prefix to test
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 * @param ptr updated after the prefix in str in there is a match
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 * @return TRUE if there is a match
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 int strstart(const char *str, const char *val, const char **ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 const char *p, *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 p = str;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 q = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 while (*q != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 if (*p != *q)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 q++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 if (ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 *ptr = p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 return 1;
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 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 * Return TRUE if val is a prefix of str (case independent). If it
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 * returns TRUE, ptr is set to the next character in 'str' after the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 * prefix.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 * @param str input string
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 * @param val prefix to test
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 * @param ptr updated after the prefix in str in there is a match
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 * @return TRUE if there is a match */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 int stristart(const char *str, const char *val, const char **ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 const char *p, *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 p = str;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 q = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 while (*q != '\0') {
64
b0e0eb595e29 * static,const,compiler warning cleanup
kabi
parents: 0
diff changeset
63 if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q))
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 q++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 if (ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 *ptr = p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 return 1;
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 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 * Copy the string str to buf. If str length is bigger than buf_size -
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 * 1 then it is clamped to buf_size - 1.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 * NOTE: this function does what strncpy should have done to be
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 * useful. NEVER use strncpy.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 * @param buf destination buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 * @param buf_size size of destination buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 * @param str source string
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 void pstrcpy(char *buf, int buf_size, const char *str)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 char *q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 if (buf_size <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 c = *str++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 if (c == 0 || q >= buf + buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 /* strcat and truncate. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 char *pstrcat(char *buf, int buf_size, const char *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 len = strlen(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 if (len < buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 pstrcpy(buf + len, buf_size - len, s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 return buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 #endif
151
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
111
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
112 /* add one element to a dynamic array */
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
113 void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem)
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
114 {
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
115 int nb, nb_alloc;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
116 unsigned long *tab;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
117
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
118 nb = *nb_ptr;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
119 tab = *tab_ptr;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
120 if ((nb & (nb - 1)) == 0) {
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
121 if (nb == 0)
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
122 nb_alloc = 1;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
123 else
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
124 nb_alloc = nb * 2;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
125 tab = av_realloc(tab, nb_alloc * sizeof(unsigned long));
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
126 *tab_ptr = tab;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
127 }
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
128 tab[nb++] = elem;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
129 *nb_ptr = nb;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
130 }
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
131