genhash revision 1.1
11.1Sroy#!/bin/sh 21.1Sroy# $NetBSD: genhash,v 1.1 2010/02/03 15:16:32 roy Exp $ 31.1Sroy 41.1Sroy# Copyright (c) 2009 The NetBSD Foundation, Inc. 51.1Sroy# 61.1Sroy# This code is derived from software contributed to The NetBSD Foundation 71.1Sroy# by Roy Marples. 81.1Sroy# 91.1Sroy# Redistribution and use in source and binary forms, with or without 101.1Sroy# modification, are permitted provided that the following conditions 111.1Sroy# are met: 121.1Sroy# 1. Redistributions of source code must retain the above copyright 131.1Sroy# notice, this list of conditions and the following disclaimer. 141.1Sroy# 2. Redistributions in binary form must reproduce the above copyright 151.1Sroy# notice, this list of conditions and the following disclaimer in the 161.1Sroy# documentation and/or other materials provided with the distribution. 171.1Sroy# 181.1Sroy# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 191.1Sroy# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 201.1Sroy# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 211.1Sroy# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 221.1Sroy# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 231.1Sroy# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241.1Sroy# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251.1Sroy# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261.1Sroy# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 271.1Sroy# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 281.1Sroy 291.1Sroy 301.1Sroy# Generate string and hash tables for our terminfo strings in term.h 311.1Sroy# We don't expose the hash or tables directly, but instead via functions. 321.1Sroy# This allows use to freely change how we hash or store our string tables 331.1Sroy# in the future. 341.1Sroy 351.1Sroy: ${TOOL_AWK:=awk} 361.1Sroy: ${TOOL_NBPERF:=nbperf} 371.1Sroy: ${TOOL_SED:=sed} 381.1Sroy 391.1SroyTERMH=${1:-term.h} 401.1Sroy 411.1Sroygenent() 421.1Sroy{ 431.1Sroy local name=$1 NAME=$2 len= 441.1Sroy 451.1Sroy # Calculate the maximum word length plus terminator 461.1Sroy len=`$TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 471.1Sroy -e 's/.*TICODE_\([^,]*\).*/\1X/' $TERMH | \ 481.1Sroy $TOOL_AWK 'BEGIN {L=0} {if (length($1)>L) L=length($1)} END {print L}'` 491.1Sroy 501.1Sroy echo 511.1Sroy echo "static const char _ti_${name}ids[][${len}] = {" 521.1Sroy $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 531.1Sroy -e 's/.*TICODE_\([^,]*\).*/ "\1",/' $TERMH 541.1Sroy echo "};" 551.1Sroy echo 561.1Sroy $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 571.1Sroy -e 's/.*TICODE_\([^,]*\).*/\1/' $TERMH | \ 581.1Sroy $TOOL_NBPERF -sn _ti_${name}hash; 591.1Sroy 601.1Sroy cat <<EOF 611.1Sroy 621.1Sroyconst char * 631.1Sroy_ti_${name}id(ssize_t idx) 641.1Sroy{ 651.1Sroy 661.1Sroy if ((size_t)idx > __arraycount(_ti_${name}ids)) 671.1Sroy return NULL; 681.1Sroy return _ti_${name}ids[idx]; 691.1Sroy} 701.1Sroy 711.1Sroyssize_t 721.1Sroy_ti_${name}index(const char *key) 731.1Sroy{ 741.1Sroy uint32_t idx; 751.1Sroy 761.1Sroy idx = _ti_${name}hash((const unsigned char *)key, strlen(key)); 771.1Sroy if (idx > __arraycount(_ti_${name}ids) || 781.1Sroy strcmp(key, _ti_${name}ids[idx]) != 0) 791.1Sroy return -1; 801.1Sroy return idx; 811.1Sroy} 821.1SroyEOF 831.1Sroy} 841.1Sroy 851.1Sroycat <<EOF 861.1Sroy/* \$NetBSD\$ */ 871.1Sroy/* DO NOT EDIT 881.1Sroy * Automatically generated from term.h */ 891.1Sroy 901.1Sroy#include <sys/cdefs.h> 911.1Sroy__RCSID("\$NetBSD: genhash,v 1.1 2010/02/03 15:16:32 roy Exp $"); 921.1Sroy 931.1Sroy#include <sys/types.h> 941.1Sroy 951.1Sroy#include <stdlib.h> 961.1Sroy#include <string.h> 971.1Sroy#include <term_private.h> 981.1Sroy#include <term.h> 991.1SroyEOF 1001.1Sroy 1011.1Sroygenent flag FLAG 1021.1Sroygenent num NUM 1031.1Sroygenent str STR 104