]> git.sur5r.net Git - i3/i3/commitdiff
use designated initializers for yajl_callbacks struct
authorAlexander Kedrik <alexander.kedrik@gmail.com>
Wed, 1 Jan 2014 16:19:55 +0000 (20:19 +0400)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 6 Jan 2014 21:12:14 +0000 (22:12 +0100)
i3-msg/main.c
i3bar/src/child.c
i3bar/src/config.c
i3bar/src/mode.c
i3bar/src/outputs.c
i3bar/src/parse_json_header.c
i3bar/src/workspaces.c
src/display_version.c
src/ipc.c
src/key_press.c
src/load_layout.c

index 11a31972eb1d002b4e83647511d980d495be98a4..513f28920bf71ea65b337bd4d576dbdc18193167 100644 (file)
@@ -118,18 +118,12 @@ static int reply_map_key_cb(void *params, const unsigned char *keyVal, unsigned
     return 1;
 }
 
-yajl_callbacks reply_callbacks = {
-    NULL,
-    &reply_boolean_cb,
-    NULL,
-    NULL,
-    NULL,
-    &reply_string_cb,
-    &reply_start_map_cb,
-    &reply_map_key_cb,
-    &reply_end_map_cb,
-    NULL,
-    NULL
+static yajl_callbacks reply_callbacks = {
+    .yajl_boolean = reply_boolean_cb,
+    .yajl_string = reply_string_cb,
+    .yajl_start_map = reply_start_map_cb,
+    .yajl_map_key = reply_map_key_cb,
+    .yajl_end_map = reply_end_map_cb,
 };
 
 int main(int argc, char *argv[]) {
index 3621234c55a0f5a2c28d309e4a9c699ffa361609..6c1c17f2136e96bd055ba70d5720b8adf1d5c85b 100644 (file)
@@ -35,7 +35,6 @@ ev_io    *stdin_io;
 ev_child *child_sig;
 
 /* JSON parser for stdin */
-yajl_callbacks callbacks;
 yajl_handle parser;
 
 /* JSON generator for stdout */
@@ -458,15 +457,16 @@ void start_child(char *command) {
         return;
 
     /* Allocate a yajl parser which will be used to parse stdin. */
-    memset(&callbacks, '\0', sizeof(yajl_callbacks));
-    callbacks.yajl_map_key = stdin_map_key;
-    callbacks.yajl_boolean = stdin_boolean;
-    callbacks.yajl_string = stdin_string;
-    callbacks.yajl_integer = stdin_integer;
-    callbacks.yajl_start_array = stdin_start_array;
-    callbacks.yajl_end_array = stdin_end_array;
-    callbacks.yajl_start_map = stdin_start_map;
-    callbacks.yajl_end_map = stdin_end_map;
+    static yajl_callbacks callbacks = {
+        .yajl_boolean = stdin_boolean,
+        .yajl_integer = stdin_integer,
+        .yajl_string = stdin_string,
+        .yajl_start_map = stdin_start_map,
+        .yajl_map_key = stdin_map_key,
+        .yajl_end_map = stdin_end_map,
+        .yajl_start_array = stdin_start_array,
+        .yajl_end_array = stdin_end_array,
+    };
 #if YAJL_MAJOR < 2
     yajl_parser_config parse_conf = { 0, 0 };
 
index dea47b9caa3297256ac9809c9e9dd1c0e2ab50b4..0e6ba3f1b2c7e8687e08235b772b9abf7ba7d51d 100644 (file)
@@ -212,17 +212,10 @@ static int config_boolean_cb(void *params_, int val) {
 
 /* A datastructure to pass all these callbacks to yajl */
 static yajl_callbacks outputs_callbacks = {
-    &config_null_cb,
-    &config_boolean_cb,
-    NULL,
-    NULL,
-    NULL,
-    &config_string_cb,
-    NULL,
-    &config_map_key_cb,
-    NULL,
-    NULL,
-    NULL
+    .yajl_null = config_null_cb,
+    .yajl_boolean = config_boolean_cb,
+    .yajl_string = config_string_cb,
+    .yajl_map_key = config_map_key_cb,
 };
 
 /*
index 7363971a37de4c8c515926f408babae6619b07e4..a34f206004caaceb395a3196f74e5fc2550602b8 100644 (file)
@@ -72,18 +72,9 @@ static int mode_map_key_cb(void *params_, const unsigned char *keyVal, unsigned
 }
 
 /* A datastructure to pass all these callbacks to yajl */
-yajl_callbacks mode_callbacks = {
-    NULL,
-    NULL,
-    NULL,
-    NULL,
-    NULL,
-    &mode_string_cb,
-    NULL,
-    &mode_map_key_cb,
-    NULL,
-    NULL,
-    NULL
+static yajl_callbacks mode_callbacks = {
+    .yajl_string = mode_string_cb,
+    .yajl_map_key = mode_map_key_cb,
 };
 
 /*
index db9867025d86f097e02a06a5c4a14be959b0d8c6..b407df59dd78a83ea99d0ed6058dd15dabbc1d8b 100644 (file)
@@ -248,18 +248,14 @@ static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsign
 }
 
 /* A datastructure to pass all these callbacks to yajl */
-yajl_callbacks outputs_callbacks = {
-    &outputs_null_cb,
-    &outputs_boolean_cb,
-    &outputs_integer_cb,
-    NULL,
-    NULL,
-    &outputs_string_cb,
-    &outputs_start_map_cb,
-    &outputs_map_key_cb,
-    &outputs_end_map_cb,
-    NULL,
-    NULL
+static yajl_callbacks outputs_callbacks = {
+    .yajl_null = outputs_null_cb,
+    .yajl_boolean = outputs_boolean_cb,
+    .yajl_integer = outputs_integer_cb,
+    .yajl_string = outputs_string_cb,
+    .yajl_start_map = outputs_start_map_cb,
+    .yajl_map_key = outputs_map_key_cb,
+    .yajl_end_map = outputs_end_map_cb,
 };
 
 /*
index c09e0f499aaf107bedc0f531dd391483b0dd2622..86afab3a2b64cd0f280837eb55912f6e36223f0d 100644 (file)
@@ -93,20 +93,6 @@ static int header_map_key(void *ctx, const unsigned char *stringval, unsigned in
     return 1;
 }
 
-static yajl_callbacks version_callbacks = {
-    NULL, /* null */
-    &header_boolean, /* boolean */
-    &header_integer,
-    NULL, /* double */
-    NULL, /* number */
-    NULL, /* string */
-    NULL, /* start_map */
-    &header_map_key,
-    NULL, /* end_map */
-    NULL, /* start_array */
-    NULL /* end_array */
-};
-
 static void child_init(i3bar_child *child) {
     child->version = 0;
     child->stop_signal = SIGSTOP;
@@ -122,6 +108,12 @@ static void child_init(i3bar_child *child) {
  *
  */
 void parse_json_header(i3bar_child *child, const unsigned char *buffer, int length, unsigned int *consumed) {
+    static yajl_callbacks version_callbacks = {
+        .yajl_boolean = header_boolean,
+        .yajl_integer = header_integer,
+        .yajl_map_key = &header_map_key,
+    };
+
     child_init(child);
 
     current_key = NO_KEY;
index 5e01b98d8257e011166adcfe04d8f052a425b575..e07a4303d753a2ec82395d6d959b4be5e6595dc4 100644 (file)
@@ -198,18 +198,12 @@ static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, uns
 }
 
 /* A datastructure to pass all these callbacks to yajl */
-yajl_callbacks workspaces_callbacks = {
-    NULL,
-    &workspaces_boolean_cb,
-    &workspaces_integer_cb,
-    NULL,
-    NULL,
-    &workspaces_string_cb,
-    &workspaces_start_map_cb,
-    &workspaces_map_key_cb,
-    NULL,
-    NULL,
-    NULL
+static yajl_callbacks workspaces_callbacks = {
+    .yajl_boolean = workspaces_boolean_cb,
+    .yajl_integer = workspaces_integer_cb,
+    .yajl_string = workspaces_string_cb,
+    .yajl_start_map = workspaces_start_map_cb,
+    .yajl_map_key = workspaces_map_key_cb,
 };
 
 /*
index 73bc54d11084c74c8fad8f8380b3f74d86e44ec7..da667ffa30d5a1ebf60e1caf942e28c85d0cce4e 100644 (file)
@@ -42,17 +42,8 @@ static int version_map_key(void *ctx, const unsigned char *stringval, unsigned i
 }
 
 static yajl_callbacks version_callbacks = {
-    NULL, /* null */
-    NULL, /* boolean */
-    NULL, /* integer */
-    NULL, /* double */
-    NULL, /* number */
-    &version_string,
-    NULL, /* start_map */
-    &version_map_key,
-    NULL, /* end_map */
-    NULL, /* start_array */
-    NULL /* end_array */
+    .yajl_string = version_string,
+    .yajl_map_key = version_map_key,
 };
 
 /*
index b907e4ec6bdf57579880d365b9dd04df0b290b8e..355c14a231700d37b5785d6a88d39c2810573e30 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -827,7 +827,6 @@ static int add_subscription(void *extra, const unsigned char *s,
  */
 IPC_HANDLER(subscribe) {
     yajl_handle p;
-    yajl_callbacks callbacks;
     yajl_status stat;
     ipc_client *current, *client = NULL;
 
@@ -846,8 +845,9 @@ IPC_HANDLER(subscribe) {
     }
 
     /* Setup the JSON parser */
-    memset(&callbacks, 0, sizeof(yajl_callbacks));
-    callbacks.yajl_string = add_subscription;
+    static yajl_callbacks callbacks = {
+        .yajl_string = add_subscription,
+    };
 
     p = yalloc(&callbacks, (void*)client);
     stat = yajl_parse(p, (const unsigned char*)message, message_size);
index 2f77a2a4da31b56e2bfcb8311ea1f90380e2658a..b8c8cd27b5213b31a93cc55df3be8e83eea1ff18 100644 (file)
@@ -51,17 +51,10 @@ static int json_end_map(void *ctx) {
 }
 
 static yajl_callbacks command_error_callbacks = {
-    NULL,
-    &json_boolean,
-    NULL,
-    NULL,
-    NULL,
-    NULL,
-    &json_start_map,
-    &json_map_key,
-    &json_end_map,
-    NULL,
-    NULL
+    .yajl_boolean = json_boolean,
+    .yajl_start_map = json_start_map,
+    .yajl_map_key = json_map_key,
+    .yajl_end_map = json_end_map,
 };
 
 /*
index 3aa96322b4e4a2ad0d32a11b23d67a810712d9de..627c1f6eb1bdc46efa79e6c27f5aa4af6d99d51a 100644 (file)
@@ -417,16 +417,16 @@ void tree_append_json(const char *filename, char **errormsg) {
     LOG("read %d bytes\n", n);
     yajl_gen g;
     yajl_handle hand;
-    yajl_callbacks callbacks;
-    memset(&callbacks, '\0', sizeof(yajl_callbacks));
-    callbacks.yajl_start_map = json_start_map;
-    callbacks.yajl_end_map = json_end_map;
-    callbacks.yajl_end_array = json_end_array;
-    callbacks.yajl_string = json_string;
-    callbacks.yajl_map_key = json_key;
-    callbacks.yajl_integer = json_int;
-    callbacks.yajl_double = json_double;
-    callbacks.yajl_boolean = json_bool;
+    static yajl_callbacks callbacks = {
+        .yajl_boolean = json_bool,
+        .yajl_integer = json_int,
+        .yajl_double = json_double,
+        .yajl_string = json_string,
+        .yajl_start_map = json_start_map,
+        .yajl_map_key = json_key,
+        .yajl_end_map = json_end_map,
+        .yajl_end_array = json_end_array,
+    };
 #if YAJL_MAJOR >= 2
     g = yajl_gen_alloc(NULL);
     hand = yajl_alloc(&callbacks, NULL, (void*)g);