source: trunk/MagicSoft/AMC/activemirrorcontrol/admin/ylwrap@ 6903

Last change on this file since 6903 was 3403, checked in by merck, 21 years ago
initial check-in of AMC software
File size: 3.7 KB
Line 
1#! /bin/sh
2# ylwrap - wrapper for lex/yacc invocations.
3# Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
4# Written by Tom Tromey <tromey@cygnus.com>.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2, or (at your option)
9# any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20# Usage:
21# ylwrap PROGRAM INPUT [OUTPUT DESIRED]... -- [ARGS]...
22# * PROGRAM is program to run.
23# * INPUT is the input file
24# * OUTPUT is file PROG generates
25# * DESIRED is file we actually want
26# * ARGS are passed to PROG
27# Any number of OUTPUT,DESIRED pairs may be used.
28
29# The program to run.
30prog="$1"
31shift
32# Make any relative path in $prog absolute.
33case "$prog" in
34 /* | [A-Za-z]:*) ;;
35 */*) prog="`pwd`/$prog" ;;
36esac
37
38# The input.
39input="$1"
40shift
41case "$input" in
42 /* | [A-Za-z]:*)
43 # Absolute path; do nothing.
44 ;;
45 *)
46 # Relative path. Make it absolute. Why? Because otherwise any
47 # debugging info in the generated file will point to the wrong
48 # place. This is really gross.
49 input="`pwd`/$input"
50 ;;
51esac
52
53# We don't want to use the absolute path if the input in the current
54# directory like when making a tar ball.
55input_base=`echo $input | sed -e 's|.*/||'`
56if test -f $input_base && cmp $input_base $input >/dev/null 2>&1; then
57 input=$input_base
58fi
59
60pairlist=
61while test "$#" -ne 0; do
62 if test "$1" = "--"; then
63 shift
64 break
65 fi
66 pairlist="$pairlist $1"
67 shift
68done
69
70# FIXME: add hostname here for parallel makes that run commands on
71# other machines. But that might take us over the 14-char limit.
72dirname=ylwrap$$
73trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
74mkdir $dirname || exit 1
75
76cd $dirname
77case "$input" in
78 /* | [A-Za-z]:*)
79 # Absolute path; do nothing.
80 ;;
81 *)
82 # Make a symbolic link, hard link or hardcopy.
83 ln -s ../"$input" . > /dev/null 2>&1 || ln ../"$input" . > /dev/null 2>&1 || cp ../"$input" .
84 ;;
85esac
86$prog ${1+"$@"} "$input"
87status=$?
88
89if test $status -eq 0; then
90 set X $pairlist
91 shift
92 first=yes
93 # Since DOS filename conventions don't allow two dots,
94 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
95 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
96 y_tab_nodot="no"
97 if test -f y_tab.c || test -f y_tab.h; then
98 y_tab_nodot="yes"
99 fi
100
101 while test "$#" -ne 0; do
102 from="$1"
103 # Handle y_tab.c and y_tab.h output by DOS
104 if test $y_tab_nodot = "yes"; then
105 if test $from = "y.tab.c"; then
106 from="y_tab.c"
107 else
108 if test $from = "y.tab.h"; then
109 from="y_tab.h"
110 fi
111 fi
112 fi
113 if test -f "$from"; then
114 # If $2 is an absolute path name, then just use that,
115 # otherwise prepend `../'.
116 case "$2" in
117 /* | [A-Za-z]:*) target="$2";;
118 *) target="../$2";;
119 esac
120 mv "$from" "$target" || status=$?
121 else
122 # A missing file is only an error for the first file. This
123 # is a blatant hack to let us support using "yacc -d". If -d
124 # is not specified, we don't want an error when the header
125 # file is "missing".
126 if test $first = yes; then
127 status=1
128 fi
129 fi
130 shift
131 shift
132 first=no
133 done
134else
135 status=$?
136fi
137
138# Remove the directory.
139cd ..
140rm -rf $dirname
141
142exit $status
Note: See TracBrowser for help on using the repository browser.