diff options
| author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-30 22:46:25 +1000 | 
|---|---|---|
| committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-30 22:46:25 +1000 | 
| commit | e396af853b01438f7e5ef34bfa6fd2507d11ce5a (patch) | |
| tree | 323739dc80680dd774acfdcf43eb76cfe93aa64c /swaymsg/main.c | |
| parent | fc6fde7d90ee031539252cb8832e11c38cfed686 (diff) | |
| parent | 9ba72433b6c87086f2772405e09e8ac8c0136a01 (diff) | |
| download | sway-e396af853b01438f7e5ef34bfa6fd2507d11ce5a.tar.xz | |
Merge remote-tracking branch 'upstream/master' into atomic
Diffstat (limited to 'swaymsg/main.c')
| -rw-r--r-- | swaymsg/main.c | 23 | 
1 files changed, 17 insertions, 6 deletions
| diff --git a/swaymsg/main.c b/swaymsg/main.c index 29f2a907..4283bf00 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -19,30 +19,40 @@ void sway_terminate(int exit_code) {  	exit(exit_code);  } +static bool success_object(json_object *result) { +	json_object *success; + +	if (!json_object_object_get_ex(result, "success", &success)) { +		return false; +	} + +	return json_object_get_boolean(success); +} +  // Iterate results array and return false if any of them failed  static bool success(json_object *r, bool fallback) {  	if (!json_object_is_type(r, json_type_array)) {  		return fallback;  	} +  	size_t results_len = json_object_array_length(r);  	if (!results_len) {  		return fallback;  	} +  	for (size_t i = 0; i < results_len; ++i) {  		json_object *result = json_object_array_get_idx(r, i); -		json_object *success; -		if (!json_object_object_get_ex(result, "success", &success)) { -			return false; -		} -		if (!json_object_get_boolean(success)) { + +		if (!success_object(result)) {  			return false;  		}  	} +  	return true;  }  static void pretty_print_cmd(json_object *r) { -	if (!success(r, true)) { +	if (!success_object(r)) {  		json_object *error;  		if (!json_object_object_get_ex(r, "error", &error)) {  			printf("An unknkown error occurred"); @@ -402,6 +412,7 @@ int main(int argc, char **argv) {  	} else {  		sway_abort("Unknown message type %s", cmdtype);  	} +  	free(cmdtype);  	char *command = NULL; | 
