+sub resperpagelink {
+ my ($cgi, $params, $res_per_page ) = @_;
+
+ my $page;
+ if ($res_per_page =~ /^all$/i) {
+ $page = 1;
+ } else {
+ $page = ceil(start( $params ) / $res_per_page);
+ }
+
+ return "<a href=\"".encode_entities($cgi->self_url).
+ "&page=$page&number=$res_per_page\">$res_per_page</a>";
+}
+
+sub printindexline {
+ my ( $input, $no_results, $opts ) = @_;
+
+ my $index_line;
+ if ($no_results > $opts->{number}) {
+
+ $index_line = prevlink( $input, $opts)." | ".
+ indexline( $input, $opts, $no_results)." | ".
+ nextlink( $input, $opts, $no_results);
+
+ print "<p style=\"text-align:center\">$index_line</p>";
+ }
+}
+
+#sub multipageheader {
+# my ( $input, $no_results, $opts ) = @_;
+#
+# my ($start, $end);
+# if ($opts->{number} =~ /^all$/i) {
+# $start = 1;
+# $end = $no_results;
+# $opts->{number} = $no_results;
+# $opts->{number_all}++;
+# } else {
+# $start = Packages::Search::start( $opts );
+# $end = Packages::Search::end( $opts );
+# if ($end > $no_results) { $end = $no_results; }
+# }
+#
+# print "<p>Found <em>$no_results</em> matching packages,";
+# if ($end == $start) {
+# print " displaying package $end.</p>";
+# } else {
+# print " displaying packages $start to $end.</p>";
+# }
+#
+# printindexline( $input, $no_results, $opts );
+#
+# if ($no_results > 100) {
+# print "<p>Results per page: ";
+# my @resperpagelinks;
+# for (50, 100, 200) {
+# if ($opts->{number} == $_) {
+# push @resperpagelinks, $_;
+# } else {
+# push @resperpagelinks, resperpagelink($input,$opts,$_);
+# }
+# }
+# if ($opts->{number_all}) {
+# push @resperpagelinks, "all";
+# } else {
+# push @resperpagelinks, resperpagelink($input, $opts, "all");
+# }
+# print join( " | ", @resperpagelinks )."</p>";
+# }
+# return ( $start, $end );
+#}
+
+sub string2id {
+ my $string = "@_";
+
+ $string =~ s/[^\w:.-]/_/g;
+ return $string;
+}
+
+our ( %url_params, %query_params );
+
+sub init_url {
+ my ($input, $params, $opts) = @_;
+
+ %url_params = ();
+ %query_params = ();
+
+ if ($params->{values}{lang}{orig} &&
+ (my $l = $params->{values}{lang}{no_replace})) {
+ $url_params{lang} = $l;
+ }
+ if ($params->{values}{source}{no_replace}) {
+ $url_params{source} = 'source';
+ $query_params{source} = 1;
+ }
+ foreach my $p (qw(suite arch)) {
+ if ($params->{values}{$p}{orig}
+ && (ref $params->{values}{$p}{final} eq 'ARRAY')
+ && @{$params->{values}{$p}{final}}) {
+ if (@{$params->{values}{$p}{final}} == 1) {
+ $url_params{$p} = $params->{values}{$p}{final}[0];
+ } else {
+ $url_params{$p} =
+ join(",",@{$params->{values}{$p}{no_replace}});
+ }
+ }
+ }
+ foreach my $p (qw(format searchon mode exact debug)) {
+ if ($params->{values}{$p}{orig}
+ && (my $pv = $params->{values}{$p}{no_replace})) {
+ $url_params{$p} = $pv;