ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/releases/8.2.0beta1/ylwrap
Revision: 1592
Committed: Sat Oct 27 21:02:32 2012 UTC (11 years, 5 months ago) by michael
Original Path: ircd-hybrid/trunk/ylwrap
File size: 6546 byte(s)
Log Message:
- Second time's the charm? Moving svnroot/ircd-hybrid-8 to
  svnroot/ircd-hybrid/trunk

File Contents

# User Rev Content
1 michael 912 #! /bin/sh
2     # ylwrap - wrapper for lex/yacc invocations.
3    
4 michael 1504 scriptversion=2012-07-14.08; # UTC
5 michael 912
6 michael 1375 # Copyright (C) 1996-2012 Free Software Foundation, Inc.
7 michael 912 #
8     # Written by Tom Tromey <tromey@cygnus.com>.
9     #
10     # This program is free software; you can redistribute it and/or modify
11     # it under the terms of the GNU General Public License as published by
12     # the Free Software Foundation; either version 2, or (at your option)
13     # any later version.
14     #
15     # This program is distributed in the hope that it will be useful,
16     # but WITHOUT ANY WARRANTY; without even the implied warranty of
17     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     # GNU General Public License for more details.
19     #
20     # You should have received a copy of the GNU General Public License
21 michael 945 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 michael 912
23     # As a special exception to the GNU General Public License, if you
24     # distribute this file as part of a program that contains a
25     # configuration script generated by Autoconf, you may include it under
26     # the same distribution terms that you use for the rest of that program.
27    
28     # This file is maintained in Automake, please report
29     # bugs to <bug-automake@gnu.org> or send patches to
30     # <automake-patches@gnu.org>.
31    
32 michael 1504 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' "$from" \
46     | sed \
47     -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
48     -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'
49     }
50    
51     # quote_for_sed [STRING]
52     # ----------------------
53     # Return STRING (or stdin) quoted to be used as a sed pattern.
54     quote_for_sed ()
55     {
56     case $# in
57     0) cat;;
58     1) printf '%s\n' "$1";;
59     esac \
60     | sed -e 's|[][\\.*]|\\&|g'
61     }
62    
63 michael 912 case "$1" in
64     '')
65 michael 1375 echo "$0: No files given. Try '$0 --help' for more information." 1>&2
66 michael 912 exit 1
67     ;;
68     --basedir)
69     basedir=$2
70     shift 2
71     ;;
72     -h|--h*)
73     cat <<\EOF
74     Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
75    
76     Wrapper for lex/yacc invocations, renaming files as desired.
77    
78     INPUT is the input file
79     OUTPUT is one file PROG generates
80     DESIRED is the file we actually want instead of OUTPUT
81     PROGRAM is program to run
82     ARGS are passed to PROG
83    
84     Any number of OUTPUT,DESIRED pairs may be used.
85    
86     Report bugs to <bug-automake@gnu.org>.
87     EOF
88     exit $?
89     ;;
90     -v|--v*)
91     echo "ylwrap $scriptversion"
92     exit $?
93     ;;
94     esac
95    
96    
97     # The input.
98     input="$1"
99     shift
100 michael 1425 # We'll later need for a correct munging of "#line" directives.
101     input_sub_rx=`get_dirname "$input" | quote_for_sed`
102 michael 912 case "$input" in
103     [\\/]* | ?:[\\/]*)
104     # Absolute path; do nothing.
105     ;;
106     *)
107     # Relative path. Make it absolute.
108     input="`pwd`/$input"
109     ;;
110     esac
111 michael 1504 input_rx=`get_dirname "$input" | quote_for_sed`
112 michael 912
113 michael 1504 # Since DOS filename conventions don't allow two dots,
114     # the DOS version of Bison writes out y_tab.c instead of y.tab.c
115     # and y_tab.h instead of y.tab.h. Test to see if this is the case.
116     y_tab_nodot=false
117     if test -f y_tab.c || test -f y_tab.h; then
118     y_tab_nodot=true
119     fi
120    
121     # The parser itself, the first file, is the destination of the .y.c
122     # rule in the Makefile.
123     parser=$1
124     # A sed program to s/FROM/TO/g for all the FROM/TO so that, for
125     # instance, we rename #include "y.tab.h" into #include "parse.h"
126     # during the conversion from y.tab.c to parse.c.
127     rename_sed=
128 michael 912 while test "$#" -ne 0; do
129     if test "$1" = "--"; then
130     shift
131     break
132     fi
133 michael 1504 from=$1
134     # Handle y_tab.c and y_tab.h output by DOS
135     if $y_tab_nodot; then
136     case $from in
137     "y.tab.c") from=y_tab.c;;
138     "y.tab.h") from=y_tab.h;;
139     esac
140     fi
141 michael 912 shift
142 michael 1504 to=$1
143     shift
144     rename_sed="${rename_sed}s|"`quote_for_sed "$from"`"|$to|g;"
145 michael 912 done
146    
147     # The program to run.
148     prog="$1"
149     shift
150     # Make any relative path in $prog absolute.
151     case "$prog" in
152     [\\/]* | ?:[\\/]*) ;;
153     *[\\/]*) prog="`pwd`/$prog" ;;
154     esac
155    
156     # FIXME: add hostname here for parallel makes that run commands on
157     # other machines. But that might take us over the 14-char limit.
158     dirname=ylwrap$$
159 michael 1257 do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
160     trap "ret=129; $do_exit" 1
161     trap "ret=130; $do_exit" 2
162     trap "ret=141; $do_exit" 13
163     trap "ret=143; $do_exit" 15
164 michael 912 mkdir $dirname || exit 1
165    
166     cd $dirname
167    
168     case $# in
169 michael 945 0) "$prog" "$input" ;;
170     *) "$prog" "$@" "$input" ;;
171 michael 912 esac
172     ret=$?
173    
174     if test $ret -eq 0; then
175 michael 1504 for from in *
176     do
177     to=`printf '%s\n' "$from" | sed "$rename_sed"`
178 michael 912 if test -f "$from"; then
179     # If $2 is an absolute path name, then just use that,
180 michael 1375 # otherwise prepend '../'.
181 michael 1504 case $to in
182     [\\/]* | ?:[\\/]*) target=$to;;
183     *) target="../$to";;
184 michael 912 esac
185    
186 michael 1504 # Do not overwrite unchanged header files to avoid useless
187     # recompilations. Always update the parser itself: it is the
188     # destination of the .y.c rule in the Makefile. Divert the
189     # output of all other files to a temporary file so we can
190     # compare them to existing versions.
191     if test $from != $parser; then
192 michael 1257 realtarget="$target"
193 michael 1504 target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
194 michael 912 fi
195    
196 michael 1504 # Munge "#line" or "#" directives. Don't let the resulting
197     # debug information point at an absolute srcdir. Use the real
198     # output file name, not yy.lex.c for instance. Adjust the
199     # include guards too.
200     FROM=`guard "$from"`
201     TARGET=`guard "$to"`
202     sed -e "/^#/!b" -e "s|$input_rx|$input_sub_rx|" -e "$rename_sed" \
203     -e "s|$FROM|$TARGET|" "$from" >"$target" || ret=$?
204 michael 912
205 michael 1504 # Check whether files must be updated.
206     if test "$from" != "$parser"; then
207 michael 1257 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
208 michael 1504 echo "$to is unchanged"
209 michael 1257 rm -f "$target"
210     else
211 michael 1504 echo "updating $to"
212 michael 912 mv -f "$target" "$realtarget"
213     fi
214     fi
215     else
216 michael 1504 # A missing file is only an error for the parser. This is a
217     # blatant hack to let us support using "yacc -d". If -d is not
218     # specified, don't fail when the header file is "missing".
219     if test "$from" = "$parser"; then
220 michael 912 ret=1
221     fi
222     fi
223     done
224     fi
225    
226     # Remove the directory.
227     cd ..
228     rm -rf $dirname
229    
230     exit $ret
231    
232     # Local Variables:
233     # mode: shell-script
234     # sh-indentation: 2
235     # eval: (add-hook 'write-file-hooks 'time-stamp)
236     # time-stamp-start: "scriptversion="
237     # time-stamp-format: "%:y-%02m-%02d.%02H"
238 michael 945 # time-stamp-time-zone: "UTC"
239     # time-stamp-end: "; # UTC"
240 michael 912 # End:

Properties

Name Value
svn:executable *