buildrng: Remove GNU sed check, because I don't know why
[projectmallard:projectmallard.git] / buildrng
1 #!/bin/sh
2
3 SPECS=`ls -d *.*/index.page */*.*/index.page | sed -e 's/\/index\.page$//'`
4
5 while [ "$#" != "0" ]; do
6     if [ "x$1" = "x-o" ]; then
7         rng_outbase="$2"
8         shift
9     elif [ "x$1" = "x-v" ]; then
10         rng_verbose=1
11     fi
12     shift
13 done
14 if [ "x$rng_outbase" = "x" ]; then
15     rng_outbase=`pwd`
16 else
17     rng_outbase=`(cd "$rng_outbase" && pwd)`
18 fi
19
20 echo_verbose() {
21     if [ "x$rng_verbose" = "x1" ]; then
22         echo "$1"
23     fi
24 }
25
26 for spec in $SPECS; do
27 rng_outdir="$rng_outbase/$spec"
28 if echo "$spec" | grep -q "/"; then
29     rng_base=`echo "$spec" | cut -f1 -d/`
30     rng_version=`echo "$spec" | cut -f2 -d/`
31 else
32     rng_base="mallard"
33     rng_version="$spec"
34 fi
35 mkdir -p "$rng_outdir"
36 rng_rncfile="$rng_outdir/${rng_base}-${rng_version}.rnc"
37 rng_rngfile="$rng_outdir/${rng_base}-${rng_version}.rng"
38 rng_tmpfile="$rng_outdir/${rng_base}-${rng_version}.rng.tmp"
39
40 echo_verbose "Creating $rng_rncfile"
41 for page in $(./linear.sh "$spec"); do
42     xsltproc --xinclude mal2rnc.xsl "${spec}/${page}.page"
43 done > "$rng_rncfile"
44
45 echo_verbose "Creating $rng_rngfile"
46 LANG= awk -f rnc2rng.awk "$rng_rncfile" > "$rng_tmpfile" || (rm -f "$rng_tmpfile" && exit 1)
47 xmllint --format "$rng_tmpfile" | \
48     sed -e 's/^  //' \
49         -e 's/^\(<start.*>\)/\n\1/' \
50         -e 's/^\(<define.*>\)/\n\1/' \
51         -e 's/^\(<!--\)/\n\1/' \
52         -e 's/^<\/grammar>/\n<\/grammar>/' \
53         -e 's/ xmlns/\n    xmlns/g' \
54         -e 's/" ns=/"\n    ns=/' \
55     > "$rng_rngfile" || (rm -f "$rng_tmpfile" && exit 1) && rm -f "$rng_tmpfile"
56 done