[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] ylwrap: various fixes
From: |
Akim Demaille |
Subject: |
[PATCH 2/2] ylwrap: various fixes |
Date: |
Wed, 19 Dec 2012 14:55:10 +0100 |
* lib/ylwrap (guard): Properly honor $1.
Keep a single _ instead of several.
(RENAME_sed): new.
Use it.
---
NEWS | 18 ++++++++++++++++++
lib/ylwrap | 27 ++++++++++++++++++---------
2 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/NEWS b/NEWS
index 7a230ef..482216c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,21 @@
+New in 1.12.7:
+
+Bugs fixed in 1.12.7:
+
+ - ylwrap renames properly header guards in generated header files,
+ instead of leaving Y_TAB_H.
+
+ - ylwrap now also converts header guards in implementation files.
+ Because ylwrap failed to rename properly #include in the
+ implementation files, current versions of Bison (e.g., 2.7)
+ duplicate the generated header file in the implementation file.
+ The header guard then protects the implementation file from
+ duplicate definitions from the header file.
+
+ - ylwrap generates header guards with a single '_' for series of non
+ alphabetic characters, instead of several. This is what Bison
+ does.
+
New in 1.12.6:
* WARNING: Future backward-incompatibilities!
diff --git a/lib/ylwrap b/lib/ylwrap
index 7befa46..514018d 100755
--- a/lib/ylwrap
+++ b/lib/ylwrap
@@ -1,7 +1,7 @@
#! /bin/sh
# ylwrap - wrapper for lex/yacc invocations.
-scriptversion=2012-07-14.08; # UTC
+scriptversion=2012-12-19.13; # UTC
# Copyright (C) 1996-2012 Free Software Foundation, Inc.
#
@@ -42,10 +42,11 @@ get_dirname ()
# The CPP macro used to guard inclusion of FILE.
guard()
{
- printf '%s\n' "$from" \
- | sed \
- -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
- -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'
+ printf '%s\n' "$1" \
+ | sed \
+ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
+ -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' \
+ -e 's/__*/_/g'
}
# quote_for_sed [STRING]
@@ -121,10 +122,16 @@ fi
# The parser itself, the first file, is the destination of the .y.c
# rule in the Makefile.
parser=$1
+
# A sed program to s/FROM/TO/g for all the FROM/TO so that, for
# instance, we rename #include "y.tab.h" into #include "parse.h"
# during the conversion from y.tab.c to parse.c.
rename_sed=
+
+# Also rename header guards, as Bison 2.7 for instance uses its header
+# guard in its implementation file.
+RENAME_sed=
+
while test "$#" -ne 0; do
if test "$1" = "--"; then
shift
@@ -142,6 +149,7 @@ while test "$#" -ne 0; do
to=$1
shift
rename_sed="${rename_sed}s|"`quote_for_sed "$from"`"|$to|g;"
+ RENAME_sed="${RENAME_sed}s|"`guard "$from"`"|"`guard "$to"`"|g;"
done
# The program to run.
@@ -197,10 +205,11 @@ if test $ret -eq 0; then
# debug information point at an absolute srcdir. Use the real
# output file name, not yy.lex.c for instance. Adjust the
# include guards too.
- FROM=`guard "$from"`
- TARGET=`guard "$to"`
- sed -e "/^#/!b" -e "s|$input_rx|$input_sub_rx|" -e "$rename_sed" \
- -e "s|$FROM|$TARGET|" "$from" >"$target" || ret=$?
+ sed -e "/^#/!b" \
+ -e "s|$input_rx|$input_sub_rx|" \
+ -e "$rename_sed" \
+ -e "$RENAME_sed" \
+ "$from" >"$target" || ret=$?
# Check whether files must be updated.
if test "$from" != "$parser"; then
--
1.8.0.2
[PATCH 1/2] tests: strengthen the ylwrap tests, Akim Demaille, 2012/12/21