From d5890e835632d01bbdd6c5f0c057c065a6c40260 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Fri, 6 Sep 2019 17:34:25 +0100 Subject: [PATCH] Replace some char * with std::string. --- source/Applewin.cpp | 13 +++-- source/Applewin.h | 2 +- source/Configuration/PageAdvanced.cpp | 4 +- source/Debugger/Debug.cpp | 69 +++++++++++-------------- source/Debugger/Debug.h | 4 +- source/Debugger/Debugger_Display.cpp | 11 ++-- source/Debugger/Debugger_Help.h | 4 +- source/Debugger/Debugger_Symbols.cpp | 24 ++++----- source/Debugger/Debugger_Symbols.h | 2 +- source/Debugger/Util_MemoryTextFile.cpp | 4 +- source/Debugger/Util_MemoryTextFile.h | 2 +- source/Frame.cpp | 12 ++--- source/ParallelPrinter.cpp | 33 ++++-------- source/ParallelPrinter.h | 4 +- source/YamlHelper.cpp | 5 ++ source/YamlHelper.h | 1 + 16 files changed, 85 insertions(+), 109 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index f76aa3c8..7562b5ad 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -80,7 +80,7 @@ HINSTANCE g_hInstance = (HINSTANCE)0; AppMode_e g_nAppMode = MODE_LOGO; static bool g_bLoadedSaveState = false; -TCHAR g_sProgramDir[MAX_PATH] = TEXT(""); // Directory of where AppleWin executable resides +std::string g_sProgramDir; // Directory of where AppleWin executable resides TCHAR g_sDebugDir [MAX_PATH] = TEXT(""); // TODO: Not currently used TCHAR g_sScreenShotDir[MAX_PATH] = TEXT(""); // TODO: Not currently used bool g_bCapturePrintScreenKey = true; @@ -472,15 +472,18 @@ void EnterMessageLoop(void) //=========================================================================== void GetProgramDirectory(void) { - GetModuleFileName((HINSTANCE)0, g_sProgramDir, MAX_PATH); - g_sProgramDir[MAX_PATH-1] = 0; + TCHAR programDir[MAX_PATH]; + GetModuleFileName((HINSTANCE)0, programDir, MAX_PATH); + programDir[MAX_PATH-1] = 0; - int loop = _tcslen(g_sProgramDir); + g_sProgramDir = programDir; + + int loop = g_sProgramDir.size(); while (loop--) { if ((g_sProgramDir[loop] == TEXT('\\')) || (g_sProgramDir[loop] == TEXT(':'))) { - g_sProgramDir[loop+1] = 0; + g_sProgramDir.resize(loop); // this reduces the size break; } } diff --git a/source/Applewin.h b/source/Applewin.h index 91ccf334..4d2dcc7a 100644 --- a/source/Applewin.h +++ b/source/Applewin.h @@ -34,7 +34,7 @@ bool GetLoadedSaveStateFlag(void); void SetLoadedSaveStateFlag(const bool bFlag); bool GetHookAltGrControl(void); -extern TCHAR g_sProgramDir[MAX_PATH]; +extern std::string g_sProgramDir; extern TCHAR g_sCurrentDir[MAX_PATH]; extern bool g_bRestart; diff --git a/source/Configuration/PageAdvanced.cpp b/source/Configuration/PageAdvanced.cpp index 5d63b6bd..a908666f 100644 --- a/source/Configuration/PageAdvanced.cpp +++ b/source/Configuration/PageAdvanced.cpp @@ -134,7 +134,7 @@ BOOL CPageAdvanced::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPAR CheckDlgButton(hWnd, IDC_PRINTER_APPEND, g_bPrinterAppend ? BST_CHECKED : BST_UNCHECKED); SendDlgItemMessage(hWnd, IDC_SPIN_PRINTER_IDLE, UDM_SETRANGE, 0, MAKELONG(999,0)); SendDlgItemMessage(hWnd, IDC_SPIN_PRINTER_IDLE, UDM_SETPOS, 0, MAKELONG(Printer_GetIdleLimit (),0)); - SendDlgItemMessage(hWnd, IDC_PRINTER_DUMP_FILENAME, WM_SETTEXT, 0, (LPARAM)Printer_GetFilename()); + SendDlgItemMessage(hWnd, IDC_PRINTER_DUMP_FILENAME, WM_SETTEXT, 0, (LPARAM)Printer_GetFilename().c_str()); InitOptions(hWnd); @@ -182,7 +182,7 @@ void CPageAdvanced::DlgOK(HWND hWnd) szFilename[nLineLength] = 0x00; Printer_SetFilename(szFilename); - RegSaveString(TEXT(REG_CONFIG), REGVALUE_PRINTER_FILENAME, 1, Printer_GetFilename()); + RegSaveString(TEXT(REG_CONFIG), REGVALUE_PRINTER_FILENAME, 1, Printer_GetFilename().c_str()); } g_bSaveStateOnExit = IsDlgButtonChecked(hWnd, IDC_SAVESTATE_ON_EXIT) ? true : false; diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 2fc7e920..1ad20c0e 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -225,7 +225,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ProfileOpmode_t g_aProfileOpmodes[ NUM_OPMODES ]; unsigned __int64 g_nProfileBeginCycles = 0; // g_nCumulativeCycles // PROFILE RESET - TCHAR g_FileNameProfile[] = TEXT("Profile.txt"); // changed from .csv to .txt since Excel doesn't give import options. + const std::string g_FileNameProfile = TEXT("Profile.txt"); // changed from .csv to .txt since Excel doesn't give import options. int g_nProfileLine = 0; char g_aProfileLine[ NUM_PROFILE_LINES ][ CONSOLE_WIDTH ]; @@ -245,7 +245,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA bool g_bSourceAddSymbols = false; bool g_bSourceAddMemory = false; - char g_aSourceFileName[ MAX_PATH ] = ""; + std::string g_aSourceFileName; MemoryTextFile_t g_AssemblerSourceBuffer; @@ -285,7 +285,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Misc. __________________________________________________________________________________________ - char g_sFileNameConfig [] = + std::string g_sFileNameConfig = #ifdef MSDOS "AWDEBUGR.CFG"; #else @@ -347,7 +347,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static void _UpdateWindowFontHeights (int nFontHeight); // Source Level Debugging - static bool BufferAssemblyListing ( char * pFileName ); + static bool BufferAssemblyListing ( const std::string & pFileName ); static bool ParseAssemblyListing ( bool bBytesToMemory, bool bAddSymbols ); @@ -2394,9 +2394,7 @@ void ConfigSave_PrepareHeader ( const Parameters_e eCategory, const Commands_e e //=========================================================================== Update_t CmdConfigSave (int nArgs) { - TCHAR sFilename[ MAX_PATH ]; - _tcscpy( sFilename, g_sProgramDir ); // TODO: g_sDebugDir - _tcscat( sFilename, g_sFileNameConfig ); + const std::string sFilename = g_sProgramDir + g_sFileNameConfig; /* HANDLE hFile = CreateFile( sfilename, @@ -4768,8 +4766,7 @@ Update_t CmdMemorySave (int nArgs) // (g_aArgs[ iArgComma2 ].eToken != TOKEN_COLON)) // return Help_Arg_1( CMD_MEMORY_SAVE ); - TCHAR sLoadSaveFilePath[ MAX_PATH ]; - _tcscpy( sLoadSaveFilePath, g_sCurrentDir ); // g_sProgramDir + std::string sLoadSaveFilePath = g_sCurrentDir; // g_sProgramDir RangeType_t eRange; eRange = Range_Get( nAddressStart, nAddress2, iArgAddress ); @@ -4791,7 +4788,7 @@ Update_t CmdMemorySave (int nArgs) { _tcscpy( g_sMemoryLoadSaveFileName, g_aArgs[ 1 ].sArg ); } - _tcscat( sLoadSaveFilePath, g_sMemoryLoadSaveFileName ); + sLoadSaveFilePath += g_sMemoryLoadSaveFileName; const BYTE * const pMemBankBase = bBankSpecified ? MemGetBankPtr(nBank) : mem; if (!pMemBankBase) @@ -4800,7 +4797,7 @@ Update_t CmdMemorySave (int nArgs) return ConsoleUpdate(); } - FILE *hFile = fopen( sLoadSaveFilePath, "rb" ); + FILE *hFile = fopen( sLoadSaveFilePath.c_str(), "rb" ); if (hFile) { ConsoleBufferPush( TEXT( "Warning: File already exists. Overwriting." ) ); @@ -4808,7 +4805,7 @@ Update_t CmdMemorySave (int nArgs) // TODO: BUG: Is this a bug/feature that we can over-write files and the user has no control over that? } - hFile = fopen( sLoadSaveFilePath, "wb" ); + hFile = fopen( sLoadSaveFilePath.c_str(), "wb" ); if (hFile) { size_t nWrote = fwrite( pMemBankBase+nAddressStart, nAddressLen, 1, hFile ); @@ -5631,8 +5628,7 @@ int CmdTextSave (int nArgs) char *pText; size_t nSize = Util_GetTextScreen( pText ); - TCHAR sLoadSaveFilePath[ MAX_PATH ]; - _tcscpy( sLoadSaveFilePath, g_sCurrentDir ); // g_sProgramDir + std::string sLoadSaveFilePath = g_sCurrentDir; // g_sProgramDir if( bHaveFileName ) _tcscpy( g_sMemoryLoadSaveFileName, g_aArgs[ 1 ].sArg ); @@ -5644,16 +5640,16 @@ int CmdTextSave (int nArgs) sprintf( g_sMemoryLoadSaveFileName, "AppleWin_Text40.txt" ); } - _tcscat( sLoadSaveFilePath, g_sMemoryLoadSaveFileName ); + sLoadSaveFilePath += g_sMemoryLoadSaveFileName; - FILE *hFile = fopen( sLoadSaveFilePath, "rb" ); + FILE *hFile = fopen( sLoadSaveFilePath.c_str(), "rb" ); if (hFile) { ConsoleBufferPush( TEXT( "Warning: File already exists. Overwriting." ) ); fclose( hFile ); } - hFile = fopen( sLoadSaveFilePath, "wb" ); + hFile = fopen( sLoadSaveFilePath.c_str(), "wb" ); if (hFile) { size_t nWrote = fwrite( pText, nSize, 1, hFile ); @@ -6518,11 +6514,11 @@ Update_t CmdOutputRun (int nArgs) // Source Level Debugging _________________________________________________________________________ //=========================================================================== -bool BufferAssemblyListing( char *pFileName ) +bool BufferAssemblyListing( const std::string & pFileName ) { bool bStatus = false; // true = loaded - if (! pFileName) + if (pFileName.empty()) return bStatus; g_AssemblerSourceBuffer.Reset(); @@ -6740,10 +6736,10 @@ Update_t CmdSource (int nArgs) for( int iArg = 1; iArg <= nArgs; iArg++ ) { - TCHAR *pFileName = g_aArgs[ iArg ].sArg; + const std::string pFileName = g_aArgs[ iArg ].sArg; int iParam; - bool bFound = FindParam( pFileName, MATCH_EXACT, iParam, _PARAM_SOURCE_BEGIN, _PARAM_SOURCE_END ) > 0 ? true : false; + bool bFound = FindParam( pFileName.c_str(), MATCH_EXACT, iParam, _PARAM_SOURCE_BEGIN, _PARAM_SOURCE_END ) > 0 ? true : false; if (bFound && (iParam == PARAM_SRC_SYMBOLS)) { g_bSourceAddSymbols = true; @@ -6755,35 +6751,32 @@ Update_t CmdSource (int nArgs) } else { - TCHAR sFileName[MAX_PATH]; - _tcscpy(sFileName,g_sProgramDir); - _tcscat(sFileName, pFileName); + const std::string sFileName = g_sProgramDir + pFileName; - const int MAX_MINI_FILENAME = 20; - TCHAR sMiniFileName[ MAX_MINI_FILENAME + 1 ]; - _tcsncpy( sMiniFileName, pFileName, MAX_MINI_FILENAME - 1 ); - sMiniFileName[ MAX_MINI_FILENAME ] = 0; + const int MAX_MINI_FILENAME = 20; + const std::string sMiniFileName = sFileName.substr(0, min(MAX_MINI_FILENAME, sFileName.size())); + TCHAR buffer[MAX_PATH] = { 0 }; if (BufferAssemblyListing( sFileName )) { - _tcscpy( g_aSourceFileName, pFileName ); + g_aSourceFileName = pFileName; if (! ParseAssemblyListing( g_bSourceAddMemory, g_bSourceAddSymbols )) { - ConsoleBufferPushFormat( sFileName, "Couldn't load filename: %s", sMiniFileName ); + ConsoleBufferPushFormat( buffer, "Couldn't load filename: %s", sMiniFileName.c_str() ); } else { if (g_nSourceAssembleBytes) { - ConsoleBufferPushFormat( sFileName, " Read: %d lines, %d symbols, %d bytes" + ConsoleBufferPushFormat( buffer, " Read: %d lines, %d symbols, %d bytes" , g_AssemblerSourceBuffer.GetNumLines() // g_nSourceAssemblyLines , g_nSourceAssemblySymbols, g_nSourceAssembleBytes ); } else { - ConsoleBufferPushFormat( sFileName, " Read: %d lines, %d symbols" + ConsoleBufferPushFormat( buffer, " Read: %d lines, %d symbols" , g_AssemblerSourceBuffer.GetNumLines() // g_nSourceAssemblyLines , g_nSourceAssemblySymbols ); } @@ -6791,7 +6784,7 @@ Update_t CmdSource (int nArgs) } else { - ConsoleBufferPushFormat( sFileName, "Error reading: %s", sMiniFileName ); + ConsoleBufferPushFormat( buffer, "Error reading: %s", sMiniFileName.c_str() ); } } } @@ -7659,7 +7652,7 @@ Update_t CmdZeroPagePointer (int nArgs) // Note: Range is [iParamBegin,iParamEnd], not the usually (STL) expected [iParamBegin,iParamEnd) //=========================================================================== -int FindParam( LPTSTR pLookupName, Match_e eMatch, int & iParam_, int iParamBegin, int iParamEnd ) +int FindParam(LPCTSTR pLookupName, Match_e eMatch, int & iParam_, int iParamBegin, int iParamEnd ) { int nFound = 0; int nLen = _tcslen( pLookupName ); @@ -7723,7 +7716,7 @@ int FindParam( LPTSTR pLookupName, Match_e eMatch, int & iParam_, int iParamBegi } //=========================================================================== -int FindCommand( LPTSTR pName, CmdFuncPtr_t & pFunction_, int * iCommand_ ) +int FindCommand( LPCTSTR pName, CmdFuncPtr_t & pFunction_, int * iCommand_ ) { g_vPotentialCommands.erase( g_vPotentialCommands.begin(), g_vPotentialCommands.end() ); @@ -8446,11 +8439,9 @@ bool ProfileSave() { bool bStatus = false; - char sFilename[MAX_PATH]; - strcpy( sFilename, g_sProgramDir ); // TODO: Allow user to decide? - strcat( sFilename, g_FileNameProfile ); + const std::string sFilename = g_sProgramDir + g_FileNameProfile; // TODO: Allow user to decide? - FILE *hFile = fopen( sFilename, "wt" ); + FILE *hFile = fopen( sFilename.c_str(), "wt" ); if (hFile) { diff --git a/source/Debugger/Debug.h b/source/Debugger/Debug.h index 921ec797..8dc3f84d 100644 --- a/source/Debugger/Debug.h +++ b/source/Debugger/Debug.h @@ -66,7 +66,7 @@ }; // Config - FileName - extern char g_sFileNameConfig[]; + extern std::string g_sFileNameConfig; // Cursor extern WORD g_nDisasmTopAddress ; @@ -107,7 +107,7 @@ extern std::vector g_vMemorySearchResults; // Source Level Debugging - extern TCHAR g_aSourceFileName[ MAX_PATH ]; + extern std::string g_aSourceFileName; extern MemoryTextFile_t g_AssemblerSourceBuffer; extern int g_iSourceDisplayStart ; diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index e4925f42..b82d17ed 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -3767,17 +3767,12 @@ void DrawSubWindow_Source2 (Update_t bUpdate) rect.right = DISPLAY_DISASM_RIGHT; // HACK: MAGIC #: 7 // Draw Title - char sTitle[ CONSOLE_WIDTH ]; - char sText [ CONSOLE_WIDTH ]; - strcpy ( sTitle, " Source: " ); - int maxSizeToCopy = g_nConsoleDisplayWidth - strlen(sTitle) - 1; - strncpy( sText , g_aSourceFileName, maxSizeToCopy ); - sText[ maxSizeToCopy - 1 ] = 0; - strcat ( sTitle, sText ); + std::string sTitle = " Source: " + g_aSourceFileName; + sTitle.resize(min(sTitle.size(), size_t(g_nConsoleDisplayWidth))); DebuggerSetColorBG( DebuggerGetColor( BG_SOURCE_TITLE )); DebuggerSetColorFG( DebuggerGetColor( FG_SOURCE_TITLE )); - PrintText( sTitle, rect ); + PrintText( sTitle.c_str(), rect ); rect.top += g_nFontHeight; // Draw Source Lines diff --git a/source/Debugger/Debugger_Help.h b/source/Debugger/Debugger_Help.h index 246dc336..b3ecdba7 100644 --- a/source/Debugger/Debugger_Help.h +++ b/source/Debugger/Debugger_Help.h @@ -14,8 +14,8 @@ void DisplayAmbigiousCommands ( int nFound ); - int FindParam( LPTSTR pLookupName, Match_e eMatch, int & iParam_, const int iParamBegin = 0, const int iParamEnd = NUM_PARAMS - 1 ); - int FindCommand( LPTSTR pName, CmdFuncPtr_t & pFunction_, int * iCommand_ = NULL ); + int FindParam( LPCTSTR pLookupName, Match_e eMatch, int & iParam_, const int iParamBegin = 0, const int iParamEnd = NUM_PARAMS - 1 ); + int FindCommand( LPCTSTR pName, CmdFuncPtr_t & pFunction_, int * iCommand_ = NULL ); inline void UnpackVersion( const unsigned int nVersion, int & nMajor_, int & nMinor_, int & nFixMajor_ , int & nFixMinor_ ) diff --git a/source/Debugger/Debugger_Symbols.cpp b/source/Debugger/Debugger_Symbols.cpp index 3bf65dec..f1fb5364 100644 --- a/source/Debugger/Debugger_Symbols.cpp +++ b/source/Debugger/Debugger_Symbols.cpp @@ -52,7 +52,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ,"A2_DOS33.SYM" ,"A2_PRODOS.SYM" }; - char g_sFileNameSymbolsUser [ MAX_PATH ] = ""; + std::string g_sFileNameSymbolsUser; char * g_aSymbolTableNames[ NUM_SYMBOL_TABLES ] = { @@ -84,7 +84,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //=========================================================================== void _PrintCurrentPath() { - ConsoleDisplayError( g_sProgramDir ); + ConsoleDisplayError( g_sProgramDir.c_str() ); } Update_t _PrintSymbolInvalidTable() @@ -551,7 +551,7 @@ Update_t _CmdSymbolsListTables (int nArgs, int bSymbolTables ) //=========================================================================== -int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrite, int nSymbolOffset ) +int ParseSymbolTable(const std::string & pPathFileName, SymbolTable_Index_e eSymbolTableWrite, int nSymbolOffset ) { char sText[ CONSOLE_WIDTH * 3 ]; bool bFileDisplayed = false; @@ -560,7 +560,7 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit int nSymbolsLoaded = 0; - if (! pPathFileName) + if (pPathFileName.empty()) return nSymbolsLoaded; //#if _UNICODE @@ -574,7 +574,7 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit sprintf( sFormat1, "%%x %%%ds", MAX_SYMBOLS_LEN ); // i.e. "%x %13s" sprintf( sFormat2, "%%%ds %%x", MAX_SYMBOLS_LEN ); // i.e. "%13s %x" - FILE *hFile = fopen( pPathFileName, "rt" ); + FILE *hFile = fopen( pPathFileName.c_str(), "rt" ); if( !hFile && g_bSymbolsDisplayMissingFile ) { @@ -749,8 +749,7 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit //=========================================================================== Update_t CmdSymbolsLoad (int nArgs) { - TCHAR sFileName[MAX_PATH]; - _tcscpy(sFileName,g_sProgramDir); + std::string sFileName = g_sProgramDir; int iSymbolTable = GetSymbolTableFromCommand(); if ((iSymbolTable < 0) || (iSymbolTable >= NUM_SYMBOL_TABLES)) @@ -763,24 +762,23 @@ Update_t CmdSymbolsLoad (int nArgs) // Debugger will call us with 0 args on startup as a way to pre-load symbol tables if (! nArgs) { - _tcscat(sFileName, g_sFileNameSymbols[ iSymbolTable ]); + sFileName += g_sFileNameSymbols[ iSymbolTable ]; nSymbols = ParseSymbolTable( sFileName, (SymbolTable_Index_e) iSymbolTable ); } int iArg = 1; if (iArg <= nArgs) { - TCHAR *pFileName = NULL; + std::string pFileName; if( g_aArgs[ iArg ].bType & TYPE_QUOTED_2 ) { pFileName = g_aArgs[ iArg ].sArg; - _tcscpy(sFileName,g_sProgramDir); - _tcscat(sFileName, pFileName); + sFileName = g_sProgramDir + pFileName; // Remember File Name of last symbols loaded - _tcscpy( g_sFileNameSymbolsUser, pFileName ); + g_sFileNameSymbolsUser = pFileName; } // SymbolOffset @@ -804,7 +802,7 @@ Update_t CmdSymbolsLoad (int nArgs) } } - if( pFileName ) + if( !pFileName.empty() ) { nSymbols = ParseSymbolTable( sFileName, (SymbolTable_Index_e) iSymbolTable, nOffsetAddr ); } diff --git a/source/Debugger/Debugger_Symbols.h b/source/Debugger/Debugger_Symbols.h index f1690872..444b0ea5 100644 --- a/source/Debugger/Debugger_Symbols.h +++ b/source/Debugger/Debugger_Symbols.h @@ -13,5 +13,5 @@ bool _CmdSymbolList_Symbol2Address ( LPCTSTR pSymbol, int bSymbolTables ); // SymbolOffset - int ParseSymbolTable ( TCHAR *pFileName, SymbolTable_Index_e eWhichTableToLoad, int nSymbolOffset = 0 ); + int ParseSymbolTable ( const std::string & pFileName, SymbolTable_Index_e eWhichTableToLoad, int nSymbolOffset = 0 ); diff --git a/source/Debugger/Util_MemoryTextFile.cpp b/source/Debugger/Util_MemoryTextFile.cpp index edb87954..94ee4f2d 100644 --- a/source/Debugger/Util_MemoryTextFile.cpp +++ b/source/Debugger/Util_MemoryTextFile.cpp @@ -31,10 +31,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA const int EOL_NULL = 0; //=========================================================================== -bool MemoryTextFile_t::Read( char *pFileName ) +bool MemoryTextFile_t::Read( const std::string & pFileName ) { bool bStatus = false; - FILE *hFile = fopen( pFileName, "rb" ); + FILE *hFile = fopen( pFileName.c_str(), "rb" ); if (hFile) { diff --git a/source/Debugger/Util_MemoryTextFile.h b/source/Debugger/Util_MemoryTextFile.h index 016a052e..c63ac9f0 100644 --- a/source/Debugger/Util_MemoryTextFile.h +++ b/source/Debugger/Util_MemoryTextFile.h @@ -21,7 +21,7 @@ m_vLines.reserve( 128 ); } - bool Read( TCHAR *pFileName ); + bool Read( const std::string & pFileName ); void Reset() { m_vBuffer.erase( m_vBuffer.begin(), m_vBuffer.end() ); diff --git a/source/Frame.cpp b/source/Frame.cpp index dad6123e..7e5b88da 100644 --- a/source/Frame.cpp +++ b/source/Frame.cpp @@ -1969,20 +1969,16 @@ static void ProcessButtonClick(int button, bool bFromButtonUI /*=false*/) case BTN_HELP: { - TCHAR filename[MAX_PATH]; - _tcscpy(filename,g_sProgramDir); - _tcscat(filename,TEXT("APPLEWIN.CHM")); + const std::string filename = g_sProgramDir + TEXT("APPLEWIN.CHM"); // (GH#437) For any internet downloaded AppleWin.chm files (stored on an NTFS drive) there may be an Alt Data Stream containing a Zone Identifier // - try to delete it, otherwise the content won't be displayed unless it's unblock (via File Properties) { - TCHAR filename_with_zone_identifier[MAX_PATH]; - _tcscpy(filename_with_zone_identifier,filename); - _tcscat(filename_with_zone_identifier,TEXT(":Zone.Identifier")); - DeleteFile(filename_with_zone_identifier); + const std::string filename_with_zone_identifier = filename + TEXT(":Zone.Identifier"); + DeleteFile(filename_with_zone_identifier.c_str()); } - HtmlHelp(g_hFrameWindow,filename,HH_DISPLAY_TOC,0); + HtmlHelp(g_hFrameWindow,filename.c_str(),HH_DISPLAY_TOC,0); helpquit = 1; } break; diff --git a/source/ParallelPrinter.cpp b/source/ParallelPrinter.cpp index 50c9b16d..47cb7300 100644 --- a/source/ParallelPrinter.cpp +++ b/source/ParallelPrinter.cpp @@ -42,7 +42,7 @@ static unsigned int g_PrinterIdleLimit = 10; static FILE* file = NULL; DWORD const PRINTDRVR_SIZE = APPLE_SLOT_SIZE; #define DEFAULT_PRINT_FILENAME "Printer.txt" -static char g_szPrintFilename[MAX_PATH] = {0}; +static std::string g_szPrintFilename; bool g_bDumpToPrinter = false; bool g_bConvertEncoding = true; bool g_bFilterUnprintable = true; @@ -97,9 +97,9 @@ static BOOL CheckPrint() //_tcsncat(filepath, _T("Printer.txt"), MAX_PATH); //file = fopen(filepath, "wb"); if (g_bPrinterAppend ) - file = fopen(Printer_GetFilename(), "ab"); + file = fopen(Printer_GetFilename().c_str(), "ab"); else - file = fopen(Printer_GetFilename(), "wb"); + file = fopen(Printer_GetFilename().c_str(), "wb"); } return (file != NULL); } @@ -228,33 +228,21 @@ static BYTE __stdcall PrintTransmit(WORD, WORD, BYTE, BYTE value, ULONG) //=========================================================================== -char* Printer_GetFilename() +const std::string & Printer_GetFilename() { return g_szPrintFilename; } -void Printer_SetFilename(char* prtFilename) +void Printer_SetFilename(const std::string & prtFilename) { - if (*prtFilename) + if (!prtFilename.empty()) { - strcpy(g_szPrintFilename, (const char *) prtFilename); + g_szPrintFilename = prtFilename; } else //No registry entry is available { - _tcsncpy(g_szPrintFilename, g_sProgramDir, MAX_PATH); - g_szPrintFilename[MAX_PATH - 1] = 0; - - // NB. _tcsncat_s() terminates program if buffer is too small! So continue to use manual buffer check & _tcsncat() - - int nLen = sizeof(g_szPrintFilename) - strlen(g_szPrintFilename) - (sizeof(DEFAULT_PRINT_FILENAME)-1) - 1; - if (nLen < 0) - { - MessageBox(g_hFrameWindow, "Printer - SetFilename(): folder too deep", "Warning", MB_ICONWARNING | MB_OK); - return; - } - - _tcsncat(g_szPrintFilename, DEFAULT_PRINT_FILENAME, sizeof(DEFAULT_PRINT_FILENAME)-1); - RegSaveString(REG_CONFIG, REGVALUE_PRINTER_FILENAME, 1, g_szPrintFilename); + g_szPrintFilename = g_sProgramDir + DEFAULT_PRINT_FILENAME; + RegSaveString(REG_CONFIG, REGVALUE_PRINTER_FILENAME, 1, g_szPrintFilename.c_str()); } } @@ -314,8 +302,7 @@ bool Printer_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT inactivity = yamlLoadHelper.LoadUint(SS_YAML_KEY_INACTIVITY); g_PrinterIdleLimit = yamlLoadHelper.LoadUint(SS_YAML_KEY_IDLELIMIT); - strncpy(g_szPrintFilename, yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME).c_str(), sizeof(g_szPrintFilename)); - g_szPrintFilename[sizeof(g_szPrintFilename)-1] = 0; + g_szPrintFilename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME); if (yamlLoadHelper.LoadBool(SS_YAML_KEY_FILEOPEN)) { diff --git a/source/ParallelPrinter.h b/source/ParallelPrinter.h index d2b96bdb..332f1c85 100644 --- a/source/ParallelPrinter.h +++ b/source/ParallelPrinter.h @@ -4,8 +4,8 @@ void PrintDestroy(); void PrintLoadRom(LPBYTE pCxRomPeripheral, UINT uSlot); void PrintReset(); void PrintUpdate(DWORD); -void Printer_SetFilename(char* pszFilename); -char* Printer_GetFilename(); +void Printer_SetFilename(const std::string & pszFilename); +const std::string & Printer_GetFilename(); void Printer_SetIdleLimit(unsigned int Duration); unsigned int Printer_GetIdleLimit(); diff --git a/source/YamlHelper.cpp b/source/YamlHelper.cpp index dbcaddcd..0d73b781 100644 --- a/source/YamlHelper.cpp +++ b/source/YamlHelper.cpp @@ -442,6 +442,11 @@ void YamlSaveHelper::SaveString(const char* key, const char* value) Save("%s: %s\n", key, (value[0] != 0) ? value : "\"\""); } +void YamlSaveHelper::SaveString(const char* key, const std::string & value) +{ + SaveString(key, value.c_str()); +} + void YamlSaveHelper::SaveFloat(const char* key, float value) { Save("%s: %f\n", key, value); diff --git a/source/YamlHelper.h b/source/YamlHelper.h index 48f0999a..f306c0a1 100644 --- a/source/YamlHelper.h +++ b/source/YamlHelper.h @@ -216,6 +216,7 @@ public: void SaveHexUint64(const char* key, UINT64 value); void SaveBool(const char* key, bool value); void SaveString(const char* key, const char* value); + void SaveString(const char* key, const std::string & value); void SaveFloat(const char* key, float value); void SaveDouble(const char* key, double value); void SaveMemory(const LPBYTE pMemBase, const UINT uMemSize);