From 3c243e4a09a55e7659f703b13a1c50f9ce82d5d9 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 14 Jul 2024 03:20:15 -0600 Subject: [PATCH] str(1): formatting --- src/str.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/str.c b/src/str.c index b4725eb..73bb911 100644 --- a/src/str.c +++ b/src/str.c @@ -29,7 +29,7 @@ static char *program_name = "str"; static struct { char *name; int (*f)(int); -}ctypes[] = { +} ctypes[] = { { "isalnum", isalnum }, { "isalpha", isalpha }, { "isblank", isblank }, @@ -49,27 +49,33 @@ int main(int argc, char *argv[]){ int i; int r; - if(argc >= 3){ - for(ctype = 0; ctype < (sizeof ctypes) / (sizeof *ctypes); - ++ctype) - if(strcmp(argv[1], ctypes[ctype].name) == 0) + if (argc >= 3) { + for (ctype = 0; ctype < (sizeof ctypes) / (sizeof *ctypes); ++ctype) { + if(strcmp(argv[1], ctypes[ctype].name) == 0) { goto pass; + } + } } - fprintf(stderr, "Usage: %s type string...\n", - argv[0] == NULL ? program_name : argv[0]); + fprintf( + stderr, + "Usage: %s type string...\n", + argv[0] == NULL ? program_name : argv[0] + ); return EX_USAGE; -pass: for(argv += 2, r = 1; *argv != NULL; ++argv) - for(i = 0; argv[0][i] != '\0'; ++i) +pass: for (argv += 2, r = 1; *argv != NULL; ++argv) { + for (i = 0; argv[0][i] != '\0'; ++i) { /* First checks if argv[0][i] is valid ASCII; ctypes(3) * don't handle non-ASCII. * This is bad. */ - if((unsigned char)argv[0][i] < 0x80 && !ctypes[ctype].f(argv[0][i])) - return 1; - else - r = 0; + if( + (unsigned char)argv[0][i] < 0x80 && !ctypes[ctype].f(argv[0][i]) + ) { return 1; } + else { r = 0; } + } + } return r; }