#! /usr/bin/env perl

# ICON
#
# ------------------------------------------
# Copyright (C) 2004-2026, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss
# Contact information: icon-model.org
# See AUTHORS.TXT for a list of authors
# See LICENSES/ for license information
# SPDX-License-Identifier: BSD-3-Clause
# ------------------------------------------

use warnings;
use strict;
use Cwd;

my $dir = getcwd;

print "
<html>
    <head>
        <title>Index of $dir</title>
    </head>
    <body>
        <address><a href='..'>up</a></address>
        <hr>
        <table>
            <tr>
                <th>File</th>
                <th>Size (bytes)</th>
                <th>Date (UTC)</th>
            </tr>
";
my $i = 0;
my $style;
for my $file (glob('*')) {
    $file eq 'index.html' and next;
    my @stat_info = stat($file);
    if($i % 2) { $style = 'style="background-color: #CCCCCC"'; }
    else       { $style = ''; }
    my $size = reverse($stat_info[7]);
    $size =~ s/(\d\d\d)(?!$)/$1,/g;
    $size = reverse($size);
    my $date = gmtime($stat_info[9]);
    print "
            <tr $style>
                <td><a href='$file'>$file</a></td>
                <td align='right'>$size</td>
                <td>$date</td>
            </tr>
";
    ++$i;
}
print "
        </table>
    </body>
<html>
";
