xref: /openbsd-src/lib/libcurses/MKterminfo.sh (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1*c7ef0cfcSnicm#!/bin/sh
2*c7ef0cfcSnicm# $Id: MKterminfo.sh,v 1.1 2023/10/17 09:52:08 nicm Exp $
3*c7ef0cfcSnicm#
4*c7ef0cfcSnicm# MKterminfo.sh -- generate terminfo.5 from Caps tabular data
5*c7ef0cfcSnicm#
6*c7ef0cfcSnicm#***************************************************************************
7*c7ef0cfcSnicm# Copyright 2018-2020,2022 Thomas E. Dickey                                *
8*c7ef0cfcSnicm# Copyright 1998-2003,2017 Free Software Foundation, Inc.                  *
9*c7ef0cfcSnicm#                                                                          *
10*c7ef0cfcSnicm# Permission is hereby granted, free of charge, to any person obtaining a  *
11*c7ef0cfcSnicm# copy of this software and associated documentation files (the            *
12*c7ef0cfcSnicm# "Software"), to deal in the Software without restriction, including      *
13*c7ef0cfcSnicm# without limitation the rights to use, copy, modify, merge, publish,      *
14*c7ef0cfcSnicm# distribute, distribute with modifications, sublicense, and/or sell       *
15*c7ef0cfcSnicm# copies of the Software, and to permit persons to whom the Software is    *
16*c7ef0cfcSnicm# furnished to do so, subject to the following conditions:                 *
17*c7ef0cfcSnicm#                                                                          *
18*c7ef0cfcSnicm# The above copyright notice and this permission notice shall be included  *
19*c7ef0cfcSnicm# in all copies or substantial portions of the Software.                   *
20*c7ef0cfcSnicm#                                                                          *
21*c7ef0cfcSnicm# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
22*c7ef0cfcSnicm# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
23*c7ef0cfcSnicm# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
24*c7ef0cfcSnicm# IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
25*c7ef0cfcSnicm# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
26*c7ef0cfcSnicm# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
27*c7ef0cfcSnicm# THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
28*c7ef0cfcSnicm#                                                                          *
29*c7ef0cfcSnicm# Except as contained in this notice, the name(s) of the above copyright   *
30*c7ef0cfcSnicm# holders shall not be used in advertising or otherwise to promote the     *
31*c7ef0cfcSnicm# sale, use or other dealings in this Software without prior written       *
32*c7ef0cfcSnicm# authorization.                                                           *
33*c7ef0cfcSnicm#***************************************************************************
34*c7ef0cfcSnicm#
35*c7ef0cfcSnicm# This script takes terminfo.head and terminfo.tail and splices in between
36*c7ef0cfcSnicm# them a table derived from the Caps data file.  Besides avoiding having
37*c7ef0cfcSnicm# the docs fall out of sync with the table, this also lets us set up tbl
38*c7ef0cfcSnicm# commands for better formatting of the table.
39*c7ef0cfcSnicm#
40*c7ef0cfcSnicm# NOTE: The s in this script really are control characters.  It translates
41*c7ef0cfcSnicm#  to \n because I couldn't get used to inserting linefeeds directly.  There
42*c7ef0cfcSnicm# had better be no s in the table source text.
43*c7ef0cfcSnicm#
44*c7ef0cfcSnicm# keep the order independent of locale:
45*c7ef0cfcSnicmif test "${LANGUAGE+set}"    = set; then LANGUAGE=C;    export LANGUAGE;    fi
46*c7ef0cfcSnicmif test "${LANG+set}"        = set; then LANG=C;        export LANG;        fi
47*c7ef0cfcSnicmif test "${LC_ALL+set}"      = set; then LC_ALL=C;      export LC_ALL;      fi
48*c7ef0cfcSnicmif test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
49*c7ef0cfcSnicmif test "${LC_CTYPE+set}"    = set; then LC_CTYPE=C;    export LC_CTYPE;    fi
50*c7ef0cfcSnicmif test "${LC_COLLATE+set}"  = set; then LC_COLLATE=C;  export LC_COLLATE;  fi
51*c7ef0cfcSnicm
52*c7ef0cfcSnicm#
53*c7ef0cfcSnicmhead="$1"
54*c7ef0cfcSnicmshift 1
55*c7ef0cfcSnicmcaps=
56*c7ef0cfcSnicmwhile test $# -gt 1
57*c7ef0cfcSnicmdo
58*c7ef0cfcSnicm	caps="$caps $1"
59*c7ef0cfcSnicm	shift 1
60*c7ef0cfcSnicmdone
61*c7ef0cfcSnicmtail="$1"
62*c7ef0cfcSnicmcat <<EOF
63*c7ef0cfcSnicm'\\" t
64*c7ef0cfcSnicm.\\" DO NOT EDIT THIS FILE BY HAND!
65*c7ef0cfcSnicm.\\" It is generated from terminfo.head, $caps, and terminfo.tail.
66*c7ef0cfcSnicm.\\"
67*c7ef0cfcSnicm.\\" Note: this must be run through tbl before nroff.
68*c7ef0cfcSnicm.\\" The magic cookie on the first line triggers this under some man programs.
69*c7ef0cfcSnicmEOF
70*c7ef0cfcSnicmcat "$head"
71*c7ef0cfcSnicm
72*c7ef0cfcSnicmtemp=temp$$
73*c7ef0cfcSnicmsorted=sorted$$
74*c7ef0cfcSnicmunsorted=unsorted$$
75*c7ef0cfcSnicmtrap 'code=$?; rm -f $sorted $temp $unsorted; exit $code' EXIT HUP INT QUIT TERM
76*c7ef0cfcSnicmrm -f $sorted $temp $unsorted
77*c7ef0cfcSnicm
78*c7ef0cfcSnicmcat $caps | sed -n "\
79*c7ef0cfcSnicm/%%-STOP-HERE-%%/q
80*c7ef0cfcSnicm/^#%center/s, expand,,
81*c7ef0cfcSnicm/^#%lw25/s, lw6 , lw7 ,
82*c7ef0cfcSnicm/^#%/s/#%//p
83*c7ef0cfcSnicm/^#/d
84*c7ef0cfcSnicms/[	][	]*/	/g
85*c7ef0cfcSnicms/$/T}/
86*c7ef0cfcSnicms/	[A-Z0-9_()\-][A-Z0-9_()\-]*	[0-9\-][0-9\-]*	[Y\-][B\-][C\-][G\-][EK\-]\**	/	T{/
87*c7ef0cfcSnicms/	bool	/	/p
88*c7ef0cfcSnicms/	num	/	/p
89*c7ef0cfcSnicms/	str	/	/p
90*c7ef0cfcSnicm" |sed -e 's/^$/../' | tr "\134" "\006" >$unsorted
91*c7ef0cfcSnicm
92*c7ef0cfcSnicmrm -f $sorted
93*c7ef0cfcSnicmrm -f $temp
94*c7ef0cfcSnicmsaved=no
95*c7ef0cfcSnicmwhile true
96*c7ef0cfcSnicmdo
97*c7ef0cfcSnicm	data=
98*c7ef0cfcSnicm	read data
99*c7ef0cfcSnicm	test -z "$data" && break
100*c7ef0cfcSnicm	case "$data" in #(vi
101*c7ef0cfcSnicm	**) #(vi
102*c7ef0cfcSnicm		echo "$data" >>$temp
103*c7ef0cfcSnicm		saved=yes
104*c7ef0cfcSnicm		;;
105*c7ef0cfcSnicm	*)
106*c7ef0cfcSnicm		if test $saved = yes ; then
107*c7ef0cfcSnicm			saved=no
108*c7ef0cfcSnicm			sort $temp >>$sorted
109*c7ef0cfcSnicm			rm -f $temp
110*c7ef0cfcSnicm		fi
111*c7ef0cfcSnicm		echo "$data" >>$sorted
112*c7ef0cfcSnicm		;;
113*c7ef0cfcSnicm	esac
114*c7ef0cfcSnicmdone <$unsorted
115*c7ef0cfcSnicmtest $saved = yes && sort $temp >>$sorted
116*c7ef0cfcSnicm
117*c7ef0cfcSnicmsed -e 's/^\.\.$//' $sorted | tr "\005\006" "\012\134"
118*c7ef0cfcSnicm
119*c7ef0cfcSnicmsed	-e '/^center expand;/s, expand,,' \
120*c7ef0cfcSnicm	-e '/^\.TS/,/^\\/s, lw[1-9][0-9]*\., l.,' \
121*c7ef0cfcSnicm	"$tail"
122