1
1
#! /bin/sh
2
2
# ylwrap - wrapper for lex/yacc invocations.
3
3
4
- scriptversion=2009-04-28.21 ; # UTC
4
+ scriptversion=2013-01-12.17 ; # UTC
5
5
6
- # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
7
- # 2007, 2009 Free Software Foundation, Inc.
6
+ # Copyright (C) 1996-2014 Free Software Foundation, Inc.
8
7
#
9
8
# Written by Tom Tromey <tromey@cygnus.com>.
10
9
#
@@ -30,9 +29,41 @@ scriptversion=2009-04-28.21; # UTC
30
29
# bugs to <bug-automake@gnu.org> or send patches to
31
30
# <automake-patches@gnu.org>.
32
31
32
+ get_dirname ()
33
+ {
34
+ case $1 in
35
+ * /* |* \\ * ) printf ' %s\n' " $1 " | sed -e ' s|\([\\/]\)[^\\/]*$|\1|' ;;
36
+ # Otherwise, we want the empty string (not ".").
37
+ esac
38
+ }
39
+
40
+ # guard FILE
41
+ # ----------
42
+ # The CPP macro used to guard inclusion of FILE.
43
+ guard ()
44
+ {
45
+ printf ' %s\n' " $1 " \
46
+ | sed \
47
+ -e ' y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
48
+ -e ' s/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' \
49
+ -e ' s/__*/_/g'
50
+ }
51
+
52
+ # quote_for_sed [STRING]
53
+ # ----------------------
54
+ # Return STRING (or stdin) quoted to be used as a sed pattern.
55
+ quote_for_sed ()
56
+ {
57
+ case $# in
58
+ 0) cat;;
59
+ 1) printf ' %s\n' " $1 " ;;
60
+ esac \
61
+ | sed -e ' s|[][\\.*]|\\&|g'
62
+ }
63
+
33
64
case " $1 " in
34
65
' ' )
35
- echo " $0 : No files given. Try \` $0 --help' for more information." 1>&2
66
+ echo " $0 : No files given. Try ' $0 --help' for more information." 1>&2
36
67
exit 1
37
68
;;
38
69
--basedir)
65
96
66
97
67
98
# The input.
68
- input=" $1 "
99
+ input=$1
69
100
shift
70
- case " $input " in
101
+ # We'll later need for a correct munging of "#line" directives.
102
+ input_sub_rx=` get_dirname " $input " | quote_for_sed`
103
+ case $input in
71
104
[\\ /]* | ? :[\\ /]* )
72
105
# Absolute path; do nothing.
73
106
;;
74
107
* )
75
108
# Relative path. Make it absolute.
76
- input=" ` pwd` /$input "
109
+ input=` pwd` /$input
77
110
;;
78
111
esac
112
+ input_rx=` get_dirname " $input " | quote_for_sed`
113
+
114
+ # The parser itself, the first file, is the destination of the .y.c
115
+ # rule in the Makefile.
116
+ parser=$1
117
+
118
+ # A sed program to s/FROM/TO/g for all the FROM/TO so that, for
119
+ # instance, we rename #include "y.tab.h" into #include "parse.h"
120
+ # during the conversion from y.tab.c to parse.c.
121
+ sed_fix_filenames=
122
+
123
+ # Also rename header guards, as Bison 2.7 for instance uses its header
124
+ # guard in its implementation file.
125
+ sed_fix_header_guards=
79
126
80
- pairlist=
81
- while test " $# " -ne 0; do
82
- if test " $1 " = " --" ; then
127
+ while test $# -ne 0; do
128
+ if test x" $1 " = x" --" ; then
83
129
shift
84
130
break
85
131
fi
86
- pairlist= " $pairlist $1 "
132
+ from= $1
87
133
shift
134
+ to=$1
135
+ shift
136
+ sed_fix_filenames=" ${sed_fix_filenames} s|" ` quote_for_sed " $from " ` " |$to |g;"
137
+ sed_fix_header_guards=" ${sed_fix_header_guards} s|" ` guard " $from " ` " |" ` guard " $to " ` " |g;"
88
138
done
89
139
90
140
# The program to run.
91
- prog=" $1 "
141
+ prog=$1
92
142
shift
93
143
# Make any relative path in $prog absolute.
94
- case " $prog " in
144
+ case $prog in
95
145
[\\ /]* | ? :[\\ /]* ) ;;
96
- * [\\ /]* ) prog=" ` pwd` /$prog " ;;
146
+ * [\\ /]* ) prog=` pwd` /$prog ;;
97
147
esac
98
148
99
- # FIXME: add hostname here for parallel makes that run commands on
100
- # other machines. But that might take us over the 14-char limit.
101
149
dirname=ylwrap$$
102
- trap " cd '` pwd` '; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
150
+ do_exit=" cd '` pwd` ' && rm -rf $dirname > /dev/null 2>&1;" ' (exit $ret); exit $ret'
151
+ trap " ret=129; $do_exit " 1
152
+ trap " ret=130; $do_exit " 2
153
+ trap " ret=141; $do_exit " 13
154
+ trap " ret=143; $do_exit " 15
103
155
mkdir $dirname || exit 1
104
156
105
157
cd $dirname
@@ -111,98 +163,56 @@ esac
111
163
ret=$?
112
164
113
165
if test $ret -eq 0; then
114
- set X $pairlist
115
- shift
116
- first=yes
117
- # Since DOS filename conventions don't allow two dots,
118
- # the DOS version of Bison writes out y_tab.c instead of y.tab.c
119
- # and y_tab.h instead of y.tab.h. Test to see if this is the case.
120
- y_tab_nodot=" no"
121
- if test -f y_tab.c || test -f y_tab.h; then
122
- y_tab_nodot=" yes"
123
- fi
124
-
125
- # The directory holding the input.
126
- input_dir=` echo " $input " | sed -e ' s,\([\\/]\)[^\\/]*$,\1,' `
127
- # Quote $INPUT_DIR so we can use it in a regexp.
128
- # FIXME: really we should care about more than `.' and `\'.
129
- input_rx=` echo " $input_dir " | sed ' s,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g' `
130
-
131
- while test " $# " -ne 0; do
132
- from=" $1 "
133
- # Handle y_tab.c and y_tab.h output by DOS
134
- if test $y_tab_nodot = " yes" ; then
135
- if test $from = " y.tab.c" ; then
136
- from=" y_tab.c"
137
- else
138
- if test $from = " y.tab.h" ; then
139
- from=" y_tab.h"
140
- fi
141
- fi
142
- fi
166
+ for from in *
167
+ do
168
+ to=` printf ' %s\n' " $from " | sed " $sed_fix_filenames " `
143
169
if test -f " $from " ; then
144
170
# If $2 is an absolute path name, then just use that,
145
- # otherwise prepend ` ../'.
146
- case " $2 " in
147
- [\\ /]* | ? :[\\ /]* ) target=" $2 " ;;
148
- * ) target=" ../$2 " ;;
171
+ # otherwise prepend ' ../'.
172
+ case $to in
173
+ [\\ /]* | ? :[\\ /]* ) target=$to ;;
174
+ * ) target=../$to ;;
149
175
esac
150
176
151
- # We do not want to overwrite a header file if it hasn't
152
- # changed. This avoid useless recompilations. However the
153
- # parser itself (the first file) should always be updated,
154
- # because it is the destination of the .y.c rule in the
155
- # Makefile. Divert the output of all other files to a temporary
156
- # file so we can compare them to existing versions.
157
- if test $first = no; then
158
- realtarget=" $target "
159
- target=" tmp-` echo $target | sed s/.* [\\ /]//g` "
177
+ # Do not overwrite unchanged header files to avoid useless
178
+ # recompilations. Always update the parser itself: it is the
179
+ # destination of the .y.c rule in the Makefile. Divert the
180
+ # output of all other files to a temporary file so we can
181
+ # compare them to existing versions.
182
+ if test $from ! = $parser ; then
183
+ realtarget=$target
184
+ target=tmp-` printf ' %s\n' " $target " | sed ' s|.*[\\/]||g' `
160
185
fi
161
- # Edit out `#line' or `#' directives.
162
- #
163
- # We don't want the resulting debug information to point at
164
- # an absolute srcdir; it is better for it to just mention the
165
- # .y file with no path.
166
- #
167
- # We want to use the real output file name, not yy.lex.c for
168
- # instance.
169
- #
170
- # We want the include guards to be adjusted too.
171
- FROM=` echo " $from " | sed \
172
- -e ' y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
173
- -e ' s/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' `
174
- TARGET=` echo " $2 " | sed \
175
- -e ' y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
176
- -e ' s/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' `
177
-
178
- sed -e " /^#/!b" -e " s,$input_rx ,," -e " s,$from ,$2 ," \
179
- -e " s,$FROM ,$TARGET ," " $from " > " $target " || ret=$?
180
-
181
- # Check whether header files must be updated.
182
- if test $first = no; then
183
- if test -f " $realtarget " && cmp -s " $realtarget " " $target " ; then
184
- echo " $2 " is unchanged
185
- rm -f " $target "
186
- else
187
- echo updating " $2 "
186
+
187
+ # Munge "#line" or "#" directives. Don't let the resulting
188
+ # debug information point at an absolute srcdir. Use the real
189
+ # output file name, not yy.lex.c for instance. Adjust the
190
+ # include guards too.
191
+ sed -e " /^#/!b" \
192
+ -e " s|$input_rx |$input_sub_rx |" \
193
+ -e " $sed_fix_filenames " \
194
+ -e " $sed_fix_header_guards " \
195
+ " $from " > " $target " || ret=$?
196
+
197
+ # Check whether files must be updated.
198
+ if test " $from " ! = " $parser " ; then
199
+ if test -f " $realtarget " && cmp -s " $realtarget " " $target " ; then
200
+ echo " $to is unchanged"
201
+ rm -f " $target "
202
+ else
203
+ echo " updating $to "
188
204
mv -f " $target " " $realtarget "
189
205
fi
190
206
fi
191
207
else
192
- # A missing file is only an error for the first file. This
193
- # is a blatant hack to let us support using "yacc -d". If -d
194
- # is not specified, we don't want an error when the header
195
- # file is "missing".
196
- if test $first = yes; then
208
+ # A missing file is only an error for the parser. This is a
209
+ # blatant hack to let us support using "yacc -d". If -d is not
210
+ # specified, don't fail when the header file is "missing".
211
+ if test " $from " = " $parser " ; then
197
212
ret=1
198
213
fi
199
214
fi
200
- shift
201
- shift
202
- first=no
203
215
done
204
- else
205
- ret=$?
206
216
fi
207
217
208
218
# Remove the directory.
0 commit comments