s/strdup/xstrdup/ - check memory allocations for failure.
[project/opkg-lede.git] / libopkg / args.c
index df02eef939f8b20ea9a5df72416abd12d94475f3..b7aafcdb6e5753af6a899a3a9d126923e366372b 100644 (file)
 #include "config.h"
 #include "args.h"
 #include "sprintf_alloc.h"
+#include "libbb/libbb.h"
 
 static void print_version(void);
 
 enum long_args_opt
 {
      ARGS_OPT_FORCE_DEFAULTS = 129,
+     ARGS_OPT_FORCE_MAINTAINER, 
      ARGS_OPT_FORCE_DEPENDS,
      ARGS_OPT_FORCE_OVERWRITE,
      ARGS_OPT_FORCE_DOWNGRADE,
@@ -46,10 +48,10 @@ enum long_args_opt
      ARGS_OPT_CACHE,
 };
 
+char *conf_file_dir;
+
 int args_init(args_t *args)
 {
-     char *conf_file_dir;
-
      if (!args) {
          return EFAULT;
      }
@@ -61,10 +63,11 @@ int args_init(args_t *args)
      if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
          conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
      }
-     sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
+     sprintf_alloc(&args->conf_file, "%s/%s", OPKGETCDIR,
                   ARGS_DEFAULT_CONF_FILE_NAME);
 
      args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
+     args->force_maintainer = ARGS_DEFAULT_FORCE_MAINTAINER;
      args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
      args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
      args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
@@ -76,6 +79,7 @@ int args_init(args_t *args)
      args->nodeps = ARGS_DEFAULT_NODEPS;
      args->verbosity = ARGS_DEFAULT_VERBOSITY;
      args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
+     args->offline_root_path = ARGS_DEFAULT_OFFLINE_ROOT_PATH;
      args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
      args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
      args->multiple_providers = 0;
@@ -88,6 +92,7 @@ int args_init(args_t *args)
 void args_deinit(args_t *args)
 {
      free (args->offline_root);
+     free (args->offline_root_path);
      free (args->offline_root_pre_script_cmd);
      free (args->offline_root_post_script_cmd);
 
@@ -112,6 +117,8 @@ int args_parse(args_t *args, int argc, char *argv[])
          {"dest", 1, 0, 'd'},
          {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
          {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
+          {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, 
+          {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, 
          {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
          {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
          {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
@@ -138,6 +145,8 @@ int args_parse(args_t *args, int argc, char *argv[])
          {"nodeps", 0, 0, ARGS_OPT_NODEPS},
          {"offline", 1, 0, 'o'},
          {"offline-root", 1, 0, 'o'},
+         {"offline-path", 1, 0, 'p'},
+         {"offline-root-path", 1, 0, 'p'},
          {"test", 0, 0, ARGS_OPT_NOACTION},
          {"tmp-dir", 1, 0, 't'},
          {"verbosity", 2, 0, 'V'},
@@ -146,7 +155,7 @@ int args_parse(args_t *args, int argc, char *argv[])
      };
 
      while (1) {
-         c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
+         c = getopt_long_only(argc, argv, "Ad:f:no:p:t:vV:", long_options, &option_index);
          if (c == -1)
               break;
 
@@ -155,20 +164,23 @@ int args_parse(args_t *args, int argc, char *argv[])
               args->query_all = 1;
               break;
          case 'd':
-              args->dest = strdup (optarg);
+              args->dest = xstrdup(optarg);
               break;
          case 'f':
               free(args->conf_file);
-              args->conf_file = strdup(optarg);
+              args->conf_file = xstrdup(optarg);
               break;
          case 'o':
-              args->offline_root = strdup (optarg);
+              args->offline_root = xstrdup(optarg);
+              break;
+         case 'p':
+              args->offline_root_path = xstrdup(optarg);
               break;
          case 'n':
               args->noaction = 1;
               break;
          case 't':
-              args->tmp_dir = strdup(optarg);
+              args->tmp_dir = xstrdup(optarg);
               break;
          case 'v':
               print_version();
@@ -185,11 +197,14 @@ int args_parse(args_t *args, int argc, char *argv[])
               break;
          case ARGS_OPT_CACHE:
               free(args->cache);
-              args->cache = strdup(optarg);
+              args->cache = xstrdup(optarg);
               break;
          case ARGS_OPT_FORCE_DEFAULTS:
               args->force_defaults = 1;
               break;
+          case ARGS_OPT_FORCE_MAINTAINER:
+               args->force_maintainer = 1;
+               break;
          case ARGS_OPT_FORCE_DEPENDS:
               args->force_depends = 1;
               break;
@@ -260,6 +275,7 @@ void args_usage(char *complaint)
      printf("\nInformational Commands:\n");
      printf("\tlist                    List available packages and descriptions\n");
      printf("\tlist_installed          List all and only the installed packages and description \n");
+     printf("\tlist_upgradable         List all the installed and upgradable packages\n");
      printf("\tfiles <pkg>             List all files belonging to <pkg>\n");
      printf("\tsearch <file|regexp>            Search for a package providing <file>\n");
      printf("\tinfo [pkg|regexp]               Display all info for <pkg>\n");
@@ -294,8 +310,10 @@ void args_usage(char *complaint)
      printf("                          directory name in a pinch).\n");
      printf("\t-o <offline_root>       Use <offline_root> as the root directory for\n");
      printf("\t-offline <offline_root> offline installation of packages.\n");
-    
-     printf("\tForce Options (use when opkg is too smart for its own good):\n");
+     printf("\t-p <path>               Path to utilities for runing postinst\n");
+     printf("\t-offline-path <path>    script in offline mode.\n");
+
+     printf("\nForce Options (use when opkg is too smart for its own good):\n");
      printf("\t-force-depends          Make dependency checks warnings instead of errors\n");
      printf("\t                                Install/remove package in spite of failed dependences\n");
      printf("\t-force-defaults         Use default options for questions asked by opkg.\n");