X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=menu%2Fm_item_new.c;h=50dde29222573b6c3f950b3a93ba0e9777693a42;hp=0d0e98441b8897bc29655c2c8fae1bdbcd566241;hb=46722468f47c2b77b3987729b4bcf2321cccfd01;hpb=3a9b6a3bf0269231bef7de74757a910dedd04e0c diff --git a/menu/m_item_new.c b/menu/m_item_new.c index 0d0e9844..50dde292 100644 --- a/menu/m_item_new.c +++ b/menu/m_item_new.c @@ -1,34 +1,45 @@ -/*-----------------------------------------------------------------------------+ -| The ncurses menu library is Copyright (C) 1995-1997 | -| by Juergen Pfeifer | -| All Rights Reserved. | -| | -| Permission to use, copy, modify, and distribute this software and its | -| documentation for any purpose and without fee is hereby granted, provided | -| that the above copyright notice appear in all copies and that both that | -| copyright notice and this permission notice appear in supporting | -| documentation, and that the name of the above listed copyright holder(s) not | -| be used in advertising or publicity pertaining to distribution of the | -| software without specific, written prior permission. | -| | -| THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO | -| THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- | -| NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR | -| ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- | -| SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | -| NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH | -| THE USE OR PERFORMANCE OF THIS SOFTWARE. | -+-----------------------------------------------------------------------------*/ +/**************************************************************************** + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer, 1995,1997 * + * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en * + ****************************************************************************/ /*************************************************************************** -* Module menu_item_new * +* Module m_item_new * * Create and destroy menu items * -* Set and get marker string for menu +* Set and get marker string for menu * ***************************************************************************/ #include "menu.priv.h" -MODULE_ID("$Id: m_item_new.c,v 1.5 1997/05/01 16:47:26 juergen Exp $") +MODULE_ID("$Id: m_item_new.c,v 1.13 2002/07/06 15:22:16 juergen Exp $") /*--------------------------------------------------------------------------- | Facility : libnmenu @@ -62,7 +73,8 @@ static bool Is_Printable_String(const char *s) | | Return Values : The item pointer or NULL if creation failed. +--------------------------------------------------------------------------*/ -ITEM *new_item(const char *name, const char *description) +NCURSES_EXPORT(ITEM *) +new_item (const char *name, const char *description) { ITEM *item; @@ -79,35 +91,13 @@ ITEM *new_item(const char *name, const char *description) *item = _nc_Default_Item; /* hope we have struct assignment */ item->name.length = strlen(name); - item->name.str = (char *)malloc(1 + item->name.length); - if (item->name.str) - { - strcpy(item->name.str, name); - } - else - { - free(item); - SET_ERROR( E_SYSTEM_ERROR ); - return (ITEM *)0; - } - + item->name.str = name; + if (description && (*description != '\0') && Is_Printable_String(description)) { item->description.length = strlen(description); - item->description.str = - (char *)malloc(1 + item->description.length); - if (item->description.str) - { - strcpy(item->description.str, description); - } - else - { - free(item->name.str); - free(item); - SET_ERROR( E_SYSTEM_ERROR ); - return (ITEM *)0; - } + item->description.str = description; } else { @@ -132,7 +122,8 @@ ITEM *new_item(const char *name, const char *description) | E_BAD_ARGUMENT - invalid value has been passed | E_CONNECTED - item is still connected to a menu +--------------------------------------------------------------------------*/ -int free_item(ITEM * item) +NCURSES_EXPORT(int) +free_item (ITEM * item) { if (!item) RETURN( E_BAD_ARGUMENT ); @@ -140,10 +131,6 @@ int free_item(ITEM * item) if (item->imenu) RETURN( E_CONNECTED ); - if (item->name.str) - free(item->name.str); - if (item->description.str) - free (item->description.str); free(item); RETURN( E_OK ); @@ -166,7 +153,8 @@ int free_item(ITEM * item) | E_BAD_ARGUMENT - an invalid value has been passed | E_SYSTEM_ERROR - no memory to store mark +--------------------------------------------------------------------------*/ -int set_menu_mark(MENU * menu, const char * mark) +NCURSES_EXPORT(int) +set_menu_mark (MENU * menu, const char * mark) { int l; @@ -194,7 +182,8 @@ int set_menu_mark(MENU * menu, const char * mark) if (menu->mark) { strcpy(menu->mark, mark); - menu->status |= _MARK_ALLOCATED; + if (menu != &_nc_Default_Menu) + menu->status |= _MARK_ALLOCATED; } else { @@ -234,7 +223,8 @@ int set_menu_mark(MENU * menu, const char * mark) | | Return Values : The marker string pointer or NULL if no marker defined +--------------------------------------------------------------------------*/ -const char *menu_mark(const MENU * menu) +NCURSES_EXPORT(const char *) +menu_mark (const MENU * menu) { return Normalize_Menu( menu )->mark; }