1
0
Fork 0
This commit is contained in:
dtb 2023-12-15 21:35:06 -07:00
parent 53a74e7c46
commit 18305d0589
3 changed files with 50 additions and 29 deletions

View File

@ -1,12 +1,2 @@
RM = rm -f
TARGETS = str
all: $(TARGETS)
str: str.c
$(CC) -DINCLUDE_ISVALUE=1 -o $@ $@.c
clean:
$(RM) $(TARGETS)
.PHONY: all clean
$(CC) -include isvalue.c -o $@ $@.c

40
str/packaging.md Normal file
View File

@ -0,0 +1,40 @@
# 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 `simexec`.
- `simexec`
- 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 -include isvalue.c -o simexec simexec.c
```
Or without `<sysexits.h>`:
```
cc -DEX_USAGE=1 -include isvalue.c -o simexec simexec.c
```

View File

@ -5,15 +5,6 @@
#if !defined EX_USAGE
# include <sysexits.h>
#endif
#if defined INCLUDE_ISVALUE_C
# include "isvalue.c"
/* This is a special addition to the command that lets `str isvalue "$input"`
* function as a lightweight replacement to the common `test -n "$input"` or
* `[ -n "$input" ]`. This will speed up your shellscript execution by a tad
* ONLY if test(1) isn't already built into your shell (most of the time, it
* is, and saves you the overhead of spawning a new process, which is greater
* than the savings of switching from test(1) to this program). */
#endif
static char *program_name = "str";
@ -43,17 +34,17 @@ int main(int argc, char *argv[]){
int i;
int r;
if(argc < 3){
usage: fprintf(stderr, "Usage: %s [type] [string...]\n",
argv[0] == NULL ? program_name : argv[0]
);
return EX_USAGE;
if(argc >= 3){
for(ctype = 0; ctype < (sizeof ctypes) / (sizeof *ctypes);
++ctype)
if(strcmp(argv[1], ctypes[ctype].name) == 0)
goto pass;
}
for(ctype = 0; ctype < (sizeof(ctypes)/sizeof(ctypes[0])); ++ctype)
if(strcmp(argv[1], ctypes[ctype].name) == 0)
goto pass;
goto usage;
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)