#!/usr/bin/perl

use varcon;

while (<>) {
    my $orig_line = $_;
    my $comment;
    if (varcon::filter $_, \$comment) {
        print $orig_line;
        next;
    } else {
        my %n;
        my %d = varcon::readline($_, \%n);
        my @missing;
        my @sps;
        foreach my $k (sort keys %d) {
            next unless defined $d{$k};
            push @missing, $k unless defined $d{$k}[0];
            push @sps, $k;
        }
        my $sps = join (' ', @sps);
        print STDERR "BAD LINE (m: @missing): $_\n" if @missing;
        print STDERR "BAD LINE (?: @sps): $_\n" unless $sps eq '_' || $sps eq 'A B C Z';
        %d = varcon::flatten(%d);
        print varcon::format(\%d) unless $n{fragile};
        print $n{orig_data} if $n{fragile};
        print " | $n{_}" if defined $n{_};
        print " $comment" if defined $comment;
        print "\n";
    }
}
