1*d90bee97SLionel Sambuc#!/bin/sh - 2*d90bee97SLionel Sambuc# $NetBSD: mktokens,v 1.12 2008/10/25 22:18:15 apb Exp $ 3*d90bee97SLionel Sambuc# 4*d90bee97SLionel Sambuc# Copyright (c) 1991, 1993 5*d90bee97SLionel Sambuc# The Regents of the University of California. All rights reserved. 6*d90bee97SLionel Sambuc# 7*d90bee97SLionel Sambuc# This code is derived from software contributed to Berkeley by 8*d90bee97SLionel Sambuc# Kenneth Almquist. 9*d90bee97SLionel Sambuc# 10*d90bee97SLionel Sambuc# Redistribution and use in source and binary forms, with or without 11*d90bee97SLionel Sambuc# modification, are permitted provided that the following conditions 12*d90bee97SLionel Sambuc# are met: 13*d90bee97SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 14*d90bee97SLionel Sambuc# notice, this list of conditions and the following disclaimer. 15*d90bee97SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 16*d90bee97SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 17*d90bee97SLionel Sambuc# documentation and/or other materials provided with the distribution. 18*d90bee97SLionel Sambuc# 3. Neither the name of the University nor the names of its contributors 19*d90bee97SLionel Sambuc# may be used to endorse or promote products derived from this software 20*d90bee97SLionel Sambuc# without specific prior written permission. 21*d90bee97SLionel Sambuc# 22*d90bee97SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*d90bee97SLionel Sambuc# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*d90bee97SLionel Sambuc# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*d90bee97SLionel Sambuc# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*d90bee97SLionel Sambuc# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*d90bee97SLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*d90bee97SLionel Sambuc# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*d90bee97SLionel Sambuc# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*d90bee97SLionel Sambuc# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*d90bee97SLionel Sambuc# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*d90bee97SLionel Sambuc# SUCH DAMAGE. 33*d90bee97SLionel Sambuc# 34*d90bee97SLionel Sambuc# @(#)mktokens 8.1 (Berkeley) 5/31/93 35*d90bee97SLionel Sambuc 36*d90bee97SLionel Sambuc: ${AWK:=awk} 37*d90bee97SLionel Sambuc: ${SED:=sed} 38*d90bee97SLionel Sambuc 39*d90bee97SLionel Sambuc# The following is a list of tokens. The second column is nonzero if the 40*d90bee97SLionel Sambuc# token marks the end of a list. The third column is the name to print in 41*d90bee97SLionel Sambuc# error messages. 42*d90bee97SLionel Sambuc 43*d90bee97SLionel Sambuccat > /tmp/ka$$ <<\! 44*d90bee97SLionel SambucTEOF 1 end of file 45*d90bee97SLionel SambucTNL 0 newline 46*d90bee97SLionel SambucTSEMI 0 ";" 47*d90bee97SLionel SambucTBACKGND 0 "&" 48*d90bee97SLionel SambucTAND 0 "&&" 49*d90bee97SLionel SambucTOR 0 "||" 50*d90bee97SLionel SambucTPIPE 0 "|" 51*d90bee97SLionel SambucTLP 0 "(" 52*d90bee97SLionel SambucTRP 1 ")" 53*d90bee97SLionel SambucTENDCASE 1 ";;" 54*d90bee97SLionel SambucTENDBQUOTE 1 "`" 55*d90bee97SLionel SambucTREDIR 0 redirection 56*d90bee97SLionel SambucTWORD 0 word 57*d90bee97SLionel SambucTIF 0 "if" 58*d90bee97SLionel SambucTTHEN 1 "then" 59*d90bee97SLionel SambucTELSE 1 "else" 60*d90bee97SLionel SambucTELIF 1 "elif" 61*d90bee97SLionel SambucTFI 1 "fi" 62*d90bee97SLionel SambucTWHILE 0 "while" 63*d90bee97SLionel SambucTUNTIL 0 "until" 64*d90bee97SLionel SambucTFOR 0 "for" 65*d90bee97SLionel SambucTDO 1 "do" 66*d90bee97SLionel SambucTDONE 1 "done" 67*d90bee97SLionel SambucTBEGIN 0 "{" 68*d90bee97SLionel SambucTEND 1 "}" 69*d90bee97SLionel SambucTCASE 0 "case" 70*d90bee97SLionel SambucTESAC 1 "esac" 71*d90bee97SLionel SambucTNOT 0 "!" 72*d90bee97SLionel Sambuc! 73*d90bee97SLionel Sambucnl=`wc -l /tmp/ka$$` 74*d90bee97SLionel Sambucexec > token.h 75*d90bee97SLionel Sambuc${AWK} '{print "#define " $1 " " NR-1}' /tmp/ka$$ 76*d90bee97SLionel Sambucecho ' 77*d90bee97SLionel Sambuc/* Array indicating which tokens mark the end of a list */ 78*d90bee97SLionel Sambucconst char tokendlist[] = {' 79*d90bee97SLionel Sambuc${AWK} '{print "\t" $2 ","}' /tmp/ka$$ 80*d90bee97SLionel Sambucecho '}; 81*d90bee97SLionel Sambuc 82*d90bee97SLionel Sambucconst char *const tokname[] = {' 83*d90bee97SLionel Sambuc${SED} -e 's/"/\\"/g' \ 84*d90bee97SLionel Sambuc -e 's/[^ ]*[ ][ ]*[^ ]*[ ][ ]*\(.*\)/ "\1",/' \ 85*d90bee97SLionel Sambuc /tmp/ka$$ 86*d90bee97SLionel Sambucecho '}; 87*d90bee97SLionel Sambuc' 88*d90bee97SLionel Sambuc${SED} 's/"//g' /tmp/ka$$ | ${AWK} ' 89*d90bee97SLionel Sambuc/TIF/{print "#define KWDOFFSET " NR-1; print ""; 90*d90bee97SLionel Sambuc print "const char *const parsekwd[] = {"} 91*d90bee97SLionel Sambuc/TIF/,/neverfound/{print " \"" $3 "\","}' 92*d90bee97SLionel Sambucecho ' 0 93*d90bee97SLionel Sambuc};' 94*d90bee97SLionel Sambuc 95*d90bee97SLionel Sambucrm /tmp/ka$$ 96