summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e7e9bcb)
raw | patch | inline | side by side (parent: e7e9bcb)
author | Max Kellermann <max@duempel.org> | |
Wed, 17 Sep 2008 10:08:03 +0000 (12:08 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 17 Sep 2008 10:08:03 +0000 (12:08 +0200) |
Since the number of screens is known at compile time, define a macro
which calculates this, instead of having a sentinel element.
which calculates this, instead of having a sentinel element.
src/screen.c | patch | blob | history |
diff --git a/src/screen.c b/src/screen.c
index 3395255233ae9d4f3c7484448a18d8ab208f50ff..a55b2cf825e3ed3f6218ecf295d86f1f61f59b27 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
#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;
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;
}
/* 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;
int
screen_exit(void)
{
- gint i;
+ guint i;
endwin();
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);
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) {
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);
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)