5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
30 # Terminal Info Generator
32 # This script generates a static terminfo database for use by mdb. For each
33 # of the terminal properties used by mdb_termio.c, this script uses tput(1)
34 # to determine the value of the given attribute for each specified terminal
35 # type. The script produces an ANSI-C source file which contains a static
36 # array for each terminal type storing the properties. An additional array
37 # is then declared containing a list of the terminal types and pointers to
38 # the previous arrays. Finally, source code for several terminfo routines
39 # are included that simply access the arrays and return the saved properties.
42 PATH
=/usr
/bin
; export PATH
44 PROGNAME
=$
(basename "$0")
48 echo "Usage: $PROGNAME -s skel -t termio [-v] term ..." >&2
57 nawk
<$skel -v name
=$secname -v skel
=$skel '
58 /\/\* [^ ]* [^ ]* \*\// && $3 == name {
61 printf("# %d \"%s\"\n", NR + 1, skel);
68 printing != 0 { print; }
76 while getopts s
:t
:v name
; do
92 shift $
(($OPTIND - 1))
94 [[ -z "$terminfo_skel" ||
-z "$termio_c" ||
$# -eq 0 ]] && usage
97 for term
in $termlist; do
98 tput -T $term init
>/dev
/null
2>&1
100 echo "`basename $0`: invalid terminal -- $term" >& 2
105 # Extract the prologue from the skeleton
106 extract_section
$terminfo_skel PROLOGUE
109 # For each terminal in the terminal list, produce a property definition array
110 # listing each property we need in mdb_termio.c and its current value.
112 for term
in $termlist; do
114 # We don't want the compiler to blame the skeleton if it doesn't like
115 # the array we generate here, so point the finger elsewhere
117 echo "# 1 \"dynamic $term data from tigen\""
119 cterm
=$
(echo "$term" |
tr '-' '_')
121 $verbose && echo "loading terminfo for $term ... \c" >& 2
122 echo "static const termio_attr_t ${cterm}_attrs[] = {"
124 sed -n '/termio_attrs\[\] = /,/^}/p' $termio_c | \
125 sed -n \
's/{ "\([a-z0-9]*\)", \([A-Z_]*\),.*/\1 \2/p' | \
126 while read attr
type; do
129 TIO_ATTR_REQSTR|TIO_ATTR_STR
)
130 data
="\"`tput -T $term $attr | od -bv |
131 sed 's/^[0-9]*//;s/ \\000//g;s/ /\\\\\\\\/g;/^\$/d'`\""
132 [ "$data" = '""' ] && data
=NULL
139 data
=`tput -T $term $attr`
142 echo "`basename $0`: unknown type for $attr: $type" >& 2
145 echo "\t{ \"$attr\", $type, (void *)$data },"
148 echo "\t{ NULL, 0, NULL }"
151 $verbose && echo "done" >& 2
155 # For each terminal in the terminal list, produce an entry in the terminal
156 # database array linking this terminal to its terminfo property array.
158 echo "# 1 \"dynamic array from tigen\""
159 echo "static const termio_desc_t termio_db[] = {"
160 for term
in $termlist; do
161 cterm
=$
(echo "$term" |
tr '-' '_')
162 echo "\t{ \"$term\", ${cterm}_attrs },"
164 echo "\t{ NULL, NULL }\n};"
166 extract_section
$terminfo_skel EPILOGUE