Skip to content

Commit

Permalink
Fix OpenBSD support and clean code (clang -Wformat errors)
Browse files Browse the repository at this point in the history
  • Loading branch information
yukiteruamano committed Aug 25, 2024
1 parent caa5770 commit cb96624
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 12 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#ifndef __OpenBSD__
#include <wordexp.h>
#endif

#include "log.h"
#include "settings_data.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit cb96624

Please sign in to comment.