use designated initializers for yajl_callbacks struct

This commit is contained in:
Alexander Kedrik
2014-01-01 20:19:55 +04:00
committed by Michael Stapelberg
parent f1560e5eb6
commit 705b43294a
11 changed files with 58 additions and 114 deletions

View 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;
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 };

View 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,
};
/*

View File

@ -73,17 +73,8 @@ 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
.yajl_string = mode_string_cb,
.yajl_map_key = mode_map_key_cb,
};
/*

View File

@ -249,17 +249,13 @@ 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
.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,
};
/*

View 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;

View File

@ -199,17 +199,11 @@ 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
.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,
};
/*