* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
+#include <getopt.h>
+
#include <glib-object.h>
#include "upkg.h"
#include "uobject.h"
#include "exportable.h"
+static const char *progname = "upkg";
+
+static const char *sopts = "VH";
+static const struct option lopts[] = {
+ { "version", 0, NULL, 'V' },
+ { "help", 0, NULL, 'H' },
+ { 0 }
+};
+
+void print_version(void)
+{
+ printf("%s\n", PACKAGE_STRING);
+ puts("\
+Copyright (C) 2009 Nick Bowler.\n\
+This is free software: you are free to change and redistribute it.\n\
+There is NO WARRANTY, to the extent permitted by law."
+ );
+}
+
+void print_usage(void)
+{
+ printf("Usage: %s [options] package\n", progname);
+}
+
+void print_help(void)
+{
+ print_usage();
+ puts("Detailed help coming soon. Until then, I'll just list my options.");
+ for (unsigned i = 0; lopts[i].name; i++) {
+ const struct option *o = &lopts[i];
+ printf("\t--%s", o->name);
+
+ if (o->has_arg == 1) {
+ printf("=val");
+ } else if (o->has_arg == 2) {
+ printf("[=val]");
+ }
+
+ printf(" (-%c)\n", o->val);
+ }
+}
+
void print_upkg_flags(const char *prefix, unsigned long flags)
{
if (flags & UPKG_FLAG_ALLOW_DOWNLOAD)
int main(int argc, char **argv)
{
struct upkg *pkg;
+ int opt;
+
+ if (argc > 0) progname = argv[0];
+
+ while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
+ switch (opt) {
+ case 'V':
+ print_version();
+ return EXIT_SUCCESS;
+ case 'H':
+ print_help();
+ return EXIT_SUCCESS;
+ default:
+ print_usage();
+ return EXIT_FAILURE;
+ }
+ }
if (argc < 2) {
fprintf(stderr, "usage: upkg file\n");