summaryrefslogtreecommitdiff
path: root/lib/libmenu/m_item_new.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-11-26 03:59:14 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-11-26 03:59:14 +0000
commit65d9e3fdab3ed1511a98387720e59db078fc3d46 (patch)
tree7fa63a0892e13f7f68f9b6a87154fc3d6a0cce17 /lib/libmenu/m_item_new.c
parent4db103e641c472e38eb16ec5885f4ee5cabe750c (diff)
libmenu from ncurses 4.1. Post 4.1 patches to be applied in a separate commit.
Diffstat (limited to 'lib/libmenu/m_item_new.c')
-rw-r--r--lib/libmenu/m_item_new.c122
1 files changed, 88 insertions, 34 deletions
diff --git a/lib/libmenu/m_item_new.c b/lib/libmenu/m_item_new.c
index 8ef123f580c..5d06576fd08 100644
--- a/lib/libmenu/m_item_new.c
+++ b/lib/libmenu/m_item_new.c
@@ -1,23 +1,24 @@
-
-/***************************************************************************
-* COPYRIGHT NOTICE *
-****************************************************************************
-* ncurses is copyright (C) 1992-1995 *
-* Zeyd M. Ben-Halim *
-* zmbenhal@netcom.com *
-* Eric S. Raymond *
-* esr@snark.thyrsus.com *
-* *
-* Permission is hereby granted to reproduce and distribute ncurses *
-* by any means and for any fee, whether alone or as part of a *
-* larger distribution, in source or in binary form, PROVIDED *
-* this notice is included with any such distribution, and is not *
-* removed from any of its header files. Mention of ncurses in any *
-* applications linked with it is highly appreciated. *
-* *
-* ncurses comes AS IS with no warranty, implied or expressed. *
-* *
-***************************************************************************/
+/*-----------------------------------------------------------------------------+
+| The ncurses menu library is Copyright (C) 1995-1997 |
+| by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> |
+| 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. |
++-----------------------------------------------------------------------------*/
/***************************************************************************
* Module menu_item_new *
@@ -27,6 +28,8 @@
#include "menu.priv.h"
+MODULE_ID("Id: m_item_new.c,v 1.5 1997/05/01 16:47:26 juergen Exp $")
+
/*---------------------------------------------------------------------------
| Facility : libnmenu
| Function : bool Is_Printable_String(const char *s)
@@ -59,7 +62,7 @@ static bool Is_Printable_String(const char *s)
|
| Return Values : The item pointer or NULL if creation failed.
+--------------------------------------------------------------------------*/
-ITEM *new_item(char *name, char *description)
+ITEM *new_item(const char *name, const char *description)
{
ITEM *item;
@@ -75,12 +78,37 @@ ITEM *new_item(char *name, char *description)
{
*item = _nc_Default_Item; /* hope we have struct assignment */
- item->name.str = name;
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->description.str = description;
- if (description && Is_Printable_String(description))
- item->description.length = strlen(description);
+ 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;
+ }
+ }
else
{
item->description.length = 0;
@@ -112,13 +140,18 @@ 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 );
}
/*---------------------------------------------------------------------------
| Facility : libnmenu
-| Function : int set_menu_mark( MENU *menu, char *mark )
+| Function : int set_menu_mark( MENU *menu, const char *mark )
|
| Description : Set the mark string used to indicate the current
| item (single-valued menu) or the selected items
@@ -131,18 +164,22 @@ int free_item(ITEM * item)
|
| Return Values : E_OK - success
| E_BAD_ARGUMENT - an invalid value has been passed
+| E_SYSTEM_ERROR - no memory to store mark
+--------------------------------------------------------------------------*/
-int set_menu_mark(MENU * menu, char * mark)
+int set_menu_mark(MENU * menu, const char * mark)
{
int l;
-
- if ( mark && *mark && Is_Printable_String(mark) )
+
+ if ( mark && (*mark != '\0') && Is_Printable_String(mark) )
l = strlen(mark);
else
l = 0;
-
+
if ( menu )
{
+ char *old_mark = menu->mark;
+ unsigned short old_status = menu->status;
+
if (menu->status & _POSTED)
{
/* If the menu is already posted, the geometry is fixed. Then
@@ -150,9 +187,27 @@ int set_menu_mark(MENU * menu, char * mark)
if (menu->marklen != l)
RETURN(E_BAD_ARGUMENT);
}
- menu->mark = l ? mark : (char *)0;
menu->marklen = l;
+ if (l)
+ {
+ menu->mark = (char *)malloc(l+1);
+ if (menu->mark)
+ {
+ strcpy(menu->mark, mark);
+ menu->status |= _MARK_ALLOCATED;
+ }
+ else
+ {
+ menu->mark = old_mark;
+ RETURN(E_SYSTEM_ERROR);
+ }
+ }
+ else
+ menu->mark = (char *)0;
+ if ((old_status & _MARK_ALLOCATED) && old_mark)
+ free(old_mark);
+
if (menu->status & _POSTED)
{
_nc_Draw_Menu( menu );
@@ -166,8 +221,7 @@ int set_menu_mark(MENU * menu, char * mark)
}
else
{
- _nc_Default_Menu.mark = l ? mark : (char *)0;
- _nc_Default_Menu.marklen = l;
+ return set_menu_mark(&_nc_Default_Menu, mark);
}
RETURN(E_OK);
}
@@ -180,7 +234,7 @@ int set_menu_mark(MENU * menu, char * mark)
|
| Return Values : The marker string pointer or NULL if no marker defined
+--------------------------------------------------------------------------*/
-char *menu_mark(const MENU * menu)
+const char *menu_mark(const MENU * menu)
{
return Normalize_Menu( menu )->mark;
}