independ str(1)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#include <ctype.h>
|
||||
#include <stddef.h> /* NULL */
|
||||
#include <stdio.h> /* fprintf(3) */
|
||||
#include <string.h> /* strcmp(3) */
|
||||
#ifdef DONT_USE_SYSTEM_SYSEXITS
|
||||
# include "../include/sysexits.h" /* EX_USAGE */
|
||||
#else
|
||||
# include <sysexits.h> /* EX_USAGE */
|
||||
#endif
|
||||
|
||||
static char *program_name = "str";
|
||||
|
||||
static struct {
|
||||
char *name;
|
||||
int (*f)(int);
|
||||
}ctypes[] = {
|
||||
{ "isalnum", isalnum },
|
||||
{ "isalpha", isalpha },
|
||||
{ "isblank", isblank },
|
||||
{ "iscntrl", iscntrl },
|
||||
{ "isdigit", isdigit },
|
||||
{ "isxdigit", isxdigit },
|
||||
{ "isgraph", isgraph },
|
||||
{ "islower", islower },
|
||||
{ "isprint", isprint },
|
||||
{ "ispunct", ispunct },
|
||||
{ "isspace", isspace },
|
||||
{ "isupper", isupper }
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int ctype;
|
||||
int i;
|
||||
|
||||
if(argc < 3){
|
||||
usage: fprintf(stderr, "Usage: %s [type] [string...]\n",
|
||||
argv[0] == NULL ? program_name : argv[0]
|
||||
);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
for(ctype = 0; ctype < (sizeof(ctypes)/sizeof(ctypes[0])); ++ctype)
|
||||
if(strcmp(argv[1], ctypes[ctype].name) == 0)
|
||||
goto pass;
|
||||
goto usage;
|
||||
|
||||
pass: for(argv += 2; *argv != NULL; ++argv)
|
||||
for(i = 0; argv[0][i] != '\0'; ++i)
|
||||
if(!ctypes[ctype].f(argv[0][i]))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user