1*cdf0e10cSrcweir# 2*cdf0e10cSrcweir# convertlinks - a perl script to make hrefs to 3*cdf0e10cSrcweir# http://api.openoffice.org/common/ref relativ. 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir 8*cdf0e10cSrcweiruse File::Find; 9*cdf0e10cSrcweir 10*cdf0e10cSrcweir# for the convenience of &wanted calls, including -eval statements: 11*cdf0e10cSrcweiruse vars qw/*name *dir/; 12*cdf0e10cSrcweir*name = *File::Find::name; 13*cdf0e10cSrcweir*dir = *File::Find::dir; 14*cdf0e10cSrcweir@files = (); 15*cdf0e10cSrcweir 16*cdf0e10cSrcweirif($#ARGV == 1) 17*cdf0e10cSrcweir{ 18*cdf0e10cSrcweir $pattern = "www"; 19*cdf0e10cSrcweir} else 20*cdf0e10cSrcweir{ 21*cdf0e10cSrcweir $pattern = $ARGV[2]; 22*cdf0e10cSrcweir} 23*cdf0e10cSrcweir 24*cdf0e10cSrcweirfind(\&wanted, "$ARGV[0]"); 25*cdf0e10cSrcweir 26*cdf0e10cSrcweir$return = 1; 27*cdf0e10cSrcweir 28*cdf0e10cSrcweirforeach $i (@files) 29*cdf0e10cSrcweir{ 30*cdf0e10cSrcweir next if( $i->{directory} =~ /.*common((\/|\\)ref(.*))/ || 31*cdf0e10cSrcweir $i->{directory} =~ /.*cpp((\/|\\)ref(.*))/ || 32*cdf0e10cSrcweir $i->{directory} =~ /.*java((\/|\\)ref(.*))/ ); 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir open ( FILEIN, $i->{filename} ) || die "could not open $i->{filename} for reading"; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir $relPath = "."; 37*cdf0e10cSrcweir $relToSource = "."; 38*cdf0e10cSrcweir if( $i->{directory} =~ /.*$pattern((\/|\\)(.*))/ ) 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir $relPath = $3; 41*cdf0e10cSrcweir $relPath =~ s#\w+#\.\.#go; 42*cdf0e10cSrcweir if($pattern eq "examples") 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir $relPath = "\.\.\/$relPath"; 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir if($pattern eq "www") 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir $relToSource = "\.\.\/$relPath"; 49*cdf0e10cSrcweir } else 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir $relToSource = $relPath; 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir } else 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir if($pattern eq "examples") 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir $relPath = "\.\."; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir if($pattern eq "www") 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir $relToSource = "\.\."; 62*cdf0e10cSrcweir } else 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir $relToSource = $relPath; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir @lines = <FILEIN>; 69*cdf0e10cSrcweir close( FILEIN ); 70*cdf0e10cSrcweir open( FILEOUT, ">$i->{filename}.tmp" ) || die "could not open $i->{filename} for writing"; 71*cdf0e10cSrcweir foreach $_ (@lines) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir # change the refenreces to the index in dependency of UDK or ODK 74*cdf0e10cSrcweir if("$ARGV[1]" eq "udk_" | "$ARGV[1]" eq "odk_") 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir s#((\")(index.html\"))#$2$ARGV[1]$3#go; 77*cdf0e10cSrcweir s#((\/|\")(faq.html\"))#$2$ARGV[1]$3#go; 78*cdf0e10cSrcweir s#((\/|\")(bylaws.html\"))#$2$ARGV[1]$3#go; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir s#((http:\/\/api\.openoffice\.org\/)(common\/ref[^\"]+))#$relPath\/$3#go; 82*cdf0e10cSrcweir s#((http:\/\/api\.openoffice\.org\/unbranded-source\/)(.*)(examples\/examples.html))#$relToSource\/$4#go; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir if($pattern eq "examples") 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir # change the links for the C++/Java examples in the ODK 87*cdf0e10cSrcweir s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(java\/*))#$3#go; 88*cdf0e10cSrcweir s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(cpp\/*))#$3#go; 89*cdf0e10cSrcweir s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(basic\/*))#$3#go; 90*cdf0e10cSrcweir s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(OLE\/*))#$3#go; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir # change link api specific stuff 93*cdf0e10cSrcweir s#((http:\/\/api\.openoffice\.org\/)(design_guide.html))#$relPath\/www\/$3#go; 94*cdf0e10cSrcweir s#(http:\/\/api\.openoffice\.org\/index.html)#$relPath\/www\/odk_index.html#go; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir # change the links for the C++ examples in the UDK 97*cdf0e10cSrcweir s#((http:\/\/udk\.openoffice\.org\/source\/browse\/udk\/product\/examples\/)(cpp\/*))#$3#go; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir # change the links to udk.openoffice.org to relativ links 100*cdf0e10cSrcweir s#(http:\/\/udk\.openoffice\.org\/index.html)#$relPath\/www\/udk_index.html#go; 101*cdf0e10cSrcweir s#((http:\/\/udk\.openoffice\.org)(\/*))#$relPath\/www$3#go; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir # change the link to tutorial 104*cdf0e10cSrcweir s#((http:\/\/api\.openoffice\.org\/)(basic\/man\/tutorial\/tutorial.pdf))#$relPath\/www\/$3#go; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir print FILEOUT $_; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir close FILEOUT; 109*cdf0e10cSrcweir chmod 0666, $i->{filename}; 110*cdf0e10cSrcweir rename "$i->{filename}.tmp", $i->{filename} || die "could not rename $i->{filename}.tmp to $i->{filename}"; 111*cdf0e10cSrcweir $return = 0; 112*cdf0e10cSrcweir} 113*cdf0e10cSrcweir 114*cdf0e10cSrcweirexit $return; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweirsub wanted { 117*cdf0e10cSrcweir %file = ( 118*cdf0e10cSrcweir directory => $dir, 119*cdf0e10cSrcweir filename => $name 120*cdf0e10cSrcweir ); 121*cdf0e10cSrcweir push @files, {%file} if /^.*\.html\z/s; 122*cdf0e10cSrcweir} 123