From 47fc08bffe94d33c88caafd084fa24e31e902798 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 3 Jan 2013 09:51:35 +0100 Subject: exclude: convert to C++ --- Makefile.am | 3 +- src/ExcludeList.cxx | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ExcludeList.hxx | 49 +++++++++++++++++++++++++++ src/UpdateWalk.cxx | 2 +- src/exclude.c | 93 --------------------------------------------------- src/exclude.h | 51 ---------------------------- 6 files changed, 147 insertions(+), 147 deletions(-) create mode 100644 src/ExcludeList.cxx create mode 100644 src/ExcludeList.hxx delete mode 100644 src/exclude.c delete mode 100644 src/exclude.h diff --git a/Makefile.am b/Makefile.am index fb1ff80f2..dd8b58952 100644 --- a/Makefile.am +++ b/Makefile.am @@ -82,7 +82,6 @@ mpd_headers = \ src/encoder_plugin.h \ src/encoder_list.h \ src/encoder_api.h \ - src/exclude.h \ src/fd_util.h \ src/gerror.h \ src/glib_compat.h \ @@ -232,7 +231,7 @@ src_mpd_SOURCES = \ src/DatabasePlugin.hxx \ src/DatabaseVisitor.hxx \ src/DatabaseSelection.cxx src/DatabaseSelection.hxx \ - src/exclude.c \ + src/ExcludeList.cxx src/ExcludeList.hxx \ src/fd_util.c \ src/fifo_buffer.c src/fifo_buffer.h \ src/growing_fifo.c src/growing_fifo.h \ diff --git a/src/ExcludeList.cxx b/src/ExcludeList.cxx new file mode 100644 index 000000000..e71a99203 --- /dev/null +++ b/src/ExcludeList.cxx @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2003-2011 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * The .mpdignore backend code. + * + */ + +#include "config.h" +#include "ExcludeList.hxx" + +extern "C" { +#include "path.h" +} + +#include +#include +#include +#include + +GSList * +exclude_list_load(const char *path_fs) +{ + assert(path_fs != NULL); + + FILE *file = fopen(path_fs, "r"); + if (file == NULL) { + if (errno != ENOENT) { + char *path_utf8 = fs_charset_to_utf8(path_fs); + g_debug("Failed to open %s: %s", + path_utf8, g_strerror(errno)); + g_free(path_utf8); + } + + return NULL; + } + + GSList *list = NULL; + char line[1024]; + while (fgets(line, sizeof(line), file) != NULL) { + char *p = strchr(line, '#'); + if (p != NULL) + *p = 0; + + p = g_strstrip(line); + if (*p != 0) + list = g_slist_prepend(list, g_pattern_spec_new(p)); + } + + fclose(file); + + return list; +} + +void +exclude_list_free(GSList *list) +{ + while (list != NULL) { + GPatternSpec *pattern = (GPatternSpec *)list->data; + g_pattern_spec_free(pattern); + list = g_slist_remove(list, list->data); + } +} + +bool +exclude_list_check(GSList *list, const char *name_fs) +{ + assert(name_fs != NULL); + + /* XXX include full path name in check */ + + for (; list != NULL; list = list->next) { + GPatternSpec *pattern = (GPatternSpec *)list->data; + + if (g_pattern_match_string(pattern, name_fs)) + return true; + } + + return false; +} diff --git a/src/ExcludeList.hxx b/src/ExcludeList.hxx new file mode 100644 index 000000000..52ba377b5 --- /dev/null +++ b/src/ExcludeList.hxx @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2003-2011 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * The .mpdignore backend code. + * + */ + +#ifndef MPD_EXCLUDE_H +#define MPD_EXCLUDE_H + +#include + +/** + * Loads and parses a .mpdignore file. + */ +GSList * +exclude_list_load(const char *path_fs); + +/** + * Frees a list returned by exclude_list_load(). + */ +void +exclude_list_free(GSList *list); + +/** + * Checks whether one of the patterns in the .mpdignore file matches + * the specified file name. + */ +bool +exclude_list_check(GSList *list, const char *name_fs); + +#endif diff --git a/src/UpdateWalk.cxx b/src/UpdateWalk.cxx index eb0565832..909687f46 100644 --- a/src/UpdateWalk.cxx +++ b/src/UpdateWalk.cxx @@ -29,9 +29,9 @@ #include "song.h" #include "PlaylistVector.hxx" #include "Mapper.hxx" +#include "ExcludeList.hxx" extern "C" { -#include "exclude.h" #include "uri.h" #include "path.h" #include "playlist_list.h" diff --git a/src/exclude.c b/src/exclude.c deleted file mode 100644 index fecc859cb..000000000 --- a/src/exclude.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/* - * The .mpdignore backend code. - * - */ - -#include "config.h" -#include "exclude.h" -#include "path.h" - -#include -#include -#include -#include - -GSList * -exclude_list_load(const char *path_fs) -{ - assert(path_fs != NULL); - - FILE *file = fopen(path_fs, "r"); - if (file == NULL) { - if (errno != ENOENT) { - char *path_utf8 = fs_charset_to_utf8(path_fs); - g_debug("Failed to open %s: %s", - path_utf8, g_strerror(errno)); - g_free(path_utf8); - } - - return NULL; - } - - GSList *list = NULL; - char line[1024]; - while (fgets(line, sizeof(line), file) != NULL) { - char *p = strchr(line, '#'); - if (p != NULL) - *p = 0; - - p = g_strstrip(line); - if (*p != 0) - list = g_slist_prepend(list, g_pattern_spec_new(p)); - } - - fclose(file); - - return list; -} - -void -exclude_list_free(GSList *list) -{ - while (list != NULL) { - GPatternSpec *pattern = list->data; - g_pattern_spec_free(pattern); - list = g_slist_remove(list, list->data); - } -} - -bool -exclude_list_check(GSList *list, const char *name_fs) -{ - assert(name_fs != NULL); - - /* XXX include full path name in check */ - - for (; list != NULL; list = list->next) { - GPatternSpec *pattern = list->data; - - if (g_pattern_match_string(pattern, name_fs)) - return true; - } - - return false; -} diff --git a/src/exclude.h b/src/exclude.h deleted file mode 100644 index 5b1229e29..000000000 --- a/src/exclude.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/* - * The .mpdignore backend code. - * - */ - -#ifndef MPD_EXCLUDE_H -#define MPD_EXCLUDE_H - -#include - -#include - -/** - * Loads and parses a .mpdignore file. - */ -GSList * -exclude_list_load(const char *path_fs); - -/** - * Frees a list returned by exclude_list_load(). - */ -void -exclude_list_free(GSList *list); - -/** - * Checks whether one of the patterns in the .mpdignore file matches - * the specified file name. - */ -bool -exclude_list_check(GSList *list, const char *name_fs); - -#endif -- cgit v1.2.3