From 169a30de45739ee3044627a52aea9daae63ce56c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 22 Apr 2021 20:36:30 +0300 Subject: [PATCH 23/23] Xaw: Fix compile error when XawListChange() takes const parameter See osdn #42036 Signed-off-by: Marko Lindqvist --- client/gui-xaw/action_dialog.c | 12 +++++++----- client/gui-xaw/citydlg.c | 6 +++--- client/gui-xaw/cityrep.c | 12 +++++++----- client/gui-xaw/cma_fe.c | 4 ++-- client/gui-xaw/connectdlg.c | 2 +- client/gui-xaw/diplodlg.c | 2 +- client/gui-xaw/finddlg.c | 3 ++- client/gui-xaw/gotodlg.c | 5 +++-- client/gui-xaw/inteldlg.c | 2 +- client/gui-xaw/messagewin.c | 4 ++-- client/gui-xaw/pages.c | 2 +- client/gui-xaw/plrdlg.c | 2 +- client/gui-xaw/repodlgs.c | 8 +++++--- client/gui-xaw/wldlg.c | 6 +++--- configure.ac | 19 +++++++++++++++++++ 15 files changed, 58 insertions(+), 31 deletions(-) diff --git a/client/gui-xaw/action_dialog.c b/client/gui-xaw/action_dialog.c index ff063fdc60..102a6d92a5 100644 --- a/client/gui-xaw/action_dialog.c +++ b/client/gui-xaw/action_dialog.c @@ -536,8 +536,9 @@ static int create_advances_list(struct player *pplayer, advances_can_steal[j] = NULL; XtSetSensitive(spy_steal_command, FALSE); - - XawListChange(spy_advances_list, (char **)advances_can_steal, 0, 0, 1); + + XawListChange(spy_advances_list, + (CONST_FOR_XAW_LIST_CHANGE char **)advances_can_steal, 0, 0, 1); XtVaGetValues(spy_advances_list, XtNwidth, &width1, NULL); XtVaGetValues(spy_advances_list_label, XtNwidth, &width2, NULL); XtVaSetValues(spy_advances_list, XtNwidth, MAX(width1,width2), NULL); @@ -629,9 +630,10 @@ static int create_improvements_list(struct player *pplayer, improvements_can_sabotage[j] = NULL; XtSetSensitive(spy_sabotage_command, FALSE); - - XawListChange(spy_improvements_list, (String *) improvements_can_sabotage, - 0, 0, 1); + + XawListChange(spy_improvements_list, + (CONST_FOR_XAW_LIST_CHANGE char**) improvements_can_sabotage, + 0, 0, 1); XtVaGetValues(spy_improvements_list, XtNwidth, &width1, NULL); XtVaGetValues(spy_improvements_list_label, XtNwidth, &width2, NULL); XtVaSetValues(spy_improvements_list, XtNwidth, MAX(width1,width2), NULL); diff --git a/client/gui-xaw/citydlg.c b/client/gui-xaw/citydlg.c index 4b0442d8ab..4d7d0d3072 100644 --- a/client/gui-xaw/citydlg.c +++ b/client/gui-xaw/citydlg.c @@ -130,9 +130,9 @@ struct city_dialog { int support_unit_base; int present_unit_base; char improvlist_names[B_LAST+1][64]; - char *improvlist_names_ptrs[B_LAST+1]; - - char *change_list_names_ptrs[B_LAST+1+U_LAST+1+1]; + CONST_FOR_XAW_LIST_CHANGE char *improvlist_names_ptrs[B_LAST + 1]; + + CONST_FOR_XAW_LIST_CHANGE char *change_list_names_ptrs[B_LAST + 1 + U_LAST + 1 + 1]; char change_list_names[B_LAST+1+U_LAST+1][200]; int change_list_ids[B_LAST+1+U_LAST+1]; int change_list_num_improvements; diff --git a/client/gui-xaw/cityrep.c b/client/gui-xaw/cityrep.c index ca80846eee..a905539558 100644 --- a/client/gui-xaw/cityrep.c +++ b/client/gui-xaw/cityrep.c @@ -569,7 +569,7 @@ void real_city_report_dialog_update(void *unused) } XawFormDoLayout(city_form, False); - XawListChange(city_list, city_list_text, i, 0, True); + XawListChange(city_list, (CONST_FOR_XAW_LIST_CHANGE char **)city_list_text, i, 0, True); XtVaGetValues(city_list, XtNlongest, &i, NULL); width=i+10; @@ -601,7 +601,7 @@ void real_city_report_update_city(struct city *pcity) for(i=0; cities_in_list[i]; i++) { if(cities_in_list[i]==pcity) { int n; - String *list; + char **list; Dimension w; char new_city_line[MAX_LEN_CITY_TEXT]; @@ -621,7 +621,7 @@ void real_city_report_update_city(struct city *pcity) change one line. It's also annoying to have to set the size of each widget explicitly, since Xt is supposed to handle that. */ XawFormDoLayout(city_form, False); - XawListChange(city_list, list, n, 0, False); + XawListChange(city_list, (CONST_FOR_XAW_LIST_CHANGE char **)list, n, 0, False); XtVaGetValues(city_list, XtNlongest, &n, NULL); w=n+10; XtVaSetValues(city_viewport, XtNwidth, w+15, NULL); @@ -1079,7 +1079,8 @@ static void chgall_refresh_command_callback(Widget w, state->fr_list[i] = fc_strdup(items[i].descr); state->fr_cids[i] = cid_encode(items[i].item); } - XawListChange(state->w.fr, state->fr_list, state->fr_count, 0, FALSE); + XawListChange(state->w.fr, (CONST_FOR_XAW_LIST_CHANGE char **)state->fr_list, + state->fr_count, 0, FALSE); state->to_count = collect_buildable_targets(targets); name_and_sort_items(targets, state->to_count, items, TRUE, NULL); @@ -1087,7 +1088,8 @@ static void chgall_refresh_command_callback(Widget w, state->to_list[i] = fc_strdup(items[i].descr); state->to_cids[i] = cid_encode(items[i].item); } - XawListChange(state->w.to, state->to_list, state->to_count, 0, FALSE); + XawListChange(state->w.to, (CONST_FOR_XAW_LIST_CHANGE char **)state->to_list, + state->to_count, 0, FALSE); chgall_update_widgets_state(state); } diff --git a/client/gui-xaw/cma_fe.c b/client/gui-xaw/cma_fe.c index 769b8f0779..8d4007092c 100644 --- a/client/gui-xaw/cma_fe.c +++ b/client/gui-xaw/cma_fe.c @@ -79,7 +79,7 @@ Widget surplus_slider[O_LAST], factor_slider[O_LAST + 1]; int minimal_surplus[O_LAST], factors[O_LAST + 1]; struct city *current_city; -char *initial_preset_list[] = { +CONST_FOR_XAW_LIST_CHANGE char *initial_preset_list[] = { N_("For information on\n" "the citizen governor and governor presets,\n" "including sample presets,\n" @@ -379,7 +379,7 @@ void show_cma_dialog(struct city *pcity, Widget citydlg) **************************************************************************/ static void update_cma_preset_list(void) { - static char *preset_lines[256]; + static CONST_FOR_XAW_LIST_CHANGE char *preset_lines[256]; static char preset_text[256][256]; int i; diff --git a/client/gui-xaw/connectdlg.c b/client/gui-xaw/connectdlg.c index aa2c9000f0..8342a4ed8c 100644 --- a/client/gui-xaw/connectdlg.c +++ b/client/gui-xaw/connectdlg.c @@ -615,7 +615,7 @@ static void server_list_timer(XtPointer meta_list, XtIntervalId * id) } if (get_server_list(servers_list, errbuf, sizeof(errbuf)) != -1) { - XawListChange(meta_list, servers_list, 0, 0, True); + XawListChange(meta_list, (CONST_FOR_XAW_LIST_CHANGE char **)servers_list, 0, 0, True); } /* else if (!lan_mode) { diff --git a/client/gui-xaw/diplodlg.c b/client/gui-xaw/diplodlg.c index 873efafd56..2e40e03837 100644 --- a/client/gui-xaw/diplodlg.c +++ b/client/gui-xaw/diplodlg.c @@ -100,7 +100,7 @@ struct Diplomacy_dialog { Widget dip_erase_clause_command; char clauselist_strings[MAX_NUM_CLAUSES+1][128]; - char *clauselist_strings_ptrs[MAX_NUM_CLAUSES+1]; + CONST_FOR_XAW_LIST_CHANGE char *clauselist_strings_ptrs[MAX_NUM_CLAUSES + 1]; }; static char *dummy_clause_list_strings[] diff --git a/client/gui-xaw/finddlg.c b/client/gui-xaw/finddlg.c index d8e2cc5201..ac25a38ac4 100644 --- a/client/gui-xaw/finddlg.c +++ b/client/gui-xaw/finddlg.c @@ -169,7 +169,8 @@ void update_find_dialog(Widget search_list) if (ncities_total) { qsort(city_name_ptrs, ncities_total, sizeof(char *), compare_strings_ptrs); - XawListChange(search_list, city_name_ptrs, ncities_total, 0, True); + XawListChange(search_list, (CONST_FOR_XAW_LIST_CHANGE char **) city_name_ptrs, + ncities_total, 0, True); } } diff --git a/client/gui-xaw/gotodlg.c b/client/gui-xaw/gotodlg.c index 1fc50741a4..752caa4cf3 100644 --- a/client/gui-xaw/gotodlg.c +++ b/client/gui-xaw/gotodlg.c @@ -79,7 +79,7 @@ void goto_list_callback(Widget w, XtPointer client_data, XtPointer call_data); static void cleanup_goto_list(void); -static char *dummy_city_list[]={ +static CONST_FOR_XAW_LIST_CHANGE char *dummy_city_list[] = { " ", " ", " ", @@ -249,7 +249,8 @@ void update_goto_dialog(Widget goto_cities) if (ncities_total) { qsort(city_name_ptrs, ncities_total, sizeof(char *), compare_strings_ptrs); - XawListChange(goto_cities, city_name_ptrs, ncities_total, 0, True); + XawListChange(goto_cities, (CONST_FOR_XAW_LIST_CHANGE char **) city_name_ptrs, + ncities_total, 0, True); } } diff --git a/client/gui-xaw/inteldlg.c b/client/gui-xaw/inteldlg.c index 925d21fcc2..595a4f3246 100644 --- a/client/gui-xaw/inteldlg.c +++ b/client/gui-xaw/inteldlg.c @@ -492,7 +492,7 @@ void update_intel_diplo_dialog(struct intel_dialog *pdialog) { int i; Dimension width; - static char *namelist_ptrs[MAX_NUM_PLAYERS]; + static CONST_FOR_XAW_LIST_CHANGE char *namelist_ptrs[MAX_NUM_PLAYERS]; static char namelist_text[MAX_NUM_PLAYERS][72]; const struct player_diplstate *state; diff --git a/client/gui-xaw/messagewin.c b/client/gui-xaw/messagewin.c index 9438eb7be2..153d35730b 100644 --- a/client/gui-xaw/messagewin.c +++ b/client/gui-xaw/messagewin.c @@ -64,7 +64,7 @@ static void meswin_goto_callback(Widget w, XtPointer client_data, static void meswin_popcity_callback(Widget w, XtPointer client_data, XtPointer call_data); -static char *dummy_message_list[] = { +static CONST_FOR_XAW_LIST_CHANGE char *dummy_message_list[] = { " ", 0 }; #define N_MSG_VIEW 24 /* max before scrolling happens */ @@ -245,7 +245,7 @@ void real_meswin_dialog_update(void *unused) XawListChange(meswin_list, dummy_message_list, 1, 0, True); } else { /* strings will not be freed */ - static char **strings = NULL; + static CONST_FOR_XAW_LIST_CHANGE char **strings = NULL; strings = fc_realloc(strings, num * sizeof(char *)); diff --git a/client/gui-xaw/pages.c b/client/gui-xaw/pages.c index 13f2fe1b70..d4baecb172 100644 --- a/client/gui-xaw/pages.c +++ b/client/gui-xaw/pages.c @@ -235,7 +235,7 @@ void real_update_start_page(void) bool is_ready; const char *nation, *leader; char name[MAX_LEN_NAME + 8]; - static char *namelist_ptrs[MAX_NUM_PLAYERS]; + static CONST_FOR_XAW_LIST_CHANGE char *namelist_ptrs[MAX_NUM_PLAYERS]; static char namelist_text[MAX_NUM_PLAYERS][256]; int j; Dimension width, height; diff --git a/client/gui-xaw/plrdlg.c b/client/gui-xaw/plrdlg.c index 2f4351af68..9978159ca4 100644 --- a/client/gui-xaw/plrdlg.c +++ b/client/gui-xaw/plrdlg.c @@ -212,7 +212,7 @@ void real_players_dialog_update(void *unused) if (players_dialog_shell) { int j = 0; Dimension width; - static char *namelist_ptrs[MAX_NUM_PLAYERS]; + static CONST_FOR_XAW_LIST_CHANGE char *namelist_ptrs[MAX_NUM_PLAYERS]; static char namelist_text[MAX_NUM_PLAYERS][256]; const struct player_diplstate *pds; diff --git a/client/gui-xaw/repodlgs.c b/client/gui-xaw/repodlgs.c index 458f96317c..5378547179 100644 --- a/client/gui-xaw/repodlgs.c +++ b/client/gui-xaw/repodlgs.c @@ -519,7 +519,9 @@ void real_science_report_dialog_update(void *unused) tech_list_names_ptrs[j]=0; qsort(tech_list_names_ptrs, j, sizeof(char *), compare_strings_ptrs); - XawListChange(science_list, (char **)tech_list_names_ptrs, 0/*j*/, 0, 1); + XawListChange(science_list, + (CONST_FOR_XAW_LIST_CHANGE char **)tech_list_names_ptrs, + 0/*j*/, 0, 1); XtDestroyWidget(popupmenu); @@ -773,7 +775,7 @@ void real_economy_report_dialog_update(void *unused) if(economy_dialog_shell) { int i, entries_used, tax, total; Dimension width; - static char *economy_list_names_ptrs[B_LAST+1]; + static CONST_FOR_XAW_LIST_CHANGE char *economy_list_names_ptrs[B_LAST + 1]; static char economy_list_names[B_LAST][200]; const char *report_title; char economy_total[48]; @@ -1075,7 +1077,7 @@ void real_units_report_dialog_update(void *unused) if (activeunits_dialog_shell) { int k; Dimension width; - static char *activeunits_list_names_ptrs[U_LAST+1]; + static CONST_FOR_XAW_LIST_CHANGE char *activeunits_list_names_ptrs[U_LAST + 1]; static char activeunits_list_names[U_LAST][200]; struct repoinfo unitarray[U_LAST]; struct repoinfo unittotals; diff --git a/client/gui-xaw/wldlg.c b/client/gui-xaw/wldlg.c index 68c458d48c..b117219939 100644 --- a/client/gui-xaw/wldlg.c +++ b/client/gui-xaw/wldlg.c @@ -66,7 +66,7 @@ struct worklist_report_dialog { Widget list; struct player *pplr; char worklist_names[MAX_NUM_WORKLISTS][MAX_LEN_NAME]; - char *worklist_names_ptrs[MAX_NUM_WORKLISTS+1]; + CONST_FOR_XAW_LIST_CHANGE char *worklist_names_ptrs[MAX_NUM_WORKLISTS+1]; struct global_worklist *worklist_ptr[MAX_NUM_WORKLISTS]; int wl_idx; }; @@ -90,10 +90,10 @@ struct worklist_dialog { WorklistOkCallback ok_callback; WorklistCancelCallback cancel_callback; - char *worklist_names_ptrs[MAX_LEN_WORKLIST+1]; + CONST_FOR_XAW_LIST_CHANGE char *worklist_names_ptrs[MAX_LEN_WORKLIST+1]; char worklist_names[MAX_LEN_WORKLIST][200]; int worklist_ids[MAX_LEN_WORKLIST]; - char *worklist_avail_names_ptrs[B_LAST+1+U_LAST+1+MAX_NUM_WORKLISTS+1+1]; + CONST_FOR_XAW_LIST_CHANGE char *worklist_avail_names_ptrs[B_LAST + 1 +U_LAST + 1 + MAX_NUM_WORKLISTS + 1 + 1]; char worklist_avail_names[B_LAST+1+U_LAST+1+MAX_NUM_WORKLISTS+1][200]; int worklist_avail_ids[B_LAST+1+U_LAST+1+MAX_NUM_WORKLISTS+1]; int worklist_avail_num_improvements; diff --git a/configure.ac b/configure.ac index 09df3d7efe..f6498f8bf1 100644 --- a/configure.ac +++ b/configure.ac @@ -1565,6 +1565,25 @@ LDFLAGS="$EXTRA_DEBUG_LDFLAGS $LDFLAGS" dnl Check this when -Werror is already set, if we're going to set it FC_VALUE_AFTER_EXIT +if test "x$gui_xaw" = "xyes" ; then + AC_CACHE_CHECK([['const' for XawListChange()]], [ac_cv_const_for_xaw_list_change], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include +]], + [char *test_strings[[2]]; +XawListChange(NULL, test_strings, 0, 0, False);])], + [ac_cv_const_for_xaw_list_change=no], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include +]], + [const char *test_strings[[2]]; +XawListChange(NULL, test_strings, 0, 0, False);])], + [ac_cv_const_for_xaw_list_change=yes], [ac_cv_const_for_xaw_list_change=unknown])])]) + if test "x${ac_cv_const_for_xaw_list_change}" = "xyes" ; then + AC_DEFINE([CONST_FOR_XAW_LIST_CHANGE], [const], [[Use const for XawListChange() parameter]]) + else + AC_DEFINE([CONST_FOR_XAW_LIST_CHANGE], [], [[Do not use const for XawListChange() parameter]]) + fi +fi + dnl Rebuild 'configure' whenever fc_version changes, if maintainer mode enabled. AC_SUBST([CONFIGURE_DEPENDENCIES], ["$CONFIGURE_DEPENDENCIES \$(top_srcdir)/fc_version"]) -- 2.30.2