Skip to content

Commit

Permalink
Workaround for 2 sonarcloud complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaro authored and brndnmtthws committed Aug 8, 2018
1 parent 3895971 commit 37a85ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
22 changes: 14 additions & 8 deletions src/audacious.cc
Expand Up @@ -228,17 +228,23 @@ double audacious_barval(struct text_object *) {
AUDACIOUS_TIME_GENERATOR(length)
AUDACIOUS_TIME_GENERATOR(position)

#define AUDACIOUS_INT_GENERATOR(name, offset) \
#define AUDACIOUS_INT_GENERATOR_0(name) \
void print_audacious_##name(struct text_object *, char *p, \
unsigned int p_max_size) { \
snprintf(p, p_max_size, "%d", get_res().name + offset); \
snprintf(p, p_max_size, "%d", get_res().name); \
}

#define AUDACIOUS_INT_GENERATOR_1(name) \
void print_audacious_##name(struct text_object *, char *p, \
unsigned int p_max_size) { \
snprintf(p, p_max_size, "%d", get_res().name + 1); \
}

AUDACIOUS_INT_GENERATOR(bitrate, 0)
AUDACIOUS_INT_GENERATOR(frequency, 0)
AUDACIOUS_INT_GENERATOR(channels, 0)
AUDACIOUS_INT_GENERATOR(playlist_length, 0)
AUDACIOUS_INT_GENERATOR(playlist_position, 1)
AUDACIOUS_INT_GENERATOR(main_volume, 0)
AUDACIOUS_INT_GENERATOR_0(bitrate)
AUDACIOUS_INT_GENERATOR_0(frequency)
AUDACIOUS_INT_GENERATOR_0(channels)
AUDACIOUS_INT_GENERATOR_0(playlist_length)
AUDACIOUS_INT_GENERATOR_1(playlist_position)
AUDACIOUS_INT_GENERATOR_0(main_volume)

#undef AUDACIOUS_PRINT_GENERATOR
26 changes: 21 additions & 5 deletions src/x11.cc
Expand Up @@ -1296,17 +1296,33 @@ void xpmdb_swap_buffers(void) {
}
#endif /* BUILD_XDBE */

#define LOCK_TEMPLATE(func, num) \
#define LOCK_TEMPLATE_1(func) \
void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \
(void)obj; \
XKeyboardState x; \
XGetKeyboardControl(display, &x); \
snprintf(p, p_max_size, "%s", (x.led_mask & num ? "On" : "Off")); \
snprintf(p, p_max_size, "%s", (x.led_mask & 1 ? "On" : "Off")); \
}

LOCK_TEMPLATE(num_led, 2)
LOCK_TEMPLATE(caps_led, 1)
LOCK_TEMPLATE(scroll_led, 4)
#define LOCK_TEMPLATE_2(func) \
void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \
(void)obj; \
XKeyboardState x; \
XGetKeyboardControl(display, &x); \
snprintf(p, p_max_size, "%s", (x.led_mask & 2 ? "On" : "Off")); \
}

#define LOCK_TEMPLATE_4(func) \
void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \
(void)obj; \
XKeyboardState x; \
XGetKeyboardControl(display, &x); \
snprintf(p, p_max_size, "%s", (x.led_mask & 4 ? "On" : "Off")); \
}

LOCK_TEMPLATE_2(num_led)
LOCK_TEMPLATE_1(caps_led)
LOCK_TEMPLATE_4(scroll_led)

void print_kb_layout(struct text_object *obj, char *p, unsigned int p_max_size) {
(void)obj;
Expand Down

0 comments on commit 37a85ad

Please sign in to comment.