From 47c4bdcc4e0193128e1ef1daab5f6f4ee0fbf11f Mon Sep 17 00:00:00 2001 From: James Date: Thu, 12 Dec 2024 16:16:14 -0600 Subject: [PATCH 1/2] Update build action to clang-format-18 --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 476aa80d7a..912a2bfa72 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -597,7 +597,7 @@ jobs: with: fetch-depth: 0 - name: Run clang-format style check for C/C++ - uses: jidicula/clang-format-action@v4.11.0 + uses: jidicula/clang-format-action@v4.14.0 with: - clang-format-version: '11' + clang-format-version: '18' exclude-regex: 'dependencies' From 38b3d14bcf2a06ec54f99ddcbd070e3270cff2ea Mon Sep 17 00:00:00 2001 From: James Date: Thu, 12 Dec 2024 16:26:09 -0600 Subject: [PATCH 2/2] Format tree with clang-format-18 --- ai/default/daimilitary.h | 2 +- ai/tex/texai.c | 3 +- ai/tex/texaicity.c | 3 +- ai/threaded/threadedai.c | 3 +- client/options.cpp | 12 ++-- client/views/view_map_common.cpp | 4 +- common/aicore/path_finding.cpp | 2 +- common/clientutils.cpp | 2 +- common/events.cpp | 4 +- common/featured_text.h | 7 +-- common/game.h | 2 +- common/helpdata.cpp | 2 +- common/map.h | 10 +-- common/name_translation.h | 5 +- common/path_finder.cpp | 2 +- common/requirements.cpp | 7 ++- common/server_settings.h | 2 +- common/vision.h | 4 +- server/advisors/autosettlers.cpp | 2 +- server/aiiface.cpp | 2 +- server/diplomats.cpp | 6 +- server/savegame/savecompat.cpp | 2 +- server/score.cpp | 2 +- server/settings.cpp | 102 ++++++++++++++++++++----------- server/techtools.cpp | 9 +-- tools/fcmp/mpgui_qt_worker.h | 2 +- tools/ruledit/tab_enablers.cpp | 4 +- utility/bitvector.h | 4 +- utility/log.h | 12 ++-- utility/registry_ini.h | 84 ++++++++++++------------- utility/shared.h | 14 ++--- utility/speclist.h | 55 +++++++++-------- utility/specpq.h | 4 +- utility/specvec.h | 2 +- utility/support.h | 6 +- 35 files changed, 207 insertions(+), 181 deletions(-) diff --git a/ai/default/daimilitary.h b/ai/default/daimilitary.h index 7506ff720a..647a4039c3 100644 --- a/ai/default/daimilitary.h +++ b/ai/default/daimilitary.h @@ -23,7 +23,7 @@ to finish him off. */ #define FINISH_HIM_CITY_COUNT 5 -typedef struct unit_list *(player_unit_list_getter)(struct player *pplayer); +typedef struct unit_list *(player_unit_list_getter) (struct player *pplayer); struct unit_type *dai_choose_defender_versus(struct city *pcity, struct unit *attacker); diff --git a/ai/tex/texai.c b/ai/tex/texai.c index 790656ce87..19f2999f2e 100644 --- a/ai/tex/texai.c +++ b/ai/tex/texai.c @@ -575,8 +575,7 @@ bool fc_ai_tex_setup(struct ai_type *ai) qstrncpy(ai->name, "tex", sizeof(ai->name)); - ai->private = new struct dai_private_data { - }; + ai->private = new struct dai_private_data {}; ai->private->contemplace_workers = false; /* We use custom code to set worker want and type */ diff --git a/ai/tex/texaicity.c b/ai/tex/texaicity.c index 61e22114e1..0c2e52494c 100644 --- a/ai/tex/texaicity.c +++ b/ai/tex/texaicity.c @@ -583,8 +583,7 @@ void texai_req_worker_task_rcv(struct texai_req *req) **************************************************************************/ void texai_city_alloc(struct ai_type *ait, struct city *pcity) { - struct texai_city *city_data = new struct texai_city { - }; + struct texai_city *city_data = new struct texai_city {}; city_data->defai.building_wait = BUILDING_WAIT_MINIMUM; adv_init_choice(&(city_data->defai.choice)); diff --git a/ai/threaded/threadedai.c b/ai/threaded/threadedai.c index d2f6e8178f..a96bbb7efd 100644 --- a/ai/threaded/threadedai.c +++ b/ai/threaded/threadedai.c @@ -570,8 +570,7 @@ bool fc_ai_threaded_setup(struct ai_type *ai) qstrncpy(ai->name, "threaded", sizeof(ai->name)); - ai->private = new struct dai_private_data { - }; + ai->private = new struct dai_private_data {}; ai->private->contemplace_workers = true; tai_init_self(ai); diff --git a/client/options.cpp b/client/options.cpp index 894ce659cd..0b1fa0de23 100644 --- a/client/options.cpp +++ b/client/options.cpp @@ -245,11 +245,13 @@ struct option { #define OPTION_INIT(optset, spec_type, spec_table_var, common_table, \ spec_table, changed_cb, cb_data) \ - { \ - .poptset = optset, .type = spec_type, .common_vtable = &common_table, \ - .spec_table_var = &spec_table, .changed_callback = changed_cb, \ - .callback_data = cb_data, .gui_data = nullptr \ - } + {.poptset = optset, \ + .type = spec_type, \ + .common_vtable = &common_table, \ + .spec_table_var = &spec_table, \ + .changed_callback = changed_cb, \ + .callback_data = cb_data, \ + .gui_data = nullptr} #define OPTION_BOOL_INIT(optset, common_table, bool_table, changed_cb) \ OPTION_INIT(optset, OT_BOOLEAN, bool_vtable, common_table, bool_table, \ changed_cb, 0) diff --git a/client/views/view_map_common.cpp b/client/views/view_map_common.cpp index 86e78ce09f..ebfed5de3b 100644 --- a/client/views/view_map_common.cpp +++ b/client/views/view_map_common.cpp @@ -318,8 +318,8 @@ bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, const tile *ptile) * backing store we need to draw it in case the canvas is resized. */ return (*canvas_x > -tileset_tile_width(tileset) - && *canvas_x - tileset_tile_height(tileset) + && *canvas_x < mapview.store_width + && *canvas_y > -tileset_tile_height(tileset) && *canvas_y < (mapview.store_height + (tileset_full_tile_height(tileset) - tileset_tile_height(tileset)))); diff --git a/common/aicore/path_finding.cpp b/common/aicore/path_finding.cpp index 9c1e695d69..0441934934 100644 --- a/common/aicore/path_finding.cpp +++ b/common/aicore/path_finding.cpp @@ -938,7 +938,7 @@ struct pf_danger_node { signed short cost; // See comment above. unsigned extra_cost; // See comment above. signed dir_to_here : 4; // See comment above. - } * danger_segment; + } *danger_segment; }; // Derived structure of struct pf_map. diff --git a/common/clientutils.cpp b/common/clientutils.cpp index b8fc65cd64..2059d72e48 100644 --- a/common/clientutils.cpp +++ b/common/clientutils.cpp @@ -46,7 +46,7 @@ static void calc_activity(struct actcalc *calc, const struct tile *ptile) int rmextra_units[MAX_EXTRA_TYPES][ACTIVITY_LAST]; int activity_total[ACTIVITY_LAST]; int activity_units[ACTIVITY_LAST]; - } * t; + } *t; t = new tmp_state[1](); memset(calc, 0, sizeof(*calc)); diff --git a/common/events.cpp b/common/events.cpp index 2241f72005..691804c2b3 100644 --- a/common/events.cpp +++ b/common/events.cpp @@ -50,9 +50,7 @@ static const char *event_sections[] = { N_("Vote: %s"), N_("Wonder: %s"), nullptr}; #define GEN_EV(event, section, descr) \ - { \ -#event, nullptr, section, descr, nullptr, event \ - } + {#event, nullptr, section, descr, nullptr, event} /* * Holds information about all event types. The entries don't have diff --git a/common/featured_text.h b/common/featured_text.h index 0c227717a7..43108d0fc3 100644 --- a/common/featured_text.h +++ b/common/featured_text.h @@ -92,7 +92,7 @@ // Offset type (in bytes). typedef int ft_offset_t; // Unset offset value. -#define FT_OFFSET_UNSET ((ft_offset_t) -1) +#define FT_OFFSET_UNSET ((ft_offset_t) - 1) // Opaque type. struct text_tag; @@ -135,10 +135,7 @@ struct ft_color { const char *foreground; const char *background; }; -#define FT_COLOR(fg, bg) \ - { \ - fg, bg \ - } +#define FT_COLOR(fg, bg) {fg, bg} /************************************************************************** Constructor. **************************************************************************/ diff --git a/common/game.h b/common/game.h index c0d7969103..4fc0d4de62 100644 --- a/common/game.h +++ b/common/game.h @@ -541,7 +541,7 @@ extern struct world wld; #define GAME_DEFAULT_SCORETURN 20 #define GAME_DEFAULT_VICTORY_CONDITIONS \ - ((victory_condition_type)(1 << VC_SPACERACE | 1 << VC_ALLIED)) + ((victory_condition_type) (1 << VC_SPACERACE | 1 << VC_ALLIED)) #define GAME_DEFAULT_END_SPACESHIP true #define GAME_DEFAULT_SPACESHIP_TRAVEL_TIME 100 diff --git a/common/helpdata.cpp b/common/helpdata.cpp index c1a272a390..d76027fdba 100644 --- a/common/helpdata.cpp +++ b/common/helpdata.cpp @@ -4203,7 +4203,7 @@ void helptext_government(char *buf, size_t bufsz, struct player *pplayer, ratio); } } // else this effect somehow has no effect; keep quiet - } // else there was some extra condition making it complicated + } // else there was some extra condition making it complicated break; case EFT_UNIT_UPKEEP_FREE_PER_CITY: if (!unittype) { diff --git a/common/map.h b/common/map.h index 8ebbc6feb4..ff610d7893 100644 --- a/common/map.h +++ b/common/map.h @@ -104,7 +104,7 @@ bool map_startpos_remove(struct tile *ptile); #endif // FREECIV_DEBUG #define native_pos_to_index_nocheck(nat_x, nat_y) \ - ((nat_x) + (nat_y) *wld.map.xsize) + ((nat_x) + (nat_y) * wld.map.xsize) #define native_pos_to_index(nat_x, nat_y) \ (CHECK_NATIVE_POS((nat_x), (nat_y)), \ native_pos_to_index_nocheck(nat_x, nat_y)) @@ -116,14 +116,14 @@ bool map_startpos_remove(struct tile *ptile); /* Obscure math. See explanation in doc/HACKING. */ #define NATIVE_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \ - (MAP_IS_ISOMETRIC ? (*(pmap_x) = ((nat_y) + ((nat_y) &1)) / 2 + (nat_x), \ + (MAP_IS_ISOMETRIC ? (*(pmap_x) = ((nat_y) + ((nat_y) & 1)) / 2 + (nat_x), \ *(pmap_y) = (nat_y) - *(pmap_x) + wld.map.xsize) \ : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y))) #define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y) \ (MAP_IS_ISOMETRIC \ - ? (*(pnat_y) = (map_x) + (map_y) -wld.map.xsize, \ - *(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) &1)) / 2) \ + ? (*(pnat_y) = (map_x) + (map_y) - wld.map.xsize, \ + *(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) & 1)) / 2) \ : (*(pnat_x) = (map_x), *(pnat_y) = (map_y))) #define NATURAL_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \ @@ -132,7 +132,7 @@ bool map_startpos_remove(struct tile *ptile); : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y))) #define MAP_TO_NATURAL_POS(pnat_x, pnat_y, map_x, map_y) \ - (MAP_IS_ISOMETRIC ? (*(pnat_y) = (map_x) + (map_y) -wld.map.xsize, \ + (MAP_IS_ISOMETRIC ? (*(pnat_y) = (map_x) + (map_y) - wld.map.xsize, \ *(pnat_x) = 2 * (map_x) - *(pnat_y)) \ : (*(pnat_x) = (map_x), *(pnat_y) = (map_y))) diff --git a/common/name_translation.h b/common/name_translation.h index 26057bd401..26a03dd28a 100644 --- a/common/name_translation.h +++ b/common/name_translation.h @@ -29,10 +29,7 @@ struct name_translation { }; // Inititalization macro. -#define NAME_INIT \ - { \ - nullptr, "\0", "\0" \ - } +#define NAME_INIT {nullptr, "\0", "\0"} /**************************************************************************** Initializes a name translation structure. diff --git a/common/path_finder.cpp b/common/path_finder.cpp index 6921485873..f001cd364b 100644 --- a/common/path_finder.cpp +++ b/common/path_finder.cpp @@ -657,7 +657,7 @@ path_finder::path_finder(const unit *unit) */ path_finder::path_finder(const unit *unit, const path::step &init) : m_d(std::make_unique( - unit, detail::vertex{init, nullptr})) + unit, detail::vertex{init, nullptr})) { } diff --git a/common/requirements.cpp b/common/requirements.cpp index edb0e3820b..a900cf1376 100644 --- a/common/requirements.cpp +++ b/common/requirements.cpp @@ -3171,9 +3171,10 @@ bool is_req_active( req->source.value.building); break; case VUT_IMPR_GENUS: - eval = (target_building ? BOOL_TO_TRISTATE( - target_building->genus == req->source.value.impr_genus) - : TRI_MAYBE); + eval = + (target_building ? BOOL_TO_TRISTATE(target_building->genus + == req->source.value.impr_genus) + : TRI_MAYBE); break; case VUT_EXTRA: eval = is_extra_type_in_range(target_tile, target_city, req->range, diff --git a/common/server_settings.h b/common/server_settings.h index 61a12b7040..1dd3159eef 100644 --- a/common/server_settings.h +++ b/common/server_settings.h @@ -15,7 +15,7 @@ received a copy of the GNU General Public License along with Freeciv21. #include "fc_types.h" // Special value to signal the absence of a server setting. -#define SERVER_SETTING_NONE ((server_setting_id) -1) +#define SERVER_SETTING_NONE ((server_setting_id) - 1) // Pure server settings. server_setting_id server_setting_by_name(const char *name); diff --git a/common/vision.h b/common/vision.h index 62c692cb0a..eae41fe070 100644 --- a/common/vision.h +++ b/common/vision.h @@ -92,9 +92,7 @@ struct vision { // Initialize a vision radius array. #define V_RADIUS(main_sq, invis_sq, subs_sq) \ - { \ - (short) (main_sq), (short) (invis_sq), (short) (subs_sq) \ - } + {(short) (main_sq), (short) (invis_sq), (short) (subs_sq)} #define ASSERT_VISION(v) \ do { \ diff --git a/server/advisors/autosettlers.cpp b/server/advisors/autosettlers.cpp index 1870c89c0a..d1ac04ea67 100644 --- a/server/advisors/autosettlers.cpp +++ b/server/advisors/autosettlers.cpp @@ -748,7 +748,7 @@ adv_want settler_evaluate_improvements(struct unit *punit, } extra_type_iterate_end; } // endif: can we arrive sooner than current worker, if any? - } // endif: are we travelling to a legal destination? + } // endif: are we travelling to a legal destination? } city_tile_iterate_index_end; } diff --git a/server/aiiface.cpp b/server/aiiface.cpp index 5de9f1014e..193898a26e 100644 --- a/server/aiiface.cpp +++ b/server/aiiface.cpp @@ -70,7 +70,7 @@ bool load_ai_module(const char *modname) struct ai_type *ai = ai_type_alloc(); bool setup_success; lt_dlhandle handle; - bool (*setup_func)(struct ai_type * ai); + bool (*setup_func)(struct ai_type *ai); const char *(*capstr_func)(void); const char *capstr; char buffer[2048]; diff --git a/server/diplomats.cpp b/server/diplomats.cpp index 5f660631a1..6dc17f3046 100644 --- a/server/diplomats.cpp +++ b/server/diplomats.cpp @@ -272,10 +272,8 @@ bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat, struct city *pcity, const struct action *paction) { struct player *cplayer; - struct packet_unit_short_info unit_packet { - }; - struct packet_city_info city_packet { - }; + struct packet_unit_short_info unit_packet {}; + struct packet_city_info city_packet {}; struct traderoute_packet_list *routes; // Fetch target city's player. Sanity checks. diff --git a/server/savegame/savecompat.cpp b/server/savegame/savecompat.cpp index 251499ca8f..35159f8e79 100644 --- a/server/savegame/savecompat.cpp +++ b/server/savegame/savecompat.cpp @@ -226,7 +226,7 @@ int current_compat_ver() { return compat[compat_current].version; } */ char bin2ascii_hex(int value, int halfbyte_wanted) { - return hex_chars[((value) >> ((halfbyte_wanted) *4)) & 0xf]; + return hex_chars[((value) >> ((halfbyte_wanted) * 4)) & 0xf]; } /** diff --git a/server/score.cpp b/server/score.cpp index 9b0e45da72..1c8fec8a15 100644 --- a/server/score.cpp +++ b/server/score.cpp @@ -352,7 +352,7 @@ void calc_civ_score(struct player *pplayer) } unit_list_iterate_end - improvement_iterate(i) + improvement_iterate(i) { if (is_great_wonder(i) && (wonder_city = city_from_great_wonder(i)) && player_owns_city(pplayer, wonder_city)) { diff --git a/server/settings.cpp b/server/settings.cpp index 6e8071db95..f298940237 100644 --- a/server/settings.cpp +++ b/server/settings.cpp @@ -1283,56 +1283,90 @@ static bool plrcol_validate(int value, struct connection *caller, #define GEN_BOOL(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_validate, func_action, \ _default) \ - { \ - name, sclass, al_read, al_write, short_help, extra_help, nullptr, \ - SST_BOOL, scateg, slevel, \ - {.boolean = {&value, _default, func_validate, bool_name, false}}, \ - func_action, false \ - } + {name, \ + sclass, \ + al_read, \ + al_write, \ + short_help, \ + extra_help, \ + nullptr, \ + SST_BOOL, \ + scateg, \ + slevel, \ + {.boolean = {&value, _default, func_validate, bool_name, false}}, \ + func_action, \ + false} #define GEN_INT(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_help, func_validate, \ func_action, _min, _max, _default) \ - { \ - name, sclass, al_read, al_write, short_help, extra_help, func_help, \ - SST_INT, scateg, slevel, \ - {.integer = {(int *) &value, _default, _min, _max, func_validate, \ - 0}}, \ - func_action, false \ - } + {name, \ + sclass, \ + al_read, \ + al_write, \ + short_help, \ + extra_help, \ + func_help, \ + SST_INT, \ + scateg, \ + slevel, \ + {.integer = {(int *) &value, _default, _min, _max, func_validate, 0}}, \ + func_action, \ + false} #define GEN_STRING(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_validate, func_action, \ _default) \ - { \ - name, sclass, al_read, al_write, short_help, extra_help, nullptr, \ - SST_STRING, scateg, slevel, \ - {.string = {value, _default, sizeof(value), func_validate, \ - (char *) ""}}, \ - func_action, false \ - } + {name, \ + sclass, \ + al_read, \ + al_write, \ + short_help, \ + extra_help, \ + nullptr, \ + SST_STRING, \ + scateg, \ + slevel, \ + {.string = {value, _default, sizeof(value), func_validate, \ + (char *) ""}}, \ + func_action, \ + false} #define GEN_ENUM(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_help, func_validate, \ func_action, func_name, _default) \ - { \ - name, sclass, al_read, al_write, short_help, extra_help, func_help, \ - SST_ENUM, scateg, slevel, \ - {.enumerator = {&value, sizeof(value), _default, func_validate, \ - (val_name_func_t) func_name, 0}}, \ - func_action, false \ - } + {name, \ + sclass, \ + al_read, \ + al_write, \ + short_help, \ + extra_help, \ + func_help, \ + SST_ENUM, \ + scateg, \ + slevel, \ + {.enumerator = {&value, sizeof(value), _default, func_validate, \ + (val_name_func_t) func_name, 0}}, \ + func_action, \ + false} #define GEN_BITWISE(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_validate, func_action, \ func_name, _default) \ - { \ - name, sclass, al_read, al_write, short_help, extra_help, nullptr, \ - SST_BITWISE, scateg, slevel, \ - {.bitwise = {(unsigned *) (void *) &value, _default, func_validate, \ - func_name, 0}}, \ - func_action, false \ - } + {name, \ + sclass, \ + al_read, \ + al_write, \ + short_help, \ + extra_help, \ + nullptr, \ + SST_BITWISE, \ + scateg, \ + slevel, \ + {.bitwise = {(unsigned *) (void *) &value, _default, func_validate, \ + func_name, 0}}, \ + func_action, \ + false} // game settings static struct setting settings[] = { diff --git a/server/techtools.cpp b/server/techtools.cpp index a6e74f7053..0948144c7b 100644 --- a/server/techtools.cpp +++ b/server/techtools.cpp @@ -238,9 +238,10 @@ static inline void package_research_info(struct packet_research_info *packet, packet->future_tech = presearch->future_tech; packet->researching = presearch->researching; packet->researching_cost = - (packet->researching != A_UNSET ? research_total_bulbs_required( - presearch, presearch->researching, false) - : 0); + (packet->researching != A_UNSET + ? research_total_bulbs_required(presearch, presearch->researching, + false) + : 0); packet->bulbs_researched = presearch->bulbs_researched; packet->tech_goal = presearch->tech_goal; packet->total_bulbs_prod = 0; @@ -693,7 +694,7 @@ void update_bulbs(struct player *pplayer, int bulbs, bool check_tech) (is_future_tech(tech) ? "Future Tech" : qUtf8Printable( - research_advance_rule_name(research, tech)))); + research_advance_rule_name(research, tech)))); research_tech_lost(research, tech); /* Make notification after losing the research, in case it is * a future tech (for getting the right tech number). */ diff --git a/tools/fcmp/mpgui_qt_worker.h b/tools/fcmp/mpgui_qt_worker.h index 3dc318e397..bb7222038d 100644 --- a/tools/fcmp/mpgui_qt_worker.h +++ b/tools/fcmp/mpgui_qt_worker.h @@ -29,7 +29,7 @@ class mpqt_worker : public QThread { Q_OBJECT public: - mpqt_worker() : m_gui(nullptr), m_fcmp(nullptr){}; + mpqt_worker() : m_gui(nullptr), m_fcmp(nullptr) {}; void run() override; void download(const QUrl &url, mpgui *gui, fcmp_params *fcmp, const dl_msg_callback &msg_callback, diff --git a/tools/ruledit/tab_enablers.cpp b/tools/ruledit/tab_enablers.cpp index beb35b59e8..13572fb69d 100644 --- a/tools/ruledit/tab_enablers.cpp +++ b/tools/ruledit/tab_enablers.cpp @@ -324,10 +324,10 @@ void tab_enabler::add_now() new_enabler = action_enabler_new(); fc_assert_action(NUM_ACTIONS > 0, action_enabler_free(new_enabler); - return ); + return); fc_assert_action(action_id_exists(NUM_ACTIONS - 1), action_enabler_free(new_enabler); - return ); + return); new_enabler->action = (NUM_ACTIONS - 1); action_enabler_add(new_enabler); diff --git a/utility/bitvector.h b/utility/bitvector.h index c90189b87d..649d57f5ef 100644 --- a/utility/bitvector.h +++ b/utility/bitvector.h @@ -24,9 +24,9 @@ class QBitArray; (((val) & (1u << (bit_no))) == (1u << (bit_no))) // Static bitvectors. -#define _BV_BYTES(bits) ((((bits) -1) / 8) + 1) +#define _BV_BYTES(bits) ((((bits) - 1) / 8) + 1) #define _BV_BYTE_INDEX(bits) ((bits) / 8) -#define _BV_BITMASK(bit) (1u << ((bit) &0x7)) +#define _BV_BITMASK(bit) (1u << ((bit) & 0x7)) #ifdef FREECIV_DEBUG #define _BV_ASSERT(bv, bit) \ fc_assert((bit) >= 0 && (bit) < (signed int) sizeof((bv).vec) * 8) diff --git a/utility/log.h b/utility/log.h index 586d844bb9..8e6bdc71b0 100644 --- a/utility/log.h +++ b/utility/log.h @@ -94,11 +94,11 @@ void fc_assert_handle_failure(const char *condition, const char *file, // Like assert() with extra message. #define fc_assert_msg(condition, message, ...) \ - ((condition) \ - ? ((void) 0) \ - : fc_assert_handle_failure( \ - #condition, QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, \ - QT_MESSAGELOG_FUNC, QString::asprintf(message, ##__VA_ARGS__))) + ((condition) ? ((void) 0) \ + : fc_assert_handle_failure( \ + #condition, QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, \ + QT_MESSAGELOG_FUNC, \ + QString::asprintf(message, ##__VA_ARGS__))) // Do action on failure. #define fc_assert_action(condition, action) \ @@ -109,7 +109,7 @@ void fc_assert_handle_failure(const char *condition, const char *file, } // Return on failure. -#define fc_assert_ret(condition) fc_assert_action(condition, return ) +#define fc_assert_ret(condition) fc_assert_action(condition, return) // Return a value on failure. #define fc_assert_ret_val(condition, val) \ fc_assert_action(condition, return val) diff --git a/utility/registry_ini.h b/utility/registry_ini.h index e6902a89f2..3bf658149a 100644 --- a/utility/registry_ini.h +++ b/utility/registry_ini.h @@ -244,16 +244,16 @@ struct entry *secfile_insert_bitwise_enum_full( comment, allow_replace, path, ...) \ (specenum_type##_is_bitwise() \ ? secfile_insert_bitwise_enum_full( \ - secfile, enumerator, \ - (secfile_enum_name_fn_t) specenum_type##_name, \ - (secfile_enum_iter_fn_t) specenum_type##_begin, \ - (secfile_enum_iter_fn_t) specenum_type##_end, \ - (secfile_enum_next_fn_t) specenum_type##_next, comment, \ - allow_replace, path, ##__VA_ARGS__) \ + secfile, enumerator, \ + (secfile_enum_name_fn_t) specenum_type##_name, \ + (secfile_enum_iter_fn_t) specenum_type##_begin, \ + (secfile_enum_iter_fn_t) specenum_type##_end, \ + (secfile_enum_next_fn_t) specenum_type##_next, comment, \ + allow_replace, path, ##__VA_ARGS__) \ : secfile_insert_plain_enum_full( \ - secfile, enumerator, \ - (secfile_enum_name_fn_t) specenum_type##_name, comment, \ - allow_replace, path, ##__VA_ARGS__)) + secfile, enumerator, \ + (secfile_enum_name_fn_t) specenum_type##_name, comment, \ + allow_replace, path, ##__VA_ARGS__)) #define secfile_insert_enum(secfile, enumerator, specenum_type, path, ...) \ secfile_insert_enum_full(secfile, enumerator, specenum_type, nullptr, \ false, path, ##__VA_ARGS__) @@ -283,16 +283,16 @@ size_t secfile_insert_bitwise_enum_vec_full( path, ...) \ (specenum_type##_is_bitwise() \ ? secfile_insert_bitwise_enum_vec_full( \ - secfile, (const int *) enumerators, dim, \ - (secfile_enum_name_fn_t) specenum_type##_name, \ - (secfile_enum_iter_fn_t) specenum_type##_begin, \ - (secfile_enum_iter_fn_t) specenum_type##_end, \ - (secfile_enum_next_fn_t) specenum_type##_next, comment, \ - allow_replace, path, ##__VA_ARGS__) \ + secfile, (const int *) enumerators, dim, \ + (secfile_enum_name_fn_t) specenum_type##_name, \ + (secfile_enum_iter_fn_t) specenum_type##_begin, \ + (secfile_enum_iter_fn_t) specenum_type##_end, \ + (secfile_enum_next_fn_t) specenum_type##_next, comment, \ + allow_replace, path, ##__VA_ARGS__) \ : secfile_insert_plain_enum_vec_full( \ - secfile, (const int *) enumerators, dim, \ - (secfile_enum_name_fn_t) specenum_type##_name, comment, \ - allow_replace, path, ##__VA_ARGS__)) + secfile, (const int *) enumerators, dim, \ + (secfile_enum_name_fn_t) specenum_type##_name, comment, \ + allow_replace, path, ##__VA_ARGS__)) #define secfile_insert_enum_vec(secfile, enumerators, dim, specenum_type, \ path, ...) \ secfile_insert_enum_vec_full(secfile, enumerators, dim, specenum_type, \ @@ -424,15 +424,15 @@ bool secfile_lookup_bitwise_enum_full(const struct section_file *secfile, #define secfile_lookup_enum(secfile, enumerator, specenum_type, path, ...) \ (specenum_type##_is_bitwise() \ ? secfile_lookup_bitwise_enum_full( \ - secfile, FC_ENUM_PTR(enumerator), \ - (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ - (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ - ##__VA_ARGS__) \ + secfile, FC_ENUM_PTR(enumerator), \ + (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ + (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ + ##__VA_ARGS__) \ : secfile_lookup_plain_enum_full( \ - secfile, FC_ENUM_PTR(enumerator), \ - (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ - (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ - ##__VA_ARGS__)) + secfile, FC_ENUM_PTR(enumerator), \ + (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ + (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ + ##__VA_ARGS__)) int secfile_lookup_plain_enum_default_full( const struct section_file *secfile, int defval, secfile_enum_is_valid_fn_t is_valid_fn, @@ -449,15 +449,15 @@ int secfile_lookup_bitwise_enum_default_full( ...) \ (specenum_type##_is_bitwise() \ ? secfile_lookup_bitwise_enum_default_full( \ - secfile, defval, \ - (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ - (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ - ##__VA_ARGS__) \ + secfile, defval, \ + (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ + (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ + ##__VA_ARGS__) \ : secfile_lookup_plain_enum_default_full( \ - secfile, defval, \ - (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ - (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ - ##__VA_ARGS__)) + secfile, defval, \ + (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ + (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ + ##__VA_ARGS__)) int *secfile_lookup_plain_enum_vec_full( const struct section_file *secfile, size_t *dim, secfile_enum_is_valid_fn_t is_valid_fn, @@ -473,15 +473,15 @@ int *secfile_lookup_bitwise_enum_vec_full( #define secfile_lookup_enum_vec(secfile, dim, specenum_type, path, ...) \ (specenum_type##_is_bitwise() \ ? (enum specenum_type *) secfile_lookup_bitwise_enum_vec_full( \ - secfile, dim, \ - (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ - (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ - ##__VA_ARGS__) \ + secfile, dim, \ + (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ + (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ + ##__VA_ARGS__) \ : (enum specenum_type *) secfile_lookup_plain_enum_vec_full( \ - secfile, dim, \ - (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ - (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ - ##__VA_ARGS__)) + secfile, dim, \ + (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \ + (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \ + ##__VA_ARGS__)) bool secfile_lookup_enum_data(const struct section_file *secfile, int *pvalue, bool bitwise, diff --git a/utility/shared.h b/utility/shared.h index 63c35cd13c..cf7af84cb3 100644 --- a/utility/shared.h +++ b/utility/shared.h @@ -80,17 +80,17 @@ enum fc_tristate fc_tristate_and(enum fc_tristate one, enum fc_tristate two); #define ADD_TO_POINTER(p, n) ((void *) ((char *) (p) + (n))) #define FC_MEMBER(type, member) (((type *) nullptr)->member) -#define FC_MEMBER_OFFSETOF(type, member) ((size_t) &FC_MEMBER(type, member)) +#define FC_MEMBER_OFFSETOF(type, member) ((size_t) & FC_MEMBER(type, member)) #define FC_MEMBER_SIZEOF(type, member) sizeof(FC_MEMBER(type, member)) #define FC_MEMBER_ARRAY_SIZE(type, member) \ ARRAY_SIZE(FC_MEMBER(type, member)) -#define FC_INT_TO_PTR(i) ((void *) (intptr_t)(i)) -#define FC_PTR_TO_INT(p) ((int) (intptr_t)(p)) -#define FC_UINT_TO_PTR(u) ((void *) (intptr_t)(u)) -#define FC_PTR_TO_UINT(p) ((unsigned int) (intptr_t)(p)) -#define FC_SIZE_TO_PTR(s) ((void *) (intptr_t)(s)) -#define FC_PTR_TO_SIZE(p) ((size_t)(intptr_t)(p)) +#define FC_INT_TO_PTR(i) ((void *) (intptr_t) (i)) +#define FC_PTR_TO_INT(p) ((int) (intptr_t) (p)) +#define FC_UINT_TO_PTR(u) ((void *) (intptr_t) (u)) +#define FC_PTR_TO_UINT(p) ((unsigned int) (intptr_t) (p)) +#define FC_SIZE_TO_PTR(s) ((void *) (intptr_t) (s)) +#define FC_PTR_TO_SIZE(p) ((size_t) (intptr_t) (p)) /**************************************************************************** Used to initialize an array 'a' of size 'size' with value 'val' in each diff --git a/utility/speclist.h b/utility/speclist.h index 23888078bd..942c02a273 100644 --- a/utility/speclist.h +++ b/utility/speclist.h @@ -171,8 +171,7 @@ static inline SPECLIST_LIST * free_data_func) fc__warn_unused_result; static inline SPECLIST_LIST * - SPECLIST_FOO(_list_new_full)(SPECLIST_FOO(_list_free_fn_t) - free_data_func) +SPECLIST_FOO(_list_new_full)(SPECLIST_FOO(_list_free_fn_t) free_data_func) { return (reinterpret_cast(genlist_new_full( reinterpret_cast(free_data_func)))); @@ -193,7 +192,7 @@ static inline SPECLIST_LIST *SPECLIST_FOO(_list_copy)( const SPECLIST_LIST *tthis) fc__warn_unused_result; static inline SPECLIST_LIST * - SPECLIST_FOO(_list_copy)(const SPECLIST_LIST *tthis) +SPECLIST_FOO(_list_copy)(const SPECLIST_LIST *tthis) { return reinterpret_cast( genlist_copy(reinterpret_cast(tthis))); @@ -207,9 +206,10 @@ static inline SPECLIST_LIST *SPECLIST_FOO(_list_copy_full)( const SPECLIST_LIST *tthis, SPECLIST_FOO(_list_copy_fn_t) copy_data_func, SPECLIST_FOO(_list_free_fn_t) free_data_func) fc__warn_unused_result; -static inline SPECLIST_LIST *SPECLIST_FOO(_list_copy_full)( - const SPECLIST_LIST *tthis, SPECLIST_FOO(_list_copy_fn_t) copy_data_func, - SPECLIST_FOO(_list_free_fn_t) free_data_func) +static inline SPECLIST_LIST * +SPECLIST_FOO(_list_copy_full)(const SPECLIST_LIST *tthis, + SPECLIST_FOO(_list_copy_fn_t) copy_data_func, + SPECLIST_FOO(_list_free_fn_t) free_data_func) { return (reinterpret_cast(genlist_copy_full( reinterpret_cast(tthis), @@ -237,8 +237,9 @@ static inline void SPECLIST_FOO(_list_unique)(SPECLIST_LIST *tthis) Remove all element duplicates (the speclist must be sorted before), using 'comp_data_func' to determine if the elements are equivalents. ****************************************************************************/ -static inline void SPECLIST_FOO(_list_unique_full)( - SPECLIST_LIST *tthis, SPECLIST_FOO(_list_comp_fn_t) comp_data_func) +static inline void +SPECLIST_FOO(_list_unique_full)(SPECLIST_LIST *tthis, + SPECLIST_FOO(_list_comp_fn_t) comp_data_func) { genlist_unique_full(reinterpret_cast(tthis), reinterpret_cast(comp_data_func)); @@ -306,8 +307,9 @@ static inline bool SPECLIST_FOO(_list_remove)(SPECLIST_LIST *tthis, Remove the first element which fit the conditional function. Returns TRUE on success. ****************************************************************************/ -static inline bool SPECLIST_FOO(_list_remove_if)( - SPECLIST_LIST *tthis, SPECLIST_FOO(_list_cond_fn_t) cond_data_func) +static inline bool +SPECLIST_FOO(_list_remove_if)(SPECLIST_LIST *tthis, + SPECLIST_FOO(_list_cond_fn_t) cond_data_func) { return genlist_remove_if( reinterpret_cast(tthis), @@ -377,7 +379,7 @@ static inline int SPECLIST_FOO(_list_size)(const SPECLIST_LIST *tthis) Return the element at position in the speclist. ****************************************************************************/ static inline SPECLIST_TYPE * - SPECLIST_FOO(_list_get)(const SPECLIST_LIST *tthis, int slindex) +SPECLIST_FOO(_list_get)(const SPECLIST_LIST *tthis, int slindex) { return (static_cast(genlist_get( reinterpret_cast(tthis), slindex))); @@ -387,7 +389,7 @@ static inline SPECLIST_TYPE * Return the first element of the speclist. ****************************************************************************/ static inline SPECLIST_TYPE * - SPECLIST_FOO(_list_front)(const SPECLIST_LIST *tthis) +SPECLIST_FOO(_list_front)(const SPECLIST_LIST *tthis) { return static_cast( genlist_front(reinterpret_cast(tthis))); @@ -397,7 +399,7 @@ static inline SPECLIST_TYPE * Return the last element of the speclist. ****************************************************************************/ static inline SPECLIST_TYPE * - SPECLIST_FOO(_list_back)(const SPECLIST_LIST *tthis) +SPECLIST_FOO(_list_back)(const SPECLIST_LIST *tthis) { return static_cast( genlist_back(reinterpret_cast(tthis))); @@ -407,7 +409,7 @@ static inline SPECLIST_TYPE * Return the element at position in the speclist. ****************************************************************************/ static inline SPECLIST_LINK * - SPECLIST_FOO(_list_link_get)(const SPECLIST_LIST *tthis, int slindex) +SPECLIST_FOO(_list_link_get)(const SPECLIST_LIST *tthis, int slindex) { return (reinterpret_cast(genlist_link_get( reinterpret_cast(tthis), slindex))); @@ -417,7 +419,7 @@ static inline SPECLIST_LINK * Return the head link of the speclist. ****************************************************************************/ static inline SPECLIST_LINK * - SPECLIST_FOO(_list_head)(const SPECLIST_LIST *tthis) +SPECLIST_FOO(_list_head)(const SPECLIST_LIST *tthis) { return reinterpret_cast( genlist_head(reinterpret_cast(tthis))); @@ -427,7 +429,7 @@ static inline SPECLIST_LINK * Return the tail link of the speclist. ****************************************************************************/ static inline SPECLIST_LINK * - SPECLIST_FOO(_list_tail)(const SPECLIST_LIST *tthis) +SPECLIST_FOO(_list_tail)(const SPECLIST_LIST *tthis) { return reinterpret_cast( genlist_tail(reinterpret_cast(tthis))); @@ -437,8 +439,8 @@ static inline SPECLIST_LINK * Return the link of the first element which match the data 'pfoo'. ****************************************************************************/ static inline SPECLIST_LINK * - SPECLIST_FOO(_list_search)(const SPECLIST_LIST *tthis, - const SPECLIST_TYPE *pfoo) +SPECLIST_FOO(_list_search)(const SPECLIST_LIST *tthis, + const SPECLIST_TYPE *pfoo) { return (reinterpret_cast(genlist_search( reinterpret_cast(tthis), pfoo))); @@ -447,8 +449,9 @@ static inline SPECLIST_LINK * /**************************************************************************** Return the link of the first element which match the conditional function. ****************************************************************************/ -static inline SPECLIST_LINK *SPECLIST_FOO(_list_search_if)( - const SPECLIST_LIST *tthis, SPECLIST_FOO(_list_cond_fn_t) cond_data_func) +static inline SPECLIST_LINK * +SPECLIST_FOO(_list_search_if)(const SPECLIST_LIST *tthis, + SPECLIST_FOO(_list_cond_fn_t) cond_data_func) { return (reinterpret_cast(genlist_search_if( reinterpret_cast(tthis), @@ -459,9 +462,9 @@ static inline SPECLIST_LINK *SPECLIST_FOO(_list_search_if)( Sort the speclist. ****************************************************************************/ static inline void - SPECLIST_FOO(_list_sort)(SPECLIST_LIST *tthis, - int (*compar)(const SPECLIST_TYPE *const *, - const SPECLIST_TYPE *const *)) +SPECLIST_FOO(_list_sort)(SPECLIST_LIST *tthis, + int (*compar)(const SPECLIST_TYPE *const *, + const SPECLIST_TYPE *const *)) { genlist_sort( reinterpret_cast(tthis), @@ -504,7 +507,7 @@ static inline void SPECLIST_FOO(_list_release_mutex)(SPECLIST_LIST *tthis) Return the data of the link. ****************************************************************************/ static inline SPECLIST_TYPE * - SPECLIST_FOO(_list_link_data)(const SPECLIST_LINK *plink) +SPECLIST_FOO(_list_link_data)(const SPECLIST_LINK *plink) { return (static_cast(genlist_link_data( reinterpret_cast(plink)))); @@ -517,7 +520,7 @@ static inline SPECLIST_LINK *SPECLIST_FOO(_list_link_prev)( const SPECLIST_LINK *plink) fc__warn_unused_result; static inline SPECLIST_LINK * - SPECLIST_FOO(_list_link_prev)(const SPECLIST_LINK *plink) +SPECLIST_FOO(_list_link_prev)(const SPECLIST_LINK *plink) { return (reinterpret_cast(genlist_link_prev( reinterpret_cast(plink)))); @@ -530,7 +533,7 @@ static inline SPECLIST_LINK *SPECLIST_FOO(_list_link_next)( const SPECLIST_LINK *plink) fc__warn_unused_result; static inline SPECLIST_LINK * - SPECLIST_FOO(_list_link_next)(const SPECLIST_LINK *plink) +SPECLIST_FOO(_list_link_next)(const SPECLIST_LINK *plink) { return (reinterpret_cast(genlist_link_next( reinterpret_cast(plink)))); diff --git a/utility/specpq.h b/utility/specpq.h index b09dd9d696..ca260b3cdc 100644 --- a/utility/specpq.h +++ b/utility/specpq.h @@ -118,8 +118,8 @@ static inline void SPECPQ_FOO(_pq_destroy)(SPECPQ_PQ *_pq) Alternative destructor for queue structure. ****************************************************************************/ static inline void - SPECPQ_FOO(_pq_destroy_full)(SPECPQ_PQ *_pq, - SPECPQ_FOO(_pq_data_free_fn_t) data_free) +SPECPQ_FOO(_pq_destroy_full)(SPECPQ_PQ *_pq, + SPECPQ_FOO(_pq_data_free_fn_t) data_free) { SPECPQ_PQ_ *pq = reinterpret_cast(_pq); int i; diff --git a/utility/specvec.h b/utility/specvec.h index 7b90ead086..c83633d4d2 100644 --- a/utility/specvec.h +++ b/utility/specvec.h @@ -89,7 +89,7 @@ static inline size_t SPECVEC_FOO(_vector_size)(const SPECVEC_VECTOR *tthis) } static inline SPECVEC_TYPE * - SPECVEC_FOO(_vector_get)(const SPECVEC_VECTOR *tthis, int svindex) +SPECVEC_FOO(_vector_get)(const SPECVEC_VECTOR *tthis, int svindex) { if (svindex == -1 && tthis->size > 0) { return tthis->p + tthis->size - 1; diff --git a/utility/support.h b/utility/support.h index 445b428544..e20fa52719 100644 --- a/utility/support.h +++ b/utility/support.h @@ -61,7 +61,7 @@ typedef int fc_errno; #define NFCPP_FREE(ptr) \ do { \ if (ptr) { \ - delete[](ptr); \ + delete[] (ptr); \ } \ } while (false) @@ -91,14 +91,14 @@ typedef int fc_errno; #define NFCNPP_FREE(ptr) \ do { \ if (ptr) { \ - delete[](ptr); \ + delete[] (ptr); \ (ptr) = nullptr; \ } \ } while (false) #define FCPP_FREE(ptr) \ do { \ - delete[](ptr); \ + delete[] (ptr); \ (ptr) = NULL; \ } while (false)