genman revision 1.6
11.1Sroy#!/bin/sh 21.6Schristos# $NetBSD: genman,v 1.6 2024/04/05 22:30:18 christos Exp $ 31.1Sroy 41.5Sroy# Copyright (c) 2009, 2013 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 variable tables for terminfo.5 from our source files. 311.1Sroy 321.3Sroyset -e 331.1Sroy: ${TOOL_SED:=sed} 341.1Sroy: ${TOOL_SORT:=sort} 351.1Sroy 361.1SroyTERMM=${1:-terminfo.5.in} 371.1SroyTERMH=${2:-term.h} 381.1SroyTERMC=${3:-termcap_map.c} 391.1Sroy 401.1Sroygentab() 411.1Sroy{ 421.1Sroy local ti=$1 tc=$2 tab=$3 431.1Sroy 441.1Sroy # Generate a list of long names and codes 451.1Sroy $TOOL_SED -n \ 461.1Sroy -e "s/#define t_\([^(]*\).*>$tab\[TICODE_\([^]]*\).*/\1 \2/p" \ 471.6Schristos $ti | $TOOL_SORT | while read name code _; do 481.4Schristos cap=$($TOOL_SED -ne "s/.*{ \"\(..\)\", TICODE_$code }.*/\1/p" \ 491.4Schristos $tc | head -n 1) 501.5Sroy desc=$($TOOL_SED -ne "s/ \* $name\: \(.*\)/\1/p" $ti) 511.6Schristos printf '.It "\\&%s" Ta Sy "\\&%s" Ta Sy "\\&%s" Ta "\\&%s"\n' "${name}" "${code}" "${cap}" "${desc}" 521.1Sroy done 531.1Sroy} 541.1Sroy 551.4Schristosboolcaps=$(gentab $TERMH $TERMC flags) 561.4Schristosnumcaps=$(gentab $TERMH $TERMC nums) 571.4Schristosstrcaps=$(gentab $TERMH $TERMC strs) 581.1Sroy 591.6Schristosprintf '.\\"DO NOT EDIT\n' 601.6Schristosprintf '.\\"Automatically generated from termcap.5.in\n' 611.6Schristosprintf '.\\"\n' 621.2Sroy 631.1Sroywhile read -r line; do 641.1Sroy case "$line" in 651.6Schristos "@BOOLCAPS@") printf '%s\n' "${boolcaps}";; 661.6Schristos "@NUMCAPS@") printf '%s\n' "${numcaps}";; 671.6Schristos "@STRCAPS@") printf '%s\n' "${strcaps}";; 681.6Schristos *) printf '%s\n' "${line}";; 691.1Sroy esac 701.1Sroydone <$TERMM 71