From 11d1c41873953b81b0d4b94e0c1d6208691e7be8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 7 Dec 2008 17:50:03 +0000 Subject: [PATCH] - 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. SVN r1313 (trunk) --- docs/rh-log.txt | 5 +++ src/cmdlib.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ src/cmdlib.h | 1 + src/p_acs.cpp | 4 +-- src/sc_man.cpp | 2 ++ 5 files changed, 101 insertions(+), 3 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 77e0a0e35a..c284a69553 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 f1e087a283..d255723eed 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 aafb9129cb..2447285207 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 b7c6f31301..f744809a81 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 0044aacb2d..7a301584e5 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()); }