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