|
a |
|
b/src/ylwrap |
|
|
1 |
#! /bin/sh
|
|
|
2 |
|
|
|
3 |
# ylwrap - wrapper for lex/yacc invocations. Local version, the
|
|
|
4 |
# autotools scriptversion=2015-08-06.06; # UTC doesnt work for us
|
|
|
5 |
# because it does not move location.hh position.hh stack.hh into the
|
|
|
6 |
# appropriate directory (which is a bug, but it's simpler to rewrite a
|
|
|
7 |
# simple version for our needs than to fix the original).
|
|
|
8 |
|
|
|
9 |
fatal() {
|
|
|
10 |
echo $* 1>&2
|
|
|
11 |
exit 1
|
|
|
12 |
}
|
|
|
13 |
usage() {
|
|
|
14 |
fatal "Usage: ylwrap query/wasaparse.y"
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
test $# -ge 1 || usage
|
|
|
18 |
|
|
|
19 |
toptmpdir=/tmp/rclylwrap$$
|
|
|
20 |
tmpdir=${toptmpdir}/tmp
|
|
|
21 |
mkdir -p "${tmpdir}"
|
|
|
22 |
|
|
|
23 |
cleanup() {
|
|
|
24 |
rm -rf "${toptmpdir}"/tmp/*
|
|
|
25 |
rmdir "${tmpdir}"
|
|
|
26 |
rmdir "${toptmpdir}"
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
trap cleanup 0 2 15
|
|
|
30 |
|
|
|
31 |
# First arg is the input file
|
|
|
32 |
|
|
|
33 |
input=$1
|
|
|
34 |
inputdir=`dirname $1`
|
|
|
35 |
curdir=`pwd` || exit 1
|
|
|
36 |
absinput="${curdir}/${input}"
|
|
|
37 |
|
|
|
38 |
(cd "${tmpdir}"; bison -d -y $absinput)
|
|
|
39 |
ls $tmpdir
|
|
|
40 |
|
|
|
41 |
for f in location.hh position.hh stack.hh; do
|
|
|
42 |
cmp -s "${tmpdir}"/$f "${inputdir}"/$f || cp -p "${tmpdir}"/$f "${inputdir}"
|
|
|
43 |
done
|
|
|
44 |
|
|
|
45 |
# Fix the include line in y.tab.c (it wants to include y.tab.h, but we already
|
|
|
46 |
# include it as wasaparse.h
|
|
|
47 |
(cd "${tmpdir}"; \
|
|
|
48 |
sed -e 's/#include "y.tab.h"//' < y.tab.c > toto; \
|
|
|
49 |
mv -f toto y.tab.c)
|
|
|
50 |
|
|
|
51 |
cmp -s "${tmpdir}"/y.tab.c "${inputdir}"/wasaparse.cpp || \
|
|
|
52 |
cp -p "${tmpdir}"/y.tab.c "${inputdir}"/wasaparse.cpp
|
|
|
53 |
cmp -s "${tmpdir}"/y.tab.h "${inputdir}"/wasaparse.h || \
|
|
|
54 |
cp -p "${tmpdir}"/y.tab.h "${inputdir}"/wasaparse.h
|