#!/usr/bin/perl #Usage: ./to-rtt-2.0.pl $strict=0; if ($strict) { $scope = "RTT::"; $scope_os = "RTT::OS::"; $scope_os2 = "RTT::os::"; }else{ $scope = ""; $scope_os = ""; $scope_os2 = ""; } # These are the non-ambiguous replaces, the ones requireing a regex ar found inline below %renames = ( $scope_os ."SingleThread" => $scope_os2 ."Thread", $scope_os ."PeriodicThread" => $scope_os2 ."Thread", $scope . "NonPeriodicActivity" => $scope . "Activity", "using namespace " . $scope . "OS" => "using namespace " . $scope . "os", "using namespace " . $scope . "Corba" => "using namespace " . $scope . "corba", $scope . "CommandInterface" => $scope . "ActionInterface", "Ports.hpp" => "Port.hpp", "Marshaller" => "MarshallInterface", "Demarshaller" => "DemarshallInterface", "marshalling\(\)->" => "getProvider(\"marshalling\")->", "scripting\(\)->" => "getProvider(\"scripting\")->", "Toolkit" => "TypekitRepository", "ToolkitPlugin" => "TypekitPlugin", "ORO_TOOLKIT_PLUGIN" => "ORO_TYPEKIT_PLUGIN", "ComponentLoader.hpp" => "Component.hpp" ); # Perl trim function to remove whitespace from the start and end of the string sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } my @files= @ARGV; # headers.txt is the output of: # find rtt/ -name "*.hpp" |grep -v boost | grep -v oro_ | grep -v fosi > headers.txt; echo -e "rtt/rtt-config.h\nrtt/transports/corba/rtt-corba-config.h\n">> headers.txt open(INFILE, " headers.txt; echo -e \"rtt/rtt-config.h\\nrtt/transports/corba/rtt-corba-config.h\\n\">> headers.txt'\n to generate it in the orocos-rtt main directory.\n"; open(CLASSFILE, "; my %headers = (); foreach(@rlines) { my $tmp = $_; my $file = $_; $tmp =~ s|rtt/(.*)\n|\1|; $file = $tmp; # fwd mapping: ($nspace,$class) = $tmp =~ /(.*\/)?(.*?)\.\w+$/; if ($nspace eq "") { $nspace = "rtt"; } $headers{$class} = $file; } #die; # Read scopes of classes @rlines = ; my %namespace = (); foreach(@rlines) { my $tmp = $_; ($nspace,$class) = $tmp =~ /^class (.*)\:\:(.*?)\n/; if ($nspace eq "rtt") { $nspace = "RTT"; } # store the classes found in this namespace into the hash. push( @{$namespace{$nspace}}, $class); } foreach( @files ) { my $filename=$_; open(INFILE, "<$filename") or die "can't open $filename: $!"; my @lines = ; my $line = ""; foreach( @lines ) { $line = "$line$_"; } # First do renames: $line =~ s|(\W)OS::|\1os::|g; $line =~ s|(\W)Corba::|\1corba::|g; $line =~ s|(\W)RTT::Corba(\W)|\1RTT::corba\2|g; $line =~ s|(\W)PeriodicActivity|\1Activity|g; while( my ($old,$new) = each(%renames) ) { if ($line =~ s|(\W)$old(\W)|\1$new\2|g ) { print "Replaced $old with $new\n"; } } # Rename includes while (my ($class,$include) = each(%headers) ) { if (! $class ) { next; } # Rewrite header locations if ($line =~ s|["<](.*?/)?$class\.hpp[">]||g) { #print "MATCH FOUND for rtt/$include !\n"; } } # Scope classes while (my ($nspace,@classes) = each(%namespace) ) { @classes = @{ $namespace{$nspace}}; # Adapt in this file each class in this namespace: foreach ( @classes ) { $class = $_; #print "Checking $class...\n"; # replace RTT::class with RTT::nspace::class if ( ! ($nspace eq "RTT") ) { $line =~ s|RTT\:\:$class(\W)|RTT\:\:$nspace\:\:$class\1|g; } # replace blah::class with nspace::class if ( $line =~ s|\w+\:\:$class(\W)|$nspace\:\:$class\1|g ) { #print "Found s|\w+\:\:$class(\W)|$nspace\:\:$class\1|g\n"; } # replace class with nspace::class. This may not be done when RTT is omitted. if ( ! ($nspace eq "RTT") ) { if ( $line =~ s|([^:\w])$class([^.\w])|\1$nspace\:\:$class\2|g ) { print "Found s|([^:\w])$class([^.\w])|\1$nspace\:\:$class\2|g\n"; } } # replace ::nspace::class with ::RTT::nspace::class (seldomly used) $line =~ s|(\W)\:\:$nspace\:\:$class(\W)|\1\:\:RTT\:\:$nspace\:\:$class\2|g; # remove forward declarations of RTT classes if ( $strict ) { $line =~ s|^\s*class $nspace\:\:$class;\n||gm; $line =~ s|^\s*(template\s*\<[\w,\s=]+\>\s*)?class $class;\n||gm; } } } open(OUTFILE, ">$filename") or die "can't open $filename: $!"; print "Writing $filename\n"; print OUTFILE $line; }