ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/ylwrap
(Generate patch)

Comparing:
ircd-hybrid-7.3/ylwrap (file contents), Revision 1029 by michael, Sun Nov 8 13:10:50 2009 UTC vs.
ircd-hybrid/trunk/ylwrap (file contents), Revision 1730 by michael, Sun Jan 6 11:27:11 2013 UTC

# Line 1 | Line 1
1   #! /bin/sh
2   # ylwrap - wrapper for lex/yacc invocations.
3  
4 < scriptversion=2009-04-28.21; # UTC
4 > scriptversion=2012-12-21.17; # UTC
5  
6 < # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
7 < # 2007, 2009 Free Software Foundation, Inc.
6 > # Copyright (C) 1996-2013 Free Software Foundation, Inc.
7   #
8   # Written by Tom Tromey <tromey@cygnus.com>.
9   #
# Line 30 | Line 29 | scriptversion=2009-04-28.21; # UTC
29   # bugs to <bug-automake@gnu.org> or send patches to
30   # <automake-patches@gnu.org>.
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 +
64   case "$1" in
65    '')
66 <    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
67      exit 1
68      ;;
69    --basedir)
# Line 67 | Line 98 | esac
98   # The input.
99   input="$1"
100   shift
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
104    [\\/]* | ?:[\\/]*)
105      # Absolute path; do nothing.
# Line 76 | Line 109 | case "$input" in
109      input="`pwd`/$input"
110      ;;
111   esac
112 + input_rx=`get_dirname "$input" | quote_for_sed`
113 +
114 + # Since DOS filename conventions don't allow two dots,
115 + # the DOS version of Bison writes out y_tab.c instead of y.tab.c
116 + # and y_tab.h instead of y.tab.h. Test to see if this is the case.
117 + y_tab_nodot=false
118 + if test -f y_tab.c || test -f y_tab.h; then
119 +  y_tab_nodot=true
120 + fi
121 +
122 + # The parser itself, the first file, is the destination of the .y.c
123 + # rule in the Makefile.
124 + parser=$1
125 +
126 + # A sed program to s/FROM/TO/g for all the FROM/TO so that, for
127 + # instance, we rename #include "y.tab.h" into #include "parse.h"
128 + # during the conversion from y.tab.c to parse.c.
129 + sed_fix_filenames=
130 +
131 + # Also rename header guards, as Bison 2.7 for instance uses its header
132 + # guard in its implementation file.
133 + sed_fix_header_guards=
134  
80 pairlist=
135   while test "$#" -ne 0; do
136    if test "$1" = "--"; then
137      shift
138      break
139    fi
140 <  pairlist="$pairlist $1"
140 >  from=$1
141 >  # Handle y_tab.c and y_tab.h output by DOS
142 >  if $y_tab_nodot; then
143 >    case $from in
144 >      "y.tab.c") from=y_tab.c;;
145 >      "y.tab.h") from=y_tab.h;;
146 >    esac
147 >  fi
148 >  shift
149 >  to=$1
150    shift
151 +  sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;"
152 +  sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;"
153   done
154  
155   # The program to run.
# Line 99 | Line 164 | esac
164   # FIXME: add hostname here for parallel makes that run commands on
165   # other machines.  But that might take us over the 14-char limit.
166   dirname=ylwrap$$
167 < trap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
167 > do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
168 > trap "ret=129; $do_exit" 1
169 > trap "ret=130; $do_exit" 2
170 > trap "ret=141; $do_exit" 13
171 > trap "ret=143; $do_exit" 15
172   mkdir $dirname || exit 1
173  
174   cd $dirname
# Line 111 | Line 180 | esac
180   ret=$?
181  
182   if test $ret -eq 0; then
183 <  set X $pairlist
184 <  shift
185 <  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
183 >  for from in *
184 >  do
185 >    to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
186      if test -f "$from"; then
187        # If $2 is an absolute path name, then just use that,
188 <      # otherwise prepend `../'.
189 <      case "$2" in
190 <        [\\/]* | ?:[\\/]*) target="$2";;
191 <        *) target="../$2";;
188 >      # otherwise prepend '../'.
189 >      case $to in
190 >        [\\/]* | ?:[\\/]*) target=$to;;
191 >        *) target="../$to";;
192        esac
193  
194 <      # We do not want to overwrite a header file if it hasn't
195 <      # changed.  This avoid useless recompilations.  However the
196 <      # parser itself (the first file) should always be updated,
197 <      # because it is the destination of the .y.c rule in the
198 <      # Makefile.  Divert the output of all other files to a temporary
199 <      # file so we can compare them to existing versions.
200 <      if test $first = no; then
201 <        realtarget="$target"
159 <        target="tmp-`echo $target | sed s/.*[\\/]//g`"
194 >      # Do not overwrite unchanged header files to avoid useless
195 >      # recompilations.  Always update the parser itself: it is the
196 >      # destination of the .y.c rule in the Makefile.  Divert the
197 >      # output of all other files to a temporary file so we can
198 >      # compare them to existing versions.
199 >      if test $from != $parser; then
200 >        realtarget="$target"
201 >        target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
202        fi
203 <      # Edit out `#line' or `#' directives.
204 <      #
205 <      # We don't want the resulting debug information to point at
206 <      # an absolute srcdir; it is better for it to just mention the
207 <      # .y file with no path.
208 <      #
209 <      # We want to use the real output file name, not yy.lex.c for
210 <      # instance.
211 <      #
212 <      # We want the include guards to be adjusted too.
213 <      FROM=`echo "$from" | sed \
214 <            -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
215 <            -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
216 <      TARGET=`echo "$2" | sed \
217 <            -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
218 <            -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
219 <
220 <      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"
203 >
204 >      # Munge "#line" or "#" directives.  Don't let the resulting
205 >      # debug information point at an absolute srcdir.  Use the real
206 >      # output file name, not yy.lex.c for instance.  Adjust the
207 >      # include guards too.
208 >      sed -e "/^#/!b"                           \
209 >          -e "s|$input_rx|$input_sub_rx|"       \
210 >          -e "$sed_fix_filenames"               \
211 >          -e "$sed_fix_header_guards"           \
212 >        "$from" >"$target" || ret=$?
213 >
214 >      # Check whether files must be updated.
215 >      if test "$from" != "$parser"; then
216 >        if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
217 >          echo "$to is unchanged"
218 >          rm -f "$target"
219 >        else
220 >          echo "updating $to"
221            mv -f "$target" "$realtarget"
222          fi
223        fi
224      else
225 <      # A missing file is only an error for the first file.  This
226 <      # is a blatant hack to let us support using "yacc -d".  If -d
227 <      # is not specified, we don't want an error when the header
228 <      # file is "missing".
196 <      if test $first = yes; then
225 >      # A missing file is only an error for the parser.  This is a
226 >      # blatant hack to let us support using "yacc -d".  If -d is not
227 >      # specified, don't fail when the header file is "missing".
228 >      if test "$from" = "$parser"; then
229          ret=1
230        fi
231      fi
200    shift
201    shift
202    first=no
232    done
204 else
205  ret=$?
233   fi
234  
235   # Remove the directory.

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)