-
Notifications
You must be signed in to change notification settings - Fork 4
/
build
executable file
·377 lines (320 loc) · 8.34 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/bin/sh
# Copyright 2023 Google LLC
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
cd `dirname $0`
# Don't leak current Werm config into tests and builds
unset WERMPROFPATH
unset WERMSOCKSDIR
unset WERMVARDIR
unset WERMSRCDIR
unset WERMJSPATH
unset WERMFLAGS
perl <<'EOF'
my $fontcnt = 0;
my $fntc;
my @wfns = (
'26:230:128:8:0:third_party/oldschool-pc-fonts/ibm_ega_8x8.wermfont',
'26:230:128:12:0:third_party/oldschool-pc-fonts/hp_100lx_10x11.wermfont',
'26:250:512:14:1:third_party/shinonome/jfdot_7x14.wermfont',
'26:230:128:16:0:third_party/oldschool-pc-fonts/ibm_vga_8x16.wermfont',
'26:230:128:16:0:third_party/oldschool-pc-fonts/ibm_vga_9x16.wermfont',
'26:230:128:20:0:third_party/oldschool-pc-fonts/dos_v_ibm_8x19.wermfont',
'26:230:128:20:0:third_party/oldschool-pc-fonts/cl_stringray_8x19.wermfont',
'26:245:128:20:0:third_party/oldschool-pc-fonts/ibm_xga_ai_12x20.wermfont',
'26:230:128:24:0:third_party/oldschool-pc-fonts/ibm_xga_ai_12x23.wermfont',
'26:230:128:32:0:third_party/oldschool-pc-fonts/dos_v_re_12x30.wermfont',
);
sub procfnt {
my ($bgbrig, $fgbrig, $td, $h, $upw, $srfi) = split ':', $_[0];
my ($w) = $srfi =~ /_([0-9]+)x[0-9]+[.]wermfont$/;
my $gcnt = 0;
my @px;
my $mbit = 1;
my $xof = 0;
my $yof = 0;
for (1..($td * $td)) { push @px, 0; }
# font header, with fields:
# narrow glyph width 1 byte
# glyph height 1 byte
# glyph count 2 bytes
# texture width and height 2 bytes, one number
# background brightness 1 byte
# foreground brightness 1 byte
# glyph list, each glyph with fields:
# codepoint and width 3 bytes
# BIT MEANING
# 23 is_wide
# 0-22 code point
# font image, each pixel 1 byte
#
# Glyphs are arranged predictably in the texture image, so specifying
# the exact position of each is not necessary.
open(my $fontsrc, '<', $srfi) or die "open: $!";
my $bits;
my $isbitline;
my $nextline = sub {
$bits = <$fontsrc>;
chomp $bits;
$isbitline = ($bits =~ /^[o.]+$/);
};
# glyph list data, the glyph metadata, as a list of integral byte values
my @glisd;
$nextline->();
while ($bits) {
$mbit <= 0x80 or die "insufficient space for the glyphs";
!$isbitline or die "unexpected bitline";
my ($cop, $pixwd) = $bits =~ /^([a-f0-9]+) ([0-9]+)$/;
my $wide = ($pixwd == $w * 2) ? 0x80 : 0x00;
$pixwd == $w or
$wide or
die "invalid glyph width: $pixwd, line $ginf";
if ($pixwd + $xof > $td) {
$yof += $h;
$xof = 0;
if ($yof + $h > $td) {
$yof = 0;
$mbit <<= 1;
}
}
$gcnt++;
my $tdatof = $yof * $td + $xof;
$unlin = 0;
for (my $y = 0; ; $y++, $tdatof += $td) {
$nextline->();
$isbitline or last;
$y < $h or die "glyph too tall for this font";
for my $x (0..length($bits)-1) {
if ('o' eq substr($bits, $x, 1) eq 'o') {
$px[$tdatof + $x] |= $mbit;
}
}
}
$cop = hex $cop;
push @glisd, $cop>>16 | $wide;
push @glisd, $cop>>8;
push @glisd, $cop;
$xof += $pixwd;
}
my $bytesthisline=0;
my $bcount = 0;
my $writebyte = sub {
my $b = $_[0] & 0xff;
printf $fntc q[\%03o], $b;
$bcount++;
++$bytesthisline < 19 and return;
$bytesthisline = 0;
print $fntc qq["\n"];
};
print $fntc qq(static char fndat${fontcnt}[] =\n");
$writebyte->($w );
$writebyte->($h );
$writebyte->($gcnt >> 8 );
$writebyte->($gcnt );
$writebyte->($td >> 8 );
$writebyte->($td );
$writebyte->($bgbrig );
$writebyte->($fgbrig );
for my $b (@glisd, @px) {
$writebyte->($b);
}
print $fntc qq[";\n];
printf STDERR "glyph # in $srfi: $gcnt, final mask: 0x%x, size: %u\n",
$mbit, $bcount;
$fontcnt++;
return unless $upw;
my @wls = ( "0#define WERMFONT_CNT " . scalar(@wfns),
"0fn1(charwi, u)",
"0{",
"1u &= 0x7fffffff;",
"1if (u <= 0x7f) return 1;",
"1switch (u) {",
"1default: return 2;",
);
open(my $fs, '<', $srfi) or die "cannot open $srfi: $!";
while (my $fln = <$fs>) {
chomp $fln;
next if $fln !~ /^([^ ]*) ([^ ]*)$/;
my $cop = hex($1);
my $wid = $w==$2 ? 1 : 2;
next if $cop <= 0x7f or $wid == 2;
push @wls, sprintf("1case 0x%05x: return 1;", $cop);
}
$fs = 0;
push @wls, "1}\n",
"0}\n";
open(my $whn, '>', 'charwi') or die "open charwi: $!";
for my $lin (@wls) {
chomp $lin;
my ($in, $st) = $lin =~ /^(.)(.*)$/;
print($whn ("\t" x $in) . $st . "\n");
}
$whn = 0;
}
sub mtime {
my ($f) = @_;
-e $f or return -1;
my @s = stat $f;
return $s[9];
}
my $fntime = 0x7fffffff;
for $f (qw[charwi font.c]) {
my $mt = mtime $f;
$mt < $fntime and $fntime = $mt;
}
my $wftime = -1;
for $w (@wfns) {
my @fs = split(':', $w);
my $f = $fs[5];
my $mt = mtime $f;
$mt > $wftime and $wftime = $mt;
}
if ($wftime > $fntime) {
print STDERR "generating font.c\n";
open($fntc, '>', 'font.c') or die "open font.c: $!";
print $fntc qq[#include "font.h"\n];
print $fntc qq[#include "http.h"\n];
print $fntc qq[#include <stdlib.h>\n];
for $f (@wfns) { procfnt $f }
print $fntc qq[int fontcnt(void) { return $fontcnt; }\n];
print $fntc qq[void servefnt(struct wrides *de, int fi)\n];
print $fntc qq[{\n];
print $fntc qq[\tswitch (fi) {\n];
for my $fi (0..$fontcnt-1) {
print $fntc qq[\tcase $fi:\n];
print $fntc qq[\t\tresp_dynamc(];
print $fntc qq[de, 'f', 200, fndat$fi, sizeof(fndat$fi)-1);\n];
print $fntc qq[\t\treturn;\n];
}
print $fntc qq[\t}\n];
print $fntc qq[\tfprintf(stderr, "invalid font index: %d\\n", fi);\n];
print $fntc qq[\tabort();\n];
print $fntc qq[}\n];
}
EOF
(
cd test/raw || exit 1
echo '#include <unistd.h>' >| data.h
find . -type f \
-not \( -name '*.c' -o -name '*.h' -o -name .gitignore \) |
while read fn
do
fnb=`basename $fn`
printf 'extern char test_%s[];\n' "$fnb" >> data.h
printf 'extern const size_t test_%s_size;\n' "$fnb" >> data.h
printf '#include "test/raw/data.h"\n' >| $fn.c
printf 'const size_t test_%s_size = %d;\n' "$fnb" `wc -c <"$fn"` >> "$fn.c"
printf 'char test_%s[] = ' "$fnb" >> "$fn.c"
touch /tmp/line.$$
while :; do
rm /tmp/line.$$
dd status=none bs=80 count=1 of=/tmp/line.$$
test -s /tmp/line.$$ || break
printf '"' >> "$fn.c"
sed '
s/\\/\\\\/g
s/\x00/\\000/g
s/\x07/\\007/g
s/\x1b/\\033/g
s/\x0d/\\015/g
s/"/\\042/g
s/\x08/\\010/g
$!s/$/\\012/
' /tmp/line.$$ | tr -d '\n' >> "$fn.c"
printf '"\n' >> "$fn.c"
done < "$fn"
printf ';\n' >> "$fn.c"
done
)
if test -z "${CC}"; then
CC=cc
fi
if ! $CC -x c -std=c99 -I. \
-D_POSIX_C_SOURCE=200809L \
-D_XOPEN_SOURCE=600 \
-D_GNU_SOURCE \
-Werror=format \
-Wno-return-type \
-Werror=unused-variable \
-Werror=missing-declarations \
-Wunused-function \
-Werror=pointer-sign \
-Werror=implicit-function-declaration \
-Werror=incompatible-pointer-types \
$WERMCCFLAGS \
-o run \
session.c \
font.c \
http.c \
inbound.c \
outstreams.c \
shared.c \
spawner.c \
uniqid.c \
test/raw/*.c \
third_party/dtach/*.c \
wts.c \
-lutil \
-lmd4c-html \
-lssl \
-lcrypto
then
echo 'Build failed - do you need to install dependencies?' >&2
grep -A4 'following packages are installed' README.md >&2
exit 1
fi
if ! ctags=`which ctags-exuberant`; then
echo '`sudo apt install exuberant-ctags` to make tags file' 2>&1
else
tmfiles='./teng ./third_party/st/tmeng ./third_party/st/tmengui'
find . -path ./var -prune \
-o -type f \( -name \*.h -o \
-name \*.c -o \
-name tmeng -o \
-name tmengui -o \
-name teng \) -print \
>/tmp/tag_files.$$
(
$ctags -h .h. -f - \
--language-force=C \
--format=1 \
`cat /tmp/tag_files.$$` \
| sed '/^fnx*[0-9]\>/d'
for p in $tmfiles; do
sed '
/^fn[0-9](\([^,)]*\).*/bt
/^fnx[0-9]([^,]*, *\([^,]*\).*/bt
d
:t
s,,\1\t'$p',
p; =; d
' $p
done | sed '
s,$,\t'$p',
N
s/\n/\t/
') \
| LC_ALL=C sort \
>| tags
fi
echo 'running tests...' >&2
for tfn in 'run test' testtm; do
WERM_TESTABORTS=1 ./$tfn || echo "TEST '$tfn' TERMINATED WITH ERROR !!!"
done >/tmp/testout.$$ 2>&1
err=
if ! diff -u passing_test_output /tmp/testout.$$
then
echo "build succeeded but tests failed; to update:
cp /tmp/testout.$$ $PWD/passing_test_output"
err=1
fi >&2
# We pipe this into wc first because grep may not recognize a null byte
# as expected.
if </tmp/testout.$$ tr -d '\n -~' | wc -c | grep -q '[^0]'
then
echo 'TEST OUTPUT HAS NON-PRINTABLE OR CONTROL CHAR(S) !!1!' >&2
err=1
fi
test -z "$err"