diff options
author | Bardur Arantsson <bardur@scientician.net> | 2019-02-15 19:20:25 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2019-02-15 19:20:25 +0100 |
commit | 3eacc4f9835c697c50838b0f341355b5600d0256 (patch) | |
tree | 649f1289c133e4cfac1f8ab702be556016f96625 | |
parent | 5a2727af08483be1a529dcbdbe6aa286694162bc (diff) |
Replace uses of format() with fmt::format()
-rw-r--r-- | src/cmd2.cc | 13 | ||||
-rw-r--r-- | src/loadsave.cc | 9 | ||||
-rw-r--r-- | src/q_fireprof.cc | 5 | ||||
-rw-r--r-- | src/q_hobbit.cc | 4 | ||||
-rw-r--r-- | src/q_library.cc | 3 | ||||
-rw-r--r-- | src/q_poison.cc | 5 | ||||
-rw-r--r-- | src/q_rand.cc | 9 | ||||
-rw-r--r-- | src/q_shroom.cc | 4 | ||||
-rw-r--r-- | src/q_thrain.cc | 4 | ||||
-rw-r--r-- | src/skills.cc | 29 | ||||
-rw-r--r-- | src/squelch/condition.cc | 25 | ||||
-rw-r--r-- | src/util.cc | 6 | ||||
-rw-r--r-- | src/util.hpp | 1 | ||||
-rw-r--r-- | src/xtra2.cc | 3 |
14 files changed, 60 insertions, 60 deletions
diff --git a/src/cmd2.cc b/src/cmd2.cc index a8e2f5d8..3c57594e 100644 --- a/src/cmd2.cc +++ b/src/cmd2.cc @@ -3485,7 +3485,7 @@ void do_cmd_boomerang() /* Break the boomerang */ if ((!artifact_p(o_ptr)) && (rand_int(100) < j)) { - msg_print(format("Your %s is destroyed.", o_name)); + msg_print(fmt::format("Your {} is destroyed.", o_name)); inc_stack_size_ex(INVEN_BOW, -1, OPTIMIZE, NO_DESCRIBE); } } @@ -3844,7 +3844,7 @@ void do_cmd_sacrifice() if (deity_info[agod].desc[i] != NULL) msg_print(deity_info[agod].desc[i]); } - if (get_check(format("Do you want to worship %s? ", deity_info[agod].name))) + if (get_check(fmt::format("Do you want to worship {}? ", deity_info[agod].name))) { follow_god(agod, FALSE); p_ptr->grace = -200; @@ -4011,18 +4011,15 @@ std::vector<s16b> show_monster_inven(int m_idx) /* Clear the line */ prt("", i + 1, col ? col - 2 : col); - /* Prepare an index --(-- */ - char tmp_val[80]; - strnfmt(tmp_val, 80, "%c)", index_to_label(i)); - - /* Clear the line with the (possibly indented) index */ - put_str(tmp_val, i + 1, col); + /* Display index */ + put_str(fmt::format("{})", index_to_label(i)), i + 1, col); /* Display the entry itself */ c_put_str(out_color[i], out_desc[i], i + 1, col + 3); /* Display the weight if needed */ { + char tmp_val[80]; int wgt = o_ptr->weight * o_ptr->number; strnfmt(tmp_val, 80, "%3d.%1d lb", wgt / 10, wgt % 10); put_str(tmp_val, i + 1, 71); diff --git a/src/loadsave.cc b/src/loadsave.cc index 87b4acc6..4db24ca7 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -37,7 +37,6 @@ #include "variable.h" #include "variable.hpp" #include "xtra2.hpp" -#include "z-form.h" #include "z-rand.hpp" #include <boost/filesystem.hpp> @@ -644,7 +643,7 @@ static bool_ do_extra(ls_flag_t flag) { if (tmp8u > d_info.size()) { - note(format("Too many dungeon types!", static_cast<int>(tmp8u))); + note(fmt::format("Too many dungeon types: {:d}", tmp8u).c_str()); } } @@ -654,7 +653,7 @@ static bool_ do_extra(ls_flag_t flag) { if (tmp16u > MAX_DUNGEON_DEPTH) { - note(format("Too many (%d) max level by dungeon type!", static_cast<int>(tmp16u))); + note(fmt::format("Too many max level by dungeon type: {:d}", tmp16u).c_str()); } } @@ -1391,7 +1390,7 @@ static bool do_objects(ls_flag_t flag, bool no_companions) /* Oops */ if (i != o_idx) { - note(format("Object allocation error (%d <> %d)", i, o_idx)); + note(fmt::format("Object allocation error ({} <> {})", i, o_idx).c_str()); return false; } @@ -1491,7 +1490,7 @@ static bool do_monsters(ls_flag_t flag, bool no_companions) /* Oops */ if (i != m_idx) { - note(format("Monster allocation error (%d <> %d)", i, m_idx)); + note(fmt::format("Monster allocation error ({} <> {})", i, m_idx).c_str()); return false; } diff --git a/src/q_fireprof.cc b/src/q_fireprof.cc index 8a5a9838..5ac09ad2 100644 --- a/src/q_fireprof.cc +++ b/src/q_fireprof.cc @@ -16,7 +16,6 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" -#include "z-form.h" #include "z-rand.hpp" #include "z-term.h" @@ -280,8 +279,8 @@ void quest_fireproof_building(bool_ *paid, bool_ *recreate) /* take item */ inc_stack_size_ex(item_idx, -1, OPTIMIZE, NO_DESCRIBE); - msg_print(format("Great! Let me fireproof some of your items in thanks. I can do %d books, ", num_books)); - msg_print(format("%d staves, or %d scrolls.", num_staff, num_scroll)); + msg_print(fmt::format("Great! Let me fireproof some of your items in thanks. I can do {} books, ", num_books)); + msg_print(fmt::format("{} staves, or {} scrolls.", num_staff, num_scroll)); /* how many items to proof? */ items = get_item_points_remaining(); diff --git a/src/q_hobbit.cc b/src/q_hobbit.cc index 9b60882b..8fd66f7a 100644 --- a/src/q_hobbit.cc +++ b/src/q_hobbit.cc @@ -17,11 +17,11 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" -#include "z-form.h" #include "z-rand.hpp" #include "z-term.h" #include <cassert> +#include <fmt/format.h> #define cquest (quest[QUEST_HOBBIT]) @@ -218,7 +218,7 @@ void quest_hobbit_init_hook() cquest.data[1] = turn; if (wizard) { - messages.add(format("Hobbit level %d", cquest.data[0]), TERM_BLUE); + messages.add(fmt::format("Hobbit level {}", cquest.data[0]), TERM_BLUE); } } diff --git a/src/q_library.cc b/src/q_library.cc index 0cbb5158..7e1ac35c 100644 --- a/src/q_library.cc +++ b/src/q_library.cc @@ -17,7 +17,6 @@ #include "util.h" #include "variable.h" #include "variable.hpp" -#include "z-form.h" #include "z-rand.hpp" #include <cassert> @@ -209,7 +208,7 @@ static void library_quest_print_spells(int first, int current) } else if (slots == 1) { c_prt(TERM_L_BLUE, "The book can hold 1 more spell.", 2, 0); } else { - c_prt(TERM_L_BLUE, format("The book can hold %d more spells.", slots), 2, 0); + c_prt(TERM_L_BLUE, fmt::format("The book can hold {} more spells.", slots), 2, 0); } row = 3; diff --git a/src/q_poison.cc b/src/q_poison.cc index c8941f90..1785df51 100644 --- a/src/q_poison.cc +++ b/src/q_poison.cc @@ -19,10 +19,11 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" -#include "z-form.h" #include "z-rand.hpp" #include "z-term.h" +#include <fmt/format.h> + #define cquest (quest[QUEST_POISON]) static int wild_locs[4][2] = @@ -315,7 +316,7 @@ void quest_poison_init_hook() cquest.data[0] = rand_int(4); if (wizard) { - messages.add(format("Wilderness poison %d, %d", wild_locs[cquest.data[0]][0], wild_locs[cquest.data[0]][1]), TERM_BLUE); + messages.add(fmt::format("Wilderness poison {}, {}", wild_locs[cquest.data[0]][0], wild_locs[cquest.data[0]][1]), TERM_BLUE); } } diff --git a/src/q_rand.cc b/src/q_rand.cc index 7e1e37b9..6222ba99 100644 --- a/src/q_rand.cc +++ b/src/q_rand.cc @@ -30,7 +30,6 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" -#include "z-form.h" #include "z-rand.hpp" #include "z-term.h" @@ -176,7 +175,7 @@ void initialize_random_quests(int n) { if (wizard) { - messages.add(format("Could not find quest monster on lvl %d", rl), TERM_RED); + messages.add(fmt::format("Could not find quest monster on lvl {}", rl), TERM_RED); } q_ptr->type = 0; } @@ -191,7 +190,7 @@ void initialize_random_quests(int n) if (wizard) { - messages.add(format("Quest for %d on lvl %d", q_ptr->r_idx, rl), TERM_RED); + messages.add(fmt::format("Quest for {} on lvl {}", q_ptr->r_idx, rl), TERM_RED); } } @@ -533,7 +532,7 @@ static bool quest_random_gen_hook(void *, void *in_, void *) } /* Pick a room size */ - get_map_size(format("qrand%d.map", random_quests[dun_level].type), &ysize, &xsize); + get_map_size(fmt::format("qrand{}.map", random_quests[dun_level].type).c_str(), &ysize, &xsize); /* Try to allocate space for room. If fails, exit */ if (!room_alloc(xsize + 2, ysize + 2, FALSE, by0, bx0, &xval, &yval)) @@ -568,7 +567,7 @@ static bool quest_random_gen_hook(void *, void *in_, void *) xstart = x1; ystart = y1; init_flags = INIT_CREATE_DUNGEON; - process_dungeon_file(format("qrand%d.map", random_quests[dun_level].type), &ystart, &xstart, cur_hgt, cur_wid, TRUE, TRUE); + process_dungeon_file(fmt::format("qrand{}.map", random_quests[dun_level].type).c_str(), &ystart, &xstart, cur_hgt, cur_wid, TRUE, TRUE); for (x = x1; x < xstart; x++) { diff --git a/src/q_shroom.cc b/src/q_shroom.cc index 1b787038..8a819672 100644 --- a/src/q_shroom.cc +++ b/src/q_shroom.cc @@ -17,11 +17,11 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" -#include "z-form.h" #include "z-rand.hpp" #include "z-term.h" #include <cassert> +#include <fmt/format.h> #define cquest (quest[QUEST_SHROOM]) @@ -327,7 +327,7 @@ void quest_shroom_init_hook() cquest.data[1] = rand_range(7, 14); if (wizard) { - messages.add(format("Shrooms number %d", cquest.data[1]), TERM_BLUE); + messages.add(fmt::format("Shrooms number {}", cquest.data[1]), TERM_BLUE); } } diff --git a/src/q_thrain.cc b/src/q_thrain.cc index c2aea278..176cc7ed 100644 --- a/src/q_thrain.cc +++ b/src/q_thrain.cc @@ -20,11 +20,11 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" -#include "z-form.h" #include "z-rand.hpp" #include "z-term.h" #include <cassert> +#include <fmt/format.h> #define cquest (quest[QUEST_THRAIN]) @@ -273,7 +273,7 @@ void quest_thrain_init_hook() cquest.data[0] = rand_range(d_info[DUNGEON_DOL_GULDUR].mindepth + 1, d_info[DUNGEON_DOL_GULDUR].maxdepth - 1); if (wizard) { - messages.add(format("Thrain lvl %d", cquest.data[0]), TERM_BLUE); + messages.add(fmt::format("Thrain lvl {}", cquest.data[0]), TERM_BLUE); } } if ((cquest.status >= QUEST_STATUS_TAKEN) && (cquest.status < QUEST_STATUS_FINISHED)) diff --git a/src/skills.cc b/src/skills.cc index 3450eb78..579d4cfb 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -330,11 +330,11 @@ void dump_skills(FILE *fff) if (!has_child(i)) { - strcat(buf, format(" . %s", skill_name.c_str())); + strcat(buf, fmt::format(" . {}", skill_name).c_str()); } else { - strcat(buf, format(" - %s", skill_name.c_str())); + strcat(buf, fmt::format(" - %s", skill_name).c_str()); } fprintf(fff, "%-49s%s%06.3f [%05.3f]", @@ -362,11 +362,11 @@ static void print_skills(std::vector<skill_entry> const &table, int sel, int sta Term_clear(); Term_get_size(&wid, &hgt); - c_prt(TERM_WHITE, format("%s Skills Screen", game_module), 0, 28); + c_prt(TERM_WHITE, fmt::format("{} Skills Screen", game_module), 0, 28); keys = format("#BEnter#W to develop a branch, #Bup#W/#Bdown#W to move, #Bright#W/#Bleft#W to modify, #B?#W for help"); display_message(0, 1, strlen(keys), TERM_WHITE, keys); c_prt((p_ptr->skill_points) ? TERM_L_BLUE : TERM_L_RED, - format("Skill points left: %d", p_ptr->skill_points), 2, 0); + fmt::format("Skill points left: {}", p_ptr->skill_points), 2, 0); print_desc_aux(s_descriptors[table[sel].skill_idx].desc.c_str(), 3, 0); for (j = start; j < start + (hgt - 7); j++) @@ -413,17 +413,17 @@ static void print_skills(std::vector<skill_entry> const &table, int sel, int sta if (!has_child(i)) { - c_prt(color, format("%c.%c%s", deb, end, name.c_str()), + c_prt(color, fmt::format("{}.{}{}", deb, end, name), j + 7 - start, table[j].indent_level * 4); } else if (skill.dev) { - c_prt(color, format("%c-%c%s", deb, end, name.c_str()), + c_prt(color, fmt::format("{}-{}{}", deb, end, name), j + 7 - start, table[j].indent_level * 4); } else { - c_prt(color, format("%c+%c%s", deb, end, name.c_str()), + c_prt(color, fmt::format("{}+{}{}", deb, end, name), j + 7 - start, table[j].indent_level * 4); } @@ -791,7 +791,7 @@ static void choose_melee() { if (melee_bool[i]) { - prt(format("%c) %s", I2A(z), melee_names[i]), z + 1, 0); + prt(fmt::format("{}) {}", I2A(z), melee_names[i]), z + 1, 0); melee_num[z] = i; z++; } @@ -895,7 +895,7 @@ static void print_skill_batch(const std::vector<std::tuple<std::string, int>> &p j++; } prt("", 2 + j, 20); - prt(format("Select a skill (a-%c), @ to select by name, +/- to scroll:", I2A(j - 1)), 0, 0); + prt(fmt::format("Select a skill (a-{}), @ to select by name, +/- to scroll:", I2A(j - 1)), 0, 0); } static int do_cmd_activate_skill_aux() @@ -1509,8 +1509,6 @@ void do_get_new_skill() /* Ok we oppose, so be sure */ if (oppose) { - const char *msg; - /* * Because this is SO critical a question, we must flush * input to prevent killing character off -- pelpel @@ -1518,9 +1516,10 @@ void do_get_new_skill() flush(); /* Prepare prompt */ - msg = format("This skill is mutually exclusive with " - "at least %s, continue?", - s_descriptors[oppose_skill].name.c_str()); + auto msg = fmt::format( + "This skill is mutually exclusive with " + "at least {}, continue?", + s_descriptors[oppose_skill].name); /* The player rejected the choice; go back to prompt */ if (!get_check(msg)) @@ -1717,7 +1716,7 @@ static void print_abilities(const std::vector<std::size_t> &table, int sel, int keys = format("#Bup#W/#Bdown#W to move, #Bright#W to buy, #B?#W for help"); display_message(0, 1, strlen(keys), TERM_WHITE, keys); c_prt((p_ptr->skill_points) ? TERM_L_BLUE : TERM_L_RED, - format("Skill points left: %d", p_ptr->skill_points), 2, 0); + fmt::format("Skill points left: {}", p_ptr->skill_points), 2, 0); print_desc_aux(ab_info[table[sel]].desc.c_str(), 3, 0); diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc index 9b97ba41..cef3dbc6 100644 --- a/src/squelch/condition.cc +++ b/src/squelch/condition.cc @@ -20,9 +20,10 @@ #include "../skill_type.hpp" #include "../util.hpp" #include "../variable.hpp" -#include "../z-form.h" #include "../z-term.h" +#include <fmt/format.h> + namespace squelch { EnumStringMap<match_type> &match_mapping() @@ -174,7 +175,7 @@ void TvalCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t b p->write(bcol, "tval"); p->write(ecol, " is "); p->write(ecol, "\""); - p->write(TERM_WHITE, format("%d", (int) m_tval)); + p->write(TERM_WHITE, fmt::format("{}", m_tval)); p->write(ecol, "\""); p->write(TERM_WHITE, "\n"); } @@ -281,9 +282,9 @@ void SvalCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t b p->write(ecol, "Its "); p->write(bcol, "sval"); p->write(ecol, " is from "); - p->write(TERM_WHITE, format("%d", m_min)); + p->write(TERM_WHITE, fmt::format("{}", m_min)); p->write(ecol, " to "); - p->write(TERM_WHITE, format("%d", m_max)); + p->write(TERM_WHITE, fmt::format("{}", m_max)); p->write(TERM_WHITE, "\n"); } @@ -696,9 +697,9 @@ void DiscountCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8 p->write(ecol, "Its "); p->write(bcol, "discount"); p->write(ecol, " is from "); - p->write(TERM_WHITE, format("%d", m_min)); + p->write(TERM_WHITE, fmt::format("{}", m_min)); p->write(ecol, " to "); - p->write(TERM_WHITE, format("%d", m_max)); + p->write(TERM_WHITE, fmt::format("{}", m_max)); p->write(TERM_WHITE, "\n"); } @@ -741,9 +742,9 @@ void LevelCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t p->write(bcol, "level"); p->write(ecol, " is from "); - p->write(TERM_WHITE, format("%d", m_min)); + p->write(TERM_WHITE, fmt::format("{}", m_min)); p->write(ecol, " to "); - p->write(TERM_WHITE, format("%d", m_max)); + p->write(TERM_WHITE, fmt::format("{}", m_max)); p->write(TERM_WHITE, "\n"); } @@ -803,9 +804,9 @@ void SkillCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t p->write(ecol, "Your skill in "); p->write(bcol, s_descriptors[m_skill_idx].name); p->write(ecol, " is from "); - p->write(TERM_WHITE, format("%d", (int) m_min)); + p->write(TERM_WHITE, fmt::format("{}", m_min)); p->write(ecol, " to "); - p->write(TERM_WHITE, format("%d", (int) m_max)); + p->write(TERM_WHITE, fmt::format("{}", m_max)); p->write(TERM_WHITE, "\n"); } @@ -848,14 +849,14 @@ void SymbolCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t p->write(bcol, "symbol"); p->write(ecol, " is "); p->write(ecol, "\""); - p->write(TERM_WHITE, format("%c", m_symbol)); + p->write(TERM_WHITE, fmt::format("{}", m_symbol)); p->write(ecol, "\""); p->write(TERM_WHITE, "\n"); } void SymbolCondition::to_json(jsoncons::json &j) const { - j["symbol"] = format("%c", m_symbol); + j["symbol"] = fmt::format("{}", m_symbol); } bool AbilityCondition::is_match(object_type *) const diff --git a/src/util.cc b/src/util.cc index 361f55be..b187b41b 100644 --- a/src/util.cc +++ b/src/util.cc @@ -2598,6 +2598,12 @@ bool_ get_check(const char *prompt) } +bool_ get_check(std::string const &prompt) +{ + return get_check(prompt.c_str()); +} + + /* * Prompts for a keypress * diff --git a/src/util.hpp b/src/util.hpp index de71e8fb..372cb09b 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -62,6 +62,7 @@ bool_ askfor_aux(char *buf, int len); bool_ askfor_aux_with_completion(char *buf, int len); bool_ get_string(const char *prompt, char *buf, int len); bool_ get_check(const char *prompt); +bool_ get_check(std::string const &prompt); bool_ get_com(const char *prompt, char *command); s32b get_quantity(const char *prompt, s32b max); extern char request_command_ignore_keymaps[MAX_IGNORE_KEYMAPS]; diff --git a/src/xtra2.cc b/src/xtra2.cc index 12dde007..5cb5da7e 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -59,7 +59,6 @@ #include "wilderness_type_info.hpp" #include "wizard2.hpp" #include "xtra1.hpp" -#include "z-form.h" #include "z-rand.hpp" #include <boost/algorithm/string/predicate.hpp> @@ -4035,7 +4034,7 @@ static int target_set_aux(int y, int x, int mode, const char *info_) screen_roff(m_ptr->r_idx, m_ptr->ego); /* Hack -- Complete the prompt (again) */ - Term_addstr( -1, TERM_WHITE, format(" [r,%s]", info.c_str())); + Term_addstr( -1, TERM_WHITE, fmt::format(" [r,{}]", info).c_str()); /* Command */ query = inkey(); |