From 9bc85c516bed428b1bd8520f2c371d016af67a68 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 16 Nov 2014 18:01:12 -0500 Subject: move flag parsing out of expac_new --- conf.c | 9 +++++---- expac.c | 20 ++++++++++---------- expac.h | 3 +-- util.h | 1 - 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/conf.c b/conf.c index c4927c5..a0248c8 100644 --- a/conf.c +++ b/conf.c @@ -71,7 +71,8 @@ static int config_add_repo(config_t *config, char *reponame) { static int parse_one_file(config_t *config, const char *filename, char **section); static int parse_include(config_t *config, const char *include, char **section) { - _cleanup_(globfreep) glob_t globbuf = {}; + glob_t globbuf; + int r = 0; if (glob(include, GLOB_NOCHECK, NULL, &globbuf) != 0) { fprintf(stderr, "warning: globbing failed on '%s': out of memory\n", @@ -80,13 +81,13 @@ static int parse_include(config_t *config, const char *include, char **section) } for (size_t i = 0; i < globbuf.gl_pathc; ++i) { - int r; r = parse_one_file(config, globbuf.gl_pathv[i], section); if (r < 0) - return r; + break; } - return 0; + globfree(&globbuf); + return r; } static char *split_keyval(char *line, const char *sep) { diff --git a/expac.c b/expac.c index 0f23c01..7c912c0 100644 --- a/expac.c +++ b/expac.c @@ -657,23 +657,21 @@ void expac_free(Expac *expac) { alpm_release(expac->alpm); } -int expac_new(Expac **expac, int argc, char **argv) { +int expac_new(Expac **expac, const char *config_file) { Expac *e; enum _alpm_errno_t alpm_errno = 0; - config_t config = { NULL, 0, 0, NULL, NULL }; + config_t config; const char *dbroot = "/"; const char *dbpath = "/var/lib/pacman"; int r; - r = parse_options(argc, argv); - if (r < 0) - return r; - e = calloc(1, sizeof(*e)); if (e == NULL) return -ENOMEM; - r = config_parse(&config, opt_config_file); + memset(&config, 0, sizeof(config)); + + r = config_parse(&config, config_file); if (r < 0) return r; @@ -687,8 +685,6 @@ int expac_new(Expac **expac, int argc, char **argv) { if (!e->alpm) return -alpm_errno; - e->db_local = alpm_get_localdb(e->alpm); - for (int i = 0; i < config.size; ++i) alpm_register_syncdb(e->alpm, config.repos[i], 0); @@ -751,7 +747,11 @@ int main(int argc, char *argv[]) { Expac *expac; int r; - r = expac_new(&expac, argc, argv); + r = parse_options(argc, argv); + if (r < 0) + return 1; + + r = expac_new(&expac, opt_config_file); if (r < 0) return 1; diff --git a/expac.h b/expac.h index d3ba546..0d6c5b6 100644 --- a/expac.h +++ b/expac.h @@ -18,10 +18,9 @@ typedef enum SearchWhat { typedef struct Expac { alpm_handle_t *alpm; - alpm_db_t *db_local; } Expac; -int expac_new(Expac **expac, int argc, char **argv); +int expac_new(Expac **expac, const char *config_file); #endif /* _EXPAC_H */ diff --git a/util.h b/util.h index 6d50426..1dcddb6 100644 --- a/util.h +++ b/util.h @@ -7,7 +7,6 @@ static inline void freep(void *p) { free(*(void **)p); } static inline void fclosep(FILE **p) { if (*p) fclose(*p); } -static inline void globfreep(glob_t *p) { globfree(p); } #define _cleanup_(x) __attribute__((cleanup(x))) #define _cleanup_free_ _cleanup_(freep) -- cgit v1.2.3-54-g00ecf