+sub finduris { # find uris for cic and theory trees generation
+ my ($uritype,$uripattern,$format) = @_;
+ my $content = "";
+ my ($uri,$localpart,$dirname);
+ my (@itemz,@already_pushed_dir);
+
+ print "FINDURIS, uritype: $uritype, uripattern: $uripattern, ".
+ "format: $format\n\n";
+
+ if (($uritype eq "cic") or ($uritype eq "theory")) {
+ # get info only of one type: cic or theory
+ foreach (keys(%map)) { # select matching uris
+ $uri = $_;
+ if ($uri =~ /^$uritype:$uripattern\//) {
+ $localpart = $uri;
+ $localpart =~ s/^$uritype:$uripattern\/(.*)/$1/;
+ if ($localpart =~ /^[^\/]*$/) { # no slash, i.e. no dir
+ push @itemz, "object," . $localpart;
+ } else { # exists at least one slash, i.e. a dir
+ ($dirname) = split (/\//, $localpart);
+ push @itemz, "dir," . $dirname;
+ #print "LOCALPART $localpart, DIRNAME $dirname\n"; #DEBUG
+ }
+ }
+ }
+ } elsif ($uritype eq "any") { # get info for both cic and theory
+ foreach (keys(%map)) {
+ $uri = $_;
+ }
+ } else {
+ die "getter internal error: unsupported uritype: \"$uritype\"";
+ }
+ @itemz = sort @itemz; # sort itemz and remove duplicates
+ my $lastitem = "";
+ if ($format eq "txt") { #now generate output
+ foreach (@itemz) {
+ next if ($_ eq $last);
+ $content .= ($_ . "\n");
+ $last = $_;
+ }
+ } elsif ($format eq "xml") {
+ $content .= "<ls>\n";
+ foreach (@itemz) {
+ next if ($_ eq $last);
+ $last = $_;
+ ($itemtype,$itemdata) = split(/,/, $_);
+ if ($itemtype eq "object") {
+ $content .= "<object type=\"$uritype\">$itemdata</object>\n";
+ } elsif ($itemtype eq "dir") {
+ $content .= "<section>$itemdata</section>\n";
+ }
+ }
+ $content .= "</ls>\n"
+ } else { # may not enter this branch
+ die "Getter internal error: invalid format received by finduris sub";
+ }
+ return $content;
+}