From d7672c3ffe8f62467f1bb130a6efa050c7fdf338 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Tue, 20 Jan 2015 09:35:31 +0000 Subject: [PATCH] [0.3.x] fixed: run script without .py extension git-svn-id: https://pykd.svn.codeplex.com/svn@89655 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/windbgext.cpp | 25 +++++++++++++------------ pykd/windbgext.h | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pykd/windbgext.cpp b/pykd/windbgext.cpp index b11c996..dc0a917 100644 --- a/pykd/windbgext.cpp +++ b/pykd/windbgext.cpp @@ -117,7 +117,7 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py) std::string scriptFileName; if ( args.size() > 0 ) { - scriptFileName = getScriptFileName( args[0] ); + scriptFileName = getScriptFileName( args[0] ); if ( scriptFileName.empty() ) { @@ -247,16 +247,18 @@ void PykdExt::printUsage() std::string PykdExt::getScriptFileName( const std::string &scriptName ) { - bool fileHasPyExt = false; + std::string scriptFileName = findScript( scriptName ); - if ( scriptName.length() > 3 ) - fileHasPyExt = scriptName.rfind(".py") == scriptName.length() - 3; - - std::string fullFileName = scriptName; + if ( scriptFileName.empty() && (scriptName.rfind(".py") != scriptName.length() - 3) ) + scriptFileName = findScript( scriptName + ".py" ); - if (!fileHasPyExt) - fullFileName += ".py"; - + return scriptFileName; +} + +/////////////////////////////////////////////////////////////////////////////// + +std::string PykdExt::findScript( const std::string &fullFileName ) +{ if ( GetFileAttributesA(fullFileName.c_str()) != INVALID_FILE_ATTRIBUTES ) return fullFileName; @@ -287,10 +289,9 @@ std::string PykdExt::getScriptFileName( const std::string &scriptName ) if (bufSize > 0) { - fullFileName = std::string(&fullFileNameCStr[0]); - return fullFileName; + return std::string(&fullFileNameCStr[0]); } - } + } } return ""; diff --git a/pykd/windbgext.h b/pykd/windbgext.h index 876f279..68d60ee 100644 --- a/pykd/windbgext.h +++ b/pykd/windbgext.h @@ -25,6 +25,7 @@ private: virtual void tearDown(); std::string getScriptFileName( const std::string &scriptName ); + std::string findScript( const std::string &fullFileName ); std::vector m_paths;