* lib/ylwrap (tr_cpp): New subroutine, turning the given string into a suitable C preprocessor symbol. Use it to reduce code duplication. Add comments about when postprocessing of C preprocessor symbols in yacc-generated header files is relevant. --- ChangeLog | 9 +++++++++ lib/ylwrap | 23 ++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog index e2c2c81..d5fa8f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2011-05-05 Stefano Lattarini <stefano.lattar...@gmail.com> + ylwrap: new subroutine `tr_cpp' + * lib/ylwrap (tr_cpp): New subroutine, turning the given string + into a suitable C preprocessor symbol. + Use it to reduce code duplication. + Add comments about when postprocessing of C preprocessor symbols + in yacc-generated header files is relevant. + +2011-05-05 Stefano Lattarini <stefano.lattar...@gmail.com> + ylwrap: fixlets in option parsing * lib/ylwrap: Do not recognize anymore the unused `--basedir' option. Be stricter in matching the `--help' and `--version' diff --git a/lib/ylwrap b/lib/ylwrap index 8ff3308..52b6900 100755 --- a/lib/ylwrap +++ b/lib/ylwrap @@ -1,7 +1,7 @@ #! /bin/sh # ylwrap - wrapper for lex/yacc invocations. -scriptversion=2011-05-05.10; # UTC +scriptversion=2011-05-05.12; # UTC # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, # 2007, 2009, 2010, 2011 Free Software Foundation, Inc. @@ -51,6 +51,14 @@ dirname_ () || printf '%s\n' "$1" | sed -e 's,\([\\/]\)[^\\/]*$,\1,' } +# Turn the given string into a suitable C preprocessor symbol. +tr_cpp () +{ + printf '%s\n' "$1" \ + | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ + -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' +} + # Since DOS filename conventions don't allow two dots, the DOS version # of Bison writes out y_tab.c instead of y.tab.c and y_tab.h instead # of y.tab.h. Test to see if this is the case. @@ -235,12 +243,13 @@ if test $ret -eq 0; then # instance. # # We want the include guards to be adjusted too. - FROM=`echo "$from" | sed \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ - -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` - TARGET=`echo "$2" | sed \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ - -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` + # TODO: This include guards seems not to be generated anymore + # by newer bison versions (at least starting from 1.875; they + # were still generated in version 1.75, though). Also, BSD and + # Solaris yacc seems not to generate such include guards either. + # So, how much is this code still relevant today? + FROM=`tr_cpp "$from"` + TARGET=`tr_cpp "$2"` sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \ -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$? -- 1.7.2.3