This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.c
130 lines (120 loc) · 3.31 KB
/
config.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Copyright © 2003-2022 Jakub Wilk <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "autoconf.h"
#include <getopt.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "config.h"
Config config = {
.color = false,
.utf8 = false,
.html = false,
.xhtml = false,
.stats = false
};
static void show_usage(void)
{
printf(
"Usage: nonogram [OPTIONS]\n\n"
"Options:\n"
" -c, --colors use colors\n"
" -u, --utf-8 use UTF-8 drawing characters\n"
" -H, --html HTML output\n"
" -X, --xhtml XHTML output\n"
#if ENABLE_DEBUG
" -f, --file=FILE validate the result using FILE\n"
#endif
" -h, --help show this help message and exit\n"
" -v, --version show version information and exit\n\n");
exit(EXIT_SUCCESS);
}
static void show_version(void)
{
printf("%s\n", PACKAGE_STRING);
exit(EXIT_SUCCESS);
}
void parse_arguments(int argc, char **argv, char **vfn)
{
static struct option options [] =
{
{ "version", 0, 0, 'v' },
{ "help", 0, 0, 'h' },
{ "colors", 0, 0, 'c' },
{ "mono", 0, 0, 'm' },
{ "utf-8", 0, 0, 'u' },
{ "html", 0, 0, 'H' },
{ "xhtml", 0, 0, 'X' },
{ "file", 0, 0, 'f' }, // XXX undocumented
{ "statistics", 0, 0, 's' }, // XXX undocumented
{ NULL, 0, 0, '\0' }
};
int optindex, c;
while (true)
{
optindex = 0;
c = getopt_long(argc, argv, "vhcmuHXsf:", options, &optindex);
if (c < 0)
break;
if (c == 0)
c = options[optindex].val;
switch (c)
{
case 'v':
show_version();
break;
case 'h':
show_usage();
break;
case 'm':
config.color = false;
break;
case 'c':
config.color = true;
break;
case 'u':
config.utf8 = true;
break;
case 'H':
config.html = true;
break;
case 'X':
config.html = config.xhtml = true;
break;
case 'f':
if (ENABLE_DEBUG && optarg != NULL)
*vfn = optarg;
break;
case 's':
config.stats = true;
break;
default:
exit(EXIT_FAILURE);
;
}
}
if (optind < argc)
{
fprintf(stderr, "%s: too many arguments\n", argv[0]);
exit(EXIT_FAILURE);
}
}
/* vim:set ts=2 sts=2 sw=2 et: */