Mercurial > mplayer.hg
comparison gui/util/list.c @ 33741:962dc701989d
Create new file list.c for list related functions.
Move gaddlist() and greplace() from interface.c to list.c.
author | ib |
---|---|
date | Thu, 07 Jul 2011 10:37:58 +0000 |
parents | |
children | e1539e14d60f |
comparison
equal
deleted
inserted
replaced
33740:2c02269701bd | 33741:962dc701989d |
---|---|
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 | |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 | |
22 #include "list.h" | |
23 #include "string.h" | |
24 | |
25 /** | |
26 * \brief This actually creates a new list containing only one element... | |
27 */ | |
28 void gaddlist(char ***list, const char *entry) | |
29 { | |
30 int i; | |
31 | |
32 if (*list) { | |
33 for (i = 0; (*list)[i]; i++) | |
34 free((*list)[i]); | |
35 | |
36 free(*list); | |
37 } | |
38 | |
39 *list = malloc(2 * sizeof(char **)); | |
40 (*list)[0] = gstrdup(entry); | |
41 (*list)[1] = NULL; | |
42 } | |
43 | |
44 /** | |
45 * \brief This replaces a string starting with search by replace. | |
46 * If not found, replace is appended. | |
47 */ | |
48 void greplace(char ***list, const char *search, const char *replace) | |
49 { | |
50 int i = 0; | |
51 int len = (search ? strlen(search) : 0); | |
52 | |
53 if (*list) { | |
54 for (i = 0; (*list)[i]; i++) { | |
55 if (search && (strncmp((*list)[i], search, len) == 0)) { | |
56 free((*list)[i]); | |
57 (*list)[i] = gstrdup(replace); | |
58 return; | |
59 } | |
60 } | |
61 | |
62 *list = realloc(*list, (i + 2) * sizeof(char *)); | |
63 } else | |
64 *list = malloc(2 * sizeof(char *)); | |
65 | |
66 (*list)[i] = gstrdup(replace); | |
67 (*list)[i + 1] = NULL; | |
68 } |