#!/usr/bin/perl -w
#
# usage: merge_tvprefs files
#
# Outputs a new tvprefs file that combines the two.  Where they
# disagree, later files in the list take precedence.  So you might
# invoke as 'merge_tvprefs tvprefs.old tvprefs.new >tvprefs.merged'.

use strict;
my %wanted;
while (<>) {
    s/\#.*//; s/^\s+//; s/\s+$//;
    next if $_ eq '';
    if (/^(never|no|yes|always): (.+)$/) {
	my ($pref, $prog) = ($1, $2);
	$wanted{$prog} = $pref;
    }
    else { die "$ARGV:$.: bad line (remnant is $_)\n" }
}
foreach (sort keys %wanted) {
    my $pref = $wanted{$_};
    print "$pref: $_\n";
}

