generously add tests for NULL in various menu related functions

This commit is contained in:
marschap
2005-02-28 20:21:40 +00:00
parent ed90f0f643
commit fcfd6b6b93
4 changed files with 572 additions and 436 deletions
+53 -14
View File
@@ -43,12 +43,15 @@ menu_create (char *id, MenuEventFunc(*event_func),
{
Menu *new_menu;
debug (RPT_DEBUG, "%s( id=\"%s\", event_func=%p, text=\"%s\", association=%p )", __FUNCTION__, id, event_func, text, association);
debug (RPT_DEBUG, "%s( id=\"%s\", event_func=%p, text=\"%s\", association=%p )",
__FUNCTION__, id, event_func, text, association);
new_menu = menuitem_create (MENUITEM_MENU, id, event_func, text);
if (new_menu != NULL) {
new_menu->data.menu.contents = LL_new();
new_menu->data.menu.association = association;
}
return new_menu;
}
@@ -56,6 +59,9 @@ menu_create (char *id, MenuEventFunc(*event_func),
void
menu_destroy (Menu *menu)
{
if (menu == NULL)
return;
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
menu_destroy_all_items (menu);
@@ -68,9 +74,10 @@ menu_destroy (Menu *menu)
void
menu_add_item (Menu *menu, MenuItem *item)
{
debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__, menu->id, item->id);
if ((menu == NULL) || (item == NULL))
return;
if (!menu) return;
debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__, menu->id, item->id);
/* Add the item to the menu */
LL_Push (menu->data.menu.contents, item);
@@ -83,15 +90,18 @@ menu_remove_item (Menu *menu, MenuItem *item)
int i;
MenuItem * item2;
if ((menu == NULL) || (item == NULL))
return
debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__, menu->id, item->id);
/* Find the item */
for (item2=LL_GetFirst(menu->data.menu.contents), i=0;
item2;
item2=LL_GetNext(menu->data.menu.contents), i++ ) {
if (item==item2) {
for (item2 = LL_GetFirst(menu->data.menu.contents), i=0;
item2 != NULL;
item2 = LL_GetNext(menu->data.menu.contents), i++ ) {
if (item == item2) {
LL_DeleteNode (menu->data.menu.contents);
if (menu->data.menu.selector_pos>=i) {
if (menu->data.menu.selector_pos >= i) {
menu->data.menu.selector_pos--;
if (menu->data.menu.scroll > 0)
menu->data.menu.scroll--;
@@ -106,9 +116,12 @@ menu_destroy_all_items (Menu *menu)
{
MenuItem * item;
if (menu == NULL)
return;
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
for( item = menu_getfirst_item(menu); item; item = menu_getfirst_item(menu) ) {
for( item = menu_getfirst_item(menu); item != NULL; item = menu_getfirst_item(menu) ) {
menuitem_destroy (item);
LL_Remove (menu->data.menu.contents, item);
}
@@ -118,9 +131,12 @@ MenuItem *menu_find_item (Menu *menu, char *id, bool recursive)
{
MenuItem * item;
if ((menu == NULL) || (id == NULL))
return NULL;
debug (RPT_DEBUG, "%s( menu=[%s], id=\"%s\", recursive=%d )", __FUNCTION__, menu->id, id, recursive);
for( item = menu_getfirst_item(menu); item; item = menu_getnext_item(menu) ) {
for( item = menu_getfirst_item(menu); item != NULL; item = menu_getnext_item(menu) ) {
if ( strcmp(item->id, id) == 0 ) {
return item;
}
@@ -137,6 +153,9 @@ MenuItem *menu_find_item (Menu *menu, char *id, bool recursive)
void menu_reset (Menu *menu)
{
if (menu == NULL)
return;
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
menu->data.menu.selector_pos = 0;
@@ -149,6 +168,9 @@ void menu_build_screen (MenuItem *menu, Screen *s)
MenuItem * subitem;
int itemnr;
if ((menu == NULL) || (s == NULL))
return;
debug (RPT_DEBUG, "%s( menu=[%s], screen=[%s] )", __FUNCTION__, menu->id, s->id);
/* TODO: Put menu in a frame to do easy scrolling */
@@ -156,13 +178,15 @@ void menu_build_screen (MenuItem *menu, Screen *s)
/* Create menu title widget */
w = widget_create ("title", WID_TITLE, s);
if (w != NULL) {
screen_add_widget (s, w);
w->text = strdup(menu->text);
w->x = 1;
}
/* Create widgets for each subitem in the menu */
for (subitem = LL_GetFirst (menu->data.menu.contents), itemnr = 0;
subitem;
subitem != NULL;
subitem = LL_GetNext (menu->data.menu.contents), itemnr ++ )
{
char buf[10];
@@ -171,6 +195,7 @@ void menu_build_screen (MenuItem *menu, Screen *s)
buf[sizeof(buf)-1] = 0;
w = widget_create (buf, WID_STRING, s);
/* (buf will be copied) */
if (w != NULL) {
screen_add_widget (s, w);
w->x = 2;
@@ -202,7 +227,7 @@ void menu_build_screen (MenuItem *menu, Screen *s)
strcpy( w->text, subitem->text );
strcat( w->text, " >" );
if (strlen(subitem->text) >= display_props->width-1) {
(w->text)[display_props->width-1] = 0;
(w->text)[display_props->width-1] = '\0';
}
break;
case MENUITEM_ACTION:
@@ -212,31 +237,38 @@ void menu_build_screen (MenuItem *menu, Screen *s)
/* Limit string length */
w->text = strdup (subitem->text);
if (strlen(subitem->text) >= display_props->width-1) {
(w->text)[display_props->width-1] = 0;
(w->text)[display_props->width-1] = '\0';
}
break;
}
}
}
/* Add arrow for selection on the left */
w = widget_create ("selector", WID_ICON, s);
if (w != NULL) {
screen_add_widget (s, w);
w->length = ICON_SELECTOR_AT_LEFT;
w->x = 1;
}
/* Add scrollers on the right side on top and bottom */
/* TODO: when menu is in a frame, these can be removed */
w = widget_create ("upscroller", WID_ICON, s);
if (w != NULL) {
screen_add_widget (s, w);
w->length = ICON_ARROW_UP;
w->x = display_props->width;
w->y = 1;
}
w = widget_create ("downscroller", WID_ICON, s);
if (w != NULL) {
screen_add_widget (s, w);
w->length = ICON_ARROW_DOWN;
w->x = display_props->width;
w->y = display_props->height;
}
}
@@ -246,6 +278,9 @@ void menu_update_screen (MenuItem *menu, Screen *s)
MenuItem * subitem;
int itemnr;
if ((menu == NULL) || (s == NULL))
return;
debug (RPT_DEBUG, "%s( menu=[%s], screen=[%s] )", __FUNCTION__, menu->id, s->id);
/* Update widgets for the title */
@@ -358,6 +393,9 @@ MenuResult menu_process_input (Menu *menu, MenuToken token, char * key)
{
MenuItem *subitem;
if (menu == NULL)
return MENURESULT_ERROR;
debug (RPT_DEBUG, "%s( menu=[%s], token=%d, key=\"%s\" )", __FUNCTION__, menu->id, token, key);
switch (token) {
@@ -371,7 +409,8 @@ MenuResult menu_process_input (Menu *menu, MenuToken token, char * key)
case MENUITEM_ACTION:
if (subitem->event_func)
subitem->event_func (subitem, MENUEVENT_SELECT);
return subitem->data.action.menu_result; return MENURESULT_QUIT;
return subitem->data.action.menu_result;
//return MENURESULT_QUIT;
case MENUITEM_CHECKBOX:
if (subitem->data.checkbox.allow_gray) {
subitem->data.checkbox.value = (subitem->data.checkbox.value + 1) % 3;
+14 -9
View File
@@ -64,7 +64,9 @@ static inline MenuItem *menu_getfirst_item (Menu *menu)
* Retrieves the first item from the list of items in the menu.
*/
{
return (MenuItem*) LL_GetFirst( menu->data.menu.contents );
return (MenuItem*) ((menu != NULL)
? LL_GetFirst(menu->data.menu.contents)
: NULL);
}
static inline MenuItem *menu_getnext_item (Menu *menu)
@@ -74,15 +76,18 @@ static inline MenuItem *menu_getnext_item (Menu *menu)
* this function, to keep the list-cursor where it is.
*/
{
return (MenuItem*) LL_GetNext( menu->data.menu.contents );
return (MenuItem*) ((menu != NULL)
? LL_GetNext(menu->data.menu.contents)
: NULL);
}
static inline MenuItem *menu_get_current_item (Menu *menu)
/* Retrieves the current item from the list of items in the menu. */
{
return LL_GetByIndex(
menu->data.menu.contents,
menu->data.menu.selector_pos);
return (MenuItem*) ((menu != NULL)
? LL_GetByIndex(menu->data.menu.contents,
menu->data.menu.selector_pos)
: NULL);
}
MenuItem *menu_find_item (Menu *menu, char *id, bool recursive);
@@ -90,23 +95,23 @@ MenuItem *menu_find_item (Menu *menu, char *id, bool recursive);
void menu_reset (Menu *menu);
/* Resets it to initial state.
* DO NOT CALL THIS FUNCTION, CALL menuitem_build_screen INSTEAD !
* DO NOT CALL THIS FUNCTION, CALL menuitem_reset_screen INSTEAD !
*/
void menu_build_screen (Menu *menu, Screen *s);
/* Builds the selected menuitem on screen using widgets.
* DO NOT CALL THIS FUNCTION, CALL menuitem_build_screen INSTEAD !
* DO NOT CALL THIS FUNCTION, CALL menuitem_rebuild_screen INSTEAD !
*/
void menu_update_screen (Menu *menu, Screen *s);
/* Updates the widgets of the selected menuitem
* DO NOT CALL THIS FUNCTION, CALL menuitem_build_screen INSTEAD !
* DO NOT CALL THIS FUNCTION, CALL menuitem_update_screen INSTEAD !
*/
MenuResult menu_process_input (Menu *menu, MenuToken token, char * key);
/* Does something with the given input.
* key is only used if token is MENUTOKEN_OTHER.
* DO NOT CALL THIS FUNCTION, CALL menuitem_build_screen INSTEAD !
* DO NOT CALL THIS FUNCTION, CALL menuitem_process_input INSTEAD !
*/
#endif
+140 -52
View File
@@ -115,6 +115,11 @@ MenuItem *menuitem_create (MenuItemType type, char *id, MenuEventFunc(*event_fun
debug (RPT_DEBUG, "%s( type=%d, id=\"%s\", event_func=%p, text=\"%s\" )",
__FUNCTION__, type, id, event_func, text);
if ((id == NULL) || (text == NULL)) {
// report (RPT_ERR, "%s: illegal id or text", __FUNCTION__);
return NULL;
}
/* Allocate space and fill struct */
new_item = malloc (sizeof(MenuItem));
if (!new_item) {
@@ -150,6 +155,7 @@ MenuItem *menuitem_create_action (char *id, MenuEventFunc(*event_func),
__FUNCTION__, id, event_func, text, menu_result);
new_item = menuitem_create (MENUITEM_ACTION, id, event_func, text);
if (new_item != NULL)
new_item->data.action.menu_result = menu_result;
return new_item;
@@ -164,8 +170,10 @@ MenuItem *menuitem_create_checkbox (char *id, MenuEventFunc(*event_func),
__FUNCTION__, id, event_func, text, allow_gray, value);
new_item = menuitem_create (MENUITEM_CHECKBOX, id, event_func, text);
if (new_item != NULL) {
new_item->data.checkbox.allow_gray = allow_gray;
new_item->data.checkbox.value = value;
}
return new_item;
}
@@ -179,8 +187,10 @@ MenuItem *menuitem_create_ring (char *id, MenuEventFunc(*event_func),
__FUNCTION__, id, event_func, text, strings, value);
new_item = menuitem_create (MENUITEM_RING, id, event_func, text);
if (new_item != NULL) {
new_item->data.ring.strings = tablist2linkedlist (strings);
new_item->data.ring.value = value;
}
return new_item;
}
@@ -195,12 +205,14 @@ MenuItem *menuitem_create_slider (char *id, MenuEventFunc(*event_func),
__FUNCTION__, id, event_func, text, mintext, maxtext, minvalue, maxvalue, stepsize, value);
new_item = menuitem_create (MENUITEM_SLIDER, id, event_func, text);
if (new_item != NULL) {
new_item->data.slider.mintext = strdup (mintext);
new_item->data.slider.maxtext = strdup (maxtext);
new_item->data.slider.minvalue = minvalue;
new_item->data.slider.maxvalue = maxvalue;
new_item->data.slider.stepsize = stepsize;
new_item->data.slider.value = value;
}
return new_item;
}
@@ -214,10 +226,12 @@ MenuItem *menuitem_create_numeric (char *id, MenuEventFunc(*event_func),
__FUNCTION__, id, event_func, text, minvalue, minvalue, value);
new_item = menuitem_create (MENUITEM_NUMERIC, id, event_func, text);
if (new_item != NULL) {
new_item->data.numeric.maxvalue = maxvalue;
new_item->data.numeric.minvalue = minvalue;
new_item->data.numeric.edit_str = malloc (MAX_NUMERIC_LEN);
new_item->data.numeric.value = value;
}
return new_item;
}
@@ -233,6 +247,7 @@ MenuItem *menuitem_create_alpha (char *id, MenuEventFunc(*event_func),
__FUNCTION__, id, event_func, text, password_char, maxlength, value);
new_item = menuitem_create (MENUITEM_ALPHA, id, event_func, text);
if (new_item != NULL) {
new_item->data.alpha.password_char = password_char;
new_item->data.alpha.minlength = minlength;
new_item->data.alpha.maxlength = maxlength;
@@ -247,6 +262,7 @@ MenuItem *menuitem_create_alpha (char *id, MenuEventFunc(*event_func),
new_item->data.alpha.value[maxlength] = 0;
new_item->data.alpha.edit_str = malloc (maxlength + 1);
}
return new_item;
}
@@ -254,9 +270,11 @@ MenuItem *menuitem_create_alpha (char *id, MenuEventFunc(*event_func),
void menuitem_destroy (MenuItem *item)
{
void (*destructor) (MenuItem *);
debug (RPT_DEBUG, "%s( item=[%s] )",
__FUNCTION__, ((item != NULL) ? item->id : "(null)"));
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
if (item != NULL) {
void (*destructor) (MenuItem *);
/* First destroy type specific data */
destructor = destructor_table[item->type];
@@ -269,83 +287,109 @@ void menuitem_destroy (MenuItem *item)
/* And finally...*/
free (item);
}
}
void menuitem_destroy_ring (MenuItem *item)
{
debug (RPT_DEBUG, "%s( item=[%s] )",
__FUNCTION__, ((item != NULL) ? item->id : "(null)"));
if (item != NULL) {
char * s;
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
/* deallocate the strings */
for (s = LL_GetFirst(item->data.ring.strings); s; s = LL_GetNext(item->data.ring.strings)) {
for (s = LL_GetFirst(item->data.ring.strings);
s != NULL;
s = LL_GetNext(item->data.ring.strings)) {
free (s);
}
/* and the list */
LL_Destroy (item->data.ring.strings);
}
}
void menuitem_destroy_slider (MenuItem *item)
{
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
debug (RPT_DEBUG, "%s( item=[%s] )",
__FUNCTION__, ((item != NULL) ? item->id : "(null)"));
if (item != NULL) {
/* These strings should always be allocated */
free (item->data.slider.mintext);
free (item->data.slider.maxtext);
}
}
void menuitem_destroy_numeric (MenuItem *item)
{
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
debug (RPT_DEBUG, "%s( item=[%s] )",
__FUNCTION__, ((item != NULL) ? item->id : "(null)"));
if (item != NULL) {
/* This string should always be allocated */
free (item->data.alpha.edit_str);
free (item->data.numeric.edit_str);
}
}
void menuitem_destroy_alpha (MenuItem *item)
{
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
debug (RPT_DEBUG, "%s( item=[%s] )",
__FUNCTION__, ((item != NULL) ? item->id : "(null)"));
if (item != NULL) {
/* These strings should always be allocated */
free (item->data.alpha.allowed_extra);
free (item->data.alpha.value);
free (item->data.alpha.edit_str);
}
}
/******** MENU ITEM RESET FUNCTIONS ********/
void menuitem_reset (MenuItem *item)
{
void (*func) (MenuItem *);
debug (RPT_DEBUG, "%s( item=[%s] )",
__FUNCTION__, ((item != NULL) ? item->id : "(null)"));
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
if (item != NULL) {
void (*func) (MenuItem *);
/* First destroy type specific data */
func = reset_table[item->type];
if (func)
func (item);
}
}
void menuitem_reset_numeric (MenuItem *item)
{
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
debug (RPT_DEBUG, "%s( item=[%s] )",
__FUNCTION__, ((item != NULL) ? item->id : "(null)"));
if (item != NULL) {
item->data.numeric.edit_pos = 0;
memset ( item->data.numeric.edit_str, 0, MAX_NUMERIC_LEN);
if (item->data.numeric.minvalue < 0) {
snprintf (item->data.numeric.edit_str, MAX_NUMERIC_LEN, "%+d", item->data.numeric.value);
snprintf (item->data.numeric.edit_str, MAX_NUMERIC_LEN,
"%+d", item->data.numeric.value);
} else {
snprintf (item->data.numeric.edit_str, MAX_NUMERIC_LEN, "%d", item->data.numeric.value);
snprintf (item->data.numeric.edit_str, MAX_NUMERIC_LEN,
"%d", item->data.numeric.value);
}
}
}
void menuitem_reset_alpha (MenuItem *item)
{
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
debug (RPT_DEBUG, "%s( item=[%s] )",
__FUNCTION__, ((item != NULL) ? item->id : "(null)"));
if (item != NULL) {
item->data.alpha.edit_pos = 0;
memset (item->data.alpha.edit_str, 0, item->data.alpha.maxlength+1);
strcpy (item->data.alpha.edit_str, item->data.alpha.value);
}
}
@@ -356,7 +400,9 @@ void menuitem_rebuild_screen (MenuItem *item, Screen *s)
Widget * w;
void (*build_screen) (MenuItem *item, Screen *s);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if (!display_props) {
/* Nothing to build if no display size is known */
@@ -364,8 +410,9 @@ void menuitem_rebuild_screen (MenuItem *item, Screen *s)
return;
}
if (s != NULL) {
/* First remove all widgets from the screen */
while ( (w = screen_getfirst_widget(s)) ) {
while ( (w = screen_getfirst_widget(s)) != NULL) {
/* We know these widgets don't have subwidgets, so we can
* easily remove them
*/
@@ -373,6 +420,7 @@ void menuitem_rebuild_screen (MenuItem *item, Screen *s)
widget_destroy (w);
}
if (item != NULL) {
/* Call type specific screen building function */
build_screen = build_screen_table [item->type];
if (build_screen) {
@@ -384,13 +432,17 @@ void menuitem_rebuild_screen (MenuItem *item, Screen *s)
/* Also always call update_screen */
menuitem_update_screen (item, s);
}
}
}
void menuitem_rebuild_screen_slider (MenuItem *item, Screen *s)
{
Widget * w;
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if (display_props->height >= 2 ) {
/* Only add a title if enough space... */
@@ -438,7 +490,9 @@ void menuitem_rebuild_screen_numeric (MenuItem *item, Screen *s)
{
Widget * w;
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if (display_props->height >= 2 ) {
/* Only add a title if enough space... */
@@ -469,7 +523,9 @@ void menuitem_rebuild_screen_alpha (MenuItem *item, Screen *s)
{
Widget * w;
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if (display_props->height >= 2 ) {
/* Only add a title if enough space... */
@@ -502,7 +558,12 @@ void menuitem_update_screen (MenuItem *item, Screen *s)
{
void (*update_screen) (MenuItem *item, Screen *s);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if ((item == NULL) || (s == NULL))
return;
/* Disable the cursor by default */
s->cursor = CURSOR_OFF;
@@ -522,7 +583,12 @@ void menuitem_update_screen_slider (MenuItem *item, Screen *s)
Widget * w;
int min_len, max_len;
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if ((item == NULL) || (s == NULL))
return;
/* Calculate the bar position and length by filling buffers */
min_len = strlen (item->data.slider.mintext);
@@ -559,7 +625,12 @@ void menuitem_update_screen_numeric (MenuItem *item, Screen *s)
{
Widget * w;
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if ((item == NULL) || (s == NULL))
return;
w = screen_find_widget (s, "value");
strcpy (w->text, item->data.numeric.edit_str);
@@ -580,7 +651,12 @@ void menuitem_update_screen_alpha (MenuItem *item, Screen *s)
{
Widget * w;
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if ((item == NULL) || (s == NULL))
return;
w = screen_find_widget (s, "value");
if (item->data.alpha.password_char == 0) {
@@ -608,7 +684,11 @@ MenuResult menuitem_process_input (MenuItem *item, MenuToken token, char * key)
{
MenuResult (*process_input) (MenuItem *item, MenuToken token, char * key);
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), token, key);
if (item == NULL)
return MENURESULT_ERROR;
/* Call type specific screen building function */
process_input = process_input_table [item->type];
@@ -622,7 +702,11 @@ MenuResult menuitem_process_input (MenuItem *item, MenuToken token, char * key)
MenuResult menuitem_process_input_slider (MenuItem *item, MenuToken token, char * key)
{
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), token, key);
if (item == NULL)
return MENURESULT_ERROR;
switch (token) {
case MENUTOKEN_MENU:
@@ -653,21 +737,18 @@ MenuResult menuitem_process_input_numeric (MenuItem *item, MenuToken token, char
char buf1[MAX_NUMERIC_LEN];
char buf2[MAX_NUMERIC_LEN];
char *format_str;
int max_len;
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), token, key);
if (item != NULL) {
/* To make life easy... */
char *str = item->data.numeric.edit_str;
int pos = item->data.numeric.edit_pos;
int allow_signed = (item->data.numeric.minvalue < 0);
char *format_str = (allow_signed) ? "%+d" : "%d";
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
if (allow_signed) {
format_str = "%+d";
} else {
format_str = "%d";
}
snprintf (buf1, MAX_NUMERIC_LEN, format_str, item->data.numeric.minvalue);
snprintf (buf2, MAX_NUMERIC_LEN, format_str, item->data.numeric.maxvalue);
@@ -689,7 +770,7 @@ MenuResult menuitem_process_input_numeric (MenuItem *item, MenuToken token, char
}
return MENURESULT_NONE;
case MENUTOKEN_ENTER:
if (str[pos] == 0) {
if (str[pos] == '\0') {
int value;
/* The user completed his input */
@@ -773,13 +854,14 @@ MenuResult menuitem_process_input_numeric (MenuItem *item, MenuToken token, char
item->data.numeric.edit_pos = 0;
return MENURESULT_NONE;
}
/* proces numeric keys */
/* process numeric keys */
if ( strlen(key) == 1 && key[0] >= '0' && key[0] <= '9') {
str[pos] = key[0];
item->data.numeric.edit_pos ++;
}
return MENURESULT_NONE;
}
}
return MENURESULT_ERROR;
}
@@ -788,12 +870,14 @@ MenuResult menuitem_process_input_alpha (MenuItem *item, MenuToken token, char *
char * p;
static char * chars = NULL;
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), token, key);
if (item != NULL) {
/* To make life easy... */
char *str = item->data.alpha.edit_str;
int pos = item->data.alpha.edit_pos;
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
/* Create list of allowed chars */
chars = realloc (chars, 26 + 26 + 10 + strlen(item->data.alpha.allowed_extra) + 1);
chars[0] = 0; /* clear string */
@@ -905,18 +989,21 @@ MenuResult menuitem_process_input_alpha (MenuItem *item, MenuToken token, char *
}
return MENURESULT_NONE;
}
}
return MENURESULT_ERROR;
}
LinkedList * tablist2linkedlist (char *strings)
{
char *tabptr, *p, *new_s;
LinkedList * list;
list = LL_new();
/* Parse strings */
p = strings;
if (strings != NULL) {
char *p = strings;
char *tabptr, *new_s;
while ((tabptr = strchr(p, '\t')) != NULL) {
int len = (int)(tabptr - p);
@@ -933,49 +1020,50 @@ LinkedList * tablist2linkedlist (char *strings)
/* Add last string */
new_s = strdup (p);
LL_Push (list, new_s);
}
return list;
}
MenuItemType menuitem_typename_to_type (char *name)
{
if (name != NULL) {
MenuItemType type;
for (type = 0; type < NUM_ITEMTYPES; type ++) {
if (strcmp (menuitemtypenames[type], name) == 0) {
return type;
}
}
}
return -1;
}
char *menuitem_type_to_typename (MenuItemType type)
{
if (type >= 0 && type < NUM_ITEMTYPES) {
return menuitemtypenames[type];
}
else {
return NULL;
}
return ((type >= 0 && type < NUM_ITEMTYPES)
? menuitemtypenames[type]
: NULL);
}
MenuEventType menuitem_eventtypename_to_eventtype (char *name)
{
if (name != NULL) {
MenuEventType type;
for (type = 0; type < NUM_EVENTTYPES; type ++) {
if (strcmp (menueventtypenames[type], name) == 0) {
return type;
}
}
}
return -1;
}
char *menuitem_eventtype_to_eventtypename (MenuEventType type)
{
if (type >= 0 && type < NUM_EVENTTYPES) {
return menueventtypenames[type];
}
else {
return NULL;
}
return ((type >= 0 && type < NUM_EVENTTYPES)
? menueventtypenames[type]
: NULL);
}
+6 -2
View File
@@ -65,12 +65,16 @@ int screen_remove_widget (Screen * s, Widget * w);
/* List functions */
static inline Widget * screen_getfirst_widget (Screen * s)
{
return LL_GetFirst(s->widgetlist);
return (Widget *) ((s != NULL)
? LL_GetFirst(s->widgetlist)
: NULL);
}
static inline Widget * screen_getnext_widget (Screen * s)
{
return LL_GetNext(s->widgetlist);
return (Widget *) ((s != NULL)
? LL_GetNext(s->widgetlist)
: NULL);
}