In some cases we need to pre-replace command line, for example, in cmd prompt: start -new_console:z
| 1294 | // In some cases we need to pre-replace command line, |
| 1295 | // for example, in cmd prompt: start -new_console:z |
| 1296 | bool CShellProc::PrepareNewConsoleInFile( |
| 1297 | const CmdOnCreateType aCmd, LPCWSTR& asFile, LPCWSTR& asParam, CEStr& lsReplaceFile, CEStr& lsReplaceParm, CEStr& exeName) |
| 1298 | { |
| 1299 | if (!asFile || !*asFile) |
| 1300 | return false; |
| 1301 | if ((wcsstr(asFile, L"-new_console") == nullptr) |
| 1302 | && (wcsstr(asFile, L"-cur_console") == nullptr)) |
| 1303 | return false; |
| 1304 | |
| 1305 | bool isNewConsoleArg = false; |
| 1306 | // To be sure, it's our "-new_console" or "-cur_console" switch, |
| 1307 | // but not a something else... |
| 1308 | RConStartArgs lTestArg; |
| 1309 | lTestArg.pszSpecialCmd = lstrdup(asFile).Detach(); |
| 1310 | if (lTestArg.ProcessNewConArg() > 0) |
| 1311 | { |
| 1312 | // pszSpecialCmd is supposed to be empty now, because asFile can contain only one "token" |
| 1313 | _ASSERTE(lTestArg.pszSpecialCmd == nullptr || *lTestArg.pszSpecialCmd == 0); |
| 1314 | lsReplaceParm = CEStr(asFile, (asFile && *asFile && asParam && *asParam) ? L" " : nullptr, asParam); |
| 1315 | _ASSERTE(!lsReplaceParm.IsEmpty()); |
| 1316 | if (gbIsCmdProcess |
| 1317 | && !GetStartingExeName(nullptr, lsReplaceParm, exeName) |
| 1318 | ) |
| 1319 | { |
| 1320 | // when just "start" is executed from "cmd.exe" - it starts itself in the new console |
| 1321 | CEStr lsTempCmd; |
| 1322 | if (GetModulePathName(nullptr, lsTempCmd)) |
| 1323 | { |
| 1324 | exeName.Set(PointToName(lsTempCmd)); |
| 1325 | // It's supposed to be "cmd.exe", so there must not be spaces in file name |
| 1326 | _ASSERTE(!wcschr(exeName, L' ')); |
| 1327 | // Insert "cmd.exe " before "-new_console" switches for clearness |
| 1328 | if (aCmd == eCreateProcess) |
| 1329 | { |
| 1330 | lsReplaceParm = CEStr(exeName, L" ", lsReplaceParm); |
| 1331 | } |
| 1332 | } |
| 1333 | } |
| 1334 | if (!exeName.IsEmpty()) |
| 1335 | { |
| 1336 | lsReplaceFile.Set(exeName.ms_Val); |
| 1337 | asFile = lsReplaceFile.ms_Val; |
| 1338 | } |
| 1339 | isNewConsoleArg = true; |
| 1340 | asParam = lsReplaceParm.ms_Val; |
| 1341 | } |
| 1342 | |
| 1343 | return isNewConsoleArg; |
| 1344 | } |
| 1345 | |
| 1346 | bool CShellProc::CheckForDefaultTerminal(const CmdOnCreateType aCmd, LPCWSTR asAction, const DWORD* anShellFlags, |
| 1347 | const DWORD* anCreateFlags, const DWORD* anShowCmd) |
nothing calls this directly
no test coverage detected