Tidying up

This commit is contained in:
Bruce Hill 2019-03-01 17:13:38 -08:00
parent e48f973be9
commit 1c70bda212

12
arg.c
View File

@ -12,9 +12,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#define EXIT_SUCCESS 0 const int EXIT_SUCCESS = 0;
#define EXIT_NO_MATCH 1 const int EXIT_NO_MATCH = 1;
#define EXIT_BAD_USAGE -1 const int EXIT_BAD_USAGE = -1;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -32,14 +32,14 @@ int main(int argc, char **argv)
if (argv[i+1] && argv[i+1][0] != '-') // --flag <value> if (argv[i+1] && argv[i+1][0] != '-') // --flag <value>
puts(argv[i+1]); // value of the flag puts(argv[i+1]); // value of the flag
return EXIT_SUCCESS; return EXIT_SUCCESS;
} else if (arg[flaglen] == '=') { // --flag=... } else if (arg[flaglen] == '=') { // --flag=<value>
puts(&arg[flaglen+1]); puts(&arg[flaglen+1]);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
} }
if (ischarflag && arg[0] == '-' && arg[1] != '-') { if (ischarflag && arg[0] == '-' && arg[1] != '-') {
// If flag is single-character without a value, e.g. -f, look // If flag is single-character, e.g. -f, look for it among other
// for it among other single character flags like -xfy. // single character flags like -xfy.
for (char *c = &arg[1]; *c; c++) { for (char *c = &arg[1]; *c; c++) {
if (*c == flag[1]) if (*c == flag[1])
return EXIT_SUCCESS; return EXIT_SUCCESS;