merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / convertlinks.pl
blobcdecaaa6f81e2a241c28618ce1a9fec76da6ec6b
2 # convertlinks - a perl script to make hrefs to
3 # http://api.openoffice.org/common/ref relativ.
5 # Copyright (c) 2000 Sun Microsystems, Inc.
8 use File::Find;
10 # for the convenience of &wanted calls, including -eval statements:
11 use vars qw/*name *dir/;
12 *name = *File::Find::name;
13 *dir = *File::Find::dir;
14 @files = ();
16 if($#ARGV == 1)
18 $pattern = "www";
19 } else
21 $pattern = $ARGV[2];
24 find(\&wanted, "$ARGV[0]");
26 $return = 1;
28 foreach $i (@files)
30 next if( $i->{directory} =~ /.*common((\/|\\)ref(.*))/ ||
31 $i->{directory} =~ /.*cpp((\/|\\)ref(.*))/ ||
32 $i->{directory} =~ /.*java((\/|\\)ref(.*))/ );
34 open ( FILEIN, $i->{filename} ) || die "could not open $i->{filename} for reading";
36 $relPath = ".";
37 $relToSource = ".";
38 if( $i->{directory} =~ /.*$pattern((\/|\\)(.*))/ )
40 $relPath = $3;
41 $relPath =~ s#\w+#\.\.#go;
42 if($pattern eq "examples")
44 $relPath = "\.\.\/$relPath";
46 if($pattern eq "www")
48 $relToSource = "\.\.\/$relPath";
49 } else
51 $relToSource = $relPath;
53 } else
55 if($pattern eq "examples")
57 $relPath = "\.\.";
59 if($pattern eq "www")
61 $relToSource = "\.\.";
62 } else
64 $relToSource = $relPath;
68 @lines = <FILEIN>;
69 close( FILEIN );
70 open( FILEOUT, ">$i->{filename}.tmp" ) || die "could not open $i->{filename} for writing";
71 foreach $_ (@lines)
73 # change the refenreces to the index in dependency of UDK or ODK
74 if("$ARGV[1]" eq "udk_" | "$ARGV[1]" eq "odk_")
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;
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;
84 if($pattern eq "examples")
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;
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;
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;
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;
103 # change the link to tutorial
104 s#((http:\/\/api\.openoffice\.org\/)(basic\/man\/tutorial\/tutorial.pdf))#$relPath\/www\/$3#go;
106 print FILEOUT $_;
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;
114 exit $return;
116 sub wanted {
117 %file = (
118 directory => $dir,
119 filename => $name
121 push @files, {%file} if /^.*\.html\z/s;