summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c113
1 files changed, 99 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index 1201330..94fed74 100644
--- a/src/main.c
+++ b/src/main.c
@@ -22,45 +22,130 @@
#include "opk.h"
#include "ustar.h"
+#include "config.h"
+
+#ifdef HAVE_GETOPT_LONG
+#include <getopt.h>
+#else
+#include <unistd.h>
+#endif
+
+const char *_optstring = "I:fchV";
+#ifdef HAVE_GETOPT_LONG
+struct option _longopts[] = {
+ {
+ .name = "info",
+ .has_arg = 1,
+ .flag = NULL,
+ .val = 'I',
+ },
+ {
+ .name = "control",
+ .has_arg = 0,
+ .flag = NULL,
+ .val = 'f',
+ },
+ {
+ .name = "contents",
+ .has_arg = 0,
+ .flag = NULL,
+ .val = 'c',
+ },
+ {
+ .name = "help",
+ .has_arg = 0,
+ .flag = NULL,
+ .val = 'h',
+ },
+ {
+ .name = "version",
+ .has_arg = 0,
+ .flag = NULL,
+ .val = 'V',
+ },
+};
+#endif
+
int
main(int argc, char *argv[])
{
struct opkg_opk_ustar_seek_name *control_files;
+ int list_members;
+ int opt;
struct opkg_opk_opk *opk;
control_files = NULL;
- if (opkg_opk_ustar_add_seek_name(&control_files, "control") !=
- OPKG_OPK_OK) {
- goto error0;
- }
- if (opkg_opk_ustar_add_seek_name(&control_files, "md5sums") !=
- OPKG_OPK_OK) {
- goto error0;
+ list_members = 0;
+#ifdef HAVE_GETOPT_LONG
+ while ((opt = getopt_long(argc, argv, _optstring, _longopts, NULL))
+ != -1) {
+#else
+ while ((opt = getopt(argc, argv, _optstring)) != -1) {
+#endif
+ switch(opt) {
+ case 'I':
+ if (opkg_opk_ustar_add_seek_name(&control_files,
+ optarg) !=
+ OPKG_OPK_OK) {
+ goto error0;
+ }
+ break;
+ case 'f':
+ if (opkg_opk_ustar_add_seek_name(&control_files,
+ "control") !=
+ OPKG_OPK_OK) {
+ goto error0;
+ }
+ break;
+ case 'c':
+ list_members = 1;
+ break;
+ case 'h':
+ /* TODO */
+ break;
+ case 'V':
+ /* TODO */
+ break;
+ default:
+ /* TODO */
+ break;
+ }
}
+ argc -= optind;
+ argv += optind;
/* Initialize outer archive. */
- opk = opkg_opk_opk_init(argv[1]);
+ opk = opkg_opk_opk_init(argv[0]);
if (opk == NULL) {
goto error0;
}
/* Read control file. */
- if (opkg_opk_opk_read_control(opk, control_files) != OPKG_OPK_OK) {
- goto error1;
+ if (control_files != NULL) {
+ if (opkg_opk_opk_read_control(opk, control_files) !=
+ OPKG_OPK_OK) {
+ goto error1;
+ }
}
/* List data files. */
- if (opkg_opk_opk_list_members(opk) != OPKG_OPK_OK) {
- goto error1;
+ if (list_members == 1) {
+ if (opkg_opk_opk_list_members(opk) != OPKG_OPK_OK) {
+ goto error1;
+ }
}
opkg_opk_opk_free(opk);
- opkg_opk_ustar_free_seek_names(control_files);
+ if (control_files != NULL) {
+ opkg_opk_ustar_free_seek_names(control_files);
+ }
return EXIT_SUCCESS;
error1:
opkg_opk_opk_free(opk);
error0:
- opkg_opk_ustar_free_seek_names(control_files);
+ if (control_files != NULL) {
+ opkg_opk_ustar_free_seek_names(control_files);
+ }
return EXIT_FAILURE;
}