summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--configure.ac2
-rw-r--r--src/main.c113
3 files changed, 101 insertions, 15 deletions
diff --git a/TODO b/TODO
index 50f4036..fb3fa82 100644
--- a/TODO
+++ b/TODO
@@ -1,2 +1 @@
-Add option handling
I18n?
diff --git a/configure.ac b/configure.ac
index c2a4411..afb70ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,8 @@ AC_CHECK_FUNCS(
for func in log10 ceil lrint; do
AC_SEARCH_LIBS([${func}], [m], [], [funcs_missing=true])
done
+AC_CHECK_FUNCS([getopt_long], [],
+ [AC_CHECK_FUNCS([getopt], [], [funcs_missing=true])])
if ${funcs_missing}; then
AC_MSG_ERROR([required functions are missing])
fi
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;
}