annotate cutils.c @ 44:7c5da7e7239a libavformat

added basic png handling
author bellard
date Sat, 01 Feb 2003 20:53:57 +0000
parents 05318cf2e886
children b0e0eb595e29
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') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 if (toupper(*(unsigned char *)p) != toupper(*(unsigned char *)q))
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