87664f81 |
1 | # -*-perl-*- |
2 | # |
9796a787 |
3 | # $Id: SWConfig.pm.in,v 1.2 2004/04/08 01:52:19 mdw Exp $ |
87664f81 |
4 | # |
5 | # Exports configuration variables |
6 | # |
7 | # (c) 1999 EBI |
8 | # |
9 | |
10 | #----- Licensing notice ----------------------------------------------------- |
11 | # |
12 | # This file is part of sw-tools. |
13 | # |
14 | # sw-tools is free software; you can redistribute it and/or modify |
15 | # it under the terms of the GNU General Public License as published by |
16 | # the Free Software Foundation; either version 2 of the License, or |
17 | # (at your option) any later version. |
18 | # |
19 | # sw-tools is distributed in the hope that it will be useful, |
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | # GNU General Public License for more details. |
23 | # |
24 | # You should have received a copy of the GNU General Public License |
25 | # along with sw-tools; if not, write to the Free Software Foundation, |
26 | # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
27 | |
87664f81 |
28 | #----- Package preamble ----------------------------------------------------- |
29 | |
30 | package SWConfig; |
31 | use IO; |
32 | use Exporter; |
33 | @ISA = qw(Exporter); |
34 | @EXPORT = qw(%C); |
35 | |
36 | #----- Configuration variables ---------------------------------------------- |
37 | |
38 | %C = (); |
39 | $C{pkg} = '@PACKAGE@'; |
40 | $C{version} = '@VERSION@'; |
41 | $C{prefix} = '@prefix@'; |
42 | $C{datadir} = '@datadir@'; |
43 | $C{index} = '${prefix}/sw-index'; |
44 | $C{doc} = '${prefix}/doc'; |
45 | |
46 | foreach my $k (qw(datadir index doc)) { |
47 | $C{$k} =~ s/\$\{(\w+)\}/$C{$1}/eg; |
48 | } |
49 | |
50 | #----- Read a configuration file -------------------------------------------- |
51 | |
52 | if (my $fh = IO::File->new("$C{datadir}/sw.conf")) { |
53 | LINE: while (my $line = $fh->getline()) { |
54 | chomp($line); |
55 | next LINE if $line =~ /^\s*\#/ || $line =~ /^\s*$/; |
56 | my ($k, $v) = split(/\s*=\s*|\s+/, $line, 2); |
57 | $v =~ s/\$\{(\w+)\}/$C{$1}/eg; |
58 | $C{$k} = $v; |
59 | } |
60 | } |
61 | |
62 | #----- That's all, folks ---------------------------------------------------- |
63 | |
64 | 1; |