mirror of https://github.com/OpenTTD/OpenTTD
Codechange: replace fprintf(<FILE*> with fmt::print(<FILE*>
parent
c518293135
commit
275ebf4509
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue