]> jfr.im git - irc/thales.git/blob - src/cmd.c
748bfd9efd814c5b40f4cefde330314f66f68f6b
[irc/thales.git] / src / cmd.c
1 #include <config.h>
2 #include "cmd.h"
3 #include <getopt.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7
8 static void
9 printf_option(const char *option, const char *description)
10 {
11 printf(" %-20s%-20s\n", option, description);
12 }
13 static void
14 print_help(void)
15 {
16 printf("Usage: thales [options]\n");
17 printf_option("--help, -h", "Display this information");
18 printf_option("--version, -v", "Display thales version");
19 printf_option("--debug, -d", "Enable output of debug information");
20 printf_option("--config, -C", "Override default configuration file");
21 }
22
23 static void
24 print_version(void)
25 {
26 puts(PACKAGE_STRING);
27 puts("Copyright (C) 2012 Free Software Foundation, Inc.");
28 puts("This is free software; see the source for copying conditions. There is NO");
29 puts("warranty; not even for MERCHANTABILITY "
30 "or FITNESS FOR A PARTICULAR PURPOSE.");
31 }
32
33 void
34 parse_cmdopts(struct cmd_options *opts, int argc, char **argv)
35 {
36 int val;
37 const char *optstr = "hvdC:";
38 struct option longopts[] = {
39 {"help", no_argument, NULL, 'h'},
40 {"version", no_argument, NULL, 'v'},
41 {"config", required_argument, NULL, 'C'},
42 {"debug", no_argument, &opts->debug, 'd'}
43 };
44 while ((val = getopt_long(argc, argv, optstr, longopts, NULL))!= EOF)
45 switch (val)
46 {
47 case 'h':
48 print_help();
49 exit(EXIT_SUCCESS);
50 case 'v':
51 print_version();
52 exit(EXIT_SUCCESS);
53 case 'c':
54 opts->conf_filename = optarg;
55 break;
56 case '?':
57 exit(EXIT_FAILURE);
58 }
59 }