[BACK]Return to genhash CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libterminfo

Annotation of src/lib/libterminfo/genhash, Revision 1.9

1.1       roy         1: #!/bin/sh
1.9     ! roy         2: # $NetBSD: genhash,v 1.8 2011/11/02 12:09:25 roy Exp $
1.1       roy         3:
1.8       roy         4: # Copyright (c) 2009, 2011 The NetBSD Foundation, Inc.
1.1       roy         5: #
                      6: # This code is derived from software contributed to The NetBSD Foundation
                      7: # by Roy Marples.
                      8: #
                      9: # Redistribution and use in source and binary forms, with or without
                     10: # modification, are permitted provided that the following conditions
                     11: # are met:
                     12: # 1. Redistributions of source code must retain the above copyright
                     13: #    notice, this list of conditions and the following disclaimer.
                     14: # 2. Redistributions in binary form must reproduce the above copyright
                     15: #    notice, this list of conditions and the following disclaimer in the
                     16: #    documentation and/or other materials provided with the distribution.
                     17: #
                     18: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     19: # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     20: # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     21: # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     22: # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     23: # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     24: # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     25: # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     26: # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     27: # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     28:
                     29:
                     30: # Generate string and hash tables for our terminfo strings in term.h
                     31: # We don't expose the hash or tables directly, but instead via functions.
1.2       snj        32: # This allows us to freely change how we hash or store our string tables
1.1       roy        33: # in the future.
                     34:
1.6       roy        35: set -e
1.1       roy        36: : ${TOOL_AWK:=awk}
                     37: : ${TOOL_NBPERF:=nbperf}
                     38: : ${TOOL_SED:=sed}
                     39:
                     40: TERMH=${1:-term.h}
                     41:
                     42: genent()
                     43: {
                     44:        local name=$1 NAME=$2 len=
                     45:
                     46:        # Calculate the maximum word length plus terminator
1.7       christos   47:        len=$($TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
1.1       roy        48:             -e 's/.*TICODE_\([^,]*\).*/\1X/' $TERMH | \
1.7       christos   49:            $TOOL_AWK \
                     50:            'BEGIN {L=0} {if (length($1)>L) L=length($1)} END {print L}')
1.1       roy        51:
                     52:        echo
                     53:        echo "static const char _ti_${name}ids[][${len}] = {"
                     54:        $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
                     55:             -e 's/.*TICODE_\([^,]*\).*/        "\1",/' $TERMH
                     56:        echo "};"
                     57:        echo
                     58:        $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
                     59:            -e 's/.*TICODE_\([^,]*\).*/\1/' $TERMH | \
1.8       roy        60:            $TOOL_NBPERF -p -s -n _ti_${name}hash;
1.1       roy        61:
                     62:        cat <<EOF
                     63:
                     64: const char *
                     65: _ti_${name}id(ssize_t idx)
                     66: {
                     67:
1.9     ! roy        68:        if ((size_t)idx >= __arraycount(_ti_${name}ids))
1.1       roy        69:                return NULL;
                     70:        return _ti_${name}ids[idx];
                     71: }
                     72:
                     73: ssize_t
                     74: _ti_${name}index(const char *key)
                     75: {
                     76:        uint32_t idx;
                     77:
                     78:        idx = _ti_${name}hash((const unsigned char *)key, strlen(key));
1.9     ! roy        79:        if (idx >= __arraycount(_ti_${name}ids) ||
1.1       roy        80:            strcmp(key, _ti_${name}ids[idx]) != 0)
                     81:                return -1;
                     82:        return idx;
                     83: }
                     84: EOF
                     85: }
                     86:
                     87: cat <<EOF
                     88: /* DO NOT EDIT
                     89:  * Automatically generated from term.h */
                     90:
1.5       roy        91: #if HAVE_NBTOOL_CONFIG_H
                     92: #include "nbtool_config.h"
                     93: #endif
                     94:
1.4       roy        95: #include <stdint.h>
1.1       roy        96: #include <stdlib.h>
                     97: #include <string.h>
                     98: #include <term_private.h>
                     99: #include <term.h>
                    100: EOF
                    101:
                    102: genent flag FLAG
                    103: genent num NUM
                    104: genent str STR

CVSweb <webmaster@jp.NetBSD.org>