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;
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);
printf("\t 4 debug level 2\n");
printf("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n");
printf("\t--conf <conf_file> 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 <directory> Use a package cache\n");
printf("\t-d <dest_name> Use <dest_name> as the the root directory for\n");
printf("\t--dest <dest_name> package installation, removal, upgrading.\n");
#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
*/
#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");
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;
}
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
print_error_list();
free_error_list();
- return err;
+ return -1;
}
#include "opkg.h"
#include "opkg_conf.h"
-#include "args.h"
#include "opkg_install.h"
#include "opkg_configure.h"
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;
};
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) {
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;
}
}
int
-opkg_conf_init(const args_t *args)
+opkg_conf_init(void)
{
int err;
char *tmp_dir_base, *tmp2;
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;
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));
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) {
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)
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);
extern opkg_conf_t *conf;
#include "hash_table.h"
-#include "args.h"
#include "pkg.h"
#include "pkg_hash.h"
#include "pkg_src_list.h"
#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 "/"
int restrict_to_default_dest;
pkg_dest_t *default_dest;
+ char *dest_str;
+
+ char *conf_file;
char *tmp_dir;
char *lists_dir;
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);