From 1870940c599328efa8ee33998688c8a49922af08 Mon Sep 17 00:00:00 2001 From: Simon Lieb Date: Fri, 2 Aug 2013 23:23:04 +0200 Subject: [PATCH] slow - Initial commit --- LICENSE | 21 +++++++++++++++++++++ Makefile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ config.mk | 19 +++++++++++++++++++ slow.c | 21 +++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 config.mk create mode 100644 slow.c diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7b55317 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT/X Consortium License + +© 2006-2012 Simon Lien + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b3a70fc --- /dev/null +++ b/Makefile @@ -0,0 +1,49 @@ +# slow - slow down output +# See LICENSE file for copyright and license details. + +include config.mk + +SRC = slow.c +OBJ = ${SRC:.c=.o} + +all: options slow + +options: + @echo slow build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "CC = ${CC}" + +.c.o: + @echo CC $< + @${CC} -c ${CFLAGS} $< + +${OBJ}: config.mk + +slow: ${OBJ} + @echo CC -o $@ + @${CC} -o $@ ${OBJ} ${LDFLAGS} + +clean: + @echo cleaning + @rm -f slow ${OBJ} slow-${VERSION}.tar.gz + +dist: clean + @echo creating dist tarball + @mkdir -p slow-${VERSION} + @cp -R LICENSE Makefile config.mk ${SRC} slow-${VERSION} + @tar -cf slow-${VERSION}.tar slow-${VERSION} + @gzip slow-${VERSION}.tar + @rm -rf slow-${VERSION} + +install: all + @echo installing executable file to ${DESTDIR}${PREFIX}/bin + @mkdir -p ${DESTDIR}${PREFIX}/bin + @cp -f slow ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/slow + +uninstall: + @echo removing executable file from ${DESTDIR}${PREFIX}/bin + @rm -f ${DESTDIR}${PREFIX}/bin/slow + +.PHONY: all options clean dist install uninstall diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..e133ebe --- /dev/null +++ b/config.mk @@ -0,0 +1,19 @@ +# slow version +VERSION = 0.1 + +# Customize below to fit your system + +# paths +PREFIX = /usr/local + +# includes and libs +INCS = +LIBS = + +# flags +CPPFLAGS = -DVERSION=\"${VERSION}\" +CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} +LDFLAGS = -s ${LIBS} + +# compiler and linker +CC = cc diff --git a/slow.c b/slow.c new file mode 100644 index 0000000..0c9e59c --- /dev/null +++ b/slow.c @@ -0,0 +1,21 @@ +#define _XOPEN_SOURCE 500 +#include +#include +#include + +int main(int argc, char *argv[]) { + char line[1024]; + int linesize = sizeof(line); + int useconds = 1000000; + + if (argc == 2) { + useconds = atoi(argv[1]); + } + + while(fgets(line, linesize, stdin)) { + usleep(useconds); + fputs(line, stdout); + } + + return 0; +}