annotate kdiff3/admin/ylwrap @ 69:8febbfb1148c

KDiff3 0.9.89
author joachim99
date Mon, 10 Apr 2006 08:40:51 +0000
parents 53b8ecbce0cb
children
rev   line source
joachim99@2 1 #! /bin/sh
joachim99@2 2 # ylwrap - wrapper for lex/yacc invocations.
joachim99@69 3
joachim99@69 4 scriptversion=2005-05-14.22
joachim99@69 5
joachim99@69 6 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005
joachim99@69 7 # Free Software Foundation, Inc.
joachim99@69 8 #
joachim99@2 9 # Written by Tom Tromey <tromey@cygnus.com>.
joachim99@2 10 #
joachim99@2 11 # This program is free software; you can redistribute it and/or modify
joachim99@2 12 # it under the terms of the GNU General Public License as published by
joachim99@2 13 # the Free Software Foundation; either version 2, or (at your option)
joachim99@2 14 # any later version.
joachim99@2 15 #
joachim99@2 16 # This program is distributed in the hope that it will be useful,
joachim99@2 17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
joachim99@2 18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
joachim99@2 19 # GNU General Public License for more details.
joachim99@2 20 #
joachim99@2 21 # You should have received a copy of the GNU General Public License
joachim99@2 22 # along with this program; if not, write to the Free Software
joachim99@69 23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
joachim99@69 24 # 02110-1301, USA.
joachim99@2 25
joachim99@2 26 # As a special exception to the GNU General Public License, if you
joachim99@2 27 # distribute this file as part of a program that contains a
joachim99@2 28 # configuration script generated by Autoconf, you may include it under
joachim99@2 29 # the same distribution terms that you use for the rest of that program.
joachim99@2 30
joachim99@69 31 # This file is maintained in Automake, please report
joachim99@69 32 # bugs to <bug-automake@gnu.org> or send patches to
joachim99@69 33 # <automake-patches@gnu.org>.
joachim99@69 34
joachim99@69 35 case "$1" in
joachim99@69 36 '')
joachim99@69 37 echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
joachim99@69 38 exit 1
joachim99@69 39 ;;
joachim99@69 40 --basedir)
joachim99@69 41 basedir=$2
joachim99@69 42 shift 2
joachim99@69 43 ;;
joachim99@69 44 -h|--h*)
joachim99@69 45 cat <<\EOF
joachim99@69 46 Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
joachim99@69 47
joachim99@69 48 Wrapper for lex/yacc invocations, renaming files as desired.
joachim99@69 49
joachim99@69 50 INPUT is the input file
joachim99@69 51 OUTPUT is one file PROG generates
joachim99@69 52 DESIRED is the file we actually want instead of OUTPUT
joachim99@69 53 PROGRAM is program to run
joachim99@69 54 ARGS are passed to PROG
joachim99@69 55
joachim99@69 56 Any number of OUTPUT,DESIRED pairs may be used.
joachim99@69 57
joachim99@69 58 Report bugs to <bug-automake@gnu.org>.
joachim99@69 59 EOF
joachim99@69 60 exit $?
joachim99@69 61 ;;
joachim99@69 62 -v|--v*)
joachim99@69 63 echo "ylwrap $scriptversion"
joachim99@69 64 exit $?
joachim99@69 65 ;;
joachim99@69 66 esac
joachim99@69 67
joachim99@2 68
joachim99@2 69 # The input.
joachim99@2 70 input="$1"
joachim99@2 71 shift
joachim99@2 72 case "$input" in
joachim99@69 73 [\\/]* | ?:[\\/]*)
joachim99@2 74 # Absolute path; do nothing.
joachim99@2 75 ;;
joachim99@69 76 *)
joachim99@2 77 # Relative path. Make it absolute.
joachim99@2 78 input="`pwd`/$input"
joachim99@2 79 ;;
joachim99@2 80 esac
joachim99@2 81
joachim99@2 82 pairlist=
joachim99@2 83 while test "$#" -ne 0; do
joachim99@69 84 if test "$1" = "--"; then
joachim99@69 85 shift
joachim99@69 86 break
joachim99@69 87 fi
joachim99@69 88 pairlist="$pairlist $1"
joachim99@69 89 shift
joachim99@2 90 done
joachim99@2 91
joachim99@2 92 # The program to run.
joachim99@2 93 prog="$1"
joachim99@2 94 shift
joachim99@2 95 # Make any relative path in $prog absolute.
joachim99@2 96 case "$prog" in
joachim99@69 97 [\\/]* | ?:[\\/]*) ;;
joachim99@69 98 *[\\/]*) prog="`pwd`/$prog" ;;
joachim99@2 99 esac
joachim99@2 100
joachim99@2 101 # FIXME: add hostname here for parallel makes that run commands on
joachim99@2 102 # other machines. But that might take us over the 14-char limit.
joachim99@2 103 dirname=ylwrap$$
joachim99@2 104 trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
joachim99@2 105 mkdir $dirname || exit 1
joachim99@2 106
joachim99@2 107 cd $dirname
joachim99@2 108
joachim99@69 109 case $# in
joachim99@69 110 0) $prog "$input" ;;
joachim99@69 111 *) $prog "$@" "$input" ;;
joachim99@69 112 esac
joachim99@69 113 ret=$?
joachim99@2 114
joachim99@69 115 if test $ret -eq 0; then
joachim99@69 116 set X $pairlist
joachim99@69 117 shift
joachim99@69 118 first=yes
joachim99@69 119 # Since DOS filename conventions don't allow two dots,
joachim99@69 120 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
joachim99@69 121 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
joachim99@69 122 y_tab_nodot="no"
joachim99@69 123 if test -f y_tab.c || test -f y_tab.h; then
joachim99@69 124 y_tab_nodot="yes"
joachim99@69 125 fi
joachim99@2 126
joachim99@69 127 # The directory holding the input.
joachim99@69 128 input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
joachim99@69 129 # Quote $INPUT_DIR so we can use it in a regexp.
joachim99@69 130 # FIXME: really we should care about more than `.' and `\'.
joachim99@69 131 input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
joachim99@69 132
joachim99@69 133 while test "$#" -ne 0; do
joachim99@69 134 from="$1"
joachim99@69 135 # Handle y_tab.c and y_tab.h output by DOS
joachim99@69 136 if test $y_tab_nodot = "yes"; then
joachim99@69 137 if test $from = "y.tab.c"; then
joachim99@69 138 from="y_tab.c"
joachim99@69 139 else
joachim99@69 140 if test $from = "y.tab.h"; then
joachim99@69 141 from="y_tab.h"
joachim99@69 142 fi
joachim99@2 143 fi
joachim99@69 144 fi
joachim99@69 145 if test -f "$from"; then
joachim99@69 146 # If $2 is an absolute path name, then just use that,
joachim99@69 147 # otherwise prepend `../'.
joachim99@69 148 case "$2" in
joachim99@69 149 [\\/]* | ?:[\\/]*) target="$2";;
joachim99@69 150 *) target="../$2";;
joachim99@69 151 esac
joachim99@2 152
joachim99@69 153 # We do not want to overwrite a header file if it hasn't
joachim99@69 154 # changed. This avoid useless recompilations. However the
joachim99@69 155 # parser itself (the first file) should always be updated,
joachim99@69 156 # because it is the destination of the .y.c rule in the
joachim99@69 157 # Makefile. Divert the output of all other files to a temporary
joachim99@69 158 # file so we can compare them to existing versions.
joachim99@69 159 if test $first = no; then
joachim99@69 160 realtarget="$target"
joachim99@69 161 target="tmp-`echo $target | sed s/.*[\\/]//g`"
joachim99@2 162 fi
joachim99@69 163 # Edit out `#line' or `#' directives.
joachim99@69 164 #
joachim99@69 165 # We don't want the resulting debug information to point at
joachim99@69 166 # an absolute srcdir; it is better for it to just mention the
joachim99@69 167 # .y file with no path.
joachim99@69 168 #
joachim99@69 169 # We want to use the real output file name, not yy.lex.c for
joachim99@69 170 # instance.
joachim99@69 171 #
joachim99@69 172 # We want the include guards to be adjusted too.
joachim99@69 173 FROM=`echo "$from" | sed \
joachim99@69 174 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
joachim99@69 175 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
joachim99@69 176 TARGET=`echo "$2" | sed \
joachim99@69 177 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
joachim99@69 178 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
joachim99@69 179
joachim99@69 180 sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
joachim99@69 181 -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
joachim99@69 182
joachim99@69 183 # Check whether header files must be updated.
joachim99@69 184 if test $first = no; then
joachim99@69 185 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
joachim99@69 186 echo "$2" is unchanged
joachim99@69 187 rm -f "$target"
joachim99@69 188 else
joachim99@69 189 echo updating "$2"
joachim99@69 190 mv -f "$target" "$realtarget"
joachim99@69 191 fi
joachim99@69 192 fi
joachim99@69 193 else
joachim99@69 194 # A missing file is only an error for the first file. This
joachim99@69 195 # is a blatant hack to let us support using "yacc -d". If -d
joachim99@69 196 # is not specified, we don't want an error when the header
joachim99@69 197 # file is "missing".
joachim99@69 198 if test $first = yes; then
joachim99@69 199 ret=1
joachim99@69 200 fi
joachim99@69 201 fi
joachim99@69 202 shift
joachim99@69 203 shift
joachim99@69 204 first=no
joachim99@69 205 done
joachim99@2 206 else
joachim99@69 207 ret=$?
joachim99@2 208 fi
joachim99@2 209
joachim99@2 210 # Remove the directory.
joachim99@2 211 cd ..
joachim99@2 212 rm -rf $dirname
joachim99@2 213
joachim99@69 214 exit $ret
joachim99@69 215
joachim99@69 216 # Local Variables:
joachim99@69 217 # mode: shell-script
joachim99@69 218 # sh-indentation: 2
joachim99@69 219 # eval: (add-hook 'write-file-hooks 'time-stamp)
joachim99@69 220 # time-stamp-start: "scriptversion="
joachim99@69 221 # time-stamp-format: "%:y-%02m-%02d.%02H"
joachim99@69 222 # time-stamp-end: "$"
joachim99@69 223 # End: