mirror of
https://github.com/AppleWin/AppleWin.git
synced 2026-04-20 15:17:50 +00:00
Replace sprintf_s() and wsprintf() with StrFormat(). (PR #1041)
And these Debugger related: . Improve FormatAddress() and GetSymbol(). . GetSymbol(), FindSymbolFromAddress(), FormatAddress() are changed to use std::string instead. . Remove static variable (not nice) in FormatAddress(). . GetSymbol() returns std::string reference instead of pointer.
This commit is contained in:
+32
-46
@@ -66,7 +66,7 @@ SSC_DIPSW CSuperSerialCard::m_DIPSWDefault =
|
||||
|
||||
CSuperSerialCard::CSuperSerialCard(UINT slot) :
|
||||
Card(CT_SSC, slot),
|
||||
m_aySerialPortChoices(NULL),
|
||||
m_strSerialPortChoices(1, '\0'), // Combo box friendly, just in case.
|
||||
m_uTCPChoiceItemIdx(0),
|
||||
m_bCfgSupportDCD(false),
|
||||
m_pExpansionRom(NULL)
|
||||
@@ -91,7 +91,8 @@ CSuperSerialCard::CSuperSerialCard(UINT slot) :
|
||||
|
||||
//
|
||||
|
||||
char serialPortName[CSuperSerialCard::SIZEOF_SERIALCHOICE_ITEM];
|
||||
const size_t SERIALCHOICE_ITEM_LENGTH = 12;
|
||||
char serialPortName[SERIALCHOICE_ITEM_LENGTH];
|
||||
std::string regSection = RegGetConfigSlotSection(m_slot);
|
||||
RegLoadString(regSection.c_str(), REGVALUE_SERIAL_PORT_NAME, TRUE, serialPortName, sizeof(serialPortName), TEXT(""));
|
||||
|
||||
@@ -125,7 +126,6 @@ void CSuperSerialCard::InternalReset()
|
||||
|
||||
CSuperSerialCard::~CSuperSerialCard()
|
||||
{
|
||||
delete [] m_aySerialPortChoices;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -266,16 +266,15 @@ bool CSuperSerialCard::CheckComm()
|
||||
else if (m_dwSerialPortItem)
|
||||
{
|
||||
_ASSERT(m_dwSerialPortItem < m_vecSerialPortsItems.size()-1); // size()-1 is TCP item
|
||||
TCHAR portname[SIZEOF_SERIALCHOICE_ITEM];
|
||||
wsprintf(portname, TEXT("\\\\.\\COM%u"), m_vecSerialPortsItems[m_dwSerialPortItem]);
|
||||
std::string portname = StrFormat("\\\\.\\COM%u", m_vecSerialPortsItems[m_dwSerialPortItem]);
|
||||
|
||||
m_hCommHandle = CreateFile(portname,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0, // exclusive access
|
||||
(LPSECURITY_ATTRIBUTES)NULL, // default security attributes
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED, // required for WaitCommEvent()
|
||||
NULL);
|
||||
m_hCommHandle = CreateFile(portname.c_str(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0, // exclusive access
|
||||
(LPSECURITY_ATTRIBUTES)NULL, // default security attributes
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED, // required for WaitCommEvent()
|
||||
NULL);
|
||||
|
||||
if (m_hCommHandle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@@ -1009,9 +1008,7 @@ void CSuperSerialCard::CommSetSerialPort(DWORD dwNewSerialPortItem)
|
||||
}
|
||||
else if (m_dwSerialPortItem != 0)
|
||||
{
|
||||
TCHAR temp[SIZEOF_SERIALCHOICE_ITEM];
|
||||
sprintf(temp, TEXT_SERIAL_COM"%d", m_vecSerialPortsItems[m_dwSerialPortItem]);
|
||||
m_currentSerialPortName = temp;
|
||||
m_currentSerialPortName = StrFormat(TEXT_SERIAL_COM "%d", m_vecSerialPortsItems[m_dwSerialPortItem]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1297,16 +1294,15 @@ void CSuperSerialCard::ScanCOMPorts()
|
||||
|
||||
for (UINT i=1; i<32; i++) // Arbitrary upper limit
|
||||
{
|
||||
TCHAR portname[SIZEOF_SERIALCHOICE_ITEM];
|
||||
wsprintf(portname, TEXT("\\\\.\\COM%u"), i);
|
||||
std::string portname = StrFormat("\\\\.\\COM%u", i);
|
||||
|
||||
HANDLE hCommHandle = CreateFile(portname,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0, // exclusive access
|
||||
(LPSECURITY_ATTRIBUTES)NULL, // default security attributes
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED, // required for WaitCommEvent()
|
||||
NULL);
|
||||
HANDLE hCommHandle = CreateFile(portname.c_str(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0, // exclusive access
|
||||
(LPSECURITY_ATTRIBUTES)NULL, // default security attributes
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED, // required for WaitCommEvent()
|
||||
NULL);
|
||||
|
||||
if (hCommHandle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@@ -1321,38 +1317,28 @@ void CSuperSerialCard::ScanCOMPorts()
|
||||
m_uTCPChoiceItemIdx = m_vecSerialPortsItems.size()-1;
|
||||
}
|
||||
|
||||
char* CSuperSerialCard::GetSerialPortChoices()
|
||||
std::string const& CSuperSerialCard::GetSerialPortChoices()
|
||||
{
|
||||
if (IsActive())
|
||||
return m_aySerialPortChoices;
|
||||
return m_strSerialPortChoices;
|
||||
|
||||
//
|
||||
ScanCOMPorts(); // Do this every time in case news ones available (eg. for USB COM ports)
|
||||
|
||||
ScanCOMPorts(); // Do this every time in case news ones available (eg. for USB COM ports)
|
||||
delete [] m_aySerialPortChoices;
|
||||
m_aySerialPortChoices = new TCHAR [ GetNumSerialPortChoices() * SIZEOF_SERIALCHOICE_ITEM + 1 ]; // +1 for final NULL item
|
||||
m_strSerialPortChoices = "None";
|
||||
m_strSerialPortChoices += '\0'; // NULL char for combo box selection.
|
||||
|
||||
TCHAR* pNextSerialChoice = m_aySerialPortChoices;
|
||||
|
||||
//
|
||||
|
||||
pNextSerialChoice += wsprintf(pNextSerialChoice, TEXT("None"));
|
||||
pNextSerialChoice++; // Skip NULL char
|
||||
|
||||
for (UINT i=1; i<m_uTCPChoiceItemIdx; i++)
|
||||
for (UINT i = 1; i < m_uTCPChoiceItemIdx; i++)
|
||||
{
|
||||
pNextSerialChoice += wsprintf(pNextSerialChoice, TEXT("COM%u"), m_vecSerialPortsItems[i]);
|
||||
pNextSerialChoice++; // Skip NULL char
|
||||
m_strSerialPortChoices += StrFormat("COM%u", m_vecSerialPortsItems[i]);
|
||||
m_strSerialPortChoices += '\0'; // NULL char for combo box selection.
|
||||
}
|
||||
|
||||
pNextSerialChoice += wsprintf(pNextSerialChoice, TEXT("TCP"));
|
||||
pNextSerialChoice++; // Skip NULL char
|
||||
m_strSerialPortChoices += "TCP";
|
||||
m_strSerialPortChoices += '\0'; // NULL char for combo box selection.
|
||||
|
||||
*pNextSerialChoice = 0;
|
||||
// std::string()'s implicit nul terminator becomes combo box end of list marker.
|
||||
|
||||
//
|
||||
|
||||
return m_aySerialPortChoices;
|
||||
return m_strSerialPortChoices;
|
||||
}
|
||||
|
||||
// Called by ctor & LoadSnapshot()
|
||||
|
||||
Reference in New Issue
Block a user