X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=menu%2Fm_item_new.c;h=4e3f67bacdd0580de188fc5243509ecae3211380;hp=f218d3ef4ef767c9167c37676d514c10dcfc988e;hb=HEAD;hpb=8b06e371ed1bce3dd6f37138e6becb5e1a562fe0 diff --git a/menu/m_item_new.c b/menu/m_item_new.c index f218d3ef..28b71caf 100644 --- a/menu/m_item_new.c +++ b/menu/m_item_new.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc. * + * Copyright 2020-2021 Thomas E. Dickey * + * Copyright 1998-2010,2012 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 * @@ -44,12 +45,12 @@ #endif #endif -MODULE_ID("$Id: m_item_new.c,v 1.31 2012/02/23 10:02:15 tom Exp $") +MODULE_ID("$Id: m_item_new.c,v 1.38 2021/06/17 21:26:02 tom Exp $") /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : bool Is_Printable_String(const char *s) -| +| | Description : Checks whether or not the string contains only printable | characters. | @@ -62,7 +63,7 @@ Is_Printable_String(const char *s) int result = TRUE; #if USE_WIDEC_SUPPORT - int count = mbstowcs(0, s, 0); + int count = (int)mbstowcs(0, s, 0); wchar_t *temp = 0; assert(s); @@ -74,7 +75,7 @@ Is_Printable_String(const char *s) mbstowcs(temp, s, (unsigned)count); for (n = 0; n < count; ++n) - if (!iswprint((wint_t) temp[n])) + if (!iswprint((wint_t)temp[n])) { result = FALSE; break; @@ -97,16 +98,16 @@ Is_Printable_String(const char *s) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : ITEM *new_item(char *name, char *description) -| +| | Description : Create a new item with name and description. Return | a pointer to this new item. | N.B.: an item must(!) have a name. | | Return Values : The item pointer or NULL if creation failed. +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(ITEM *) +MENU_EXPORT(ITEM *) new_item(const char *name, const char *description) { ITEM *item; @@ -117,23 +118,25 @@ new_item(const char *name, const char *description) if (!name || (*name == '\0') || !Is_Printable_String(name)) { - item = (ITEM *) 0; + item = (ITEM *)0; SET_ERROR(E_BAD_ARGUMENT); } else { item = typeCalloc(ITEM, 1); + if (item) { + T((T_CREATE("item %p"), (void *)item)); *item = _nc_Default_Item; /* hope we have struct assignment */ - item->name.length = strlen(name); + item->name.length = (unsigned short)strlen(name); item->name.str = name; if (description && (*description != '\0') && Is_Printable_String(description)) { - item->description.length = strlen(description); + item->description.length = (unsigned short)strlen(description); item->description.str = description; } else @@ -149,18 +152,18 @@ new_item(const char *name, const char *description) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : int free_item(ITEM *item) -| -| Description : Free the allocated storage for this item. +| +| Description : Free the allocated storage for this item. | N.B.: a connected item can't be freed. | | Return Values : E_OK - success | E_BAD_ARGUMENT - invalid value has been passed -| E_CONNECTED - item is still connected to a menu +| E_CONNECTED - item is still connected to a menu +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(int) -free_item(ITEM * item) +MENU_EXPORT(int) +free_item(ITEM *item) { T((T_CALLED("free_item(%p)"), (void *)item)); @@ -176,31 +179,31 @@ free_item(ITEM * item) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | 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 | (multi-valued menu). -| The mark argument may be NULL, in which case no +| The mark argument may be NULL, in which case no | marker is used. -| This might be a little bit tricky, because this may -| affect the geometry of the menu, which we don't allow +| This might be a little bit tricky, because this may +| affect the geometry of the menu, which we don't allow | if it is already posted. | | Return Values : E_OK - success | E_BAD_ARGUMENT - an invalid value has been passed | E_SYSTEM_ERROR - no memory to store mark +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(int) -set_menu_mark(MENU * menu, const char *mark) +MENU_EXPORT(int) +set_menu_mark(MENU *menu, const char *mark) { - unsigned l; + short l; T((T_CALLED("set_menu_mark(%p,%s)"), (void *)menu, _nc_visbuf(mark))); if (mark && (*mark != '\0') && Is_Printable_String(mark)) - l = strlen(mark); + l = (short)strlen(mark); else l = 0; @@ -213,7 +216,7 @@ set_menu_mark(MENU * menu, const char *mark) { /* If the menu is already posted, the geometry is fixed. Then we can only accept a mark with exactly the same length */ - if (menu->marklen != (int)l) + if (menu->marklen != l) RETURN(E_BAD_ARGUMENT); } menu->marklen = l; @@ -223,12 +226,12 @@ set_menu_mark(MENU * menu, const char *mark) if (menu->mark) { if (menu != &_nc_Default_Menu) - menu->status |= _MARK_ALLOCATED; + SetStatus(menu, _MARK_ALLOCATED); } else { menu->mark = old_mark; - menu->marklen = (old_mark != 0) ? strlen(old_mark) : 0; + menu->marklen = (short)((old_mark != 0) ? strlen(old_mark) : 0); RETURN(E_SYSTEM_ERROR); } } @@ -257,15 +260,15 @@ set_menu_mark(MENU * menu, const char *mark) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : char *menu_mark(const MENU *menu) -| +| | Description : Return a pointer to the marker string | | Return Values : The marker string pointer or NULL if no marker defined +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(const char *) -menu_mark(const MENU * menu) +MENU_EXPORT(const char *) +menu_mark(const MENU *menu) { T((T_CALLED("menu_mark(%p)"), (const void *)menu)); returnPtr(Normalize_Menu(menu)->mark);