]> git.draconx.ca Git - liblbx.git/commitdiff
Add basic stubbiness for lbxtool.
authorNick Bowler <draconx@gmail.com>
Sat, 22 Dec 2007 20:01:35 +0000 (15:01 -0500)
committerNick Bowler <draconx@gmail.com>
Sat, 22 Dec 2007 20:01:35 +0000 (15:01 -0500)
src/.gitignore
src/Makefile.am
src/lbxtool.c [new file with mode: 0644]

index f299a28c8cff86e8e69cc77e63ccceb8de91a26f..72d6853a669d07fbcf9b711384c4f3e01da68942 100644 (file)
@@ -5,3 +5,4 @@ Makefile.in
 *.o
 *.lo
 *.la
+lbxtool
index 0292af70d6475020028915849644af762a911500..0c9c6389c97054148dfffb51db284f2bf22e4551 100644 (file)
@@ -1,3 +1,7 @@
-lib_LTLIBRARIES = liblbx.la
+lib_LTLIBRARIES   = liblbx.la
+bin_PROGRAMS      = lbxtool
 
 liblbx_la_SOURCES = lbx.c
+
+lbxtool_SOURCES   = lbxtool.c
+lbxtool_LDADD     = liblbx.la
diff --git a/src/lbxtool.c b/src/lbxtool.c
new file mode 100644 (file)
index 0000000..f9a17d1
--- /dev/null
@@ -0,0 +1,59 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+#include "lbx.h"
+
+static const char *progname;
+#define errmsg(fmt, ...) (\
+       fprintf(stderr, "%s: " fmt ": %m.\n", progname, __VA_ARGS__)\
+)
+
+enum {
+       MODE_NONE,
+       MODE_LIST,
+       MODE_EXTRACT,
+};
+
+int main(int argc, char **argv)
+{
+       int mode = MODE_NONE;
+       FILE *f  = stdin;
+       int opt;
+
+       struct option longopts[] = {
+               { "list",    0, NULL, 'l' },
+               { "extract", 0, NULL, 'x' },
+
+               { "file",    1, NULL, 'f' },
+
+               { 0 }
+       };
+
+       progname = argv[0];
+       while ((opt = getopt_long(argc, argv, "lxf:", longopts, NULL)) != -1) {
+               switch(opt) {
+               case 'l':
+                       mode = MODE_LIST;
+                       break;
+               case 'x':
+                       mode = MODE_EXTRACT;
+                       break;
+               case 'f':
+                       f = fopen(optarg, "rb");
+                       if (!f) {
+                               errmsg("failed to open file", 0, 4);
+                               return EXIT_FAILURE;
+                       }
+                       break;
+               default:
+                       return EXIT_FAILURE;
+               }
+       }
+
+       if (mode == MODE_NONE) {
+               fprintf(stderr, "%s: you must specify a mode.\n", progname);
+               return EXIT_FAILURE;
+       }
+}