]> git.sesse.net Git - nageru/blob - flags.cpp
Make NUM_CARDS into a command-line flag.
[nageru] / flags.cpp
1 #include <stdio.h>
2 #include <getopt.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5
6 #include "flags.h"
7
8 Flags global_flags;
9
10 void parse_flags(int argc, char * const argv[])
11 {
12         static const option long_options[] = {
13                 { "num-cards", required_argument, 0, 'c' },
14                 { 0, 0, 0, 0 }
15         };
16         for ( ;; ) {
17                 int option_index = 0;
18                 int c = getopt_long(argc, argv, "c:", long_options, &option_index);
19
20                 if (c == -1) {
21                         break;
22                 }
23                 switch (c) {
24                 case 'c':
25                         global_flags.num_cards = atoi(optarg);
26                         break;
27                 default:
28                         fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
29                         exit(1);
30                 }
31         }
32 }