From cfda11fb768888fb2802e265ed8d5438cef2f123 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 14 Jul 2012 10:08:52 +0200 Subject: [PATCH] ylwrap: refactoring: don't rely on the file order Forthcoming changes will make us iterate over the files in a different order. lib/ylwrap (first): Remove, replaced by... (parser): this. --- lib/ylwrap | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/ylwrap b/lib/ylwrap index 725b388..d245ba0 100755 --- a/lib/ylwrap +++ b/lib/ylwrap @@ -117,6 +117,9 @@ if test -f y_tab.c || test -f y_tab.h; then y_tab_nodot=true fi +# The parser itself, the first file, is the destination of the .y.c +# rule in the Makefile. +parser=$1 # The list of file to rename: FROM TO... pairlist= # A sed program to s/FROM/TO/g for all the FROM/TO so that, for @@ -173,7 +176,6 @@ ret=$? if test $ret -eq 0; then set X $pairlist shift - first=yes input_rx=`get_dirname "$input" | quote_for_sed` @@ -189,11 +191,11 @@ if test $ret -eq 0; then esac # Do not overwrite unchanged header files to avoid useless - # recompilations. Always update the parser itself (the first - # file): it is the destination of the .y.c rule in the Makefile. - # Divert the output of all other files to a temporary file so we - # can compare them to existing versions. - if test $first = no; then + # recompilations. Always update the parser itself: it is the + # destination of the .y.c rule in the Makefile. Divert the + # output of all other files to a temporary file so we can + # compare them to existing versions. + if test $from != $parser; then realtarget="$target" target=tmp-`printf '%s\n' "$target" | sed s/.*[\\/]//g` fi @@ -207,8 +209,8 @@ if test $ret -eq 0; then sed -e "/^#/!b" -e "s|$input_rx|$input_sub_rx|" -e "$rename_sed" \ -e "s|$FROM|$TARGET|" "$from" >"$target" || ret=$? - # Check whether header files must be updated. - if test $first = no; then + # Check whether files must be updated. + if test "$from" != "$parser"; then if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then echo "$to is unchanged" rm -f "$target" @@ -218,17 +220,15 @@ if test $ret -eq 0; then fi fi else - # A missing file is only an error for the first file. This - # is a blatant hack to let us support using "yacc -d". If -d - # is not specified, we don't want an error when the header - # file is "missing". - if test $first = yes; then + # A missing file is only an error for the parser. This is a + # blatant hack to let us support using "yacc -d". If -d is not + # specified, don't fail when the header file is "missing". + if test "$from" = "$parser"; then ret=1 fi fi shift shift - first=no done else ret=$? -- 2.7.4