1
0
Fork 0

remove str, incorporated into bonsai

This commit is contained in:
dtb 2023-12-24 19:46:37 -07:00
parent f8de45942d
commit 8d54508796
4 changed files with 0 additions and 145 deletions

View File

@ -1 +0,0 @@
str: str.c

View File

@ -1,40 +0,0 @@
# Packaging str
## Files
- `src/str`
- Can be moved to a system sources directory if it's desirable to keep
system sources on hand. Doesn't reference anything else in the
repository.
- `str.1`
- Included manual page for `str`. Can be placed in the appropriate
manual pages directory. If it displays weirdly and your fix is
portable, mail me and I'll probably bring it upstream.
- `str.c`
- A single C file that builds to a single executable, which should be
named `str`.
- `str`
- Program binary. Should be placed in a user-accessible binaries
directory.
## Dependencies
- `<sysexits.h>`
- Ignored if `EX_USAGE` is already defined.
- C standard library
## Compilation
```
cc -o str str.c
```
Or without `<sysexits.h>`:
```
cc -DEX_USAGE=1 -o str str.c
```

View File

@ -1,47 +0,0 @@
.TH STRIS 1
.SH NAME
str \(en test the character types of string arguments
.SH SYNOPSIS
str
.RB [ type ]
.RB [ string... ]
.SH DESCRIPTION
Str tests each character in an arbitrary quantity of string arguments against
the function of the same name within ctype(3).
.SH DIAGNOSTICS
Str exits successfully if all tests pass and unsuccessfully if a test failed.
.PP
Str will exit unsuccessfully if a string is empty, as none of its contents
passed the test.
.PP
Str will print a message to standard error and exit unsuccessfully if used
improperly.
.SH ISVALUE
Str used to have an "isvalue" type as an extension to ctype(3). This was
removed in favor of using strcmp(1) to compare strings against the empty string
('').
.SH BUGS
There's no way of knowing which argument failed the test without re-testing
arguments individually.
.PP
If a character in a string isn't valid ASCII str will exit unsuccessfully.
.SH SEE ALSO
ctype(3), ascii(7)
.SH COPYRIGHT
Public domain.

View File

@ -1,57 +0,0 @@
#include <ctype.h>
#include <stddef.h> /* NULL */
#include <stdio.h> /* fprintf(3) */
#include <string.h> /* strcmp(3) */
#if !defined EX_USAGE
# include <sysexits.h>
#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;
int r;
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]);
return EX_USAGE;
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(argv[0][i] < 0x80 && !ctypes[ctype].f(argv[0][i]))
return 1;
else
r = 0;
return r;
}