diff options
author | Dave Reisner <dreisner@archlinux.org> | 2014-11-16 18:01:12 -0500 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2014-11-16 18:04:08 -0500 |
commit | 9bc85c516bed428b1bd8520f2c371d016af67a68 (patch) | |
tree | a8506729b319624f80bc16a85a1133f46187bb4b | |
parent | 3857cd02e80e371747005f358701a463b5365b04 (diff) | |
download | expac-9bc85c516bed428b1bd8520f2c371d016af67a68.tar.xz |
move flag parsing out of expac_new
-rw-r--r-- | conf.c | 9 | ||||
-rw-r--r-- | expac.c | 20 | ||||
-rw-r--r-- | expac.h | 3 | ||||
-rw-r--r-- | util.h | 1 |
4 files changed, 16 insertions, 17 deletions
@@ -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) { @@ -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; @@ -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 */ @@ -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) |