2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1995, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * keypad.c
2N/A *
2N/A * XCurses Library
2N/A *
2N/A * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
2N/A *
2N/A */
2N/A
2N/A#ifdef M_RCSID
2N/A#ifndef lint
2N/Astatic char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/keypad.c 1.3 1995/05/24 19:43:46 ant Exp $";
2N/A#endif
2N/A#endif
2N/A
2N/A#include <private.h>
2N/A#include <stdlib.h>
2N/A
2N/A/*f
2N/A * Add a function key string to the decode tree.
2N/A * Return -1 on error, else the length of the key sequence.
2N/A */
2N/Astatic int
2N/Adecode_add(root, str, code)
2N/At_decode **root;
2N/Aconst char *str;
2N/Ashort code;
2N/A{
2N/A const char *start;
2N/A t_decode *node, *saved;
2N/A
2N/A if (root == (t_decode **) 0)
2N/A return -1;
2N/A
2N/A if (str == (char *) 0)
2N/A return 0;
2N/A
2N/A start = str;
2N/A saved = (t_decode *) 0;
2N/A
2N/A if (*root == (t_decode *) 0) {
2N/A /* First node of tree. */
2N/A node = (t_decode *) malloc(sizeof *node);
2N/A if (node == (t_decode *) 0)
2N/A return -1;
2N/A
2N/A *root = saved = node;
2N/A
2N/A node->child = node->sibling = (t_decode *) 0;
2N/A node->ch = *str++;
2N/A node->key = 0;
2N/A } else {
2N/A /* Find node to insert function key sequence into the tree. */
2N/A for (node = *root; *str != '\0'; ++str, node = node->child) {
2N/A while (node->ch != *str
2N/A && node->sibling != (t_decode *)0)
2N/A node = node->sibling;
2N/A
2N/A if (node->ch != *str) {
2N/A node->sibling = (t_decode *) malloc(
2N/A sizeof *node
2N/A );
2N/A if (node->sibling == (t_decode *) 0)
2N/A return -1;
2N/A
2N/A saved = node = node->sibling;
2N/A node->child = node->sibling = (t_decode *) 0;
2N/A node->ch = *str++;
2N/A node->key = 0;
2N/A break;
2N/A }
2N/A
2N/A if (node->child == (t_decode *) 0)
2N/A break;
2N/A }
2N/A }
2N/A
2N/A /* Insert string into the tree; node->child == null. */
2N/A while (*str != '\0') {
2N/A node->child = (t_decode *) malloc(sizeof *node);
2N/A if (node->child == (t_decode *) 0) {
2N/A __m_decode_free(&saved);
2N/A return -1;
2N/A }
2N/A
2N/A node = node->child;
2N/A node->child = node->sibling = (t_decode *) 0;
2N/A node->ch = *str++;
2N/A node->key = 0;
2N/A }
2N/A
2N/A node->key = code;
2N/A
2N/A return (int) (str - start);
2N/A}
2N/A
2N/Avoid
2N/A__m_decode_free(tree)
2N/At_decode **tree;
2N/A{
2N/A if (*tree != (t_decode *) 0) {
2N/A __m_decode_free(&(*tree)->sibling);
2N/A __m_decode_free(&(*tree)->child);
2N/A free(*tree);
2N/A *tree = (t_decode *) 0;
2N/A }
2N/A}
2N/A
2N/A/*f
2N/A * Initialise the function key decode tree.
2N/A */
2N/Aint
2N/A__m_decode_init(tree)
2N/At_decode **tree;
2N/A{
2N/A int max, len;
2N/A short (*p)[2];
2N/A
2N/A *tree = (t_decode *) 0;
2N/A
2N/A for (max = -1, p = __m_keyindex; **p != -1; ++p) {
2N/A len = decode_add(tree, cur_term->_str[**p], (*p)[1]);
2N/A if (len < 0)
2N/A return -1;
2N/A if (max < len)
2N/A max = len;
2N/A }
2N/A
2N/A return max;
2N/A}
2N/A
2N/A/*f
2N/A * When true for a given window, then multibyte function key processing
2N/A * is done for all input throough that window, see wgetch().
2N/A */
2N/Aint
2N/Akeypad(WINDOW *w, bool bf)
2N/A{
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("keypad(%p, %d)", w, bf);
2N/A#endif
2N/A
2N/A w->_flags &= ~W_USE_KEYPAD;
2N/A
2N/A if (bf)
2N/A w->_flags |= W_USE_KEYPAD;
2N/A
2N/A return __m_return_code("keypad", OK);
2N/A}
2N/A