#!/bin/perl

#
# This program searches the KnotDB database for knot types, then checks for the corresponding files.
#

use strict;
use warnings;
use File::Slurp;
use File::Copy;
use File::Path;
use Data::Dumper;

require 'tightknot_common.pl';

# We start by loading the database.

my $DBFILE = read_file('KnotDB.pl');
my %knots;
eval($DBFILE);

foreach (keys %knots) {

  if ($_ =~ /\#/) {  # This is a composite

    my $fn;

    if (defined $knots{$_}{filename}) { $fn = $knots{$_}{filename} }
    else {$fn = $_};

    my %parseagain;
    %parseagain = parsefilename($fn);

    print "$_: $knots{$_}{summands}";

    @{ $knots{$_}{summands} } = @{ $parseagain{summands} };

    print "-> $knots{$_}{summands} \n";

  }

}

print "Writing ProposedKnotDB.pl.\n";

open(KNOTDB,'>ProposedKnotDB.pl') or die "Unable to create Knot database.";
print KNOTDB Data::Dumper->Dump([\%knots],['*knots']),"\n";
close KNOTDB;
