4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
44 #include <sys/types.h>
47 #include "curses_inc.h"
49 static short keycodes
[] = {
150 static bool *funckey
;
151 static short *codeptr
;
157 p
->_keyval
= *codeptr
;
158 funckey
[(unsigned char)(txt
)[0]] |= _KEY
;
162 /* Map text into num, updating the map structure p. */
165 _keyfunc(char **keyptr
, char **lastkey
)
167 for (; keyptr
<= lastkey
; keyptr
++, codeptr
++)
169 p
->_sends
= (*keyptr
);
170 p
->_keyval
= *codeptr
;
171 funckey
[(unsigned char)(*keyptr
)[0]] |= _KEY
;
176 /* Map text into num, updating the map structure p. */
179 _keyfunc2(char **keyptr
, char **lastkey
)
181 short code_value
= KEY_F(11);
183 for (; *keyptr
&& keyptr
<= lastkey
; keyptr
++, code_value
++) {
185 p
->_keyval
= (short) code_value
;
186 funckey
[(unsigned char)*keyptr
[0]] |= _KEY
;
194 _KEY_MAP keymap
[((sizeof (keycodes
) / sizeof (short)) +
195 ((KEY_F(63) - KEY_F(11)) + 1))], **key_ptrs
;
197 int numbytes
, key_size
= cur_term
->_ksz
;
199 if (cur_term
->internal_keys
!= NULL
)
203 funckey
= cur_term
->funckeystarter
;
205 /* If backspace key sends \b, don't map it. */
206 if (key_backspace
&& strcmp(key_backspace
, "\b"))
207 _laddone(key_backspace
);
210 _keyfunc(&key_catab
, &key_dl
);
212 /* If down arrow key sends \n, don't map it. */
213 if (key_down
&& strcmp(key_down
, "\n"))
217 _keyfunc(&key_eic
, &key_il
);
219 /* If left arrow key sends \b, don't map it. */
220 if (key_left
&& strcmp(key_left
, "\b"))
224 _keyfunc(&key_ll
, &key_up
);
225 _keyfunc(&key_a1
, &key_c3
);
226 _keyfunc(&key_btab
, &key_btab
);
227 _keyfunc(&key_beg
, &key_sundo
);
228 _keyfunc2(&key_f11
, &key_f63
);
229 _keyfunc(&key_mouse
, &key_mouse
);
232 * malloc returns the address of a list of pointers to
233 * (_KEY_MAP *) structures
236 if ((key_ptrs
= (_KEY_MAP
**)
238 malloc((key_size
+ (numkeys
= (short)(p
- keymap
))) *
239 sizeof (_KEY_MAP
*))) == NULL
) {
244 * Number of bytes needed is the number of structures times their size
245 * malloc room for our array of _KEY_MAP structures
248 if ((p
= (_KEY_MAP
*) malloc((unsigned)
250 (numbytes
= (int)(sizeof (_KEY_MAP
) * numkeys
)))) == NULL
) {
251 /* Can't do it, free list of pointers, indicate */
252 /* error upon return. */
253 free((char *) key_ptrs
);
255 term_errno
= TERM_BAD_MALLOC
;
257 strcpy(term_parm_err
, "setkeymap");
264 (void) memcpy((char *) &(key_ptrs
[numkeys
]),
265 (char *) cur_term
->_keys
, (key_size
*
266 sizeof (_KEY_MAP
*)));
267 free(cur_term
->_keys
);
269 (void) memcpy((char *) (cur_term
->internal_keys
= p
),
270 (char *) keymap
, numbytes
);
271 cur_term
->_keys
= key_ptrs
;
272 cur_term
->_ksz
+= numkeys
;
274 * Reset _lastkey_ordered to -1 since we put the keys read in
275 * from terminfo at the beginning of the keys table.
277 cur_term
->_lastkey_ordered
= -1;
278 cur_term
->_lastmacro_ordered
+= numkeys
;
279 cur_term
->_first_macro
+= numkeys
;
281 /* Initialize our pointers to the structures */
286 fprintf(outf
, "return key structure %x, ending at %x\n",