mktokens revision 17987
11556Srgrimes#!/bin/sh -
21556Srgrimes#
31556Srgrimes# Copyright (c) 1991, 1993
41556Srgrimes#	The Regents of the University of California.  All rights reserved.
51556Srgrimes#
61556Srgrimes# This code is derived from software contributed to Berkeley by
71556Srgrimes# Kenneth Almquist.
81556Srgrimes#
91556Srgrimes# Redistribution and use in source and binary forms, with or without
101556Srgrimes# modification, are permitted provided that the following conditions
111556Srgrimes# are met:
121556Srgrimes# 1. Redistributions of source code must retain the above copyright
131556Srgrimes#    notice, this list of conditions and the following disclaimer.
141556Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
151556Srgrimes#    notice, this list of conditions and the following disclaimer in the
161556Srgrimes#    documentation and/or other materials provided with the distribution.
171556Srgrimes# 3. All advertising materials mentioning features or use of this software
181556Srgrimes#    must display the following acknowledgement:
191556Srgrimes#	This product includes software developed by the University of
201556Srgrimes#	California, Berkeley and its contributors.
211556Srgrimes# 4. Neither the name of the University nor the names of its contributors
221556Srgrimes#    may be used to endorse or promote products derived from this software
231556Srgrimes#    without specific prior written permission.
241556Srgrimes#
251556Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
261556Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
271556Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
281556Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291556Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
301556Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
311556Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
321556Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
331556Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3436150Scharnier# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3536150Scharnier# SUCH DAMAGE.
3636150Scharnier#
371556Srgrimes#	@(#)mktokens	8.1 (Berkeley) 5/31/93
3899110Sobrien#	$Id: mktokens,v 1.2 1994/09/24 02:57:58 davidg Exp $
3999110Sobrien
401556Srgrimes# The following is a list of tokens.  The second column is nonzero if the
41100437Stjr# token marks the end of a list.  The third column is the name to print in
4217987Speter# error messages.
43102576Skeramida
4417987Spetercat > /tmp/ka$$ <<\!
45153091SstefanfTEOF	1	end of file
4645266ScracauerTNL	0	newline
4753891ScracauerTSEMI	0	";"
4817987SpeterTBACKGND 0	"&"
491556SrgrimesTAND	0	"&&"
501556SrgrimesTOR	0	"||"
511556SrgrimesTPIPE	0	"|"
521556SrgrimesTLP	0	"("
531556SrgrimesTRP	1	")"
541556SrgrimesTENDCASE 1	";;"
551556SrgrimesTENDBQUOTE 1	"`"
561556SrgrimesTREDIR	0	redirection
571556SrgrimesTWORD	0	word
581556SrgrimesTIF	0	"if"
591556SrgrimesTTHEN	1	"then"
601556SrgrimesTELSE	1	"else"
611556SrgrimesTELIF	1	"elif"
621556SrgrimesTFI	1	"fi"
631556SrgrimesTWHILE	0	"while"
641556SrgrimesTUNTIL	0	"until"
651556SrgrimesTFOR	0	"for"
661556SrgrimesTDO	1	"do"
671556SrgrimesTDONE	1	"done"
681556SrgrimesTBEGIN	0	"{"
691556SrgrimesTEND	1	"}"
7017987SpeterTCASE	0	"case"
711556SrgrimesTESAC	1	"esac"
7217987SpeterTNOT	0	"!"
731556Srgrimes!
7417987Speternl=`wc -l /tmp/ka$$`
751556Srgrimesexec > token.h
761556Srgrimesawk '{print "#define " $1 " " NR-1}' /tmp/ka$$
771556Srgrimesecho '
781556Srgrimes/* Array indicating which tokens mark the end of a list */
791556Srgrimesconst char tokendlist[] = {'
801556Srgrimesawk '{print "\t" $2 ","}' /tmp/ka$$
811556Srgrimesecho '};
821556Srgrimes
831556Srgrimeschar *const tokname[] = {'
841556Srgrimessed -e 's/"/\\"/g' \
851556Srgrimes    -e 's/[^	 ]*[	 ][	 ]*[^	 ]*[	 ][	 ]*\(.*\)/	"\1",/' \
861556Srgrimes    /tmp/ka$$
871556Srgrimesecho '};
881556Srgrimes'
891556Srgrimessed 's/"//g' /tmp/ka$$ | awk '
901556Srgrimes/TIF/{print "#define KWDOFFSET " NR-1; print ""; print "char *const parsekwd[] = {"}
9117987Speter/TIF/,/neverfound/{print "	\"" $3 "\","}'
921556Srgrimesecho '	0
931556Srgrimes};'
94149933Sstefanf
95149933Sstefanfrm /tmp/ka$$
9690111Simp