tmisu

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

commit e1e054e6edfca2b0c9d151d05aa795266f5a7cf8
parent 46f780a4116ced91784633de6c37a654e1dac1e4
Author: Sweets <Sweets@users.noreply.github.com>
Date:   Wed,  1 Jul 2020 10:15:07 -0700

make format.c less acoustic
Diffstat:
Mformat.c | 64+++++++++++++++++++++-------------------------------------------
1 file changed, 21 insertions(+), 43 deletions(-)

diff --git a/format.c b/format.c @@ -19,51 +19,29 @@ char* escape_quotes(char *str, char *out) { void output_notification(gchar *app_name, guint32 replaces_id, gchar *app_icon, gchar *summary, gchar *body, GVariant *actions, GVariant *hints, gint32 timeout) { - /* This function will raise warnings. I don't fucking care. */ - - /* 2048 characters should be significantly long enough*/ - char *string = (char *)calloc(2048, sizeof(char)); - -#ifndef PRINT_JSON - strcat(string, app_name); - -#ifdef RECEIVE_APP_ICON - sprintf(string, "%s%s%s", string, OUTPUT_DELIMITER, app_icon); -#endif - - /* TODO: actions */ - /* TODO: hints */ - -#ifdef RECEIVE_REPLACES_ID - sprintf(string, "%s%s%lu", string, OUTPUT_DELIMITER, replaces_id); -#endif - - sprintf(string, "%s%s%d%s%s%s%s", string, OUTPUT_DELIMITER, - timeout, OUTPUT_DELIMITER, summary, OUTPUT_DELIMITER, body); + +#ifdef PRINT_JSON + + char *escaped_string = (char *)calloc(512, sizeof(char)); + + printf("{ \"app_name\": \"%s\",", escape_quotes(app_name, escaped_string)); + printf(" \"app_icon\": \"%s\",", escape_quotes(app_icon, escaped_string)); + printf(" \"replaces_id\": %u, \"timeout\": %d," replaces_id, timeout); + printf(" \"summary\": \"%s\",", escape_quotes(summary, escaped_string)); + printf(" \"body\": \"%s\" }\n", escape_quotes(body, escaped_string)); + + free(escaped_string); + #else - char *escaped_str = (char *)calloc(512, sizeof(char)); - - sprintf(string, "{ \"app_name\": \"%s\"", escape_quotes(app_name, escaped_str)); - free(escaped_str); - -#ifdef RECEIVE_APP_ICON - sprintf(string, "%s, \"app_icon\": \"%s\"", string, escape_quotes(app_icon, escaped_str)); -#endif - - /* TODO: actions */ - /* TODO: hints */ - -#ifdef RECEIVE_REPLACES_ID - sprintf(string, "%s, \"replaces_id\": %lu", string, replaces_id); + + printf("%s%s%s%s%u%s%d%s%s%s%s\n", + app_name, OUTPUT_DELIMITER, + app_icon, OUTPUT_DELIMITER, + replaces_id, OUTPUT_DELIMITER, + timeout, OUTPUT_DELIMITER, + summary, OUTPUT_DELIMITER, body); + #endif - sprintf(string, "%s, \"timeout\": %d, \"summary\": \"%s\"", string, timeout, escape_quotes(summary, escaped_str)); - - sprintf(string, "%s, \"body\": \"%s\" }", string, escape_quotes(body, escaped_str)); -#endif - - printf("%s\n", string); fflush(stdout); - - free(string); }