forked from LibreDWG/libredwg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json-check
executable file
·80 lines (74 loc) · 2.36 KB
/
json-check
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
#!/bin/bash
# dwg -> json
# json -> dwg2
# teigha dwg2 -> dxf just to confirm written DWG readability
d="${1:-example_2000}"
b="$(basename "$d" .dwg)"
dir="$(dirname "$d")"
r="$(basename "$dir")"
case $dir in
*test/test-data) ;;
*test/test-data/*) b="${b}_${r}" ;;
*td) ;;
*td/*) b="${b}_${r}" ;;
.) ;;
*) b="${b}_${r}" ;;
esac
case $r in
20*) ;;
r9) r=9 ;;
r1[0234]) r=${r:1} ;;
*) case $b in
*_20*) r="${b:(-4)}" ;;
*_r9) r=9; ;;
*_r1[0234]) r="${b:(-2)}" ;;
esac ;;
esac
# first create a dwg log to compare against
./log -v3 "$d"
mv "$b.log" "$b.log.orig"
rm "./$b.json" "./$b.dwg" 2>/dev/null
./json -v4 "$d"
if [ -f "$b.json" ]; then
./dwg -y -v4 "$b.json"
fi
if [ -f "$b.dwg" ]; then
case $(uname) in
Darwin) TeighaFileConverter=/Applications/TeighaFileConverter.app/Contents/MacOS/TeighaFileConverter ;;
Linux) TeighaFileConverter=/usr/bin/TeighaFileConverter ;;
Windows) TeighaFileConverter=TeighaFileConverter ;;
esac
if [ -x "$TeighaFileConverter" ]; then
cp "./$b.dwg" test/
echo TeighaFileConverter "test" "." "ACAD$r" DXF 0 1 "$b.dwg"
$TeighaFileConverter "test" "." "ACAD$r" DXF 0 1 "$b.dwg"
mv "./$b.dxf.err" "$b.json.err"
else
rm "$b.json.err" 2>/dev/null
echo TeighaFileConverter not installed
fi
./log -v3 "$b.dwg"
log1="$b.log.orig"
log2="$b.log"
echo diff -bu "log1" "$log2"
diff -bu "$log1" "$log2"
test -f "$b.json.err" && cat "$b.json.err"
if [ -f "$log1" ] && [ -f "$log2" ]; then
grep -E '^Add entity' "$log1" >"$log1.tmp"
grep -E '^Add entity' "$log2" >"$log2.tmp"
if diff -bu0 "$log1.tmp" "$log2.tmp" >/dev/null 2>/dev/null; then
echo entities roundtrip ok
rm "$log1.tmp" "$log2.tmp" 2>/dev/null
else
diff -bu0 "$log1.tmp" "$log2.tmp" | grep -v '^@@'
fi
grep -E '^Add object' "$log1" >"$log1.tmp"
grep -E '^Add object' "$log2" >"$log2.tmp"
if diff -bu0 "$log1.tmp" "$log2.tmp" >/dev/null 2>/dev/null; then
echo objects roundtrip ok
rm "$log1.tmp" "$log2.tmp" 2>/dev/null
else
diff -bu0 "$log1.tmp" "$log2.tmp" | grep -v '^@@'
fi
fi
fi