1#!/usr/local/bin/bash
2
3if [[ $# -ne 2 ]]; then
4    echo "usage: ./unicode_groups.sh SRCDIR BLDDIR"
5    exit 1
6fi
7
8srcdir="$1"
9blddir="$2"
10
11for fre in encodings/unicode_{blocks,group_*}_{8,x,u}_encoding_policy_{ignore,substitute,fail}.re; do
12    echo $fre
13    fc=${fre/.re/.c}
14    fe=${fre/.re/}
15    opts="$(head -n 1 $fre | sed -E 's/.*OUTPUT(.*)/\1/')"
16
17    # compile re2c source
18    $blddir/re2c $opts $fre -o$fc --no-version --no-generation-date
19
20    read line < $fc
21    if [[ $line =~ "error: " ]]; then
22        echo "*** re2c error, skipping ***"
23        continue
24    fi
25
26    # compile C source
27    g++ -W -Wall -Wextra \
28        -I $srcdir \
29        -I $blddir \
30        -I $srcdir/src/encoding/utf8 \
31        -I $srcdir/src/encoding/utf16 \
32        $srcdir/src/encoding/utf8/utf8.cc \
33        $srcdir/src/encoding/utf16/utf16.cc \
34        $fc \
35        -o $fe
36
37    # execute (runs silently if OK, otherwize report an error)
38    ./$fe
39
40    rm -f $fe
41done
42
43echo "note: run-time failures for surrogates with '--encoding-policy substitute' are OK"
44echo "note: compile-time failures for surrogates with '--encoding-policy fail' are OK"
45