xref: /illumos-gate/usr/src/lib/libeti/menu/common/curitem.c (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright (c) 1997, by Sun Mircrosystems, Inc.
28  * All rights reserved.
29  */
30 
31 /*LINTLIBRARY*/
32 
33 #include <sys/types.h>
34 #include "private.h"
35 
36 int
37 set_current_item(MENU *m, ITEM *current)
38 {
39 	int top;
40 
41 	if (m && current && Imenu(current) == m) {
42 		if (Indriver(m)) {
43 			return (E_BAD_STATE);
44 		}
45 		if (current != Current(m)) {
46 			if (LinkNeeded(m)) {
47 				_link_items(m);
48 			}
49 
50 			top = Top(m);
51 			_chk_current(m, &top, current);
52 
53 			/* Next clear the pattern buffer. */
54 			Pindex(m) = 0;
55 			IthPattern(m, Pindex(m)) = '\0';
56 			_affect_change(m, top, current);
57 		}
58 	} else {
59 		return (E_BAD_ARGUMENT);
60 	}
61 	return (E_OK);
62 }
63 
64 ITEM *
65 current_item(MENU *m)
66 {
67 	if (m && Items(m)) {
68 		return (Current(m));
69 	} else {
70 		return ((ITEM *)0);
71 	}
72 }
73 
74 int
75 item_index(ITEM *i)
76 {
77 	if (i && Imenu(i)) {
78 		return (Index(i));
79 	} else {
80 		return (-1);
81 	}
82 }
83