~leon_plickat/wlopm

ec680722d4adb18e0d43e048cc2d31c0e688ce88 — Leon Henrik Plickat 3 years ago fec8a5d
Use function for json error messages
1 files changed, 13 insertions(+), 20 deletions(-)

M wlopm.c
M wlopm.c => wlopm.c +13 -20
@@ 201,6 201,17 @@ static char *power_mode_to_string (enum zwlr_output_power_v1_mode mode)
	return mode == ZWLR_OUTPUT_POWER_V1_MODE_ON ? "on" : "off";
}

static void print_json_error (const char *output_name, const char *msg)
{
	fprintf(stdout,
			"%s\n    {\n"
			"      \"output\": \"%s\",\n"
			"      \"error\": \"%s\"\n"
			"    }",
			json_prev ? "," : "", output_name, msg);
	json_prev = true;
}

static void do_operation (struct Operation *operation)
{
	if ( *operation->name == '*' )


@@ 215,16 226,7 @@ static void do_operation (struct Operation *operation)
		if ( output == NULL )
		{
			if (json)
			{
				fprintf(stdout,
						"%s\n    {\n"
						"      \"output\": \"%s\",\n"
						"      \"error\": \"output does not exist\"\n"
						"    }",
						json_prev ? "," : "",
						operation->name);
				json_prev = true;
			}
				print_json_error(operation->name, "output does not exist");
			else
				fprintf(stderr, "ERROR: Output '%s' does not exist.\n",
						operation->name);


@@ 338,16 340,7 @@ static void sync_handle_done (void *data, struct wl_callback *wl_callback, uint3
			if (output->operation_failed)
			{
				if (json)
				{
					fprintf(stdout,
							"%s\n    {\n"
							"      \"output\": \"%s\","
							"      \"error\": \"setting power mode failed\"\n"
							"    }",
							json_prev ? "," : "",
							output->name);
					json_prev = true;
				}
					print_json_error(output->name, "setting power mode failed");
				else
					fprintf(stderr, "ERROR: Setting power mode for output '%s' failed.\n",
							output->name);