summaryrefslogtreecommitdiff
path: root/src/options.c
blob: cab807931ffcde77bb9066556a15f0de80c62701 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <unistd.h>

#include "options.h"
#include "logging.h"

static void print_usage(const char *progname)
{
   printf("Usage: %s [-c config_file] [-v[v[v]]] [-q[q[q]]] [-h]\n"
	  "  -v    Increase output verbosity (-vvv displays every log message)\n"
	  "  -q    Decrease output verbosity (-qqq suppresses even fatal errors)\n"
	  "  -c    Specify configuration file to read (default 'config.lua')\n"
	  "  -h    Print this help message and exit\n",
	  progname);	  
}

int parse_options(struct argent_options *opts, int argc, char **argv)
{
   opts->log_level = WARN;
   opts->conf_filename = "config.lua";
   
   int opt;
   while ((opt = getopt(argc, argv, "hqvc:")) != -1) {
      switch (opt) {
      case 'q':
	 opts->log_level -= 1;
	 break;
	 
      case 'v':
	 opts->log_level += 1;
	 break;
	 
      case 'c':
	 opts->conf_filename = optarg;
	 break;

      case 'h':
	 print_usage(argv[0]);
	 return 2;

      default:
	 print_usage(argv[0]);
	 return 1;
      }
   }

   // ew, globals (sorry)
   argent_log_level = opts->log_level;

   return 0;
}