intcmp(1): formatting, fixes argv[0] ternary and usage function

This commit is contained in:
Emma Tebibyte 2024-07-13 17:01:53 -06:00
parent d9dd4e6057
commit 0c530dffbf
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -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;
}