* Move the filtering functions from lib/myopt.[ch] to src/filters.[ch].
* Add filters.[ch] to src/Makefile.am
* Add #include "filters.h" to main.c and archives.c so they still get
at the filterlist definition.
}
}
}
-
-struct filterlist *filters = NULL;
-
-void loadfilter(char *fn) {
- FILE *file;
- char linebuf[1024];
- struct filterlist *filtertail;
-
- file = fopen(fn, "r");
- if (!file) {
- warningf(_("failed to open filter file `%.255s' for reading"), fn);
- return;
- }
-
- while (fgets(linebuf, sizeof(linebuf), file)) {
- struct filterlist *filter;
-
- filter = m_malloc(sizeof(struct filterlist));
- if (!filter) {
- ohshite(_("Error allocating memory for filter entry"));
- }
- memset(filter, 0, sizeof(struct filterlist));
-
- if (linebuf[0] == '#' || linebuf[0] == '\n') {
- continue;
- }
-
- if (linebuf[strlen(linebuf) - 1] == '\n')
- linebuf[strlen(linebuf) - 1] = '\0';
-
- if (linebuf[0] == '+') {
- filter->positive = 1;
- } else if (linebuf[0] == '-') {
- filter->positive = 0;
- } else {
- warningf(_("Invalid filter line: `%.255s'"), linebuf);
- free(filter);
- continue;
- }
-
- filter->filterstring = strdup(&linebuf[1]);
- if (!filter->filterstring) {
- ohshite(_("Error allocating memory for filter entry"));
- }
-
- if (! filters) {
- filters = filter;
- filtertail = filter;
- } else {
- filtertail->next = filter;
- filtertail = filtertail->next;
- }
- }
-
- if (ferror(file))
- ohshite(_("read error in configuration file `%.255s'"), fn);
-
- if (fclose(file))
- ohshite(_("error closing configuration file `%.255s'"), fn);
-}
-
-void loadfilters(void) {
- struct dirent *dent;
- char *dirname = CONFIGDIR "/filters.d";
- DIR *dir = opendir(dirname);
- if (!dir) {
- if (errno == ENOENT)
- return NULL;
- else
- ohshite(_("Error opening filters.d"));
- }
-
- while ((dent = readdir(dir)) != NULL) {
- struct stat statbuf;
- char *file = m_malloc(strlen(dirname) + 1 + strlen(dent->d_name) + 1);
- if (!file)
- ohshite(_("Error allocating memory for file"));
- sprintf(file, "%s/%s", dirname, dent->d_name);
- if (stat(file, &statbuf) != 0) {
- ohshite(_("Error stating file"));
- }
- if (S_ISREG(statbuf.st_mode)) {
- loadfilter(file);
- }
- free(file);
- }
- closedir(dir);
-}
void myfileopt(const char* fn, const struct cmdinfo* cmdinfos);
void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos);
void loadcfgfile(const char *prog, const struct cmdinfo *cmdinfos);
-void loadfilter(char *fn);
-void loadfilters(void);
-
-struct filterlist {
- int positive;
- char *filterstring;
- struct filterlist *next;
-};
#endif /* MYOPT_H */
INCLUDES = \
-DLOCALEDIR=\"$(localedir)\" -I$(top_srcdir)/intl \
-DADMINDIR=\"$(admindir)\" \
+ -DCONFIGDIR=\"$(pkgconfdir)\" \
-I$(top_srcdir)/lib
processarc.c \
remove.c \
select.c \
- update.c
+ update.c \
+ filters.c filters.h
dpkg_LDADD = \
$(LIBINTL) ../lib/libdpkg.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
#include "filesdb.h"
#include "main.h"
#include "archives.h"
+#include "filters.h"
#define MAXCONFLICTORS 20
--- /dev/null
+/*
+ * dpkg - main program for package management
+ * filters.c - filtering routines for excluding bits of packages
+ *
+ * Copyright (C) 2007,2008 Tollef Fog Heen <tfheen@err.no>
+ *
+ * This 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,
+ * or (at your option) any later version.
+ *
+ * This 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.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+
+#include <dpkg.h>
+
+#include "filters.h"
+
+struct filterlist *filters = NULL;
+
+void loadfilter(char *fn) {
+ FILE *file;
+ char linebuf[1024];
+ struct filterlist *filtertail;
+
+ file = fopen(fn, "r");
+ if (!file) {
+ warningf(_("failed to open filter file `%.255s' for reading"), fn);
+ return;
+ }
+
+ while (fgets(linebuf, sizeof(linebuf), file)) {
+ struct filterlist *filter;
+
+ filter = m_malloc(sizeof(struct filterlist));
+ if (!filter) {
+ ohshite(_("Error allocating memory for filter entry"));
+ }
+ memset(filter, 0, sizeof(struct filterlist));
+
+ if (linebuf[0] == '#' || linebuf[0] == '\n') {
+ continue;
+ }
+
+ if (linebuf[strlen(linebuf) - 1] == '\n')
+ linebuf[strlen(linebuf) - 1] = '\0';
+
+ if (linebuf[0] == '+') {
+ filter->positive = 1;
+ } else if (linebuf[0] == '-') {
+ filter->positive = 0;
+ } else {
+ warningf(_("Invalid filter line: `%.255s'"), linebuf);
+ free(filter);
+ continue;
+ }
+
+ filter->filterstring = strdup(&linebuf[1]);
+ if (!filter->filterstring) {
+ ohshite(_("Error allocating memory for filter entry"));
+ }
+
+ if (! filters) {
+ filters = filter;
+ filtertail = filter;
+ } else {
+ filtertail->next = filter;
+ filtertail = filtertail->next;
+ }
+ }
+
+ if (ferror(file))
+ ohshite(_("read error in configuration file `%.255s'"), fn);
+
+ if (fclose(file))
+ ohshite(_("error closing configuration file `%.255s'"), fn);
+}
+
+void loadfilters(void) {
+ struct dirent *dent;
+ char *dirname = CONFIGDIR "/filters.d";
+ DIR *dir = opendir(dirname);
+ if (!dir) {
+ if (errno == ENOENT)
+ return NULL;
+ else
+ ohshite(_("Error opening filters.d"));
+ }
+
+ while ((dent = readdir(dir)) != NULL) {
+ struct stat statbuf;
+ char *file = m_malloc(strlen(dirname) + 1 + strlen(dent->d_name) + 1);
+ if (!file)
+ ohshite(_("Error allocating memory for file"));
+ sprintf(file, "%s/%s", dirname, dent->d_name);
+ if (stat(file, &statbuf) != 0) {
+ ohshite(_("Error stating file"));
+ }
+ if (S_ISREG(statbuf.st_mode)) {
+ loadfilter(file);
+ }
+ free(file);
+ }
+ closedir(dir);
+}
--- /dev/null
+/*
+ * dpkg - main program for package management
+ * filters.h - external definitions for filter handling
+ *
+ * Copyright (C) 2007,2008 Tollef Fog Heen <tfheen@err.no>
+ *
+ * This 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,
+ * or (at your option) any later version.
+ *
+ * This 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.
+ */
+
+void loadfilter(char *fn);
+void loadfilters(void);
+
+struct filterlist {
+ int positive;
+ char *filterstring;
+ struct filterlist *next;
+};
+
#include <myopt.h>
#include "main.h"
+#include "filters.h"
static void printversion(void) {
if (printf(_("Debian `%s' package management program version %s.\n"),