Mercurial > mplayer.hg
annotate gui/util/string.c @ 34102:dd8320c2a2cb
libmpcodec: add vf_lavfi.
This filter wraps a complete libavfilter filter graph.
As the API of libavfilter is not completely stable yet, the filter is not
enabled by default, so as not to let mplayer unbuildable.
Some strange behaviours may appear due to the very different model of buffer
allocation between mplayer and lavfi.
author | cigaes |
---|---|
date | Wed, 12 Oct 2011 11:38:10 +0000 |
parents | d7527ee45784 |
children | a345e7162d0a |
rev | line source |
---|---|
33048 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
18 | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
19 #include <stdio.h> |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
20 #include <stdlib.h> |
33737 | 21 #include <string.h> |
22 | |
33048 | 23 #include "string.h" |
24 | |
33982 | 25 /** |
26 * @brief Convert a string to lower case. | |
27 * | |
28 * @param string to be converted | |
29 * | |
30 * @return converted string | |
31 * | |
32 * @note Only characters from A to Z will be converted and this is an in-place conversion. | |
33 */ | |
33052 | 34 char *strlower(char *in) |
35 { | |
36 char *p = in; | |
37 | |
38 while (*p) { | |
39 if (*p >= 'A' && *p <= 'Z') | |
40 *p += 'a' - 'A'; | |
41 | |
42 p++; | |
43 } | |
44 | |
45 return in; | |
46 } | |
47 | |
33982 | 48 /** |
49 * @brief Swap characters in a string. | |
50 * | |
51 * @param in string to be processed | |
52 * @param from character to be swapped | |
53 * @param to character to swap in | |
54 * | |
55 * @return processed string | |
56 * | |
57 * @note All occurrences will be swapped and this is an in-place processing. | |
58 */ | |
33048 | 59 char *strswap(char *in, char from, char to) |
60 { | |
33049 | 61 char *p = in; |
33048 | 62 |
33049 | 63 while (*p) { |
64 if (*p == from) | |
65 *p = to; | |
33048 | 66 |
33049 | 67 p++; |
68 } | |
33048 | 69 |
70 return in; | |
71 } | |
72 | |
33982 | 73 /** |
74 * @brief Remove all space characters from a string, | |
75 * but leave text enclosed in quotation marks untouched. | |
76 * | |
77 * @param in string to be processed | |
78 * | |
79 * @return processed string | |
80 * | |
81 * @note This is an in-place processing. | |
82 */ | |
33048 | 83 char *trim(char *in) |
84 { | |
33051 | 85 char *src, *dest; |
86 int freeze = 0; | |
33048 | 87 |
33051 | 88 src = dest = in; |
33048 | 89 |
33051 | 90 while (*src) { |
91 if (*src == '"') | |
92 freeze = !freeze; | |
33048 | 93 |
33051 | 94 if (freeze || (*src != ' ')) |
95 *dest++ = *src; | |
96 | |
97 src++; | |
33048 | 98 } |
99 | |
33051 | 100 *dest = 0; |
101 | |
33048 | 102 return in; |
103 } | |
33073 | 104 |
33982 | 105 /** |
106 * @brief Remove a comment from a string, | |
107 * but leave text enclosed in quotation marks untouched. | |
108 * | |
109 * A comment starts either with a semicolon anywhere in the string | |
110 * or with a number sign character at the very beginning. | |
111 * | |
112 * @param in string to be processed | |
113 * | |
114 * @return string without comment | |
115 * | |
116 * @note This is an in-place processing, i.e. @a in will be shortened. | |
117 */ | |
33073 | 118 char *decomment(char *in) |
119 { | |
120 char *p; | |
121 int nap = 0; | |
122 | |
123 p = in; | |
124 | |
33080 | 125 if (*p == '#') |
126 *p = 0; | |
127 | |
33073 | 128 while (*p) { |
129 if (*p == '"') | |
130 nap = !nap; | |
131 | |
132 if ((*p == ';') && !nap) { | |
133 *p = 0; | |
134 break; | |
135 } | |
136 | |
137 p++; | |
138 } | |
139 | |
140 return in; | |
141 } | |
33737 | 142 |
143 char *gstrchr(const char *str, int c) | |
144 { | |
145 if (!str) | |
146 return NULL; | |
147 | |
148 return strchr(str, c); | |
149 } | |
150 | |
151 int gstrcmp(const char *a, const char *b) | |
152 { | |
153 if (!a && !b) | |
154 return 0; | |
155 if (!a || !b) | |
156 return -1; | |
157 | |
158 return strcmp(a, b); | |
159 } | |
160 | |
33786 | 161 int gstrcasecmp(const char *a, const char *b) |
162 { | |
163 if (!a && !b) | |
164 return 0; | |
165 if (!a || !b) | |
166 return -1; | |
167 | |
168 return strcasecmp(a, b); | |
169 } | |
170 | |
33737 | 171 int gstrncmp(const char *a, const char *b, int n) |
172 { | |
173 if (!a && !b) | |
174 return 0; | |
175 if (!a || !b) | |
176 return -1; | |
177 | |
178 return strncmp(a, b, n); | |
179 } | |
180 | |
33982 | 181 /** |
182 * @brief Duplicate a string. | |
183 * | |
184 * If @a str is NULL, it returns NULL. | |
185 * The string is duplicated by calling strdup(). | |
186 * | |
187 * @param str string to be duplicated | |
188 * | |
189 * @return duplicated string (newly allocated) | |
190 */ | |
33737 | 191 char *gstrdup(const char *str) |
192 { | |
193 if (!str) | |
194 return NULL; | |
195 | |
196 return strdup(str); | |
197 } | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
198 |
33982 | 199 /** |
200 * @brief Assign a duplicated string. | |
201 * | |
202 * The string is duplicated by calling #gstrdup(). | |
203 * | |
204 * @note @a *old is freed prior to the assignment. | |
205 * | |
206 * @param old pointer to a variable suitable to store the new pointer | |
207 * @param str string to be duplicated | |
208 */ | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
209 void setdup(char **old, const char *str) |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
210 { |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
211 free(*old); |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
212 *old = gstrdup(str); |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
213 } |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
214 |
33982 | 215 /** |
216 * @brief Assign a newly allocated string | |
217 * containing the path created from a directory and a filename. | |
218 * | |
219 * @note @a *old is freed prior to the assignment. | |
220 * | |
221 * @param old pointer to a variable suitable to store the new pointer | |
222 * @param dir directory | |
223 * @param name filename | |
224 */ | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
225 void setddup(char **old, const char *dir, const char *name) |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
226 { |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
227 free(*old); |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
228 *old = malloc(strlen(dir) + strlen(name) + 2); |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
229 if (*old) |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
230 sprintf(*old, "%s/%s", dir, name); |
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33737
diff
changeset
|
231 } |