From df095ad14d4217ab3223862f3a6b9a2134c709b2 Mon Sep 17 00:00:00 2001 From: "graham.gower" Date: Fri, 11 Dec 2009 03:04:53 +0000 Subject: [PATCH] Remove args_t and cleanup unused stuff. git-svn-id: http://opkg.googlecode.com/svn/trunk@484 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- libopkg/args.c | 28 +++++----------------------- libopkg/args.h | 16 +--------------- libopkg/libopkg.c | 28 ++++++++++++++-------------- libopkg/opkg.c | 9 +-------- libopkg/opkg_conf.c | 33 ++++++++++++++++++++------------- libopkg/opkg_conf.h | 8 ++++++-- 6 files changed, 47 insertions(+), 75 deletions(-) diff --git a/libopkg/args.c b/libopkg/args.c index bc2fb61..aa24f7c 100644 --- a/libopkg/args.c +++ b/libopkg/args.c @@ -46,25 +46,7 @@ enum long_args_opt ARGS_OPT_CACHE, }; -void args_init(args_t *args) -{ - memset(args, 0, sizeof(args_t)); - - args->dest = ARGS_DEFAULT_DEST; - - sprintf_alloc(&args->conf_file, "%s/%s", OPKGETCDIR, - ARGS_DEFAULT_CONF_FILE_NAME); - conf->verbosity = ARGS_DEFAULT_VERBOSITY; -} - -void args_deinit(args_t *args) -{ - free (args->dest); - free(args->conf_file); - args->conf_file = NULL; -} - -int args_parse(args_t *args, int argc, char *argv[]) +int args_parse(int argc, char *argv[]) { int c; int option_index = 0; @@ -120,11 +102,10 @@ int args_parse(args_t *args, int argc, char *argv[]) conf->query_all = 1; break; case 'd': - args->dest = xstrdup(optarg); + conf->dest_str = xstrdup(optarg); break; case 'f': - free(args->conf_file); - args->conf_file = xstrdup(optarg); + conf->conf_file = xstrdup(optarg); break; case 'o': conf->offline_root = xstrdup(optarg); @@ -240,7 +221,8 @@ void args_usage(const char *complaint) printf("\t 4 debug level 2\n"); printf("\t-f Use as the opkg configuration file\n"); printf("\t--conf Default configuration file location\n"); - printf(" is %s/%s\n", ARGS_DEFAULT_CONF_FILE_DIR, ARGS_DEFAULT_CONF_FILE_NAME); + printf(" is %s/opkg.conf\n", + OPKG_CONF_DEFAULT_CONF_FILE_DIR); printf("\t--cache Use a package cache\n"); printf("\t-d Use as the the root directory for\n"); printf("\t--dest package installation, removal, upgrading.\n"); diff --git a/libopkg/args.h b/libopkg/args.h index 82bae56..99782a0 100644 --- a/libopkg/args.h +++ b/libopkg/args.h @@ -18,21 +18,7 @@ #ifndef ARGS_H #define ARGS_H -struct args -{ - char *conf_file; - char *dest; -}; -typedef struct args args_t; - -#define ARGS_DEFAULT_CONF_FILE_DIR OPKGETCDIR"/opkg" -#define ARGS_DEFAULT_CONF_FILE_NAME "opkg.conf" -#define ARGS_DEFAULT_DEST NULL -#define ARGS_DEFAULT_VERBOSITY 1 - -void args_init(args_t *args); -void args_deinit(args_t *args); -int args_parse(args_t *args, int argc, char *argv[]); +int args_parse(int argc, char *argv[]); void args_usage(const char *complaint); #endif diff --git a/libopkg/libopkg.c b/libopkg/libopkg.c index f6f6fe9..3ff6085 100644 --- a/libopkg/libopkg.c +++ b/libopkg/libopkg.c @@ -16,29 +16,28 @@ */ #include "includes.h" -#include "libopkg.h" -#include "args.h" #include "opkg_conf.h" #include "opkg_cmd.h" #include "file_util.h" +#include "args.h" +#include "opkg_download.h" #include "opkg_message.h" -/* This is used for backward compatibility */ +/* This is used for backwards compatibility */ int opkg_op (int argc, char *argv[]) { - int err, opts; - args_t args; + int opts; char *cmd_name; opkg_cmd_t *cmd; int nocheckfordirorfile = 0; int noreadfeedsfile = 0; - args_init (&args); + conf->verbosity = NOTICE; - opts = args_parse (&args, argc, argv); + opts = args_parse (argc, argv); if (opts == argc || opts < 0) { args_usage ("opkg must have one sub-command argument"); @@ -74,18 +73,16 @@ opkg_op (int argc, char *argv[]) conf->pfm = cmd->pfm; - err = opkg_conf_init (&args); - args_deinit (&args); - if (err) + if(opkg_conf_init()) goto err0; if (!nocheckfordirorfile) { if (!noreadfeedsfile) { - if ((err = pkg_hash_load_feeds())) + if (pkg_hash_load_feeds()) goto err1; } - if ((err = pkg_hash_load_status_files())) + if (pkg_hash_load_status_files()) goto err1; } @@ -97,9 +94,12 @@ opkg_op (int argc, char *argv[]) args_usage (NULL); } - err = opkg_cmd_exec (cmd, argc - opts, (const char **) (argv + opts)); + if (opkg_cmd_exec (cmd, argc - opts, (const char **) (argv + opts))) + goto err2; + return 0; +err2: #ifdef HAVE_CURL opkg_curl_cleanup(); #endif @@ -110,5 +110,5 @@ err0: print_error_list(); free_error_list(); - return err; + return -1; } diff --git a/libopkg/opkg.c b/libopkg/opkg.c index 383dfb5..7f9862b 100644 --- a/libopkg/opkg.c +++ b/libopkg/opkg.c @@ -20,7 +20,6 @@ #include "opkg.h" #include "opkg_conf.h" -#include "args.h" #include "opkg_install.h" #include "opkg_configure.h" @@ -115,15 +114,9 @@ curl_progress_cb(struct _curl_cb_data *cb_data, double t, /* dltotal */ int opkg_new() { - args_t args; - - args_init(&args); - - if (opkg_conf_init(&args)) + if (opkg_conf_init()) goto err0; - args_deinit(&args); - if (pkg_hash_load_feeds()) goto err1; diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c index 1afa612..6ba246b 100644 --- a/libopkg/opkg_conf.c +++ b/libopkg/opkg_conf.c @@ -84,14 +84,15 @@ opkg_option_t options[] = { }; static int -resolve_pkg_dest_list(nv_pair_list_t *nv_pair_list, const char *default_dest_name) +resolve_pkg_dest_list(nv_pair_list_t *nv_pair_list) { nv_pair_list_elt_t *iter; nv_pair_t *nv_pair; pkg_dest_t *dest; char *root_dir; - for (iter = nv_pair_list_first(nv_pair_list); iter; iter = nv_pair_list_next(nv_pair_list, iter)) { + for (iter = nv_pair_list_first(nv_pair_list); iter; + iter = nv_pair_list_next(nv_pair_list, iter)) { nv_pair = (nv_pair_t *)iter->data; if (conf->offline_root) { @@ -106,14 +107,14 @@ resolve_pkg_dest_list(nv_pair_list_t *nv_pair_list, const char *default_dest_nam if (conf->default_dest == NULL) conf->default_dest = dest; - if (default_dest_name && !strcmp(dest->name, default_dest_name)) { + if (conf->dest_str && !strcmp(dest->name, conf->dest_str)) { conf->default_dest = dest; conf->restrict_to_default_dest = 1; } } - if (default_dest_name && !conf->restrict_to_default_dest) { - opkg_msg(ERROR, "Unknown dest name: `%s'.\n", default_dest_name); + if (conf->dest_str && !conf->restrict_to_default_dest) { + opkg_msg(ERROR, "Unknown dest name: `%s'.\n", conf->dest_str); return -1; } @@ -375,7 +376,7 @@ root_filename_alloc(char *filename) } int -opkg_conf_init(const args_t *args) +opkg_conf_init(void) { int err; char *tmp_dir_base, *tmp2; @@ -400,11 +401,11 @@ opkg_conf_init(const args_t *args) if (!conf->offline_root) conf->offline_root = xstrdup(getenv("OFFLINE_ROOT")); - if (args->conf_file) { + if (conf->conf_file) { struct stat stat_buf; - err = stat(args->conf_file, &stat_buf); + err = stat(conf->conf_file, &stat_buf); if (err == 0) - if (opkg_conf_parse_file(args->conf_file, + if (opkg_conf_parse_file(conf->conf_file, &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) { /* Memory leakage from opkg_conf_parse-file */ return -1; @@ -416,7 +417,7 @@ opkg_conf_init(const args_t *args) else { const char *conf_file_dir = getenv("OPKG_CONF_DIR"); if (conf_file_dir == NULL) - conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR; + conf_file_dir = OPKG_CONF_DEFAULT_CONF_FILE_DIR; sprintf_alloc(&etc_opkg_conf_pattern, "%s/*.conf", conf_file_dir); } memset(&globbuf, 0, sizeof(globbuf)); @@ -426,8 +427,8 @@ opkg_conf_init(const args_t *args) int i; for (i = 0; i < globbuf.gl_pathc; i++) { if (globbuf.gl_pathv[i]) - if (args->conf_file && - !strcmp(args->conf_file, globbuf.gl_pathv[i])) + if (conf->conf_file && + !strcmp(conf->conf_file, globbuf.gl_pathv[i])) continue; if ( opkg_conf_parse_file(globbuf.gl_pathv[i], &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) { @@ -502,7 +503,7 @@ opkg_conf_init(const args_t *args) OPKG_CONF_DEFAULT_DEST_ROOT_DIR); } - err = resolve_pkg_dest_list(&tmp_dest_nv_pair_list, args->dest); + err = resolve_pkg_dest_list(&tmp_dest_nv_pair_list); nv_pair_list_deinit(&tmp_dest_nv_pair_list); if (err) @@ -521,6 +522,12 @@ opkg_conf_deinit(void) free(conf->lists_dir); + if (conf->dest_str) + free(conf->dest_str); + + if (conf->conf_file) + free(conf->conf_file); + pkg_src_list_deinit(&conf->pkg_src_list); pkg_dest_list_deinit(&conf->pkg_dest_list); nv_pair_list_deinit(&conf->arch_list); diff --git a/libopkg/opkg_conf.h b/libopkg/opkg_conf.h index a268bba..67b660f 100644 --- a/libopkg/opkg_conf.h +++ b/libopkg/opkg_conf.h @@ -22,7 +22,6 @@ typedef struct opkg_conf opkg_conf_t; extern opkg_conf_t *conf; #include "hash_table.h" -#include "args.h" #include "pkg.h" #include "pkg_hash.h" #include "pkg_src_list.h" @@ -33,6 +32,8 @@ extern opkg_conf_t *conf; #define OPKG_CONF_TMP_DIR_SUFFIX "opkg-XXXXXX" #define OPKG_CONF_LISTS_DIR OPKG_STATE_DIR_PREFIX "/lists" +#define OPKG_CONF_DEFAULT_CONF_FILE_DIR OPKGETCDIR"/opkg" + /* In case the config file defines no dest */ #define OPKG_CONF_DEFAULT_DEST_NAME "root" #define OPKG_CONF_DEFAULT_DEST_ROOT_DIR "/" @@ -47,6 +48,9 @@ struct opkg_conf int restrict_to_default_dest; pkg_dest_t *default_dest; + char *dest_str; + + char *conf_file; char *tmp_dir; char *lists_dir; @@ -120,7 +124,7 @@ struct opkg_option { void * const value; }; -int opkg_conf_init(const args_t *args); +int opkg_conf_init(void); void opkg_conf_deinit(void); int opkg_conf_write_status_files(void); -- 2.25.1