From f08c809806692ce0999417f10eb03248ff9c6a8c Mon Sep 17 00:00:00 2001 From: yvs Date: Fri, 22 Nov 2024 15:15:28 +0200 Subject: [PATCH] increase warning-level to 2 (+Wextra) and fix warnings --- CHANGELOG.md | 3 +++ CMakeLists.txt | 1 + GNUmakefile | 1 + cli.c | 23 +++++++++++----------- common.c | 22 ++++++++++----------- common.h | 20 +++++++++---------- debian/changelog | 6 ++++++ dns.c | 13 ++++++++++--- meson.build | 2 +- parser.c | 18 ++++++++--------- parser.h | 4 ++-- pinger.c | 6 +++--- pingpath.c | 16 +++++++++------- series.c | 6 ++++-- stat.c | 2 +- tabs/aux.c | 8 ++++---- tabs/aux.h | 2 +- tabs/graph.c | 12 +++++++++--- tabs/ping.c | 20 ++++++++++++------- tabs/plot.c | 8 ++++---- ui/action.c | 50 ++++++++++++++++++++++++++++++------------------ ui/appbar.c | 4 ++-- ui/clipboard.c | 16 ++++++++++------ ui/notifier.c | 47 ++++++++++++++++++++++++++------------------- ui/notifier.h | 6 +++--- ui/option.c | 28 +++++++++++++-------------- whois.c | 7 +++++-- 27 files changed, 205 insertions(+), 146 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e6b909..6caf6ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.3.43 +- increase warning-level to 2 (+Wextra) and fix warnings + ## 0.3.42 - notifier position: reassure again gtk_widget_measure() call diff --git a/CMakeLists.txt b/CMakeLists.txt index 375b1e3..7c288d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ set(SRCS "${PROJECT_NAME}.c" common.c # mandatory add_compile_options("-Wall") +add_compile_options("-Wextra") check_library_exists(c sqrt "${CMAKE_LIBRARY_PATH}" HAVE_SQRT_IN_C) if(NOT HAVE_SQRT_IN_C) check_library_exists(m sqrt "${CMAKE_LIBRARY_PATH}" HAVE_SQRT_IN_M) diff --git a/GNUmakefile b/GNUmakefile index 6911a8d..70b0128 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -24,6 +24,7 @@ PKGS = gtk4 CC ?= gcc CFLAGS += -Wall +CFLAGS += -Wextra CFLAGS += -I. LIBS = -lm diff --git a/cli.c b/cli.c index e729391..d701dc8 100644 --- a/cli.c +++ b/cli.c @@ -302,7 +302,8 @@ static char* reorder_patt(const char *str, const char *patt) { static void reorder_elems(const char *str, t_elem_desc *desc) { if (!str || !desc || !desc->elems || !desc->patt) return; char *order = reorder_patt(str, desc->patt); - int len = desc->mm.max - desc->mm.min + 1; + int num = desc->mm.max - desc->mm.min + 1; + size_t len = (num > 0) ? num : 0; type2ndx_fn type2ndx = desc->t2n; if (type2ndx && order && (len > 0) && (strnlen(order, len + 1) == len)) { t_type_elem *elems = &desc->elems[desc->mm.min]; @@ -323,7 +324,7 @@ static void reorder_elems(const char *str, t_elem_desc *desc) { g_free(order); } -static char* cli_char_opts(int type, const char *value, int cat, t_elem_desc *desc, int max, const char *hdr) { +static char* cli_char_opts(int type, const char *value, unsigned cat, t_elem_desc *desc, int max, const char *hdr) { if (!desc || !desc->elems) return NULL; CLI_REORDER_PRINT_ELEMS(desc->elems, max); clean_elems(type); @@ -336,7 +337,7 @@ static char* cli_char_opts(int type, const char *value, int cat, t_elem_desc *de #define RECAP_TYPE_EXPAND(type) (((type) == 't') ? "text" : (((type) == 'c') ? "csv" : \ ((g_ascii_tolower(type) == 'j') ? "json" : "unknown"))) -static gboolean cli_opt_elem(const char *name, const char *value, GError **error, int cat) { +static gboolean cli_opt_elem(const char *name, const char *value, GError **error, unsigned cat) { if (!value) return false; char *str = NULL; switch (cat) { @@ -370,28 +371,28 @@ static gboolean cli_opt_elem(const char *name, const char *value, GError **error CLI_SET_ERR; return false; } -static gboolean cli_opt_p(const char *name, const char *value, void *unused, GError **error) { +static gboolean cli_opt_p(const char *name, const char *value, t_opts *opts G_GNUC_UNUSED, GError **error) { return cli_opt_elem(name, value, error, OPT_TYPE_PAD); } -static gboolean cli_opt_I(const char *name, const char *value, void *unused, GError **error) { +static gboolean cli_opt_I(const char *name, const char *value, t_opts *opts G_GNUC_UNUSED, GError **error) { return cli_opt_elem(name, value, error, OPT_TYPE_INFO); } -static gboolean cli_opt_S(const char *name, const char *value, void *unused, GError **error) { +static gboolean cli_opt_S(const char *name, const char *value, t_opts *opts G_GNUC_UNUSED, GError **error) { return cli_opt_elem(name, value, error, OPT_TYPE_STAT); } -static gboolean cli_opt_L(const char *name, const char *value, void *unused, GError **error) { +static gboolean cli_opt_L(const char *name, const char *value, t_opts *opts G_GNUC_UNUSED, GError **error) { return cli_opt_elem(name, value, error, OPT_TYPE_GRLG); } -static gboolean cli_opt_G(const char *name, const char *value, void *unused, GError **error) { +static gboolean cli_opt_G(const char *name, const char *value, t_opts *opts G_GNUC_UNUSED, GError **error) { return cli_opt_elem(name, value, error, OPT_TYPE_GREX); } #ifdef WITH_PLOT -static gboolean cli_opt_P(const char *name, const char *value, void *unused, GError **error) { +static gboolean cli_opt_P(const char *name, const char *value, t_opts *opts G_GNUC_UNUSED, GError **error) { return cli_opt_elem(name, value, error, OPT_TYPE_PLEL); } #endif @@ -417,11 +418,11 @@ static gboolean cli_opt_T(const char *name, const char *value, t_opts *opts, GEr return okay; } -static gboolean cli_opt_r(const char *name, const char *value, void *unused, GError **error) { +static gboolean cli_opt_r(const char *name, const char *value, t_opts *opts G_GNUC_UNUSED, GError **error) { return cli_opt_elem(name, value, error, OPT_TYPE_RECAP); } -static gboolean cli_opt_A(const char *name, const char *value, void *unused, GError **error) { +static gboolean cli_opt_A(const char *name, const char *value, t_opts *opts G_GNUC_UNUSED, GError **error) { int aopt = activetab + 1; gboolean valid = cli_int_opt(name, value, error, OPT_ATAB_HDR, ATAB_MIN + 1, ATAB_MAX + 1, &aopt); if (valid) activetab = aopt - 1; diff --git a/common.c b/common.c index 186a31b..ec63687 100644 --- a/common.c +++ b/common.c @@ -65,14 +65,14 @@ const int n_colors = G_N_ELEMENTS(colors); // -static int elem_type2ndx(int type, t_type_elem *elem, int max) { - for (int i = 0; i < max; i++) if (type == elem[i].type) return i; +static unsigned elem_type2ndx(int type, t_type_elem *elem, unsigned max) { + for (unsigned i = 0; i < max; i++) if (type == elem[i].type) return i; return -1; } -int pingelem_type2ndx(int type) { return elem_type2ndx(type, pingelem, G_N_ELEMENTS(pingelem)); } -int graphelem_type2ndx(int type) { return elem_type2ndx(type, graphelem, G_N_ELEMENTS(graphelem)); } +unsigned pingelem_type2ndx(int type) { return elem_type2ndx(type, pingelem, G_N_ELEMENTS(pingelem)); } +unsigned graphelem_type2ndx(int type) { return elem_type2ndx(type, graphelem, G_N_ELEMENTS(graphelem)); } #ifdef WITH_PLOT -int plotelem_type2ndx(int type) { return elem_type2ndx(type, plotelem, G_N_ELEMENTS(plotelem)); } +unsigned plotelem_type2ndx(int type) { return elem_type2ndx(type, plotelem, G_N_ELEMENTS(plotelem)); } #endif static const char* char_pattern[] = { [INFO_CHAR] = INFO_PATT, [STAT_CHAR] = STAT_PATT, @@ -224,20 +224,20 @@ gboolean* pingelem_enabler(int type) { return elem_enabler(type, pingelem, G_N gboolean* graphelem_enabler(int type) { return elem_enabler(type, graphelem, G_N_ELEMENTS(graphelem)); } gboolean is_grelem_enabled(int type) { - int ndx = graphelem_type2ndx(type); - return ((ndx >= 0) && (ndx < G_N_ELEMENTS(graphelem))) ? graphelem[ndx].enable : false; + unsigned ndx = graphelem_type2ndx(type); + return (ndx < G_N_ELEMENTS(graphelem)) ? graphelem[ndx].enable : false; } #ifdef WITH_PLOT gboolean* plotelem_enabler(int type) { return elem_enabler(type, plotelem, G_N_ELEMENTS(plotelem)); } gboolean is_plelem_enabled(int type) { - int ndx = plotelem_type2ndx(type); - return ((ndx >= 0) && (ndx < G_N_ELEMENTS(plotelem))) ? plotelem[ndx].enable : false; + unsigned ndx = plotelem_type2ndx(type); + return (ndx < G_N_ELEMENTS(plotelem)) ? plotelem[ndx].enable : false; } #endif -#define CLEAN_ELEM_LOOP(elems, min, max) { for (int i = 0; i < G_N_ELEMENTS(elems); i++) \ +#define CLEAN_ELEM_LOOP(elems, min, max) { for (unsigned i = 0; i < G_N_ELEMENTS(elems); i++) \ if (((min) <= (elems)[i].type) && ((elems)[i].type <= (max))) (elems)[i].enable = false; } void clean_elems(int type) { @@ -325,7 +325,7 @@ void print_refs(GSList *refs, const char *prefix) { } #endif -GSList* list_add_nodup(GSList **list, void *data, GCompareFunc cmp, int max) { +GSList* list_add_nodup(GSList **list, void *data, GCompareFunc cmp, unsigned max) { if (!list || !data || !cmp) return NULL; GSList *elem = g_slist_find_custom(*list, data, cmp); if (elem) { g_free(data); return elem; } diff --git a/common.h b/common.h index deeb08d..645021f 100644 --- a/common.h +++ b/common.h @@ -14,11 +14,7 @@ #include "config.h" #define APPNAME "pingpath" -#define VERSION "0.3.42" - -#ifndef WITH_PLOT -//#define WITH_PLOT // tmp -#endif +#define VERSION "0.3.43" enum { X_RES = 1024, Y_RES = 720 }; enum { MAXADDR = 10 }; @@ -490,14 +486,16 @@ typedef struct t_type_elem { typedef struct t_legend { const char *name, *as, *cc, *av, *jt; } t_legend; -typedef int (*type2ndx_fn)(int); +typedef unsigned (*type2ndx_fn)(int); +typedef int (*type2ent_fn)(int); typedef struct elem_desc { t_type_elem *elems; const t_minmax mm; const int cat; const char *patt; - type2ndx_fn t2n, t2e; + type2ndx_fn t2n; + type2ent_fn t2e; } t_elem_desc; typedef struct th_color { double ondark, onlight; } t_th_color; @@ -530,13 +528,13 @@ char* get_nth_color(int nth); int char2ndx(int cat, gboolean ent, char ch); gboolean* pingelem_enabler(int type); gboolean* graphelem_enabler(int type); -int pingelem_type2ndx(int type); -int graphelem_type2ndx(int type); +unsigned pingelem_type2ndx(int type); +unsigned graphelem_type2ndx(int type); gboolean is_grelem_enabled(int type); void clean_elems(int type); #ifdef WITH_PLOT gboolean* plotelem_enabler(int type); -int plotelem_type2ndx(int type); +unsigned plotelem_type2ndx(int type); gboolean is_plelem_enabled(int type); #endif @@ -549,7 +547,7 @@ int host_cmp(const void *a, const void *b); int ref_cmp(const t_ref *a, const t_ref *b); t_ref* ref_new(t_hop *hop, int ndx); void print_refs(GSList *refs, const char *prefix); -GSList* list_add_nodup(GSList **list, void *data, GCompareFunc cmp, int max); +GSList* list_add_nodup(GSList **list, void *data, GCompareFunc cmp, unsigned max); GSList* list_add_ref(GSList **list, t_hop *hop, int ndx); extern void log_add(const char *fmt, ...); diff --git a/debian/changelog b/debian/changelog index 61137e9..ae74959 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +pingpath (0.3.43) mantic noble; urgency=low + + * increase warning-level to 2 (+Wextra) and fix warnings + + -- yvs Fri, 22 Nov 2024 15:14:27 +0200 + pingpath (0.3.42) mantic noble; urgency=low * notifier position: reassure again gtk_widget_measure() call diff --git a/dns.c b/dns.c index f4f2046..02ad01f 100644 --- a/dns.c +++ b/dns.c @@ -1,8 +1,8 @@ #include -#include "dns.h" #include "common.h" +#include "dns.h" typedef struct dns_elem { // network stuff @@ -182,13 +182,20 @@ void dns_lookup(t_hop *hop, int ndx) { } else FAIL("g_resolver_get_default()"); } +static void dns_host_on_free(gpointer data, gpointer user_data G_GNUC_UNUSED) { + host_free(data); +} +static void dns_query_on_free(gpointer data, gpointer user_data G_GNUC_UNUSED) { + dns_query_free(data); +} + void dns_cache_free(void) { PR_DNS_C; - g_slist_foreach(dns_cache, (GFunc)host_free, NULL); + g_slist_foreach(dns_cache, dns_host_on_free, NULL); g_slist_free_full(dns_cache, g_free); dns_cache = NULL; PR_DNS_Q; - g_slist_foreach(dns_query, (GFunc)dns_query_free, NULL); + g_slist_foreach(dns_query, dns_query_on_free, NULL); g_slist_free_full(dns_query, g_free); dns_query = NULL; } diff --git a/meson.build b/meson.build index b3a9905..4609e0d 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project('pingpath', 'c', default_options: [ # 'c_std=gnu99,c99', - 'warning_level=1' ], + 'warning_level=2' ], meson_version: '>= 0.53', license: 'GPL-2.0-or-later', version: '.'.join(['0', '3', find_program('git', required: false).found() ? diff --git a/parser.c b/parser.c index e325e10..dc953a0 100644 --- a/parser.c +++ b/parser.c @@ -250,11 +250,11 @@ gboolean parser_init(void) { hostname_char0_regex = compile_regex("^[" DIGIT_OR_LETTER ":]", 0); hostname_chars_regex = compile_regex("^[" DIGIT_OR_LETTER ":.-]+$", 0); gboolean okay = multiline_regex && hostname_char0_regex && hostname_chars_regex; - for (int i = 0; i < G_N_ELEMENTS(regexes); i++) { + for (unsigned i = 0; i < G_N_ELEMENTS(regexes); i++) { regexes[i].rx.regex = compile_regex(regexes[i].rx.pattern, 0); if (!regexes[i].rx.regex) okay = false; } - for (int i = 0; i < G_N_ELEMENTS(str_rx); i++) { + for (unsigned i = 0; i < G_N_ELEMENTS(str_rx); i++) { str_rx[i].regex = compile_regex(str_rx[i].pattern, 0); if (!str_rx[i].regex) okay = false; } @@ -285,9 +285,9 @@ gboolean parser_mmint(const char *str, const char *option, t_minmax minmax, int return okay; } -char* parser_str(const char *str, const char *option, int cat) { +char* parser_str(const char *str, const char *option, unsigned cat) { const int PARSE_MAX_CHARS = 128; - if ((cat >= 0) && (cat < G_N_ELEMENTS(str_rx))) { + if (cat < G_N_ELEMENTS(str_rx)) { char *buff = g_strndup(str, PARSE_MAX_CHARS); if (buff) { char *val = g_strdup(g_strstrip(buff)); g_free(buff); @@ -318,7 +318,7 @@ char* parser_valid_target(const char *target) { void parser_whois(char *buff, t_whois *welem) { // if there are multiple sources (despite -m query), take the last tag and mark it with '*' static const char skip_as_prfx[] = "AS"; - static int as_prfx_len = sizeof(skip_as_prfx) - 1; + static unsigned as_prfx_len = sizeof(skip_as_prfx) - 1; if (!buff || !welem) return; memset(welem, 0, sizeof(*welem)); // BUFFNOLINT char *str = NULL; @@ -371,16 +371,16 @@ gboolean parser_range(char *range, char delim, const char *option, t_minmax *min } #ifdef WITH_PLOT -gboolean parser_ivec(char *range, char delim, const char *option, int *dest, int max) { +gboolean parser_ivec(char *range, char delim, const char *option, int *dest, unsigned max) { if (!range || (max <= 0)) return false; const char delims[] = { delim, 0 }; char **abcs = g_strsplit(range, delims, max); - int val[max]; for (int i = 0; i < max; i++) val[i] = INT_MIN; + int val[max]; for (unsigned i = 0; i < max; i++) val[i] = INT_MIN; gboolean okay = true; - if (abcs) for (int i = 0; abcs[i] && (i < G_N_ELEMENTS(val)); i++) + if (abcs) for (unsigned i = 0; abcs[i] && (i < G_N_ELEMENTS(val)); i++) okay &= parser_valint(abcs[i], &val[i], option); g_strfreev(abcs); - if (okay) for (int i = 0; i < max; i++) dest[i] = val[i]; + if (okay) for (unsigned i = 0; i < max; i++) dest[i] = val[i]; return okay; } #endif diff --git a/parser.h b/parser.h index 9bb78c2..83622be 100644 --- a/parser.h +++ b/parser.h @@ -15,12 +15,12 @@ enum { OPT_TYPE_INT, OPT_TYPE_PAD, OPT_TYPE_INFO, OPT_TYPE_STAT, OPT_TYPE_GRLG, gboolean parser_init(void); void parser_parse(int at, char *input); char* parser_valid_target(const char *target); -char* parser_str(const char *str, const char *option, int cat); +char* parser_str(const char *str, const char *option, unsigned cat); void parser_whois(char *buff, t_whois* welem); gboolean parser_mmint(const char *str, const char *option, t_minmax minmax, int *value); gboolean parser_range(char *range, char delim, const char *option, t_minmax *minmax); #ifdef WITH_PLOT -gboolean parser_ivec(char *range, char delim, const char *option, int *dest, int max); +gboolean parser_ivec(char *range, char delim, const char *option, int *dest, unsigned max); #endif #endif diff --git a/pinger.c b/pinger.c index b3e9719..67520fb 100644 --- a/pinger.c +++ b/pinger.c @@ -107,7 +107,7 @@ static void pinger_print_text(gboolean csv) { for (int i = opts.min; i < lim; i++) { // data per hop t_ping_column column[G_N_ELEMENTS(pingelem)] = {0}; int lines = 0; - for (int j = 0; j < G_N_ELEMENTS(pingelem); j++) if (pingelem[j].enable) { + for (unsigned j = 0; j < G_N_ELEMENTS(pingelem); j++) if (pingelem[j].enable) { int type = pingelem[j].type; switch (type) { case PE_NO: @@ -508,7 +508,7 @@ static gboolean create_ping(int at, t_proc *proc) { return proc->active; } -static int pinger_check_expired(void *unused) { +static gboolean pinger_on_expired(gpointer user_data G_GNUC_UNUSED) { if (!atquit) for (int i = 0; i < MAXTTL; i++) if (pings[i].active) { LOG("proc(%d) is still active after expire time, stopping..", i); pinger_nth_stop(i, "runtime expired"); @@ -536,7 +536,7 @@ void pinger_start(void) { // schedule expiration check out if (exp_timer) { g_source_remove(exp_timer); exp_timer = 0; } unsigned exp_in = round(opts.cycles * (opts.timeout * 1.024)) + opts.timeout * 2; // ~24msec of possible ping time resolution - exp_timer = g_timeout_add_seconds(exp_in, pinger_check_expired, NULL); + exp_timer = g_timeout_add_seconds(exp_in, pinger_on_expired, NULL); LOG("expiration set to %d seconds for %d cycles", exp_in, opts.cycles); } diff --git a/pingpath.c b/pingpath.c index f03038d..d207a98 100644 --- a/pingpath.c +++ b/pingpath.c @@ -37,7 +37,7 @@ static GtkWidget *currtabref, *tabrefs[TAB_NDX_MAX]; static GtkNotebook *nb_ref; #endif -static gboolean on_win_close(GtkWindow *window, void *unused) { +static gboolean on_win_close(GtkWindow *self G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) { // workarounds to exit gracefully cb_tab_unsel(nb_tabs[TAB_PING_NDX]); cb_tab_unsel(nb_tabs[TAB_LOG_NDX]); @@ -50,7 +50,9 @@ static gboolean on_win_close(GtkWindow *window, void *unused) { return false; } -static void on_tab_switch(GtkNotebook *nb, GtkWidget *tab, unsigned ndx, void *unused) { +static void on_tab_switch(GtkNotebook *self G_GNUC_UNUSED, GtkWidget *tab, + guint page_num G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) +{ tab_dependent(tab); if (GTK_IS_BOX(tab)) for (GtkWidget *widget = gtk_widget_get_first_child(tab); @@ -70,7 +72,7 @@ static void on_tab_switch(GtkNotebook *nb, GtkWidget *tab, unsigned ndx, void *u static inline void log_libver(const char *pre, char *ver) { if (ver) { LOG("%s: %s", pre, ver); g_free(ver); }} -static void app_cb(GtkApplication* app, void *unused) { +static void on_app_activate(GtkApplication* app, gpointer user_data G_GNUC_UNUSED) { style_set(); GtkWidget *win = gtk_application_window_new(app); if (!GTK_IS_WINDOW(win)) APPQUIT("%s", "app window"); @@ -95,7 +97,7 @@ static void app_cb(GtkApplication* app, void *unused) { if (opts.plot) nb_tabs[TAB_PLOT_NDX] = plottab_init(); #endif nb_tabs[TAB_LOG_NDX] = logtab_init(win); - for (int i = 0; i < G_N_ELEMENTS(nb_tabs); i++) { + for (unsigned i = 0; i < G_N_ELEMENTS(nb_tabs); i++) { { if (!opts.graph && (i == TAB_GRAPH_NDX)) continue; #ifdef WITH_PLOT if (!opts.plot && (i == TAB_PLOT_NDX)) continue; @@ -128,7 +130,7 @@ static void app_cb(GtkApplication* app, void *unused) { if (autostart && opts.target) { pinger_start(); appbar_update(); } } -static void recap_cb(GApplication* app, void *unused) { +static void on_recap_activate(GApplication *app, gpointer user_data G_GNUC_UNUSED) { g_timeout_add_seconds(1, (GSourceFunc)pinger_recap_cb, app); if (G_IS_APPLICATION(app)) g_application_hold(app); pinger_start(); @@ -184,11 +186,11 @@ int main(int argc, char **argv) { if (opts.recap) { app = g_application_new("net.tools." APPNAME, APPFLAGS); g_return_val_if_fail(G_IS_APPLICATION(app), EX_UNAVAILABLE); - g_signal_connect(app, EV_ACTIVE, G_CALLBACK(recap_cb), NULL); + g_signal_connect(app, EV_ACTIVE, G_CALLBACK(on_recap_activate), NULL); } else { GtkApplication *gtkapp = gtk_application_new("net.tools." APPNAME, APPFLAGS); g_return_val_if_fail(GTK_IS_APPLICATION(gtkapp), EX_UNAVAILABLE); - g_signal_connect(gtkapp, EV_ACTIVE, G_CALLBACK(app_cb), NULL); + g_signal_connect(gtkapp, EV_ACTIVE, G_CALLBACK(on_app_activate), NULL); app = G_APPLICATION(gtkapp); } int rc = g_application_run(app, argc, argv); diff --git a/series.c b/series.c index a06aa7d..ef72228 100644 --- a/series.c +++ b/series.c @@ -67,7 +67,9 @@ static void series_save_rseq(int nth, t_rseq *data) { } } -static void* stat_dup_series(const void *src, void *unused) { return g_memdup2(src, sizeof(t_rseq)); } +static gpointer series_on_copy(gconstpointer src, gpointer data G_GNUC_UNUSED) { + return g_memdup2(src, sizeof(t_rseq)); +} // pub @@ -106,7 +108,7 @@ void series_free(gboolean unreg) { void series_lock(void) { grm_lock = true; for (int i = 0; i < series_count; i++) { // keep current data - KEPT_SERIES(i) = SERIES(i) ? g_slist_copy_deep(SERIES(i), stat_dup_series, NULL) : NULL; + KEPT_SERIES(i) = SERIES(i) ? g_slist_copy_deep(SERIES(i), series_on_copy, NULL) : NULL; KEPT_SERIES_LEN(i) = g_slist_length(KEPT_SERIES(i)); } grm_lock = false; diff --git a/stat.c b/stat.c index ea48c77..4e0e3af 100644 --- a/stat.c +++ b/stat.c @@ -482,7 +482,7 @@ void stat_legend(int at, t_legend *data) { void stat_whois_enabler(void) { gboolean enable = false; - for (int i = 0; i < G_N_ELEMENTS(pingelem); i++) + for (unsigned i = 0; i < G_N_ELEMENTS(pingelem); i++) if (IS_WHOIS_NDX(pingelem[i].type) && pingelem[i].enable) { enable = true; break; } if (enable != opts.whois) { opts.whois = enable; LOG("whois %sabled", enable ? "en" : "dis"); } } diff --git a/tabs/aux.c b/tabs/aux.c index 395a029..a921dba 100644 --- a/tabs/aux.c +++ b/tabs/aux.c @@ -42,7 +42,7 @@ gboolean basetab_init(t_tab *tab, GtkWidget* (*make_dyn)(void), GtkWidget* (*mak return true; } -gboolean drawtab_init(t_tab *tab, const char *color, GSList *layers, int ndx) { +gboolean drawtab_init(t_tab *tab, const char *color, GSList *layers, unsigned ndx) { if (!tab || !layers) return false; TAB_ELEM_INIT(tab->lab, gtk_box_new(GTK_ORIENTATION_VERTICAL, 2), CSS_PAD, NULL); TAB_ELEM_INIT(tab->dyn, gtk_box_new(GTK_ORIENTATION_VERTICAL, 0), NULL, color); @@ -77,7 +77,7 @@ void tab_setup(t_tab *tab) { } } t_tab_widget tab_widget[] = {tab->hdr, tab->dyn, tab->info}; - for (int i = 0; i < G_N_ELEMENTS(tab_widget); i++) + for (unsigned i = 0; i < G_N_ELEMENTS(tab_widget); i++) if (GTK_IS_WIDGET(tab_widget[i].w)) gtk_widget_set_can_focus(tab_widget[i].w, false); if (style_loaded && tab->tab.css && GTK_IS_WIDGET(tab->tab.w)) @@ -87,7 +87,7 @@ void tab_setup(t_tab *tab) { void tab_color(t_tab *tab) { if (!style_loaded || !tab) return; t_tab_widget tab_widget[] = {tab->hdr, tab->dyn, tab->info}; - for (int i = 0; i < G_N_ELEMENTS(tab_widget); i++) + for (unsigned i = 0; i < G_N_ELEMENTS(tab_widget); i++) if (tab_widget[i].col && GTK_IS_WIDGET(tab_widget[i].w)) tab_aux_reload_css(&tab_widget[i], tab_widget[i].col); if (tab->tab.col && GTK_IS_WIDGET(tab->tab.w)) @@ -95,7 +95,7 @@ void tab_color(t_tab *tab) { } void tab_reload_theme(void) { - for (int i = 0; i < G_N_ELEMENTS(nb_tabs); i++) if (nb_tabs[i]) tab_color(nb_tabs[i]); + for (unsigned i = 0; i < G_N_ELEMENTS(nb_tabs); i++) if (nb_tabs[i]) tab_color(nb_tabs[i]); } inline gboolean need_drawing(void) { diff --git a/tabs/aux.h b/tabs/aux.h index e7984e0..9108d19 100644 --- a/tabs/aux.h +++ b/tabs/aux.h @@ -28,7 +28,7 @@ typedef struct tab { } t_tab; gboolean basetab_init(t_tab *tab, GtkWidget* (*make_dyn)(void), GtkWidget* (*make_extra)(void)); -gboolean drawtab_init(t_tab *tab, const char *color, GSList *layers, int ndx); +gboolean drawtab_init(t_tab *tab, const char *color, GSList *layers, unsigned ndx); void tab_setup(t_tab *tab); void tab_color(t_tab *tab); void tab_reload_theme(void); diff --git a/tabs/graph.c b/tabs/graph.c index 554046a..21a0d48 100644 --- a/tabs/graph.c +++ b/tabs/graph.c @@ -215,7 +215,9 @@ static void gr_draw_smth(cairo_t *cr, double width, double alpha, } } -static void gr_draw_grid(GtkDrawingArea *area, cairo_t* cr, int width, int height, void *unused) { +static void gr_draw_grid(GtkDrawingArea *area, cairo_t *cr, + int width, int height, gpointer user_data G_GNUC_UNUSED) +{ const double dash_size[] = {1}; if (!GTK_IS_DRAWING_AREA(area) || !cr || !width || !height) return; int w0 = width - (GRAPH_LEFT + GRAPH_RIGHT), h0 = height - (GRAPH_TOP + GRAPH_BOTTOM); @@ -272,7 +274,9 @@ static void gr_draw_grid(GtkDrawingArea *area, cairo_t* cr, int width, int heigh } } -static void gr_draw_marks(GtkDrawingArea *area, cairo_t* cr, int width, int height, void *unused) { +static void gr_draw_marks(GtkDrawingArea *area, cairo_t *cr, + int width G_GNUC_UNUSED, int height G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) +{ if (!GTK_IS_DRAWING_AREA(area) || !cr || !graph_font || (grm.y0 <= 0)) return; if (!mark_pango) { mark_pango = pango_cairo_create_layout(cr); @@ -335,7 +339,9 @@ static void gr_draw_mean(cairo_t *cr, gboolean mean, gboolean area) { } } -static void gr_draw_graph(GtkDrawingArea *area, cairo_t* cr, int width, int height, void *unused) { +static void gr_draw_graph(GtkDrawingArea *area, cairo_t* cr, + int width G_GNUC_UNUSED, int height G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) +{ static const int graph_tsz = (CELL_SIZE - TICK_SIZE) * X_FREQ; if (!GTK_IS_DRAWING_AREA(area) || !cr) return; if (!graph_pango) { diff --git a/tabs/ping.c b/tabs/ping.c index f14ab01..2350f45 100644 --- a/tabs/ping.c +++ b/tabs/ping.c @@ -161,14 +161,16 @@ static gboolean pt_reorder_cells(t_listline *lines, int len, int sn, int dn, gbo #define PT_LAB_TEXT(lab) (GTK_IS_LABEL(lab) ? gtk_label_get_text(GTK_LABEL(lab)) : "") -static GdkContentProvider* pt_hdr_dnd_drag(GtkDragSource *src, gdouble x, gdouble y, t_pt_dnd *dnd) { +static GdkContentProvider* pt_hdr_dnd_drag(GtkDragSource *self G_GNUC_UNUSED, + gdouble x, gdouble y, t_pt_dnd *dnd) +{ if (!dnd) return NULL; dnd->dx = round(x); dnd->dy = round(y); DNDORD("DND-drag[%s]: dx,dy=(%d,%d)", PT_LAB_TEXT(dnd->w), dnd->dx, dnd->dy); return gdk_content_provider_new_typed(G_TYPE_POINTER, dnd); } -static void pt_hdr_dnd_icon(GtkDragSource *src, GdkDrag *drag, t_pt_dnd *dnd) { +static void pt_hdr_dnd_icon(GtkDragSource *src, GdkDrag *drag G_GNUC_UNUSED, t_pt_dnd *dnd) { if (!GTK_IS_DRAG_SOURCE(src) || !dnd || !GTK_IS_WIDGET(dnd->w)) return; GdkPaintable *icon = gtk_widget_paintable_new(dnd->w); if (!GDK_IS_PAINTABLE(icon)) return; @@ -177,7 +179,9 @@ static void pt_hdr_dnd_icon(GtkDragSource *src, GdkDrag *drag, t_pt_dnd *dnd) { DNDORD("DND-icon[%s]: dx,dy=(%d,%d)", PT_LAB_TEXT(dnd->w), dnd->dx, dnd->dy); } -static GdkDragAction pt_hdr_on_move(GtkDropTarget *dst, gdouble x, gdouble y, t_pt_dnd *ddnd) { +static GdkDragAction pt_hdr_on_move(GtkDropTarget *dst, + gdouble x G_GNUC_UNUSED, gdouble y G_GNUC_UNUSED, t_pt_dnd *ddnd) +{ if (!GTK_IS_DROP_TARGET(dst) || !ddnd) return 0; // ENUMNOLINT const GValue *val = gtk_drop_target_get_value(dst); @@ -185,8 +189,10 @@ static GdkDragAction pt_hdr_on_move(GtkDropTarget *dst, gdouble x, gdouble y, t_ return (sdnd && (sdnd != ddnd) && (sdnd->desc == ddnd->desc)) ? GDK_ACTION_COPY : 0; // ENUMNOLINT } -static gboolean pt_hdr_on_drop(GtkDropTarget *dst, const GValue *val, gdouble x, gdouble y, t_pt_dnd *ddnd) { - t_pt_dnd *sdnd = (val && G_VALUE_HOLDS_POINTER(val)) ? g_value_get_pointer(val) : NULL; +static gboolean pt_hdr_on_drop(GtkDropTarget *self G_GNUC_UNUSED, const GValue *value, + gdouble x, gdouble y, t_pt_dnd *ddnd) +{ + t_pt_dnd *sdnd = (value && G_VALUE_HOLDS_POINTER(value)) ? g_value_get_pointer(value) : NULL; if (!sdnd || !ddnd || !ddnd->desc || !ddnd->hdr || !ddnd->body) return false; int sn = pt_box_wndx(ddnd->b, sdnd->w), dn = pt_box_wndx(ddnd->b, ddnd->w); if ((sn < 0) || (dn < 0) || (sn == dn)) return false; @@ -304,13 +310,13 @@ static GtkWidget* pt_make_info(void) { static GtkWidget* pt_make_dyn(void) { GtkSizeGroup* group[PE_MAX]; - for (int i = 0; i < G_N_ELEMENTS(group); i++) { + for (unsigned i = 0; i < G_N_ELEMENTS(group); i++) { group[i] = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); g_return_val_if_fail(group[i], NULL); } TAB_ELEM_WITH(pingtab.hdr, pt_make_dynlist(listbox.hdrlines, HDRLINES, pingelem, listbox.bodylines, group), NULL, CSS_BGROUND, NULL); gtk_box_append(GTK_BOX(pingtab.tab.w), pingtab.hdr.w); GtkWidget *dyn = pt_make_dynlist(listbox.bodylines, MAXTTL, NULL, NULL, group); - for (int i = 0; i < G_N_ELEMENTS(group); i++) if (group[i]) g_object_unref(group[i]); + for (unsigned i = 0; i < G_N_ELEMENTS(group); i++) if (group[i]) g_object_unref(group[i]); return dyn; } diff --git a/tabs/plot.c b/tabs/plot.c index 7e90d21..6e7dead 100644 --- a/tabs/plot.c +++ b/tabs/plot.c @@ -308,7 +308,7 @@ static GLuint plot_compile_shader(const GLchar* src, GLenum type, GError **err) } static void plot_del_res_vao(t_plot_res *res) { - if (res) for (int i = 0; i < G_N_ELEMENTS(res->vo); i++) { + if (res) for (unsigned i = 0; i < G_N_ELEMENTS(res->vo); i++) { GLuint *pvao = &(res->vo[i].vao); if (*pvao > 0) { glDeleteVertexArrays(1, pvao); *pvao = 0; } } @@ -317,7 +317,7 @@ static void plot_del_res_vao(t_plot_res *res) { static void plot_del_vbo(GLuint *pid) { if (pid && *pid) { glDeleteBuffers(1, pid); *pid = 0; }} static void plot_del_res_vbo_dbo(t_plot_res *res) { - if (res) for (int i = 0; i < G_N_ELEMENTS(res->vo); i++) { + if (res) for (unsigned i = 0; i < G_N_ELEMENTS(res->vo); i++) { plot_del_vbo(&(res->vo[i].vbo.id)); plot_del_vbo(&(res->vo[i].dbo.main.id)); plot_del_vbo(&(res->vo[i].dbo.ext.id)); @@ -399,7 +399,7 @@ static gboolean plot_res_init(t_plot_res *res, GError **err) { #define PLOT_EXT_ATTR(prog) { PLOT_BASE_ATTR(prog); PLOT_GET_FORM(prog, colo2, PLOT_COL2); } if (!res) return false; if (!plot_compile_res(res, err)) return false; - for (int i = 0; i < G_N_ELEMENTS(res->vo); i++) { + for (unsigned i = 0; i < G_N_ELEMENTS(res->vo); i++) { GLuint *pvao = &(res->vo[i].vao); glGenVertexArrays(1, pvao); if (*pvao) continue; @@ -483,7 +483,7 @@ static void area_init(GtkGLArea *area, t_plot_res *res) { plot_res_ready = true; } -static void area_free(GtkGLArea *unused, t_plot_res *res) { plot_res_free(res); } +static void area_free(GtkWidget *self G_GNUC_UNUSED, t_plot_res *res) { plot_res_free(res); } static void plot_draw_elems(GLuint vao, t_plot_idc buff, GLint vtr, const vec4 colo1, GLint loc1, const vec4 colo2, GLint loc2, const mat4 mat, GLenum mode) { diff --git a/ui/action.c b/ui/action.c index d2c54e1..4d8e98f 100644 --- a/ui/action.c +++ b/ui/action.c @@ -156,14 +156,18 @@ static const char* accl_sa_label(int ndx) { return ""; } -static void on_startstop(GSimpleAction *action, GVariant *var, void *unused) { +static void on_startstop(GSimpleAction *action G_GNUC_UNUSED, + GVariant *parameter G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) +{ if (!opts.target) return; MI_LOG(MENU_SA_START, menu_sa_label); if (stat_timer) pinger_stop("by request"); else pinger_start(); appbar_update(); } -static void on_pauseresume(GSimpleAction *action, GVariant *var, void *unused) { +static void on_pauseresume(GSimpleAction *action G_GNUC_UNUSED, + GVariant *parameter G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) +{ MI_LOG(MENU_SA_PAUSE, menu_sa_label); pinger_state.pause = !pinger_state.pause; action_update(); @@ -174,19 +178,22 @@ static void on_pauseresume(GSimpleAction *action, GVariant *var, void *unused) { } } -static void on_reset(GSimpleAction *action, GVariant *var, void *unused) { +static void on_reset(GSimpleAction *action G_GNUC_UNUSED, + GVariant *parameter G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) +{ MI_LOG(MENU_SA_RESET, menu_sa_label); pinger_clear_data(false); } -static void hide_help_cb(GtkWidget *button, GtkWidget *dialog) { +static void on_hide_help(GtkButton *self G_GNUC_UNUSED, GtkWidget *dialog) { if (GTK_IS_WIDGET(dialog)) gtk_widget_set_visible(dialog, false); } -static gboolean help_dialog_cb(GtkEventControllerKey *eck, unsigned val, unsigned code, unsigned mod, GtkButton *btn) { - if ((val != GDK_KEY_Escape) || (mod & GDK_MODIFIER_MASK) || !GTK_IS_BUTTON(btn)) return false; - g_signal_emit_by_name(btn, EV_CLICK); - return true; +static void help_on_escape(GtkEventControllerKey *self G_GNUC_UNUSED, + guint keyval, guint keycode G_GNUC_UNUSED, GdkModifierType state, GtkButton *button) +{ + if ((keyval == GDK_KEY_Escape) && !(state & GDK_MODIFIER_MASK) && GTK_IS_BUTTON(button)) + g_signal_emit_by_name(button, EV_CLICK); } static gboolean show_help_dialog(GtkWidget *win) { @@ -250,7 +257,7 @@ static inline char* get_help_message(void) { #undef SPANHDR #undef SPANOPT #undef SPANSUB - char* list[8] = {0}; int ndx = 0; + char* list[8] = {0}; unsigned ndx = 0; #define HELP_MESG(cond, mesg) { if ((cond) && (ndx < G_N_ELEMENTS(list))) list[ndx++] = (mesg); } HELP_MESG(true, prolog); HELP_MESG(opts.graph, prolog_graph); @@ -266,7 +273,7 @@ static inline char* get_help_message(void) { #undef HELP_MESG } -static void on_help(GSimpleAction *action, GVariant *var, GtkWindow *win) { +static void on_help(GSimpleAction *action G_GNUC_UNUSED, GVariant *parameter G_GNUC_UNUSED, GtkWindow *win) { static t_help_dialog_in help_dialog; if (!GTK_IS_WINDOW(win)) return; if (show_help_dialog(help_dialog.win)) return; @@ -306,11 +313,11 @@ static void on_help(GSimpleAction *action, GVariant *var, GtkWindow *win) { if (!GTK_IS_BUTTON(help_dialog.btn)) { help_dialog.btn = gtk_button_new_with_label(OKAY_BUTTON); g_return_if_fail(GTK_IS_BUTTON(help_dialog.btn)); - g_signal_connect(help_dialog.btn, EV_CLICK, G_CALLBACK(hide_help_cb), help_dialog.win); + g_signal_connect(help_dialog.btn, EV_CLICK, G_CALLBACK(on_hide_help), help_dialog.win); gtk_box_append(GTK_BOX(help_dialog.box), help_dialog.btn); GtkEventController *kcntrl = gtk_event_controller_key_new(); if (GTK_IS_EVENT_CONTROLLER(kcntrl)) { // optional - g_signal_connect(kcntrl, EV_KEY, G_CALLBACK(help_dialog_cb), help_dialog.btn); + g_signal_connect(kcntrl, EV_KEY, G_CALLBACK(help_on_escape), help_dialog.btn); gtk_widget_add_controller(help_dialog.win, kcntrl); } } @@ -327,18 +334,21 @@ static void on_help(GSimpleAction *action, GVariant *var, GtkWindow *win) { show_help_dialog(help_dialog.win); } -static void on_quit(GSimpleAction *action, GVariant *var, GtkWindow *win) { +static void on_quit(GSimpleAction *action G_GNUC_UNUSED, GVariant *parameter G_GNUC_UNUSED, GtkWindow *win) { if (GTK_IS_WINDOW(win)) { MA_LOG(MENU_SA_QUIT, menu_sa_label); gtk_window_close(win); } } -static void on_legend(GSimpleAction *action, GVariant *var, void *unused) { +static void on_legend(GSimpleAction *action G_GNUC_UNUSED, + GVariant *parameter G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) { MA_LOG(ACCL_SA_LGND, accl_sa_label); opts.legend = !opts.legend; option_legend(); } #ifdef WITH_PLOT -void on_rotation(GSimpleAction *action, GVariant *var, t_kb_plot_aux *data) { +void on_rotation(GSimpleAction *action G_GNUC_UNUSED, + GVariant *parameter G_GNUC_UNUSED, t_kb_plot_aux *data) +{ if (!data || !is_tab_that(TAB_PLOT_NDX)) return; t_lg_space lg = opts.rglob ? data->global : data->local; if (!lg.aux || !lg.pval) return; @@ -354,7 +364,9 @@ void on_rotation(GSimpleAction *action, GVariant *var, t_kb_plot_aux *data) { set_rotor_n_redraw(step, lg.rev, lg.aux->pn); } -void on_scale(GSimpleAction *action, GVariant *var, t_kb_plot_aux *data) { +void on_scale(GSimpleAction *action G_GNUC_UNUSED, + GVariant *parameter G_GNUC_UNUSED, t_kb_plot_aux *data) +{ if (!data || !is_tab_that(TAB_PLOT_NDX)) return; int step = (data->label == ACCL_SA_IN) ? -1 : ((data->label == ACCL_SA_OUT) ? 1 : 0); const t_ent_spn_aux *aux = data->global.aux; @@ -396,14 +408,14 @@ static void map_sa_entries(GActionMap *map, GActionEntry entr[], t_sa_desc desc[ for (int i = 0; i < n; i++) desc[i].sa = G_SIMPLE_ACTION(g_action_map_lookup_action(map, entr[i].name)); } -#define LOOP_SET_ACCELS(desc) { for (int i = 0; i < G_N_ELEMENTS(desc); i++) \ +#define LOOP_SET_ACCELS(desc) { for (unsigned i = 0; i < G_N_ELEMENTS(desc); i++) \ gtk_application_set_accels_for_action(app, (desc)[i].name, (desc)[i].shortcut); } static gboolean create_action_menu(GtkApplication *app, GtkWidget *win, GtkWidget *bar) { g_return_val_if_fail(GTK_IS_APPLICATION(app) && GTK_IS_WINDOW(win) && GTK_IS_HEADER_BAR(bar), false); GActionMap *map = G_ACTION_MAP(app); map_sa_entries(map, menu_sa_entries, menu_sa_desc, G_N_ELEMENTS(menu_sa_entries), win); - for (int i = 0; i < G_N_ELEMENTS(accl_sa_entries); i++) + for (unsigned i = 0; i < G_N_ELEMENTS(accl_sa_entries); i++) map_sa_entries(map, &accl_sa_entries[i], &accl_sa_desc[i], 1, accl_sa_desc[i].data); if (!(action_menu = action_menu_init(bar))) return false; LOOP_SET_ACCELS(menu_sa_desc); @@ -425,7 +437,7 @@ static gboolean create_action_menu(GtkApplication *app, GtkWidget *win, GtkWidge static void action_update_internal(GMenu *menu) { if (G_IS_MENU(menu)) { g_menu_remove_all(menu); - for (int i = 0; i < G_N_ELEMENTS(menu_sa_desc); i++) { + for (unsigned i = 0; i < G_N_ELEMENTS(menu_sa_desc); i++) { GMenuItem *item = g_menu_item_new(menu_sa_label(i), menu_sa_desc[i].name); if (item) { g_menu_append_item(menu, item); g_object_unref(item); }}} gboolean run = pinger_state.run, pause = pinger_state.pause; diff --git a/ui/appbar.c b/ui/appbar.c index f588a4b..654581c 100644 --- a/ui/appbar.c +++ b/ui/appbar.c @@ -44,7 +44,7 @@ static gboolean start_datetime(GtkWidget *bar) { return true; } -static void target_cb(GtkWidget *widget, GtkWidget *entry) { +static void on_target(GtkEntry *entry G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) { g_return_if_fail(GTK_IS_EDITABLE(entry)); char *target = parser_valid_target(gtk_editable_get_text(GTK_EDITABLE(entry))); if (target) { @@ -64,7 +64,7 @@ static gboolean add_target_input(GtkWidget *bar) { gtk_editable_set_editable(GTK_EDITABLE(entry), true); gtk_editable_set_max_width_chars(GTK_EDITABLE(entry), g_utf8_strlen(hint, MAXHOSTNAME) - 5); if (opts.target) gtk_editable_set_text(GTK_EDITABLE(entry), opts.target); - g_signal_connect(entry, EV_ACTIVE, G_CALLBACK(target_cb), entry); + g_signal_connect(entry, EV_ACTIVE, G_CALLBACK(on_target), NULL); gtk_header_bar_pack_start(GTK_HEADER_BAR(bar), entry); return true; } diff --git a/ui/clipboard.c b/ui/clipboard.c index c77947c..d93a536 100644 --- a/ui/clipboard.c +++ b/ui/clipboard.c @@ -47,7 +47,9 @@ static void cb_popover_show(GtkWidget *popover, double x, double y) { gtk_popover_popup(GTK_POPOVER(popover)); } -static void cb_on_press(GtkGestureClick *gest, int cnt, double x, double y, GtkWidget *pop) { +static void cb_on_press(GtkGestureClick *gest, gint n_press G_GNUC_UNUSED, + gdouble x, gdouble y, GtkWidget *pop) +{ if (!GTK_IS_GESTURE_CLICK(gest) || !GTK_IS_POPOVER(pop)) return; GdkEvent *ev = gtk_gesture_get_last_event(GTK_GESTURE(gest), gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(gest))); @@ -68,7 +70,9 @@ static gboolean any_list_sel(t_tab *tab) { return false; } -static void cb_on_sel(GtkListBox* list, t_tab *tab) { if (tab) { tab->sel = any_list_sel(tab); cb_menu_update(tab); }} +static void cb_on_sel(GtkListBox *self G_GNUC_UNUSED, t_tab *tab) { + if (tab) { tab->sel = any_list_sel(tab); cb_menu_update(tab); } +} static char* c_strjoinv(const char delim, const char **array) { if (!array) return NULL; @@ -204,7 +208,7 @@ gboolean clipboard_init(GtkWidget *win, t_tab *tab) { gtk_widget_set_parent(tab->pop, tab->tab.w); g_signal_connect(gest, EV_PRESS, G_CALLBACK(cb_on_press), tab->pop); GtkWidget* list[] = {tab->hdr.w, tab->dyn.w, tab->info.w}; - for (int i = 0; i < G_N_ELEMENTS(list); i++) if (GTK_IS_LIST_BOX(list[i])) + for (unsigned i = 0; i < G_N_ELEMENTS(list); i++) if (GTK_IS_LIST_BOX(list[i])) g_signal_connect(list[i], EV_ROW_CHANGE, G_CALLBACK(cb_on_sel), tab); gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gest), 0); gtk_gesture_single_set_exclusive(GTK_GESTURE_SINGLE(gest), true); @@ -213,7 +217,7 @@ gboolean clipboard_init(GtkWidget *win, t_tab *tab) { return true; } -void cb_on_copy_l1(GSimpleAction *action, GVariant *var, void *data) { +void cb_on_copy_l1(GSimpleAction *self G_GNUC_UNUSED, GVariant *parameter G_GNUC_UNUSED, gpointer data) { t_tab *tab = data; if (!tab || !GTK_IS_LIST_BOX(tab->dyn.w)) return; GdkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(tab->tab.w)); @@ -224,7 +228,7 @@ void cb_on_copy_l1(GSimpleAction *action, GVariant *var, void *data) { } } -void cb_on_copy_l2(GSimpleAction *action, GVariant *var, void *data) { +void cb_on_copy_l2(GSimpleAction *self G_GNUC_UNUSED, GVariant *parameter G_GNUC_UNUSED, gpointer data) { t_tab *tab = data; if (!tab || !GTK_IS_LIST_BOX(tab->dyn.w)) return; GdkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(tab->tab.w)); @@ -257,7 +261,7 @@ void cb_tab_unsel(t_tab *tab) { } } -void cb_on_sall(GSimpleAction *action, GVariant *var, void *data) { +void cb_on_sall(GSimpleAction *self G_GNUC_UNUSED, GVariant *parameter G_GNUC_UNUSED, gpointer data) { t_tab *tab = data; if (!tab || !GTK_IS_LIST_BOX(tab->dyn.w)) return; VERBOSE("%s action %s", tab->name, cb_menu_label(tab->sel)); diff --git a/ui/notifier.c b/ui/notifier.c index c97fa92..1b527ab 100644 --- a/ui/notifier.c +++ b/ui/notifier.c @@ -64,7 +64,6 @@ static t_notifier notifier[] = { .x = 50, .y = 50, .movetoright = true }, #endif }; -#define NT_VALID_NDX(ndx) (((ndx) >= 0) && ((ndx) < G_N_ELEMENTS(notifier))) // @@ -157,7 +156,9 @@ static char* nb_lgnd_nth_state(int nth, gboolean enable) { return nb_lgnd_state_buff; } -static void nt_lgnd_row_cb(GtkListBox* self, GtkListBoxRow* row, void *data) { +static void nt_lgnd_row_cb(GtkListBox *self G_GNUC_UNUSED, + GtkListBoxRow *row, gpointer user_data G_GNUC_UNUSED) +{ if (GTK_IS_LIST_BOX_ROW(row)) { GtkWidget *box = gtk_list_box_row_get_child(row); if (GTK_IS_BOX(box)) { @@ -183,7 +184,9 @@ static void nt_lgnd_row_cb(GtkListBox* self, GtkListBoxRow* row, void *data) { } #ifdef WITH_DND -static GdkContentProvider* nt_dnd_drag(GtkDragSource *unused, gdouble x, gdouble y, t_notifier *nt) { +static GdkContentProvider* nt_dnd_drag(GtkDragSource *self G_GNUC_UNUSED, + gdouble x, gdouble y, t_notifier *nt) +{ GdkContentProvider *prov = NULL; if (nt) { nt->dx = round(x); nt->dy = round(y); @@ -192,7 +195,7 @@ static GdkContentProvider* nt_dnd_drag(GtkDragSource *unused, gdouble x, gdouble return prov; } -static void nt_dnd_icon(GtkDragSource *src, GdkDrag *drag, t_notifier *nt) { +static void nt_dnd_icon(GtkDragSource *src, GdkDrag *drag G_GNUC_UNUSED, t_notifier *nt) { if (GTK_IS_DRAG_SOURCE(src) && nt && GTK_IS_WIDGET(nt->box)) { GdkPaintable *icon = gtk_widget_paintable_new(nt->box); if (icon) { @@ -201,10 +204,12 @@ static void nt_dnd_icon(GtkDragSource *src, GdkDrag *drag, t_notifier *nt) { DNDORD("DND-icon: dx=%d dy=%d", nt->dx, nt->dy); }} } -static gboolean nt_on_drop(GtkDropTarget *unused, const GValue *val, gdouble x, gdouble y, t_notifier *receiver) { - gboolean okay = receiver && val && G_VALUE_HOLDS_POINTER(val); +static gboolean nt_on_drop(GtkDropTarget *self G_GNUC_UNUSED, const GValue *value, + gdouble x, gdouble y, t_notifier *receiver) +{ + gboolean okay = receiver && value && G_VALUE_HOLDS_POINTER(value); if (okay) { - t_notifier *sender = g_value_get_pointer(val); + t_notifier *sender = g_value_get_pointer(value); okay = sender && (sender == receiver); if (okay) { int sx = round(x) - sender->dx, sy = round(y) - sender->dy; @@ -268,7 +273,7 @@ static void nt_init_legend(GtkWidget *inbox, GtkWidget *over, t_notifier *nt) { g_signal_connect(inbox, EV_ROW_ACTIVE, G_CALLBACK(nt_lgnd_row_cb), NULL); if (style_loaded) nt_reload_css(inbox, CSS_GRAPH_BG); GtkSizeGroup* group[GE_MAX]; - for (int i = 0; i < G_N_ELEMENTS(group); i++) + for (unsigned i = 0; i < G_N_ELEMENTS(group); i++) group[i] = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); t_nt_leg *leg = nt->content ? nt->content : NULL; int n = nt->content_n; for (int i = 0; leg && (i < n); i++, leg++) { @@ -280,14 +285,16 @@ static void nt_init_legend(GtkWidget *inbox, GtkWidget *over, t_notifier *nt) { if (leg->row) nt_make_leg_row(GTK_LIST_BOX(inbox), group, i, leg, nt->css.col); } } - for (int i = 0; i < G_N_ELEMENTS(group); i++) if (group[i]) g_object_unref(group[i]); + for (unsigned i = 0; i < G_N_ELEMENTS(group); i++) if (group[i]) g_object_unref(group[i]); #ifdef WITH_DND nt_init_dnd_over(inbox, over, nt); #endif } #ifdef WITH_PLOT -static void nt_rotor_cb(GtkButton *unused, t_kb_plot_aux *aux) { if (aux) on_rotation(NULL, NULL, aux); } +static void nt_rotor_cb(GtkButton *self G_GNUC_UNUSED, t_kb_plot_aux *aux) { + if (aux) on_rotation(NULL, NULL, aux); +} static void nt_init_rotor(GtkWidget *inbox, GtkWidget *over, t_notifier *nt) { if (!GTK_IS_BOX(inbox)) return; @@ -307,13 +314,13 @@ static void nt_init_rotor(GtkWidget *inbox, GtkWidget *over, t_notifier *nt) { {&kb_plot_aux[ACCL_SA_PGDN], &kb_plot_aux[ACCL_SA_DOWN], &kb_plot_aux[ACCL_SA_PGUP] }, }; GtkSizeGroup* group[G_N_ELEMENTS(rotor_cntrl[0])]; - for (int i = 0; i < G_N_ELEMENTS(group); i++) + for (unsigned i = 0; i < G_N_ELEMENTS(group); i++) group[i] = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - for (int i = 0; i < G_N_ELEMENTS(rotor_cntrl); i++) { + for (unsigned i = 0; i < G_N_ELEMENTS(rotor_cntrl); i++) { GtkWidget *row = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); if (row) { gtk_box_append(GTK_BOX(inbox), row); - for (int j = 0; j < G_N_ELEMENTS(rotor_cntrl[j]); j++) { + for (unsigned j = 0; j < G_N_ELEMENTS(rotor_cntrl[j]); j++) { t_rotor_arrow *arrow = rotor_cntrl[i][j]; GtkWidget *elem = NULL; if (arrow) { const char *ico = is_sysicon(arrow->ico); @@ -329,7 +336,7 @@ static void nt_init_rotor(GtkWidget *inbox, GtkWidget *over, t_notifier *nt) { } } } - for (int i = 0; i < G_N_ELEMENTS(group); i++) if (group[i]) g_object_unref(group[i]); + for (unsigned i = 0; i < G_N_ELEMENTS(group); i++) if (group[i]) g_object_unref(group[i]); #ifdef WITH_DND nt_init_dnd_over(inbox, over, nt); #endif @@ -406,8 +413,8 @@ static void nt_fill_legend_elem(GtkWidget* label, const char *f1, const char *f2 // pub // -inline GtkWidget* notifier_init(int ndx, GtkWidget *base) { - return NT_VALID_NDX(ndx) ? nt_init(base, ¬ifier[ndx]) : NULL; } +inline GtkWidget* notifier_init(unsigned ndx, GtkWidget *base) { + return (ndx < G_N_ELEMENTS(notifier)) ? nt_init(base, ¬ifier[ndx]) : NULL; } void notifier_inform(const char *fmt, ...) { va_list ap; @@ -417,10 +424,10 @@ void notifier_inform(const char *fmt, ...) { va_end(ap); } -inline gboolean notifier_get_visible(int ndx) { - return NT_VALID_NDX(ndx) ? notifier[ndx].visible : false; } -inline void notifier_set_visible(int ndx, gboolean visible) { - if (NT_VALID_NDX(ndx)) nt_set_visible(¬ifier[ndx], visible); } +inline gboolean notifier_get_visible(unsigned ndx) { + return (ndx < G_N_ELEMENTS(notifier)) ? notifier[ndx].visible : false; } +inline void notifier_set_visible(unsigned ndx, gboolean visible) { + if (ndx < G_N_ELEMENTS(notifier)) nt_set_visible(¬ifier[ndx], visible); } void notifier_legend_vis_rows(int upto) { static int nt_lgnd_vis_rows; diff --git a/ui/notifier.h b/ui/notifier.h index 8332b6a..281dcf9 100644 --- a/ui/notifier.h +++ b/ui/notifier.h @@ -11,10 +11,10 @@ enum { NT_MAIN_NDX, NT_LEGEND_NDX, #endif }; -GtkWidget* notifier_init(int ndx, GtkWidget *base); +GtkWidget* notifier_init(unsigned ndx, GtkWidget *base); void notifier_inform(const char *fmt, ...); -gboolean notifier_get_visible(int ndx); -void notifier_set_visible(int ndx, gboolean visible); +gboolean notifier_get_visible(unsigned ndx); +void notifier_set_visible(unsigned ndx, gboolean visible); void notifier_legend_vis_rows(int upto); void notifier_legend_update(void); void notifier_legend_refresh(void); diff --git a/ui/option.c b/ui/option.c index 046129d..1705a0b 100644 --- a/ui/option.c +++ b/ui/option.c @@ -36,7 +36,8 @@ t_opts opts = { .target = NULL, .dns = DEF_DNS, .whois = DEF_WHOIS, .cycles = DE }; typedef struct ent_rad_map { - int ndx, val; + unsigned ndx; + int val; char *str; } t_ent_rad_map; @@ -363,7 +364,7 @@ static void toggle_cb(GtkCheckButton *check, t_ent_bool *en) { static void radio_cb(GtkCheckButton *check, t_ent_rad_map *map) { if (!GTK_IS_CHECK_BUTTON(check) || !map) return; - int ndx = map->ndx; if ((ndx < 0) || (ndx >= G_N_ELEMENTS(ent_rad))) return; + unsigned ndx = map->ndx; if (ndx >= G_N_ELEMENTS(ent_rad)) return; t_ent_rad *en = &ent_rad[ndx]; int *pval = en->pval, type = en->c.en.type; if (pval && ((type == ENT_RAD_IPV) || (type == ENT_RAD_GRAPH))) { @@ -377,9 +378,8 @@ static void radio_cb(GtkCheckButton *check, t_ent_rad_map *map) { } } -static void arrow_cb(GtkWidget *widget, t_ent_exp_common *en) { - if (!en) return; - if (GTK_IS_TOGGLE_BUTTON(en->arrow)) { +static void arrow_cb(GtkToggleButton *self G_GNUC_UNUSED, t_ent_exp_common *en) { + if (en && GTK_IS_TOGGLE_BUTTON(en->arrow)) { gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(en->arrow)); g_object_set(G_OBJECT(en->arrow), ICON_PROP, active ? GO_UP_ICON : GO_DOWN_ICON, NULL); if (GTK_IS_WIDGET(en->sub)) gtk_widget_set_visible(en->sub, active); @@ -611,10 +611,10 @@ static GtkWidget* add_opt_expand(GtkWidget* list, t_ent_exp *en) { if (!en) return NULL; GtkWidget *box = add_expand_common(list, &en->c); if (GTK_IS_BOX(box) && en->c.sub && en->desc) { - t_elem_desc *desc = en->desc; type2ndx_fn type2ndx = desc->t2e; - if (type2ndx) for (int i = desc->mm.min; i <= desc->mm.max; i++) { + t_elem_desc *desc = en->desc; type2ent_fn type2ent = desc->t2e; + if (type2ent) for (int i = desc->mm.min; i <= desc->mm.max; i++) { int type = desc->elems[i].type; - int ndx = type2ndx(type); + int ndx = type2ent(type); if (ndx < 0) WARN("Unknown %d type", type); else add_opt_check(en->c.sub, &ent_bool[ndx]); } @@ -666,7 +666,7 @@ static GtkWidget* add_opt_range(GtkWidget* listbox, t_ent_spn *en) { GtkWidget *box = add_expand_common(listbox, &en->c); if (GTK_IS_BOX(box) && en->c.sub) { t_ent_spn_elem *elem = en->list; - for (int n = 0; (n < G_N_ELEMENTS(en->list)) && elem && elem->title; n++, elem++) { + for (unsigned n = 0; (n < G_N_ELEMENTS(en->list)) && elem && elem->title; n++, elem++) { GtkWidget *subbox = NULL; switch (elem->kind) { #ifdef WITH_PLOT @@ -687,13 +687,13 @@ static GtkWidget* add_opt_range(GtkWidget* listbox, t_ent_spn *en) { #ifdef WITH_PLOT case ROTOR_COLUMN: add_opt_check(subbox, &ent_bool[ENT_BOOL_GLOB]); - for (int i = 0; i < ENT_SPN_ROT_MAX; i++) if (elem->aux[i].sfx) { + for (unsigned i = 0; i < ENT_SPN_ROT_MAX; i++) if (elem->aux[i].sfx) { GtkWidget *row = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, MARGIN); if (!row) continue; grey_into_box(row, gtk_label_new(elem->aux[i].sfx), true, true); add_minmax(row, elem, i, elem->aux[i].step, elem->aux[i].wrap); gtk_box_append(GTK_BOX(subbox), row); - if ((i >= ENT_SPN_ROT0) && (i <= ENT_SPN_ROT2)) // leave only buttons for rotation spins + if (/*(i >= ENT_SPN_ROT0) &&*/ i <= ENT_SPN_ROT2) // leave only buttons for rotation spins for (GtkWidget *txt = gtk_widget_get_first_child(GTK_WIDGET(elem->aux[i].spin)); GTK_IS_WIDGET(txt); txt = gtk_widget_get_next_sibling(txt)) if (GTK_IS_TEXT(txt)) gtk_widget_set_visible(txt, false); @@ -717,7 +717,7 @@ static GtkWidget* add_opt_radio(GtkWidget* list, t_ent_rad *en) { if (GTK_IS_BOX(box) && en->c.sub) { GtkWidget *group = NULL; t_ent_rad_map *map = en->map; - for (int i = 0; (i < G_N_ELEMENTS(en->map)) && map && map->str; i++, map++) { + for (unsigned i = 0; (i < G_N_ELEMENTS(en->map)) && map && map->str; i++, map++) { GtkWidget *button = gtk_check_button_new_with_label(map->str); g_return_val_if_fail(GTK_CHECK_BUTTON(button), box); if (style_loaded) gtk_widget_add_css_class(button, CSS_PAD); @@ -846,8 +846,8 @@ gboolean option_init(GtkWidget* bar) { } #define ENT_LOOP_SET(row) { if (GTK_IS_WIDGET(row)) gtk_widget_set_sensitive(row, notrun); } -#define ENT_LOOP_STR(arr) { for (int i = 0; i < G_N_ELEMENTS(arr); i++) ENT_LOOP_SET((arr)[i].box); } -#define ENT_LOOP_EXP(arr) { for (int i = 0; i < G_N_ELEMENTS(arr); i++) if (!(arr)[i].c.atrun) { \ +#define ENT_LOOP_STR(arr) { for (unsigned i = 0; i < G_N_ELEMENTS(arr); i++) ENT_LOOP_SET((arr)[i].box); } +#define ENT_LOOP_EXP(arr) { for (unsigned i = 0; i < G_N_ELEMENTS(arr); i++) if (!(arr)[i].c.atrun) { \ ENT_LOOP_SET((arr)[i].c.box); if (GTK_IS_TOGGLE_BUTTON((arr)[i].c.arrow)) \ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON((arr)[i].c.arrow), false); }} diff --git a/whois.c b/whois.c index 8642282..3615f69 100644 --- a/whois.c +++ b/whois.c @@ -312,13 +312,16 @@ void whois_resolv(t_hop *hop, int ndx) { } else FAIL("g_socket_client_new()"); } +static void wc_on_free(gpointer data, gpointer user_data G_GNUC_UNUSED) { wc_free(data); } +static void wq_on_close(gpointer data, gpointer user_data G_GNUC_UNUSED) { whois_query_close(data); } + void whois_cache_free(void) { PR_WHOIS_C; - g_slist_foreach(whois_cache, (GFunc)wc_free, NULL); + g_slist_foreach(whois_cache, wc_on_free, NULL); g_slist_free_full(whois_cache, g_free); whois_cache = NULL; PR_WHOIS_Q; - g_slist_foreach(whois_query, (GFunc)whois_query_close, NULL); + g_slist_foreach(whois_query, wq_on_close, NULL); g_slist_free(whois_query); whois_query = NULL; }