Merge branch 'master' into jgrpp
# Conflicts: # src/lang/english_AU.txt # src/openttd.cpp # src/viewport_sprite_sorter_sse4.cpp
This commit is contained in:
@@ -245,28 +245,31 @@ void CDECL debug(const char *dbg, const char *format, ...)
|
||||
* For setting individual levels a string like \c "net=3,grf=6" should be used.
|
||||
* If the string starts with a number, the number is used as global debugging level.
|
||||
* @param s Text describing the wanted debugging levels.
|
||||
* @param error_func The function to call if a parse error occurs.
|
||||
*/
|
||||
void SetDebugString(const char *s)
|
||||
void SetDebugString(const char *s, void (*error_func)(const char *))
|
||||
{
|
||||
int v;
|
||||
char *end;
|
||||
const char *t;
|
||||
|
||||
/* global debugging level? */
|
||||
/* Store planned changes into map during parse */
|
||||
std::map<const char *, int> new_levels;
|
||||
|
||||
/* Global debugging level? */
|
||||
if (*s >= '0' && *s <= '9') {
|
||||
const DebugLevel *i;
|
||||
|
||||
v = strtoul(s, &end, 0);
|
||||
s = end;
|
||||
|
||||
for (i = debug_level; i != endof(debug_level); ++i) *i->level = v;
|
||||
for (i = debug_level; i != endof(debug_level); ++i) {
|
||||
new_levels[i->name] = v;
|
||||
}
|
||||
}
|
||||
|
||||
/* individual levels */
|
||||
/* Individual levels */
|
||||
for (;;) {
|
||||
const DebugLevel *i;
|
||||
int *p;
|
||||
|
||||
/* skip delimiters */
|
||||
while (*s == ' ' || *s == ',' || *s == '\t') s++;
|
||||
if (*s == '\0') break;
|
||||
@@ -275,10 +278,10 @@ void SetDebugString(const char *s)
|
||||
while (*s >= 'a' && *s <= 'z') s++;
|
||||
|
||||
/* check debugging levels */
|
||||
p = nullptr;
|
||||
for (i = debug_level; i != endof(debug_level); ++i) {
|
||||
const DebugLevel *found = nullptr;
|
||||
for (const DebugLevel *i = debug_level; i != endof(debug_level); ++i) {
|
||||
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) {
|
||||
p = i->level;
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -286,13 +289,23 @@ void SetDebugString(const char *s)
|
||||
if (*s == '=') s++;
|
||||
v = strtoul(s, &end, 0);
|
||||
s = end;
|
||||
if (p != nullptr) {
|
||||
*p = v;
|
||||
if (found != nullptr) {
|
||||
new_levels[found->name] = v;
|
||||
} else {
|
||||
ShowInfoF("Unknown debug level '%.*s'", (int)(s - t), t);
|
||||
char buf[1024];
|
||||
seprintf(buf, lastof(buf), "Unknown debug level '%*s'", (int)(s - t), t);
|
||||
error_func(buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Apply the changes after parse is successful */
|
||||
for (const DebugLevel *i = debug_level; i != endof(debug_level); ++i) {
|
||||
const auto &nl = new_levels.find(i->name);
|
||||
if (nl != new_levels.end()) {
|
||||
*i->level = nl->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user