|
10 | 10 | #ifdef _WIN32
|
11 | 11 | #include "Platform.h"
|
12 | 12 | #endif
|
| 13 | +#include <iostream> |
13 | 14 | #include <string.h>
|
14 | 15 |
|
15 | 16 | // In-house headers:
|
|
28 | 29 | // Throws: None.
|
29 | 30 | //--
|
30 | 31 | CMICmnStreamStdin::CMICmnStreamStdin()
|
31 |
| - : m_strPromptCurrent("(gdb)"), m_bShowPrompt(true), m_pCmdBuffer(nullptr) {} |
| 32 | + : m_strPromptCurrent("(gdb)"), m_bShowPrompt(true) {} |
32 | 33 |
|
33 | 34 | //++
|
34 | 35 | // Details: CMICmnStreamStdin destructor.
|
@@ -61,9 +62,7 @@ bool CMICmnStreamStdin::Initialize() {
|
61 | 62 | MI::ModuleInit<CMICmnLog>(IDS_MI_INIT_ERR_LOG, bOk, errMsg);
|
62 | 63 | MI::ModuleInit<CMICmnResources>(IDS_MI_INIT_ERR_RESOURCES, bOk, errMsg);
|
63 | 64 |
|
64 |
| - if (bOk) { |
65 |
| - m_pCmdBuffer = new char[m_constBufferSize]; |
66 |
| - } else { |
| 65 | + if (!bOk) { |
67 | 66 | CMIUtilString strInitError(CMIUtilString::Format(
|
68 | 67 | MIRSRC(IDS_MI_INIT_ERR_STREAMSTDIN), errMsg.c_str()));
|
69 | 68 | SetErrorDescription(strInitError);
|
@@ -94,11 +93,6 @@ bool CMICmnStreamStdin::Shutdown() {
|
94 | 93 |
|
95 | 94 | ClrErrorDescription();
|
96 | 95 |
|
97 |
| - if (m_pCmdBuffer != nullptr) { |
98 |
| - delete[] m_pCmdBuffer; |
99 |
| - m_pCmdBuffer = nullptr; |
100 |
| - } |
101 |
| - |
102 | 96 | bool bOk = MIstatus::success;
|
103 | 97 | CMIUtilString errMsg;
|
104 | 98 |
|
@@ -186,33 +180,22 @@ bool CMICmnStreamStdin::GetEnablePrompt() const { return m_bShowPrompt; }
|
186 | 180 | const char *CMICmnStreamStdin::ReadLine(CMIUtilString &vwErrMsg) {
|
187 | 181 | vwErrMsg.clear();
|
188 | 182 |
|
189 |
| - // Read user input |
190 |
| - const char *pText = ::fgets(&m_pCmdBuffer[0], m_constBufferSize, stdin); |
191 |
| - if (pText == nullptr) { |
| 183 | + std::getline(std::cin, m_pCmdString); |
| 184 | + |
| 185 | + if (std::cin.eof()) { |
192 | 186 | #ifdef _MSC_VER
|
193 | 187 | // Was Ctrl-C hit?
|
194 | 188 | // On Windows, Ctrl-C gives an ERROR_OPERATION_ABORTED as error on the
|
195 |
| - // command-line. |
196 |
| - // The end-of-file indicator is also set, so without this check we will exit |
197 |
| - // next if statement. |
| 189 | + // command-line and the end-of-file indicator is also set. |
198 | 190 | if (::GetLastError() == ERROR_OPERATION_ABORTED)
|
199 | 191 | return nullptr;
|
200 | 192 | #endif
|
201 |
| - if (::feof(stdin)) { |
202 |
| - const bool bForceExit = true; |
203 |
| - CMIDriver::Instance().SetExitApplicationFlag(bForceExit); |
204 |
| - } else if (::ferror(stdin) != 0) |
205 |
| - vwErrMsg = ::strerror(errno); |
| 193 | + const bool bForceExit = true; |
| 194 | + CMIDriver::Instance().SetExitApplicationFlag(bForceExit); |
| 195 | + } else if (std::cin.fail()) { |
| 196 | + vwErrMsg = ::strerror(errno); |
206 | 197 | return nullptr;
|
207 | 198 | }
|
208 | 199 |
|
209 |
| - // Strip off new line characters |
210 |
| - for (char *pI = m_pCmdBuffer; *pI != '\0'; pI++) { |
211 |
| - if ((*pI == '\n') || (*pI == '\r')) { |
212 |
| - *pI = '\0'; |
213 |
| - break; |
214 |
| - } |
215 |
| - } |
216 |
| - |
217 |
| - return pText; |
| 200 | + return m_pCmdString.c_str(); |
218 | 201 | }
|
0 commit comments