Print this page
XXX Remove nawk(1)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/tools/scripts/tigen.sh
+++ new/usr/src/cmd/mdb/tools/scripts/tigen.sh
1 1 #!/bin/ksh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License, Version 1.0 only
7 7 # (the "License"). You may not use this file except in compliance
8 8 # with the License.
9 9 #
10 10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 11 # or http://www.opensolaris.org/os/licensing.
12 12 # See the License for the specific language governing permissions
13 13 # and limitations under the License.
14 14 #
15 15 # When distributing Covered Code, include this CDDL HEADER in each
16 16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 17 # If applicable, add the following below this CDDL HEADER, with the
18 18 # fields enclosed by brackets "[]" replaced with your own identifying
19 19 # information: Portions Copyright [yyyy] [name of copyright owner]
20 20 #
21 21 # CDDL HEADER END
22 22 #
23 23 #
24 24 # Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 25 # Use is subject to license terms.
26 26 #
27 27 #
28 28
29 29 #
30 30 # Terminal Info Generator
31 31 #
32 32 # This script generates a static terminfo database for use by mdb. For each
33 33 # of the terminal properties used by mdb_termio.c, this script uses tput(1)
34 34 # to determine the value of the given attribute for each specified terminal
35 35 # type. The script produces an ANSI-C source file which contains a static
36 36 # array for each terminal type storing the properties. An additional array
37 37 # is then declared containing a list of the terminal types and pointers to
38 38 # the previous arrays. Finally, source code for several terminfo routines
39 39 # are included that simply access the arrays and return the saved properties.
40 40 #
41 41
42 42 PATH=/usr/bin; export PATH
43 43
44 44 PROGNAME=$(basename "$0")
45 45
46 46 usage()
↓ open down ↓ |
46 lines elided |
↑ open up ↑ |
47 47 {
48 48 echo "Usage: $PROGNAME -s skel -t termio [-v] term ..." >&2
49 49 exit 2
50 50 }
51 51
52 52 extract_section()
53 53 {
54 54 typeset skel="$1"
55 55 typeset secname="$2"
56 56
57 - nawk <$skel -v name=$secname -v skel=$skel '
57 + /usr/xpg4/bin/awk <$skel -v name=$secname -v skel=$skel '
58 58 /\/\* [^ ]* [^ ]* \*\// && $3 == name {
59 59 if ($2 == "BEGIN") {
60 60 printing = 1;
61 61 printf("# %d \"%s\"\n", NR + 1, skel);
62 62 } else {
63 63 printing = 0;
64 64 }
65 65 next;
66 66 }
67 67
68 68 printing != 0 { print; }
69 69 '
70 70 }
71 71
72 72 verbose=false
73 73 termio_c=
74 74 terminfo_skel=
75 75
76 76 while getopts s:t:v name ; do
77 77 case $name in
78 78 v)
79 79 verbose=true
80 80 ;;
81 81 s)
82 82 terminfo_skel=$OPTARG
83 83 ;;
84 84 t)
85 85 termio_c=$OPTARG
86 86 ;;
87 87 ?)
88 88 usage
89 89 ;;
90 90 esac
91 91 done
92 92 shift $(($OPTIND - 1))
93 93
94 94 [[ -z "$terminfo_skel" || -z "$termio_c" || $# -eq 0 ]] && usage
95 95
96 96 termlist=$*
97 97 for term in $termlist; do
98 98 tput -T $term init >/dev/null 2>&1
99 99 if [ $? -ne 0 ]; then
100 100 echo "`basename $0`: invalid terminal -- $term" >& 2
101 101 exit 1
102 102 fi
103 103 done
104 104
105 105 # Extract the prologue from the skeleton
106 106 extract_section $terminfo_skel PROLOGUE
107 107
108 108 #
109 109 # For each terminal in the terminal list, produce a property definition array
110 110 # listing each property we need in mdb_termio.c and its current value.
111 111 #
112 112 for term in $termlist; do
113 113 #
114 114 # We don't want the compiler to blame the skeleton if it doesn't like
115 115 # the array we generate here, so point the finger elsewhere
116 116 #
117 117 echo "# 1 \"dynamic $term data from tigen\""
118 118
119 119 cterm=$(echo "$term" |tr '-' '_')
120 120
121 121 $verbose && echo "loading terminfo for $term ... \c" >& 2
122 122 echo "static const termio_attr_t ${cterm}_attrs[] = {"
123 123
124 124 sed -n '/termio_attrs\[\] = /,/^}/p' $termio_c | \
125 125 sed -n \ 's/{ "\([a-z0-9]*\)", \([A-Z_]*\),.*/\1 \2/p' | \
126 126 while read attr type; do
127 127
128 128 case "$type" in
129 129 TIO_ATTR_REQSTR|TIO_ATTR_STR)
130 130 data="\"`tput -T $term $attr | od -bv |
131 131 sed 's/^[0-9]*//;s/ /\\\\\\\\/g;/^\$/d'`\""
132 132 [ "$data" = '""' ] && data=NULL
133 133 ;;
134 134 TIO_ATTR_BOOL)
135 135 tput -T $term $attr
136 136 data=`expr 1 - $?`
137 137 ;;
138 138 TIO_ATTR_INT)
139 139 data=`tput -T $term $attr`
140 140 ;;
141 141 *)
142 142 echo "`basename $0`: unknown type for $attr: $type" >& 2
143 143 exit 1
144 144 esac
145 145 echo "\t{ \"$attr\", $type, (void *)$data },"
146 146 done
147 147
148 148 echo "\t{ NULL, NULL, NULL }"
149 149 echo "};\n"
150 150
151 151 $verbose && echo "done" >& 2
152 152 done
153 153
154 154 #
155 155 # For each terminal in the terminal list, produce an entry in the terminal
156 156 # database array linking this terminal to its terminfo property array.
157 157 #
158 158 echo "# 1 \"dynamic array from tigen\""
159 159 echo "static const termio_desc_t termio_db[] = {"
160 160 for term in $termlist; do
161 161 cterm=$(echo "$term" |tr '-' '_')
162 162 echo "\t{ \"$term\", ${cterm}_attrs },"
163 163 done
164 164 echo "\t{ NULL, NULL }\n};"
165 165
166 166 extract_section $terminfo_skel EPILOGUE
167 167
168 168 exit 0
↓ open down ↓ |
101 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX