simplify
This commit is contained in:
parent
53a74e7c46
commit
18305d0589
12
str/Makefile
12
str/Makefile
@ -1,12 +1,2 @@
|
|||||||
RM = rm -f
|
|
||||||
TARGETS = str
|
|
||||||
|
|
||||||
all: $(TARGETS)
|
|
||||||
|
|
||||||
str: str.c
|
str: str.c
|
||||||
$(CC) -DINCLUDE_ISVALUE=1 -o $@ $@.c
|
$(CC) -include isvalue.c -o $@ $@.c
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) $(TARGETS)
|
|
||||||
|
|
||||||
.PHONY: all clean
|
|
||||||
|
40
str/packaging.md
Normal file
40
str/packaging.md
Normal 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
|
||||||
|
```
|
27
str/str.c
27
str/str.c
@ -5,15 +5,6 @@
|
|||||||
#if !defined EX_USAGE
|
#if !defined EX_USAGE
|
||||||
# include <sysexits.h>
|
# include <sysexits.h>
|
||||||
#endif
|
#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";
|
static char *program_name = "str";
|
||||||
|
|
||||||
@ -43,17 +34,17 @@ int main(int argc, char *argv[]){
|
|||||||
int i;
|
int i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if(argc < 3){
|
if(argc >= 3){
|
||||||
usage: fprintf(stderr, "Usage: %s [type] [string...]\n",
|
for(ctype = 0; ctype < (sizeof ctypes) / (sizeof *ctypes);
|
||||||
argv[0] == NULL ? program_name : argv[0]
|
++ctype)
|
||||||
);
|
if(strcmp(argv[1], ctypes[ctype].name) == 0)
|
||||||
return EX_USAGE;
|
goto pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ctype = 0; ctype < (sizeof(ctypes)/sizeof(ctypes[0])); ++ctype)
|
fprintf(stderr, "Usage: %s [type] [string...]\n",
|
||||||
if(strcmp(argv[1], ctypes[ctype].name) == 0)
|
argv[0] == NULL ? program_name : argv[0]);
|
||||||
goto pass;
|
|
||||||
goto usage;
|
return EX_USAGE;
|
||||||
|
|
||||||
pass: for(argv += 2, r = 1; *argv != NULL; ++argv)
|
pass: for(argv += 2, r = 1; *argv != NULL; ++argv)
|
||||||
for(i = 0; argv[0][i] != '\0'; ++i)
|
for(i = 0; argv[0][i] != '\0'; ++i)
|
||||||
|
Loading…
Reference in New Issue
Block a user