1dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#!/bin/sh -
2dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#	$NetBSD: mktokens,v 1.10 2003/08/22 11:22:23 agc Exp $
3dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#
4dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# Copyright (c) 1991, 1993
5dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#	The Regents of the University of California.  All rights reserved.
6dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#
7dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# This code is derived from software contributed to Berkeley by
8dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# Kenneth Almquist.
9dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#
10dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# Redistribution and use in source and binary forms, with or without
11dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# modification, are permitted provided that the following conditions
12dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# are met:
13dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# 1. Redistributions of source code must retain the above copyright
14dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#    notice, this list of conditions and the following disclaimer.
15dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# 2. Redistributions in binary form must reproduce the above copyright
16dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#    notice, this list of conditions and the following disclaimer in the
17dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#    documentation and/or other materials provided with the distribution.
18dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# 3. Neither the name of the University nor the names of its contributors
19dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#    may be used to endorse or promote products derived from this software
20dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#    without specific prior written permission.
21dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#
22dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# SUCH DAMAGE.
33dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#
34dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#	@(#)mktokens	8.1 (Berkeley) 5/31/93
35dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
36dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# The following is a list of tokens.  The second column is nonzero if the
37dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# token marks the end of a list.  The third column is the name to print in
38dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project# error messages.
39dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
40dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectcat > /tmp/ka$$ <<\!
41dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTEOF	1	end of file
42dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTNL	0	newline
43dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTSEMI	0	";"
44dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTBACKGND 0	"&"
45dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTAND	0	"&&"
46dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTOR	0	"||"
47dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTPIPE	0	"|"
48dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTLP	0	"("
49dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTRP	1	")"
50dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTENDCASE 1	";;"
51dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTENDBQUOTE 1	"`"
52dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTREDIR	0	redirection
53dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTWORD	0	word
54dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTIF	0	"if"
55dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTTHEN	1	"then"
56dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTELSE	1	"else"
57dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTELIF	1	"elif"
58dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTFI	1	"fi"
59dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTWHILE	0	"while"
60dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTUNTIL	0	"until"
61dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTFOR	0	"for"
62dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTDO	1	"do"
63dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTDONE	1	"done"
64dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTBEGIN	0	"{"
65dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTEND	1	"}"
66dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTCASE	0	"case"
67dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTESAC	1	"esac"
68dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectTNOT	0	"!"
69dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project!
70dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectnl=`wc -l /tmp/ka$$`
71dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectexec > token.h
72dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectawk '{print "#define " $1 " " NR-1}' /tmp/ka$$
73dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectecho '
74dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* Array indicating which tokens mark the end of a list */
75dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char tokendlist[] = {'
76dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectawk '{print "\t" $2 ","}' /tmp/ka$$
77dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectecho '};
78dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
79dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char *const tokname[] = {'
80dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectsed -e 's/"/\\"/g' \
81dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    -e 's/[^	 ]*[	 ][	 ]*[^	 ]*[	 ][	 ]*\(.*\)/	"\1",/' \
82dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    /tmp/ka$$
83dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectecho '};
84dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project'
85dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectsed 's/"//g' /tmp/ka$$ | awk '
86dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/TIF/{print "#define KWDOFFSET " NR-1; print ""; 
87dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project      print "const char *const parsekwd[] = {"}
88dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/TIF/,/neverfound/{print "	\"" $3 "\","}'
89dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectecho '	0
90dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};'
91dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
92dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectrm /tmp/ka$$
93