#!/usr/bin/perl

use Getopt::Std;

#---------------------------------------------------------------------------
# main

$Usage = qq{
Usage: $0 [options]

Options: -c filename           channels.conf
         -h	               Show this help text
};

$sim = $get = $verbose = 0;
die $Usage if (!getopts('c:h') || $opt_h || !$opt_c);
$channelsfile = $opt_c;

open(CHANNELS, "$channelsfile") || die "cannot open $channelsfile file: $!";
while(<CHANNELS>) {
	next if (/^:/);
	chomp;
	my($name, $frequency, $polarization, $source, $symbolrate, $vpid, $apid,
	 $tpid, $ca, $service_id, $nid, $tid, $rid) = split(/\:/, $_);

	if ( $source eq 'T' || $source eq 'C' ) {
	    if ( length($frequency) > 3) {
		$frequency=substr($frequency, 0, length($frequency)-3);
	    }
	    if ( length($frequency) > 3) {
		$frequency=substr($frequency, 0, length($frequency)-3);
	    }
	}

	$data = $nid>0 ? $tid : $frequency;

	print "$name\t$source-$nid-$data-$service_id\n";
}
close (CHANNELS);
