From 97c96d1063bbde4c51d2aa9e670aaf69a3d63299 Mon Sep 17 00:00:00 2001 From: dtb Date: Tue, 13 Sep 2022 00:52:52 -0400 Subject: [PATCH] independ pscat(1) --- Makefile | 20 +++++++++++++------- pscat/Makefile | 28 ++++++++++++++++++++++++++++ {man => pscat}/pscat.1 | 0 {src => pscat}/pscat.c | 29 +++++++++++++++++++---------- 4 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 pscat/Makefile rename {man => pscat}/pscat.1 (100%) rename {src => pscat}/pscat.c (79%) diff --git a/Makefile b/Makefile index 7a8dcd1..d164c7d 100644 --- a/Makefile +++ b/Makefile @@ -93,11 +93,13 @@ nutshell.o: libio usefulmacros src/nutshell.c src/nutshell.h src/nutshell_builti nutshell: libio nutshell.o $(CC) $(CFLAGS) -o bin/nutshell build/libio.o build/nutshell.o -pscat.o: libio src/pscat.c - $(CC) $(CFLAGS) -c -o build/pscat.o src/pscat.c +pscat: bin/pscat -pscat: libio pscat.o - $(CC) $(CFLAGS) -o bin/pscat build/libio.o build/pscat.o +bin/pscat: pscat/pscat + mv pscat/pscat bin/pscat + +pscat/pscat: sysexits pscat/pscat.c pscat/Makefile + $(MAKE) -C pscat sane retval.o: libio src/retval.c sysexits $(CC) $(CFLAGS) -c -o build/retval.o src/retval.c @@ -105,13 +107,17 @@ retval.o: libio src/retval.c sysexits retval: libio retval.o $(CC) $(CFLAGS) -o bin/retval build/retval.o build/libio.o -roll: roll/roll +roll: bin/roll + +bin/roll: roll/roll mv roll/roll bin/roll roll/roll: sysexits roll/roll.c roll/Makefile $(MAKE) -C roll sane -rot13: rot13/rot13 +rot13: bin/rot13 + +bin/rot13: rot13/rot13 mv rot13/rot13 bin/rot13 rot13/rot13: sysexits rot13/rot13.c rot13/Makefile @@ -288,4 +294,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 stdbool sysexits usefulmacros +.PHONY: all clean cleanlibraries cleanprograms pscat roll rot13 stdbool sysexits usefulmacros diff --git a/pscat/Makefile b/pscat/Makefile new file mode 100644 index 0000000..0436451 --- /dev/null +++ b/pscat/Makefile @@ -0,0 +1,28 @@ +all: pscat + +clean: + rm -rf ../dist/pscat ../dist/pscat.tar ../dist/pscat.tar.gz pscat + +dist: ../dist/pscat.tar.gz + +sane: pscat.c ../include/sysexits.h + $(CC) -DUSE_ASCII_H -DDONT_USE_SYSTEM_SYSEXITS -o pscat pscat.c + +pscat: pscat.c + $(CC) -o pscat pscat.c + +../dist/pscat: pscat + mkdir -p ../dist/pscat.tmp/bin/ ../dist/pscat.tmp/share/man/man1/ + cp pscat ../dist/pscat.tmp/bin/pscat + cp pscat.1 ../dist/pscat.tmp/share/man/man1/pscat.1 + mv ../dist/pscat.tmp ../dist/pscat + +../dist/pscat.tar: ../dist/pscat + cd ../dist/pscat && pax -w -x ustar . >../pscat.tar.tmp + mv ../dist/pscat.tar.tmp ../dist/pscat.tar + +../dist/pscat.tar.gz: ../dist/pscat.tar + gzip -c <../dist/pscat.tar >../dist/pscat.tar.gz.tmp + mv ../dist/pscat.tar.gz.tmp ../dist/pscat.tar.gz + +.PHONY: all clean sane diff --git a/man/pscat.1 b/pscat/pscat.1 similarity index 100% rename from man/pscat.1 rename to pscat/pscat.1 diff --git a/src/pscat.c b/pscat/pscat.c similarity index 79% rename from src/pscat.c rename to pscat/pscat.c index f33a4c3..7f85356 100644 --- a/src/pscat.c +++ b/pscat/pscat.c @@ -1,15 +1,25 @@ -#include -#include +#ifndef DONT_USE_SYSTEM_SYSEXITS +# include +#else +# include "../include/sysexits.h" +#endif /* ifndef DONT_USE_SYSTEM_SYSEXITS */ + +#include #include #include -#include "libio.h" static char *program_name = "pscat"; /* Originally designed to use parentheses but changed to brackets to escape the * hassle of escaping them from the Bourne shell. */ -#define L_PAREN ASCII_LEFT_SQUARE_BRACKET -#define R_PAREN ASCII_RIGHT_SQUARE_BRACKET +#ifndef USE_ASCII_H +# define L_PAREN '[' +# define R_PAREN ']' +#else +# include "../include/ascii.h" +# define L_PAREN ASCII_LEFT_SQUARE_BRACKET +# define R_PAREN ASCII_RIGHT_SQUARE_BRACKET +#endif /* ifndef USE_ASCII_H */ /* Test string containing { c, '\0' } without iteration. * Theoretically saves a little bit of time compared to strcmp(3). */ @@ -53,7 +63,6 @@ check_arg(char **argv){ } int main(int argc, char *argv[]){ - char *argv0; char **psstart; int child; int i; @@ -61,13 +70,13 @@ int main(int argc, char *argv[]){ int retval; int terms; - argv0 = argv[0] == NULL ? program_name : argv[0]; retval = 0; if((terms = check_arg(++argv)) == 0){ - write(2, "Usage: ", 7); - fdprint(2, argv0); - write(2, " \"[\" [utility [argument...]] \"]\" ...\n", 37); + fprintf(stderr, + "Usage: %s \"[\" [utility [argument...]] \"]\" ...\n", + argv[0] == NULL ? program_name : argv[0] + ); return EX_USAGE; }