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
|
#!/usr/bin/env sh
# Every writer, in both languages, over every document, into $OUT/write/.
#
# write/text/{d,g}/<doc>.txt
# write/md/{d,g}/<doc>.md
# write/html/{d,g}/<doc>.html
# write/epub/{d,g}/<doc>.epub
# write/typst/{d,g}/<doc>/<doc>.typ and image/ beside it
#
# Each writer is given the .ocda.db, because that carries the images. The .ssp
# is used as well, for the one comparison that matters at this level: a writer
# is not told which serialisation it was handed, so the two must agree.
#
# The summary counts, for each format, how many documents the two languages'
# writers agreed on byte for byte. That is the check that says the model is
# sufficient: neither writer was written from the other.
set -e
. "$(dirname "$0")/config.sh"
: "${ARTEFACTS:?set ARTEFACTS to a directory of .ssp and .ocda.db files}"
list=$(find "$ARTEFACTS" -name '*.ssp' | sort)
[ -n "$LIMIT" ] && list=$(echo "$list" | head -n "$LIMIT")
for fmt in text md html epub typst; do
for impl in d g; do mkdir -p "$OUT/write/$fmt/$impl"; done
done
n=0
agree_text=0; agree_md=0; agree_html=0; agree_epub=0; agree_typst=0
forms=0
for ssp in $list; do
stem=$(basename "$ssp" .ssp); lang=${stem##*.}; uid=${stem%.*}
db=$(find "$ARTEFACTS" -name "$uid.ocda.db" | head -1)
src=${db:-$ssp}
[ -n "$db" ] && args="$src $lang" || args="$src"
n=$((n+1))
one() { sh "$(dirname "$0")/one.sh" "$@"; }
one text-d $args > "$OUT/write/text/d/$stem.txt"
one text-g $args > "$OUT/write/text/g/$stem.txt"
cmp -s "$OUT/write/text/d/$stem.txt" "$OUT/write/text/g/$stem.txt" \
&& agree_text=$((agree_text+1)) || echo "TEXT DIFFERS $stem"
one md-d $args > "$OUT/write/md/d/$stem.md"
one md-g $args > "$OUT/write/md/g/$stem.md"
cmp -s "$OUT/write/md/d/$stem.md" "$OUT/write/md/g/$stem.md" \
&& agree_md=$((agree_md+1)) || echo "MD DIFFERS $stem"
one html-d $args > "$OUT/write/html/d/$stem.html"
one html-g $args > "$OUT/write/html/g/$stem.html"
cmp -s "$OUT/write/html/d/$stem.html" "$OUT/write/html/g/$stem.html" \
&& agree_html=$((agree_html+1)) || echo "HTML DIFFERS $stem"
"$WRITERS/dlang/result/bin/ocda-write" --epub $args \
--out "$OUT/write/epub/d/$stem.epub"
"$WRITERS/gleam/result/bin/ocda-write" --epub $args \
--out "$OUT/write/epub/g/$stem.epub"
cmp -s "$OUT/write/epub/d/$stem.epub" "$OUT/write/epub/g/$stem.epub" \
&& agree_epub=$((agree_epub+1)) || echo "EPUB DIFFERS $stem"
# a .typ names its images by path, so it and they go in a directory together
for impl in d g; do mkdir -p "$OUT/write/typst/$impl/$stem"; done
"$WRITERS/dlang/result/bin/ocda-write" --typst $args \
--out "$OUT/write/typst/d/$stem/$stem.typ"
"$WRITERS/gleam/result/bin/ocda-write" --typst $args \
--out "$OUT/write/typst/g/$stem/$stem.typ"
cmp -s "$OUT/write/typst/d/$stem/$stem.typ" \
"$OUT/write/typst/g/$stem/$stem.typ" \
&& agree_typst=$((agree_typst+1)) || echo "TYPST DIFFERS $stem"
# and the claim that a writer cannot tell the serialisations apart. A .typ
# names its images rather than carrying them, so this one holds for it even
# though only the .ocda.db has the image files.
if [ -n "$db" ]; then
"$WRITERS/dlang/result/bin/ocda-write" --typst "$ssp" > "$OUT/from-ssp.typ"
if cmp -s "$OUT/from-ssp.typ" "$OUT/write/typst/d/$stem/$stem.typ"
then forms=$((forms+1))
else echo "FORMS DIFFER $stem"
fi
fi
done
echo
echo "documents written: $n"
echo "D == Gleam, text $agree_text"
echo "D == Gleam, markdown $agree_md"
echo "D == Gleam, html $agree_html"
echo "D == Gleam, epub $agree_epub"
echo "D == Gleam, typst $agree_typst"
echo ".ssp and .ocda.db give the same .typ $forms"
|