]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/m_new.c
668370610515e1b0f255504c476cf0b92cf7d5b3
[ncurses.git] / menu / m_new.c
1 /*-----------------------------------------------------------------------------+
2 |           The ncurses menu library is  Copyright (C) 1995-1997               |
3 |             by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de>                 |
4 |                          All Rights Reserved.                                |
5 |                                                                              |
6 | Permission to use, copy, modify, and distribute this software and its        |
7 | documentation for any purpose and without fee is hereby granted, provided    |
8 | that the above copyright notice appear in all copies and that both that      |
9 | copyright notice and this permission notice appear in supporting             |
10 | documentation, and that the name of the above listed copyright holder(s) not |
11 | be used in advertising or publicity pertaining to distribution of the        |
12 | software without specific, written prior permission.                         | 
13 |                                                                              |
14 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO  |
15 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-  |
16 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR   |
17 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
18 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
19 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH    |
20 | THE USE OR PERFORMANCE OF THIS SOFTWARE.                                     |
21 +-----------------------------------------------------------------------------*/
22
23 /***************************************************************************
24 * Module menu_new                                                          *
25 * Creation and destruction of new menus                                    *
26 ***************************************************************************/
27
28 #include "menu.priv.h"
29
30 MODULE_ID("$Id: m_new.c,v 1.5 1997/05/01 16:47:26 juergen Exp $")
31
32 /*---------------------------------------------------------------------------
33 |   Facility      :  libnmenu  
34 |   Function      :  MENU *new_menu(ITEM **items)
35 |   
36 |   Description   :  Creates a new menu connected to the item pointer
37 |                    array items and returns a pointer to the new menu.
38 |                    The new menu is initialized with the values from the
39 |                    default menu.
40 |
41 |   Return Values :  NULL on error
42 +--------------------------------------------------------------------------*/
43 MENU *new_menu(ITEM ** items)
44 {
45   MENU *menu = (MENU *)calloc(1,sizeof(MENU));
46   
47   if (menu)
48     {
49       *menu = _nc_Default_Menu;
50       menu->rows = menu->frows;
51       menu->cols = menu->fcols;
52       if (items && *items)
53         {
54           if (!_nc_Connect_Items(menu,items))
55             {
56               free(menu);
57               menu = (MENU *)0;
58             }
59         }
60     }
61
62   if (!menu)
63     SET_ERROR(E_SYSTEM_ERROR);
64
65   return(menu);
66 }
67
68 /*---------------------------------------------------------------------------
69 |   Facility      :  libnmenu  
70 |   Function      :  int free_menu(MENU *menu)  
71 |   
72 |   Description   :  Disconnects menu from its associated item pointer 
73 |                    array and frees the storage allocated for the menu.
74 |
75 |   Return Values :  E_OK               - success
76 |                    E_BAD_ARGUMENT     - Invalid menu pointer passed
77 |                    E_POSTED           - Menu is already posted
78 +--------------------------------------------------------------------------*/
79 int free_menu(MENU * menu)
80 {
81   if (!menu)
82     RETURN(E_BAD_ARGUMENT);
83   
84   if ( menu->status & _POSTED )
85     RETURN(E_POSTED);
86   
87   if (menu->items) 
88     _nc_Disconnect_Items(menu);
89   
90   if ((menu->status & _MARK_ALLOCATED) && menu->mark)
91     free(menu->mark);
92
93   free(menu);
94   RETURN(E_OK);
95 }
96
97 /* m_new.c ends here */