xref: /openbsd/usr.bin/yacc/yyfix.sh (revision 443dcd37)
1d8f7465dSmillert#!/bin/sh -
2d8f7465dSmillert#
3*443dcd37Ssobrado#	$OpenBSD: yyfix.sh,v 1.3 2009/06/12 13:33:29 sobrado Exp $
4d8f7465dSmillert# Copyright (c) 1990 The Regents of the University of California.
5d8f7465dSmillert# All rights reserved.
6d8f7465dSmillert#
7d8f7465dSmillert# Redistribution and use in source and binary forms, with or without
8d8f7465dSmillert# modification, are permitted provided that the following conditions
9d8f7465dSmillert# are met:
10d8f7465dSmillert# 1. Redistributions of source code must retain the above copyright
11d8f7465dSmillert#    notice, this list of conditions and the following disclaimer.
12d8f7465dSmillert# 2. Redistributions in binary form must reproduce the above copyright
13d8f7465dSmillert#    notice, this list of conditions and the following disclaimer in the
14d8f7465dSmillert#    documentation and/or other materials provided with the distribution.
15f75387cbSmillert# 3. Neither the name of the University nor the names of its contributors
16d8f7465dSmillert#    may be used to endorse or promote products derived from this software
17d8f7465dSmillert#    without specific prior written permission.
18d8f7465dSmillert#
19d8f7465dSmillert# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20d8f7465dSmillert# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21d8f7465dSmillert# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22d8f7465dSmillert# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23d8f7465dSmillert# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24d8f7465dSmillert# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25d8f7465dSmillert# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26d8f7465dSmillert# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27d8f7465dSmillert# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28d8f7465dSmillert# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29d8f7465dSmillert# SUCH DAMAGE.
30d8f7465dSmillert#
31d8f7465dSmillert#	from: @(#)yyfix.sh	5.2 (Berkeley) 5/12/90
32d8f7465dSmillert#
33d8f7465dSmillertOLDYACC="yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef"
34d8f7465dSmillertNEWYACC="yylhs yylen yydefred yydgoto yysindex yyrindex yygindex \
35d8f7465dSmillert	 yytable yycheck"
36d8f7465dSmillert
37d8f7465dSmillertif [ $# -eq 0 ]; then
38*443dcd37Ssobrado	echo "usage: `basename $0` file [tables]" >&2
39d8f7465dSmillert	exit 1
40d8f7465dSmillertfi
41d8f7465dSmillert
42d8f7465dSmillertfile=$1
43d8f7465dSmillert>$file
44d8f7465dSmillertshift
45d8f7465dSmillert
46d8f7465dSmillertif [ $# -eq 0 ] ; then
47d8f7465dSmillert	if grep yylhs y.tab.c > /dev/null ; then
48d8f7465dSmillert		if grep yyname y.tab.c > /dev/null ; then
49d8f7465dSmillert			NEWYACC="$NEWYACC yyname"
50d8f7465dSmillert		fi
51d8f7465dSmillert		if grep yyrule y.tab.c > /dev/null ; then
52d8f7465dSmillert			NEWYACC="$NEWYACC yyrule"
53d8f7465dSmillert		fi
54d8f7465dSmillert		set $NEWYACC
55d8f7465dSmillert	else
56d8f7465dSmillert		set $OLDYACC
57d8f7465dSmillert	fi
58d8f7465dSmillertfi
59d8f7465dSmillert
60d8f7465dSmillertfor i
61d8f7465dSmillertdo
62d8f7465dSmillerted - y.tab.c << END
63d8f7465dSmillert/^\(.*\)$i[ 	]*\[]/s//extern \1 $i[];\\
64d8f7465dSmillert\1 $i []/
65d8f7465dSmillert.ka
66d8f7465dSmillert/}/kb
67d8f7465dSmillert'br $file
68d8f7465dSmillert'a,.w $file
69d8f7465dSmillert'a,.d
70d8f7465dSmillertw
71d8f7465dSmillertq
72d8f7465dSmillertEND
73d8f7465dSmillertdone
74