diff --git a/.gitignore b/.gitignore index 6c1976f..2023dfa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,12 @@ bin/lowercase bin/nonzero bin/nutshell bin/pscat +bin/retval bin/rldecode bin/rlencode bin/roll +bin/roll_stdio +bin/rot13 bin/simexec bin/sleep bin/str diff --git a/Makefile b/Makefile index bce0cd4..ef93e1d 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ cleanprograms: $(RM) bin/str $(RM) bin/substitute $(RM) bin/sysexits + $(RM) bin/retval $(RM) bin/rldecode $(RM) bin/rlencode $(RM) bin/roll @@ -99,16 +100,22 @@ pscat.o: libio src/pscat.c pscat: libio pscat.o $(CC) $(CFLAGS) -o bin/pscat build/libio.o build/pscat.o +retval.o: libio src/retval.c sysexits + $(CC) $(CFLAGS) -c -o build/retval.o src/retval.c + +retval: libio retval.o + $(CC) $(CFLAGS) -o bin/retval build/retval.o build/libio.o + roll.o: lib/libio.h src/roll.c sysexits $(CC) $(CFLAGS) -c -o build/roll.o src/roll.c -roll: libio sysexits roll.o +roll: libio roll.o $(CC) $(CFLAGS) -o bin/roll build/libio.o build/roll.o roll_stdio.o: lib/libio.h src/roll.c sysexits $(CC) $(CFLAGS) -c -DUSE_STDIO -o build/roll_stdio.o src/roll.c -roll_stdio: libio sysexits roll_stdio.o +roll_stdio: libio roll_stdio.o $(CC) $(CFLAGS) -o bin/roll_stdio build/libio.o build/roll_stdio.o rot13.o: libio sysexits src/rot13.c diff --git a/src/retval.c b/src/retval.c index 5ede610..ca3d68d 100644 --- a/src/retval.c +++ b/src/retval.c @@ -1,24 +1,25 @@ -#include -#include -#include -#include -#include "libstr.h" -#include "noargvzero.h" +#include /* isdigit(3) */ +#include /* EX_USAGE */ +#include /* write(2) */ +#include "libio.h" /* fdprint(3), parse_uint(3) */ + +static char *program_name = "retval"; int main(int argc, char *argv[]){ - int retval; + unsigned int s; - NOARGVZERO(argv); - - if(argv[1] == NULL){ - fprintf(stderr, "Usage: %s [exit code]\n", argv[0]); + if(argc < 2){ +usage: write(2, "Usage: ", 7); + fdprint(2, argv[0] == NULL ? program_name : argv[0]); + write(2, " [status]\n", 10); return EX_USAGE; } - if(strint(argv[1], &retval, ASCII_DIGITS_DECIMAL_UPPER) == NULL){ - fprintf(stderr, "%s: %s: Not an integer\n", argv[0], argv[1]); - return EX_USAGE; - } + for(s = 0; argv[1][s] != '\0'; ++s) + if(!isdigit(argv[1][s])) + goto usage; - return retval; + s = parse_uint(argv[1]); + + return s; }