Click here to Skip to main content
12,633,985 members (22,008 online)
Click here to Skip to main content

Stats

198.5K views
1.6K downloads
53 bookmarked
Posted

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

, , 29 Jan 2009 CPOL
Utility to run PC-Lint on Visual C++ solutions and projects, generating XML and HTML reports of the results.
/************************************************************************
 *
 *  Description : CVc7SolutionFileReaderImpl - implementation class to parse
 *                Visual C++ solution files for Visual Studio .NET 2002 onwards.
 *
 *     (c) Copyright 2000-2008 by Anna-Jayne Metcalfe (anna@riverblade.co.uk)
 *     and Beth Mackenzie (beth@riverblade.co.uk) / Riverblade Limited
 *
 *  Licence Terms:
 *
 *     This code may be freely reused, subject to the licence terms below.
 *     Please do let us know of any bugs you find or improvements you make,
 *     so that we can pass them on to the rest of the development community.
 *
 *     This code is free software; you can redistribute it and/or
 *     modify it under the terms of the Code Project Open License (CPOL)
 *     version 1.0 (http://www.codeproject.com/info/cpol10.aspx).
 *
 *     This code is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     Code Project Open Licence for further details.
 *
 ************************************************************************
 *    $Archive: /Projects/Applications/LintProject/Development/Shared/Vs7SolutionFileReaderImpl.h $
 *   $Revision: 3 $
 *       $Date: 22/02/08 20:58 $
 *     $Author: Anna $
 * 
 * $Nokeywords: $
 ************************************************************************/

/// \file	
/// \brief Implementation class for CSolutionFileReader.

#pragma once

#include "SolutionFileReaderImpl.h"



namespace Riverblade
{
	namespace Libraries
	{
		namespace AddInSolutionModel
		{
			/// \brief Implementation class which parses solution files for Visual Studio .NET 2002 onwards.
			///
			class CVs7SolutionFileReaderImpl : public CSolutionFileReaderImpl
			{
				public:
					/// \brief Default constructor.
					///
					CVs7SolutionFileReaderImpl(void)
						:	CSolutionFileReaderImpl(),
							m_mapProjectGUIDs(),
							m_bParsingSolutionConfigurations(false),
							m_bParsingProjectConfigurations(false)
					{
					}


					/// \brief Class destructor.
					///
					virtual ~CVs7SolutionFileReaderImpl(void)
					{
					}
					
					
					/// \brief Parse the given text from the solution file.
					///
					/// \param	arrayLines		An array containing the text from the file.
					/// \return					\em true if the text was parsed correctly; \em false otherwise.
					///
					virtual bool Parse(const CAtlArray<CString>& arrayLines)
					{
						for (size_t uLine = 0; uLine < arrayLines.GetCount(); uLine++)
						{
							const CString sLine = arrayLines[uLine];

							// e.g. Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ResOrgAddIn", "ResOrgAddIn\ResOrgAddIn.vcproj", "{C1385D10-8039-4095-80DF-0D1F9B3EAAC5}"
							if (sLine.Find( _T("Project(") ) == 0)
							{
								ATLVERIFY(ParseProject(sLine) );
							}
							else if ( (sLine.Find( _T("GlobalSection(SolutionConfiguration)") ) >= 0) ||
									  (sLine.Find( _T("GlobalSection(SolutionConfigurationPlatforms)") ) >= 0) )
							{
								m_bParsingSolutionConfigurations = true;
							}
							else if (sLine.Find( _T("EndGlobalSection") ) >= 0)
							{
								m_bParsingSolutionConfigurations = false;
								m_bParsingProjectConfigurations = false;
							}
							else if ( (sLine.Find( _T("GlobalSection(ProjectConfiguration)") ) >= 0) ||
									  (sLine.Find( _T("GlobalSection(ProjectConfigurationPlatforms)") ) >= 0) )
							{
								m_bParsingProjectConfigurations = true;
							}
							else if (m_bParsingSolutionConfigurations)
							{
								ATLVERIFY(ParseSolutionConfiguration(sLine) );
							}
							else if (m_bParsingProjectConfigurations)
							{
								ATLVERIFY(ParseProjectConfiguration(sLine) );
							}
						}
						return true;
					}


