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