Changeset - r14533:80e1809325a6
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2010-02-12 23:47:50
rubidium@openttd.org
(svn r19114) -Change: [strgen] Modify the outputted format for MSVC builds of strgen so it also shows fatal errors in the 'error list' and it also counts them. (Fatal) errors are marked as warnings so a failing language file is not causing the complete compilation to fail.
1 file changed with 8 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/strgen/strgen.cpp
Show inline comments
 
@@ -93,135 +93,138 @@ static uint _numgenders;
 
static char _cases[MAX_NUM_CASES][16];
 
static uint _numcases;
 

	
 
static const char *_cur_ident;
 

	
 
struct CmdPair {
 
	const CmdStruct *a;
 
	const char *v;
 
};
 

	
 
struct ParsedCommandStruct {
 
	uint np;
 
	CmdPair pairs[32];
 
	const CmdStruct *cmd[32]; // ordered by param #
 
};
 

	
 
/* Used when generating some advanced commands. */
 
static ParsedCommandStruct _cur_pcs;
 
static int _cur_argidx;
 

	
 
static uint HashStr(const char *s)
 
{
 
	uint hash = 0;
 
	for (; *s != '\0'; s++) hash = ROL(hash, 3) ^ *s;
 
	return hash % HASH_SIZE;
 
}
 

	
 
static void HashAdd(const char *s, LangString *ls)
 
{
 
	uint hash = HashStr(s);
 
	ls->hash_next = _hash_head[hash];
 
	_hash_head[hash] = ls->index + 1;
 
}
 

	
 
static LangString *HashFind(const char *s)
 
{
 
	int idx = _hash_head[HashStr(s)];
 

	
 
	while (--idx >= 0) {
 
		LangString *ls = _strings[idx];
 

	
 
		if (strcmp(ls->name, s) == 0) return ls;
 
		idx = ls->hash_next;
 
	}
 
	return NULL;
 
}
 

	
 
#ifdef _MSC_VER
 
# define LINE_NUM_FMT "(%d)"
 
# define LINE_NUM_FMT(s) "%s (%d): warning: %s (" s ")\n"
 
#else
 
# define LINE_NUM_FMT ":%d"
 
# define LINE_NUM_FMT(s) "%s: :%d: " s ": %s\n"
 
#endif
 

	
 
static void CDECL strgen_warning(const char *s, ...) WARN_FORMAT(1, 2);
 

	
 
static void CDECL strgen_warning(const char *s, ...)
 
{
 
	char buf[1024];
 
	va_list va;
 
	va_start(va, s);
 
	vsnprintf(buf, lengthof(buf), s, va);
 
	va_end(va);
 
	fprintf(stderr, "%s" LINE_NUM_FMT ": warning: %s\n", _file, _cur_line, buf);
 
	fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, buf);
 
	_warnings++;
 
}
 

	
 
static void CDECL strgen_error(const char *s, ...) WARN_FORMAT(1, 2);
 

	
 
static void CDECL strgen_error(const char *s, ...)
 
{
 
	char buf[1024];
 
	va_list va;
 
	va_start(va, s);
 
	vsnprintf(buf, lengthof(buf), s, va);
 
	va_end(va);
 
	fprintf(stderr, "%s" LINE_NUM_FMT ": error: %s\n", _file, _cur_line, buf);
 
	fprintf(stderr, LINE_NUM_FMT("error"), _file, _cur_line, buf);
 
	_errors++;
 
}
 

	
 
void NORETURN CDECL error(const char *s, ...)
 
{
 
	char buf[1024];
 
	va_list va;
 
	va_start(va, s);
 
	vsnprintf(buf, lengthof(buf), s, va);
 
	va_end(va);
 
	fprintf(stderr, "%s" LINE_NUM_FMT ": FATAL: %s\n", _file, _cur_line, buf);
 
	fprintf(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, buf);
 
#ifdef _MSC_VER
 
	fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled");
 
#endif
 
	/* We were writing output to a file, remove it. */
 
	if (_output_file != NULL) {
 
		fclose(_output_file);
 
		unlink(_output_filename);
 
	}
 
	exit(1);
 
}
 

	
 
static void PutByte(byte c)
 
{
 
	if (_put_pos == lengthof(_put_buf)) error("Put buffer too small");
 
	_put_buf[_put_pos++] = c;
 
}
 

	
 

	
 
static void PutUtf8(uint32 value)
 
{
 
	if (value < 0x80) {
 
		PutByte(value);
 
	} else if (value < 0x800) {
 
		PutByte(0xC0 + GB(value,  6, 5));
 
		PutByte(0x80 + GB(value,  0, 6));
 
	} else if (value < 0x10000) {
 
		PutByte(0xE0 + GB(value, 12, 4));
 
		PutByte(0x80 + GB(value,  6, 6));
 
		PutByte(0x80 + GB(value,  0, 6));
 
	} else if (value < 0x110000) {
 
		PutByte(0xF0 + GB(value, 18, 3));
 
		PutByte(0x80 + GB(value, 12, 6));
 
		PutByte(0x80 + GB(value,  6, 6));
 
		PutByte(0x80 + GB(value,  0, 6));
 
	} else {
 
		strgen_warning("Invalid unicode value U+0x%X", value);
 
	}
 
}
 

	
 

	
 
size_t Utf8Validate(const char *s)
 
{
 
	uint32 c;
 

	
 
	if (!HasBit(s[0], 7)) {
 
		/* 1 byte */
 
		return 1;
 
	} else if (GB(s[0], 5, 3) == 6 && IsUtf8Part(s[1])) {
 
		/* 2 bytes */
 
		c = GB(s[0], 0, 5) << 6 | GB(s[1], 0, 6);
 
		if (c >= 0x80) return 2;
0 comments (0 inline, 0 general)