ylwrap revision 38889
138889Sjdp#! /bin/sh 238889Sjdp# ylwrap - wrapper for lex/yacc invocations. 338889Sjdp# Copyright (C) 1996, 1997 Free Software Foundation, Inc. 438889Sjdp# Written by Tom Tromey <tromey@cygnus.com>. 538889Sjdp# 638889Sjdp# This program is free software; you can redistribute it and/or modify 738889Sjdp# it under the terms of the GNU General Public License as published by 838889Sjdp# the Free Software Foundation; either version 2, or (at your option) 938889Sjdp# any later version. 1038889Sjdp# 1138889Sjdp# This program is distributed in the hope that it will be useful, 1238889Sjdp# but WITHOUT ANY WARRANTY; without even the implied warranty of 1338889Sjdp# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1438889Sjdp# GNU General Public License for more details. 1538889Sjdp# 1638889Sjdp# You should have received a copy of the GNU General Public License 1738889Sjdp# along with this program; if not, write to the Free Software 1838889Sjdp# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 1938889Sjdp 2038889Sjdp# Usage: 2138889Sjdp# ylwrap PROGRAM INPUT [OUTPUT DESIRED]... -- [ARGS]... 2238889Sjdp# * PROGRAM is program to run. 2338889Sjdp# * INPUT is the input file 2438889Sjdp# * OUTPUT is file PROG generates 2538889Sjdp# * DESIRED is file we actually want 2638889Sjdp# * ARGS are passed to PROG 2738889Sjdp# Any number of OUTPUT,DESIRED pairs may be used. 2838889Sjdp 2938889Sjdp# The program to run. 3038889Sjdpprog="$1" 3138889Sjdpshift 3238889Sjdp# Make any relative path in $prog absolute. 3338889Sjdpcase "$prog" in 3438889Sjdp /*) ;; 3538889Sjdp */*) prog="`pwd`/$prog" ;; 3638889Sjdpesac 3738889Sjdp 3838889Sjdp# The input. 3938889Sjdpinput="$1" 4038889Sjdpshift 4138889Sjdpcase "$input" in 4238889Sjdp /*) 4338889Sjdp # Absolute path; do nothing. 4438889Sjdp ;; 4538889Sjdp *) 4638889Sjdp # Relative path. Make it absolute. Why? Because otherwise any 4738889Sjdp # debugging info in the generated file will point to the wrong 4838889Sjdp # place. This is really gross. 4938889Sjdp input="`pwd`/$input" 5038889Sjdp ;; 5138889Sjdpesac 5238889Sjdp 5338889Sjdppairlist= 5438889Sjdpwhile test "$#" -ne 0; do 5538889Sjdp if test "$1" = "--"; then 5638889Sjdp shift 5738889Sjdp break 5838889Sjdp fi 5938889Sjdp pairlist="$pairlist $1" 6038889Sjdp shift 6138889Sjdpdone 6238889Sjdp 6338889Sjdp# FIXME: add hostname here for parallel makes that run commands on 6438889Sjdp# other machines. But that might take us over the 14-char limit. 6538889Sjdpdirname=ylwrap$$ 6638889Sjdptrap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 6738889Sjdpmkdir $dirname || exit 1 6838889Sjdp 6938889Sjdpcd $dirname 7038889Sjdp$prog ${1+"$@"} "$input" 7138889Sjdpstatus=$? 7238889Sjdp 7338889Sjdpif test $status -eq 0; then 7438889Sjdp set X $pairlist 7538889Sjdp shift 7638889Sjdp first=yes 7738889Sjdp while test "$#" -ne 0; do 7838889Sjdp if test -f "$1"; then 7938889Sjdp # If $2 is an absolute path name, then just use that, 8038889Sjdp # otherwise prepend `../'. 8138889Sjdp case "$2" in 8238889Sjdp /*) target="$2";; 8338889Sjdp *) target="../$2";; 8438889Sjdp esac 8538889Sjdp mv "$1" "$target" || status=$? 8638889Sjdp else 8738889Sjdp # A missing file is only an error for the first file. This 8838889Sjdp # is a blatant hack to let us support using "yacc -d". If -d 8938889Sjdp # is not specified, we don't want an error when the header 9038889Sjdp # file is "missing". 9138889Sjdp if test $first = yes; then 9238889Sjdp status=1 9338889Sjdp fi 9438889Sjdp fi 9538889Sjdp shift 9638889Sjdp shift 9738889Sjdp first=no 9838889Sjdp done 9938889Sjdpelse 10038889Sjdp status=$? 10138889Sjdpfi 10238889Sjdp 10338889Sjdp# Remove the directory. 10438889Sjdpcd .. 10538889Sjdprm -rf $dirname 10638889Sjdp 10738889Sjdpexit $status 108