2 # $Id: MKkey_defs.sh,v 1.18 2019/04/06 23:38:16 tom Exp $
3 ##############################################################################
4 # Copyright (c) 2001-2017,2019 Free Software Foundation, Inc. #
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: #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
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. #
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 #
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
39 test $# = 0 && set Caps
46 trap 'rm -f $data pass[1234]_$$' EXIT INT QUIT TERM HUP
48 # change repeated tabs (used for readability) to single tabs (needed to make
49 # awk see the right field alignment of the corresponding columns):
50 if sort -k 6 "$@" >$data 2>/dev/null
53 sed -e 's/[ ][ ]*/ /g' "$@" |sort -n -k 6 >$data
54 elif sort -n +5 "$@" >$data 2>/dev/null
56 # SunOS (and SVr4, marked as obsolete but still recognized)
57 sed -e 's/[ ][ ]*/ /g' "$@" |sort -n +5 >$data
59 echo "Your sort utility is broken. Please install one that works." >&2
63 # add keys that we generate automatically:
65 key_resize kr1 str R1 KEY_RESIZE + ----- Terminal resize event
66 key_event kv1 str V1 KEY_EVENT + ----- We were interrupted by an event
73 * These definitions were generated by $THIS $*
85 ${AWK-awk} >$output <$data '
86 function print_cols(text,cols) {
94 function decode(keycode) {
96 if (substr(keycode, 1, 2) == "0x") {
97 digits="0123456789abcdef";
98 } else if (substr(keycode, 1, 1) == "0") {
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;
116 while (key_max < maxkey) {
118 key_max = (key_max * 2) + 1;
120 octal_fmt = sprintf ("%%0%do", (bits + 2) / 3 + 1);
130 $5 != "-" && $6 != "-" {
132 if (pass == 1 || pass == 2)
140 if (thiskey > maxkey)
142 if (pass == 2 || pass == 3) {
143 showkey=sprintf(octal_fmt, thiskey);
144 if ($5 == "KEY_F(0)" ) {
146 print_cols("KEY_F0", 16);
147 print_cols(showkey, 16);
148 print "/* Function keys. Space for 64 */";
150 print_cols("KEY_F(n)", 16);
151 print_cols("(KEY_F0+(n))", 16);
152 print "/* Value of function key n */"
156 print_cols(showkey, 16);
158 for (i = 8; i <= NF; i++)
167 } else if (pass == 4) {
170 print_cols("KEY_MAX", 16);
171 result = sprintf (octal_fmt, key_max);
172 print_cols(result, 16);
173 printf "/* Maximum key value is ";
174 printf octal_fmt, maxkey;
179 if test $pass = 1 ; then