From cb9662465a673502429b680137e8a0f49bdcd643 Mon Sep 17 00:00:00 2001 From: Jose Maldonado aka Yukiteru Date: Sun, 25 Aug 2024 01:55:26 -0400 Subject: [PATCH] Fix OpenBSD support and clean code (clang -Wformat errors) --- src/notification.c | 16 ++++++++-------- src/rules.c | 6 +++--- src/utils.c | 12 ++++++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/notification.c b/src/notification.c index 1d2689680..089c9f8e3 100644 --- a/src/notification.c +++ b/src/notification.c @@ -61,9 +61,9 @@ void notification_print(const struct notification *n) printf("\ticon_id: '%s'\n", STR_NN(n->icon_id)); printf("\tdesktop_entry: '%s'\n", n->desktop_entry ? n->desktop_entry : ""); printf("\tcategory: %s\n", STR_NN(n->category)); - printf("\ttimeout: %ld\n", n->timeout/1000); - printf("\tstart: %ld\n", n->start); - printf("\ttimestamp: %ld\n", n->timestamp); + printf("\ttimeout: %lld\n", n->timeout/1000); + printf("\tstart: %lld\n", n->start); + printf("\ttimestamp: %lld\n", n->timestamp); printf("\turgency: %s\n", notification_urgency_to_string(n->urgency)); printf("\ttransient: %d\n", n->transient); printf("\tformatted: '%s'\n", STR_NN(n->msg)); @@ -144,8 +144,8 @@ void notification_run_script(struct notification *n) // Set environment variables gchar *n_id_str = g_strdup_printf("%i", n->id); gchar *n_progress_str = g_strdup_printf("%i", n->progress); - gchar *n_timeout_str = g_strdup_printf("%li", n->timeout/1000); - gchar *n_timestamp_str = g_strdup_printf("%li", n->timestamp / 1000); + gchar *n_timeout_str = g_strdup_printf("%lli", n->timeout/1000); + gchar *n_timestamp_str = g_strdup_printf("%lli", n->timestamp / 1000); safe_setenv("DUNST_APP_NAME", appname); safe_setenv("DUNST_SUMMARY", summary); safe_setenv("DUNST_BODY", body); @@ -713,14 +713,14 @@ void notification_update_text_to_render(struct notification *n) char *new_buf; if (hours > 0) { new_buf = - g_strdup_printf("%s (%ldh %ldm %lds old)", buf, hours, + g_strdup_printf("%s (%lldh %lldm %llds old)", buf, hours, minutes, seconds); } else if (minutes > 0) { new_buf = - g_strdup_printf("%s (%ldm %lds old)", buf, minutes, + g_strdup_printf("%s (%lldm %llds old)", buf, minutes, seconds); } else { - new_buf = g_strdup_printf("%s (%lds old)", buf, seconds); + new_buf = g_strdup_printf("%s (%llds old)", buf, seconds); } g_free(buf); diff --git a/src/rules.c b/src/rules.c index e369cf622..ddd717b24 100644 --- a/src/rules.c +++ b/src/rules.c @@ -139,12 +139,12 @@ void rule_print(const struct rule *r) if (r->msg_urgency != URG_NONE) printf("\tmsg_urgency: '%s'\n", notification_urgency_to_string(r->msg_urgency)); if (r->stack_tag != NULL) printf("\tstack_tag: '%s'\n", r->stack_tag); if (r->desktop_entry != NULL) printf("\tdesktop_entry: '%s'\n", r->desktop_entry); - if (r->match_dbus_timeout != -1) printf("\tmatch_dbus_timeout: %ld\n", r->match_dbus_timeout); + if (r->match_dbus_timeout != -1) printf("\tmatch_dbus_timeout: %lld\n", r->match_dbus_timeout); if (r->match_transient != -1) printf("\tmatch_transient: %d\n", r->match_transient); // modifiers - if (r->timeout != -1) printf("\ttimeout: %ld\n", r->timeout); - if (r->override_dbus_timeout != -1) printf("\toverride_dbus_timeout: %ld\n", r->override_dbus_timeout); + if (r->timeout != -1) printf("\ttimeout: %lld\n", r->timeout); + if (r->override_dbus_timeout != -1) printf("\toverride_dbus_timeout: %lld\n", r->override_dbus_timeout); if (r->markup != -1) printf("\tmarkup: %d\n", r->markup); if (r->action_name != NULL) printf("\taction_name: '%s'\n", r->action_name); if (r->urgency != URG_NONE) printf("\turgency: '%s'\n", notification_urgency_to_string(r->urgency)); diff --git a/src/utils.c b/src/utils.c index e47945717..a4067d44a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -13,7 +13,9 @@ #include #include #include +#ifndef __OpenBSD__ #include +#endif #include "log.h" #include "settings_data.h" @@ -180,6 +182,7 @@ int string_array_length(char **s) /* see utils.h */ char *string_to_path(char *string) { +#ifndef __OpenBSD__ ASSERT_OR_RET(string, string); wordexp_t we; @@ -208,6 +211,15 @@ char *string_to_path(char *string) wordfree(&we); return res; +#else + if (string && STRN_EQ(string, "~/", 2)) { + char *home = g_strconcat(user_get_home(), "/", NULL); + string = string_replace_at(string, 0, 2, home); + g_free(home); + } + + return string; +#endif } /* see utils.h */