#!/usr/bin/perl use Getopt::Long; GetOptions('help' => \$opt{help}, 'tags' => \$opt{tags}, 'dest=s' => \$DestDIR , 'source=s' => \$SourceDIR ); help() if($opt{help} == 1); if($opt{tags}){ open(TAGS,$opt{tags}); @tags = ; close(TAGS); }else{ @tags = ; } chomp(@tags); foreach(@tags){ my($file,$line,$func) = split(/ +/,$_); $index{$file} ||= {}; $index{$file}->{$line} = $func; } foreach $source (keys %index){ $line = 0; mkdir(joinpath($DestDIR,$index{$source}->{$line})); open(OUT,">".joinpath($DestDIR,path2name($source),"SOURCE")); open(SOURCE,joinpath($SourceDIR,$source)); while(){ $line++; if($index{$source}->{$line}){ close(OUT); mkdir(joinpath($DestDIR,$index{$source}->{$line})); open(OUT,">".joinpath($DestDIR,$index{$source}->{$line},"SOURCE")); } print OUT $_; } close(OUT); close(SOURCE); } sub joinpath{ my($path); local($_); while(@_){ $_ = shift(@_); last if($_ !~ /^\/*$/); } $path = $_; foreach(@_){ next if($_ =~ /^\/*$/); if($path =~ /\/$/){ $path .= $_; }else{ $path .= "/$_"; } } return $path; } sub path2name{ my($path) = @_; $path =~ m/([^\/]*)$/s; return $1; } sub help{ print "$0 [--help]\n"; print " --help : Show this message\n"; exit(0); }