| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | #include <config.h> | - |
| 23 | | - |
| 24 | | - |
| 25 | #include "argmatch.h" | - |
| 26 | | - |
| 27 | #include <stdbool.h> | - |
| 28 | #include <stdio.h> | - |
| 29 | #include <stdlib.h> | - |
| 30 | #include <string.h> | - |
| 31 | | - |
| 32 | #include "gettext.h" | - |
| 33 | #define _(msgid) gettext (msgid) | - |
| 34 | | - |
| 35 | #include "error.h" | - |
| 36 | #include "quotearg.h" | - |
| 37 | #include "quote.h" | - |
| 38 | #include "getprogname.h" | - |
| 39 | | - |
| 40 | #if USE_UNLOCKED_IO | - |
| 41 | # include "unlocked-io.h" | - |
| 42 | #endif | - |
| 43 | | - |
| 44 | | - |
| 45 | | - |
| 46 | | - |
| 47 | #ifndef ARGMATCH_QUOTING_STYLE | - |
| 48 | # define ARGMATCH_QUOTING_STYLE locale_quoting_style | - |
| 49 | #endif | - |
| 50 | | - |
| 51 | | - |
| 52 | #ifndef ARGMATCH_DIE | - |
| 53 | # include "exitfail.h" | - |
| 54 | # define ARGMATCH_DIE exit (exit_failure) | - |
| 55 | #endif | - |
| 56 | | - |
| 57 | #ifdef ARGMATCH_DIE_DECL | - |
| 58 | ARGMATCH_DIE_DECL; | - |
| 59 | #endif | - |
| 60 | | - |
| 61 | static void | - |
| 62 | __argmatch_die (void) | - |
| 63 | { | - |
| 64 | ARGMATCH_DIE; | - |
| 65 | } never executed: end of block | 0 |
| 66 | | - |
| 67 | | - |
| 68 | | - |
| 69 | argmatch_exit_fn argmatch_die = __argmatch_die; | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | ptrdiff_t | - |
| 84 | argmatch (const char *arg, const char *const *arglist, | - |
| 85 | const char *vallist, size_t valsize) | - |
| 86 | { | - |
| 87 | size_t i; | - |
| 88 | size_t arglen; | - |
| 89 | ptrdiff_t matchind = -1; | - |
| 90 | bool ambiguous = false; | - |
| 91 | | - |
| 92 | arglen = strlen (arg); | - |
| 93 | | - |
| 94 | | - |
| 95 | for (i = 0; arglist[i]; i++)| TRUE | evaluated 4228 times by 22 testsEvaluated by:- b2sum
- cp
- date
- df
- dir
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- stat
- tail
- tee
- touch
- uniq
- vdir
| | FALSE | evaluated 232 times by 15 testsEvaluated by:- b2sum
- cp
- date
- df
- dir
- du
- ls
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
|
| 232-4228 |
| 96 | { | - |
| 97 | if (!strncmp (arglist[i], arg, arglen)) never executed: __result = (((const unsigned char *) (const char *) ( arglist[i] ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( arg ))[3] - __s2[3]); never executed: end of block never executed: end of block | TRUE | evaluated 1214 times by 19 testsEvaluated by:- b2sum
- cp
- date
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- stat
- tail
- tee
- uniq
- vdir
| | FALSE | evaluated 3014 times by 21 testsEvaluated by:- cp
- date
- df
- dir
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- stat
- tail
- tee
- touch
- uniq
- vdir
|
| TRUE | never evaluated | | FALSE | evaluated 4228 times by 22 testsEvaluated by:- b2sum
- cp
- date
- df
- dir
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- stat
- tail
- tee
- touch
- uniq
- vdir
|
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-4228 |
| 98 | { | - |
| 99 | if (strlen (arglist[i]) == arglen)| TRUE | evaluated 1202 times by 19 testsEvaluated by:- b2sum
- cp
- date
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- stat
- tail
- tee
- uniq
- vdir
| | FALSE | evaluated 12 times by 4 tests |
| 12-1202 |
| 100 | | - |
| 101 | return i;executed 1202 times by 19 tests: return i;Executed by:- b2sum
- cp
- date
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- stat
- tail
- tee
- uniq
- vdir
| 1202 |
| 102 | else if (matchind == -1)| TRUE | evaluated 12 times by 4 tests | | FALSE | never evaluated |
| 0-12 |
| 103 | | - |
| 104 | matchind = i;executed 12 times by 4 tests: matchind = i; | 12 |
| 105 | else | - |
| 106 | { | - |
| 107 | | - |
| 108 | if (vallist == NULL| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 109 | || memcmp (vallist + valsize * matchind,| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 110 | vallist + valsize * i, valsize))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 111 | { | - |
| 112 | | - |
| 113 | | - |
| 114 | ambiguous = true; | - |
| 115 | } never executed: end of block | 0 |
| 116 | } never executed: end of block | 0 |
| 117 | } | - |
| 118 | }executed 3026 times by 22 tests: end of blockExecuted by:- b2sum
- cp
- date
- df
- dir
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- stat
- tail
- tee
- touch
- uniq
- vdir
| 3026 |
| 119 | if (ambiguous)| TRUE | never evaluated | | FALSE | evaluated 232 times by 15 testsEvaluated by:- b2sum
- cp
- date
- df
- dir
- du
- ls
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
|
| 0-232 |
| 120 | return -2; never executed: return -2; | 0 |
| 121 | else | - |
| 122 | return matchind;executed 232 times by 15 tests: return matchind;Executed by:- b2sum
- cp
- date
- df
- dir
- du
- ls
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
| 232 |
| 123 | } | - |
| 124 | | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | | - |
| 129 | | - |
| 130 | void | - |
| 131 | argmatch_invalid (const char *context, const char *value, ptrdiff_t problem) | - |
| 132 | { | - |
| 133 | char const *format = (problem == -1| TRUE | evaluated 37 times by 11 testsEvaluated by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
| | FALSE | never evaluated |
| 0-37 |
| 134 | ? _("invalid argument %s for %s") | - |
| 135 | : _("ambiguous argument %s for %s")); | - |
| 136 | | - |
| 137 | error (0, 0, format, quotearg_n_style (0, ARGMATCH_QUOTING_STYLE, value), | - |
| 138 | quote_n (1, context)); | - |
| 139 | }executed 37 times by 11 tests: end of blockExecuted by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
| 37 |
| 140 | | - |
| 141 | | - |
| 142 | | - |
| 143 | | - |
| 144 | | - |
| 145 | void | - |
| 146 | argmatch_valid (const char *const *arglist, | - |
| 147 | const char *vallist, size_t valsize) | - |
| 148 | { | - |
| 149 | size_t i; | - |
| 150 | const char *last_val = NULL; | - |
| 151 | | - |
| 152 | | - |
| 153 | | - |
| 154 | fputs (_("Valid arguments are:"), stderr); | - |
| 155 | for (i = 0; arglist[i]; i++)| TRUE | evaluated 163 times by 11 testsEvaluated by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
| | FALSE | evaluated 37 times by 11 testsEvaluated by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
|
| 37-163 |
| 156 | if ((i == 0)| TRUE | evaluated 37 times by 11 testsEvaluated by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
| | FALSE | evaluated 126 times by 11 testsEvaluated by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
|
| 37-126 |
| 157 | || memcmp (last_val, vallist + valsize * i, valsize))| TRUE | evaluated 113 times by 11 testsEvaluated by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
| | FALSE | evaluated 13 times by 3 tests |
| 13-113 |
| 158 | { | - |
| 159 | fprintf (stderr, "\n - %s", quote (arglist[i])); | - |
| 160 | last_val = vallist + valsize * i; | - |
| 161 | }executed 150 times by 11 tests: end of blockExecuted by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
| 150 |
| 162 | else | - |
| 163 | { | - |
| 164 | fprintf (stderr, ", %s", quote (arglist[i])); | - |
| 165 | }executed 13 times by 3 tests: end of block | 13 |
| 166 | putc ('\n', stderr); | - |
| 167 | }executed 37 times by 11 tests: end of blockExecuted by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
| 37 |
| 168 | | - |
| 169 | | - |
| 170 | | - |
| 171 | | - |
| 172 | | - |
| 173 | | - |
| 174 | | - |
| 175 | ptrdiff_t | - |
| 176 | __xargmatch_internal (const char *context, | - |
| 177 | const char *arg, const char *const *arglist, | - |
| 178 | const char *vallist, size_t valsize, | - |
| 179 | argmatch_exit_fn exit_fn) | - |
| 180 | { | - |
| 181 | ptrdiff_t res = argmatch (arg, arglist, vallist, valsize); | - |
| 182 | if (res >= 0)| TRUE | evaluated 1047 times by 16 testsEvaluated by:- cp
- date
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- tail
- tee
- uniq
| | FALSE | evaluated 37 times by 11 testsEvaluated by:- cp
- date
- dir
- numfmt
- od
- ptx
- shred
- sort
- touch
- uniq
- vdir
|
| 37-1047 |
| 183 | | - |
| 184 | return res;executed 1047 times by 16 tests: return res;Executed by:- cp
- date
- du
- ginstall
- ln
- ls
- mv
- numfmt
- od
- ptx
- rm
- shred
- sort
- tail
- tee
- uniq
| 1047 |
| 185 | | - |
| 186 | | - |
| 187 | argmatch_invalid (context, arg, res); | - |
| 188 | argmatch_valid (arglist, vallist, valsize); | - |
| 189 | (*exit_fn) (); | - |
| 190 | | - |
| 191 | return -1; never executed: return -1; | 0 |
| 192 | } | - |
| 193 | | - |
| 194 | | - |
| 195 | | - |
| 196 | const char * | - |
| 197 | argmatch_to_argument (const char *value, | - |
| 198 | const char *const *arglist, | - |
| 199 | const char *vallist, size_t valsize) | - |
| 200 | { | - |
| 201 | size_t i; | - |
| 202 | | - |
| 203 | for (i = 0; arglist[i]; i++)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 204 | if (!memcmp (value, vallist + valsize * i, valsize))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 205 | return arglist[i]; never executed: return arglist[i]; | 0 |
| 206 | return NULL; never executed: return ((void *)0) ; | 0 |
| 207 | } | - |
| 208 | | - |
| 209 | #ifdef TEST | - |
| 210 | | - |
| 211 | | - |
| 212 | | - |
| 213 | | - |
| 214 | | - |
| 215 | enum backup_type | - |
| 216 | { | - |
| 217 | | - |
| 218 | no_backups, | - |
| 219 | | - |
| 220 | | - |
| 221 | simple_backups, | - |
| 222 | | - |
| 223 | | - |
| 224 | | - |
| 225 | numbered_existing_backups, | - |
| 226 | | - |
| 227 | | - |
| 228 | numbered_backups | - |
| 229 | }; | - |
| 230 | | - |
| 231 | | - |
| 232 | | - |
| 233 | static const char *const backup_args[] = | - |
| 234 | { | - |
| 235 | "no", "none", "off", | - |
| 236 | "simple", "never", | - |
| 237 | "existing", "nil", | - |
| 238 | "numbered", "t", | - |
| 239 | 0 | - |
| 240 | }; | - |
| 241 | | - |
| 242 | static const enum backup_type backup_vals[] = | - |
| 243 | { | - |
| 244 | no_backups, no_backups, no_backups, | - |
| 245 | simple_backups, simple_backups, | - |
| 246 | numbered_existing_backups, numbered_existing_backups, | - |
| 247 | numbered_backups, numbered_backups | - |
| 248 | }; | - |
| 249 | | - |
| 250 | int | - |
| 251 | main (int argc, const char *const *argv) | - |
| 252 | { | - |
| 253 | const char *cp; | - |
| 254 | enum backup_type backup_type = no_backups; | - |
| 255 | | - |
| 256 | if (argc > 2) | - |
| 257 | { | - |
| 258 | fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", getprogname ()); | - |
| 259 | exit (1); | - |
| 260 | } | - |
| 261 | | - |
| 262 | if ((cp = getenv ("VERSION_CONTROL"))) | - |
| 263 | backup_type = XARGMATCH ("$VERSION_CONTROL", cp, | - |
| 264 | backup_args, backup_vals); | - |
| 265 | | - |
| 266 | if (argc == 2) | - |
| 267 | backup_type = XARGMATCH (getprogname (), argv[1], | - |
| 268 | backup_args, backup_vals); | - |
| 269 | | - |
| 270 | printf ("The version control is '%s'\n", | - |
| 271 | ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals)); | - |
| 272 | | - |
| 273 | return 0; | - |
| 274 | } | - |
| 275 | #endif | - |
| | |