bump product version to 4.1.6.2
[LibreOffice.git] / solenv / bin / convertlinks.pl
blob96a45286df05bf52107bf14ee0f656b4dd5bba84
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 # convertlinks - a perl script to make hrefs to
21 # http://api.openoffice.org/common/ref relativ.
24 use File::Find;
26 # for the convenience of &wanted calls, including -eval statements:
27 use vars qw/*name *dir/;
28 *name = *File::Find::name;
29 *dir = *File::Find::dir;
30 @files = ();
32 if($#ARGV == 1)
34 $pattern = "www";
35 } else
37 $pattern = $ARGV[2];
40 find(\&wanted, "$ARGV[0]");
42 $return = 1;
44 foreach $i (@files)
46 next if( $i->{directory} =~ /.*common((\/|\\)ref(.*))/ ||
47 $i->{directory} =~ /.*cpp((\/|\\)ref(.*))/ ||
48 $i->{directory} =~ /.*java((\/|\\)ref(.*))/ );
50 open ( FILEIN, $i->{filename} ) || die "could not open $i->{filename} for reading";
52 $relPath = ".";
53 $relToSource = ".";
54 if( $i->{directory} =~ /.*$pattern((\/|\\)(.*))/ )
56 $relPath = $3;
57 $relPath =~ s#\w+#\.\.#go;
58 if($pattern eq "examples")
60 $relPath = "\.\.\/$relPath";
62 if($pattern eq "www")
64 $relToSource = "\.\.\/$relPath";
65 } else
67 $relToSource = $relPath;
69 } else
71 if($pattern eq "examples")
73 $relPath = "\.\.";
75 if($pattern eq "www")
77 $relToSource = "\.\.";
78 } else
80 $relToSource = $relPath;
84 @lines = <FILEIN>;
85 close( FILEIN );
86 open( FILEOUT, ">$i->{filename}.tmp" ) || die "could not open $i->{filename} for writing";
87 foreach $_ (@lines)
89 # change the refenreces to the index in dependency of UDK or ODK
90 if("$ARGV[1]" eq "udk_" | "$ARGV[1]" eq "odk_")
92 s#((\")(index.html\"))#$2$ARGV[1]$3#go;
93 s#((\/|\")(faq.html\"))#$2$ARGV[1]$3#go;
94 s#((\/|\")(bylaws.html\"))#$2$ARGV[1]$3#go;
97 s#((http:\/\/api\.openoffice\.org\/)(common\/ref[^\"]+))#$relPath\/$3#go;
98 s#((http:\/\/api\.openoffice\.org\/unbranded-source\/)(.*)(examples\/examples.html))#$relToSource\/$4#go;
100 if($pattern eq "examples")
102 # change the links for the C++/Java examples in the ODK
103 s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(java\/*))#$3#go;
104 s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(cpp\/*))#$3#go;
105 s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(basic\/*))#$3#go;
106 s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(OLE\/*))#$3#go;
108 # change link api specific stuff
109 s#((http:\/\/api\.openoffice\.org\/)(design_guide.html))#$relPath\/www\/$3#go;
110 s#(http:\/\/api\.openoffice\.org\/index.html)#$relPath\/www\/odk_index.html#go;
112 # change the links for the C++ examples in the UDK
113 s#((http:\/\/udk\.openoffice\.org\/source\/browse\/udk\/product\/examples\/)(cpp\/*))#$3#go;
115 # change the links to udk.openoffice.org to relativ links
116 s#(http:\/\/udk\.openoffice\.org\/index.html)#$relPath\/www\/udk_index.html#go;
117 s#((http:\/\/udk\.openoffice\.org)(\/*))#$relPath\/www$3#go;
119 # change the link to tutorial
120 s#((http:\/\/api\.openoffice\.org\/)(basic\/man\/tutorial\/tutorial.pdf))#$relPath\/www\/$3#go;
122 print FILEOUT $_;
124 close FILEOUT;
125 chmod 0666, $i->{filename};
126 rename "$i->{filename}.tmp", $i->{filename} || die "could not rename $i->{filename}.tmp to $i->{filename}";
127 $return = 0;
130 exit $return;
132 sub wanted {
133 %file = (
134 directory => $dir,
135 filename => $name
137 push @files, {%file} if /^.*\.html\z/s;