summaryrefslogtreecommitdiff
path: root/solenv/bin/convertlinks.pl
blob: c8644aa4c9affe04b18ae18b36e0409e7ba88d14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#
# convertlinks - a perl script to make hrefs to
# http://api.openoffice.org/common/ref relativ.
#
# Copyright (c) 2000 Sun Microsystems, Inc.
#

use File::Find;

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
@files = ();

if($#ARGV == 1)
{
    $pattern = "www";
} else
{
    $pattern = $ARGV[2];
}

find(\&wanted, "$ARGV[0]");

$return = 1;

foreach $i (@files)
{
    next if( $i->{directory} =~ /.*common((\/|\\)ref(.*))/ ||
         $i->{directory} =~ /.*cpp((\/|\\)ref(.*))/ ||
         $i->{directory} =~ /.*java((\/|\\)ref(.*))/ );

    open ( FILEIN, $i->{filename} ) || die "could not open $i->{filename} for reading";

    $relPath = ".";
    $relToSource = ".";
    if( $i->{directory} =~ /.*$pattern((\/|\\)(.*))/ )
    {
        $relPath = $3;
        $relPath =~ s#\w+#\.\.#go;
        if($pattern eq "examples")
        {
            $relPath = "\.\.\/$relPath";
        }
        if($pattern eq "www")
        {
            $relToSource = "\.\.\/$relPath";
        } else
        {
            $relToSource = $relPath;
        }
    } else
    {
        if($pattern eq "examples")
        {
            $relPath = "\.\.";
        }
        if($pattern eq "www")
        {
            $relToSource = "\.\.";
        } else
        {
            $relToSource = $relPath;
        }
    }

    @lines = <FILEIN>;
    close( FILEIN );
    open( FILEOUT, ">$i->{filename}.tmp" ) || die "could not open $i->{filename} for writing";
    foreach $_ (@lines)
    {
        # change the refenreces to the index in dependency of UDK or ODK
        if("$ARGV[1]" eq "udk_" | "$ARGV[1]" eq "odk_")
        {
            s#((\")(index.html\"))#$2$ARGV[1]$3#go;
            s#((\/|\")(faq.html\"))#$2$ARGV[1]$3#go;
            s#((\/|\")(bylaws.html\"))#$2$ARGV[1]$3#go;
        }

        s#((http:\/\/api\.openoffice\.org\/)(common\/ref[^\"]+))#$relPath\/$3#go;
        s#((http:\/\/api\.openoffice\.org\/unbranded-source\/)(.*)(examples\/examples.html))#$relToSource\/$4#go;

        if($pattern eq "examples")
        {
            # change the links for the C++/Java examples in the ODK
            s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(java\/*))#$3#go;
            s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(cpp\/*))#$3#go;
            s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(basic\/*))#$3#go;
            s#((http:\/\/api\.openoffice\.org\/source\/browse\/api\/odk\/examples\/)(OLE\/*))#$3#go;

            # change link api specific stuff
            s#((http:\/\/api\.openoffice\.org\/)(design_guide.html))#$relPath\/www\/$3#go;
            s#(http:\/\/api\.openoffice\.org\/index.html)#$relPath\/www\/odk_index.html#go;

            # change the links for the C++ examples in the UDK
            s#((http:\/\/udk\.openoffice\.org\/source\/browse\/udk\/product\/examples\/)(cpp\/*))#$3#go;

            # change the links to udk.openoffice.org to relativ links
            s#(http:\/\/udk\.openoffice\.org\/index.html)#$relPath\/www\/udk_index.html#go;
            s#((http:\/\/udk\.openoffice\.org)(\/*))#$relPath\/www$3#go;

            # change the link to tutorial
            s#((http:\/\/api\.openoffice\.org\/)(basic\/man\/tutorial\/tutorial.pdf))#$relPath\/www\/$3#go;
        }
        print FILEOUT $_;
    }
    close FILEOUT;
    chmod 0666, $i->{filename};
    rename "$i->{filename}.tmp", $i->{filename} || die "could not rename $i->{filename}.tmp to $i->{filename}";
    $return = 0;
}

exit $return;

sub wanted {
    %file = (
         directory => $dir,
         filename  => $name
         );
    push @files, {%file} if /^.*\.html\z/s;
}