#!/usr/local/bin/perl # dejavadoc.perl # fix braindead javadoc's endless names use HTML::Parse qw(parse_htmlfile); # HTML::Parse is from Internet/perl/CPAN/libwww-perl if ($#ARGV < 1) { print "usage: dejavadoc javadoc-folder dedoc-folder [-start subpath] \n"; exit(0); } $home= $ARGV[0]; $nuhome= $ARGV[1]; $here = `pwd`; chop($here); $home = "$here/$home" if ($home !~ m,^/,); $nuhome = "$here/$nuhome" if ($nuhome !~ m,^/,); if ($ARGV[2] eq "-start" ) { $startpath= $ARGV[3]; } if ($ARGV[2] eq "-listdir" ) { $listdir = 1; } if ($listdir) { listDir( "", $nuhome); exit(); } if (! $startpath) { opendir(DIR, $home); while ($f= readdir(DIR)) { moveDocs( $f, $home, $nuhome); } closedir(DIR); } editDir( "", $nuhome); exit(); ########### sub listDir { local($path,$home)= @_; print "listDir $path\n"; opendir(DIR1, "$home/$path"); local(@all) = readdir(DIR1); closedir(DIR1); foreach $f (@all) { next if ($f =~ /^\./); $pf= "$home/$path/$f"; if ($startpath ne "") { $startpath= "" if ($pf =~ /$startpath/); } $f= "$path/$f" if ($path ne ""); listDir( $f, $home) if (-d $pf) ; } } sub editDir { local($path,$home)= @_; print "editDir $home/$path\n" if $debug; opendir(DIR1, "$home/$path"); local(@all) = readdir(DIR1); closedir(DIR1); foreach $f (@all) { next if ($f =~ /^\./); $pf= "$home/$path/$f"; if ($startpath ne "") { $startpath= "" if ($pf =~ /$startpath/); } else { editDocs( $f, $home, $path) if (-f $pf); } $f= "$path/$f" if ($path ne ""); editDir( $f, $home) if (-d $pf) ; } } sub moveDocs { local($f, $oldhome, $nuhome)= @_; local($echo)= "echo" if $debug; $_ = $f; if ( (tr/././ > 1) && (/\.html/i) ) { my $lastdot= rindex( $_, "."); my $lldot= 1 + rindex($_, ".", $lastdot-1); my $pathto= substr( $_, 0, $lldot); my $filen= substr( $_, $lldot); ($pathnu= $pathto) =~ tr|.|/|; my $filenu= $pathnu . $filen; system("$echo cd $nuhome;$echo mkdir -p $pathnu;$echo cp $oldhome/$f $filenu"); } } sub editDocs { local($f, $home, $subpath)= @_; $fpath= "$home/$subpath/$f"; print "editDocs $home .. $subpath/$f\n" if $debug; next if (! -f $fpath ); next if (! -w $fpath ); @subs= split('/',$subpath); $h = parse_htmlfile($fpath); next if ($h eq ''); next if ($h->is_empty()); print "Parsing $f\n"; my $fixed= 0; for (@{ $h->extract_links(qw(a)) }) { ($link, $linkelem) = @$_; print "link= $link\n" if $debug; $_= $link; if ( ($_ !~ m,^[/#],) && (tr/././ > 1) && (/\.html/i) ) { $lastdot= rindex( $_, "."); $lldot= 1 + rindex($_, ".", $lastdot-1); $pathto= substr( $_, 0, $lldot); $filen= substr( $_, $lldot); ($pathnu= $pathto) =~ tr|.|/|; @subn= split('/',$pathnu); my $j; my $n= $#subs; for ($j= 0; $j<=$n; $j++) { last if ($subs[$j] ne $subn[$j]); } my $k= $j; my $p= ""; for ($k= $j; $k<=$n; $k++) { $p .= "../"; } for ($k= $j; $k<=$#subn; $k++) { $p .= $subn[$k] . "/"; } $pathnu = $p; print " path=$pathnu file=$filen\n" if $debug; $linknu= $pathnu . $filen; $linkelem->attr('href', $linknu); $fixed= 1; } } if ($fixed) { $nufile= "$home/$subpath/$f"; open( NUFILE, ">$nufile") || die "can't write $nufile"; print NUFILE $h->as_HTML(); close(NUFILE); } } # h does =head2 $h = HTML::Element->new('tag', 'attrname' => 'value',...) =head2 $h->tag() =head2 $h->starttag() =head2 $h->endtag() =head2 $h->parent([$newparent]) =head2 $h->implicit([$bool]) =head2 $h->is_inside('tag',...) =head2 $h->pos() =head2 $h->attr('attr', [$value]) =head2 $h->content() =head2 $h->is_empty() =head2 $h->insert_element($element, $implicit) =head2 $h->push_content($element_or_text,...) =head2 $h->delete_content() =head2 $h->delete() =head2 $h->traverse(\&callback, [$ignoretext]) =head2 $h->extract_links([@wantedTypes]) =head2 $h->dump() =head2 $h->as_HTML() =cut