make debug() the first action in each function

don't fail on NULL pointer arguments in debug()
This commit is contained in:
marschap
2005-03-13 16:32:16 +00:00
parent 75fef67dfe
commit 0de01ac0f7
+51 -37
View File
@@ -59,11 +59,12 @@ menu_create (char *id, MenuEventFunc(*event_func),
void void
menu_destroy (Menu *menu) menu_destroy (Menu *menu)
{ {
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__,
((menu != NULL) ? menu->id : "(null)"));
if (menu == NULL) if (menu == NULL)
return; return;
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
menu_destroy_all_items (menu); menu_destroy_all_items (menu);
LL_Destroy (menu->data.menu.contents); LL_Destroy (menu->data.menu.contents);
menu->data.menu.contents = NULL; menu->data.menu.contents = NULL;
@@ -74,11 +75,13 @@ menu_destroy (Menu *menu)
void void
menu_add_item (Menu *menu, MenuItem *item) menu_add_item (Menu *menu, MenuItem *item)
{ {
debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__,
((menu != NULL) ? menu->id : "(null)"),
((item != NULL) ? item->id : "(null)"));
if ((menu == NULL) || (item == NULL)) if ((menu == NULL) || (item == NULL))
return; return;
debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__, menu->id, item->id);
/* Add the item to the menu */ /* Add the item to the menu */
LL_Push (menu->data.menu.contents, item); LL_Push (menu->data.menu.contents, item);
item->parent = menu; item->parent = menu;
@@ -90,13 +93,15 @@ menu_remove_item (Menu *menu, MenuItem *item)
int i; int i;
MenuItem * item2; MenuItem * item2;
if ((menu == NULL) || (item == NULL)) debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__,
return ((menu != NULL) ? menu->id : "(null)"),
((item != NULL) ? item->id : "(null)"));
debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__, menu->id, item->id); if ((menu == NULL) || (item == NULL))
return;
/* Find the item */ /* Find the item */
for (item2 = LL_GetFirst(menu->data.menu.contents), i=0; for (item2 = LL_GetFirst(menu->data.menu.contents), i = 0;
item2 != NULL; item2 != NULL;
item2 = LL_GetNext(menu->data.menu.contents), i++ ) { item2 = LL_GetNext(menu->data.menu.contents), i++ ) {
if (item == item2) { if (item == item2) {
@@ -116,11 +121,12 @@ menu_destroy_all_items (Menu *menu)
{ {
MenuItem * item; MenuItem * item;
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__,
((menu != NULL) ? menu->id : "(null)"));
if (menu == NULL) if (menu == NULL)
return; return;
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
for( item = menu_getfirst_item(menu); item != NULL; item = menu_getfirst_item(menu) ) { for( item = menu_getfirst_item(menu); item != NULL; item = menu_getfirst_item(menu) ) {
menuitem_destroy (item); menuitem_destroy (item);
LL_Remove (menu->data.menu.contents, item); LL_Remove (menu->data.menu.contents, item);
@@ -131,11 +137,12 @@ MenuItem *menu_find_item (Menu *menu, char *id, bool recursive)
{ {
MenuItem * item; MenuItem * item;
debug (RPT_DEBUG, "%s( menu=[%s], id=\"%s\", recursive=%d )", __FUNCTION__,
((menu != NULL) ? menu->id : "(null)"), id, recursive);
if ((menu == NULL) || (id == NULL)) if ((menu == NULL) || (id == NULL))
return 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 != NULL; item = menu_getnext_item(menu) ) { for( item = menu_getfirst_item(menu); item != NULL; item = menu_getnext_item(menu) ) {
if ( strcmp(item->id, id) == 0 ) { if ( strcmp(item->id, id) == 0 ) {
return item; return item;
@@ -153,11 +160,12 @@ MenuItem *menu_find_item (Menu *menu, char *id, bool recursive)
void menu_reset (Menu *menu) void menu_reset (Menu *menu)
{ {
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__,
((menu != NULL) ? menu->id : "(null)"));
if (menu == NULL) if (menu == NULL)
return; return;
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
menu->data.menu.selector_pos = 0; menu->data.menu.selector_pos = 0;
menu->data.menu.scroll = 0; menu->data.menu.scroll = 0;
} }
@@ -168,11 +176,13 @@ void menu_build_screen (MenuItem *menu, Screen *s)
MenuItem * subitem; MenuItem * subitem;
int itemnr; int itemnr;
debug (RPT_DEBUG, "%s( menu=[%s], screen=[%s] )", __FUNCTION__,
((menu != NULL) ? menu->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if ((menu == NULL) || (s == NULL)) if ((menu == NULL) || (s == NULL))
return; return;
debug (RPT_DEBUG, "%s( menu=[%s], screen=[%s] )", __FUNCTION__, menu->id, s->id);
/* TODO: Put menu in a frame to do easy scrolling */ /* TODO: Put menu in a frame to do easy scrolling */
/* Problem: frames are not handled correctly by renderer */ /* Problem: frames are not handled correctly by renderer */
@@ -278,11 +288,13 @@ void menu_update_screen (MenuItem *menu, Screen *s)
MenuItem * subitem; MenuItem * subitem;
int itemnr; int itemnr;
debug (RPT_DEBUG, "%s( menu=[%s], screen=[%s] )", __FUNCTION__,
((menu != NULL) ? menu->id : "(null)"),
((s != NULL) ? s->id : "(null)"));
if ((menu == NULL) || (s == NULL)) if ((menu == NULL) || (s == NULL))
return; return;
debug (RPT_DEBUG, "%s( menu=[%s], screen=[%s] )", __FUNCTION__, menu->id, s->id);
/* Update widgets for the title */ /* Update widgets for the title */
w = screen_find_widget (s, "title"); w = screen_find_widget (s, "title");
if (!w) report (RPT_ERR, "%s: could not find widget: %s", __FUNCTION__, "title"); if (!w) report (RPT_ERR, "%s: could not find widget: %s", __FUNCTION__, "title");
@@ -368,35 +380,36 @@ void menu_update_screen (MenuItem *menu, Screen *s)
/* Update selector position */ /* Update selector position */
w = screen_find_widget (s, "selector"); w = screen_find_widget (s, "selector");
if (!w) report (RPT_ERR, "%s: could not find widget: %s", __FUNCTION__, "selector"); if (w != NULL)
w->y = 2 + menu->data.menu.selector_pos - menu->data.menu.scroll; w->y = 2 + menu->data.menu.selector_pos - menu->data.menu.scroll;
else
report (RPT_ERR, "%s: could not find widget: %s", __FUNCTION__, "selector");
/* Enable upscroller */ /* Enable upscroller (if necessary) */
w = screen_find_widget (s, "upscroller"); w = screen_find_widget (s, "upscroller");
if (!w) report (RPT_ERR, "%s: could not find widget: %s", __FUNCTION__, "upscroller"); if (w != NULL)
if (menu->data.menu.scroll > 0) { w->type = (menu->data.menu.scroll > 0) ? WID_ICON : WID_NONE;
w->type = WID_ICON; else
} else { report (RPT_ERR, "%s: could not find widget: %s", __FUNCTION__, "upscroller");
w->type = WID_NONE; /* disable it this way */
} /* Enable downscroller (if necessary) */
/* Enable downscroller */
w = screen_find_widget (s, "downscroller"); w = screen_find_widget (s, "downscroller");
if (!w) report (RPT_ERR, "%s: could not find widget: %s", __FUNCTION__, "downscroller"); if (w != NULL)
if (LL_Length(menu->data.menu.contents) - menu->data.menu.scroll - display_props->height + 1 > 0 ) { w->type = (LL_Length(menu->data.menu.contents) >= menu->data.menu.scroll + display_props->height)
w->type = WID_ICON; ? WID_ICON : WID_NONE;
} else { else
w->type = WID_NONE; /* disable it this way */ report (RPT_ERR, "%s: could not find widget: %s", __FUNCTION__, "downscroller");
}
} }
MenuResult menu_process_input (Menu *menu, MenuToken token, char * key) MenuResult menu_process_input (Menu *menu, MenuToken token, char * key)
{ {
MenuItem *subitem; MenuItem *subitem;
debug (RPT_DEBUG, "%s( menu=[%s], token=%d, key=\"%s\" )", __FUNCTION__,
((menu != NULL) ? menu->id : "(null)"), token, key);
if (menu == NULL) if (menu == NULL)
return MENURESULT_ERROR; return MENURESULT_ERROR;
debug (RPT_DEBUG, "%s( menu=[%s], token=%d, key=\"%s\" )", __FUNCTION__, menu->id, token, key);
switch (token) { switch (token) {
case MENUTOKEN_MENU: case MENUTOKEN_MENU:
@@ -404,7 +417,8 @@ MenuResult menu_process_input (Menu *menu, MenuToken token, char * key)
case MENUTOKEN_ENTER: case MENUTOKEN_ENTER:
subitem = LL_GetByIndex (menu->data.menu.contents, subitem = LL_GetByIndex (menu->data.menu.contents,
menu->data.menu.selector_pos); menu->data.menu.selector_pos);
if (!subitem) break; if (!subitem)
break;
switch (subitem->type) { switch (subitem->type) {
case MENUITEM_ACTION: case MENUITEM_ACTION:
if (subitem->event_func) if (subitem->event_func)