libncurses: updated to 6.0
[tomato.git] / release / src / router / libncurses / include / MKkey_defs.sh
blob45a06d0327712443a18648fe338b1c23501f8762
1 #! /bin/sh
2 # $Id: MKkey_defs.sh,v 1.15 2013/03/09 16:32:01 tom Exp $
3 ##############################################################################
4 # Copyright (c) 2001-2003,2013 Free Software Foundation, Inc. #
5 # #
6 # Permission is hereby granted, free of charge, to any person obtaining a #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the #
12 # following conditions: #
13 # #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
16 # #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23 # DEALINGS IN THE SOFTWARE. #
24 # #
25 # Except as contained in this notice, the name(s) of the above copyright #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written #
28 # authorization. #
29 ##############################################################################
31 # MKkey_defs.sh -- generate function-key definitions for curses.h
33 # Author: Thomas E. Dickey 2001
35 # Extract function-key definitions from the Caps file
37 : ${AWK-awk}
38 DATA=${1-Caps}
40 data=data$$
41 pass1=pass1_$$
42 pass2=pass2_$$
43 pass3=pass3_$$
44 pass4=pass4_$$
45 trap 'rm -f $data pass[1234]_$$' 0 1 2 5 15
47 # change repeated tabs (used for readability) to single tabs (needed to make
48 # awk see the right field alignment of the corresponding columns):
49 if sort -k 6 $DATA >$data 2>/dev/null
50 then
51 # POSIX
52 sed -e 's/[ ][ ]*/ /g' < $DATA |sort -n -k 6 >$data
53 elif sort -n +5 $DATA >$data 2>/dev/null
54 then
55 # SunOS (and SVr4, marked as obsolete but still recognized)
56 sed -e 's/[ ][ ]*/ /g' < $DATA |sort -n +5 >$data
57 else
58 echo "Your sort utility is broken. Please install one that works." >&2
59 exit 1
62 # add keys that we generate automatically:
63 cat >>$data <<EOF
64 key_resize kr1 str R1 KEY_RESIZE + ----- Terminal resize event
65 key_event kv1 str V1 KEY_EVENT + ----- We were interrupted by an event
66 EOF
68 THIS=./`basename $0`
69 PARM=./`basename $DATA`
71 cat <<EOF
73 * These definitions were generated by $THIS $PARM
75 EOF
77 # KEY_RESET
78 maxkey=345
80 for pass in 1 2 3 4
83 output=pass${pass}_$$
85 ${AWK-awk} >$output <$data '
86 function print_cols(text,cols) {
87 printf "%s", text
88 len = length(text);
89 while (len < cols) {
90 printf " "
91 len += 8;
94 function decode(keycode) {
95 result = 0;
96 if (substr(keycode, 1, 2) == "0x") {
97 digits="0123456789abcdef";
98 } else if (substr(keycode, 1, 1) == "0") {
99 digits="01234567";
100 } else {
101 digits="0123456789";
103 while (length(keycode) != 0) {
104 digit=substr(keycode, 1, 1);
105 keycode=substr(keycode, 2);
106 result = result * length(digits) + index(digits, digit) - 1;
108 return result;
111 BEGIN {
112 maxkey='$maxkey';
113 pass='$pass';
114 key_max=1;
115 bits=1;
116 while (key_max < maxkey) {
117 bits = bits + 1;
118 key_max = (key_max * 2) + 1;
120 octal_fmt = sprintf ("%%0%do", (bits + 2) / 3 + 1);
123 /^$/ {next;}
124 /^#/ {next;}
125 /^capalias/ {next;}
126 /^infoalias/ {next;}
128 $5 != "-" && $6 != "-" {
129 if ($6 == "+") {
130 if (pass == 1 || pass == 2)
131 next;
132 thiskey=maxkey + 1;
133 } else {
134 if (pass == 3)
135 next;
136 thiskey=decode($6);
138 if (thiskey > maxkey)
139 maxkey = thiskey;
140 if (pass == 2 || pass == 3) {
141 showkey=sprintf(octal_fmt, thiskey);
142 if ($5 == "KEY_F(0)" ) {
143 printf "#define "
144 print_cols("KEY_F0", 16);
145 print_cols(showkey, 16);
146 print "/* Function keys. Space for 64 */";
147 printf "#define "
148 print_cols("KEY_F(n)", 16);
149 print_cols("(KEY_F0+(n))", 16);
150 print "/* Value of function key n */"
151 } else {
152 printf "#define "
153 print_cols($5, 16);
154 print_cols(showkey, 16);
155 printf "/*"
156 for (i = 8; i <= NF; i++)
157 printf " %s", $i
158 print " */"
162 END {
163 if (pass == 1) {
164 print maxkey;
165 } else if (pass == 4) {
166 print "";
167 printf "#define ";
168 print_cols("KEY_MAX", 16);
169 result = sprintf (octal_fmt, key_max);
170 print_cols(result, 16);
171 printf "/* Maximum key value is ";
172 printf octal_fmt, maxkey;
173 print " */";
177 if test $pass = 1 ; then
178 maxkey=`cat $pass1`
181 done
183 cat $pass2
184 cat $pass3
185 cat $pass4