~ubuntu-branches/ubuntu/wily/acsccid/wily

« back to all changes in this revision

Viewing changes to config/ylwrap

  • Committer: Package Import Robot
  • Author(s): Godfrey Chung
  • Date: 2013-09-02 11:46:30 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130902114630-lujvp61jp7wacnwv
Tags: 1.0.5-1
* New upstream release.
* Updated Standards-Version to 3.9.4.
* Updated debian/copyright.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /bin/sh
2
2
# ylwrap - wrapper for lex/yacc invocations.
3
3
 
4
 
scriptversion=2011-08-25.18; # UTC
 
4
scriptversion=2012-12-21.17; # UTC
5
5
 
6
 
# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
7
 
# 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
 
6
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
8
7
#
9
8
# Written by Tom Tromey <tromey@cygnus.com>.
10
9
#
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)
67
98
# The input.
68
99
input="$1"
69
100
shift
 
101
# We'll later need for a correct munging of "#line" directives.
 
102
input_sub_rx=`get_dirname "$input" | quote_for_sed`
70
103
case "$input" in
71
104
  [\\/]* | ?:[\\/]*)
72
105
    # Absolute path; do nothing.
76
109
    input="`pwd`/$input"
77
110
    ;;
78
111
esac
79
 
 
80
 
pairlist=
 
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
 
81
135
while test "$#" -ne 0; do
82
136
  if test "$1" = "--"; then
83
137
    shift
84
138
    break
85
139
  fi
86
 
  pairlist="$pairlist $1"
87
 
  shift
 
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;"
88
153
done
89
154
 
90
155
# The program to run.
115
180
ret=$?
116
181
 
117
182
if test $ret -eq 0; then
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
 
183
  for from in *
 
184
  do
 
185
    to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
147
186
    if test -f "$from"; then
148
187
      # If $2 is an absolute path name, then just use that,
149
 
      # otherwise prepend `../'.
150
 
      case "$2" in
151
 
        [\\/]* | ?:[\\/]*) target="$2";;
152
 
        *) target="../$2";;
 
188
      # otherwise prepend '../'.
 
189
      case $to in
 
190
        [\\/]* | ?:[\\/]*) target=$to;;
 
191
        *) target="../$to";;
153
192
      esac
154
193
 
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
 
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
162
200
        realtarget="$target"
163
 
        target="tmp-`echo $target | sed s/.*[\\/]//g`"
 
201
        target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
164
202
      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
 
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
187
216
        if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
188
 
          echo "$2" is unchanged
 
217
          echo "$to is unchanged"
189
218
          rm -f "$target"
190
219
        else
191
 
          echo updating "$2"
 
220
          echo "updating $to"
192
221
          mv -f "$target" "$realtarget"
193
222
        fi
194
223
      fi
195
224
    else
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
 
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
201
229
        ret=1
202
230
      fi
203
231
    fi
204
 
    shift
205
 
    shift
206
 
    first=no
207
232
  done
208
 
else
209
 
  ret=$?
210
233
fi
211
234
 
212
235
# Remove the directory.