wininet: Load persistent cookies from other paths in get_cookie function.
[wine] / tools / winapi / setup.pm
1 #
2 # Copyright 1999, 2000, 2001 Patrik Stridvall
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 #
18
19 package setup;
20
21 use strict;
22
23 BEGIN {
24     use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
25     require Exporter;
26
27     @ISA = qw(Exporter);
28     @EXPORT = qw();
29     @EXPORT_OK = qw($current_dir $wine_dir $winapi_dir);
30
31     use vars qw($current_dir $wine_dir $winapi_dir);
32
33     my $tool = $0;
34     $tool =~ s%^(?:.*?/)?([^/]+)$%$1%;
35
36     if(defined($current_dir) && defined($wine_dir) &&
37        defined($winapi_dir))
38     {
39         # Nothing
40     } elsif($0 =~ m%^(.*?)/?tools/([^/]+)/[^/]+$%) {
41         my $dir = $2;
42
43         if(defined($1) && $1 ne "")
44         {
45             $wine_dir = $1;
46         } else {
47             $wine_dir = ".";
48
49         }
50
51         require Cwd;
52         my $cwd = Cwd::cwd();
53
54         if($wine_dir =~ /^\./) {
55             $current_dir = ".";
56             my $pwd; chomp($pwd = `pwd`);
57             foreach my $n (1..((length($wine_dir) + 1) / 3)) {
58                 $pwd =~ s/\/([^\/]*)$//;
59                 $current_dir = "$1/$current_dir";
60             }
61             $current_dir =~ s%/\.$%%;
62         } elsif($wine_dir eq $cwd) {
63             $wine_dir = ".";
64             $current_dir = ".";
65         } elsif($cwd =~ m%^$wine_dir/(.*?)?$%) {
66             $current_dir = $1;
67             $wine_dir = ".";
68             foreach my $dir (split(m%/%, $current_dir)) {
69                 $wine_dir = "../$wine_dir";
70             }
71             $wine_dir =~ s%/\.$%%;
72         } else {
73             print STDERR "$tool: You must run this tool in the main Wine directory or a sub directory\n";
74             exit 1;
75         }
76
77         $winapi_dir = "$wine_dir/tools/winapi";
78         $winapi_dir =~ s%^\./%%;
79
80         push @INC, $winapi_dir;
81     } else {
82         print STDERR "$tool: You must run this tool in the main Wine directory or a sub directory\n";
83         exit 1;
84     }
85 }
86
87 1;