#!/usr/bin/perl
use POSIX;
use Date::Calc qw(Days_in_Month);

## http://www.frankandernest.com/images/archive/99/990101.gif

@ls = `ls *.html`;
chomp @ls;

foreach $toto (@ls) {
  print STDERR "\n$toto : ";
  open FILE, "<$toto"
    or die "Error : Cannot open file ($toto) : $!\n";
  @all = <FILE>;
  close FILE;
  chomp @all;
#  chop @all;

#  $ll = "@all";
#  @all = split /\n/mg, $ll;


  foreach $val (@all) {
    if ($val =~ m%\"(\d{2})(\d{2})(\d{2})\.\w{3}\"%) {
      print STDERR ".";
      $year  = $1;
      $month = $2;
      $date  = $3;
      $ok{$year}{$month}{$date} = "";
    }
  }
}

foreach $year (sort num keys %ok) {
  foreach $month (sort num keys %{$ok{$year}}) {
    print "\$", (($year < 92) ? "exists" : "missing"), "{\"$year\"}";
    print "{\"$month\"} = ";
    @dates = sort num keys %{$ok{$year}{$month}};
    
#    print "\n$year:$month (", $#dates + 1, ") ";
    if ($year < 92) {
      print "[";
      while ($#dates > 0) {
	$tmp = shift @dates;
	$tmp = $1 if ($tmp =~ /^0(.+)/);
	print $tmp, ", ";
      }
       print $dates[0], "];\n";
    } else {
      print "[";
      $done = "F";
      for ($i = 1; $i <= Days_in_Month($year,$month); $i++) {
	$j = ($i < 10) ? "0$i" : "$i";
	if (! exists $ok{$year}{$month}{$j}) {
	  print (($done eq "T") ? ", " : "");
	  print "$i";
	  $done = "T";
	}
      }
      print "];\n";
    }
  }
}

print "\n\n";

sub num {$a <=> $b}
