commit 5da1768ac0aae5a2fd93cea096a0d69245220148 Author: z3bra <willy@mailoo.org> Date: Sun Feb 15 12:28:49 2015 initial commit. Maybe latest? Diffstat: Makefile | 40 ++++++++++++++++++++++++++++++++++++++++ mkb.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile @@ -0,0 +1,40 @@ +PREFIX:=/usr +MANPREFIX:=$(PREFIX)/share/man + +CC := tcc +LD := $(CC) + +CFLAGS += -pedantic -Wall +LDFLAGS += + +BIN = mkb +SRC = \ + mkb.c + +OBJ = $(SRC:.c=.o) + +.POSIX: +.SUFFIXES: .1 .1.gz + +all: binutils + +binutils: $(BIN) + +.o: + @echo "LD $@" + @$(LD) $< -o $@ $(LDFLAGS) + +.c.o: + @echo "CC $<" + @$(CC) -c $< -o $@ $(CFLAGS) + +install: $(BIN) + mkdir -p $(DESTDIR)$(PREFIX)/bin/ + cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin/ + chmod 755 $(DESTDIR)$(PREFIX)/bin/$(BIN) + +uninstall: + rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN); \ + +clean : + rm -f $(OBJ) $(BIN) diff --git a/mkb.c b/mkb.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <err.h> + +#define DEFAULT_SIZE 32 +#define DEFAULT_CHAR1 "[1;37m▣" +#define DEFAULT_CHAR2 "[1;30m▣" + +int +main (int argc, char **argv) +{ + int i; + unsigned float size = 0; + unsigned float value = 0; + char *char1 = NULL; + char *char2 = NULL; + char *current = NULL; + + size = getenv("SIZE") ? atoi(getenv("SIZE")) : DEFAULT_SIZE; + char1 = getenv("CHAR1") ? getenv("CHAR1") : DEFAULT_CHAR1; + char2 = getenv("CHAR2") ? getenv("CHAR2") : DEFAULT_CHAR2; + + if (argc < 2) + scanf("%f", &value); + else + value = atof(argv[1]); + + if (value > 100) + errx(1, "value should remain between 0 and 100"); + + for (i=0; i<size; i++) { + current = (i < value / 100 * size) ? char1 : char2; + write(fileno(stdout), current, strnlen(current, 32)); + } + + putc('\n', stdout); + + return 0; +}