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
|
streq: libio streq.o
|
||||||
$(CC) $(CFLAGS) -o bin/streq build/libio.o build/streq.o
|
$(CC) $(CFLAGS) -o bin/streq build/libio.o build/streq.o
|
||||||
|
|
||||||
str.o: src/str.c
|
str: bin/str
|
||||||
$(CC) $(CFLAGS) -c -o build/str.o src/str.c
|
|
||||||
|
|
||||||
str: libio str.o
|
bin/str: str/str
|
||||||
$(CC) $(CFLAGS) -o bin/str build/libio.o build/str.o
|
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
|
sleep.o: libio sysexits src/sleep.c usefulmacros
|
||||||
$(CC) $(CFLAGS) -c -o build/sleep.o src/sleep.c
|
$(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.pcf" >"~/.fonts/unscii-16-full.pcf"
|
||||||
curl "http://viznut.fi/unscii/unscii-16-full.ttf" >"~/.fonts/unscii-16-full.ttf"
|
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 <ctype.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h> /* NULL */
|
||||||
|
#include <stdio.h> /* fprintf(3) */
|
||||||
#include <string.h> /* strcmp(3) */
|
#include <string.h> /* strcmp(3) */
|
||||||
#include <sysexits.h>
|
#ifdef DONT_USE_SYSTEM_SYSEXITS
|
||||||
#include <unistd.h> /* write(2) */
|
# include "../include/sysexits.h" /* EX_USAGE */
|
||||||
#include "libio.h" /* fdprint(3) */
|
#else
|
||||||
#include "usefulmacros.h"
|
# include <sysexits.h> /* EX_USAGE */
|
||||||
|
#endif
|
||||||
|
|
||||||
static char *program_name = "str";
|
static char *program_name = "str";
|
||||||
|
|
||||||
@ -31,16 +33,16 @@ int main(int argc, char *argv[]){
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(argc < 3){
|
if(argc < 3){
|
||||||
error: write(2, "Usage: ", 7);
|
usage: fprintf(stderr, "Usage: %s [type] [string...]\n",
|
||||||
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
|
argv[0] == NULL ? program_name : argv[0]
|
||||||
write(2, " [type] [string...]\n", 20);
|
);
|
||||||
return EX_USAGE;
|
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)
|
if(strcmp(argv[1], ctypes[ctype].name) == 0)
|
||||||
goto pass;
|
goto pass;
|
||||||
goto error;
|
goto usage;
|
||||||
|
|
||||||
pass: for(argv += 2; *argv != NULL; ++argv)
|
pass: for(argv += 2; *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