]> jfr.im git - irc/thales.git/blob - src/cmd.c
Add legal notices.
[irc/thales.git] / src / cmd.c
1 /* Command line parsing program of GNU Thales. Copyright (C)
2 2012 Free Software Foundation, Inc. This file is part of GNU Thales.
3
4 GNU Thales is free software; you can redistribute it and/or modify it under the
5 terms of the GNU General Public License as published by the Free Software
6 Foundation; either version 3 of the License, or (at your option) any later
7 version.
8
9 GNU Make is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include "cmd.h"
19 #include <getopt.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23
24 static void
25 printf_option(const char *option, const char *description)
26 {
27 printf(" %-20s%-20s\n", option, description);
28 }
29 static void
30 print_help(void)
31 {
32 printf("Usage: thales [options]\n");
33 printf_option("--help, -h", "Display this information");
34 printf_option("--version, -v", "Display thales version");
35 printf_option("--debug, -d", "Enable output of debug information");
36 printf_option("--config, -C", "Override default configuration file");
37 }
38
39 static void
40 print_version(void)
41 {
42 puts(PACKAGE_STRING);
43 puts("Copyright (C) 2012 Free Software Foundation, Inc.");
44 puts("This is free software; see the source for copying conditions. There is NO");
45 puts("warranty; not even for MERCHANTABILITY "
46 "or FITNESS FOR A PARTICULAR PURPOSE.");
47 }
48
49 void
50 parse_cmdopts(struct cmd_options *opts, int argc, char **argv)
51 {
52 int val;
53 const char *optstr = "hvdC:";
54 struct option longopts[] = {
55 {"help", no_argument, NULL, 'h'},
56 {"version", no_argument, NULL, 'v'},
57 {"config", required_argument, NULL, 'C'},
58 {"debug", no_argument, &opts->debug, 'd'}
59 };
60 while ((val = getopt_long(argc, argv, optstr, longopts, NULL))!= EOF)
61 switch (val)
62 {
63 case 'h':
64 print_help();
65 exit(EXIT_SUCCESS);
66 case 'v':
67 print_version();
68 exit(EXIT_SUCCESS);
69 case 'c':
70 opts->conf_filename = optarg;
71 break;
72 case '?':
73 exit(EXIT_FAILURE);
74 }
75 }