123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #! /bin/sh
- scriptversion=2016-01-11.22;
- get_dirname ()
- {
- case $1 in
- */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';;
-
- esac
- }
- guard ()
- {
- printf '%s\n' "$1" \
- | sed \
- -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
- -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' \
- -e 's/__*/_/g'
- }
- quote_for_sed ()
- {
- case $# in
- 0) cat;;
- 1) printf '%s\n' "$1";;
- esac \
- | sed -e 's|[][\\.*]|\\&|g'
- }
- case "$1" in
- '')
- echo "$0: No files given. Try '$0 --help' for more information." 1>&2
- exit 1
- ;;
- --basedir)
- basedir=$2
- shift 2
- ;;
- -h|--h*)
- cat <<\EOF
- Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
- Wrapper for lex/yacc invocations, renaming files as desired.
- INPUT is the input file
- OUTPUT is one file PROG generates
- DESIRED is the file we actually want instead of OUTPUT
- PROGRAM is program to run
- ARGS are passed to PROG
- Any number of OUTPUT,DESIRED pairs may be used.
- Report bugs to <bug-automake@gnu.org>.
- EOF
- exit $?
- ;;
- -v|--v*)
- echo "ylwrap $scriptversion"
- exit $?
- ;;
- esac
- input=$1
- shift
- input_sub_rx=`get_dirname "$input" | quote_for_sed`
- case $input in
- [\\/]* | ?:[\\/]*)
-
- ;;
- *)
-
- input=`pwd`/$input
- ;;
- esac
- input_rx=`get_dirname "$input" | quote_for_sed`
- y_tab_nodot=false
- if test -f y_tab.c || test -f y_tab.h; then
- y_tab_nodot=true
- fi
- parser=$1
- sed_fix_filenames=
- sed_fix_header_guards=
- while test $# -ne 0; do
- if test x"$1" = x"--"; then
- shift
- break
- fi
- from=$1
-
- if $y_tab_nodot; then
- case $from in
- "y.tab.c") from=y_tab.c;;
- "y.tab.h") from=y_tab.h;;
- esac
- fi
- shift
- to=$1
- shift
- sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;"
- sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;"
- done
- prog=$1
- shift
- case $prog in
- [\\/]* | ?:[\\/]*) ;;
- *[\\/]*) prog=`pwd`/$prog ;;
- esac
- dirname=ylwrap$$
- do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
- trap "ret=129; $do_exit" 1
- trap "ret=130; $do_exit" 2
- trap "ret=141; $do_exit" 13
- trap "ret=143; $do_exit" 15
- mkdir $dirname || exit 1
- cd $dirname
- case $# in
- 0) "$prog" "$input" ;;
- *) "$prog" "$@" "$input" ;;
- esac
- ret=$?
- if test $ret -eq 0; then
- for from in *
- do
- to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
- if test -f "$from"; then
-
-
- case $to in
- [\\/]* | ?:[\\/]*) target=$to;;
- *) target=../$to;;
- esac
-
-
-
-
-
- if test $from != $parser; then
- realtarget=$target
- target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
- fi
-
-
-
-
- sed -e "/^#/!b" \
- -e "s|$input_rx|$input_sub_rx|" \
- -e "$sed_fix_filenames" \
- -e "$sed_fix_header_guards" \
- "$from" >"$target" || ret=$?
-
- if test "$from" != "$parser"; then
- if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
- echo "$to is unchanged"
- rm -f "$target"
- else
- echo "updating $to"
- mv -f "$target" "$realtarget"
- fi
- fi
- else
-
-
-
- if test "$from" = "$parser"; then
- ret=1
- fi
- fi
- done
- fi
- cd ..
- rm -rf $dirname
- exit $ret
|