From 278f8f57a7946bb3cce41f471614ef52e3e77d48 Mon Sep 17 00:00:00 2001 From: dtb Date: Tue, 13 Sep 2022 23:54:18 -0400 Subject: [PATCH] independ str(1) --- Makefile | 12 +++++++----- str/Makefile | 28 ++++++++++++++++++++++++++++ {man => str}/str.1 | 0 {src => str}/str.c | 22 ++++++++++++---------- 4 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 str/Makefile rename {man => str}/str.1 (100%) rename {src => str}/str.c (66%) diff --git a/Makefile b/Makefile index d164c7d..95410c7 100644 --- a/Makefile +++ b/Makefile @@ -145,11 +145,13 @@ streq.o: libio sysexits src/streq.c streq: libio streq.o $(CC) $(CFLAGS) -o bin/streq build/libio.o build/streq.o -str.o: src/str.c - $(CC) $(CFLAGS) -c -o build/str.o src/str.c +str: bin/str -str: libio str.o - $(CC) $(CFLAGS) -o bin/str build/libio.o build/str.o +bin/str: str/str + mv str/str bin/str + +str/str: sysexits str/str.c str/Makefile + $(MAKE) -C str sane sleep.o: libio sysexits src/sleep.c usefulmacros $(CC) $(CFLAGS) -c -o build/sleep.o src/sleep.c @@ -294,4 +296,4 @@ unscii-user: curl "http://viznut.fi/unscii/unscii-16-full.pcf" >"~/.fonts/unscii-16-full.pcf" curl "http://viznut.fi/unscii/unscii-16-full.ttf" >"~/.fonts/unscii-16-full.ttf" -.PHONY: all clean cleanlibraries cleanprograms pscat roll rot13 stdbool sysexits usefulmacros +.PHONY: all clean cleanlibraries cleanprograms pscat roll rot13 stdbool str sysexits usefulmacros diff --git a/str/Makefile b/str/Makefile new file mode 100644 index 0000000..c04f6bf --- /dev/null +++ b/str/Makefile @@ -0,0 +1,28 @@ +all: str + +clean: + rm -rf ../dist/str ../dist/str.tar ../dist/str.tar.gz str + +dist: ../dist/str.tar.gz + +sane: str.c ../include/sysexits.h + $(CC) -DDONT_USE_SYSTEM_SYSEXITS -o str str.c + +str: str.c + $(CC) -o str str.c + +../dist/str: str + mkdir -p ../dist/str.tmp/bin/ ../dist/str.tmp/share/man/man1/ + cp str ../dist/str.tmp/bin/str + cp str.1 ../dist/str.tmp/share/man/man1/str.1 + mv ../dist/str.tmp ../dist/str + +../dist/str.tar: ../dist/str + cd ../dist/str && pax -w -x ustar . >../str.tar.tmp + mv ../dist/str.tar.tmp ../dist/str.tar + +../dist/str.tar.gz: ../dist/str.tar + gzip -c <../dist/str.tar >../dist/str.tar.gz.tmp + mv ../dist/str.tar.gz.tmp ../dist/str.tar.gz + +.PHONY: all clean sane diff --git a/man/str.1 b/str/str.1 similarity index 100% rename from man/str.1 rename to str/str.1 diff --git a/src/str.c b/str/str.c similarity index 66% rename from src/str.c rename to str/str.c index 5e063ad..3099a99 100644 --- a/src/str.c +++ b/str/str.c @@ -1,10 +1,12 @@ #include -#include +#include /* NULL */ +#include /* fprintf(3) */ #include /* strcmp(3) */ -#include -#include /* write(2) */ -#include "libio.h" /* fdprint(3) */ -#include "usefulmacros.h" +#ifdef DONT_USE_SYSTEM_SYSEXITS +# include "../include/sysexits.h" /* EX_USAGE */ +#else +# include /* EX_USAGE */ +#endif static char *program_name = "str"; @@ -31,16 +33,16 @@ int main(int argc, char *argv[]){ 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); +usage: fprintf(stderr, "Usage: %s [type] [string...]\n", + argv[0] == NULL ? program_name : argv[0] + ); return EX_USAGE; } - for(ctype = 0; ctype < ARRAYLEN(ctypes); ++ctype) + for(ctype = 0; ctype < (sizeof(ctypes)/sizeof(ctypes[0])); ++ctype) if(strcmp(argv[1], ctypes[ctype].name) == 0) goto pass; - goto error; + goto usage; pass: for(argv += 2; *argv != NULL; ++argv) for(i = 0; argv[0][i] != '\0'; ++i)