mktokens revision 222182
1251875Speter#!/bin/sh - 2251875Speter 3251875Speter#- 4251875Speter# Copyright (c) 1991, 1993 5251875Speter# The Regents of the University of California. All rights reserved. 6251875Speter# 7251875Speter# This code is derived from software contributed to Berkeley by 8251875Speter# Kenneth Almquist. 9251875Speter# 10251875Speter# Redistribution and use in source and binary forms, with or without 11251875Speter# modification, are permitted provided that the following conditions 12251875Speter# are met: 13251875Speter# 1. Redistributions of source code must retain the above copyright 14251875Speter# notice, this list of conditions and the following disclaimer. 15251875Speter# 2. Redistributions in binary form must reproduce the above copyright 16251875Speter# notice, this list of conditions and the following disclaimer in the 17251875Speter# documentation and/or other materials provided with the distribution. 18251875Speter# 4. Neither the name of the University nor the names of its contributors 19251875Speter# may be used to endorse or promote products derived from this software 20251875Speter# without specific prior written permission. 21251875Speter# 22251875Speter# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23251875Speter# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24251875Speter# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25251875Speter# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26251875Speter# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27251875Speter# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28362181Sdim# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29251875Speter# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30251875Speter# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31251875Speter# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32251875Speter# SUCH DAMAGE. 33251875Speter# 34251875Speter# @(#)mktokens 8.1 (Berkeley) 5/31/93 35251875Speter# $FreeBSD: head/bin/sh/mktokens 222182 2011-05-22 15:24:56Z jilles $ 36251875Speter 37251875Speter# The following is a list of tokens. The second column is nonzero if the 38251875Speter# token marks the end of a list. The third column is the name to print in 39253734Speter# error messages. 40253734Speter 41253734Spetertemp=`/usr/bin/mktemp -t ka` 42253734Spetercat > $temp <<\! 43253734SpeterTEOF 1 end of file 44253734SpeterTNL 0 newline 45251875SpeterTSEMI 0 ";" 46251875SpeterTBACKGND 0 "&" 47251875SpeterTAND 0 "&&" 48251875SpeterTOR 0 "||" 49251875SpeterTPIPE 0 "|" 50251875SpeterTLP 0 "(" 51251875SpeterTRP 1 ")" 52251875SpeterTENDCASE 1 ";;" 53251875SpeterTREDIR 0 redirection 54251875SpeterTWORD 0 word 55251875SpeterTIF 0 "if" 56251875SpeterTTHEN 1 "then" 57251875SpeterTELSE 1 "else" 58251875SpeterTELIF 1 "elif" 59251875SpeterTFI 1 "fi" 60251875SpeterTWHILE 0 "while" 61251875SpeterTUNTIL 0 "until" 62251875SpeterTFOR 0 "for" 63362181SdimTDO 1 "do" 64251875SpeterTDONE 1 "done" 65362181SdimTBEGIN 0 "{" 66251875SpeterTEND 1 "}" 67251875SpeterTCASE 0 "case" 68251875SpeterTESAC 1 "esac" 69251875SpeterTNOT 0 "!" 70251875Speter! 71251875Speternl=`wc -l $temp` 72251875Speterexec > token.h 73251875Speterawk '{print "#define " $1 " " NR-1}' $temp 74251875Speterecho ' 75251875Speter/* Array indicating which tokens mark the end of a list */ 76251875Speterconst char tokendlist[] = {' 77251875Speterawk '{print "\t" $2 ","}' $temp 78251875Speterecho '}; 79251875Speter 80251875Speterconst char *const tokname[] = {' 81251875Spetersed -e 's/"/\\"/g' \ 82251875Speter -e 's/[^ ]*[ ][ ]*[^ ]*[ ][ ]*\(.*\)/ "\1",/' \ 83251875Speter $temp 84251875Speterecho '}; 85251875Speter' 86251875Spetersed 's/"//g' $temp | awk ' 87251875Speter/TIF/{print "#define KWDOFFSET " NR-1; print ""; print "const char *const parsekwd[] = {"} 88251875Speter/TIF/,/neverfound/{print " \"" $3 "\","}' 89251875Speterecho ' 0 90251875Speter};' 91251875Speter 92251875Speterrm $temp 93251875Speter