###!/usr/bin/perl

## the next line should point to the perl.exe executable when executed on windows.
## it should replace the first line
#!C:/Perl64/bin/perl.exe

# script written by: maxime.lefrancois@emse.fr

print "Content-type: text/html\n\n";

# foreach (sort keys %ENV) { 
#   print "$_  =  $ENV{$_}<br/>"; 
# }

my %h = ( "html" => "text/html",
  "ttl" => "text/turtle" ,
  "rdf" => "application/rdf+xml" ,
  "jsonld" => "application/ld+json" ,
  "n3" => "application/n3" ,
  "nt" => "application/n-triples" ,
  );

"$ENV{\"DOCUMENT_ROOT\"}$ENV{\"REDIRECT_URL\"}" =~ /^(.*\/)([^\/]+)$/ ;
my $DIR = $1;
my $filename = $2;
opendir(DIR, $1 );
@files = grep(/^$filename\.[^\.]+$/,readdir(DIR));
closedir(DIR);
foreach $file (@files) {
  $file =~ /^$filename\.([^\.]+)$/;
  $ext = $1;
  print " <li><a href=\"$ENV{\"REDIRECT_URL\"}.$1\">$filename.$ext</a>, type $h{$ext}</li>\n";
}
