i3 - improved tiling WM


use designated initializers for yajl_callbacks struct

Patch status: rejected

Patch by Alexander Kedrik

To apply this patch, use:
curl http://cr.i3wm.org/patch/358/raw.patch | git am

b/i3-msg/main.c

23
@@ -119,17 +119,11 @@ static int reply_map_key_cb(void *params, const unsigned char *keyVal, unsigned
24
 }
25
 
26
 yajl_callbacks reply_callbacks = {
27
-    NULL,
28
-    &reply_boolean_cb,
29
-    NULL,
30
-    NULL,
31
-    NULL,
32
-    &reply_string_cb,
33
-    &reply_start_map_cb,
34
-    &reply_map_key_cb,
35
-    &reply_end_map_cb,
36
-    NULL,
37
-    NULL
38
+    .yajl_boolean = reply_boolean_cb,
39
+    .yajl_string = reply_string_cb,
40
+    .yajl_start_map = reply_start_map_cb,
41
+    .yajl_map_key = reply_map_key_cb,
42
+    .yajl_end_map = reply_end_map_cb,
43
 };
44
 
45
 int main(int argc, char *argv[]) {

b/i3bar/src/child.c

50
@@ -35,7 +35,6 @@ ev_io    *stdin_io;
51
 ev_child *child_sig;
52
 
53
 /* JSON parser for stdin */
54
-yajl_callbacks callbacks;
55
 yajl_handle parser;
56
 
57
 /* JSON generator for stdout */
58
@@ -458,15 +457,16 @@ void start_child(char *command) {
59
         return;
60
 
61
     /* Allocate a yajl parser which will be used to parse stdin. */
62
-    memset(&callbacks, '\0', sizeof(yajl_callbacks));
63
-    callbacks.yajl_map_key = stdin_map_key;
64
-    callbacks.yajl_boolean = stdin_boolean;
65
-    callbacks.yajl_string = stdin_string;
66
-    callbacks.yajl_integer = stdin_integer;
67
-    callbacks.yajl_start_array = stdin_start_array;
68
-    callbacks.yajl_end_array = stdin_end_array;
69
-    callbacks.yajl_start_map = stdin_start_map;
70
-    callbacks.yajl_end_map = stdin_end_map;
71
+    yajl_callbacks callbacks = {
72
+        .yajl_boolean = stdin_boolean,
73
+        .yajl_integer = stdin_integer,
74
+        .yajl_string = stdin_string,
75
+        .yajl_start_map = stdin_start_map,
76
+        .yajl_map_key = stdin_map_key,
77
+        .yajl_end_map = stdin_end_map,
78
+        .yajl_start_array = stdin_start_array,
79
+        .yajl_end_array = stdin_end_array,
80
+    };
81
 #if YAJL_MAJOR < 2
82
     yajl_parser_config parse_conf = { 0, 0 };
83
 

b/i3bar/src/config.c

88
@@ -212,17 +212,10 @@ static int config_boolean_cb(void *params_, int val) {
89
 
90
 /* A datastructure to pass all these callbacks to yajl */
91
 static yajl_callbacks outputs_callbacks = {
92
-    &config_null_cb,
93
-    &config_boolean_cb,
94
-    NULL,
95
-    NULL,
96
-    NULL,
97
-    &config_string_cb,
98
-    NULL,
99
-    &config_map_key_cb,
100
-    NULL,
101
-    NULL,
102
-    NULL
103
+    .yajl_null = config_null_cb,
104
+    .yajl_boolean = config_boolean_cb,
105
+    .yajl_string = config_string_cb,
106
+    .yajl_map_key = config_map_key_cb,
107
 };
108
 
109
 /*

b/i3bar/src/mode.c

114
@@ -73,17 +73,8 @@ static int mode_map_key_cb(void *params_, const unsigned char *keyVal, unsigned
115
 
116
 /* A datastructure to pass all these callbacks to yajl */
117
 yajl_callbacks mode_callbacks = {
118
-    NULL,
119
-    NULL,
120
-    NULL,
121
-    NULL,
122
-    NULL,
123
-    &mode_string_cb,
124
-    NULL,
125
-    &mode_map_key_cb,
126
-    NULL,
127
-    NULL,
128
-    NULL
129
+    .yajl_string = mode_string_cb,
130
+    .yajl_map_key = mode_map_key_cb,
131
 };
132
 
133
 /*

b/i3bar/src/outputs.c

138
@@ -249,17 +249,13 @@ static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsign
139
 
140
 /* A datastructure to pass all these callbacks to yajl */
141
 yajl_callbacks outputs_callbacks = {
142
-    &outputs_null_cb,
143
-    &outputs_boolean_cb,
144
-    &outputs_integer_cb,
145
-    NULL,
146
-    NULL,
147
-    &outputs_string_cb,
148
-    &outputs_start_map_cb,
149
-    &outputs_map_key_cb,
150
-    &outputs_end_map_cb,
151
-    NULL,
152
-    NULL
153
+    .yajl_null = outputs_null_cb,
154
+    .yajl_boolean = outputs_boolean_cb,
155
+    .yajl_integer = outputs_integer_cb,
156
+    .yajl_string = outputs_string_cb,
157
+    .yajl_start_map = outputs_start_map_cb,
158
+    .yajl_map_key = outputs_map_key_cb,
159
+    .yajl_end_map = outputs_end_map_cb,
160
 };
161
 
162
 /*

b/i3bar/src/parse_json_header.c

167
@@ -93,20 +93,6 @@ static int header_map_key(void *ctx, const unsigned char *stringval, unsigned in
168
     return 1;
169
 }
170
 
171
-static yajl_callbacks version_callbacks = {
172
-    NULL, /* null */
173
-    &header_boolean, /* boolean */
174
-    &header_integer,
175
-    NULL, /* double */
176
-    NULL, /* number */
177
-    NULL, /* string */
178
-    NULL, /* start_map */
179
-    &header_map_key,
180
-    NULL, /* end_map */
181
-    NULL, /* start_array */
182
-    NULL /* end_array */
183
-};
184
-
185
 static void child_init(i3bar_child *child) {
186
     child->version = 0;
187
     child->stop_signal = SIGSTOP;
188
@@ -122,6 +108,12 @@ static void child_init(i3bar_child *child) {
189
  *
190
  */
191
 void parse_json_header(i3bar_child *child, const unsigned char *buffer, int length, unsigned int *consumed) {
192
+    static yajl_callbacks version_callbacks = {
193
+        .yajl_boolean = header_boolean,
194
+        .yajl_integer = header_integer,
195
+        .yajl_map_key = &header_map_key,
196
+    };
197
+
198
     child_init(child);
199
 
200
     current_key = NO_KEY;

b/i3bar/src/workspaces.c

205
@@ -199,17 +199,11 @@ static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, uns
206
 
207
 /* A datastructure to pass all these callbacks to yajl */
208
 yajl_callbacks workspaces_callbacks = {
209
-    NULL,
210
-    &workspaces_boolean_cb,
211
-    &workspaces_integer_cb,
212
-    NULL,
213
-    NULL,
214
-    &workspaces_string_cb,
215
-    &workspaces_start_map_cb,
216
-    &workspaces_map_key_cb,
217
-    NULL,
218
-    NULL,
219
-    NULL
220
+    .yajl_boolean = workspaces_boolean_cb,
221
+    .yajl_integer = workspaces_integer_cb,
222
+    .yajl_string = workspaces_string_cb,
223
+    .yajl_start_map = workspaces_start_map_cb,
224
+    .yajl_map_key = workspaces_map_key_cb,
225
 };
226
 
227
 /*

b/src/display_version.c

232
@@ -42,17 +42,8 @@ static int version_map_key(void *ctx, const unsigned char *stringval, unsigned i
233
 }
234
 
235
 static yajl_callbacks version_callbacks = {
236
-    NULL, /* null */
237
-    NULL, /* boolean */
238
-    NULL, /* integer */
239
-    NULL, /* double */
240
-    NULL, /* number */
241
-    &version_string,
242
-    NULL, /* start_map */
243
-    &version_map_key,
244
-    NULL, /* end_map */
245
-    NULL, /* start_array */
246
-    NULL /* end_array */
247
+    .yajl_string = version_string,
248
+    .yajl_map_key = version_map_key,
249
 };
250
 
251
 /*

b/src/ipc.c

256
@@ -815,7 +815,6 @@ static int add_subscription(void *extra, const unsigned char *s,
257
  */
258
 IPC_HANDLER(subscribe) {
259
     yajl_handle p;
260
-    yajl_callbacks callbacks;
261
     yajl_status stat;
262
     ipc_client *current, *client = NULL;
263
 
264
@@ -834,8 +833,9 @@ IPC_HANDLER(subscribe) {
265
     }
266
 
267
     /* Setup the JSON parser */
268
-    memset(&callbacks, 0, sizeof(yajl_callbacks));
269
-    callbacks.yajl_string = add_subscription;
270
+    yajl_callbacks callbacks = {
271
+        .yajl_string = add_subscription,
272
+    };
273
 
274
     p = yalloc(&callbacks, (void*)client);
275
     stat = yajl_parse(p, (const unsigned char*)message, message_size);

b/src/key_press.c

280
@@ -51,17 +51,10 @@ static int json_end_map(void *ctx) {
281
 }
282
 
283
 static yajl_callbacks command_error_callbacks = {
284
-    NULL,
285
-    &json_boolean,
286
-    NULL,
287
-    NULL,
288
-    NULL,
289
-    NULL,
290
-    &json_start_map,
291
-    &json_map_key,
292
-    &json_end_map,
293
-    NULL,
294
-    NULL
295
+    .yajl_boolean = json_boolean,
296
+    .yajl_start_map = json_start_map,
297
+    .yajl_map_key = json_map_key,
298
+    .yajl_end_map = json_end_map,
299
 };
300
 
301
 /*

b/src/load_layout.c

306
@@ -402,16 +402,16 @@ void tree_append_json(const char *filename) {
307
     LOG("read %d bytes\n", n);
308
     yajl_gen g;
309
     yajl_handle hand;
310
-    yajl_callbacks callbacks;
311
-    memset(&callbacks, '\0', sizeof(yajl_callbacks));
312
-    callbacks.yajl_start_map = json_start_map;
313
-    callbacks.yajl_end_map = json_end_map;
314
-    callbacks.yajl_end_array = json_end_array;
315
-    callbacks.yajl_string = json_string;
316
-    callbacks.yajl_map_key = json_key;
317
-    callbacks.yajl_integer = json_int;
318
-    callbacks.yajl_double = json_double;
319
-    callbacks.yajl_boolean = json_bool;
320
+    yajl_callbacks callbacks = {
321
+        .yajl_boolean = json_bool,
322
+        .yajl_integer = json_int,
323
+        .yajl_double = json_double,
324
+        .yajl_string = json_string,
325
+        .yajl_start_map = json_start_map,
326
+        .yajl_map_key = json_key,
327
+        .yajl_end_map = json_end_map,
328
+        .yajl_end_array = json_end_array,
329
+    };
330
 #if YAJL_MAJOR >= 2
331
     g = yajl_gen_alloc(NULL);
332
     hand = yajl_alloc(&callbacks, NULL, (void*)g);