-lib_LTLIBRARIES = liblbx.la
+lib_LTLIBRARIES = liblbx.la
+bin_PROGRAMS = lbxtool
liblbx_la_SOURCES = lbx.c
+
+lbxtool_SOURCES = lbxtool.c
+lbxtool_LDADD = liblbx.la
--- /dev/null
+#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;
+ }
+}