Blame build-aux/ylwrap

Packit Service 9285f1
#! /bin/sh
Packit Service 9285f1
# ylwrap - wrapper for lex/yacc invocations.
Packit Service 9285f1
Packit Service 9285f1
scriptversion=2013-01-12.17; # UTC
Packit Service 9285f1
Packit Service 9285f1
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
Packit Service 9285f1
#
Packit Service 9285f1
# Written by Tom Tromey <tromey@cygnus.com>.
Packit Service 9285f1
#
Packit Service 9285f1
# This program is free software; you can redistribute it and/or modify
Packit Service 9285f1
# it under the terms of the GNU General Public License as published by
Packit Service 9285f1
# the Free Software Foundation; either version 2, or (at your option)
Packit Service 9285f1
# any later version.
Packit Service 9285f1
#
Packit Service 9285f1
# This program is distributed in the hope that it will be useful,
Packit Service 9285f1
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 9285f1
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 9285f1
# GNU General Public License for more details.
Packit Service 9285f1
#
Packit Service 9285f1
# You should have received a copy of the GNU General Public License
Packit Service 9285f1
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service 9285f1
Packit Service 9285f1
# As a special exception to the GNU General Public License, if you
Packit Service 9285f1
# distribute this file as part of a program that contains a
Packit Service 9285f1
# configuration script generated by Autoconf, you may include it under
Packit Service 9285f1
# the same distribution terms that you use for the rest of that program.
Packit Service 9285f1
Packit Service 9285f1
# This file is maintained in Automake, please report
Packit Service 9285f1
# bugs to <bug-automake@gnu.org> or send patches to
Packit Service 9285f1
# <automake-patches@gnu.org>.
Packit Service 9285f1
Packit Service 9285f1
get_dirname ()
Packit Service 9285f1
{
Packit Service 9285f1
  case $1 in
Packit Service 9285f1
    */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';;
Packit Service 9285f1
    # Otherwise,  we want the empty string (not ".").
Packit Service 9285f1
  esac
Packit Service 9285f1
}
Packit Service 9285f1
Packit Service 9285f1
# guard FILE
Packit Service 9285f1
# ----------
Packit Service 9285f1
# The CPP macro used to guard inclusion of FILE.
Packit Service 9285f1
guard ()
Packit Service 9285f1
{
Packit Service 9285f1
  printf '%s\n' "$1"                                                    \
Packit Service 9285f1
    | sed                                                               \
Packit Service 9285f1
        -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'   \
Packit Service 9285f1
        -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'                        \
Packit Service 9285f1
        -e 's/__*/_/g'
Packit Service 9285f1
}
Packit Service 9285f1
Packit Service 9285f1
# quote_for_sed [STRING]
Packit Service 9285f1
# ----------------------
Packit Service 9285f1
# Return STRING (or stdin) quoted to be used as a sed pattern.
Packit Service 9285f1
quote_for_sed ()
Packit Service 9285f1
{
Packit Service 9285f1
  case $# in
Packit Service 9285f1
    0) cat;;
Packit Service 9285f1
    1) printf '%s\n' "$1";;
Packit Service 9285f1
  esac \
Packit Service 9285f1
    | sed -e 's|[][\\.*]|\\&|g'
Packit Service 9285f1
}
Packit Service 9285f1
Packit Service 9285f1
case "$1" in
Packit Service 9285f1
  '')
Packit Service 9285f1
    echo "$0: No files given.  Try '$0 --help' for more information." 1>&2
Packit Service 9285f1
    exit 1
Packit Service 9285f1
    ;;
Packit Service 9285f1
  --basedir)
Packit Service 9285f1
    basedir=$2
Packit Service 9285f1
    shift 2
Packit Service 9285f1
    ;;
Packit Service 9285f1
  -h|--h*)
Packit Service 9285f1
    cat <<\EOF
Packit Service 9285f1
Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
Packit Service 9285f1
Packit Service 9285f1
Wrapper for lex/yacc invocations, renaming files as desired.
Packit Service 9285f1
Packit Service 9285f1
  INPUT is the input file
Packit Service 9285f1
  OUTPUT is one file PROG generates
Packit Service 9285f1
  DESIRED is the file we actually want instead of OUTPUT
Packit Service 9285f1
  PROGRAM is program to run
Packit Service 9285f1
  ARGS are passed to PROG
