]> git.sesse.net Git - nageru/blob - flags.cpp
Add usage information on invalid option or --help.
[nageru] / flags.cpp
1 #include "flags.h"
2
3 #include <getopt.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 Flags global_flags;
8
9 void usage()
10 {
11         fprintf(stderr, "Usage: nageru [OPTION]...\n");
12         fprintf(stderr, "\n");
13         fprintf(stderr, "  -h, --help                      print usage information\n");
14         fprintf(stderr, "  -c, --num-cards                 set number of input cards (default 2)\n");
15         fprintf(stderr, "  -t, --theme=FILE                choose theme (default theme.lua)\n");
16         fprintf(stderr, "  -v, --va-display=SPEC           VA-API device for H.264 encoding\n");
17         fprintf(stderr, "                                    ($DISPLAY spec or /dev/dri/render* path)\n");
18         fprintf(stderr, "      --http-uncompressed-video   send uncompressed NV12 video to HTTP clients\n");
19         fprintf(stderr, "      --flat-audio                start with most audio processing turned off\n");
20 }
21
22 void parse_flags(int argc, char * const argv[])
23 {
24         static const option long_options[] = {
25                 { "help", no_argument, 0, 'h' },
26                 { "num-cards", required_argument, 0, 'c' },
27                 { "theme", required_argument, 0, 't' },
28                 { "va-display", required_argument, 0, 1000 },
29                 { "http-uncompressed-video", no_argument, 0, 1001 },
30                 { "flat-audio", no_argument, 0, 1002 },
31                 { 0, 0, 0, 0 }
32         };
33         for ( ;; ) {
34                 int option_index = 0;
35                 int c = getopt_long(argc, argv, "c:t:", long_options, &option_index);
36
37                 if (c == -1) {
38                         break;
39                 }
40                 switch (c) {
41                 case 'c':
42                         global_flags.num_cards = atoi(optarg);
43                         break;
44                 case 't':
45                         global_flags.theme_filename = optarg;
46                         break;
47                 case 1000:
48                         global_flags.va_display = optarg;
49                         break;
50                 case 1001:
51                         global_flags.uncompressed_video_to_http = true;
52                         break;
53                 case 1002:
54                         global_flags.flat_audio = true;
55                         break;
56                 case 'h':
57                         usage();
58                         exit(0);
59                 default:
60                         fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
61                         fprintf(stderr, "\n");
62                         usage();
63                         exit(1);
64                 }
65         }
66 }