]> git.draconx.ca Git - liblbx.git/blobdiff - src/lbxtool.c
Add a name field to support LBX1 fallback.
[liblbx.git] / src / lbxtool.c
index a8b899ac80a10d4d0c7317b6d122e371b8d62d12..96c8ddd06e8ef87c7a016f2923e4cfac9967fa98 100644 (file)
@@ -1,6 +1,7 @@
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <getopt.h>
 
 #include "lbx.h"
@@ -16,8 +17,8 @@ enum {
        MODE_EXTRACT,
 };
 
-int list(FILE *f, int verbose) {
-       LBX *lbx = lbx_fopen(f);
+int list(FILE *f, const char *name, int verbose) {
+       LBX *lbx = lbx_fopen(f, name);
        if (!lbx) {
                errmsg("failed to open archive: %s.\n", lbx_strerror());
                return EXIT_FAILURE;
@@ -33,15 +34,17 @@ int list(FILE *f, int verbose) {
 int main(int argc, char **argv)
 {
        int mode = MODE_NONE, verbose = 0;
+       const char *name = "stdin";
        FILE *f  = stdin;
        int opt;
 
-       static const char         *sopts   = "lxf:v";
+       static const char         *sopts   = "lxf:i:v";
        static const struct option lopts[] = {
                { "list",    0, NULL, 'l' },
                { "extract", 0, NULL, 'x' },
 
                { "file",    1, NULL, 'f' },
+               { "index",   1, NULL, 'i' },
 
                { "verbose", 0, NULL, 'v' },
 
@@ -58,12 +61,21 @@ int main(int argc, char **argv)
                        mode = MODE_EXTRACT;
                        break;
                case 'f':
+                       if (strcmp(optarg, "-") == 0)
+                               break;
+
+                       name = strrchr(optarg, '/');
+                       name = name ? name+1 : optarg;
+
                        f = fopen(optarg, "rb");
                        if (!f) {
                                errmsg("failed to open file %s: %m\n", optarg);
                                return EXIT_FAILURE;
                        }
                        break;
+               case 'i':
+                       /* FIXME: Add index file support. */
+                       break;
                case 'v':
                        verbose = 1;
                        break;
@@ -74,7 +86,7 @@ int main(int argc, char **argv)
 
        switch (mode) {
        case MODE_LIST:
-               return list(f, verbose);
+               return list(f, name, verbose);
        case MODE_EXTRACT:
                return EXIT_SUCCESS;
        }