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