summaryrefslogtreecommitdiff
path: root/ewmh/ewmh.c.m4
diff options
context:
space:
mode:
authorArnaud Fontaine <arnau@debian.org>2009-12-15 00:27:50 +0100
committerArnaud Fontaine <arfontaine@ITEM-58736.dhcp.oxfd.uk.sopra>2010-02-11 14:47:30 +0000
commit749cb7b570c8dc8d758ffb2cb8bacff6d3994701 (patch)
tree471c8cfffdcb90a90cbc84e96b0ea81e5c7bcc1b /ewmh/ewmh.c.m4
parentc491679ca6734193ccfc967d715f4c71a61ef02e (diff)
Replace all the ugly if statements with a loop
Diffstat (limited to 'ewmh/ewmh.c.m4')
-rw-r--r--ewmh/ewmh.c.m427
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;
}
/**