static const char *progname;
#define errmsg(fmt, ...) (\
- fprintf(stderr, "%s: " fmt ": %m.\n", progname, __VA_ARGS__)\
+ fprintf(stderr, "%s: " fmt, progname, __VA_ARGS__)\
)
enum {
MODE_EXTRACT,
};
+int list(FILE *f, int verbose) {
+ LBX *lbx = lbx_fopen(f);
+ if (!lbx) {
+ errmsg("failed to open archive: %s.\n", lbx_strerror());
+ return EXIT_FAILURE;
+ }
+
+ if (verbose) {
+ printf("Files in archive: %zd\n", lbx_numfiles(lbx));
+ }
+
+ lbx_close(lbx);
+}
+
int main(int argc, char **argv)
{
- int mode = MODE_NONE;
+ int mode = MODE_NONE, verbose = 0;
FILE *f = stdin;
int opt;
- struct option longopts[] = {
+ static const char *sopts = "lxf:v";
+ static const struct option lopts[] = {
{ "list", 0, NULL, 'l' },
{ "extract", 0, NULL, 'x' },
{ "file", 1, NULL, 'f' },
+ { "verbose", 0, NULL, 'v' },
+
{ 0 }
};
- progname = argv[0];
- while ((opt = getopt_long(argc, argv, "lxf:", longopts, NULL)) != -1) {
+ progname = "lbxtool"; /* argv[0]; */
+ while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
switch(opt) {
case 'l':
mode = MODE_LIST;
case 'f':
f = fopen(optarg, "rb");
if (!f) {
- errmsg("failed to open file", 0, 4);
+ errmsg("failed to open file %s: %m\n", optarg);
return EXIT_FAILURE;
}
break;
+ case 'v':
+ verbose = 1;
+ break;
default:
return EXIT_FAILURE;
}
}
- if (mode == MODE_NONE) {
- fprintf(stderr, "%s: you must specify a mode.\n", progname);
- return EXIT_FAILURE;
+ switch (mode) {
+ case MODE_LIST:
+ return list(f, verbose);
+ case MODE_EXTRACT:
+ return EXIT_SUCCESS;
}
+
+ fprintf(stderr, "%s: you must specify a mode.\n", progname);
+ return EXIT_FAILURE;
}