185720Sjake#!/bin/sh 285720Sjake# $Id: MKterminfo.sh,v 1.20 2024/01/13 20:37:40 tom Exp $ 385720Sjake# 485720Sjake# MKterminfo.sh -- generate terminfo.5 from Caps tabular data 585720Sjake# 685720Sjake#*************************************************************************** 785720Sjake# Copyright 2018-2020,2022 Thomas E. Dickey * 885720Sjake# Copyright 1998-2003,2017 Free Software Foundation, Inc. * 985720Sjake# * 1085720Sjake# Permission is hereby granted, free of charge, to any person obtaining a * 1185720Sjake# copy of this software and associated documentation files (the * 1285720Sjake# "Software"), to deal in the Software without restriction, including * 1385720Sjake# without limitation the rights to use, copy, modify, merge, publish, * 1485720Sjake# distribute, distribute with modifications, sublicense, and/or sell * 1585720Sjake# copies of the Software, and to permit persons to whom the Software is * 1685720Sjake# furnished to do so, subject to the following conditions: * 1785720Sjake# * 1885720Sjake# The above copyright notice and this permission notice shall be included * 1985720Sjake# in all copies or substantial portions of the Software. * 2085720Sjake# * 2185720Sjake# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 2285720Sjake# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 2385720Sjake# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 2485720Sjake# IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 2585720Sjake# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2685720Sjake# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2785720Sjake# THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2885720Sjake# * 29124139Sobrien# Except as contained in this notice, the name(s) of the above copyright * 30124139Sobrien# holders shall not be used in advertising or otherwise to promote the * 31124139Sobrien# sale, use or other dealings in this Software without prior written * 3285720Sjake# authorization. * 3385720Sjake#*************************************************************************** 3485720Sjake# 3585720Sjake# This script takes terminfo.head and terminfo.tail and splices in between 3685720Sjake# them a table derived from the Caps data file. Besides avoiding having 3791107Sjake# the docs fall out of sync with the table, this also lets us set up tbl 3891107Sjake# commands for better formatting of the table. 3985720Sjake# 4085720Sjake# NOTE: The s in this script really are control characters. It translates 4185720Sjake# to \n because I couldn't get used to inserting linefeeds directly. There 4297445Sjake# had better be no s in the table source text. 4397445Sjake# 4491139Sjake# keep the order independent of locale: 4591139Sjakeif test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi 4691139Sjakeif test "${LANG+set}" = set; then LANG=C; export LANG; fi 4791139Sjakeif test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi 4885720Sjakeif test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi 4985720Sjakeif test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi 5085720Sjakeif test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi 5185720Sjake 5285720Sjake# 5385720Sjakehead="$1" 5485720Sjakeshift 1 5585720Sjakecaps= 5685720Sjakewhile test $# -gt 1 5785720Sjakedo 5885720Sjake caps="$caps $1" 5985720Sjake shift 1 6085720Sjakedone 6185720Sjaketail="$1" 6285720Sjakecat <<EOF 6385720Sjake'\\" t 6498472Speter.\\" DO NOT EDIT THIS FILE BY HAND! 6598472Speter.\\" It is generated from terminfo.head, $caps, and terminfo.tail. 6685720Sjake.\\" 6785720Sjake.\\" Note: this must be run through tbl before nroff. 6885720Sjake.\\" The magic cookie on the first line triggers this under some man programs. 6985720SjakeEOF 7085720Sjakecat "$head" 7185720Sjake 72122499Sjaketemp=temp$$ 73122499Sjakesorted=sorted$$ 7485720Sjakeunsorted=unsorted$$ 7585720Sjaketrap 'code=$?; rm -f $sorted $temp $unsorted; exit $code' EXIT HUP INT QUIT TERM 7685720Sjakerm -f $sorted $temp $unsorted 7785720Sjake 7885720Sjakecat $caps | sed -n "\ 7985720Sjake/%%-STOP-HERE-%%/q 8085720Sjake/^#%center/s, expand,, 8185720Sjake/^#%lw25/s, lw6 , lw7 , 8285720Sjake/^#%/s/#%//p 8385720Sjake/^#/d 8485720Sjakes/[ ][ ]*/ /g 8585720Sjakes/$/T}/ 8685720Sjakes/ [A-Z0-9_()\-][A-Z0-9_()\-]* [0-9\-][0-9\-]* [Y\-][B\-][C\-][G\-][EK\-]\** / T{\\ 8785720Sjake.ad l\ 8885720Sjake/ 8985720Sjakes/ bool / /p 9085720Sjakes/ num / /p 9185720Sjakes/ str / /p 9285720Sjake" |sed -e 's/^$/../' | tr "\134" "\006" >$unsorted 9385720Sjake 9485720Sjakerm -f $sorted 9585720Sjakerm -f $temp 9685720Sjakesaved=no 9785720Sjakewhile true 9885720Sjakedo 9985720Sjake data= 10085720Sjake read data 10185720Sjake test -z "$data" && break 10285720Sjake case "$data" in #(vi 10385720Sjake **) #(vi 10485720Sjake echo "$data" >>$temp 10585720Sjake saved=yes 10685720Sjake ;; 10785720Sjake *) 10885720Sjake if test $saved = yes ; then 10985720Sjake saved=no 11085720Sjake sort $temp >>$sorted 11185720Sjake rm -f $temp 11285720Sjake fi 11385720Sjake echo "$data" >>$sorted 11485720Sjake ;; 11585720Sjake esac 11685720Sjakedone <$unsorted 11785720Sjaketest $saved = yes && sort $temp >>$sorted 11885720Sjake 11985720Sjakesed -e 's/^\.\.$//' $sorted | tr "\005\006" "\012\134" 12085720Sjake 12185720Sjakesed -e '/^center expand;/s, expand,,' \ 12285720Sjake -e '/^\.TS/,/^\\/s, lw[1-9][0-9]*\., l.,' \ 12385720Sjake "$tail" 12485720Sjake