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/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright (c) 1997, by Sun Mircrosystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.8 */
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include <stdlib.h>
2N/A#include "private.h"
2N/A
2N/A/* Connect and disconnect an item list from a menu */
2N/A
2N/A
2N/A/* Find the maximum length name and description */
2N/A
2N/Astatic void
2N/Amaxlengths(MENU *m)
2N/A{
2N/A int maxn, maxd;
2N/A ITEM **ip;
2N/A
2N/A maxn = maxd = 0;
2N/A for (ip = Items(m); *ip; ip++) {
2N/A if (NameLen(*ip) > maxn) {
2N/A maxn = NameLen(*ip);
2N/A }
2N/A if (DescriptionLen(*ip) > maxd) {
2N/A maxd = DescriptionLen(*ip);
2N/A }
2N/A }
2N/A MaxName(m) = maxn;
2N/A MaxDesc(m) = maxd;
2N/A}
2N/A
2N/Aint
2N/A_connect(MENU *m, ITEM **items)
2N/A{
2N/A ITEM **ip;
2N/A int i;
2N/A
2N/A /* Is the list of items connected to any other menu? */
2N/A for (ip = items; *ip; ip++) {
2N/A /* Return Null if item points to a menu */
2N/A if (Imenu(*ip)) {
2N/A return (FALSE);
2N/A }
2N/A }
2N/A
2N/A for (i = 0, ip = items; *ip; ip++) {
2N/A /* Return FALSE if this item is a prevoious item */
2N/A if (Imenu(*ip)) {
2N/A for (ip = items; *ip; ip++) {
2N/A /* Reset index and menu pointers */
2N/A Index(*ip) = 0;
2N/A Imenu(*ip) = (MENU *) NULL;
2N/A }
2N/A return (FALSE);
2N/A }
2N/A if (OneValue(m)) {
2N/A /* Set all values to FALSE if selection not allowed */
2N/A Value(*ip) = FALSE;
2N/A }
2N/A Index(*ip) = i++;
2N/A Imenu(*ip) = m;
2N/A }
2N/A
2N/A Nitems(m) = i;
2N/A Items(m) = items;
2N/A
2N/A /* Go pick up the sizes of names and descriptions */
2N/A maxlengths(m);
2N/A
2N/A /* Set up match buffer */
2N/A if ((Pattern(m) = (char *)malloc((unsigned)MaxName(m)+1)) ==
2N/A (char *)0) {
2N/A return (FALSE);
2N/A }
2N/A
2N/A IthPattern(m, 0) = '\0';
2N/A Pindex(m) = 0;
2N/A (void) set_menu_format(m, FRows(m), FCols(m));
2N/A Current(m) = IthItem(m, 0);
2N/A Top(m) = 0;
2N/A return (TRUE);
2N/A}
2N/A
2N/Avoid
2N/A_disconnect(MENU *m)
2N/A{
2N/A ITEM **ip;
2N/A
2N/A for (ip = Items(m); *ip; ip++) {
2N/A /* Release items for another menu */
2N/A Imenu(*ip) = (MENU *) NULL;
2N/A }
2N/A free(Pattern(m));
2N/A Pattern(m) = NULL;
2N/A Items(m) = (ITEM **) NULL;
2N/A Nitems(m) = 0;
2N/A}