genhash revision 1.7
11.1Sroy#!/bin/sh 21.7Schristos# $NetBSD: genhash,v 1.7 2010/10/12 12:57:51 christos 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.7Schristos len=$($TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 481.1Sroy -e 's/.*TICODE_\([^,]*\).*/\1X/' $TERMH | \ 491.7Schristos $TOOL_AWK \ 501.7Schristos 'BEGIN {L=0} {if (length($1)>L) L=length($1)} END {print L}') 511.1Sroy 521.1Sroy echo 531.1Sroy echo "static const char _ti_${name}ids[][${len}] = {" 541.1Sroy $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 551.1Sroy -e 's/.*TICODE_\([^,]*\).*/ "\1",/' $TERMH 561.1Sroy echo "};" 571.1Sroy echo 581.1Sroy $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \ 591.1Sroy -e 's/.*TICODE_\([^,]*\).*/\1/' $TERMH | \ 601.1Sroy $TOOL_NBPERF -sn _ti_${name}hash; 611.1Sroy 621.1Sroy cat <<EOF 631.1Sroy 641.1Sroyconst char * 651.1Sroy_ti_${name}id(ssize_t idx) 661.1Sroy{ 671.1Sroy 681.1Sroy if ((size_t)idx > __arraycount(_ti_${name}ids)) 691.1Sroy return NULL; 701.1Sroy return _ti_${name}ids[idx]; 711.1Sroy} 721.1Sroy 731.1Sroyssize_t 741.1Sroy_ti_${name}index(const char *key) 751.1Sroy{ 761.1Sroy uint32_t idx; 771.1Sroy 781.1Sroy idx = _ti_${name}hash((const unsigned char *)key, strlen(key)); 791.1Sroy if (idx > __arraycount(_ti_${name}ids) || 801.1Sroy strcmp(key, _ti_${name}ids[idx]) != 0) 811.1Sroy return -1; 821.1Sroy return idx; 831.1Sroy} 841.1SroyEOF 851.1Sroy} 861.1Sroy 871.1Sroycat <<EOF 881.1Sroy/* \$NetBSD\$ */ 891.1Sroy/* DO NOT EDIT 901.1Sroy * Automatically generated from term.h */ 911.1Sroy 921.5Sroy#if HAVE_NBTOOL_CONFIG_H 931.5Sroy#include "nbtool_config.h" 941.5Sroy#endif 951.5Sroy 961.1Sroy#include <sys/cdefs.h> 971.7Schristos__RCSID("\$NetBSD: genhash,v 1.7 2010/10/12 12:57:51 christos Exp $"); 981.1Sroy 991.4Sroy#include <stdint.h> 1001.1Sroy#include <stdlib.h> 1011.1Sroy#include <string.h> 1021.1Sroy#include <term_private.h> 1031.1Sroy#include <term.h> 1041.1SroyEOF 1051.1Sroy 1061.1Sroygenent flag FLAG 1071.1Sroygenent num NUM 1081.1Sroygenent str STR 109