you asked for it!!
i am using this code to process the output of exuberant ctags to get a basic layout of the code in xml.... the implementation of the thing to output is not coming!
the input file can be obtained by just going into a perl project folder and typing
Code:
ctags -R -x * > ctags_ouput.proc
here is the actual perl code
Code:
#!/usr/bin/env perl
#read perl codes easily
use strict;
open IN_FILE, "<", "ctags_output.proc";
my @lines = <IN_FILE>;
close(IN_FILE);
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 STDOUT "Got package $packageName @ $lineNo in $fileName\n";
for my $key (keys %project)
{
if($packageName =~ /^$key/)
{
if(length($parent)<length($key))
{
$parent = $key;
}
}
}
print STDOUT "Found parent of $packageName -> $parent\n";
if(exists $project{$packageName})
{}
else
{
$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 STDOUT "Got subroutine $subName of $key @ $lineNo in $fileName\n";
my %sub = {'name'=>"$subName",'nu'=>"$lineNo"};
push($project{$key}{'subroutines'},{%sub});
}
}
}
}
#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)
{
my $package = $doc->createElement("package");
$package->setAttribute('name',$i);
$package->setAttribute('path',$project{$i}{'path'});
$package->setAttribute('lineNo',$project{$i}{'lineNo'});
my $len = scalar @{$project{$i}{'subroutines'}};
for(my $j=0;$j<$len;$j++)
{
my $subroutine = $doc->createElement("subroutine");
print STDOUT $project{$i}{'subroutine'}[$j]{'name'};
$subroutine->setAttribute('name',$project{$i}{'subroutine'}[$j]{'name'});
$subroutine->setAttribute('lineNo',$project{$i}{'subroutine'}[$j]{'nu'});
$package->appendChild($subroutine);
}
$xml->appendChild($package);
}
print OUT_FILE $xml->toString;
close OUT_FILE;
if(!($ARGV[0] eq 'silent'))
{
print map { "$_ =>\n\tpath=$project{$_}{'path'}\n\tlineNo=$project{$_}{'lineNo'}\n\tsuper=$project{$_}{'super'}\n\tsubroutines=join('',$project{$_}{'subroutines'})\n\n\n" } keys %project;
}
edit:
i forgot to mention that the error is in and around line 62
Bookmarks