Mercurial > mplayer.hg
changeset 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 | 2c02269701bd |
children | e1539e14d60f |
files | Makefile gui/interface.c gui/interface.h gui/ui/gtk/preferences.c gui/util/list.c gui/util/list.h |
diffstat | 6 files changed, 96 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Thu Jul 07 10:16:22 2011 +0000 +++ b/Makefile Thu Jul 07 10:37:58 2011 +0000 @@ -541,6 +541,7 @@ gui/ui/sub.c \ gui/ui/widgets.c \ gui/util/cut.c \ + gui/util/list.c \ gui/util/string.c \ gui/wm/ws.c \ gui/wm/wsxdnd.c \
--- a/gui/interface.c Thu Jul 07 10:16:22 2011 +0000 +++ b/gui/interface.c Thu Jul 07 10:37:58 2011 +0000 @@ -24,6 +24,7 @@ #include "skin/skin.h" #include "ui/gmplayer.h" #include "ui/widgets.h" +#include "util/list.h" #include "util/mem.h" #include "util/string.h" #include "wm/ws.h" @@ -77,51 +78,6 @@ static int initialized; -/** - * \brief This actually creates a new list containing only one element... - */ -void gaddlist(char ***list, const char *entry) -{ - int i; - - if (*list) { - for (i = 0; (*list)[i]; i++) - free((*list)[i]); - - free(*list); - } - - *list = malloc(2 * sizeof(char **)); - (*list)[0] = gstrdup(entry); - (*list)[1] = NULL; -} - -/** - * \brief This replaces a string starting with search by replace. - * If not found, replace is appended. - */ -static void greplace(char ***list, const char *search, const char *replace) -{ - int i = 0; - int len = (search ? strlen(search) : 0); - - if (*list) { - for (i = 0; (*list)[i]; i++) { - if (search && (strncmp((*list)[i], search, len) == 0)) { - free((*list)[i]); - (*list)[i] = gstrdup(replace); - return; - } - } - - *list = realloc(*list, (i + 2) * sizeof(char *)); - } else - *list = malloc(2 * sizeof(char *)); - - (*list)[i] = gstrdup(replace); - (*list)[i + 1] = NULL; -} - void guiInit(void) { int i;
--- a/gui/interface.h Thu Jul 07 10:16:22 2011 +0000 +++ b/gui/interface.h Thu Jul 07 10:37:58 2011 +0000 @@ -211,7 +211,6 @@ extern float gtkEquChannels[6][10]; -void gaddlist(char ***list, const char *entry); void gmp_msg(int mod, int lev, const char *format, ...); void *gtkSet(int cmd, float fparam, void *vparam); void guiDone(void);
--- a/gui/ui/gtk/preferences.c Thu Jul 07 10:16:22 2011 +0000 +++ b/gui/ui/gtk/preferences.c Thu Jul 07 10:37:58 2011 +0000 @@ -44,6 +44,7 @@ #include "gui/interface.h" #include "gui/ui/gmplayer.h" #include "gui/ui/widgets.h" +#include "gui/util/list.h" #include "gui/util/mem.h" #include "gui/util/string.h" #include "preferences.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/util/list.c Thu Jul 07 10:37:58 2011 +0000 @@ -0,0 +1,68 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdlib.h> +#include <string.h> + +#include "list.h" +#include "string.h" + +/** + * \brief This actually creates a new list containing only one element... + */ +void gaddlist(char ***list, const char *entry) +{ + int i; + + if (*list) { + for (i = 0; (*list)[i]; i++) + free((*list)[i]); + + free(*list); + } + + *list = malloc(2 * sizeof(char **)); + (*list)[0] = gstrdup(entry); + (*list)[1] = NULL; +} + +/** + * \brief This replaces a string starting with search by replace. + * If not found, replace is appended. + */ +void greplace(char ***list, const char *search, const char *replace) +{ + int i = 0; + int len = (search ? strlen(search) : 0); + + if (*list) { + for (i = 0; (*list)[i]; i++) { + if (search && (strncmp((*list)[i], search, len) == 0)) { + free((*list)[i]); + (*list)[i] = gstrdup(replace); + return; + } + } + + *list = realloc(*list, (i + 2) * sizeof(char *)); + } else + *list = malloc(2 * sizeof(char *)); + + (*list)[i] = gstrdup(replace); + (*list)[i + 1] = NULL; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/util/list.h Thu Jul 07 10:37:58 2011 +0000 @@ -0,0 +1,25 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_GUI_LIST_H +#define MPLAYER_GUI_LIST_H + +void gaddlist(char ***list, const char *entry); +void greplace(char ***list, const char *search, const char *replace); + +#endif /* MPLAYER_GUI_LIST_H */