diff options
author | Arnaud Fontaine <arnau@debian.org> | 2009-12-15 00:27:50 +0100 |
---|---|---|
committer | Arnaud Fontaine <arnau@debian.org> | 2010-11-14 20:22:29 +0900 |
commit | efdd87e4be6a72fa4c25f71078f773c65c12b659 (patch) | |
tree | c0d653239dc72f2cc7d9bfbd32741d5a395a589e /ewmh | |
parent | ec283ed176d57082028388e0cb1f9fb433836182 (diff) |
Replace all the ugly if statements with a loop
Diffstat (limited to 'ewmh')
-rw-r--r-- | ewmh/ewmh.c.m4 | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/ewmh/ewmh.c.m4 b/ewmh/ewmh.c.m4 index a73cc5b..f1bfe89 100644 --- a/ewmh/ewmh.c.m4 +++ b/ewmh/ewmh.c.m4 @@ -31,6 +31,7 @@ #include <stdlib.h> #include <stdio.h> #include <assert.h> +#include <stddef.h> #include <xcb/xcb.h> #include <xcb/xproto.h> @@ -48,10 +49,11 @@ typedef struct { uint8_t name_len; /** The Atom name string */ char *name; + size_t m_offset; } ewmh_atom_t; define(`DO_ENTRY', ` - { sizeof("$1") - 1, "$1" }ifelse(`$2', , , `,')')dnl + { sizeof("$1") - 1, "$1", offsetof(xcb_ewmh_connection_t, $1) }ifelse(`$2', , , `,')')dnl define(`DO', `DO_ENTRY(`$1', `$2')ifelse(`$2', , , `DO(shift($@))')')dnl @@ -533,23 +535,20 @@ xcb_ewmh_init_atoms_replies(xcb_ewmh_connection_t * const ewmh, xcb_intern_atom_cookie_t *ewmh_cookies, xcb_generic_error_t **e) { - uint8_t i = 0; + uint8_t i, ret = 1; xcb_intern_atom_reply_t *reply; - define(`DO_ENTRY', ` if((reply = xcb_intern_atom_reply(ewmh->connection, ewmh_cookies[i++], e)) == NULL) - goto init_atoms_replies_error; - ewmh->$1 = reply->atom; - free(reply); - -')dnl - include(atomlist.m4)dnl - - free(ewmh_cookies); - return 1; + for(i = 0; i < NB_EWMH_ATOMS; i++) + if((reply = xcb_intern_atom_reply(ewmh->connection, ewmh_cookies[i], e))) + { + *((xcb_atom_t *) (((char *) ewmh) + ewmh_atoms[i].m_offset)) = reply->atom; + free(reply); + } + else + ret = 0; - init_atoms_replies_error: free(ewmh_cookies); - return 0; + return ret; } /** |