1 /* Test of exact or abbreviated match search.
2 Copyright (C) 1990, 1998-1999, 2001-2020 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007, based on test code
18 by David MacKenzie <djm@gnu.ai.mit.edu>. */
28 # define N_(Msgid) (Msgid)
30 /* Some packages define ARGMATCH_DIE and ARGMATCH_DIE_DECL in <config.h>, and
31 thus must link with a definition of that function. Provide it here. */
32 #ifdef ARGMATCH_DIE_DECL
34 _Noreturn ARGMATCH_DIE_DECL
;
35 ARGMATCH_DIE_DECL
{ exit (1); }
43 numbered_existing_backups
,
47 static const char *const backup_args
[] =
50 "simple", "never", "single",
51 "existing", "nil", "numbered-existing",
52 "numbered", "t", "newstyle",
56 static const enum backup_type backup_vals
[] =
58 no_backups
, no_backups
, no_backups
,
59 simple_backups
, simple_backups
, simple_backups
,
60 numbered_existing_backups
, numbered_existing_backups
, numbered_existing_backups
,
61 numbered_backups
, numbered_backups
, numbered_backups
64 ARGMATCH_DEFINE_GROUP(backup
, enum backup_type
);
66 static const argmatch_backup_doc argmatch_backup_docs
[] =
68 { "no", N_("never make backups (even if --backup is given)") },
69 { "numbered", N_("make numbered backups") },
70 { "existing", N_("numbered if numbered backups exist, simple otherwise") },
71 { "simple", N_("always make simple backups") },
75 static const argmatch_backup_arg argmatch_backup_args
[] =
78 { "none", no_backups
},
79 { "off", no_backups
},
80 { "simple", simple_backups
},
81 { "never", simple_backups
},
82 { "single", simple_backups
},
83 { "existing", numbered_existing_backups
},
84 { "nil", numbered_existing_backups
},
85 { "numbered-existing", numbered_existing_backups
},
86 { "numbered", numbered_backups
},
87 { "t", numbered_backups
},
88 { "newstyle", numbered_backups
},
92 const argmatch_backup_group_type argmatch_backup_group
=
97 The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
98 The version control method may be selected via the --backup option or through\n\
99 the VERSION_CONTROL environment variable. Here are the values:\n"),
104 main (int argc
, char *argv
[])
106 #define CHECK(Input, Output) \
108 ASSERT (ARGMATCH (Input, backup_args, backup_vals) == Output); \
109 ASSERT (argmatch_backup_choice (Input) == Output); \
112 enum backup_type val = argmatch_backup_args[Output].val; \
113 ASSERT (*argmatch_backup_value ("test", Input) == val); \
114 ASSERT (*argmatch_backup_value ("test", \
115 argmatch_backup_argument (&val)) \
121 CHECK ("klingon", -1);
128 CHECK ("nilpotent", -1);
135 /* Exact match and abbreviated. */
136 CHECK ("numbered", 9);
137 CHECK ("numbere", -2);
138 CHECK ("number", -2);
145 /* Ambiguous abbreviated. */
148 /* Ambiguous abbreviated, but same value ("single" and "simple"). */
153 argmatch_backup_usage (stdout
);