Packit Service 9285f1
Packit Service 9285f1
Any number of OUTPUT,DESIRED pairs may be used.
Packit Service 9285f1
Packit Service 9285f1
Report bugs to <bug-automake@gnu.org>.
Packit Service 9285f1
EOF
Packit Service 9285f1
    exit $?
Packit Service 9285f1
    ;;
Packit Service 9285f1
  -v|--v*)
Packit Service 9285f1
    echo "ylwrap $scriptversion"
Packit Service 9285f1
    exit $?
Packit Service 9285f1
    ;;
Packit Service 9285f1
esac
Packit Service 9285f1
Packit Service 9285f1
Packit Service 9285f1
# The input.
Packit Service 9285f1
input=$1
Packit Service 9285f1
shift
Packit Service 9285f1
# We'll later need for a correct munging of "#line" directives.
Packit Service 9285f1
input_sub_rx=`get_dirname "$input" | quote_for_sed`
Packit Service 9285f1
case $input in
Packit Service 9285f1
  [\\/]* | ?:[\\/]*)
Packit Service 9285f1
    # Absolute path; do nothing.
Packit Service 9285f1
    ;;
Packit Service 9285f1
  *)
Packit Service 9285f1
    # Relative path.  Make it absolute.
Packit Service 9285f1
    input=`pwd`/$input
Packit Service 9285f1
    ;;
Packit Service 9285f1
esac
Packit Service 9285f1
input_rx=`get_dirname "$input" | quote_for_sed`
Packit Service 9285f1
Packit Service 9285f1
# Since DOS filename conventions don't allow two dots,
Packit Service 9285f1
# the DOS version of Bison writes out y_tab.c instead of y.tab.c
Packit Service 9285f1
# and y_tab.h instead of y.tab.h. Test to see if this is the case.
Packit Service 9285f1
y_tab_nodot=false
Packit Service 9285f1
if test -f y_tab.c || test -f y_tab.h; then
Packit Service 9285f1
  y_tab_nodot=true
Packit Service 9285f1
fi
Packit Service 9285f1
Packit Service 9285f1
# The parser itself, the first file, is the destination of the .y.c
Packit Service 9285f1
# rule in the Makefile.
Packit Service 9285f1
parser=$1
Packit Service 9285f1
Packit Service 9285f1
# A sed program to s/FROM/TO/g for all the FROM/TO so that, for
Packit Service 9285f1
# instance, we rename #include "y.tab.h" into #include "parse.h"
Packit Service 9285f1
# during the conversion from y.tab.c to parse.c.
Packit Service 9285f1
sed_fix_filenames=
Packit Service 9285f1
Packit Service 9285f1
# Also rename header guards, as Bison 2.7 for instance uses its header
Packit Service 9285f1
# guard in its implementation file.
Packit Service 9285f1
sed_fix_header_guards=
Packit Service 9285f1
Packit Service 9285f1
while test $# -ne 0; do
Packit Service 9285f1
  if test x"$1" = x"--"; then
Packit Service 9285f1
    shift
Packit Service 9285f1
    break
Packit Service 9285f1
  fi
Packit Service 9285f1
  from=$1
Packit Service 9285f1
  # Handle y_tab.c and y_tab.h output by DOS
Packit Service 9285f1
  if $y_tab_nodot; then
Packit Service 9285f1
    case $from in
Packit Service 9285f1
      "y.tab.c") from=y_tab.c;;
Packit Service 9285f1
      "y.tab.h") from=y_tab.h;;
Packit Service 9285f1
    esac
Packit Service 9285f1
  fi
Packit Service 9285f1
  shift
Packit Service 9285f1
  to=$1
Packit Service 9285f1
  shift
Packit Service 9285f1
  sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;"
Packit Service 9285f1
  sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;"
Packit Service 9285f1
done
Packit Service 9285f1
Packit Service 9285f1
# The program to run.
Packit Service 9285f1
prog=$1
Packit Service 9285f1
shift
Packit Service 9285f1
# Make any relative path in $prog absolute.
Packit Service 9285f1
case $prog in
Packit Service 9285f1
  [\\/]* | ?:[\\/]*) ;;
Packit Service 9285f1
  *[\\/]*) prog=`pwd`/$prog ;;
