Codechange: replace error/usererror printf variant with fmt variant and rename
This commit is contained in:
@@ -10,6 +10,7 @@ if (NOT HOST_BINARY_DIR)
|
||||
strgen_base.cpp
|
||||
../core/alloc_func.cpp
|
||||
../misc/getoptdata.cpp
|
||||
../error.cpp
|
||||
../string.cpp
|
||||
)
|
||||
add_definitions(-DSTRGEN)
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../core/endian_func.hpp"
|
||||
#include "../error_func.h"
|
||||
#include "../string_func.h"
|
||||
#include "../strings_type.h"
|
||||
#include "../misc/getoptdata.h"
|
||||
@@ -16,7 +17,6 @@
|
||||
|
||||
#include "strgen.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <exception>
|
||||
|
||||
#if !defined(_WIN32) || defined(__CYGWIN__)
|
||||
@@ -64,14 +64,9 @@ void NORETURN StrgenFatalI(const std::string &msg)
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
void NORETURN CDECL error(const char *s, ...)
|
||||
void NORETURN FatalErrorI(const std::string &msg)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list va;
|
||||
va_start(va, s);
|
||||
vseprintf(buf, lastof(buf), s, va);
|
||||
va_end(va);
|
||||
fprintf(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, buf);
|
||||
fprintf(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg.c_str());
|
||||
#ifdef _MSC_VER
|
||||
fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled");
|
||||
#endif
|
||||
@@ -93,7 +88,7 @@ struct FileStringReader : StringReader {
|
||||
StringReader(data, file, master, translation)
|
||||
{
|
||||
this->fh = fopen(file, "rb");
|
||||
if (this->fh == nullptr) error("Could not open %s", file);
|
||||
if (this->fh == nullptr) FatalError("Could not open {}", file);
|
||||
}
|
||||
|
||||
/** Free/close the file. */
|
||||
@@ -114,7 +109,7 @@ struct FileStringReader : StringReader {
|
||||
this->StringReader::ParseFile();
|
||||
|
||||
if (StrEmpty(_lang.name) || StrEmpty(_lang.own_name) || StrEmpty(_lang.isocode)) {
|
||||
error("Language must include ##name, ##ownname and ##isocode");
|
||||
FatalError("Language must include ##name, ##ownname and ##isocode");
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -135,7 +130,7 @@ void FileStringReader::HandlePragma(char *str)
|
||||
} else if (!memcmp(str + 8, "rtl", 3)) {
|
||||
_lang.text_dir = TD_RTL;
|
||||
} else {
|
||||
error("Invalid textdir %s", str + 8);
|
||||
FatalError("Invalid textdir {}", str + 8);
|
||||
}
|
||||
} else if (!memcmp(str, "digitsep ", 9)) {
|
||||
str += 9;
|
||||
@@ -150,37 +145,37 @@ void FileStringReader::HandlePragma(char *str)
|
||||
const char *buf = str + 10;
|
||||
long langid = strtol(buf, nullptr, 16);
|
||||
if (langid > (long)UINT16_MAX || langid < 0) {
|
||||
error("Invalid winlangid %s", buf);
|
||||
FatalError("Invalid winlangid {}", buf);
|
||||
}
|
||||
_lang.winlangid = (uint16)langid;
|
||||
} else if (!memcmp(str, "grflangid ", 10)) {
|
||||
const char *buf = str + 10;
|
||||
long langid = strtol(buf, nullptr, 16);
|
||||
if (langid >= 0x7F || langid < 0) {
|
||||
error("Invalid grflangid %s", buf);
|
||||
FatalError("Invalid grflangid {}", buf);
|
||||
}
|
||||
_lang.newgrflangid = (uint8)langid;
|
||||
} else if (!memcmp(str, "gender ", 7)) {
|
||||
if (this->master) error("Genders are not allowed in the base translation.");
|
||||
if (this->master) FatalError("Genders are not allowed in the base translation.");
|
||||
char *buf = str + 7;
|
||||
|
||||
for (;;) {
|
||||
const char *s = ParseWord(&buf);
|
||||
|
||||
if (s == nullptr) break;
|
||||
if (_lang.num_genders >= MAX_NUM_GENDERS) error("Too many genders, max %d", MAX_NUM_GENDERS);
|
||||
if (_lang.num_genders >= MAX_NUM_GENDERS) FatalError("Too many genders, max {}", MAX_NUM_GENDERS);
|
||||
strecpy(_lang.genders[_lang.num_genders], s, lastof(_lang.genders[_lang.num_genders]));
|
||||
_lang.num_genders++;
|
||||
}
|
||||
} else if (!memcmp(str, "case ", 5)) {
|
||||
if (this->master) error("Cases are not allowed in the base translation.");
|
||||
if (this->master) FatalError("Cases are not allowed in the base translation.");
|
||||
char *buf = str + 5;
|
||||
|
||||
for (;;) {
|
||||
const char *s = ParseWord(&buf);
|
||||
|
||||
if (s == nullptr) break;
|
||||
if (_lang.num_cases >= MAX_NUM_CASES) error("Too many cases, max %d", MAX_NUM_CASES);
|
||||
if (_lang.num_cases >= MAX_NUM_CASES) FatalError("Too many cases, max {}", MAX_NUM_CASES);
|
||||
strecpy(_lang.cases[_lang.num_cases], s, lastof(_lang.cases[_lang.num_cases]));
|
||||
_lang.num_cases++;
|
||||
}
|
||||
@@ -197,7 +192,7 @@ bool CompareFiles(const char *n1, const char *n2)
|
||||
FILE *f1 = fopen(n1, "rb");
|
||||
if (f1 == nullptr) {
|
||||
fclose(f2);
|
||||
error("can't open %s", n1);
|
||||
FatalError("can't open {}", n1);
|
||||
}
|
||||
|
||||
size_t l1, l2;
|
||||
@@ -234,7 +229,7 @@ struct FileWriter {
|
||||
this->fh = fopen(this->filename, "wb");
|
||||
|
||||
if (this->fh == nullptr) {
|
||||
error("Could not open %s", this->filename);
|
||||
FatalError("Could not open {}", this->filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +315,7 @@ struct HeaderFileWriter : HeaderWriter, FileWriter {
|
||||
# if defined(_WIN32)
|
||||
unlink(this->real_filename);
|
||||
# endif
|
||||
if (rename(this->filename, this->real_filename) == -1) error("rename() failed");
|
||||
if (rename(this->filename, this->real_filename) == -1) FatalError("rename() failed");
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -343,7 +338,7 @@ struct LanguageFileWriter : LanguageWriter, FileWriter {
|
||||
void Finalise()
|
||||
{
|
||||
if (fputc(0, this->fh) == EOF) {
|
||||
error("Could not write to %s", this->filename);
|
||||
FatalError("Could not write to {}", this->filename);
|
||||
}
|
||||
this->FileWriter::Finalise();
|
||||
}
|
||||
@@ -351,7 +346,7 @@ struct LanguageFileWriter : LanguageWriter, FileWriter {
|
||||
void Write(const byte *buffer, size_t length)
|
||||
{
|
||||
if (fwrite(buffer, sizeof(*buffer), length, this->fh) != length) {
|
||||
error("Could not write to %s", this->filename);
|
||||
FatalError("Could not write to {}", this->filename);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "../stdafx.h"
|
||||
#include "../core/alloc_func.hpp"
|
||||
#include "../core/endian_func.hpp"
|
||||
#include "../error_func.h"
|
||||
#include "../string_func.h"
|
||||
#include "../table/control_codes.h"
|
||||
|
||||
@@ -556,7 +557,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
|
||||
StrgenError("Missing }} from command '{}'", start);
|
||||
return nullptr;
|
||||
}
|
||||
if (s - start == MAX_COMMAND_PARAM_SIZE) error("param command too long");
|
||||
if (s - start == MAX_COMMAND_PARAM_SIZE) FatalError("param command too long");
|
||||
*param++ = c;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user