]> Pileus Git - ~andy/lamechat/blob - args.c
Make logfile optional.
[~andy/lamechat] / args.c
1 /*
2  * Copyright (C) 2016 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <getopt.h>
21
22 #include "util.h"
23 #include "args.h"
24
25 /* Options */
26 static char *short_options = "h";
27
28 struct option long_options[] = {
29         {"help",   0, NULL, 'h'},
30 };
31
32 /* Usage */
33 static void usage(char *name)
34 {
35         printf("Usage:\n");
36         printf("  %s [OPTION...]\n", name);
37         printf("\n");
38         printf("Options:\n");
39         printf("  -h, --help        Print usage information\n");
40 }
41
42 /* Initialize */
43 void args_setup(int argc, char **argv)
44 {
45         /* Parse arguments */
46         while (1) {
47                 int c = getopt_long(argc, argv,
48                                 short_options, long_options, NULL);
49                 if (c == -1)
50                         break;
51                 switch (c) {
52                         case 'h':
53                                 usage(argv[0]);
54                                 exit(0);
55                                 break;
56                 }
57         }
58 }