Skip to content

Commit 9a49e18

Browse files
committed
Convert SUDS plot files to SVG.
1 parent d35679d commit 9a49e18

File tree

5 files changed

+223
-1
lines changed

5 files changed

+223
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mini-dumper
2929
od10
3030
old-cpio
3131
palx
32+
plt
3233
scrmbl
3334
tape-dir
3435
tendmp

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ UTILS = cat36 itsarc magdmp magfrm dskdmp dump \
1515
macdmp macro-tapes tape-dir harscntopbm palx cross \
1616
ipak kldcp klfedr scrmbl unscr tvpic tito dart od10 \
1717
constantinople dumper mini-dumper linum tendmp acct \
18-
old-cpio classify-tape
18+
old-cpio classify-tape plt
1919

2020
all: dis10 $(UTILS) check
2121

@@ -81,6 +81,9 @@ acct: acct.o dec.o $(OBJS) $(LIBWORD)
8181
tito: tito.o $(OBJS) $(LIBWORD)
8282
$(CC) $(CFLAGS) $^ -o $@
8383

84+
plt: plt.o svg.o $(OBJS) libwords.a
85+
$(CC) $(CFLAGS) $^ -o $@
86+
8487
dart: dart.o dec.o $(OBJS) $(LIBWORD)
8588
$(CC) $(CFLAGS) $^ -o $@
8689

plt.c

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/* Copyright (C) 2024 Lars Brinkhoff <lars@nocrew.org>
2+
3+
This program is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation, either version 2 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
15+
16+
#include <stdio.h>
17+
#include <unistd.h>
18+
#include "dis.h"
19+
#include "svg.h"
20+
21+
static void finish(word_t data, void (*fn)(FILE *))
22+
{
23+
if (data != -1)
24+
return;
25+
if (fn != NULL)
26+
fn(stdout);
27+
exit(0);
28+
}
29+
30+
static int sext(int data)
31+
{
32+
data &= 0377777;
33+
data ^= 0200000;
34+
return data - 0200000;
35+
}
36+
37+
static int posx(word_t data)
38+
{
39+
return sext(data >> 19);
40+
}
41+
42+
static int posy(word_t data)
43+
{
44+
return sext(data >> 1);
45+
}
46+
47+
static void (*plot)(FILE *f, int x, int y);
48+
49+
static void vector(word_t data)
50+
{
51+
int x = posx(data);
52+
int y = posy(data);
53+
plot(stdout, x, y);
54+
}
55+
56+
static word_t vectors(FILE *f, word_t data)
57+
{
58+
plot = svg_polyline_begin;
59+
do {
60+
vector(data);
61+
plot = svg_polyline_point;
62+
data = get_word(f);
63+
finish(data, svg_polyline_end);
64+
} while (data & 1);
65+
svg_polyline_end(stdout);
66+
return data;
67+
}
68+
69+
static void ascii(word_t data)
70+
{
71+
int c1, c2, c3, c4, c5;
72+
c1 = (data >> 29) & 0177;
73+
c2 = (data >> 22) & 0177;
74+
c3 = (data >> 15) & 0177;
75+
c4 = (data >> 8) & 0177;
76+
c5 = (data >> 1) & 0177;
77+
if (c1)
78+
svg_text_character(stdout, c1);
79+
if (c2)
80+
svg_text_character(stdout, c2);
81+
if (c3)
82+
svg_text_character(stdout, c3);
83+
if (c4)
84+
svg_text_character(stdout, c4);
85+
if (c5)
86+
svg_text_character(stdout, c5);
87+
}
88+
89+
static word_t text(FILE *f, word_t data)
90+
{
91+
int x = posx(data);
92+
int y = posy(data);
93+
94+
if ((data & 0777777000000LL) == 0400001000000LL)
95+
finish(-1, NULL);
96+
97+
svg_text_begin(stdout, x, y);
98+
99+
data = get_word(f);
100+
finish(data, svg_text_end);
101+
if ((data & 1) == 0) {
102+
svg_text_end(stdout);
103+
return data;
104+
}
105+
106+
if (data & 0777777000000LL) {
107+
printf("Not text\n");
108+
exit(1);
109+
}
110+
111+
for(;;) {
112+
data = get_word(f);
113+
finish(data, svg_text_end);
114+
if (data & 1)
115+
ascii(data);
116+
else {
117+
svg_text_end(stdout);
118+
return data;
119+
}
120+
}
121+
}
122+
123+
static void plt(FILE *f)
124+
{
125+
word_t data;
126+
127+
data = get_word(f);
128+
finish(data, NULL);
129+
130+
for (;;) {
131+
switch (data & 01000001) {
132+
case 00000000:
133+
data = vectors(f, data);
134+
break;
135+
case 01000000:
136+
data = text(f, data);
137+
break;
138+
default:
139+
fprintf(stderr, "Error in input: %012llo\n", data);
140+
exit(1);
141+
}
142+
}
143+
}
144+
145+
int main(void)
146+
{
147+
svg_file_begin(stdout);
148+
plt(stdin);
149+
return 0;
150+
}

svg.c

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <stdio.h>
2+
#include "svg.h"
3+
4+
void svg_file_begin(FILE *f)
5+
{
6+
fprintf(f, "<svg viewBox=\"%d %d %d %d\" ",
7+
-600, -600, 1200, 1200);
8+
fprintf(f, "xmlns=\"http://www.w3.org/2000/svg\">\n");
9+
}
10+
11+
void svg_file_end(FILE *f)
12+
{
13+
fprintf(f, "</svg>\n");
14+
}
15+
16+
void svg_polyline_begin(FILE *f, int x, int y)
17+
{
18+
fprintf(f, " <polyline points=\"%d,%d", x, y);
19+
}
20+
21+
void svg_polyline_point(FILE *f, int x, int y)
22+
{
23+
fprintf(f, " %d,%d", x, y);
24+
}
25+
26+
void svg_polyline_end(FILE *f)
27+
{
28+
fprintf(f, "\" fill=\"none\" stroke=\"black\" />\n");
29+
}
30+
31+
void svg_text_begin(FILE *f, int x, int y)
32+
{
33+
fprintf(f, " <text x=\"%d\" y=\"%d\">", x, y);
34+
}
35+
36+
void svg_text_character(FILE *f, int c)
37+
{
38+
switch(c) {
39+
case '<':
40+
fprintf(f, "&lt;");
41+
break;
42+
case '>':
43+
fprintf(f, "&gt;");
44+
break;
45+
case '&':
46+
fprintf(f, "&amp;");
47+
break;
48+
default:
49+
if (c <= 31)
50+
fprintf(f, "[^%c]", c + '@');
51+
else
52+
fprintf(f, "%c", c);
53+
break;
54+
}
55+
}
56+
57+
void svg_text_end(FILE *f)
58+
{
59+
fprintf(f, "</text>\n");
60+
}

svg.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
void svg_file_begin(FILE *f);
2+
void svg_file_end(FILE *f);
3+
void svg_polyline_begin(FILE *f, int x, int y);
4+
void svg_polyline_point(FILE *f, int x, int y);
5+
void svg_polyline_end(FILE *f);
6+
void svg_text_begin(FILE *f, int x, int y);
7+
void svg_text_character(FILE *f, int c);
8+
void svg_text_end(FILE *f);

0 commit comments

Comments
 (0)