Usage: CD " " CD ".." Note: Subdirectory MUST be quoted with double quotes. ===========================================================================
| 4416 | // Note: Subdirectory MUST be quoted with double quotes. |
| 4417 | //=========================================================================== |
| 4418 | Update_t CmdConfigSetDebugDir (int nArgs) |
| 4419 | { |
| 4420 | if ( nArgs > 1 ) |
| 4421 | return Help_Arg_1( CMD_CONFIG_SET_DEBUG_DIR ); |
| 4422 | |
| 4423 | if ( nArgs == 0 ) |
| 4424 | return CmdConfigGetDebugDir(0); |
| 4425 | |
| 4426 | // http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx |
| 4427 | |
| 4428 | // TODO: Support paths prefixed with "\\?\" (for long/unicode pathnames) |
| 4429 | if (strncmp("\\\\?\\", g_aArgs[1].sArg, 4) == 0) |
| 4430 | return Help_Arg_1( CMD_CONFIG_SET_DEBUG_DIR ); |
| 4431 | |
| 4432 | std::string sPath; |
| 4433 | |
| 4434 | if (g_aArgs[1].sArg[1] == ':') // Absolute |
| 4435 | { |
| 4436 | sPath = g_aArgs[1].sArg; |
| 4437 | } |
| 4438 | else if (g_aArgs[1].sArg[0] == PATH_SEPARATOR) // Absolute |
| 4439 | { |
| 4440 | if (g_sCurrentDir[1] == ':') |
| 4441 | { |
| 4442 | sPath = g_sCurrentDir.substr(0, 2) + g_aArgs[1].sArg; // Prefix with drive letter & colon |
| 4443 | } |
| 4444 | else |
| 4445 | { |
| 4446 | sPath = g_aArgs[1].sArg; |
| 4447 | } |
| 4448 | } |
| 4449 | else // Relative |
| 4450 | { |
| 4451 | std::string SAME_DIR( "." ); SAME_DIR += PATH_SEPARATOR; |
| 4452 | std::string UP_DIR ( ".."); UP_DIR += PATH_SEPARATOR; |
| 4453 | std::string sNewPath( g_aArgs[1].sArg ); |
| 4454 | |
| 4455 | // if new path doesn't have a trailing slash, append one |
| 4456 | if (*(sNewPath.rbegin()) != PATH_SEPARATOR) |
| 4457 | sNewPath += PATH_SEPARATOR; |
| 4458 | |
| 4459 | // Support ".." and various permutations |
| 4460 | // cd "..\" |
| 4461 | // cd "abc\..\def\" |
| 4462 | // |
| 4463 | // 1. find next slash in newpath |
| 4464 | // 2. subdir = newpath.substr() |
| 4465 | // 3. if subdir == "..\" |
| 4466 | // reverse find slash in g_sCurrentDir |
| 4467 | // g_sCurrentDir = g_sCurrentDir.substr() |
| 4468 | // else |
| 4469 | // g_sCurrentDir += subdir |
| 4470 | size_t iPrevSeparator = 0; |
| 4471 | size_t iPathSeparator = 0; |
| 4472 | |
| 4473 | while ((iPathSeparator = sNewPath.find( PATH_SEPARATOR, iPrevSeparator )) != std::string::npos) |
| 4474 | { |
| 4475 | #if _DEBUG |
nothing calls this directly
no test coverage detected