Changeset - r26342:d8dee617c9b0
[Not reviewed]
master
0 4 0
Niels Martin Hansen - 2 years ago 2022-08-26 10:08:47
nielsm@indvikleren.dk
Fix #9940: Print debuglevel parse errors to console when changed from console
4 files changed with 8 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -1584,13 +1584,13 @@ DEF_CONSOLE_CMD(ConDebugLevel)
 

	
 
	if (argc > 2) return false;
 

	
 
	if (argc == 1) {
 
		IConsolePrint(CC_DEFAULT, "Current debug-level: '{}'", GetDebugString());
 
	} else {
 
		SetDebugString(argv[1]);
 
		SetDebugString(argv[1], [](const char *err) { IConsolePrint(CC_ERROR, std::string(err)); });
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConExit)
src/debug.cpp
Show inline comments
 
@@ -156,14 +156,15 @@ void DebugPrint(const char *level, const
 

	
 
/**
 
 * Set debugging levels by parsing the text in \a s.
 
 * 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? */
 
@@ -200,13 +201,14 @@ void SetDebugString(const char *s)
 
		if (*s == '=') s++;
 
		v = strtoul(s, &end, 0);
 
		s = end;
 
		if (p != nullptr) {
 
			*p = v;
 
		} else {
 
			ShowInfoF("Unknown debug level '%.*s'", (int)(s - t), t);
 
			std::string error_string = fmt::format("Unknown debug level '{}'", std::string(t, s - t));
 
			error_func(error_string.c_str());
 
			return;
 
		}
 
	}
 
}
 

	
 
/**
src/debug.h
Show inline comments
 
@@ -54,13 +54,13 @@ extern int _debug_desync_level;
 
extern int _debug_console_level;
 
#ifdef RANDOM_DEBUG
 
extern int _debug_random_level;
 
#endif
 

	
 
char *DumpDebugFacilityNames(char *buf, char *last);
 
void SetDebugString(const char *s);
 
void SetDebugString(const char *s, void (*error_func)(const char *));
 
const char *GetDebugString();
 

	
 
/* Shorter form for passing filename and linenumber */
 
#define FILE_LINE __FILE__, __LINE__
 

	
 
/* Used for profiling
src/openttd.cpp
Show inline comments
 
@@ -561,13 +561,13 @@ int openttd_main(int argc, char *argv[])
 
		case 'D':
 
			musicdriver = "null";
 
			sounddriver = "null";
 
			videodriver = "dedicated";
 
			blitter = "null";
 
			dedicated = true;
 
			SetDebugString("net=4");
 
			SetDebugString("net=4", ShowInfo);
 
			if (mgo.opt != nullptr) {
 
				scanner->dedicated_host = ParseFullConnectionString(mgo.opt, scanner->dedicated_port);
 
			}
 
			break;
 
		case 'f': _dedicated_forks = true; break;
 
		case 'n':
 
@@ -585,13 +585,13 @@ int openttd_main(int argc, char *argv[])
 
		case 'r': ParseResolution(&resolution, mgo.opt); break;
 
		case 't': scanner->startyear = atoi(mgo.opt); break;
 
		case 'd': {
 
#if defined(_WIN32)
 
				CreateConsole();
 
#endif
 
				if (mgo.opt != nullptr) SetDebugString(mgo.opt);
 
				if (mgo.opt != nullptr) SetDebugString(mgo.opt, ShowInfo);
 
				break;
 
			}
 
		case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break;
 
		case 'g':
 
			if (mgo.opt != nullptr) {
 
				_file_to_saveload.SetName(mgo.opt);
0 comments (0 inline, 0 general)