summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-28 18:33:32 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-04-28 18:33:32 (EDT)
commitf6a6b1c9dae1538b9fed7ab52b5ffd31cc411326 (patch)
treea429da20c41ee73852bc282ff942c718b5ff2d37 /src/main.c
parent88dd37d6cc8bf40fd8766b41add0ae17a9cd7065 (diff)
opk: Manage control file list and listing flag
Instead of main() doing so.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c81
1 files changed, 27 insertions, 54 deletions
diff --git a/src/main.c b/src/main.c
index 5a20236..3338fcc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,7 +27,6 @@
#include "defs.h"
#include "i18n.h"
#include "opk.h"
-#include "ustar.h"
#ifdef HAVE_GETOPT_LONG
#include <getopt.h>
@@ -146,11 +145,9 @@ _help_tip(const char *program_name)
int
main(int argc, char *argv[])
{
- const char *program_name;
- struct opkg_opk_ustar_seek_name *control_files;
- int list_members;
- int opt;
- struct opkg_opk_opk *opk;
+ const char *program_name;
+ struct opkg_opk_opk *opk;
+ int opt;
#ifdef ENABLE_NLS
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
@@ -161,9 +158,14 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
#endif
- program_name = argv[0];
- control_files = NULL;
- list_members = 0;
+ program_name = argv[0];
+
+ /* Initialize package. */
+ opk = opkg_opk_opk_init();
+ if (opk == NULL) {
+ return EXIT_FAILURE;
+ }
+
opterr = 0;
#ifdef HAVE_GETOPT_LONG
while ((opt = getopt_long(argc, argv, _optstring, _longopts, NULL))
@@ -173,21 +175,21 @@ main(int argc, char *argv[])
#endif
switch(opt) {
case 'I':
- if (opkg_opk_ustar_add_seek_name(&control_files,
- optarg) !=
- OPKG_OPK_OK) {
- goto error0;
+ if (opkg_opk_opk_print_control(opk, optarg)
+ != OPKG_OPK_OK) {
+ opkg_opk_opk_free(opk);
+ return EXIT_FAILURE;
}
break;
case 'f':
- if (opkg_opk_ustar_add_seek_name(&control_files,
- "control") !=
- OPKG_OPK_OK) {
- goto error0;
+ if (opkg_opk_opk_print_control(opk, "control")
+ != OPKG_OPK_OK) {
+ opkg_opk_opk_free(opk);
+ return EXIT_FAILURE;
}
break;
case 'c':
- list_members = 1;
+ opkg_opk_opk_list_data(opk);
break;
case 'h':
_help(program_name);
@@ -200,6 +202,7 @@ main(int argc, char *argv[])
"\"%c\"\n"),
program_name, optopt);
_help_tip(program_name);
+ opkg_opk_opk_free(opk);
return EXIT_FAILURE;
}
}
@@ -210,52 +213,22 @@ main(int argc, char *argv[])
fprintf(stderr, _("%s: Missing package file operand\n"),
program_name);
_help_tip(program_name);
+ opkg_opk_opk_free(opk);
return EXIT_FAILURE;
} else if (argc > 1) {
fprintf(stderr, _("%s: Too many package file operands\n"),
program_name);
_help_tip(program_name);
+ opkg_opk_opk_free(opk);
return EXIT_FAILURE;
}
- if (control_files == NULL && list_members == 0) {
- fprintf(stderr, _("%s: At least one of -I, -f, or -c must be "
- "given\n"), program_name);
- _help_tip(program_name);
- return EXIT_FAILURE;
- }
-
- /* Initialize outer archive. */
- opk = opkg_opk_opk_init(argv[0]);
- if (opk == NULL) {
- goto error0;
- }
- /* Read control file. */
- if (control_files != NULL) {
- if (opkg_opk_opk_read_control(opk, control_files) !=
- OPKG_OPK_OK) {
- goto error1;
- }
- }
-
- /* List data files. */
- if (list_members == 1) {
- if (opkg_opk_opk_list_members(opk) != OPKG_OPK_OK) {
- goto error1;
- }
+ /* Read package. */
+ if (opkg_opk_opk_read(opk, argv[0]) != OPKG_OPK_OK) {
+ opkg_opk_opk_free(opk);
+ return EXIT_FAILURE;
}
opkg_opk_opk_free(opk);
- if (control_files != NULL) {
- opkg_opk_ustar_free_seek_names(control_files);
- }
return EXIT_SUCCESS;
-
- error1:
- opkg_opk_opk_free(opk);
- error0:
- if (control_files != NULL) {
- opkg_opk_ustar_free_seek_names(control_files);
- }
- return EXIT_FAILURE;
}