Click here to Skip to main content
15,893,381 members
Articles / Desktop Programming / MFC

LintProject - Improving the Usability of PC-Lint with Visual C++ Solutions and Projects

,
Rate me:
Please Sign up or sign in to vote.
4.83/5 (36 votes)
29 Jan 2009CPOL13 min read 281K   1.7K   52  
Utility to run PC-Lint on Visual C++ solutions and projects, generating XML and HTML reports of the results.
//////////////////////////////////////////////////////////////////////
// SplitPath.cpp : implementation of the CSplitPath class.          //
// (c) 1999, Kevin Lussier                                          //
//////////////////////////////////////////////////////////////////////

/// \file	
/// \brief CSplitPath implementation

#include "StdAfx.h"

#include "SplitPath.h"



namespace Riverblade
{
	namespace Libraries
	{
		namespace Utils
		{

////////////////////////////////////////////////////////////////////////////////
// CSplitPath

/// \brief Main constructor.
///
/// \param	lpszPath		A pointer to a NULL terminated string holding the pathname to split
///
CSplitPath::CSplitPath(LPCTSTR const lpszPath)
{
    // Initialize our objects
	::memset( szComputer, 0, sizeof( szComputer ) );
    ::memset( szPath, 0, sizeof( szPath ) );
    ::memset( szDrive, 0, sizeof( szDrive ) );
    ::memset( szDir, 0, sizeof( szDir ) );
    ::memset( szFilename, 0, sizeof( szFilename ) );
    ::memset( szExtension, 0, sizeof( szExtension ) );

    // If we were given a path, split it
    if (NULL != lpszPath)
	{
        ATLVERIFY(Split(lpszPath) );
    }
}


/// \brief Class destructor.
///
CSplitPath::~CSplitPath(void)
{
}


/// \brief Split the given pathname.
///
/// \param	lpszPath		A pointer to a NULL terminated string holding the pathname to split
/// \return					\em TRUE if the path was split successfully; \em FALSE otherwise.
///
bool CSplitPath::Split(LPCTSTR const lpszPath)
{
    // If we weren't given a path, fail
    if (NULL == lpszPath)
	{
        // Return failure
        return false;
    }

#if (_MSC_VER >= 1400)
	// VS2005 or later
	::_tcsncpy_s(szPath, _MAX_PATH, lpszPath, ::_tcslen(lpszPath) );

	// Split the given path
	::_tsplitpath_s(szPath,
					szDrive,
					_MAX_DRIVE,
					szDir,
					_MAX_DIR,
					szFilename,
					_MAX_FNAME,
					szExtension,
					_MAX_EXT);
#else
	// VS2003

	// Copy the path
	(void)::_tcsncpy( szPath, lpszPath, sizeof(szPath) - 1);


	// Split the given path
	::_tsplitpath(szPath, szDrive, szDir, szFilename, szExtension);
#endif

	// If UNC name
	// PathIsUNC() suggested by coghlans@technologist.com on the LintProject CP forum [Anna 19.11.2004]
	if (::PathIsUNC(lpszPath) )
	{
#if (_MSC_VER >= 1400)
		// VS2005
		//
		// Get the computername
		(void)::_tcsncpy_s(szComputer, _MAX_FNAME, _tcsstr(szDir, _T("\\\\") ) + 2, _MAX_DIR - 1);
		TCHAR* pch = _tcsstr(szComputer, _T("\\") );
		if (NULL != pch)
		{
			*pch = '\0';
		}

		// Strip the computername from the directory
		(void)::_tcsncpy_s(szDir, _MAX_DIR, _tcsstr(szDir, _T("\\\\") ) + 2, _MAX_DIR - 1);
		(void)::_tcsncpy_s(szDir, _MAX_DIR, _tcsstr(szDir, _T("\\") ), _MAX_DIR - 1);
#else
		// VS2003
		//
		// Get the computername
		(void)::_tcsncpy(szComputer, _tcsstr(szDir, _T("\\\\") ) + 2, _MAX_FNAME - 1);
		(void)::_tcsnset(_tcsstr(szComputer, _T("\\") ), 0, 1);

		// Strip the computername from the directory
		(void)::_tcsncpy(szDir, _tcsstr(szDir, _T("\\\\") ) + 2, _MAX_DIR - 1);
		(void)::_tcsncpy(szDir, _tcsstr(szDir, _T("\\") ), _MAX_DIR -1);
#endif
	}
	return true;
}

		}	// namespace Utils
	}	// namespace Libraries
}	// namespace Riverblade

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.

One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.

I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:

I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!

Written By
Software Developer Riverblade Ltd
United Kingdom United Kingdom
I'm a software developer and/or tester with Riverblade Ltd (www.riverblade.co.uk) developing our core product range including our Visual Lint integration product and Lint Project Professional.

I incorporate a number of technologies into a daily basis including Windows API, C++ (VS2008), Managed C++, CLI, Databases, Java, JNI, Eclipse Framework, CDT and of course Visual Studio Extensibility (VSIP VSX).

In my spare time I enjoy cooking (prepping ingredients from scratch!), running, cycling, swimming, reading, interested in experimental electronic music (such as ClockDVA), movies, volunteering my IT skills where I can.

Comments and Discussions