home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ncurses-1.9.9e-src.tgz / tar.out / fsf / ncurses / menu / m_new.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  4KB  |  92 lines

  1.  
  2. /***************************************************************************
  3. *                            COPYRIGHT NOTICE                              *
  4. ****************************************************************************
  5. *                ncurses is copyright (C) 1992-1995                        *
  6. *                          Zeyd M. Ben-Halim                               *
  7. *                          zmbenhal@netcom.com                             *
  8. *                          Eric S. Raymond                                 *
  9. *                          esr@snark.thyrsus.com                           *
  10. *                                                                          *
  11. *        Permission is hereby granted to reproduce and distribute ncurses  *
  12. *        by any means and for any fee, whether alone or as part of a       *
  13. *        larger distribution, in source or in binary form, PROVIDED        *
  14. *        this notice is included with any such distribution, and is not    *
  15. *        removed from any of its header files. Mention of ncurses in any   *
  16. *        applications linked with it is highly appreciated.                *
  17. *                                                                          *
  18. *        ncurses comes AS IS with no warranty, implied or expressed.       *
  19. *                                                                          *
  20. ***************************************************************************/
  21.  
  22. /***************************************************************************
  23. * Module menu_new                                                          *
  24. * Creation and destruction of new menus                                    *
  25. ***************************************************************************/
  26.  
  27. #include "menu.priv.h"
  28.  
  29. /*---------------------------------------------------------------------------
  30. |   Facility      :  libnmenu  
  31. |   Function      :  MENU *new_menu(ITEM **items)
  32. |   
  33. |   Description   :  Creates a new menu connected to the item pointer
  34. |                    array items and returns a pointer to the new menu.
  35. |                    The new menu is initialized with the values from the
  36. |                    default menu.
  37. |
  38. |   Return Values :  NULL on error
  39. +--------------------------------------------------------------------------*/
  40. MENU *new_menu(ITEM ** items)
  41. {
  42.   MENU *menu = (MENU *)calloc(1,sizeof(MENU));
  43.   
  44.   if (menu)
  45.     {
  46.       *menu = _nc_Default_Menu;
  47.       menu->rows = menu->frows;
  48.       menu->cols = menu->fcols;
  49.       if (items && *items)
  50.     {
  51.       if (!_nc_Connect_Items(menu,items))
  52.         {
  53.           free(menu);
  54.           menu = (MENU *)0;
  55.         }
  56.     }
  57.     }
  58.  
  59.   if (!menu)
  60.     SET_ERROR(E_SYSTEM_ERROR);
  61.  
  62.   return(menu);
  63. }
  64.  
  65. /*---------------------------------------------------------------------------
  66. |   Facility      :  libnmenu  
  67. |   Function      :  int free_menu(MENU *menu)  
  68. |   
  69. |   Description   :  Disconnects menu from its associated item pointer 
  70. |                    array and frees the storage allocated for the menu.
  71. |
  72. |   Return Values :  E_OK               - success
  73. |                    E_BAD_ARGUMENT     - Invalid menu pointer passed
  74. |                    E_POSTED           - Menu is already posted
  75. +--------------------------------------------------------------------------*/
  76. int free_menu(MENU * menu)
  77. {
  78.   if (!menu)
  79.     RETURN(E_BAD_ARGUMENT);
  80.   
  81.   if ( menu->status & _POSTED )
  82.     RETURN(E_POSTED);
  83.   
  84.   if (menu->items) 
  85.     _nc_Disconnect_Items(menu);
  86.   
  87.   free(menu);
  88.   RETURN(E_OK);
  89. }
  90.  
  91. /* m_new.c ends here */
  92.