hey.... i fixed most of the changes.... here is the latest code
the spelling thing was a humongous mistake... i fixed it up.... "cleaned up" the code a little bit.... however the thing still does not work! (check my previous post for exactly where)
Code:
#!/usr/bin/env perl
use strict;
#use warnings;
open IN_FILE, "<", "ctags_output.proc";
open LOG_STD, "+>", "parseCTAGS.log";
my @lines = <IN_FILE>;
close(IN_FILE);
my $projectFolder = $ARGV[0];
my %project;
#Process CTAGS file
for my $i (@lines) {
#Process package names
if ( $i =~ /([a-zA-Z0-9:]*)\s+package\s+([\d]*)\s+([a-zA-z\/.0-9]*)\s+package\s+([.]*)/ )
{
my $packageName = $1;
my $lineNo = $2;
my $fileName = $3;
my $parent = "";
my $count = 0;
print LOG_STD "Got package $packageName @ $lineNo in $fileName\n";
for my $key ( keys %project ) {
if ( $packageName =~ /^$key/ ) {
if ( length($parent) < length($key) ) {
$parent = $key;
}
}
}
print LOG_STD "Found parent of $packageName -> $parent\n";
unless ( $project{$packageName} ) {
$project{$packageName} = {
'path' => "$fileName",
'lineNo' => "$lineNo",
'super' => "$parent",
'subrountines' => ()
};
}
next;
}
#Process Function names
if ( $i =~ /([a-zA-Z0-9:_]*)\s+subroutine\s+([\d]*)\s+([a-zA-z\/.0-9]*)\s+sub\s+([.]*)/ )
{
my $subName = $1;
my $lineNo = $2;
my $fileName = $3;
for my $key ( keys %project ) {
if ( $fileName eq $project{$key}{'path'} ) {
print LOG_STD
"Got subroutine $subName of $key @ $lineNo in $fileName\n";
my %sub = ( 'name', "$subName", 'nu', "$lineNo" );
push( @{ $project{$key}{'subroutines'} }, \%sub );
#use Data::Dumper;
#print "func[$subName, $lineNo, $key, $fileName] -->\n";
#print Dumper(@{$project{$key}{'subroutines'}});
#print "\n\n\n";
}
}
}
}
#Write output to XML file
open OUT_FILE, "+>", "project_parsed.xml";
use XML::DOM;
my $doc = XML::DOM::Document->new();
my $decl = $doc->createXMLDecl('1.0');
print OUT_FILE $decl->toString;
my $xml = $doc->createElement("project");
for my $i ( keys %project ) {
#Write package details
my $package = $doc->createElement("package");
$package->setAttribute( 'name', $i );
$package->setAttribute( 'path', $project{$i}{'path'} );
$package->setAttribute( 'lineNo', $project{$i}{'lineNo'} );
open PERL_FILE, "<", "$projectFolder/$project{$i}{'path'}";
my @file = <PERL_FILE>;
#Write uses
for my $line (@file) {
if ( $line =~ /^use\s+([A-Za-z0-9:]*)[.]*;/ ) {
print LOG_STD "\tUsing $1 in $i\n";
my $calls = $doc->createElement("calls");
$calls->setAttribute( "name", $1 );
$package->appendChild($calls);
}
}
close(PERL_FILE);
#Write subroutines
foreach ( @{ $project{$i}{'subroutines'} } ) {
my $subroutine = $doc->createElement("subroutine");
use Data::Dumper;
print "$_---->";
print Dumper($_);
print "$_{'name'},$_{'nu'}\n";
$subroutine->setAttribute( 'name', $_{'name'} );
$subroutine->setAttribute( 'lineNo', $_{'nu'} );
$package->appendChild($subroutine);
}
$xml->appendChild($package);
}
print OUT_FILE $xml->toString;
close OUT_FILE;
close LOG_STD;
Bookmarks