forked from bonsai/harakit
remove str(1)
This commit is contained in:
parent
cfef7aec1d
commit
3910c341bd
7
Makefile
7
Makefile
@ -28,7 +28,7 @@ RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \
|
||||
CFLAGS += -I$(SYSEXITS)
|
||||
|
||||
.PHONY: all
|
||||
all: dj false fop hru intcmp mm npc rpn scrut str strcmp stris swab true
|
||||
all: dj false fop hru intcmp mm npc rpn scrut strcmp stris swab true
|
||||
|
||||
build:
|
||||
# keep build/include until bindgen(1) has stdin support
|
||||
@ -118,11 +118,6 @@ scrut: build/bin/scrut
|
||||
build/bin/scrut: src/scrut.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/scrut.c
|
||||
|
||||
.PHONY: str
|
||||
str: build/bin/str
|
||||
build/bin/str: src/str.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/str.c
|
||||
|
||||
.PHONY: stris
|
||||
stris: build/bin/stris
|
||||
build/bin/stris: src/stris.rs build build/o/libgetopt.rlib \
|
||||
|
58
docs/str.1
58
docs/str.1
@ -1,58 +0,0 @@
|
||||
.\" Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||
.\" Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media>
|
||||
.\"
|
||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
|
||||
.TH STR 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 DEPRECATED FEATURES
|
||||
|
||||
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 AUTHOR
|
||||
|
||||
Written by DTB <trinity@trinity.moe>.
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||
<https://gnu.org/licenses/gpl.html>.
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
ctype(3p), strcmp(1), ascii(7)
|
75
src/str.c
75
src/str.c
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
||||
* Copyright (c) 2023 Marceline Cramer <mars@tebibyte.media>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stddef.h> /* NULL */
|
||||
#include <stdio.h> /* fprintf(3) */
|
||||
#include <stdlib.h> /* EXIT_FAILURE */
|
||||
#include <string.h> /* strcmp(3) */
|
||||
#include <sysexits.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;
|
||||
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((unsigned char)argv[0][i] < 0x80 && !ctypes[ctype].f(argv[0][i]))
|
||||
return 1;
|
||||
else
|
||||
r = 0;
|
||||
|
||||
return r;
|
||||
}
|
Loading…
Reference in New Issue
Block a user