independ str(1)
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h> /* strcmp(3) */
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h> /* write(2) */
|
||||
#include "libio.h" /* fdprint(3) */
|
||||
#include "usefulmacros.h"
|
||||
|
||||
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){
|
||||
error: write(2, "Usage: ", 7);
|
||||
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
|
||||
write(2, " [type] [string...]\n", 20);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
for(ctype = 0; ctype < ARRAYLEN(ctypes); ++ctype)
|
||||
if(strcmp(argv[1], ctypes[ctype].name) == 0)
|
||||
goto pass;
|
||||
goto error;
|
||||
|
||||
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