summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile36
-rw-r--r--clock.c3
-rw-r--r--common.h2
-rw-r--r--counter.c3
-rwxr-xr-xlarge.sh160
-rw-r--r--timer.c5
7 files changed, 111 insertions, 99 deletions
diff --git a/.gitignore b/.gitignore
index 2cdb29a..3fcf56d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@
*.lo
*.bo
/large.h
+/large-*.c
/pdatools
/pdatools.c
/backlight
diff --git a/Makefile b/Makefile
index 69b6757..b0afb6b 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,13 @@ HDR =\
common.h\
large.h
-OBJ = $(BIN:=.o)
+COMMON =\
+ large-digits.o\
+ large-colon.o\
+ large-dot.o\
+ large-minus.o
+
+OBJ = $(BIN:=.o) $(COMMON)
BOBJ = $(OBJ:.o=.bo)
MAN1 = $(BIN:=.1)
@@ -48,16 +54,28 @@ pdatools.c: pdatools.c.in Makefile
cat pdatools.c.in >> $@
large.h: large.sh
- ./large.sh > $@
+ ./large.sh h > $@
+
+large-digits.c: large.sh
+ ./large.sh c 0 1 2 3 4 5 6 7 8 9 > $@
+
+large-colon.c: large.sh
+ ./large.sh c colon > $@
+
+large-dot.c: large.sh
+ ./large.sh c dot > $@
+
+large-minus.c: large.sh
+ ./large.sh c minus > $@
backlight: backlight.o
$(CC) -o $@ $@.o $(LDFLAGS)
-clock: clock.o
- $(CC) -o $@ $@.o $(LDFLAGS)
+clock: clock.o large-digits.o large-colon.o
+ $(CC) -o $@ $@.o large-digits.o large-colon.o $(LDFLAGS)
-counter: counter.o
- $(CC) -o $@ $@.o $(LDFLAGS)
+counter: counter.o large-digits.o large-minus.o
+ $(CC) -o $@ $@.o large-digits.o large-minus.o $(LDFLAGS)
dice: dice.o
$(CC) -o $@ $@.o $(LDFLAGS)
@@ -65,8 +83,8 @@ dice: dice.o
stopwatch: stopwatch.o
$(CC) -o $@ $@.o $(LDFLAGS)
-timer: timer.o
- $(CC) -o $@ $@.o $(LDFLAGS)
+timer: timer.o large-digits.o large-colon.o large-dot.o large-minus.o
+ $(CC) -o $@ $@.o large-digits.o large-colon.o large-dot.o large-minus.o $(LDFLAGS)
install-common:
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1"
@@ -82,7 +100,7 @@ uninstall:
-rm -f -- "$(DESTDIR)$(PREFIX)/lib/pdatools"
clean:
- -rm -rf -- *.o *.a *.lo *.so *.bo *.su $(BIN) large.h pdatools pdatools.c
+ -rm -rf -- *.o *.a *.lo *.so *.bo *.su $(BIN) large.h large-*.c pdatools pdatools.c
.SUFFIXES:
.SUFFIXES: .o .c .bo
diff --git a/clock.c b/clock.c
index fd06edb..e4a8ce2 100644
--- a/clock.c
+++ b/clock.c
@@ -4,9 +4,6 @@
USAGE("[-u | -v | -w] [-2s]");
-#define INCLUDE_LARGE_COLON
-#include "large.h"
-
static volatile sig_atomic_t caught_sigterm = 0;
static volatile sig_atomic_t caught_sigwinch = 1;
diff --git a/common.h b/common.h
index 627fcc2..153940e 100644
--- a/common.h
+++ b/common.h
@@ -10,3 +10,5 @@
#include <sys/timerfd.h>
#include <sys/timex.h>
#include <termios.h>
+
+#include "large.h"
diff --git a/counter.c b/counter.c
index 1b8f637..2ebb5d1 100644
--- a/counter.c
+++ b/counter.c
@@ -6,9 +6,6 @@
USAGE("[-2s]");
-#define INCLUDE_LARGE_MINUS
-#include "large.h"
-
static volatile sig_atomic_t caught_sigterm = 0;
static volatile sig_atomic_t caught_sigwinch = 1;
diff --git a/large.sh b/large.sh
index 3b35d3d..2fccb5d 100755
--- a/large.sh
+++ b/large.sh
@@ -143,88 +143,90 @@ large_minus() {
' '
}
-printf '#define LARGE_Y %i\n' $(large_0 | wc -l)
-printf '#define LARGE_X %i\n' $(large_0 | head -n 1 | tr -d '\n' | wc -c)
-printf '#define LARGE_XC %i\n' $(large_colon | head -n 1 | tr -d '\n' | wc -c)
-printf '#define LARGE_XD %i\n' $(large_dot | head -n 1 | tr -d '\n' | wc -c)
-printf '#define LARGE_XM %i\n' $(large_minus | head -n 1 | tr -d '\n' | wc -c)
+what="$1"
+shift 1
+if test $# = 0; then
+ set 0 1 2 3 4 5 6 7 8 9 colon dot minus
+fi
-printf '#define SMALL_Y %i\n' $(expr \( $(large_0 | wc -l) + 1 \) / 2)
-printf '#define SMALL_X %i\n' $(expr \( $(large_0 | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2)
-printf '#define SMALL_XC %i\n' $(expr \( $(large_colon | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2)
-printf '#define SMALL_XD %i\n' $(expr \( $(large_dot | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2)
-printf '#define SMALL_XM %i\n' $(expr \( $(large_minus | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2)
+if test "$what" = h; then
+ printf '#define LARGE_Y %i\n' $(large_0 | wc -l)
+ printf '#define LARGE_X %i\n' $(large_0 | head -n 1 | tr -d '\n' | wc -c)
+ printf '#define LARGE_XC %i\n' $(large_colon | head -n 1 | tr -d '\n' | wc -c)
+ printf '#define LARGE_XD %i\n' $(large_dot | head -n 1 | tr -d '\n' | wc -c)
+ printf '#define LARGE_XM %i\n' $(large_minus | head -n 1 | tr -d '\n' | wc -c)
+ printf '#define SMALL_Y %i\n' $(expr \( $(large_0 | wc -l) + 1 \) / 2)
+ printf '#define SMALL_X %i\n' $(expr \( $(large_0 | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2)
+ printf '#define SMALL_XC %i\n' $(expr \( $(large_colon | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2)
+ printf '#define SMALL_XD %i\n' $(expr \( $(large_dot | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2)
+ printf '#define SMALL_XM %i\n' $(expr \( $(large_minus | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2)
+fi
-for c in 0 1 2 3 4 5 6 7 8 9 colon dot minus; do
- if test $c = colon; then
- printf '%s\n' '#ifdef INCLUDE_LARGE_COLON'
- elif test $c = dot; then
- printf '%s\n' '#ifdef INCLUDE_LARGE_DOT'
- elif test $c = minus; then
- printf '%s\n' '#ifdef INCLUDE_LARGE_MINUS'
- fi
- printf 'static const char *large_%s[] = {\n' $c
- large_$c | \
- sed -e 's/X/ /g' -e 's/\[/\\033\[7m /g' -e 's/\]/ \\033\[27m/g' | \
- sed -e 's/^/"/' -e 's/$/",/' | \
- sed '$s/,$//'
- printf '};\n'
+for c; do
+ if test "$what" = h; then
+ printf 'extern const char *large_%s[];\n' $c
+ printf 'extern const char *small_%s[];\n' $c
+ else
+ printf 'const char *large_%s[] = {\n' $c
+ large_$c | \
+ sed -e 's/X/ /g' -e 's/\[/\\033\[7m /g' -e 's/\]/ \\033\[27m/g' | \
+ sed -e 's/^/"/' -e 's/$/",/' | \
+ sed '$s/,$//'
+ printf '};\n'
- printf 'static const char *small_%s[] = {\n' $c
- (
- if expr $(large_$c | wc -l) % 2 >/dev/null; then
- printf '%*.s\n' $(expr \( $(large_0 | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2 \* 2) ''
- fi
- if expr $(large_$c | head -n 1 | tr -d '\n' | wc -c) % 2 >/dev/null; then
- large_$c | tr '][' XX | sed 's/$/ /g'
- else
- large_$c | tr '][' XX
- fi
- ) | tr ' \n' ., | sed 's/\([^,]*\),\([^,]*\),/:\1:\2:\n/g' | while read line; do
- high="$(printf '%s\n' "$line" | cut -d : -f 2)"
- low="$(printf '%s\n' "$line" | cut -d : -f 3)"
- while test -n "$high"; do
- block="$(printf '%s\n' "$high" | colrm 3)$(printf '%s\n' "$low" | colrm 3)"
- high="$(printf '%s\n' "$high" | colrm 1 2)"
- low="$(printf '%s\n' "$low" | colrm 1 2)"
- if test "$block" = '....'; then
- printf ' '
- elif test "$block" = '...X'; then
- printf '▗'
- elif test "$block" = '..X.'; then
- printf '▖'
- elif test "$block" = '..XX'; then
- printf '▄'
- elif test "$block" = '.X..'; then
- printf '▝'
- elif test "$block" = '.X.X'; then
- printf '▐'
- elif test "$block" = '.XX.'; then
- printf '▞'
- elif test "$block" = '.XXX'; then
- printf '▟'
- elif test "$block" = 'X...'; then
- printf '▘'
- elif test "$block" = 'X..X'; then
- printf '▚'
- elif test "$block" = 'X.X.'; then
- printf '▌'
- elif test "$block" = 'X.XX'; then
- printf '▙'
- elif test "$block" = 'XX..'; then
- printf '▀'
- elif test "$block" = 'XX.X'; then
- printf '▜'
- elif test "$block" = 'XXX.'; then
- printf '▛'
- elif test "$block" = 'XXXX'; then
- printf '█'
+ printf 'const char *small_%s[] = {\n' $c
+ (
+ if expr $(large_$c | wc -l) % 2 >/dev/null; then
+ printf '%*.s\n' $(expr \( $(large_0 | head -n 1 | tr -d '\n' | wc -c) + 1 \) / 2 \* 2) ''
+ fi
+ if expr $(large_$c | head -n 1 | tr -d '\n' | wc -c) % 2 >/dev/null; then
+ large_$c | tr '][' XX | sed 's/$/ /g'
+ else
+ large_$c | tr '][' XX
fi
- done
- printf '\n'
- done | sed -e 's/^/"/' -e 's/$/",/' | sed '$s/,$//'
- printf '};\n'
- if test $c = colon || test $c = dot || test $c = minus; then
- printf '%s\n' '#endif'
+ ) | tr ' \n' ., | sed 's/\([^,]*\),\([^,]*\),/:\1:\2:\n/g' | while read line; do
+ high="$(printf '%s\n' "$line" | cut -d : -f 2)"
+ low="$(printf '%s\n' "$line" | cut -d : -f 3)"
+ while test -n "$high"; do
+ block="$(printf '%s\n' "$high" | colrm 3)$(printf '%s\n' "$low" | colrm 3)"
+ high="$(printf '%s\n' "$high" | colrm 1 2)"
+ low="$(printf '%s\n' "$low" | colrm 1 2)"
+ if test "$block" = '....'; then
+ printf ' '
+ elif test "$block" = '...X'; then
+ printf '▗'
+ elif test "$block" = '..X.'; then
+ printf '▖'
+ elif test "$block" = '..XX'; then
+ printf '▄'
+ elif test "$block" = '.X..'; then
+ printf '▝'
+ elif test "$block" = '.X.X'; then
+ printf '▐'
+ elif test "$block" = '.XX.'; then
+ printf '▞'
+ elif test "$block" = '.XXX'; then
+ printf '▟'
+ elif test "$block" = 'X...'; then
+ printf '▘'
+ elif test "$block" = 'X..X'; then
+ printf '▚'
+ elif test "$block" = 'X.X.'; then
+ printf '▌'
+ elif test "$block" = 'X.XX'; then
+ printf '▙'
+ elif test "$block" = 'XX..'; then
+ printf '▀'
+ elif test "$block" = 'XX.X'; then
+ printf '▜'
+ elif test "$block" = 'XXX.'; then
+ printf '▛'
+ elif test "$block" = 'XXXX'; then
+ printf '█'
+ fi
+ done
+ printf '\n'
+ done | sed -e 's/^/"/' -e 's/$/",/' | sed '$s/,$//'
+ printf '};\n'
fi
done
diff --git a/timer.c b/timer.c
index 4a6b051..a906e65 100644
--- a/timer.c
+++ b/timer.c
@@ -14,11 +14,6 @@
USAGE("[-2s] [[hours:]minutes:]second[.deciseconds]");
-#define INCLUDE_LARGE_COLON
-#define INCLUDE_LARGE_DOT
-#define INCLUDE_LARGE_MINUS
-#include "large.h"
-
static volatile sig_atomic_t caught_sigterm = 0;
static volatile sig_atomic_t caught_sigwinch = 1;