Packit Service 9285f1
esac
Packit Service 9285f1
Packit Service 9285f1
dirname=ylwrap$$
Packit Service 9285f1
do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
Packit Service 9285f1
trap "ret=129; $do_exit" 1
Packit Service 9285f1
trap "ret=130; $do_exit" 2
Packit Service 9285f1
trap "ret=141; $do_exit" 13
Packit Service 9285f1
trap "ret=143; $do_exit" 15
Packit Service 9285f1
mkdir $dirname || exit 1
Packit Service 9285f1
Packit Service 9285f1
cd $dirname
Packit Service 9285f1
Packit Service 9285f1
case $# in
Packit Service 9285f1
  0) "$prog" "$input" ;;
Packit Service 9285f1
  *) "$prog" "$@" "$input" ;;
Packit Service 9285f1
esac
Packit Service 9285f1
ret=$?
Packit Service 9285f1
Packit Service 9285f1
if test $ret -eq 0; then
Packit Service 9285f1
  for from in *
Packit Service 9285f1
  do
Packit Service 9285f1
    to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
Packit Service 9285f1
    if test -f "$from"; then
Packit Service 9285f1
      # If $2 is an absolute path name, then just use that,
Packit Service 9285f1
      # otherwise prepend '../'.
Packit Service 9285f1
      case $to in
Packit Service 9285f1
        [\\/]* | ?:[\\/]*) target=$to;;
Packit Service 9285f1
        *) target=../$to;;
Packit Service 9285f1
      esac
Packit Service 9285f1
Packit Service 9285f1
      # Do not overwrite unchanged header files to avoid useless
Packit Service 9285f1
      # recompilations.  Always update the parser itself: it is the
Packit Service 9285f1
      # destination of the .y.c rule in the Makefile.  Divert the
Packit Service 9285f1
      # output of all other files to a temporary file so we can
Packit Service 9285f1
      # compare them to existing versions.
Packit Service 9285f1
      if test $from != $parser; then
Packit Service 9285f1
        realtarget=$target
Packit Service 9285f1
        target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
Packit Service 9285f1
      fi
Packit Service 9285f1
Packit Service 9285f1
      # Munge "#line" or "#" directives.  Don't let the resulting
Packit Service 9285f1
      # debug information point at an absolute srcdir.  Use the real
Packit Service 9285f1
      # output file name, not yy.lex.c for instance.  Adjust the
Packit Service 9285f1
      # include guards too.
Packit Service 9285f1
      sed -e "/^#/!b"                           \
Packit Service 9285f1
          -e "s|$input_rx|$input_sub_rx|"       \
Packit Service 9285f1
          -e "$sed_fix_filenames"               \
Packit Service 9285f1
          -e "$sed_fix_header_guards"           \
Packit Service 9285f1
        "$from" >"$target" || ret=$?
Packit Service 9285f1
Packit Service 9285f1
      # Check whether files must be updated.
Packit Service 9285f1
      if test "$from" != "$parser"; then
Packit Service 9285f1
        if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
Packit Service 9285f1
          echo "$to is unchanged"
Packit Service 9285f1
          rm -f "$target"
Packit Service 9285f1
        else
Packit Service 9285f1
          echo "updating $to"
Packit Service 9285f1
          mv -f "$target" "$realtarget"
Packit Service 9285f1
        fi
Packit Service 9285f1
      fi
Packit Service 9285f1
    else
Packit Service 9285f1
      # A missing file is only an error for the parser.  This is a
Packit Service 9285f1
      # blatant hack to let us support using "yacc -d".  If -d is not
Packit Service 9285f1
      # specified, don't fail when the header file is "missing".
Packit Service 9285f1
      if test "$from" = "$parser"; then
Packit Service 9285f1
        ret=1
Packit Service 9285f1
      fi
Packit Service 9285f1
    fi
Packit Service 9285f1
  done
Packit Service 9285f1
fi
Packit Service 9285f1
Packit Service 9285f1
# Remove the directory.
Packit Service 9285f1
cd ..
Packit Service 9285f1
rm -rf $dirname
Packit Service 9285f1
Packit Service 9285f1
exit $ret
Packit Service 9285f1
Packit Service 9285f1
# Local Variables:
Packit Service 9285f1
# mode: shell-script
Packit Service 9285f1
# sh-indentation: 2
Packit Service 9285f1
# eval: (add-hook 'write-file-hooks 'time-stamp)
Packit Service 9285f1
# time-stamp-start: "scriptversion="
Packit Service 9285f1
# time-stamp-format: "%:y-%02m-%02d.%02H"
Packit Service 9285f1
# time-stamp-time-zone: "UTC"
Packit Service 9285f1
# time-stamp-end: "; # UTC"
Packit Service 9285f1
# End: