#!/usr/bin/perl use strict; my $rootname ='Components'; open(KOMPO,">components.xml") || die "Can't open components.xml\n"; my $id=0; my $indentstr=' '; my $indent=0; print KOMPO << "EOH"; ${indentstr} EOH $id++; $indent += 2; my $lastdeepth = 0; open(COMPOFIND,"find . -name '*.cd' |"); my @oldpackagepath = (); while() { chop; my $compofile = $_; s:^./::; s:/component\.cd$::; s/.cd$//; my @packagepath = split(/\//); $"='::'; print "@packagepath\n"; my $name = pop(@packagepath); my $tiefe = $#packagepath + 1; print "@packagepath - $name\n"; my $oldtiefe = $#oldpackagepath+1 ; my $gemtiefe = ($tiefe > $oldtiefe ? $oldtiefe : $tiefe); # gemeinsames prefix my $pc=0; while($pc < $gemtiefe && $packagepath[$pc] eq $oldpackagepath[$pc]) { $pc++; } my $i=$oldtiefe; while($i > $pc) { $indent--; $i--; print KOMPO $indentstr x $indent . "\n"; } while($i<$tiefe) { print KOMPO $indentstr x $indent . "\n"; $indent++; $id++; $i++; } my $compohead=''; my $oldport = ''; my $port = ''; if(open(CD,"< $compofile")) { print STDERR "Component Description found \n"; while() { next if(/^\s*$/); if(/name\s+(\S+)/) { $name = $1; next; } if(!/name/ && !$compohead) { print KOMPO $indentstr x $indent . "\n"; $indent++; $id++; $compohead = "found"; } if(/port\s+(\S+)\s+(\S+)\s+(\S+)/) { $port = $1; my $reqprov = $2; my $inter=$3; #print "Port $port oldport=$oldport\n"; if($port ne $oldport) { if($oldport) { $indent--; print KOMPO $indentstr x $indent . "\n"; } print KOMPO $indentstr x $indent . "\n"; $id++; $indent++; } $oldport=$port; if($reqprov =~ /^require/) { #print "require $inter\n"; print KOMPO $indentstr x $indent . "\n"; $id++; } elsif($reqprov =~ /^provide/) { #print "provide $inter\n"; print KOMPO $indentstr x $indent . "\n"; $id++; } else { print STDERR "Error in $compofile: Keyword $reqprov not valid (require/provide expected)\n"; } } } if($port) { $indent--; print KOMPO $indentstr x $indent . "\n"; } $indent--; print KOMPO $indentstr x $indent . "\n"; } @oldpackagepath = @packagepath; } my $i=$#oldpackagepath+1; while($i > 0) { $i--; $indent--; print KOMPO $indentstr x $indent . "\n"; } close(COMPOFIND); print KOMPO << "END"; END