str(1): formatting
This commit is contained in:
parent
49031102f2
commit
3c243e4a09
32
src/str.c
32
src/str.c
@ -29,7 +29,7 @@ static char *program_name = "str";
|
|||||||
static struct {
|
static struct {
|
||||||
char *name;
|
char *name;
|
||||||
int (*f)(int);
|
int (*f)(int);
|
||||||
}ctypes[] = {
|
} ctypes[] = {
|
||||||
{ "isalnum", isalnum },
|
{ "isalnum", isalnum },
|
||||||
{ "isalpha", isalpha },
|
{ "isalpha", isalpha },
|
||||||
{ "isblank", isblank },
|
{ "isblank", isblank },
|
||||||
@ -49,27 +49,33 @@ int main(int argc, char *argv[]){
|
|||||||
int i;
|
int i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if(argc >= 3){
|
if (argc >= 3) {
|
||||||
for(ctype = 0; ctype < (sizeof ctypes) / (sizeof *ctypes);
|
for (ctype = 0; ctype < (sizeof ctypes) / (sizeof *ctypes); ++ctype) {
|
||||||
++ctype)
|
if(strcmp(argv[1], ctypes[ctype].name) == 0) {
|
||||||
if(strcmp(argv[1], ctypes[ctype].name) == 0)
|
|
||||||
goto pass;
|
goto pass;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Usage: %s type string...\n",
|
fprintf(
|
||||||
argv[0] == NULL ? program_name : argv[0]);
|
stderr,
|
||||||
|
"Usage: %s type string...\n",
|
||||||
|
argv[0] == NULL ? program_name : argv[0]
|
||||||
|
);
|
||||||
|
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
|
|
||||||
pass: for(argv += 2, r = 1; *argv != NULL; ++argv)
|
pass: for (argv += 2, r = 1; *argv != NULL; ++argv) {
|
||||||
for(i = 0; argv[0][i] != '\0'; ++i)
|
for (i = 0; argv[0][i] != '\0'; ++i) {
|
||||||
/* First checks if argv[0][i] is valid ASCII; ctypes(3)
|
/* First checks if argv[0][i] is valid ASCII; ctypes(3)
|
||||||
* don't handle non-ASCII.
|
* don't handle non-ASCII.
|
||||||
* This is bad. */
|
* This is bad. */
|
||||||
if((unsigned char)argv[0][i] < 0x80 && !ctypes[ctype].f(argv[0][i]))
|
if(
|
||||||
return 1;
|
(unsigned char)argv[0][i] < 0x80 && !ctypes[ctype].f(argv[0][i])
|
||||||
else
|
) { return 1; }
|
||||||
r = 0;
|
else { r = 0; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user