From 120d8179202f359b4cca399ed396a205e28b01c2 Mon Sep 17 00:00:00 2001 From: Christoph Lohmann <20h@r-36.net> Date: Mon, 23 Apr 2012 16:27:40 +0200 Subject: [PATCH] Adding the yes(1) command. --- Makefile | 3 ++- TODO | 1 - yes.1 | 10 ++++++++++ yes.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 yes.1 create mode 100644 yes.c diff --git a/Makefile b/Makefile index 5035701..832057e 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,8 @@ SRC = \ tty.c \ uname.c \ seq.c \ - wc.c + wc.c \ + yes.c OBJ = $(SRC:.c=.o) $(LIB) BIN = $(SRC:.c=) diff --git a/TODO b/TODO index 83c8b5e..91aa2a6 100644 --- a/TODO +++ b/TODO @@ -60,4 +60,3 @@ unlink file who -yes [string] diff --git a/yes.1 b/yes.1 new file mode 100644 index 0000000..6b4c0c5 --- /dev/null +++ b/yes.1 @@ -0,0 +1,10 @@ +.TH YES 1 sbase\-VERSION +.SH NAME +yes \- output a string repeatedly +.SH SYNOPSIS +.B yes +.RB [ string ... ] +.SH DESCRIPTION +.B yes +will repeatedly output 'y' or the strings specified. + diff --git a/yes.c b/yes.c new file mode 100644 index 0000000..20de891 --- /dev/null +++ b/yes.c @@ -0,0 +1,44 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include + +#include "arg.h" +#include "util.h" + +char *argv0; + +void +usage(void) +{ + eprintf("usage: %s [string ...]\n", basename(argv0)); +} + +int +main(int argc, char *argv[]) +{ + int i; + + ARGBEGIN { + default: + usage(); + } ARGEND; + + if (!argc) { + for(;;) + puts("y"); + } + + for (;;) { + for (i = 0; i < argc; i++) { + fputs(argv[i], stdout); + if (argv[i+1] != NULL) + fputs(" ", stdout); + } + fputs("\n", stdout); + } + + return EXIT_SUCCESS; +} +