Changeset - r27555:efb2f3b16d4d
[Not reviewed]
master
0 3 0
Rubidium - 12 months ago 2023-06-08 15:15:32
rubidium@openttd.org
Codechange: replace stredup + StrMakeValidInPlace with std::string + StrMakeValid
3 files changed with 6 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/console.cpp
Show inline comments
 
@@ -47,13 +47,13 @@ void IConsoleInit()
 
	IConsoleStdLibRegister();
 
}
 

	
 
static void IConsoleWriteToLogFile(const char *string)
 
static void IConsoleWriteToLogFile(const std::string &string)
 
{
 
	if (_iconsole_output_file != nullptr) {
 
		/* if there is an console output file ... also print it there */
 
		const char *header = GetLogPrefix();
 
		if ((strlen(header) != 0 && fwrite(header, strlen(header), 1, _iconsole_output_file) != 1) ||
 
				fwrite(string, strlen(string), 1, _iconsole_output_file) != 1 ||
 
				fwrite(string.c_str(), string.size(), 1, _iconsole_output_file) != 1 ||
 
				fwrite("\n", 1, 1, _iconsole_output_file) != 1) {
 
			fclose(_iconsole_output_file);
 
			_iconsole_output_file = nullptr;
 
@@ -104,23 +104,20 @@ void IConsolePrint(TextColour colour_cod
 
		return;
 
	}
 

	
 
	/* Create a copy of the string, strip if of colours and invalid
 
	/* Create a copy of the string, strip it of colours and invalid
 
	 * characters and (when applicable) assign it to the console buffer */
 
	char *str = stredup(string.c_str());
 
	StrMakeValidInPlace(str);
 
	std::string str = StrMakeValid(string);
 

	
 
	if (_network_dedicated) {
 
		NetworkAdminConsole("console", str);
 
		fmt::print("{}{}\n", GetLogPrefix(), str);
 
		fflush(stdout);
 
		IConsoleWriteToLogFile(str);
 
		free(str); // free duplicated string since it's not used anymore
 
		return;
 
	}
 

	
 
	IConsoleWriteToLogFile(str);
 
	IConsoleGUIPrint(colour_code, str);
 
	free(str);
 
}
 

	
 
/**
src/console_gui.cpp
Show inline comments
 
@@ -462,7 +462,7 @@ static void IConsoleHistoryNavigate(int 
 
 * @param colour_code the colour of the command. Red in case of errors, etc.
 
 * @param str the message entered or output on the console (notice, error, etc.)
 
 */
 
void IConsoleGUIPrint(TextColour colour_code, char *str)
 
void IConsoleGUIPrint(TextColour colour_code, const std::string &str)
 
{
 
	_iconsole_buffer.push_front(IConsoleLine(str, colour_code));
 
	SetWindowDirty(WC_CONSOLE, 0);
src/console_internal.h
Show inline comments
 
@@ -86,6 +86,6 @@ bool GetArgumentInteger(uint32 *value, c
 

	
 
void IConsoleGUIInit();
 
void IConsoleGUIFree();
 
void IConsoleGUIPrint(TextColour colour_code, char *string);
 
void IConsoleGUIPrint(TextColour colour_code, const std::string &string);
 

	
 
#endif /* CONSOLE_INTERNAL_H */
0 comments (0 inline, 0 general)