This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22
23
24
25 #if 10 <= __GNUC__
26 # pragma GCC diagnostic ignored "-Wanalyzer-null-argument"
27 #endif
28
29 #include "argmatch.h"
30
31 #include <stdlib.h>
32
33 #include "macros.h"
34
35 # define N_(Msgid) (Msgid)
36
37
38
39 #ifdef ARGMATCH_DIE_DECL
40
41 _Noreturn ARGMATCH_DIE_DECL;
42 ARGMATCH_DIE_DECL { exit (1); }
43
44 #endif
45
46 enum backup_type
47 {
48 no_backups,
49 simple_backups,
50 numbered_existing_backups,
51 numbered_backups
52 };
53
54 static const char *const backup_args[] =
55 {
56 "no", "none", "off",
57 "simple", "never", "single",
58 "existing", "nil", "numbered-existing",
59 "numbered", "t", "newstyle",
60 NULL
61 };
62
63 static const enum backup_type backup_vals[] =
64 {
65 no_backups, no_backups, no_backups,
66 simple_backups, simple_backups, simple_backups,
67 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups,
68 numbered_backups, numbered_backups, numbered_backups
69 };
70
71 ARGMATCH_DEFINE_GROUP(backup, enum backup_type)
72
73 static const argmatch_backup_doc argmatch_backup_docs[] =
74 {
75 { "no", N_("never make backups (even if --backup is given)") },
76 { "numbered", N_("make numbered backups") },
77 { "existing", N_("numbered if numbered backups exist, simple otherwise") },
78 { "simple", N_("always make simple backups") },
79 { NULL, NULL }
80 };
81
82 static const argmatch_backup_arg argmatch_backup_args[] =
83 {
84 { "no", no_backups },
85 { "none", no_backups },
86 { "off", no_backups },
87 { "simple", simple_backups },
88 { "never", simple_backups },
89 { "single", simple_backups },
90 { "existing", numbered_existing_backups },
91 { "nil", numbered_existing_backups },
92 { "numbered-existing", numbered_existing_backups },
93 { "numbered", numbered_backups },
94 { "t", numbered_backups },
95 { "newstyle", numbered_backups },
96 { NULL, no_backups }
97 };
98
99 const argmatch_backup_group_type argmatch_backup_group =
100 {
101 argmatch_backup_args,
102 argmatch_backup_docs,
103 N_("\
104 The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
105 The version control method may be selected via the --backup option or through\n\
106 the VERSION_CONTROL environment variable. Here are the values:\n"),
107 NULL
108 };
109
110 int
111 main (int argc, char *argv[])
112 {
113 #define CHECK(Input, Output) \
114 do { \
115 ASSERT (ARGMATCH (Input, backup_args, backup_vals) == Output); \
116 ASSERT (argmatch_backup_choice (Input) == Output); \
117 if (0 <= Output) \
118 { \
119 enum backup_type val \
120 = argmatch_backup_args[Output < 0 ? 0 : Output].val; \
121 ASSERT (*argmatch_backup_value ("test", Input) == val); \
122 ASSERT (*argmatch_backup_value ("test", \
123 argmatch_backup_argument (&val)) \
124 == val); \
125 } \
126 } while (0)
127
128
129 CHECK ("klingon", -1);
130
131
132 CHECK ("none", 1);
133 CHECK ("nil", 7);
134
135
136 CHECK ("nilpotent", -1);
137
138
139 CHECK ("simpl", 3);
140 CHECK ("simp", 3);
141 CHECK ("sim", 3);
142
143
144 CHECK ("numbered", 9);
145 CHECK ("numbere", -2);
146 CHECK ("number", -2);
147 CHECK ("numbe", -2);
148 CHECK ("numb", -2);
149 CHECK ("num", -2);
150 CHECK ("nu", -2);
151 CHECK ("n", -2);
152
153
154 CHECK ("ne", -2);
155
156
157 CHECK ("si", 3);
158 CHECK ("s", 3);
159 #undef CHECK
160
161 argmatch_backup_usage (stdout);
162
163 return 0;
164 }