Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 36 additions & 4 deletions scr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions test/test.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
----------------------------------------------------------------
















----------------------------------------------------------------
2 load
ok














----------------------------------------------------------------
: ok ." Hello, World!" cr ;















----------------------------------------------------------------
















68 changes: 68 additions & 0 deletions test/test.ds
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
--- SCREEN 0 ---------------------------------------------------
















--- SCREEN 1 ---------------------------------------------------
2 load
ok














--- SCREEN 2 ---------------------------------------------------
: ok ." Hello, World!" cr ;















--- SCREEN 3 ---------------------------------------------------
















64 changes: 64 additions & 0 deletions test/test.l
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions test/test.ls
Original file line number Diff line number Diff line change
@@ -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
Loading