Debugger: replace sprintf() part 3 - Debugger_Symbols

- Change _CmdSymbolsInfoHeader() to return std::string
This commit is contained in:
Kelvin Lee 2022-04-17 21:12:40 +10:00
parent 08c730c647
commit d83dae3b29

View File

@ -75,7 +75,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// Utils _ ________________________________________________________________________________________ // Utils _ ________________________________________________________________________________________
void _CmdSymbolsInfoHeader( int iTable, char * pText, int nDisplaySize = 0 ); std::string _CmdSymbolsInfoHeader( int iTable, int nDisplaySize = 0 );
void _PrintCurrentPath(); void _PrintCurrentPath();
Update_t _PrintSymbolInvalidTable(); Update_t _PrintSymbolInvalidTable();
@ -90,33 +90,28 @@ void _PrintCurrentPath()
Update_t _PrintSymbolInvalidTable() Update_t _PrintSymbolInvalidTable()
{ {
char sText[ CONSOLE_WIDTH * 2 ];
char sTemp[ CONSOLE_WIDTH * 2 ];
// TODO: display the user specified file name // TODO: display the user specified file name
ConsoleBufferPush( "Invalid symbol table." ); ConsoleBufferPush( "Invalid symbol table." );
ConsolePrintFormat( "Only %s%d%s symbol tables are supported:" ConsolePrintFormat( "Only " CHC_NUM_DEC "%d" CHC_DEFAULT " symbol tables are supported:"
, CHC_NUM_DEC, NUM_SYMBOL_TABLES , NUM_SYMBOL_TABLES
, CHC_DEFAULT
); );
std::string sText;
// Similar to _CmdSymbolsInfoHeader() // Similar to _CmdSymbolsInfoHeader()
sText[0] = 0;
for ( int iTable = 0; iTable < NUM_SYMBOL_TABLES; iTable++ ) for ( int iTable = 0; iTable < NUM_SYMBOL_TABLES; iTable++ )
{ {
sprintf( sTemp, "%s%s%s%c " // %s" sText += StrFormat( CHC_USAGE "%s" CHC_ARG_SEP "%c "
, CHC_USAGE, g_aSymbolTableNames[ iTable ] , g_aSymbolTableNames[ iTable ]
, CHC_ARG_SEP
, (iTable != (NUM_SYMBOL_TABLES-1)) , (iTable != (NUM_SYMBOL_TABLES-1))
? ',' ? ','
: '.' : '.'
); );
strcat( sText, sTemp );
} }
// return ConsoleDisplayError( sText ); // return ConsoleDisplayError( sText.c_str() );
ConsolePrint( sText ); ConsolePrint( sText.c_str() );
return ConsoleUpdate(); return ConsoleUpdate();
} }
@ -286,7 +281,7 @@ Update_t CmdSymbolsClear (int nArgs)
// Format the summary of the specified symbol table // Format the summary of the specified symbol table
//=========================================================================== //===========================================================================
void _CmdSymbolsInfoHeader( int iTable, char * pText, int nDisplaySize /* = 0 */ ) std::string _CmdSymbolsInfoHeader( int iTable, int nDisplaySize /* = 0 */ )
{ {
// Common case is to use/calc the table size // Common case is to use/calc the table size
bool bActive = (g_bDisplaySymbolTables & (1 << iTable)) ? true : false; bool bActive = (g_bDisplaySymbolTables & (1 << iTable)) ? true : false;
@ -295,25 +290,17 @@ void _CmdSymbolsInfoHeader( int iTable, char * pText, int nDisplaySize /* = 0 */
// Short Desc: `MAIN`: `1000` // Short Desc: `MAIN`: `1000`
// // 2.6.2.19 Color for name of symbol table: _CmdPrintSymbol() "SYM HOME" _CmdSymbolsInfoHeader "SYM" // // 2.6.2.19 Color for name of symbol table: _CmdPrintSymbol() "SYM HOME" _CmdSymbolsInfoHeader "SYM"
// CHC_STRING and CHC_NUM_DEC are both cyan, using CHC_USAGE instead of CHC_STRING // CHC_STRING and CHC_NUM_DEC are both cyan, using CHC_USAGE instead of CHC_STRING
sprintf( pText, "%s%s%s:%s%d " // %s" return StrFormat(CHC_USAGE "%s" CHC_ARG_SEP ":%s%d " // CHC_DEFAULT
, CHC_USAGE, g_aSymbolTableNames[ iTable ] , g_aSymbolTableNames[ iTable ]
, CHC_ARG_SEP
, bActive ? CHC_NUM_DEC : CHC_WARNING, nSymbols , bActive ? CHC_NUM_DEC : CHC_WARNING, nSymbols
// , CHC_DEFAULT
); );
} }
//=========================================================================== //===========================================================================
Update_t CmdSymbolsInfo (int nArgs) Update_t CmdSymbolsInfo (int nArgs)
{ {
const char sIndent[] = " ";
char sText[ CONSOLE_WIDTH * 4 ] = "";
char sTemp[ CONSOLE_WIDTH * 2 ] = "";
int bDisplaySymbolTables = 0; int bDisplaySymbolTables = 0;
strcpy( sText, sIndent ); // Indent new line
if (! nArgs) if (! nArgs)
{ {
// default to all tables // default to all tables
@ -330,27 +317,27 @@ Update_t CmdSymbolsInfo (int nArgs)
bDisplaySymbolTables = (1 << iWhichTable); bDisplaySymbolTables = (1 << iWhichTable);
} }
//sprintf( sText, " Symbols Main: %s%d%s User: %s%d%s Source: %s%d%s" std::string const sIndent = " ";
// "Main:# Basic:# Asm:# User1:# User2:# Src1:# Src2:# Dos:# Prodos:# std::string sText = sIndent; // Indent new line
for ( int iTable = 0, bTable = 1; bTable <= bDisplaySymbolTables; iTable++, bTable <<= 1 ) for ( int iTable = 0, bTable = 1; bTable <= bDisplaySymbolTables; iTable++, bTable <<= 1 )
{ {
if ( bDisplaySymbolTables & bTable ) if ( !!(bDisplaySymbolTables & bTable) )
{ {
_CmdSymbolsInfoHeader( iTable, sTemp ); // 15 chars per table std::string hdr = _CmdSymbolsInfoHeader( iTable ); // 15 chars per table
// 2.8.0.4 BUGFIX: Check for buffer overflow and wrap text // 2.8.0.4 BUGFIX: Check for buffer overflow and wrap text
int nLen = ConsoleColor_StringLength( sTemp ); int nLen = ConsoleColor_StringLength( hdr.c_str() );
int nDst = ConsoleColor_StringLength( sText ); int nDst = ConsoleColor_StringLength( sText.c_str() );
if ((nDst + nLen) > CONSOLE_WIDTH ) if ( (nDst + nLen) > CONSOLE_WIDTH )
{ {
ConsolePrint( sText ); ConsolePrint( sText.c_str() );
strcpy( sText, sIndent ); // Indent new line sText = sIndent; // Indent new line
} }
strcat( sText, sTemp ); sText += hdr;
} }
} }
ConsolePrint( sText ); ConsolePrint( sText.c_str() );
return ConsoleUpdate(); return ConsoleUpdate();
} }
@ -473,8 +460,6 @@ Update_t _CmdSymbolsListTables (int nArgs, int bSymbolTables )
SYMBOL B = $2000 SYMBOL B = $2000
SYM B SYM B
*/ */
TCHAR sText[ CONSOLE_WIDTH ] = "";
for ( int iArgs = 1; iArgs <= nArgs; iArgs++ ) for ( int iArgs = 1; iArgs <= nArgs; iArgs++ )
{ {
@ -505,8 +490,7 @@ Update_t _CmdSymbolsListTables (int nArgs, int bSymbolTables )
++iSymbol; ++iSymbol;
} }
} }
_CmdSymbolsInfoHeader( iTable, sText ); ConsolePrint(_CmdSymbolsInfoHeader(iTable).c_str() );
ConsolePrint( sText );
} }
} }
} }
@ -952,8 +936,6 @@ Update_t _CmdSymbolsCommon ( int nArgs, int bSymbolTables )
if (iUpdate != UPDATE_NOTHING) if (iUpdate != UPDATE_NOTHING)
return iUpdate; return iUpdate;
TCHAR sText[ CONSOLE_WIDTH ];
int iArg = 0; int iArg = 0;
while (iArg++ <= nArgs) while (iArg++ <= nArgs)
{ {
@ -992,13 +974,7 @@ Update_t _CmdSymbolsCommon ( int nArgs, int bSymbolTables )
{ {
if ( bUpdate & UPDATE_SYMBOLS ) if ( bUpdate & UPDATE_SYMBOLS )
{ {
//sprintf( sText, " Symbol Table: %s%s%s, %sloaded symbols: %s%d" ConsolePrint( _CmdSymbolsInfoHeader( iTable, g_nSymbolsLoaded ).c_str() );
// , CHC_STRING, g_aSymbolTableNames[ iTable ]
// , CHC_DEFAULT, CHC_DEFAULT
// , CHC_NUM_DEC, g_nSymbolsLoaded
//);
_CmdSymbolsInfoHeader( iTable, sText, g_nSymbolsLoaded );
ConsolePrint( sText );
} }
} }
else else
@ -1020,8 +996,7 @@ Update_t _CmdSymbolsCommon ( int nArgs, int bSymbolTables )
int iTable = _GetSymbolTableFromFlag( bSymbolTables ); int iTable = _GetSymbolTableFromFlag( bSymbolTables );
if (iTable != NUM_SYMBOL_TABLES) if (iTable != NUM_SYMBOL_TABLES)
{ {
_CmdSymbolsInfoHeader( iTable, sText ); ConsolePrint( _CmdSymbolsInfoHeader( iTable ).c_str() );
ConsolePrint( sText );
} }
return ConsoleUpdate() | UPDATE_DISASM; return ConsoleUpdate() | UPDATE_DISASM;
} }
@ -1032,8 +1007,7 @@ Update_t _CmdSymbolsCommon ( int nArgs, int bSymbolTables )
int iTable = _GetSymbolTableFromFlag( bSymbolTables ); int iTable = _GetSymbolTableFromFlag( bSymbolTables );
if (iTable != NUM_SYMBOL_TABLES) if (iTable != NUM_SYMBOL_TABLES)
{ {
_CmdSymbolsInfoHeader( iTable, sText ); ConsolePrint( _CmdSymbolsInfoHeader( iTable ).c_str() );
ConsolePrint( sText );
} }
return ConsoleUpdate() | UPDATE_DISASM; return ConsoleUpdate() | UPDATE_DISASM;
} }