Deleted Added
full compact
MKkey_defs.sh (97049) MKkey_defs.sh (98503)
1#! /bin/sh
1#! /bin/sh
2# $Id: MKkey_defs.sh,v 1.7 2002/01/13 01:36:32 tom Exp $
2# $Id: MKkey_defs.sh,v 1.8 2002/06/01 17:24:28 tom Exp $
3##############################################################################
4# Copyright (c) 2001,2002 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##############################################################################
30#
31# MKkey_defs.sh -- generate function-key definitions for curses.h
32#
33# Author: Thomas E. Dickey <dickey@herndon4.his.com> 2001
34#
35# Extract function-key definitions from the Caps file
36#
37: ${AWK-awk}
38DATA=${1-Caps}
39
40data=data$$
41pass1=pass1_$$
42pass2=pass2_$$
43pass3=pass3_$$
44pass4=pass4_$$
45trap 'rm -f $data pass[1234]_$$' 0 1 2 5 15
46sed -e 's/[ ]\+/ /g' < $DATA |sort -n +5 >$data
3##############################################################################
4# Copyright (c) 2001,2002 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##############################################################################
30#
31# MKkey_defs.sh -- generate function-key definitions for curses.h
32#
33# Author: Thomas E. Dickey <dickey@herndon4.his.com> 2001
34#
35# Extract function-key definitions from the Caps file
36#
37: ${AWK-awk}
38DATA=${1-Caps}
39
40data=data$$
41pass1=pass1_$$
42pass2=pass2_$$
43pass3=pass3_$$
44pass4=pass4_$$
45trap 'rm -f $data pass[1234]_$$' 0 1 2 5 15
46sed -e 's/[ ]\+/ /g' < $DATA |sort -n +5 >$data
47cat >>$data <<EOF
48key_resize kr1 str R1 KEY_RESIZE + ----- Terminal resize event
49EOF
47
48cat <<EOF
49/*
50 * These definitions were generated by $0 $DATA
51 */
52EOF
53
50
51cat <<EOF
52/*
53 * These definitions were generated by $0 $DATA
54 */
55EOF
56
54# KEY_RESIZE
55maxkey=410
57# KEY_RESET
58maxkey=345
56
57for pass in 1 2 3 4
58do
59
60output=pass${pass}_$$
61
62${AWK-awk} >$output <$data '
63function print_cols(text,cols) {
64 printf "%s", text
65 len = length(text);
66 while (len < cols) {
67 printf " "
68 len += 8;
69 }
70}
71function decode(keycode) {
72 result = 0;
73 if (substr(keycode, 1, 2) == "0x") {
74 digits="0123456789abcdef";
75 } else if (substr(keycode, 1, 1) == "0") {
76 digits="01234567";
77 } else {
78 digits="0123456789";
79 }
80 while (length(keycode) != 0) {
81 digit=substr(keycode, 1, 1);
82 keycode=substr(keycode, 2);
83 result = result * length(digits) + index(digits, digit) - 1;
84 }
85 return result;
86}
87
88BEGIN {
89 maxkey='$maxkey';
90 pass='$pass';
91 key_max=1;
92 bits=1;
93 while (key_max < maxkey) {
94 bits = bits + 1;
95 key_max = (key_max * 2) + 1;
96 }
97 octal_fmt = sprintf ("%%0%do", (bits + 2) / 3 + 1);
98}
99
100/^$/ {next;}
101/^#/ {next;}
102/^capalias/ {next;}
103/^infoalias/ {next;}
104
105$5 != "-" && $6 != "-" {
106 if ($6 == "+") {
107 if (pass == 1 || pass == 2)
108 next;
109 thiskey=maxkey + 1;
110 } else {
111 if (pass == 3)
112 next;
113 thiskey=decode($6);
114 }
115 if (thiskey > maxkey)
116 maxkey = thiskey;
117 if (pass == 2 || pass == 3) {
118 showkey=sprintf(octal_fmt, thiskey);
119 if ($5 == "KEY_F(0)" ) {
120 printf "#define "
121 print_cols("KEY_F0", 16);
122 print_cols(showkey, 16);
123 print "/* Function keys. Space for 64 */";
124 printf "#define "
125 print_cols("KEY_F(n)", 16);
126 print_cols("(KEY_F0+(n))", 16);
127 print "/* Value of function key n */"
128 } else {
129 printf "#define "
130 print_cols($5, 16);
131 print_cols(showkey, 16);
132 printf "/*"
133 for (i = 8; i <= NF; i++)
134 printf " %s", $i
135 print " */"
136 }
137 }
138 }
139END {
140 if (pass == 1) {
141 print maxkey;
142 } else if (pass == 4) {
143 print "";
144 printf "#define ";
145 print_cols("KEY_MAX", 16);
146 result = sprintf (octal_fmt, key_max);
147 print_cols(result, 16);
148 printf "/* Maximum key value is ";
149 printf octal_fmt, maxkey;
150 print " */";
151 }
152 }
153'
154if test $pass = 1 ; then
155 maxkey=`cat $pass1`
156fi
157
158done
159
160cat $pass2
161cat $pass3
162cat $pass4
59
60for pass in 1 2 3 4
61do
62
63output=pass${pass}_$$
64
65${AWK-awk} >$output <$data '
66function print_cols(text,cols) {
67 printf "%s", text
68 len = length(text);
69 while (len < cols) {
70 printf " "
71 len += 8;
72 }
73}
74function decode(keycode) {
75 result = 0;
76 if (substr(keycode, 1, 2) == "0x") {
77 digits="0123456789abcdef";
78 } else if (substr(keycode, 1, 1) == "0") {
79 digits="01234567";
80 } else {
81 digits="0123456789";
82 }
83 while (length(keycode) != 0) {
84 digit=substr(keycode, 1, 1);
85 keycode=substr(keycode, 2);
86 result = result * length(digits) + index(digits, digit) - 1;
87 }
88 return result;
89}
90
91BEGIN {
92 maxkey='$maxkey';
93 pass='$pass';
94 key_max=1;
95 bits=1;
96 while (key_max < maxkey) {
97 bits = bits + 1;
98 key_max = (key_max * 2) + 1;
99 }
100 octal_fmt = sprintf ("%%0%do", (bits + 2) / 3 + 1);
101}
102
103/^$/ {next;}
104/^#/ {next;}
105/^capalias/ {next;}
106/^infoalias/ {next;}
107
108$5 != "-" && $6 != "-" {
109 if ($6 == "+") {
110 if (pass == 1 || pass == 2)
111 next;
112 thiskey=maxkey + 1;
113 } else {
114 if (pass == 3)
115 next;
116 thiskey=decode($6);
117 }
118 if (thiskey > maxkey)
119 maxkey = thiskey;
120 if (pass == 2 || pass == 3) {
121 showkey=sprintf(octal_fmt, thiskey);
122 if ($5 == "KEY_F(0)" ) {
123 printf "#define "
124 print_cols("KEY_F0", 16);
125 print_cols(showkey, 16);
126 print "/* Function keys. Space for 64 */";
127 printf "#define "
128 print_cols("KEY_F(n)", 16);
129 print_cols("(KEY_F0+(n))", 16);
130 print "/* Value of function key n */"
131 } else {
132 printf "#define "
133 print_cols($5, 16);
134 print_cols(showkey, 16);
135 printf "/*"
136 for (i = 8; i <= NF; i++)
137 printf " %s", $i
138 print " */"
139 }
140 }
141 }
142END {
143 if (pass == 1) {
144 print maxkey;
145 } else if (pass == 4) {
146 print "";
147 printf "#define ";
148 print_cols("KEY_MAX", 16);
149 result = sprintf (octal_fmt, key_max);
150 print_cols(result, 16);
151 printf "/* Maximum key value is ";
152 printf octal_fmt, maxkey;
153 print " */";
154 }
155 }
156'
157if test $pass = 1 ; then
158 maxkey=`cat $pass1`
159fi
160
161done
162
163cat $pass2
164cat $pass3
165cat $pass4