From f088d75ee4bae12e7bd1297a8eb6a618833636a4 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 15 Mar 2022 01:00:56 +0100 Subject: [PATCH] Cleanup some duplicate checks. --- include/helper.h | 4 ++-- include/mode-private.h | 1 + source/modes/dmenu.c | 2 +- source/modes/drun.c | 6 +++--- source/modes/script.c | 2 +- source/modes/window.c | 2 +- source/theme.c | 12 ++++++------ source/widgets/textbox.c | 4 +--- source/xcb.c | 8 +++----- source/xrmoptions.c | 6 +++--- 10 files changed, 22 insertions(+), 25 deletions(-) diff --git a/include/helper.h b/include/helper.h index b333bd29..83a06970 100644 --- a/include/helper.h +++ b/include/helper.h @@ -149,11 +149,11 @@ int execute_generator(const char *cmd) __attribute__((nonnull)); /** * @param pidfile The pidfile to create. - * @param kill Try killing running instance. + * @param kill_running Try killing running instance. * * returns file descriptor (or -1 when failed) */ -int create_pid_file(const char *pidfile, gboolean kill); +int create_pid_file(const char *pidfile, gboolean kill_running); /** * Remove pid file diff --git a/include/mode-private.h b/include/mode-private.h index ab6f04e5..99d48309 100644 --- a/include/mode-private.h +++ b/include/mode-private.h @@ -27,6 +27,7 @@ #ifndef ROFI_MODE_PRIVATE_H #define ROFI_MODE_PRIVATE_H +#include "mode.h" #include G_BEGIN_DECLS diff --git a/source/modes/dmenu.c b/source/modes/dmenu.c index 53416c3f..1a274b7e 100644 --- a/source/modes/dmenu.c +++ b/source/modes/dmenu.c @@ -476,7 +476,7 @@ static int dmenu_token_match(const Mode *sw, rofi_int_matcher **tokens, // int retv = helper_token_match ( tokens, esc ); int match = 1; if (tokens) { - for (int j = 0; match && tokens != NULL && tokens[j] != NULL; j++) { + for (int j = 0; match && tokens[j] != NULL; j++) { rofi_int_matcher *ftokens[2] = {tokens[j], NULL}; int test = 0; test = helper_token_match(ftokens, esc); diff --git a/source/modes/drun.c b/source/modes/drun.c index 48296919..8d4278e8 100644 --- a/source/modes/drun.c +++ b/source/modes/drun.c @@ -44,11 +44,11 @@ #include #include -#include "modes/drun.h" -#include "modes/filebrowser.h" #include "helper.h" #include "history.h" #include "mode-private.h" +#include "modes/drun.h" +#include "modes/filebrowser.h" #include "rofi.h" #include "settings.h" #include "timings.h" @@ -1386,7 +1386,7 @@ static int drun_token_match(const Mode *data, rofi_int_matcher **tokens, } int match = 1; if (tokens) { - for (int j = 0; match && tokens != NULL && tokens[j] != NULL; j++) { + for (int j = 0; match && tokens[j] != NULL; j++) { int test = 0; rofi_int_matcher *ftokens[2] = {tokens[j], NULL}; // Match name diff --git a/source/modes/script.c b/source/modes/script.c index 16e05a96..182ea3f2 100644 --- a/source/modes/script.c +++ b/source/modes/script.c @@ -397,7 +397,7 @@ static int script_token_match(const Mode *sw, rofi_int_matcher **tokens, ScriptModePrivateData *rmpd = sw->private_data; int match = 1; if (tokens) { - for (int j = 0; match && tokens != NULL && tokens[j] != NULL; j++) { + for (int j = 0; match && tokens[j] != NULL; j++) { rofi_int_matcher *ftokens[2] = {tokens[j], NULL}; int test = 0; test = helper_token_match(ftokens, rmpd->cmd_list[index].entry); diff --git a/source/modes/window.c b/source/modes/window.c index e5f78686..2d001418 100644 --- a/source/modes/window.c +++ b/source/modes/window.c @@ -418,7 +418,7 @@ static int window_match(const Mode *sw, rofi_int_matcher **tokens, client *c = cache_client->data[idx]; if (tokens) { - for (int j = 0; match && tokens != NULL && tokens[j] != NULL; j++) { + for (int j = 0; match && tokens[j] != NULL; j++) { int test = 0; // Dirty hack. Normally helper_token_match does _all_ the matching, // Now we want it to match only one item at the time. diff --git a/source/theme.c b/source/theme.c index 3cd6093c..0c5daa45 100644 --- a/source/theme.c +++ b/source/theme.c @@ -1235,17 +1235,17 @@ GList *rofi_theme_get_list_distance(const widget *widget, iter = g_list_next(iter)) { Property *prop = (Property *)(iter->data); if (prop->type == P_PADDING) { - RofiDistance *p = g_new0(RofiDistance, 1); - *p = prop->value.padding.left; - retv = g_list_append(retv, p); + RofiDistance *pnew = g_new0(RofiDistance, 1); + *pnew = prop->value.padding.left; + retv = g_list_append(retv, pnew); } else if (prop->type == P_INTEGER) { - RofiDistance *p = g_new0(RofiDistance, 1); + RofiDistance *pnew = g_new0(RofiDistance, 1); RofiDistance d = (RofiDistance){.base = {prop->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID}; - *p = d; - retv = g_list_append(retv, p); + *pnew = d; + retv = g_list_append(retv, pnew); } else { g_warning("Invalid type detected in list."); } diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index bf989900..93d4c4d7 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -728,9 +728,7 @@ static void textbox_cursor_del_eol(textbox *tb) { static void textbox_cursor_del_sol(textbox *tb) { if (tb && tb->cursor >= 0) { int length = tb->cursor; - if (length >= 0) { - textbox_delete(tb, 0, length); - } + textbox_delete(tb, 0, length); } } static void textbox_cursor_del_word(textbox *tb) { diff --git a/source/xcb.c b/source/xcb.c index de3a1925..7a75d088 100644 --- a/source/xcb.c +++ b/source/xcb.c @@ -63,8 +63,8 @@ #include "xcb.h" #include -#include "modes/window.h" #include "mode.h" +#include "modes/window.h" #include @@ -977,10 +977,8 @@ int monitor_active(workarea *mon) { } g_debug("Monitor active"); if (mon_set) { - if (mon) { - *mon = mon_cache; - return TRUE; - } + *mon = mon_cache; + return TRUE; } if (config.monitor != NULL) { g_debug("Monitor lookup by name : %s", config.monitor); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 44747b64..b692fb91 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -625,11 +625,11 @@ static gboolean __config_parser_set_property(XrmOption *option, if (p->type == P_LIST) { for (GList *iter = p->value.list; iter != NULL; iter = g_list_next(iter)) { - Property *p = (Property *)iter->data; + Property *p2 = (Property *)iter->data; if (value == NULL) { - value = g_strdup((char *)(p->value.s)); + value = g_strdup((char *)(p2->value.s)); } else { - char *nv = g_strjoin(",", value, (char *)(p->value.s), NULL); + char *nv = g_strjoin(",", value, (char *)(p2->value.s), NULL); g_free(value); value = nv; }