diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 77e0a0e35..c284a6955 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,9 @@ December 7, 2008 (Changes by Graf Zahl) +- Added a strbin1 function that does the same as strbin but creates a copy + instead of overwriting the original string. ACS performing this operation + in place caused crashes with RTC-3057. +- fixed: FScriptPosition::Message did not print the message if it was not + a fatal error. - Fixed: The save percentage for Doom's green armor was slightly too low which caused roundoff errors that made it less than 1/3 effective. - Added support for "RRGGBB" strings to V_GetColor. diff --git a/src/cmdlib.cpp b/src/cmdlib.cpp index f1e087a28..d255723ee 100644 --- a/src/cmdlib.cpp +++ b/src/cmdlib.cpp @@ -470,6 +470,97 @@ int strbin (char *str) return str - start; } +// [RH] Replaces the escape sequences in a string with actual escaped characters. +// This operation is done in-place. The result is the new length of the string. + +FString strbin1 (const char *start) +{ + FString result; + const char *p = start; + char c; + int i; + + while ( (c = *p++) ) { + if (c != '\\') { + result << c; + } else { + switch (*p) { + case 'a': + result << '\a'; + break; + case 'b': + result << '\b'; + break; + case 'c': + result << '\034'; // TEXTCOLOR_ESCAPE + break; + case 'f': + result << '\f'; + break; + case 'n': + result << '\n'; + break; + case 't': + result << '\t'; + break; + case 'r': + result << '\r'; + break; + case 'v': + result << '\v'; + break; + case '?': + result << '\?'; + break; + case '\n': + break; + case 'x': + case 'X': + c = 0; + p++; + for (i = 0; i < 2; i++) { + c <<= 4; + if (*p >= '0' && *p <= '9') + c += *p-'0'; + else if (*p >= 'a' && *p <= 'f') + c += 10 + *p-'a'; + else if (*p >= 'A' && *p <= 'F') + c += 10 + *p-'A'; + else + break; + p++; + } + result << c; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + c = 0; + for (i = 0; i < 3; i++) { + c <<= 3; + if (*p >= '0' && *p <= '7') + c += *p-'0'; + else + break; + p++; + } + result << c; + break; + default: + result << *p; + break; + } + p++; + } + } + return result; +} + //========================================================================== // // ExpandEnvVars @@ -534,3 +625,4 @@ FString ExpandEnvVars(const char *searchpathstring) } return out; } + diff --git a/src/cmdlib.h b/src/cmdlib.h index aafb9129c..244728520 100644 --- a/src/cmdlib.h +++ b/src/cmdlib.h @@ -52,6 +52,7 @@ void FormatGUID (char *buffer, size_t buffsize, const GUID &guid); const char *myasctime (); int strbin (char *str); +FString strbin1 (const char *start); void CreatePath(const char * fn); diff --git a/src/p_acs.cpp b/src/p_acs.cpp index b7c6f3130..f744809a8 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4070,9 +4070,7 @@ int DLevelScript::RunScript () case PCD_ENDPRINTBOLD: case PCD_MOREHUDMESSAGE: case PCD_ENDLOG: - strbin (work.LockBuffer()); - work.Truncate ((long)strlen(work)); - work.UnlockBuffer(); + work = strbin1 (work); if (pcd == PCD_ENDLOG) { Printf ("%s\n", work.GetChars()); diff --git a/src/sc_man.cpp b/src/sc_man.cpp index 0044aacb2..7a301584e 100644 --- a/src/sc_man.cpp +++ b/src/sc_man.cpp @@ -1109,6 +1109,8 @@ void STACK_ARGS FScriptPosition::Message (int severity, const char *message, ... I_Error ("Script error, \"%s\" line %d:\n%s\n", FileName.GetChars(), ScriptLine, composed.GetChars()); } + Printf (level, "Script %s, \"%s\" line %d:\n%s\n", + type, FileName.GetChars(), ScriptLine, composed.GetChars()); }