From dd8ec48fcbe7fa3dd088fa3de851a44ecc8f58af Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sun, 8 Nov 2009 19:27:01 +0100 Subject: [PATCH] bmpx: convert to callbacks.print While here, also drop those calls to memset, as the whole info object is being zeroed at the beginning of main(). (Probably this is useful upon config reload, too.) --- src/bmpx.c | 17 +++++++++++++++++ src/bmpx.h | 7 +++++++ src/conky.c | 20 -------------------- src/core.c | 12 ++++++------ 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/bmpx.c b/src/bmpx.c index 2e04670e..3c6ebabe 100644 --- a/src/bmpx.c +++ b/src/bmpx.c @@ -145,3 +145,20 @@ void fail(GError *error) current_info->bmpx.bitrate = 0; current_info->bmpx.track = 0; } + +#define BMPX_PRINT_GENERATOR(name, fmt) \ +void print_bmpx_##name(struct text_object *obj, char *p, int p_max_size) \ +{ \ + (void)obj; \ + snprintf(p, p_max_size, fmt, info.bmpx.name); \ +} + +BMPX_PRINT_GENERATOR(title, "%s") +BMPX_PRINT_GENERATOR(artist, "%s") +BMPX_PRINT_GENERATOR(album, "%s") +BMPX_PRINT_GENERATOR(uri, "%s") +BMPX_PRINT_GENERATOR(track, "%i") +BMPX_PRINT_GENERATOR(bitrate, "%i") + +#undef BMPX_PRINT_GENERATOR + diff --git a/src/bmpx.h b/src/bmpx.h index 91064e38..71f9ed0d 100644 --- a/src/bmpx.h +++ b/src/bmpx.h @@ -36,4 +36,11 @@ struct bmpx_s { int track; }; +void print_bmpx_title(struct text_object *, char *, int); +void print_bmpx_artist(struct text_object *, char *, int); +void print_bmpx_album(struct text_object *, char *, int); +void print_bmpx_uri(struct text_object *, char *, int); +void print_bmpx_track(struct text_object *, char *, int); +void print_bmpx_bitrate(struct text_object *, char *, int); + #endif /*BMPX_H_*/ diff --git a/src/conky.c b/src/conky.c index f27a4105..55c582d7 100644 --- a/src/conky.c +++ b/src/conky.c @@ -1636,26 +1636,6 @@ void generate_text_internal(char *p, int p_max_size, } #endif /* XMMS */ -#ifdef BMPX - OBJ(bmpx_title) { - snprintf(p, p_max_size, "%s", cur->bmpx.title); - } - OBJ(bmpx_artist) { - snprintf(p, p_max_size, "%s", cur->bmpx.artist); - } - OBJ(bmpx_album) { - snprintf(p, p_max_size, "%s", cur->bmpx.album); - } - OBJ(bmpx_uri) { - snprintf(p, p_max_size, "%s", cur->bmpx.uri); - } - OBJ(bmpx_track) { - snprintf(p, p_max_size, "%i", cur->bmpx.track); - } - OBJ(bmpx_bitrate) { - snprintf(p, p_max_size, "%i", cur->bmpx.bitrate); - } -#endif /* BMPX */ /* we have four different types of top (top, top_mem, * top_time and top_io). To avoid having almost-same code four * times, we have this special handler. */ diff --git a/src/core.c b/src/core.c index 319041fc..776bbeb5 100644 --- a/src/core.c +++ b/src/core.c @@ -1205,17 +1205,17 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif /* AUDACIOUS */ #ifdef BMPX END OBJ(bmpx_title, &update_bmpx) - memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); + obj->callbacks.print = &print_bmpx_title; END OBJ(bmpx_artist, &update_bmpx) - memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); + obj->callbacks.print = &print_bmpx_artist; END OBJ(bmpx_album, &update_bmpx) - memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); + obj->callbacks.print = &print_bmpx_album; END OBJ(bmpx_track, &update_bmpx) - memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); + obj->callbacks.print = &print_bmpx_track; END OBJ(bmpx_uri, &update_bmpx) - memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); + obj->callbacks.print = &print_bmpx_uri; END OBJ(bmpx_bitrate, &update_bmpx) - memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); + obj->callbacks.print = &print_bmpx_bitrate; #endif #ifdef EVE END OBJ_ARG(eve, 0, "eve needs arguments: ")