MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / CmdConfigSetDebugDir

Function CmdConfigSetDebugDir

source/Debugger/Debug.cpp:4418–4521  ·  view source on GitHub ↗

Usage: CD " " CD ".." Note: Subdirectory MUST be quoted with double quotes. ===========================================================================

Source from the content-addressed store, hash-verified

4416// Note: Subdirectory MUST be quoted with double quotes.
4417//===========================================================================
4418Update_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

Callers

nothing calls this directly

Calls 4

Help_Arg_1Function · 0.85
CmdConfigGetDebugDirFunction · 0.85
LogOutputFunction · 0.85
SetCurrentImageDirFunction · 0.85

Tested by

no test coverage detected