Parsing Visual Studio project files

A

Ann Ominous

Hi
I've got a Visual Studio workspace with 100 project files. I have to
document the compiler flags used in each project and would like to do
this in Perl.
There are several possible build configurations in the project files.
I'm only interested in the Win32 Release config. I want to read all the
CPP lines in the relevant config. I've not been able to extract the
relevant lines. I can get the starting line of each block, but am not
pushing the CPP flags into the array. I think my problem lies in using
next /last.
Here's my code and some data from one project.
TIA for any help.
-ao-


__CODE__
#!/usr/local/bin/perl -w

#use strict;

# open the Build All worksapce, read all the projects and print out the
# compiler flags used

$workspace = $ARGV[1];
$workspace = "BuildAll.dsw";


open ( BUILDALL, $workspace )
|| die "Cannot open $workspace: $!";

while( <BUILDALL> )
{
if ( /^Project.*=\"(.*)\"/ )
{
@words = split( /\"/, $_ );
$projects{ $words[1] } = $words[3];
$num_projects++;
}
}
close( BUILDALL )
|| die "Cannot close BuildAll\n";

print "Workspace $workspace has $num_projects projects\n\n";


# now go through each file and look for the "Win32 Release"
configuration

foreach $p (sort keys(%projects) )
{
print $p, "\t$projects{ $p }", "\n" ;
open( PROJECT, $projects{ $p } )
|| die "Cannot open project $p\n";

$done = 0;
#while( ! $done && <PROJECT> )
while( <PROJECT> )
{
#next if /^$/;
@cpp_flags = ();
#if( /(CFG).*Win32 Release/ )

if( /\(CFG\).*Win32 Release"$/ )
{
# once we get the correct config read until we get next IF block or
ENDIF
while( <PROJECT> )
{
#print "\t$_";

#cpp_flags = $_ if /CPP/;

if ( /CPP/ )
{
push( @cpp_flags, $_);
#$cpp_flags = $_;
#print $cpp_flags;
}

# quit when we get to next IF stagement
if ( /IF?/ )
{
$done = 1;
last;
}
#next;
}
}
$done && print "@cpp_flags";
}

close( PROJECT )
|| die "Cannot close project $p\n";
}



__DSPFILE_SYNTAX__

# Microsoft Developer Studio Project File - Name="MyProject" - Package
Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **

# TARGTYPE "Win32 (x86) Static Library" 0x0104

CFG=MyProject - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using
NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "MyProject.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "MyProject.mak" CFG="MyProject - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "MyProject - Win32 Release" (based on "Win32 (x86) Static
Library")
!MESSAGE "MyProject - Win32 Debug" (based on "Win32 (x86) Static
Library")
!MESSAGE

# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName "MyProject"
# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe

!IF "$(CFG)" == "MyProject - Win32 Release"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "MyProject___Win32_Release"
# PROP BASE Intermediate_Dir "MyProject___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../../R_NT"
# PROP Intermediate_Dir "R_NT"
# PROP Target_Dir ""
MTL=midl.exe
LINK32=link.exe
# ADD BASE CPP /nologo /MD /W3 /GX /Z7 /O2 /I "..\SDA" /I "..\\" /I
"..\..\..\..\ProjectB\dev" /D "WIN32" /D "_WINDOWS" /D "MyProject_LIB"
/D "_UNICODE" /YX /FD /c
# SUBTRACT BASE CPP /Fr
# ADD CPP /nologo /MD /W3 /GX /I "../" /I "../../" /I
"../../../../ProjectA/Includes/" /I "../SDA" /I "../MyProject" /D
"WIN32" /D "_WINDOWS" /D "MyProject_LIB" /D "UNICODE" /D "_UNICODE" /YX
/FD /c
# SUBTRACT CPP /Fr
# ADD BASE RSC /l 0x809
# ADD RSC /l 0x809
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo

!ELSEIF "$(CFG)" == "MyProject - Win32 Debug"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top