independ str(1)
This commit is contained in:
parent
97c96d1063
commit
278f8f57a7
12
Makefile
12
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
|
||||
|
28
str/Makefile
Normal file
28
str/Makefile
Normal file
@ -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
|
@ -1,10 +1,12 @@
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <stddef.h> /* NULL */
|
||||
#include <stdio.h> /* fprintf(3) */
|
||||
#include <string.h> /* strcmp(3) */
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h> /* write(2) */
|
||||
#include "libio.h" /* fdprint(3) */
|
||||
#include "usefulmacros.h"
|
||||
#ifdef DONT_USE_SYSTEM_SYSEXITS
|
||||
# include "../include/sysexits.h" /* EX_USAGE */
|
||||
#else
|
||||
# include <sysexits.h> /* 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)
|
Loading…
Reference in New Issue
Block a user