dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / tools / scripts / tigen.sh
blob8ed511defb93f0cbe5f05486a91509ae7cbcb873
1 #!/bin/ksh
3 # CDDL HEADER START
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
8 # with the License.
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]
21 # CDDL HEADER END
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")
46 usage()
48 echo "Usage: $PROGNAME -s skel -t termio [-v] term ..." >&2
49 exit 2
52 extract_section()
54 typeset skel="$1"
55 typeset secname="$2"
57 nawk <$skel -v name=$secname -v skel=$skel '
58 /\/\* [^ ]* [^ ]* \*\// && $3 == name {
59 if ($2 == "BEGIN") {
60 printing = 1;
61 printf("# %d \"%s\"\n", NR + 1, skel);
62 } else {
63 printing = 0;
65 next;
68 printing != 0 { print; }
72 verbose=false
73 termio_c=
74 terminfo_skel=
76 while getopts s:t:v name ; do
77 case $name in
79 verbose=true
82 terminfo_skel=$OPTARG
85 termio_c=$OPTARG
88 usage
90 esac
91 done
92 shift $(($OPTIND - 1))
94 [[ -z "$terminfo_skel" || -z "$termio_c" || $# -eq 0 ]] && usage
96 termlist=$*
97 for term in $termlist; do
98 tput -T $term init >/dev/null 2>&1
99 if [ $? -ne 0 ]; then
100 echo "`basename $0`: invalid terminal -- $term" >& 2
101 exit 1
103 done
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
128 case "$type" in
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
134 TIO_ATTR_BOOL)
135 tput -T $term $attr
136 data=`expr 1 - $?`
138 TIO_ATTR_INT)
139 data=`tput -T $term $attr`
142 echo "`basename $0`: unknown type for $attr: $type" >& 2
143 exit 1
144 esac
145 echo "\t{ \"$attr\", $type, (void *)$data },"
146 done
148 echo "\t{ NULL, 0, NULL }"
149 echo "};\n"
151 $verbose && echo "done" >& 2
152 done
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 },"
163 done
164 echo "\t{ NULL, NULL }\n};"
166 extract_section $terminfo_skel EPILOGUE
168 exit 0