intcmp(1): formatting, fixes argv[0] ternary and usage function
This commit is contained in:
parent
d9dd4e6057
commit
0c530dffbf
19
src/intcmp.c
19
src/intcmp.c
|
@ -33,10 +33,8 @@
|
|||
static char *program_name = "intcmp";
|
||||
|
||||
int usage(char *s) {
|
||||
fprintf(
|
||||
stderr, "Usage: %s [-egl] integer integer...\n",
|
||||
s == NULL ? program_name : s
|
||||
);
|
||||
fprintf(stderr, "Usage: %s [-egl] integer integer...\n", s);
|
||||
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
|
@ -45,25 +43,26 @@ int main(int argc, char *argv[]) {
|
|||
size_t i;
|
||||
unsigned char mode;
|
||||
int r; /* reference integer */
|
||||
char *s = (argv[0] == NULL ? program_name : argv[0]);
|
||||
|
||||
mode = 0;
|
||||
|
||||
if (argc == 0 | argc < 3) { return usage(argv[0]); }
|
||||
if (argc == 0 | argc < 3) { return usage(s); }
|
||||
|
||||
while ((c = getopt(argc, argv, "egl")) != -1) {
|
||||
switch(c){
|
||||
switch (c){
|
||||
case 'e': mode |= EQUAL; break;
|
||||
case 'g': mode |= GREATER; break;
|
||||
case 'l': mode |= LESSER; break;
|
||||
default: return usage(argv[0]);
|
||||
default: return usage(s);
|
||||
}
|
||||
}
|
||||
|
||||
if(optind + 2 /* ref cmp */ > argc){ return usage(argv[0]); }
|
||||
if (optind + 2 /* ref cmp */ > argc) { return usage(s); }
|
||||
|
||||
i = optind;
|
||||
|
||||
do{
|
||||
do {
|
||||
r = c;
|
||||
c = strtol(argv[i], &argv[i], 10);
|
||||
|
||||
|
@ -82,7 +81,7 @@ int main(int argc, char *argv[]) {
|
|||
|| (!(mode & GREATER) && r > c)
|
||||
|| (!(mode & LESSER) && r < c)
|
||||
) { return 1; }
|
||||
} while(++i < argc);
|
||||
} while (++i < argc);
|
||||
|
||||
return EX_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user