-$Search::Param::debug = 1 if $debug > 1;
-
-# If you want, just print out a list of all of the variables and exit.
-print $input->header if $debug;
-# print $input->dump;
-# exit;
-
-my %params_def = ( keywords => { default => undef, match => '^\s*([-+\@\w\/.:]+)\s*$' },
- suite => { default => 'stable', match => '^(\w+)$',
- alias => 'version', array => ',',
- replace => { all => \@SUITES } },
- case => { default => 'insensitive', match => '^(\w+)$' },
- official => { default => 0, match => '^(\w+)$' },
- use_cache => { default => 1, match => '^(\w+)$' },
- subword => { default => 0, match => '^(\w+)$' },
- exact => { default => undef, match => '^(\w+)$' },
- searchon => { default => 'all', match => '^(\w+)$' },
- section => { default => 'all', match => '^([\w-]+)$',
- alias => 'release', array => ',',
- replace => { all => \@SECTIONS } },
- arch => { default => 'any', match => '^(\w+)$',
- array => ',', replace =>
- { any => \@ARCHITECTURES } },
- archive => { default => 'all', match => '^(\w+)$',
- array => ',', replace =>
- { all => \@ARCHIVES } },
- format => { default => 'html', match => '^(\w+)$' },
- );
-my %params = Packages::Search::parse_params( $input, \%params_def );
-
-my $format = $params{values}{format}{final};
+$debug = 0 if !defined($debug) || $debug !~ /^\d+$/o;
+$Packages::CGI::debug = $debug;
+
+# read the configuration
+our $config_read_time ||= 0;
+our $db_read_time ||= 0;
+our ( $topdir, $ROOT, @SUITES, @SECTIONS, @ARCHIVES, @ARCHITECTURES );
+
+# FIXME: move to own module
+my $modtime = (stat( "../config.sh" ))[9];
+if ($modtime > $config_read_time) {
+ if (!open (C, '<', "../config.sh")) {
+ error( "Internal: Cannot open configuration file." );
+ }
+ while (<C>) {
+ next if /^\s*\#/o;
+ chomp;
+ $topdir = $1 if /^\s*topdir="?([^\"]*)"?\s*$/o;
+ $ROOT = $1 if /^\s*root="?([^\"]*)"?\s*$/o;
+ $Packages::HTML::HOME = $1 if /^\s*home="?([^\"]*)"?\s*$/o;
+ $Packages::HTML::SEARCH_CGI = $1 if /^\s*searchcgi="?([^\"]*)"?\s*$/o;
+ $Packages::HTML::SEARCH_PAGE = $1 if /^\s*searchpage="?([^\"]*)"?\s*$/o;
+ $Packages::HTML::WEBMASTER_MAIL = $1 if /^\s*webmaster="?([^\"]*)"?\s*$/o;
+ $Packages::HTML::CONTACT_MAIL = $1 if /^\s*contact="?([^\"]*)"?\s*$/o;
+ @SUITES = split(/\s+/, $1) if /^\s*suites="?([^\"]*)"?\s*$/o;
+ @SECTIONS = split(/\s+/, $1) if /^\s*sections="?([^\"]*)"?\s*$/o;
+ @ARCHIVES = split(/\s+/, $1) if /^\s*archives="?([^\"]*)"?\s*$/o;
+ @ARCHITECTURES = split(/\s+/, $1) if /^\s*architectures="?([^\"]*)"?\s*$/o;
+ }
+ close (C);
+ debug( "read config ($modtime > $config_read_time)" );
+ $config_read_time = $modtime;
+}
+my $DBDIR = $topdir . "/files/db";
+my $thisscript = $Packages::HTML::SEARCH_CGI;
+
+if (my $path = $input->param('path')) {
+ my @components = map { lc $_ } split /\//, $path;
+
+ my %SUITES = map { $_ => 1 } @SUITES;
+ my %SECTIONS = map { $_ => 1 } @SECTIONS;
+ my %ARCHIVES = map { $_ => 1 } @ARCHIVES;
+ my %ARCHITECTURES = map { $_ => 1 } @ARCHITECTURES;
+
+ foreach (@components) {
+ if ($SUITES{$_}) {
+ $input->param('suite', $_);
+ } elsif ($SECTIONS{$_}) {
+ $input->param('section', $_);
+ } elsif ($ARCHIVES{$_}) {
+ $input->param('archive', $_);
+ } elsif ($ARCHITECTURES{$_}) {
+ $input->param('arch', $_);
+ }
+ }
+}
+
+my ( $format, $keyword, $case, $subword, $exact, $searchon,
+ @suites, @sections, @archives, @archs );
+
+# my %params_def = ( keywords => { default => undef,
+# match => '^\s*([-+\@\w\/.:]+)\s*$',
+# var => \$keyword },
+# suite => { default => 'stable', match => '^([\w-]+)$',
+# alias => 'version', array => ',',
+# var => \@suites,
+# replace => { all => \@SUITES } },
+# archive => { default => 'all', match => '^([\w-]+)$',
+# array => ',', var => \@archives,
+# replace => { all => \@ARCHIVES } },
+# case => { default => 'insensitive', match => '^(\w+)$',
+# var => \$case },
+# official => { default => 0, match => '^(\w+)$' },
+# subword => { default => 0, match => '^(\w+)$',
+# var => \$subword },
+# exact => { default => undef, match => '^(\w+)$',
+# var => \$exact },
+# searchon => { default => 'all', match => '^(\w+)$',
+# var => \$searchon },
+# section => { default => 'all', match => '^([\w-]+)$',
+# alias => 'release', array => ',',
+# var => \@sections,
+# replace => { all => \@SECTIONS } },
+# arch => { default => 'any', match => '^(\w+)$',
+# array => ',', var => \@archs, replace =>
+# { any => \@ARCHITECTURES } },
+# format => { default => 'html', match => '^(\w+)$',
+# var => \$format },
+# );
+my %opts;
+my %params = Packages::Search::parse_params( $input, \%params_def, \%opts );
+