From 298b3d46b2dc1b2fc7cd7c54c8904c6299bb6400 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 22 Dec 2007 15:01:35 -0500 Subject: [PATCH] Add basic stubbiness for lbxtool. --- src/.gitignore | 1 + src/Makefile.am | 6 ++++- src/lbxtool.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/lbxtool.c diff --git a/src/.gitignore b/src/.gitignore index f299a28..72d6853 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -5,3 +5,4 @@ Makefile.in *.o *.lo *.la +lbxtool diff --git a/src/Makefile.am b/src/Makefile.am index 0292af7..0c9c638 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 0000000..f9a17d1 --- /dev/null +++ b/src/lbxtool.c @@ -0,0 +1,59 @@ +#define _GNU_SOURCE +#include +#include +#include + +#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; + } +} -- 2.43.2