]> git.draconx.ca Git - liblbx.git/blob - src/lbxtool.c
Add basic stubbiness for lbxtool.
[liblbx.git] / src / lbxtool.c
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <getopt.h>
5
6 #include "lbx.h"
7
8 static const char *progname;
9 #define errmsg(fmt, ...) (\
10         fprintf(stderr, "%s: " fmt ": %m.\n", progname, __VA_ARGS__)\
11 )
12
13 enum {
14         MODE_NONE,
15         MODE_LIST,
16         MODE_EXTRACT,
17 };
18
19 int main(int argc, char **argv)
20 {
21         int mode = MODE_NONE;
22         FILE *f  = stdin;
23         int opt;
24
25         struct option longopts[] = {
26                 { "list",    0, NULL, 'l' },
27                 { "extract", 0, NULL, 'x' },
28
29                 { "file",    1, NULL, 'f' },
30
31                 { 0 }
32         };
33
34         progname = argv[0];
35         while ((opt = getopt_long(argc, argv, "lxf:", longopts, NULL)) != -1) {
36                 switch(opt) {
37                 case 'l':
38                         mode = MODE_LIST;
39                         break;
40                 case 'x':
41                         mode = MODE_EXTRACT;
42                         break;
43                 case 'f':
44                         f = fopen(optarg, "rb");
45                         if (!f) {
46                                 errmsg("failed to open file", 0, 4);
47                                 return EXIT_FAILURE;
48                         }
49                         break;
50                 default:
51                         return EXIT_FAILURE;
52                 }
53         }
54
55         if (mode == MODE_NONE) {
56                 fprintf(stderr, "%s: you must specify a mode.\n", progname);
57                 return EXIT_FAILURE;
58         }
59 }