m_items.c revision 1.8
1/* $OpenBSD: m_items.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */ 2 3/**************************************************************************** 4 * Copyright 2020,2021 Thomas E. Dickey * 5 * Copyright 1998-2005,2010 Free Software Foundation, Inc. * 6 * * 7 * Permission is hereby granted, free of charge, to any person obtaining a * 8 * copy of this software and associated documentation files (the * 9 * "Software"), to deal in the Software without restriction, including * 10 * without limitation the rights to use, copy, modify, merge, publish, * 11 * distribute, distribute with modifications, sublicense, and/or sell * 12 * copies of the Software, and to permit persons to whom the Software is * 13 * furnished to do so, subject to the following conditions: * 14 * * 15 * The above copyright notice and this permission notice shall be included * 16 * in all copies or substantial portions of the Software. * 17 * * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25 * * 26 * Except as contained in this notice, the name(s) of the above copyright * 27 * holders shall not be used in advertising or otherwise to promote the * 28 * sale, use or other dealings in this Software without prior written * 29 * authorization. * 30 ****************************************************************************/ 31 32/**************************************************************************** 33 * Author: Juergen Pfeifer, 1995,1997 * 34 ****************************************************************************/ 35 36/*************************************************************************** 37* Module m_items * 38* Connect and disconnect items to and from menus * 39***************************************************************************/ 40 41#include "menu.priv.h" 42 43MODULE_ID("$Id: m_items.c,v 1.8 2023/10/17 09:52:10 nicm Exp $") 44 45/*--------------------------------------------------------------------------- 46| Facility : libnmenu 47| Function : int set_menu_items(MENU *menu, ITEM **items) 48| 49| Description : Sets the item pointer array connected to menu. 50| 51| Return Values : E_OK - success 52| E_POSTED - menu is already posted 53| E_CONNECTED - one or more items are already connected 54| to another menu. 55| E_BAD_ARGUMENT - An incorrect menu or item array was 56| passed to the function 57+--------------------------------------------------------------------------*/ 58MENU_EXPORT(int) 59set_menu_items(MENU *menu, ITEM **items) 60{ 61 T((T_CALLED("set_menu_items(%p,%p)"), (void *)menu, (void *)items)); 62 63 if (!menu || (items && !(*items))) 64 RETURN(E_BAD_ARGUMENT); 65 66 if (menu->status & _POSTED) 67 RETURN(E_POSTED); 68 69 if (menu->items) 70 _nc_Disconnect_Items(menu); 71 72 if (items) 73 { 74 if (!_nc_Connect_Items(menu, items)) 75 RETURN(E_CONNECTED); 76 } 77 78 menu->items = items; 79 RETURN(E_OK); 80} 81 82/*--------------------------------------------------------------------------- 83| Facility : libnmenu 84| Function : ITEM **menu_items(const MENU *menu) 85| 86| Description : Returns a pointer to the item pointer array of the menu 87| 88| Return Values : NULL on error 89+--------------------------------------------------------------------------*/ 90MENU_EXPORT(ITEM **) 91menu_items(const MENU *menu) 92{ 93 T((T_CALLED("menu_items(%p)"), (const void *)menu)); 94 returnItemPtr(menu ? menu->items : (ITEM **)0); 95} 96 97/*--------------------------------------------------------------------------- 98| Facility : libnmenu 99| Function : int item_count(const MENU *menu) 100| 101| Description : Get the number of items connected to the menu. If the 102| menu pointer is NULL we return -1. 103| 104| Return Values : Number of items or -1 to indicate error. 105+--------------------------------------------------------------------------*/ 106MENU_EXPORT(int) 107item_count(const MENU *menu) 108{ 109 T((T_CALLED("item_count(%p)"), (const void *)menu)); 110 returnCode(menu ? menu->nitems : -1); 111} 112 113/* m_items.c ends here */ 114