genhash revision 1.6
11.1Sroy#!/bin/sh 21.6Sroy# $NetBSD: genhash,v 1.6 2010/03/03 12:09:49 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.2Ssnj# This allows us to freely change how we hash or store our string tables 331.1Sroy# in the future. 341.1Sroy 351.6Sroyset -e 361.1Sroy: ${TOOL_AWK:=awk} 371.1Sroy: ${TOOL_NBPERF:=nbperf} 381.1Sroy: ${TOOL_SED:=sed} 391.1Sroy 401.1SroyTERMH=${1:-term.h} 411.1Sroy 421.1Sroygenent() 431.1Sroy{ 441.1Sroy local name=$1 NAME=$2 len= 451.1Sroy 461.1Sroy # Calculate the maximum word length plus terminator 471.1Sroy len=`$TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 481.1Sroy -e 's/.*TICODE_\([^,]*\).*/\1X/' $TERMH | \ 491.1Sroy $TOOL_AWK 'BEGIN {L=0} {if (length($1)>L) L=length($1)} END {print L}'` 501.1Sroy 511.1Sroy echo 521.1Sroy echo "static const char _ti_${name}ids[][${len}] = {" 531.1Sroy $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 541.1Sroy -e 's/.*TICODE_\([^,]*\).*/ "\1",/' $TERMH 551.1Sroy echo "};" 561.1Sroy echo 571.1Sroy $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 581.1Sroy -e 's/.*TICODE_\([^,]*\).*/\1/' $TERMH | \ 591.1Sroy $TOOL_NBPERF -sn _ti_${name}hash; 601.1Sroy 611.1Sroy cat <<EOF 621.1Sroy 631.1Sroyconst char * 641.1Sroy_ti_${name}id(ssize_t idx) 651.1Sroy{ 661.1Sroy 671.1Sroy if ((size_t)idx > __arraycount(_ti_${name}ids)) 681.1Sroy return NULL; 691.1Sroy return _ti_${name}ids[idx]; 701.1Sroy} 711.1Sroy 721.1Sroyssize_t 731.1Sroy_ti_${name}index(const char *key) 741.1Sroy{ 751.1Sroy uint32_t idx; 761.1Sroy 771.1Sroy idx = _ti_${name}hash((const unsigned char *)key, strlen(key)); 781.1Sroy if (idx > __arraycount(_ti_${name}ids) || 791.1Sroy strcmp(key, _ti_${name}ids[idx]) != 0) 801.1Sroy return -1; 811.1Sroy return idx; 821.1Sroy} 831.1SroyEOF 841.1Sroy} 851.1Sroy 861.1Sroycat <<EOF 871.1Sroy/* \$NetBSD\$ */ 881.1Sroy/* DO NOT EDIT 891.1Sroy * Automatically generated from term.h */ 901.1Sroy 911.5Sroy#if HAVE_NBTOOL_CONFIG_H 921.5Sroy#include "nbtool_config.h" 931.5Sroy#endif 941.5Sroy 951.1Sroy#include <sys/cdefs.h> 961.6Sroy__RCSID("\$NetBSD: genhash,v 1.6 2010/03/03 12:09:49 roy Exp $"); 971.1Sroy 981.4Sroy#include <stdint.h> 991.1Sroy#include <stdlib.h> 1001.1Sroy#include <string.h> 1011.1Sroy#include <term_private.h> 1021.1Sroy#include <term.h> 1031.1SroyEOF 1041.1Sroy 1051.1Sroygenent flag FLAG 1061.1Sroygenent num NUM 1071.1Sroygenent str STR 108