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