diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 6382d81e4b..848424d058 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -478,45 +478,45 @@ bool CrashLog::MakeCrashLog() const char buffer[65536]; bool ret = true; - printf("Crash encountered, generating crash log...\n"); + fmt::print("Crash encountered, generating crash log...\n"); this->FillCrashLog(buffer, lastof(buffer)); - printf("%s\n", buffer); - printf("Crash log generated.\n\n"); + fmt::print("{}\n", buffer); + fmt::print("Crash log generated.\n\n"); - printf("Writing crash log to disk...\n"); + fmt::print("Writing crash log to disk...\n"); bool bret = this->WriteCrashLog(buffer, filename, lastof(filename)); if (bret) { - printf("Crash log written to %s. Please add this file to any bug reports.\n\n", filename); + fmt::print("Crash log written to {}. Please add this file to any bug reports.\n\n", filename); } else { - printf("Writing crash log failed. Please attach the output above to any bug reports.\n\n"); + fmt::print("Writing crash log failed. Please attach the output above to any bug reports.\n\n"); ret = false; } /* Don't mention writing crash dumps because not all platforms support it. */ int dret = this->WriteCrashDump(filename, lastof(filename)); if (dret < 0) { - printf("Writing crash dump failed.\n\n"); + fmt::print("Writing crash dump failed.\n\n"); ret = false; } else if (dret > 0) { - printf("Crash dump written to %s. Please add this file to any bug reports.\n\n", filename); + fmt::print("Crash dump written to {}. Please add this file to any bug reports.\n\n", filename); } - printf("Writing crash savegame...\n"); + fmt::print("Writing crash savegame...\n"); bret = this->WriteSavegame(filename, lastof(filename)); if (bret) { - printf("Crash savegame written to %s. Please add this file and the last (auto)save to any bug reports.\n\n", filename); + fmt::print("Crash savegame written to {}. Please add this file and the last (auto)save to any bug reports.\n\n", filename); } else { ret = false; - printf("Writing crash savegame failed. Please attach the last (auto)save to any bug reports.\n\n"); + fmt::print("Writing crash savegame failed. Please attach the last (auto)save to any bug reports.\n\n"); } - printf("Writing crash screenshot...\n"); + fmt::print("Writing crash screenshot...\n"); bret = this->WriteScreenshot(filename, lastof(filename)); if (bret) { - printf("Crash screenshot written to %s. Please add this file to any bug reports.\n\n", filename); + fmt::print("Crash screenshot written to {}. Please add this file to any bug reports.\n\n", filename); } else { ret = false; - printf("Writing crash screenshot failed.\n\n"); + fmt::print("Writing crash screenshot failed.\n\n"); } this->SendSurvey(); diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index aadee357e0..01aad5fb7a 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -85,7 +85,7 @@ static inline bool HaveChatMessages(bool show_all) * Add a text message to the 'chat window' to be shown * @param colour The colour this message is to be shown in * @param duration The duration of the chat message in seconds - * @param message message itself in printf() style + * @param message message itself */ void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message) { diff --git a/src/openttd.cpp b/src/openttd.cpp index 61c0e1da9d..d7f0d064e8 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -225,7 +225,7 @@ static void ShowHelp() /* ShowInfo put output to stderr, but version information should go * to stdout; this is the only exception */ #if !defined(_WIN32) - printf("%s\n", str.c_str()); + fmt::print("{}\n", str); #else ShowInfoI(str); #endif @@ -262,7 +262,7 @@ static void WriteSavegameInfo(const char *name) /* ShowInfo put output to stderr, but version information should go * to stdout; this is the only exception */ #if !defined(_WIN32) - printf("%s\n", message.c_str()); + fmt::print("%s\n", message); #else ShowInfoI(message); #endif diff --git a/src/os/macosx/crashlog_osx.cpp b/src/os/macosx/crashlog_osx.cpp index df1736a6f6..0b1b303c2c 100644 --- a/src/os/macosx/crashlog_osx.cpp +++ b/src/os/macosx/crashlog_osx.cpp @@ -169,24 +169,24 @@ public: char buffer[65536]; bool ret = true; - printf("Crash encountered, generating crash log...\n"); + fmt::print("Crash encountered, generating crash log...\n"); this->FillCrashLog(buffer, lastof(buffer)); - printf("%s\n", buffer); - printf("Crash log generated.\n\n"); + fmt::print("{}\n", buffer); + fmt::print("Crash log generated.\n\n"); - printf("Writing crash log to disk...\n"); + fmt::print("Writing crash log to disk...\n"); if (!this->WriteCrashLog(buffer, filename_log, lastof(filename_log))) { filename_log[0] = '\0'; ret = false; } - printf("Writing crash savegame...\n"); + fmt::print("Writing crash savegame...\n"); if (!this->WriteSavegame(filename_save, lastof(filename_save))) { filename_save[0] = '\0'; ret = false; } - printf("Writing crash screenshot...\n"); + fmt::print("Writing crash screenshot...\n"); if (!this->WriteScreenshot(filename_screenshot, lastof(filename_screenshot))) { filename_screenshot[0] = '\0'; ret = false; diff --git a/src/os/unix/crashlog_unix.cpp b/src/os/unix/crashlog_unix.cpp index a3fc1d5e97..dcbad13d70 100644 --- a/src/os/unix/crashlog_unix.cpp +++ b/src/os/unix/crashlog_unix.cpp @@ -156,15 +156,15 @@ static void CDECL HandleCrash(int signum) } if (_gamelog.TestEmergency()) { - printf("A serious fault condition occurred in the game. The game will shut down.\n"); - printf("As you loaded an emergency savegame no crash information will be generated.\n"); + fmt::print("A serious fault condition occurred in the game. The game will shut down.\n"); + fmt::print("As you loaded an emergency savegame no crash information will be generated.\n"); abort(); } if (SaveloadCrashWithMissingNewGRFs()) { - printf("A serious fault condition occurred in the game. The game will shut down.\n"); - printf("As you loaded an savegame for which you do not have the required NewGRFs\n"); - printf("no crash information will be generated.\n"); + fmt::print("A serious fault condition occurred in the game. The game will shut down.\n"); + fmt::print("As you loaded an savegame for which you do not have the required NewGRFs\n"); + fmt::print("no crash information will be generated.\n"); abort(); } diff --git a/src/pathfinder/npf/aystar.cpp b/src/pathfinder/npf/aystar.cpp index 163d7859ec..698b8183ac 100644 --- a/src/pathfinder/npf/aystar.cpp +++ b/src/pathfinder/npf/aystar.cpp @@ -211,7 +211,7 @@ void AyStar::Free() this->openlist_hash.Delete(true); this->closedlist_hash.Delete(true); #ifdef AYSTAR_DEBUG - printf("[AyStar] Memory free'd\n"); + Debug(misc, 0, "[AyStar] Memory free'd"); #endif } @@ -229,7 +229,7 @@ void AyStar::Clear() this->closedlist_hash.Clear(true); #ifdef AYSTAR_DEBUG - printf("[AyStar] Cleared AyStar\n"); + Debug(misc, 0, "[AyStar] Cleared AyStar"); #endif } @@ -250,9 +250,9 @@ int AyStar::Main() while ((r = this->Loop()) == AYSTAR_STILL_BUSY && (this->loops_per_tick == 0 || ++i < this->loops_per_tick)) { } #ifdef AYSTAR_DEBUG switch (r) { - case AYSTAR_FOUND_END_NODE: printf("[AyStar] Found path!\n"); break; - case AYSTAR_EMPTY_OPENLIST: printf("[AyStar] OpenList run dry, no path found\n"); break; - case AYSTAR_LIMIT_REACHED: printf("[AyStar] Exceeded search_nodes, no path found\n"); break; + case AYSTAR_FOUND_END_NODE: Debug(misc, 0, "[AyStar] Found path!"); break; + case AYSTAR_EMPTY_OPENLIST: Debug(misc, 0, "[AyStar] OpenList run dry, no path found"); break; + case AYSTAR_LIMIT_REACHED: Debug(misc, 0, "[AyStar] Exceeded search_nodes, no path found"); break; default: break; } #endif @@ -280,7 +280,7 @@ int AyStar::Main() void AyStar::AddStartNode(AyStarNode *start_node, uint g) { #ifdef AYSTAR_DEBUG - printf("[AyStar] Starting A* Algorithm from node (%d, %d, %d)\n", + Debug(misc, 0, "[AyStar] Starting A* Algorithm from node ({}, {}, {})\n", TileX(start_node->tile), TileY(start_node->tile), start_node->direction); #endif this->OpenListAdd(nullptr, start_node, 0, g); diff --git a/src/pathfinder/npf/queue.cpp b/src/pathfinder/npf/queue.cpp index 960cda8e5c..f1acf26eb3 100644 --- a/src/pathfinder/npf/queue.cpp +++ b/src/pathfinder/npf/queue.cpp @@ -303,29 +303,26 @@ void Hash::PrintStatistics() const max_usage = usage[collision]; } } - printf( - "---\n" - "Hash size: %u\n" - "Nodes used: %u\n" - "Non empty buckets: %u\n" - "Max collision: %u\n", + Debug(misc, 0, "Hash size: {}, Nodes used: {}, Non empty buckets: {}, Max collision: {}", this->num_buckets, this->size, used_buckets, max_collision ); - printf("{ "); + std::string line; + line += "{ "; for (i = 0; i <= max_collision; i++) { if (usage[i] > 0) { - printf("%u:%u ", i, usage[i]); + fmt::format_to(std::back_inserter(line), "{}:{} ", i, usage[i]); #if 0 if (i > 0) { uint j; - for (j = 0; j < usage[i] * 160 / 800; j++) putchar('#'); + for (j = 0; j < usage[i] * 160 / 800; j++) line += "#"; } - printf("\n"); + line += "\n"; #endif } } - printf ("}\n"); + line += "}"; + Debug(misc, 0, "{}", line); } #endif diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index a59b7cff64..530e0c32d9 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -269,7 +269,7 @@ void Squirrel::PrintFunc(HSQUIRRELVM vm, const std::string &s) /* Check if we have a custom print function */ SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func; if (func == nullptr) { - printf("%s", s.c_str()); + fmt::print("%s", s); } else { (*func)(false, s); } diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index e4f4f55ed7..fc58f8a142 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -427,7 +427,7 @@ int CDECL main(int argc, char *argv[]) return 0; case 'C': - printf("args\tflags\tcommand\treplacement\n"); + fmt::print("args\tflags\tcommand\treplacement\n"); for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) { char flags; if (cs->proc == EmitGender) { @@ -439,21 +439,21 @@ int CDECL main(int argc, char *argv[]) } else { flags = '0'; // Command needs no parameters } - printf("%i\t%c\t\"%s\"\t\"%s\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd); + fmt::print("{}\t{:c}\t\"{}\"\t\"{}\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd); } return 0; case 'L': - printf("count\tdescription\tnames\n"); + fmt::print("count\tdescription\tnames\n"); for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) { - printf("%i\t\"%s\"\t%s\n", pf->plural_count, pf->description, pf->names); + fmt::print("{}\t\"{}\"\t{}\n", pf->plural_count, pf->description, pf->names); } return 0; case 'P': - printf("name\tflags\tdefault\tdescription\n"); + fmt::print("name\tflags\tdefault\tdescription\n"); for (size_t j = 0; j < lengthof(_pragmas); j++) { - printf("\"%s\"\t%s\t\"%s\"\t\"%s\"\n", + fmt::print("\"{}\"\t{}\t\"{}\"\t\"{}\"\n", _pragmas[j][0], _pragmas[j][1], _pragmas[j][2], _pragmas[j][3]); } return 0;