Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • automake/ylwrap

    r59310bf r00cc023  
    22# ylwrap - wrapper for lex/yacc invocations.
    33
    4 scriptversion=2013-01-12.17; # UTC
    5 
    6 # Copyright (C) 1996-2014 Free Software Foundation, Inc.
     4scriptversion=2011-08-25.18; # UTC
     5
     6# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
     7# 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
    78#
    89# Written by Tom Tromey <tromey@cygnus.com>.
     
    3031# <automake-patches@gnu.org>.
    3132
    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 
    6433case "$1" in
    6534  '')
    66     echo "$0: No files given.  Try '$0 --help' for more information." 1>&2
     35    echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
    6736    exit 1
    6837    ;;
     
    9766
    9867# The input.
    99 input=$1
     68input="$1"
    10069shift
    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
     70case "$input" in
    10471  [\\/]* | ?:[\\/]*)
    10572    # Absolute path; do nothing.
     
    10774  *)
    10875    # Relative path.  Make it absolute.
    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 
    135 while test $# -ne 0; do
    136   if test x"$1" = x"--"; then
     76    input="`pwd`/$input"
     77    ;;
     78esac
     79
     80pairlist=
     81while test "$#" -ne 0; do
     82  if test "$1" = "--"; then
    13783    shift
    13884    break
    13985  fi
    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
     86  pairlist="$pairlist $1"
    14887  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;"
    15388done
    15489
    15590# The program to run.
    156 prog=$1
     91prog="$1"
    15792shift
    15893# Make any relative path in $prog absolute.
    159 case $prog in
     94case "$prog" in
    16095  [\\/]* | ?:[\\/]*) ;;
    161   *[\\/]*) prog=`pwd`/$prog ;;
    162 esac
    163 
     96  *[\\/]*) prog="`pwd`/$prog" ;;
     97esac
     98
     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.
    164101dirname=ylwrap$$
    165102do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
     
    179116
    180117if test $ret -eq 0; then
    181   for from in *
    182   do
    183     to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
     118  set X $pairlist
     119  shift
     120  first=yes
     121  # Since DOS filename conventions don't allow two dots,
     122  # the DOS version of Bison writes out y_tab.c instead of y.tab.c
     123  # and y_tab.h instead of y.tab.h. Test to see if this is the case.
     124  y_tab_nodot="no"
     125  if test -f y_tab.c || test -f y_tab.h; then
     126    y_tab_nodot="yes"
     127  fi
     128
     129  # The directory holding the input.
     130  input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
     131  # Quote $INPUT_DIR so we can use it in a regexp.
     132  # FIXME: really we should care about more than `.' and `\'.
     133  input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
     134
     135  while test "$#" -ne 0; do
     136    from="$1"
     137    # Handle y_tab.c and y_tab.h output by DOS
     138    if test $y_tab_nodot = "yes"; then
     139      if test $from = "y.tab.c"; then
     140        from="y_tab.c"
     141      else
     142        if test $from = "y.tab.h"; then
     143          from="y_tab.h"
     144        fi
     145      fi
     146    fi
    184147    if test -f "$from"; then
    185148      # If $2 is an absolute path name, then just use that,
    186       # otherwise prepend '../'.
    187       case $to in
    188         [\\/]* | ?:[\\/]*) target=$to;;
    189         *) target=../$to;;
     149      # otherwise prepend `../'.
     150      case "$2" in
     151        [\\/]* | ?:[\\/]*) target="$2";;
     152        *) target="../$2";;
    190153      esac
    191154
    192       # Do not overwrite unchanged header files to avoid useless
    193       # recompilations.  Always update the parser itself: it is the
    194       # destination of the .y.c rule in the Makefile.  Divert the
    195       # output of all other files to a temporary file so we can
    196       # compare them to existing versions.
    197       if test $from != $parser; then
    198         realtarget=$target
    199         target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
    200       fi
    201 
    202       # Munge "#line" or "#" directives.  Don't let the resulting
    203       # debug information point at an absolute srcdir.  Use the real
    204       # output file name, not yy.lex.c for instance.  Adjust the
    205       # include guards too.
    206       sed -e "/^#/!b"                           \
    207           -e "s|$input_rx|$input_sub_rx|"       \
    208           -e "$sed_fix_filenames"               \
    209           -e "$sed_fix_header_guards"           \
    210         "$from" >"$target" || ret=$?
    211 
    212       # Check whether files must be updated.
    213       if test "$from" != "$parser"; then
     155      # We do not want to overwrite a header file if it hasn't
     156      # changed.  This avoid useless recompilations.  However the
     157      # parser itself (the first file) should always be updated,
     158      # because it is the destination of the .y.c rule in the
     159      # Makefile.  Divert the output of all other files to a temporary
     160      # file so we can compare them to existing versions.
     161      if test $first = no; then
     162        realtarget="$target"
     163        target="tmp-`echo $target | sed s/.*[\\/]//g`"
     164      fi
     165      # Edit out `#line' or `#' directives.
     166      #
     167      # We don't want the resulting debug information to point at
     168      # an absolute srcdir; it is better for it to just mention the
     169      # .y file with no path.
     170      #
     171      # We want to use the real output file name, not yy.lex.c for
     172      # instance.
     173      #
     174      # We want the include guards to be adjusted too.
     175      FROM=`echo "$from" | sed \
     176            -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
     177            -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
     178      TARGET=`echo "$2" | sed \
     179            -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
     180            -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
     181
     182      sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
     183          -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
     184
     185      # Check whether header files must be updated.
     186      if test $first = no; then
    214187        if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
    215           echo "$to is unchanged"
     188          echo "$2" is unchanged
    216189          rm -f "$target"
    217190        else
    218           echo "updating $to"
     191          echo updating "$2"
    219192          mv -f "$target" "$realtarget"
    220193        fi
    221194      fi
    222195    else
    223       # A missing file is only an error for the parser.  This is a
    224       # blatant hack to let us support using "yacc -d".  If -d is not
    225       # specified, don't fail when the header file is "missing".
    226       if test "$from" = "$parser"; then
     196      # A missing file is only an error for the first file.  This
     197      # is a blatant hack to let us support using "yacc -d".  If -d
     198      # is not specified, we don't want an error when the header
     199      # file is "missing".
     200      if test $first = yes; then
    227201        ret=1
    228202      fi
    229203    fi
     204    shift
     205    shift
     206    first=no
    230207  done
     208else
     209  ret=$?
    231210fi
    232211
Note: See TracChangeset for help on using the changeset viewer.