src/strgen/strgen.cpp
branchNewGRF_ports
changeset 10274 b3c58f3df92b
parent 10242 52b4a9006029
child 10724 68a692eacf22
--- a/src/strgen/strgen.cpp	Fri Apr 18 21:20:03 2008 +0000
+++ b/src/strgen/strgen.cpp	Sun Apr 20 15:27:28 2008 +0000
@@ -155,7 +155,7 @@
 # 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 @@
 	_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 @@
 	_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 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 @@
 		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 @@
 
 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 @@
 {
 	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 @@
 	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 @@
 	}
 
 	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 @@
 
 		// 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 @@
 			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 @@
 	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 @@
 		char *end;
 
 		*argno = strtoul(s, &end, 0);
-		if (*end != ':') fatal("missing arg #");
+		if (*end != ':') error("missing arg #");
 		s = end + 1;
 	}
 
@@ -590,7 +589,7 @@
 
 	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 @@
 		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 @@
 			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 @@
 	} 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 @@
 			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 @@
 			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 @@
 		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 @@
 
 	// 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 @@
 		}
 
 		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 @@
 	// 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 @@
 
 	s = strchr(str, ':');
 	if (s == NULL) {
-		error("Line has no ':' delimiter");
+		strgen_error("Line has no ':' delimiter");
 		return;
 	}
 
@@ -806,7 +805,7 @@
 		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 @@
 
 	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 @@
 
 	} 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 @@
 	// 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 @@
 	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 @@
 	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 @@
 	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 @@
 #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 @@
 	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 @@
 			// 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 @@
 		fputc((length >> 8) | 0xC0, f);
 		fputc(length & 0xFF, f);
 	} else {
-		fatal("string too long");
+		error("string too long");
 	}
 }
 
@@ -1142,7 +1141,7 @@
 	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 @@
 			// 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> ";