Makefile-Update
view release on metacpan or search on metacpan
lib/Makefile/Update/VCProj.pm view on Meta::CPAN
package Makefile::Update::VCProj;
# ABSTRACT: Update list of sources and headers in Visual C++ projects.
use Exporter qw(import);
our @EXPORT = qw(update_vcproj);
use strict;
use warnings;
our $VERSION = '0.4'; # VERSION
sub update_vcproj
{
my ($in, $out, $sources, $headers, $filter_cb) = @_;
# Use standard/default classifier for the files if none is explicitly
# specified.
if (!defined $filter_cb) {
$filter_cb = sub {
my ($file) = @_;
return 'Source Files' if $file =~ q{\.c(c|pp|xx|\+\+)?$};
return 'Header Files' if $file =~ q{\.h(h|pp|xx|\+\+)?$};
warn qq{No filter defined for the file "$file".\n};
undef
}
}
# Hash mapping the filter to all the files using it (whether sources or
# headers).
my %files_by_filter;
foreach my $file (@$sources, @$headers) {
my $filter = $filter_cb->($file);
if (defined $filter) {
push @{$files_by_filter{$filter}}, $file
}
}
# Name of the current filter, if any.
my $filter;
# Hash containing 0 or 1 for each file using the current filter.
my %seen;
# Indicates whether the closing angle bracket of "<File>" tags is on its
# own line (which is how MSVS 2005 and 2008 format their files) or on the
# same line as "RelativePath" attribute (which is how MSVS 2003 does it).
my $angle_bracket_on_same_line = 0;
# Set to 1 if we made any changes.
my $changed = 0;
while (defined (my $line_with_eol = <$in>)) {
(my $line = $line_with_eol) =~ s/\r?\n$//;
if ($line =~ /^\s*<Filter$/) {
if (defined($filter)) {
warn qq{Nested <Filter> tag at line $. while parsing filter } .
qq{"$filter" is not supported.\n};
next;
}
print $out $line_with_eol;
$line_with_eol = <$in>;
if (defined $line_with_eol &&
$line_with_eol =~ /^\s*Name="(.*)"\r?\n$/) {
$filter = $1;
if (!exists $files_by_filter{$filter}) {
# If we don't have any files for this filter, don't remove
# all the files from it, just skip it entirely instead.
( run in 1.103 second using v1.01-cache-2.11-cpan-39bf76dae61 )