1
1
/*
2
2
This file is part of Warzone 2100.
3
3
Copyright (C) 1999-2004 Eidos Interactive
4
- Copyright (C) 2005-2020 Warzone 2100 Project
4
+ Copyright (C) 2005-2025 Warzone 2100 Project
5
5
6
6
Warzone 2100 is free software; you can redistribute it and/or modify
7
7
it under the terms of the GNU General Public License as published by
@@ -847,15 +847,13 @@ bool seq_AddTextForVideo(const char *pText, SDWORD xOffset, SDWORD yOffset, doub
847
847
return true ;
848
848
}
849
849
850
-
851
850
static bool seq_AddTextFromFile (const char *pTextName, SEQ_TEXT_POSITIONING textJustification)
852
851
{
853
852
char aTextName[MAX_STR_LENGTH];
854
- char *pTextBuffer, *pCurrentLine, *pText ;
853
+ char *pTextBuffer;
855
854
UDWORD fileSize;
856
855
SDWORD xOffset, yOffset;
857
856
double startTime, endTime;
858
- const char *seps = " \n " ;
859
857
860
858
// NOTE: The original game never had a fullscreen mode for FMVs on >640x480 screens.
861
859
// They would just use double sized videos, and move the text to that area.
@@ -871,35 +869,33 @@ static bool seq_AddTextFromFile(const char *pTextName, SEQ_TEXT_POSITIONING text
871
869
}
872
870
873
871
pTextBuffer = fileLoadBuffer;
874
- pCurrentLine = strtok (pTextBuffer, seps);
875
- while (pCurrentLine != nullptr )
872
+ std::istringstream stream (pTextBuffer);
873
+ std::string pCurrentLine;
874
+
875
+ while (std::getline (stream, pCurrentLine))
876
876
{
877
- if (* pCurrentLine != ' /' )
877
+ if (! pCurrentLine. empty () && pCurrentLine[ 0 ] != ' /' )
878
878
{
879
- if (sscanf (pCurrentLine, " %d %d %lf %lf" , &xOffset, &yOffset, &startTime, &endTime) == 4 )
879
+ std::istringstream lineStream (pCurrentLine);
880
+ if (lineStream >> xOffset >> yOffset >> startTime >> endTime)
880
881
{
881
882
// Since all the positioning was hardcoded to specific values, we now calculate the
882
883
// ratio of our screen, compared to what the game expects and multiply that to x, y.
883
884
// This makes the text always take up the full screen, instead of original style.
884
885
xOffset = static_cast <SDWORD>((double )pie_GetVideoBufferWidth () / 640 . * (double )xOffset);
885
886
yOffset = static_cast <SDWORD>((double )pie_GetVideoBufferHeight () / 480 . * (double )yOffset);
886
887
// get the text
887
- pText = strrchr (pCurrentLine, ' "' );
888
- ASSERT (pText != nullptr , " error parsing text file" );
889
- if (pText != nullptr )
890
- {
891
- *pText = (UBYTE)0 ;
892
- }
893
- pText = strchr (pCurrentLine, ' "' );
894
- ASSERT (pText != nullptr , " error parsing text file" );
895
- if (pText != nullptr )
888
+ size_t firstQuote = pCurrentLine.find (' "' );
889
+ size_t lastQuote = pCurrentLine.rfind (' "' );
890
+
891
+ ASSERT (firstQuote != std::string::npos && lastQuote != std::string::npos && firstQuote < lastQuote, " error parsing text file" );
892
+ if (firstQuote != std::string::npos && lastQuote != std::string::npos && firstQuote < lastQuote)
896
893
{
897
- seq_AddTextForVideo (_ (&pText[1 ]), xOffset, yOffset, startTime, endTime, textJustification);
894
+ std::string text = pCurrentLine.substr (firstQuote + 1 , lastQuote - firstQuote - 1 );
895
+ seq_AddTextForVideo (_ (text.c_str ()), xOffset, yOffset, startTime, endTime, textJustification);
898
896
}
899
897
}
900
898
}
901
- // get next line
902
- pCurrentLine = strtok (nullptr , seps);
903
899
}
904
900
return true ;
905
901
}
0 commit comments