Codechange: replace fprintf(<FILE*> with fmt::print(<FILE*>

This commit is contained in:
Rubidium
2023-05-21 08:13:28 +02:00
committed by rubidium42
parent c518293135
commit 275ebf4509
11 changed files with 39 additions and 41 deletions

View File

@@ -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);
}
}
}