9 static const char *progname;
10 #define errmsg(fmt, ...) (\
11 fprintf(stderr, "%s: " fmt, progname, __VA_ARGS__)\
20 int list(FILE *f, const char *name, int verbose) {
21 LBX *lbx = lbx_fopen(f, name);
23 errmsg("failed to open archive: %s.\n", lbx_strerror());
28 printf("Files in archive: %zd\n", lbx_numfiles(lbx));
34 int main(int argc, char **argv)
36 int mode = MODE_NONE, verbose = 0;
37 const char *name = "stdin";
41 static const char *sopts = "lxf:i:v";
42 static const struct option lopts[] = {
43 { "list", 0, NULL, 'l' },
44 { "extract", 0, NULL, 'x' },
46 { "file", 1, NULL, 'f' },
47 { "index", 1, NULL, 'i' },
49 { "verbose", 0, NULL, 'v' },
54 progname = "lbxtool"; /* argv[0]; */
55 while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
64 if (strcmp(optarg, "-") == 0)
67 name = strrchr(optarg, '/');
68 name = name ? name+1 : optarg;
70 f = fopen(optarg, "rb");
72 errmsg("failed to open file %s: %m\n", optarg);
77 /* FIXME: Add index file support. */
89 return list(f, name, verbose);
94 fprintf(stderr, "%s: you must specify a mode.\n", progname);