aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-17 12:08:03 +0200
committerMax Kellermann <max@duempel.org>2008-09-17 12:08:03 +0200
commit2cbb38814a0e883563e743031dbde58b83b90749 (patch)
tree20be4eff3e61925bbd5957cc6dd0106eb9608c1a
parente7e9bcbe5f33eb13e14a2b053643b0de33892757 (diff)
downloadmpd-2cbb38814a0e883563e743031dbde58b83b90749.tar.gz
mpd-2cbb38814a0e883563e743031dbde58b83b90749.tar.xz
mpd-2cbb38814a0e883563e743031dbde58b83b90749.zip
screen: added macro NUM_SCREENS
Since the number of screens is known at compile time, define a macro which calculates this, instead of having a sentinel element.
-rw-r--r--src/screen.c41
1 files changed, 16 insertions, 25 deletions
diff --git a/src/screen.c b/src/screen.c
index 339525523..a55b2cf82 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -93,9 +93,10 @@ static const struct
#ifdef ENABLE_LYRICS_SCREEN
{ SCREEN_LYRICS_ID, "lyrics", &screen_lyrics },
#endif
- { G_MAXINT, NULL, NULL }
};
+#define NUM_SCREENS (sizeof(screens) / sizeof(screens[0]))
+
static gboolean welcome = TRUE;
static struct screen screen;
static const struct screen_functions *mode_fn = &screen_playlist;
@@ -105,26 +106,24 @@ static int seek_target_time = 0;
gint
screen_get_id(const char *name)
{
- gint i=0;
+ guint i;
- while (screens[i].name) {
+ for (i = 0; i < NUM_SCREENS; ++i)
if (strcmp(name, screens[i].name) == 0)
return screens[i].id;
- i++;
- }
+
return -1;
}
static gint
lookup_mode(gint id)
{
- gint i=0;
+ guint i;
- while (screens[i].name) {
+ for (i = 0; i < NUM_SCREENS; ++i)
if (screens[i].id == id)
return i;
- i++;
- }
+
return -1;
}
@@ -147,7 +146,7 @@ switch_screen_mode(gint id, mpdclient_t *c)
/* get functions for the new mode */
new_mode = lookup_mode(id);
- if (new_mode >= 0 && screens[new_mode].functions) {
+ if (new_mode >= 0) {
D("switch_screen(%s)\n", screens[new_mode].name );
mode_fn = screens[new_mode].functions;
screen.mode = new_mode;
@@ -417,7 +416,7 @@ paint_status_window(mpdclient_t *c)
int
screen_exit(void)
{
- gint i;
+ guint i;
endwin();
@@ -425,14 +424,11 @@ screen_exit(void)
mode_fn->close();
/* close and exit all screens (playlist,browse,help...) */
- i=0;
- while (screens[i].functions) {
+ for (i = 0; i < NUM_SCREENS; ++i) {
const struct screen_functions *sf = screens[i].functions;
if (sf->exit)
sf->exit();
-
- i++;
}
string_list_free(screen.find_history);
@@ -445,7 +441,7 @@ screen_exit(void)
void
screen_resize(void)
{
- gint i;
+ guint i;
D("Resize rows %d->%d, cols %d->%d\n",screen.rows,LINES,screen.cols,COLS);
if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
@@ -484,16 +480,14 @@ screen_resize(void)
screen.buf = g_malloc(screen.cols);
/* close and exit all screens (playlist,browse,help...) */
- i=0;
- while (screens[i].functions) {
+ for (i = 0; i < NUM_SCREENS; ++i) {
const struct screen_functions *sf = screens[i].functions;
if (sf->resize)
sf->resize(screen.main_window.cols, screen.main_window.rows);
-
- i++;
}
+
/* ? - without this the cursor becomes visible with aterm & Eterm */
curs_set(1);
curs_set(0);
@@ -629,19 +623,16 @@ ncurses_init(void)
int
screen_init(mpdclient_t *c)
{
- gint i;
+ guint i;
/* initialize screens */
- i=0;
- while (screens[i].functions) {
+ for (i = 0; i < NUM_SCREENS; ++i) {
const struct screen_functions *fn = screens[i].functions;
if (fn->init)
fn->init(screen.main_window.w,
screen.main_window.cols,
screen.main_window.rows);
-
- i++;
}
if (mode_fn->open != NULL)