diff --git a/src/console.cpp b/src/console.cpp index 96de9ac8b8..56b0014b50 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -112,7 +112,7 @@ void IConsolePrint(TextColour colour_code, const std::string &string) if (_network_dedicated) { NetworkAdminConsole("console", str); - fprintf(stdout, "%s%s\n", GetLogPrefix(), str); + fmt::print("{}{}\n", GetLogPrefix(), str); fflush(stdout); IConsoleWriteToLogFile(str); free(str); // free duplicated string since it's not used anymore diff --git a/src/debug.cpp b/src/debug.cpp index b088af9aaa..7a411a1077 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -127,14 +127,14 @@ void DebugPrint(const char *level, const std::string &message) static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR); if (f == nullptr) return; - fprintf(f, "%s%s\n", GetLogPrefix(), message.c_str()); + fmt::print(f, "{}{}\n", GetLogPrefix(), message); fflush(f); #ifdef RANDOM_DEBUG } else if (strcmp(level, "random") == 0) { static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR); if (f == nullptr) return; - fprintf(f, "%s\n", message.c_str()); + fmt::print(f, "{}\n", message); fflush(f); #endif } else { diff --git a/src/map.cpp b/src/map.cpp index 52aa621ca0..dfaa6ec866 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -87,7 +87,7 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add, seprintf(buf, lastof(buf), "TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed", exp, (uint32)tile, add); #if !defined(_MSC_VER) - fprintf(stderr, "%s:%d %s\n", file, line, buf); + fmt::print(stderr, "{}:{} {}\n", file, line, buf); #else _assert(buf, (char*)file, line); #endif diff --git a/src/openttd.cpp b/src/openttd.cpp index d7f0d064e8..19a2bc515b 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -615,13 +615,11 @@ int openttd_main(int argc, char *argv[]) _load_check_data.Clear(); SaveOrLoadResult res = SaveOrLoad(mgo.opt, SLO_CHECK, DFT_GAME_FILE, SAVE_DIR, false); if (res != SL_OK || _load_check_data.HasErrors()) { - fprintf(stderr, "Failed to open savegame\n"); + fmt::print(stderr, "Failed to open savegame\n"); if (_load_check_data.HasErrors()) { InitializeLanguagePacks(); // A language pack is needed for GetString() - char buf[256]; SetDParamStr(0, _load_check_data.error_msg); - GetString(buf, _load_check_data.error, lastof(buf)); - fprintf(stderr, "%s\n", buf); + fmt::print(stderr, "{}\n", GetString(_load_check_data.error)); } return ret; } diff --git a/src/os/macosx/macos.mm b/src/os/macosx/macos.mm index 9db5cd049f..773c77e32f 100644 --- a/src/os/macosx/macos.mm +++ b/src/os/macosx/macos.mm @@ -135,7 +135,7 @@ void ShowMacDialog(const char *title, const char *message, const char *buttonLab */ void ShowMacDialog(const char *title, const char *message, const char *buttonLabel) { - fprintf(stderr, "%s: %s\n", title, message); + fmt::print(stderr, "{}: {}\n", title, message); } #endif diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index 249020458a..edacf2feaf 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -212,7 +212,7 @@ std::string FS2OTTD(const std::string &name) void ShowInfoI(const std::string &str) { - fprintf(stderr, "%s\n", str.c_str()); + fmt::print(stderr, "{}\n", str); } #if !defined(__APPLE__) @@ -220,9 +220,9 @@ void ShowOSErrorBox(const char *buf, bool system) { /* All unix systems, except OSX. Only use escape codes on a TTY. */ if (isatty(fileno(stderr))) { - fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf); + fmt::print(stderr, "\033[1;31mError: {}\033[0;39m\n", buf); } else { - fprintf(stderr, "Error: %s\n", buf); + fmt::print(stderr, "Error: {}\n", buf); } } #endif diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index b941e642ac..07987cb14d 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -321,7 +321,7 @@ static INT_PTR CALLBACK HelpDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARAM void ShowInfoI(const std::string &str) { if (_has_console) { - fprintf(stderr, "%s\n", str.c_str()); + fmt::print(stderr, "{}\n", str); } else { bool old; ReleaseCapture(); diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index 530e0c32d9..62542ad856 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -221,7 +221,7 @@ void Squirrel::ErrorPrintFunc(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) { - fprintf(stderr, "%s", s.c_str()); + fmt::print(stderr, "{}", s); } else { (*func)(true, s); } @@ -238,7 +238,7 @@ void Squirrel::RunError(HSQUIRRELVM vm, const SQChar *error) Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); SQPrintFunc *func = engine->print_func; if (func == nullptr) { - fprintf(stderr, "%s", msg.c_str()); + fmt::print(stderr, "{}", msg); } else { (*func)(true, msg); } diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp index 603278859d..273d414b0c 100644 --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -29,7 +29,7 @@ */ void NORETURN FatalErrorI(const std::string &msg) { - fprintf(stderr, "settingsgen: FATAL: %s\n", msg.c_str()); + fmt::print(stderr, "settingsgen: FATAL: {}\n", msg); exit(1); } @@ -483,7 +483,7 @@ int CDECL main(int argc, char *argv[]) break; case -2: - fprintf(stderr, "Invalid arguments\n"); + fmt::print(stderr, "Invalid arguments\n"); return 1; } } diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index fc58f8a142..3f7b181e7a 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -34,41 +34,41 @@ #ifdef _MSC_VER -# define LINE_NUM_FMT(s) "%s (%d): warning: %s (" s ")\n" +# define LINE_NUM_FMT(s) "{} ({}): warning: {} (" s ")\n" #else -# define LINE_NUM_FMT(s) "%s:%d: " s ": %s\n" +# define LINE_NUM_FMT(s) "{}:{}: " s ": {}\n" #endif void StrgenWarningI(const std::string &msg) { if (_show_todo > 0) { - fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, msg.c_str()); + fmt::print(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, msg); } else { - fprintf(stderr, LINE_NUM_FMT("info"), _file, _cur_line, msg.c_str()); + fmt::print(stderr, LINE_NUM_FMT("info"), _file, _cur_line, msg); } _warnings++; } void StrgenErrorI(const std::string &msg) { - fprintf(stderr, LINE_NUM_FMT("error"), _file, _cur_line, msg.c_str()); + fmt::print(stderr, LINE_NUM_FMT("error"), _file, _cur_line, msg); _errors++; } void NORETURN StrgenFatalI(const std::string &msg) { - fprintf(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg.c_str()); + fmt::print(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg); #ifdef _MSC_VER - fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled"); + fmt::print(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled"); #endif throw std::exception(); } void NORETURN FatalErrorI(const std::string &msg) { - fprintf(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg.c_str()); + fmt::print(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg); #ifdef _MSC_VER - fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled"); + fmt::print(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled"); #endif exit(2); } @@ -266,9 +266,9 @@ struct HeaderFileWriter : HeaderWriter, FileWriter { HeaderFileWriter(const char *filename) : FileWriter("tmp.xxx"), real_filename(stredup(filename)), prev(0), total_strings(0) { - fprintf(this->fh, "/* This file is automatically generated. Do not modify */\n\n"); - fprintf(this->fh, "#ifndef TABLE_STRINGS_H\n"); - fprintf(this->fh, "#define TABLE_STRINGS_H\n"); + fmt::print(this->fh, "/* This file is automatically generated. Do not modify */\n\n"); + fmt::print(this->fh, "#ifndef TABLE_STRINGS_H\n"); + fmt::print(this->fh, "#define TABLE_STRINGS_H\n"); } /** Free the filename. */ @@ -279,8 +279,8 @@ struct HeaderFileWriter : HeaderWriter, FileWriter { void WriteStringID(const char *name, int stringid) { - if (prev + 1 != stringid) fprintf(this->fh, "\n"); - fprintf(this->fh, "static const StringID %s = 0x%X;\n", name, stringid); + if (prev + 1 != stringid) fmt::print(this->fh, "\n"); + fmt::print(this->fh, "static const StringID {} = 0x{:X};\n", name, stringid); prev = stringid; total_strings++; } @@ -293,17 +293,17 @@ struct HeaderFileWriter : HeaderWriter, FileWriter { max_plural_forms = std::max(max_plural_forms, _plural_forms[i].plural_count); } - fprintf(this->fh, + fmt::print(this->fh, "\n" - "static const uint LANGUAGE_PACK_VERSION = 0x%X;\n" - "static const uint LANGUAGE_MAX_PLURAL = %u;\n" - "static const uint LANGUAGE_MAX_PLURAL_FORMS = %d;\n" - "static const uint LANGUAGE_TOTAL_STRINGS = %u;\n" + "static const uint LANGUAGE_PACK_VERSION = 0x{:X};\n" + "static const uint LANGUAGE_MAX_PLURAL = {};\n" + "static const uint LANGUAGE_MAX_PLURAL_FORMS = {};\n" + "static const uint LANGUAGE_TOTAL_STRINGS = {};\n" "\n", - (uint)data.Version(), (uint)lengthof(_plural_forms), max_plural_forms, total_strings + data.Version(), lengthof(_plural_forms), max_plural_forms, total_strings ); - fprintf(this->fh, "#endif /* TABLE_STRINGS_H */\n"); + fmt::print(this->fh, "#endif /* TABLE_STRINGS_H */\n"); this->FileWriter::Finalise(); @@ -493,7 +493,7 @@ int CDECL main(int argc, char *argv[]) break; case -2: - fprintf(stderr, "Invalid arguments\n"); + fmt::print(stderr, "Invalid arguments\n"); return 0; } } @@ -556,7 +556,7 @@ int CDECL main(int argc, char *argv[]) /* if showing warnings, print a summary of the language */ if ((_show_todo & 2) != 0) { - fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf); + fmt::print("{} warnings and {} errors for {}\n", _warnings, _errors, pathbuf); } } } diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm index 88361dbc7a..df08df857f 100644 --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -397,7 +397,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel if (VideoDriver::GetInstance() == nullptr) { CocoaSetupApplication(); // Setup application before showing dialog } else if (!_cocoa_video_started && VideoDriver::GetInstance()->Start({}) != nullptr) { - fprintf(stderr, "%s: %s\n", title, message); + fmt::print(stderr, "{}: {}\n", title, message); return; }