summaryrefslogtreecommitdiff
path: root/src/strgen
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-04-18 21:33:21 +0000
committersmatz <smatz@openttd.org>2008-04-18 21:33:21 +0000
commit3fe8c58257c809ba5b4aefaf1327fc3a4a8a3e2b (patch)
treed732eb31de7088d8bef31e9bf345a580cd7d41a2 /src/strgen
parentcd7536123b6a9d7edefd96c989d02effe94f29b3 (diff)
downloadopenttd-3fe8c58257c809ba5b4aefaf1327fc3a4a8a3e2b.tar.xz
(svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
Diffstat (limited to 'src/strgen')
-rw-r--r--src/strgen/strgen.cpp99
1 files changed, 49 insertions, 50 deletions
diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp
index ca151755d..e4a034a4e 100644
--- a/src/strgen/strgen.cpp
+++ b/src/strgen/strgen.cpp
@@ -155,7 +155,7 @@ static LangString *HashFind(const char *s)
# define LINE_NUM_FMT ":%d"
#endif
-static void CDECL warning(const char *s, ...)
+static void CDECL strgen_warning(const char *s, ...)
{
char buf[1024];
va_list va;
@@ -166,7 +166,7 @@ static void CDECL warning(const char *s, ...)
_warnings++;
}
-void CDECL error(const char *s, ...)
+static void CDECL strgen_error(const char *s, ...)
{
char buf[1024];
va_list va;
@@ -177,8 +177,7 @@ void CDECL error(const char *s, ...)
_errors++;
}
-
-static void NORETURN CDECL fatal(const char *s, ...)
+void NORETURN CDECL error(const char *s, ...)
{
char buf[1024];
va_list va;
@@ -191,7 +190,7 @@ static void NORETURN CDECL fatal(const char *s, ...)
static void PutByte(byte c)
{
- if (_put_pos == lengthof(_put_buf)) fatal("Put buffer too small");
+ if (_put_pos == lengthof(_put_buf)) error("Put buffer too small");
_put_buf[_put_pos++] = c;
}
@@ -213,7 +212,7 @@ static void PutUtf8(uint32 value)
PutByte(0x80 + GB(value, 6, 6));
PutByte(0x80 + GB(value, 0, 6));
} else {
- warning("Invalid unicode value U+0x%X", value);
+ strgen_warning("Invalid unicode value U+0x%X", value);
}
}
@@ -245,7 +244,7 @@ size_t Utf8Validate(const char *s)
static void EmitSingleChar(char *buf, int value)
{
- if (*buf != '\0') warning("Ignoring trailing letters in command");
+ if (*buf != '\0') strgen_warning("Ignoring trailing letters in command");
PutUtf8(value);
}
@@ -254,7 +253,7 @@ static void EmitSetX(char *buf, int value)
{
char *err;
int x = strtol(buf, &err, 0);
- if (*err != 0) fatal("SetX param invalid");
+ if (*err != 0) error("SetX param invalid");
PutUtf8(SCC_SETX);
PutByte((byte)x);
}
@@ -267,9 +266,9 @@ static void EmitSetXY(char *buf, int value)
int y;
x = strtol(buf, &err, 0);
- if (*err != ' ') fatal("SetXY param invalid");
+ if (*err != ' ') error("SetXY param invalid");
y = strtol(err + 1, &err, 0);
- if (*err != 0) fatal("SetXY param invalid");
+ if (*err != 0) error("SetXY param invalid");
PutUtf8(SCC_SETXY);
PutByte((byte)x);
@@ -371,14 +370,14 @@ static void EmitPlural(char *buf, int value)
}
if (nw == 0)
- fatal("%s: No plural words", _cur_ident);
+ error("%s: No plural words", _cur_ident);
if (_plural_form_counts[_lang_pluralform] != nw) {
if (_translated) {
- fatal("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
+ error("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
_plural_form_counts[_lang_pluralform], nw);
} else {
- if ((_show_todo & 2) != 0) warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident);
+ if ((_show_todo & 2) != 0) strgen_warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident);
if (nw > _plural_form_counts[_lang_pluralform]) {
nw = _plural_form_counts[_lang_pluralform];
} else {
@@ -405,7 +404,7 @@ static void EmitGender(char *buf, int value)
// This is a {G=DER} command
for (nw = 0; ; nw++) {
- if (nw >= 8) fatal("G argument '%s' invalid", buf);
+ if (nw >= 8) error("G argument '%s' invalid", buf);
if (strcmp(buf, _genders[nw]) == 0) break;
}
// now nw contains the gender index
@@ -422,7 +421,7 @@ static void EmitGender(char *buf, int value)
words[nw] = ParseWord(&buf);
if (words[nw] == NULL) break;
}
- if (nw != _numgenders) fatal("Bad # of arguments for gender command");
+ if (nw != _numgenders) error("Bad # of arguments for gender command");
PutUtf8(SCC_GENDER_LIST);
PutByte(TranslateArgumentIdx(argidx));
EmitWordList(words, nw);
@@ -553,7 +552,7 @@ static uint ResolveCaseName(const char *str, uint len)
for (i = 0; i < MAX_NUM_CASES; i++) {
if (memcmp(_cases[i], str, len) == 0 && _cases[i][len] == 0) return i + 1;
}
- fatal("Invalid case-name '%s'", str);
+ error("Invalid case-name '%s'", str);
}
@@ -578,7 +577,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
char *end;
*argno = strtoul(s, &end, 0);
- if (*end != ':') fatal("missing arg #");
+ if (*end != ':') error("missing arg #");
s = end + 1;
}
@@ -590,7 +589,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
cmd = FindCmd(start, s - start - 1);
if (cmd == NULL) {
- error("Undefined command '%.*s'", s - start - 1, start);
+ strgen_error("Undefined command '%.*s'", s - start - 1, start);
return NULL;
}
@@ -598,14 +597,14 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
const char *casep = s;
if (!(cmd->flags & C_CASE))
- fatal("Command '%s' can't have a case", cmd->cmd);
+ error("Command '%s' can't have a case", cmd->cmd);
do c = *s++; while (c != '}' && c != ' ' && c != '\0');
*casei = ResolveCaseName(casep, s - casep - 1);
}
if (c == '\0') {
- error("Missing } from command '%s'", start);
+ strgen_error("Missing } from command '%s'", start);
return NULL;
}
@@ -618,10 +617,10 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
c = *s++;
if (c == '}') break;
if (c == '\0') {
- error("Missing } from command '%s'", start);
+ strgen_error("Missing } from command '%s'", start);
return NULL;
}
- if (s - start == 250) fatal("param command too long");
+ if (s - start == 250) error("param command too long");
*param++ = c;
}
}
@@ -646,7 +645,7 @@ static void HandlePragma(char *str)
} else if (!memcmp(str, "plural ", 7)) {
_lang_pluralform = atoi(str + 7);
if (_lang_pluralform >= lengthof(_plural_form_counts))
- fatal("Invalid pluralform %d", _lang_pluralform);
+ error("Invalid pluralform %d", _lang_pluralform);
} else if (!memcmp(str, "gender ", 7)) {
char* buf = str + 7;
@@ -654,7 +653,7 @@ static void HandlePragma(char *str)
const char* s = ParseWord(&buf);
if (s == NULL) break;
- if (_numgenders >= MAX_NUM_GENDER) fatal("Too many genders, max %d", MAX_NUM_GENDER);
+ if (_numgenders >= MAX_NUM_GENDER) error("Too many genders, max %d", MAX_NUM_GENDER);
ttd_strlcpy(_genders[_numgenders], s, sizeof(_genders[_numgenders]));
_numgenders++;
}
@@ -665,12 +664,12 @@ static void HandlePragma(char *str)
const char* s = ParseWord(&buf);
if (s == NULL) break;
- if (_numcases >= MAX_NUM_CASES) fatal("Too many cases, max %d", MAX_NUM_CASES);
+ if (_numcases >= MAX_NUM_CASES) error("Too many cases, max %d", MAX_NUM_CASES);
ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases]));
_numcases++;
}
} else {
- fatal("unknown pragma '%s'", str);
+ error("unknown pragma '%s'", str);
}
}
@@ -690,16 +689,16 @@ static void ExtractCommandString(ParsedCommandStruct* p, const char* s, bool war
if (ar == NULL) break;
// Sanity checking
- if (argno != -1 && ar->consumes == 0) fatal("Non consumer param can't have a paramindex");
+ if (argno != -1 && ar->consumes == 0) error("Non consumer param can't have a paramindex");
if (ar->consumes) {
if (argno != -1) argidx = argno;
- if (argidx < 0 || argidx >= lengthof(p->cmd)) fatal("invalid param idx %d", argidx);
- if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) fatal("duplicate param idx %d", argidx);
+ if (argidx < 0 || argidx >= lengthof(p->cmd)) error("invalid param idx %d", argidx);
+ if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) error("duplicate param idx %d", argidx);
p->cmd[argidx++] = ar;
} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
- if (p->np >= lengthof(p->pairs)) fatal("too many commands in string, max %d", lengthof(p->pairs));
+ if (p->np >= lengthof(p->pairs)) error("too many commands in string, max %d", lengthof(p->pairs));
p->pairs[p->np].a = ar;
p->pairs[p->np].v = param[0] != '\0' ? strdup(param) : "";
p->np++;
@@ -738,7 +737,7 @@ static bool CheckCommandsMatch(char *a, char *b, const char *name)
// For each string in templ, see if we find it in lang
if (templ.np != lang.np) {
- warning("%s: template string and language string have a different # of commands", name);
+ strgen_warning("%s: template string and language string have a different # of commands", name);
result = false;
}
@@ -756,7 +755,7 @@ static bool CheckCommandsMatch(char *a, char *b, const char *name)
}
if (!found) {
- warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd);
+ strgen_warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd);
result = false;
}
}
@@ -765,7 +764,7 @@ static bool CheckCommandsMatch(char *a, char *b, const char *name)
// Check if the non consumer commands match up also.
for (i = 0; i < lengthof(templ.cmd); i++) {
if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) {
- warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
+ strgen_warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
lang.cmd[i] == NULL ? "<empty>" : lang.cmd[i]->cmd,
templ.cmd[i] == NULL ? "<empty>" : templ.cmd[i]->cmd);
result = false;
@@ -791,7 +790,7 @@ static void HandleString(char *str, bool master)
s = strchr(str, ':');
if (s == NULL) {
- error("Line has no ':' delimiter");
+ strgen_error("Line has no ':' delimiter");
return;
}
@@ -806,7 +805,7 @@ static void HandleString(char *str, bool master)
const char *tmp;
for (tmp = s; *tmp != '\0';) {
size_t len = Utf8Validate(tmp);
- if (len == 0) fatal("Invalid UTF-8 sequence in '%s'", s);
+ if (len == 0) error("Invalid UTF-8 sequence in '%s'", s);
tmp += len;
}
}
@@ -821,18 +820,18 @@ static void HandleString(char *str, bool master)
if (master) {
if (ent != NULL && casep == NULL) {
- error("String name '%s' is used multiple times", str);
+ strgen_error("String name '%s' is used multiple times", str);
return;
}
if (ent == NULL && casep != NULL) {
- error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str);
+ strgen_error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str);
return;
}
if (ent == NULL) {
if (_strings[_next_string_id]) {
- error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
+ strgen_error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
return;
}
@@ -859,12 +858,12 @@ static void HandleString(char *str, bool master)
} else {
if (ent == NULL) {
- warning("String name '%s' does not exist in master file", str);
+ strgen_warning("String name '%s' does not exist in master file", str);
return;
}
if (ent->translated && casep == NULL) {
- error("String name '%s' is used multiple times", str);
+ strgen_error("String name '%s' is used multiple times", str);
return;
}
@@ -912,7 +911,7 @@ static void ParseFile(const char *file, bool english)
// derive some strings from english....
in = fopen(file, "r");
- if (in == NULL) fatal("Cannot open file");
+ if (in == NULL) error("Cannot open file");
_cur_line = 1;
while (fgets(buf, sizeof(buf), in) != NULL) {
rstrip(buf);
@@ -922,7 +921,7 @@ static void ParseFile(const char *file, bool english)
fclose(in);
if (StrEmpty(_lang_name) || StrEmpty(_lang_ownname) || StrEmpty(_lang_isocode)) {
- fatal("Language must include ##name, ##ownname and ##isocode");
+ error("Language must include ##name, ##ownname and ##isocode");
}
}
@@ -991,7 +990,7 @@ bool CompareFiles(const char *n1, const char *n2)
if (f2 == NULL) return false;
f1 = fopen(n1, "rb");
- if (f1 == NULL) fatal("can't open %s", n1);
+ if (f1 == NULL) error("can't open %s", n1);
do {
l1 = fread(b1, 1, sizeof(b1), f1);
@@ -1017,7 +1016,7 @@ static void WriteStringsH(const char *filename)
int next = -1;
out = fopen("tmp.xxx", "w");
- if (out == NULL) fatal("can't open tmp.xxx");
+ if (out == NULL) error("can't open tmp.xxx");
fprintf(out, "/* This file is automatically generated. Do not modify */\n\n");
fprintf(out, "#ifndef TABLE_STRINGS_H\n");
@@ -1052,7 +1051,7 @@ static void WriteStringsH(const char *filename)
#if defined(WIN32) || defined(WIN64)
unlink(filename);
#endif
- if (rename("tmp.xxx", filename) == -1) fatal("rename() failed");
+ if (rename("tmp.xxx", filename) == -1) error("rename() failed");
}
}
@@ -1061,7 +1060,7 @@ static int TranslateArgumentIdx(int argidx)
int i, sum;
if (argidx < 0 || argidx >= lengthof(_cur_pcs.cmd))
- fatal("invalid argidx %d", argidx);
+ error("invalid argidx %d", argidx);
for (i = sum = 0; i < argidx; i++) {
const CmdStruct *cs = _cur_pcs.cmd[i];
@@ -1112,7 +1111,7 @@ static void PutCommandString(const char *str)
// Output the one from the master string... it's always accurate.
cs = _cur_pcs.cmd[_cur_argidx++];
if (cs == NULL) {
- fatal("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1);
+ error("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1);
}
}
@@ -1128,7 +1127,7 @@ static void WriteLength(FILE *f, uint length)
fputc((length >> 8) | 0xC0, f);
fputc(length & 0xFF, f);
} else {
- fatal("string too long");
+ error("string too long");
}
}
@@ -1142,7 +1141,7 @@ static void WriteLangfile(const char *filename)
uint j;
f = fopen(filename, "wb");
- if (f == NULL) fatal("can't open %s", filename);
+ if (f == NULL) error("can't open %s", filename);
memset(&hdr, 0, sizeof(hdr));
for (i = 0; i != 32; i++) {
@@ -1180,7 +1179,7 @@ static void WriteLangfile(const char *filename)
// Produce a message if a string doesn't have a translation.
if (_show_todo > 0 && ls->translated == NULL) {
if ((_show_todo & 2) != 0) {
- warning("'%s' is untranslated", ls->name);
+ strgen_warning("'%s' is untranslated", ls->name);
}
if ((_show_todo & 1) != 0) {
const char *s = "<TODO> ";