diff --git a/Makefile b/Makefile index d91fe26..a31f82f 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,18 @@ BIN=scr PREFIX?=/usr/local BINDIR=${PREFIX}/bin +CFLAGS+=-g -O2 -std=c11 -D_POSIX_C_SOURCE=200112L -pedantic -Wall -Wno-strict-overflow + .PHONY: build clean install uninstall build: ${BIN} clean: - -rm ${BIN} + -rm -vf ${BIN} install: ${BIN} @mkdir -p ${BINDIR} cp ${BIN} ${BINDIR}/${BIN} uninstall: - rm ${BINDIR}/${BIN} + -rm -vf ${BINDIR}/${BIN} diff --git a/README b/README index c270224..3629a26 100644 --- a/README +++ b/README @@ -31,6 +31,8 @@ screen numbers (respectively) are included. $ scr -ls example.blk example.scr $ +The -d option specifies whether the screen divider (dashed line) is included. + To convert a screen file to a block file: The -r option specifies that the input is in screen format and the output should diff --git a/scr.c b/scr.c index 991de76..0e8b394 100644 --- a/scr.c +++ b/scr.c @@ -8,7 +8,7 @@ extern char *__progname; void usage() { - fprintf(stderr, "usage: %s [-hrnls] [-b base] [infile [outfile]]\n", __progname); + fprintf(stderr, "usage: %s [-hrnlsd] [-b base] [infile [outfile]]\n", __progname); exit(1); } @@ -22,6 +22,8 @@ main(int argc, char *argv[]) { lopt = 0; int sopt; sopt = 0; + int dopt; + dopt = 0; int bopt; bopt = 0; int boptarg; @@ -36,7 +38,7 @@ main(int argc, char *argv[]) { ofp = stdout; char ch; - while ((ch = getopt(argc, argv, "hrnlsb:")) != -1) { + while ((ch = getopt(argc, argv, "hrnlsdb:")) != -1) { switch (ch) { case 'r': if (ropt != 0) @@ -58,6 +60,11 @@ main(int argc, char *argv[]) { usage(); sopt = 1; break; + case 'd': + if (dopt != 0) + usage(); + dopt = 1; + break; case 'b': if (bopt != 0) usage(); @@ -171,8 +178,33 @@ main(int argc, char *argv[]) { exit(2); } if (!q || d) { - if (sopt) - fprintf(ofp, " SCREEN %d\n", sn++); + if (sopt || dopt) { + if (lopt || (sopt && !dopt)) + for (i = 0; i < 3; i++) + fputc(' ', ofp); + int n; + n = 0; + if (dopt) { + for (i = 0; i < 3; i++) + fputc('-', ofp); + n += 3; + } + if (sopt) { + if (dopt) { + fputc(' ', ofp); + n++; + } + n += fprintf(ofp, "SCREEN %d", sn++); + if (dopt) { + fputc(' ', ofp); + n++; + } + } + if (dopt) + for (i = n; i < 64; i++) + fputc('-', ofp); + fputc('\n', ofp); + } for (i = 0; i < 16; i++) { fputs(s[i], ofp); fputc('\n', ofp); diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..32ca698 --- /dev/null +++ b/test.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +test() { + ./scr -rsl example.scr | ./scr -"$1" | cmp - test/test."$1" +} + +test l +test s +test d +test ls +test ds +test lsd diff --git a/test/test.d b/test/test.d new file mode 100644 index 0000000..e8931fb --- /dev/null +++ b/test/test.d @@ -0,0 +1,68 @@ +---------------------------------------------------------------- + + + + + + + + + + + + + + + + +---------------------------------------------------------------- +2 load +ok + + + + + + + + + + + + + + +---------------------------------------------------------------- +: ok ." Hello, World!" cr ; + + + + + + + + + + + + + + + +---------------------------------------------------------------- + + + + + + + + + + + + + + + + diff --git a/test/test.ds b/test/test.ds new file mode 100644 index 0000000..e94fe0f --- /dev/null +++ b/test/test.ds @@ -0,0 +1,68 @@ +--- SCREEN 0 --------------------------------------------------- + + + + + + + + + + + + + + + + +--- SCREEN 1 --------------------------------------------------- +2 load +ok + + + + + + + + + + + + + + +--- SCREEN 2 --------------------------------------------------- +: ok ." Hello, World!" cr ; + + + + + + + + + + + + + + + +--- SCREEN 3 --------------------------------------------------- + + + + + + + + + + + + + + + + diff --git a/test/test.l b/test/test.l new file mode 100644 index 0000000..018f062 --- /dev/null +++ b/test/test.l @@ -0,0 +1,64 @@ + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + 0 2 load + 1 ok + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + 0 : ok ." Hello, World!" cr ; + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 diff --git a/test/test.ls b/test/test.ls new file mode 100644 index 0000000..a37de59 --- /dev/null +++ b/test/test.ls @@ -0,0 +1,68 @@ + SCREEN 0 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + SCREEN 1 + 0 2 load + 1 ok + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + SCREEN 2 + 0 : ok ." Hello, World!" cr ; + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + SCREEN 3 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 diff --git a/test/test.lsd b/test/test.lsd new file mode 100644 index 0000000..9691fd1 --- /dev/null +++ b/test/test.lsd @@ -0,0 +1,68 @@ + --- SCREEN 0 --------------------------------------------------- + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + --- SCREEN 1 --------------------------------------------------- + 0 2 load + 1 ok + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + --- SCREEN 2 --------------------------------------------------- + 0 : ok ." Hello, World!" cr ; + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 + --- SCREEN 3 --------------------------------------------------- + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 diff --git a/test/test.s b/test/test.s new file mode 100644 index 0000000..663ca64 --- /dev/null +++ b/test/test.s @@ -0,0 +1,68 @@ + SCREEN 0 + + + + + + + + + + + + + + + + + SCREEN 1 +2 load +ok + + + + + + + + + + + + + + + SCREEN 2 +: ok ." Hello, World!" cr ; + + + + + + + + + + + + + + + + SCREEN 3 + + + + + + + + + + + + + + + +