From 80c980184660f1de5cc84118d9db7283933798e5 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 21 May 2008 21:24:53 +0300 Subject: [PATCH] Fix coding style --- src/filters.c | 241 +++++++++++++++++++++++++++----------------------- src/filters.h | 12 +-- 2 files changed, 137 insertions(+), 116 deletions(-) diff --git a/src/filters.c b/src/filters.c index 98002a19..88aeb719 100644 --- a/src/filters.c +++ b/src/filters.c @@ -38,120 +38,141 @@ #include "main.h" static struct filterlist *filters = NULL; - static struct filterlist **filtertail = &filters; - -static void loadfilter(const char *fn) { - FILE *file; - char linebuf[1024]; - - 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)); - 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")); - } - - *filtertail = filter; - filtertail = &filter->next; - } - - if (ferror(file)) - ohshite(_("read error in configuration file `%.255s'"), fn); - - if (fclose(file)) - ohshite(_("error closing configuration file `%.255s'"), fn); +static struct filterlist **filtertail = &filters; + +static void +loadfilter(const char *fn) +{ + FILE *file; + char linebuf[1024]; + + 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)); + 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")); + + *filtertail = filter; + filtertail = &filter->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; - 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); - 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 +loadfilters(void) +{ + struct dirent *dent; + char *dirname = CONFIGDIR "/filters.d"; + DIR *dir = opendir(dirname); + + if (!dir) { + if (errno == ENOENT) + return; + 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); + + sprintf(file, "%s/%s", dirname, dent->d_name); + if (stat(file, &statbuf) != 0) + ohshite(_("error stating file '%s'"), file); + if (S_ISREG(statbuf.st_mode)) + loadfilter(file); + free(file); + } + closedir(dir); } -int filter_should_skip(struct TarInfo *ti) { - int remove = 0; - if (filters) { - struct filterlist *f; - - /* Last match wins */ - for (f = filters; f != NULL; f = f->next) { - debug(dbg_eachfile, "tarobject comparing '%s' and '%s'", &ti->Name[1], f->filterstring); - if (fnmatch(f->filterstring, &ti->Name[1], 0) == 0) { - if (f->positive == 0) { - remove = 1; - debug(dbg_eachfile, "do_filter removing %s", ti->Name); - } else { - remove = 0; - debug(dbg_eachfile, "do_filter including %s", ti->Name); +static int +do_filter_should_skip(struct TarInfo *ti) +{ + int remove = 0; + struct filterlist *f; + + /* Last match wins. */ + for (f = filters; f != NULL; f = f->next) { + debug(dbg_eachfile, "tarobject comparing '%s' and '%s'", + &ti->Name[1], f->filterstring); + + if (fnmatch(f->filterstring, &ti->Name[1], 0) == 0) { + if (f->positive == 0) { + remove = 1; + debug(dbg_eachfile, "do_filter removing %s", + ti->Name); + } else { + remove = 0; + debug(dbg_eachfile, "do_filter including %s", + ti->Name); + } + } } - } - } - - if (remove) { - for (f = filters; f != NULL; f = f->next) { - char *pattern; - - pattern = m_malloc(strlen(ti->Name) + 1); - strcpy(pattern, &ti->Name[1]); - strcat(pattern, "*"); - - debug(dbg_eachfile, - "tarobject seeing if '%s' needs to be reincluded", &ti->Name[1]); - if ((f->positive == 1) && - (ti->Type == Directory) && - (fnmatch(pattern, f->filterstring, 0) == 0)) { - remove = 0; - debug(dbg_eachfile, "tarobject reincluding %s", ti->Name); + + if (remove) { + for (f = filters; f != NULL; f = f->next) { + char *pattern; + + pattern = m_malloc(strlen(ti->Name) + 1); + strcpy(pattern, &ti->Name[1]); + strcat(pattern, "*"); + + debug(dbg_eachfile, + "tarobject seeing if '%s' needs to be reincluded", + &ti->Name[1]); + if ((f->positive == 1) && + (ti->Type == Directory) && + (fnmatch(pattern, f->filterstring, 0) == 0)) { + remove = 0; + debug(dbg_eachfile, "tarobject reincluding %s", + ti->Name); + } + } } - } - } - } - return remove; + + return remove; +} + +int +filter_should_skip(struct TarInfo *ti) +{ + if (filters) + return do_filter_should_skip(ti); + else + return 0; } + diff --git a/src/filters.h b/src/filters.h index 540337ce..993f5286 100644 --- a/src/filters.h +++ b/src/filters.h @@ -14,9 +14,9 @@ * 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. + * 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. */ #ifndef DPKG_FILTERS_H @@ -28,9 +28,9 @@ void loadfilters(void); int filter_should_skip(struct TarInfo *ti); struct filterlist { - int positive; - char *filterstring; - struct filterlist *next; + int positive; + char *filterstring; + struct filterlist *next; }; #endif -- 2.39.5