tmisu

Notification to stdout daemon
git clone https://git.inz.fi/tmisu/
Log | Files | Refs | README | LICENSE

commit d5677e6c44a774aa36b698dcdab4760f2524e013
parent e9b47710d8bfc5300f00b5088ee569be56ffd261
Author: Sweets <sweets@comfi.es>
Date:   Sat,  3 Oct 2020 20:37:48 -0700

Merge pull request #19 from MarkusG/master

Add unknown type formatter to hints_output_iterator()
Diffstat:
Msrc/output.c | 19+++++++++++++------
Msrc/output.h | 2+-
2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/output.c b/src/output.c @@ -72,7 +72,8 @@ void output_notification(GVariant *parameters) { void hints_output_iterator(GVariant *hints, const char *str_format, const char *int_format, const char *uint_format, const char *double_format, const char *boolean_format, - const char *byte_format, const char *element_delimiter) { + const char *byte_format, const char *err_format, + const char *element_delimiter) { GVariantIter iterator; gchar *key; @@ -85,7 +86,6 @@ void hints_output_iterator(GVariant *hints, const char *str_format, while (g_variant_iter_loop(&iterator, "{sv}", &key, NULL)) { if (index) printf(element_delimiter); - /* Strings */ if ((value = g_variant_lookup_value(hints, key, GT_STRING))) { value_sanitized = sanitize(g_variant_get_string(value, NULL)); @@ -115,8 +115,12 @@ void hints_output_iterator(GVariant *hints, const char *str_format, /* Booleans */ else if ((value = g_variant_lookup_value(hints, key, GT_BOOL))) printf(boolean_format, key, g_variant_get_boolean(value)); - else + else { + // value is of unknown type + printf(err_format, key); + index++; continue; + } g_variant_unref(value); index++; @@ -140,7 +144,8 @@ void default_output(gchar *app_name, gchar *app_icon, guint32 replaces_id, *uint_format = calloc(64, sizeof(char)), *double_format = calloc(64, sizeof(char)), *boolean_format = calloc(64, sizeof(char)), - *byte_format = calloc(64, sizeof(char)); + *byte_format = calloc(64, sizeof(char)), + *err_format = calloc(64, sizeof(char)); sprintf(str_format, "\t%%s: %%s%s", delimiter); sprintf(int_format, "\t%%s: %%d%s", delimiter); @@ -148,10 +153,11 @@ void default_output(gchar *app_name, gchar *app_icon, guint32 replaces_id, sprintf(double_format, "\t%%s: %%f%s", delimiter); sprintf(boolean_format, "\t%%s: %%x%s", delimiter); sprintf(byte_format, "\t%%s: %%d%s", delimiter); + sprintf(err_format, "\t%%s:%s", delimiter); hints_output_iterator(hints, str_format, int_format, uint_format, double_format, boolean_format, - byte_format, ""); + byte_format, err_format, ""); free(str_format); free(int_format); @@ -159,6 +165,7 @@ void default_output(gchar *app_name, gchar *app_icon, guint32 replaces_id, free(double_format); free(boolean_format); free(byte_format); + free(err_format); printf("actions:%s", delimiter); @@ -186,7 +193,7 @@ void json_output(gchar *app_name, gchar *app_icon, guint32 replaces_id, printf("\"hints\": {"); hints_output_iterator(hints, "\"%s\": \"%s\"", "\"%s\": %d", "\"%s\": %u", - "\"%s\": %f", "\"%s\": %x", "\"%s\": %d", ", "); + "\"%s\": %f", "\"%s\": %x", "\"%s\": %d", "\"%s\": \"\"", ", "); printf("}, \"actions\": {"); unsigned int index = 0; diff --git a/src/output.h b/src/output.h @@ -18,7 +18,7 @@ char *sanitize(const char*); void output_notification(GVariant*); void hints_output_iterator(GVariant*, const char*, const char*, const char*, - const char*, const char*, const char*, const char*); + const char*, const char*, const char*, const char*, const char*); void default_output(gchar*, gchar*, guint32, gint32, GVariant*, gchar**, gchar*, gchar*); void json_output(gchar*, gchar*, guint32, gint32, GVariant*, gchar**, gchar*,