From: Nick Bowler Date: Sat, 5 Jan 2008 07:31:30 +0000 (-0500) Subject: Add version, help, and usage messages to the tools. X-Git-Url: https://git.draconx.ca/gitweb/liblbx.git/commitdiff_plain/b0910e37f2dbf5b4e3dcd8bdfcef16d5d6b597cb Add version, help, and usage messages to the tools. --- diff --git a/doc/man/lbximg.1 b/doc/man/lbximg.1 index cebcef7..564655b 100644 --- a/doc/man/lbximg.1 +++ b/doc/man/lbximg.1 @@ -49,6 +49,12 @@ Use the embedded palette of an LBX image specified by as the override palette. In Moo2, this is notably used to select the player colour for ship images. Colours in the override palette supersede those in both the base palette and the embedded palette. +.It Fl V , -version +Print a version message and exit. +.It Fl -usage +Print a short usage message and exit. +.It Fl -help +Print a help message and exit .It Ar frameno ... Specifies the frames to decode as a sequence of intervals, with frames indexing from zero. By default, all frames are decoded. Multiplicity is ignored, as is diff --git a/doc/man/lbxtool.1 b/doc/man/lbxtool.1 index a5ac319..c91a969 100644 --- a/doc/man/lbxtool.1 +++ b/doc/man/lbxtool.1 @@ -31,6 +31,12 @@ instead of standard input. If is -, .Nm will read from standard input anyway. +.It Fl V , -version +Print a version message and exit. +.It Fl -usage +Print a short usage message and exit. +.It Fl -help +Print a help message and exit .It Ar Limit the operation to these files in the archive. By default, all files are selected. Supports common shell globbing features. diff --git a/src/Makefile.am b/src/Makefile.am index ab54c5a..3736bd8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,11 +6,11 @@ lbx_HEADERS = lbx.h image.h liblbx_la_SOURCES = byteorder.h misc.h misc.c lbx.c image.c -lbxtool_SOURCES = lbxtool.c +lbxtool_SOURCES = tools.h lbxtool.c lbxtool_LDADD = liblbx.la if BUILD_LBXIMG -lbximg_SOURCES = lbximg.c +lbximg_SOURCES = tools.h lbximg.c lbximg_LDADD = liblbx.la lbximg_CFLAGS = $(PNG_CFLAGS) lbximg_LDFLAGS = $(PNG_LIBS) diff --git a/src/lbximg.c b/src/lbximg.c index 6151619..d56824c 100644 --- a/src/lbximg.c +++ b/src/lbximg.c @@ -27,6 +27,7 @@ #include +#include "tools.h" #include "image.h" #include "lbx.h" @@ -35,6 +36,19 @@ static int verbose = 0; static char *outname = "out"; static int usepalette = 1; +static void printusage(void) +{ + puts("usage: lbximg [-i|-d] [-v] [-p palette_file] [-O override_file]" + " [-f path]"); + puts(" [frameno ...]"); +} + +static void printhelp(void) +{ + printusage(); + puts("For now, see the man page for detailed help."); +} + static const char *progname; #define errmsg(fmt, ...) (\ fprintf(stderr, "%s: " fmt, progname, __VA_ARGS__)\ @@ -356,7 +370,7 @@ int main(int argc, char **argv) LBX_IMG *img; int opt; - static const char *sopts = "idvf:p:O:"; + static const char *sopts = "idvf:p:O:V"; static const struct option lopts[] = { { "ident", 0, NULL, 'i' }, { "decode", 0, NULL, 'd' }, @@ -365,6 +379,10 @@ int main(int argc, char **argv) { "palette", 1, NULL, 'p' }, { "override", 1, NULL, 'p' }, + { "version", 0, NULL, 'V' }, + { "usage", 0, NULL, 'U' }, + { "help", 0, NULL, 'H' }, + { "nopalette", 0, &usepalette, 0 }, { 0 } @@ -410,6 +428,15 @@ int main(int argc, char **argv) return EXIT_FAILURE; } break; + case 'V': + puts(VERSION_BOILERPLATE("lbximg")); + return EXIT_SUCCESS; + case 'U': + printusage(); + return EXIT_SUCCESS; + case 'H': + printhelp(); + return EXIT_SUCCESS; case '?': case ':': return EXIT_FAILURE; diff --git a/src/lbxtool.c b/src/lbxtool.c index 2c6105b..1d80eeb 100644 --- a/src/lbxtool.c +++ b/src/lbxtool.c @@ -23,8 +23,20 @@ #include #include +#include "tools.h" #include "lbx.h" +static void printusage(void) +{ + puts("usage: lbxtool [-l|-x] [-v] [-f path] [file ...]"); +} + +static void printhelp(void) +{ + printusage(); + puts("For now, see the man page for detailed help."); +} + static const char *progname; #define errmsg(fmt, ...) (\ fprintf(stderr, "%s: " fmt, progname, __VA_ARGS__)\ @@ -159,7 +171,7 @@ int main(int argc, char **argv) FILE *f = stdin; int opt; - static const char *sopts = "lxf:i:v"; + static const char *sopts = "lxf:i:vV"; static const struct option lopts[] = { { "list", 0, NULL, 'l' }, { "extract", 0, NULL, 'x' }, @@ -169,6 +181,10 @@ int main(int argc, char **argv) { "verbose", 0, NULL, 'v' }, + { "version", 0, NULL, 'V' }, + { "usage", 0, NULL, 'U' }, + { "help", 0, NULL, 'H' }, + { 0 } }; @@ -200,6 +216,15 @@ int main(int argc, char **argv) case 'v': verbose = 1; break; + case 'V': + puts(VERSION_BOILERPLATE("lbxtool")); + return EXIT_SUCCESS; + case 'U': + printusage(); + return EXIT_SUCCESS; + case 'H': + printhelp(); + return EXIT_SUCCESS; default: return EXIT_FAILURE; }