				// Implementation
				private:
					/// \brief Parse the given line, extracting any project definition information.
					///
					/// \param	sLine			A string containing the line to parse.
					/// \return					\em true if the text was parsed correctly; \em false otherwise.
					///
					bool ParseProject(const CString& sLine)
					{
						CString sProject = Utils::Between(sLine, _T("="), _T(",") );

						if (!sProject.IsEmpty() )
						{
							CString sRemnant = Utils::After(sLine, sProject);

							sProject.Trim( _T(" \"") );

							CSolutionFileReaderProjectImpl project;
							project.m_sProject		= sProject;

							sRemnant.TrimLeft( _T(", \"") );

							CString sRelativePath = Utils::Before(sRemnant, _T(",") );
							sRelativePath.Trim( _T("\" ") );

							project.m_sGUID = Utils::After(sRemnant, _T(",") );;
							project.m_sGUID.Trim( _T(" ") );
							project.m_sGUID.Trim( _T("\"") );

							// If the project path includes an extension, it is a real project.
							// Otherwise, it could be "Solution Items" or a solution folder [Anna 30.11.2007].
							if (!Utils::CSplitPath(sRelativePath).GetExtension().IsEmpty() )
							{
								// Since the project pathname returned is relative,
								// we need to convert it to a fully qualified pathname
								Utils::CSplitPath split(m_sPathName);
								project.m_sPathName = Utils::CombinePath(split.GetDrive() + split.GetDirectory(), sRelativePath);
							}

							if (!project.m_sPathName.IsEmpty() )
							{
								// If the project is a "real" one (i.e. not a solution folder or suchlike)
								// store its pathname
								m_arrayProjectFilePathNames.Add(project.m_sPathName);
							}

							m_mapProjectGUIDs[project.m_sGUID]	= sProject;
							m_mapProjects[sProject]				= project;

							return true;
						}
						return false;
					}


					/// \brief Parse the given solution configuration.
					///
					/// \param	sLine		A string containing the text to parse.
					/// \return				\em true if the configuration was parsed successfully; false otherwise.
					///
					bool ParseSolutionConfiguration(const CString& sLine)
					{
						CString sTemp = sLine;
						sTemp.Replace( _T("\t"), _T(" ") );		// Strip tabs

						// e.g.  Unicode Debug = Unicode Debug
						CString sSolutionConfig = Utils::Before(sTemp, _T("=") );

						sSolutionConfig.Trim( _T(" ") );

						(void)m_arraySolutionConfigs.Add(sSolutionConfig);

						return true;
					}


					/// \brief Parse the given project configuration.
					///
					/// \param	sLine		A string containing the text to parse.
					/// \return				\em true if the configuration was parsed successfully; false otherwise.
					///
					bool ParseProjectConfiguration(const CString& sLine)
					{
						// e.g. {5EED9388-7FFD-43BA-A64F-51AA92B649D5}.Unicode Debug.ActiveCfg = Unicode Debug|Win32
						if (sLine.Find( _T(".ActiveCfg") ) > 0)
						{
							CString sTemp = sLine;
							sTemp.Replace( _T("\t"), _T(" ") );		// Strip tabs

							CString sProjectGUID	= Utils::Chomp(sTemp, _T(".") );
							CString sSolutionConfig	= Utils::Chomp(sTemp, _T(".") );
							CString sProjectConfig	= Utils::After(sTemp, _T("=") );

							sProjectGUID.Trim( _T(" ") );
							sSolutionConfig.Trim( _T(" ") );
							sProjectConfig.Trim( _T(" ") );

							CString sProjectName;
							(void)m_mapProjectGUIDs.Lookup(sProjectGUID, sProjectName);
							ATLASSERT(!sProjectName.IsEmpty() );

							CSolutionFileReaderProjectImpl info;
							(void)m_mapProjects.Lookup(sProjectName, info);
							ATLASSERT(info.m_sProject == sProjectName);

							info.AddConfiguration(sSolutionConfig, sProjectConfig);
							m_mapProjects[sProjectName]	= info;
						}
						return true;
					}


				// Data members
				private:
					CAtlMap<CString, CString>	m_mapProjectGUIDs;					///< Maps project GUID to name.
					bool						m_bParsingSolutionConfigurations;	///< \em true if we are currently parsing solution configurations.
					bool						m_bParsingProjectConfigurations;	///< \em true if we are currently parsing project configurations.
			};


		};	// namespace AddInSolutionModel
	};	// 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)

Share

About the Authors

Anna-Jayne Metcalfe
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!

-+- Beth Mackenzie -+-
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.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 29 Jan 2009
Article Copyright 2004 by Anna-Jayne Metcalfe, -+- Beth Mackenzie -+-
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid