mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: replace stredup + StrMakeValidInPlace with std::string + StrMakeValid
This commit is contained in:
parent
e762855201
commit
3f35787458
|
@ -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_code, const std::string &string)
|
|||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -462,7 +462,7 @@ static void IConsoleHistoryNavigate(int direction)
|
|||
* @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);
|
||||
|
|
|
@ -86,6 +86,6 @@ bool GetArgumentInteger(uint32 *value, const char *arg);
|
|||
|
||||
void IConsoleGUIInit();
|
||||
void IConsoleGUIFree();
|
||||
void IConsoleGUIPrint(TextColour colour_code, char *string);
|
||||
void IConsoleGUIPrint(TextColour colour_code, const std::string &string);
|
||||
|
||||
#endif /* CONSOLE_INTERNAL_H */
|
||||
|
|
Loading…
Reference in New Issue