| 1 |
|
#! /bin/sh |
| 2 |
|
# ylwrap - wrapper for lex/yacc invocations. |
| 3 |
|
|
| 4 |
< |
scriptversion=2012-07-14.08; # UTC |
| 4 |
> |
scriptversion=2013-01-12.17; # UTC |
| 5 |
|
|
| 6 |
< |
# Copyright (C) 1996-2012 Free Software Foundation, Inc. |
| 6 |
> |
# Copyright (C) 1996-2013 Free Software Foundation, Inc. |
| 7 |
|
# |
| 8 |
|
# Written by Tom Tromey <tromey@cygnus.com>. |
| 9 |
|
# |
| 40 |
|
# guard FILE |
| 41 |
|
# ---------- |
| 42 |
|
# The CPP macro used to guard inclusion of FILE. |
| 43 |
< |
guard() |
| 43 |
> |
guard () |
| 44 |
|
{ |
| 45 |
< |
printf '%s\n' "$from" \ |
| 46 |
< |
| sed \ |
| 47 |
< |
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ |
| 48 |
< |
-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' |
| 45 |
> |
printf '%s\n' "$1" \ |
| 46 |
> |
| sed \ |
| 47 |
> |
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ |
| 48 |
> |
-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' \ |
| 49 |
> |
-e 's/__*/_/g' |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
# quote_for_sed [STRING] |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
# The input. |
| 99 |
< |
input="$1" |
| 99 |
> |
input=$1 |
| 100 |
|
shift |
| 101 |
|
# We'll later need for a correct munging of "#line" directives. |
| 102 |
|
input_sub_rx=`get_dirname "$input" | quote_for_sed` |
| 103 |
< |
case "$input" in |
| 103 |
> |
case $input in |
| 104 |
|
[\\/]* | ?:[\\/]*) |
| 105 |
|
# Absolute path; do nothing. |
| 106 |
|
;; |
| 107 |
|
*) |
| 108 |
|
# Relative path. Make it absolute. |
| 109 |
< |
input="`pwd`/$input" |
| 109 |
> |
input=`pwd`/$input |
| 110 |
|
;; |
| 111 |
|
esac |
| 112 |
|
input_rx=`get_dirname "$input" | quote_for_sed` |
| 122 |
|
# The parser itself, the first file, is the destination of the .y.c |
| 123 |
|
# rule in the Makefile. |
| 124 |
|
parser=$1 |
| 125 |
+ |
|
| 126 |
|
# A sed program to s/FROM/TO/g for all the FROM/TO so that, for |
| 127 |
|
# instance, we rename #include "y.tab.h" into #include "parse.h" |
| 128 |
|
# during the conversion from y.tab.c to parse.c. |
| 129 |
< |
rename_sed= |
| 130 |
< |
while test "$#" -ne 0; do |
| 131 |
< |
if test "$1" = "--"; then |
| 129 |
> |
sed_fix_filenames= |
| 130 |
> |
|
| 131 |
> |
# Also rename header guards, as Bison 2.7 for instance uses its header |
| 132 |
> |
# guard in its implementation file. |
| 133 |
> |
sed_fix_header_guards= |
| 134 |
> |
|
| 135 |
> |
while test $# -ne 0; do |
| 136 |
> |
if test x"$1" = x"--"; then |
| 137 |
|
shift |
| 138 |
|
break |
| 139 |
|
fi |
| 148 |
|
shift |
| 149 |
|
to=$1 |
| 150 |
|
shift |
| 151 |
< |
rename_sed="${rename_sed}s|"`quote_for_sed "$from"`"|$to|g;" |
| 151 |
> |
sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;" |
| 152 |
> |
sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;" |
| 153 |
|
done |
| 154 |
|
|
| 155 |
|
# The program to run. |
| 156 |
< |
prog="$1" |
| 156 |
> |
prog=$1 |
| 157 |
|
shift |
| 158 |
|
# Make any relative path in $prog absolute. |
| 159 |
< |
case "$prog" in |
| 159 |
> |
case $prog in |
| 160 |
|
[\\/]* | ?:[\\/]*) ;; |
| 161 |
< |
*[\\/]*) prog="`pwd`/$prog" ;; |
| 161 |
> |
*[\\/]*) prog=`pwd`/$prog ;; |
| 162 |
|
esac |
| 163 |
|
|
| 156 |
– |
# FIXME: add hostname here for parallel makes that run commands on |
| 157 |
– |
# other machines. But that might take us over the 14-char limit. |
| 164 |
|
dirname=ylwrap$$ |
| 165 |
|
do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret' |
| 166 |
|
trap "ret=129; $do_exit" 1 |
| 180 |
|
if test $ret -eq 0; then |
| 181 |
|
for from in * |
| 182 |
|
do |
| 183 |
< |
to=`printf '%s\n' "$from" | sed "$rename_sed"` |
| 183 |
> |
to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"` |
| 184 |
|
if test -f "$from"; then |
| 185 |
|
# If $2 is an absolute path name, then just use that, |
| 186 |
|
# otherwise prepend '../'. |
| 187 |
|
case $to in |
| 188 |
|
[\\/]* | ?:[\\/]*) target=$to;; |
| 189 |
< |
*) target="../$to";; |
| 189 |
> |
*) target=../$to;; |
| 190 |
|
esac |
| 191 |
|
|
| 192 |
|
# Do not overwrite unchanged header files to avoid useless |
| 195 |
|
# output of all other files to a temporary file so we can |
| 196 |
|
# compare them to existing versions. |
| 197 |
|
if test $from != $parser; then |
| 198 |
< |
realtarget="$target" |
| 198 |
> |
realtarget=$target |
| 199 |
|
target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'` |
| 200 |
|
fi |
| 201 |
|
|
| 203 |
|
# debug information point at an absolute srcdir. Use the real |
| 204 |
|
# output file name, not yy.lex.c for instance. Adjust the |
| 205 |
|
# include guards too. |
| 206 |
< |
FROM=`guard "$from"` |
| 207 |
< |
TARGET=`guard "$to"` |
| 208 |
< |
sed -e "/^#/!b" -e "s|$input_rx|$input_sub_rx|" -e "$rename_sed" \ |
| 209 |
< |
-e "s|$FROM|$TARGET|" "$from" >"$target" || ret=$? |
| 206 |
> |
sed -e "/^#/!b" \ |
| 207 |
> |
-e "s|$input_rx|$input_sub_rx|" \ |
| 208 |
> |
-e "$sed_fix_filenames" \ |
| 209 |
> |
-e "$sed_fix_header_guards" \ |
| 210 |
> |
"$from" >"$target" || ret=$? |
| 211 |
|
|
| 212 |
|
# Check whether files must be updated. |
| 213 |
|
if test "$from" != "$parser"; then |