From 16f229114a5459c0f3e07205b22ccebb5cfcf9f1 Mon Sep 17 00:00:00 2001 From: Andreas Mohr Date: Sat, 20 Feb 2016 14:29:21 +0000 Subject: [PATCH] Ticket #3598: cleanup some -Wcast-qual compiler warnings. Introduce CONST_WIDGET helper and use it. Signed-off-by: Andreas Mohr Signed-off-by: Andrew Borodin --- lib/widget/dialog.c | 4 ++-- lib/widget/widget-common.c | 2 +- lib/widget/widget-common.h | 3 ++- src/editor/editcmd.c | 6 +++--- src/editor/editcmd_dialogs.c | 2 +- src/editor/editdraw.c | 4 ++-- src/editor/editoptions.c | 5 +++-- src/editor/editwidget.c | 13 +++++++------ src/filemanager/boxes.c | 2 +- src/filemanager/find.c | 6 +++--- src/filemanager/panel.c | 12 ++++++------ 11 files changed, 31 insertions(+), 28 deletions(-) diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 216edf284..c8dddf916 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -201,7 +201,7 @@ dlg_unfocus (WDialog * h) static int dlg_find_widget_callback (const void *a, const void *b) { - const Widget *w = WIDGET (a); + const Widget *w = CONST_WIDGET (a); widget_cb_fn f = (widget_cb_fn) b; return (w->callback == f) ? 0 : 1; @@ -595,7 +595,7 @@ frontend_dlg_run (WDialog * h) static int dlg_find_widget_by_id (gconstpointer a, gconstpointer b) { - Widget *w = WIDGET (a); + const Widget *w = CONST_WIDGET (a); unsigned long id = GPOINTER_TO_UINT (b); return w->id == id ? 0 : 1; diff --git a/lib/widget/widget-common.c b/lib/widget/widget-common.c index 4bd9af294..d89cac7d3 100644 --- a/lib/widget/widget-common.c +++ b/lib/widget/widget-common.c @@ -281,7 +281,7 @@ widget_erase (Widget * w) gboolean widget_is_active (const void *w) { - return (w == WIDGET (w)->owner->current->data); + return (w == CONST_WIDGET (w)->owner->current->data); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index be5f41f01..9cb9d1371 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -12,8 +12,9 @@ /*** typedefs(not structures) and defined constants **********************************************/ #define WIDGET(x) ((Widget *)(x)) +#define CONST_WIDGET(x) ((const Widget *)(x)) -#define widget_move(w, _y, _x) tty_gotoyx (WIDGET(w)->y + (_y), WIDGET(w)->x + (_x)) +#define widget_move(w, _y, _x) tty_gotoyx (CONST_WIDGET(w)->y + (_y), CONST_WIDGET(w)->x + (_x)) /* Sets/clear the specified flag in the options field */ #define widget_want_cursor(w,i) widget_set_options(w, W_WANT_CURSOR, i) #define widget_want_hotkey(w,i) widget_set_options(w, W_WANT_HOTKEY, i) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 60dbf3d4d..86a3aa8fd 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1487,7 +1487,7 @@ edit_syntax_onoff_cb (void *data, void *user_data) { (void) user_data; - if (edit_widget_is_editor ((const Widget *) data)) + if (edit_widget_is_editor (CONST_WIDGET (data))) { WEdit *edit = (WEdit *) data; @@ -1511,7 +1511,7 @@ edit_redraw_page_cb (void *data, void *user_data) { (void) user_data; - if (edit_widget_is_editor ((const Widget *) data)) + if (edit_widget_is_editor (CONST_WIDGET (data))) ((WEdit *) data)->force |= REDRAW_PAGE; } @@ -2244,7 +2244,7 @@ edit_close_cmd (WEdit * edit) del_widget (edit); - if (edit_widget_is_editor (WIDGET (h->current->data))) + if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) edit = (WEdit *) h->current->data; else { diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index ed436f860..7fdd6b66a 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -346,7 +346,7 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean c char * editcmd_dialog_completion_show (const WEdit * edit, int max_len, GString ** compl, int num_compl) { - const Widget *we = WIDGET (edit); + const Widget *we = CONST_WIDGET (edit); int start_x, start_y, offset, i; char *curr = NULL; WDialog *compl_dlg; diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 4aac59718..230d75038 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -348,7 +348,7 @@ edit_status_window (WEdit * edit) static inline void edit_draw_frame (const WEdit * edit, int color, gboolean active) { - const Widget *w = (const Widget *) edit; + const Widget *w = CONST_WIDGET (edit); /* draw a frame around edit area */ tty_setcolor (color); @@ -374,7 +374,7 @@ edit_draw_frame (const WEdit * edit, int color, gboolean active) static inline void edit_draw_window_icons (const WEdit * edit, int color) { - const Widget *w = WIDGET (edit); + const Widget *w = CONST_WIDGET (edit); char tmp[17]; tty_setcolor (color); diff --git a/src/editor/editoptions.c b/src/editor/editoptions.c index cc19158ed..a299bf824 100644 --- a/src/editor/editoptions.c +++ b/src/editor/editoptions.c @@ -84,7 +84,7 @@ edit_reset_over_col (void *data, void *user_data) { (void) user_data; - if (edit_widget_is_editor ((const Widget *) data)) + if (edit_widget_is_editor (CONST_WIDGET (data))) ((WEdit *) data)->over_col = 0; } @@ -102,9 +102,10 @@ edit_reload_syntax (void *data, void *user_data) { (void) user_data; - if (edit_widget_is_editor (WIDGET (data))) + if (edit_widget_is_editor (CONST_WIDGET (data))) { WEdit *edit = (WEdit *) data; + edit_load_syntax (edit, NULL, edit->syntax_type); } } diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index d60f03eca..b66f668cc 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -332,7 +332,7 @@ edit_window_list (const WDialog * h) listbox = create_listbox_window (lines, cols, _("Open files"), "[Open files]"); for (w = h->widgets; w != NULL; w = g_list_next (w)) - if (edit_widget_is_editor (WIDGET (w->data))) + if (edit_widget_is_editor (CONST_WIDGET (w->data))) { WEdit *e = (WEdit *) w->data; char *fname; @@ -427,7 +427,7 @@ edit_dialog_command_execute (WDialog * h, long command) break; case CK_Close: /* if there are no opened files anymore, close MC editor */ - if (edit_widget_is_editor (WIDGET (h->current->data)) && + if (edit_widget_is_editor (CONST_WIDGET (h->current->data)) && edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL) dlg_stop (h); break; @@ -476,7 +476,7 @@ edit_dialog_command_execute (WDialog * h, long command) break; case CK_WindowMove: case CK_WindowResize: - if (edit_widget_is_editor (WIDGET (h->current->data))) + if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) edit_handle_move_resize ((WEdit *) h->current->data, command); break; case CK_WindowList: @@ -643,7 +643,7 @@ edit_quit (WDialog * h) h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ for (l = h->widgets; l != NULL; l = g_list_next (l)) - if (edit_widget_is_editor (WIDGET (l->data))) + if (edit_widget_is_editor (CONST_WIDGET (l->data))) { e = (WEdit *) l->data; @@ -890,7 +890,8 @@ edit_dialog_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) /* Try find top fullscreen window */ for (l = h->widgets; l != NULL; l = g_list_next (l)) - if (edit_widget_is_editor (WIDGET (l->data)) && ((WEdit *) l->data)->fullscreen) + if (edit_widget_is_editor (CONST_WIDGET (l->data)) + && ((WEdit *) l->data)->fullscreen) top = l; /* Handle fullscreen/close buttons in the top line */ @@ -1266,7 +1267,7 @@ edit_get_file_name (const WEdit * edit) WEdit * find_editor (const WDialog * h) { - if (edit_widget_is_editor (WIDGET (h->current->data))) + if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) return (WEdit *) h->current->data; return (WEdit *) find_widget_type (h, edit_callback); } diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index 6905e59be..46bbd276b 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -1139,7 +1139,7 @@ configure_vfs (void) char * cd_dialog (void) { - const Widget *w = WIDGET (current_panel); + const Widget *w = CONST_WIDGET (current_panel); char *my_str; quick_widget_t quick_widgets[] = { diff --git a/src/filemanager/find.c b/src/filemanager/find.c index a54aac9e6..ee5ad19c0 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -1228,7 +1228,7 @@ find_rotate_dash (const WDialog * h, gboolean show) { static size_t pos = 0; static const char rotating_dash[4] = "|/-\\"; - const Widget *w = WIDGET (h); + const Widget *w = CONST_WIDGET (h); if (!verbose) return; @@ -1458,7 +1458,7 @@ view_edit_currently_selected_file (gboolean unparsed_view, gboolean edit) static void find_calc_button_locations (const WDialog * h, gboolean all_buttons) { - const int cols = WIDGET (h)->cols; + const int cols = CONST_WIDGET (h)->cols; int l1, l2; @@ -1489,7 +1489,7 @@ find_relocate_buttons (const WDialog * h, gboolean all_buttons) find_calc_button_locations (h, all_buttons); for (i = 0; i < fbuts_num; i++) - fbuts[i].button->x = WIDGET (h)->x + fbuts[i].x; + fbuts[i].button->x = CONST_WIDGET (h)->x + fbuts[i].x; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index a598a3f59..3cc52065e 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -405,7 +405,7 @@ static int panel_lines (const WPanel * p) { /* 3 lines are: top frame, column header, botton frame */ - return (WIDGET (p)->lines - 3 - (panels_options.show_mini_info ? 2 : 0)); + return (CONST_WIDGET (p)->lines - 3 - (panels_options.show_mini_info ? 2 : 0)); } /* --------------------------------------------------------------------------------------------- */ @@ -1066,7 +1066,7 @@ paint_dir (WPanel * panel) static void display_total_marked_size (const WPanel * panel, int y, int x, gboolean size_only) { - Widget *w = WIDGET (panel); + const Widget *w = CONST_WIDGET (panel); char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf; int cols; @@ -1112,7 +1112,7 @@ mini_info_separator (const WPanel * panel) { if (panels_options.show_mini_info) { - Widget *w = WIDGET (panel); + const Widget *w = CONST_WIDGET (panel); int y; y = panel_lines (panel) + 2; @@ -1155,7 +1155,7 @@ show_free_space (const WPanel * panel) if (myfs_stats.avail != 0 || myfs_stats.total != 0) { - Widget *w = WIDGET (panel); + const Widget *w = CONST_WIDGET (panel); char buffer1[6], buffer2[6], tmp[BUF_SMALL]; size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1, @@ -1256,7 +1256,7 @@ panel_get_encoding_info_str (const WPanel * panel) static void show_dir (const WPanel * panel) { - Widget *w = WIDGET (panel); + const Widget *w = CONST_WIDGET (panel); gchar *tmp; @@ -1554,7 +1554,7 @@ panel_get_title_without_hotkey (const char *title) static void panel_print_header (const WPanel * panel) { - Widget *w = WIDGET (panel); + const Widget *w = CONST_WIDGET (panel); int y, x; int i; -- 2.11.4.GIT