5
5
# This program is free software; you can redistribute and/or
6
6
# modify it under the same terms as Perl itself.
8
# $Id: Xpd.pm 7492 2009-11-05 09:41:22Z tzafrir $
8
# $Id: Xpd.pm 7256 2009-09-29 19:20:32Z tzafrir $
327
327
# static xpd related helper functions
328
328
#------------------------------------
330
sub format_rank($$) {
331
my ($rank, $prio) = @_;
333
# 0 is replaced with a character that is sorted *AFTER* numbers.
334
$prio = '_' x $width unless defined $prio && $prio;
335
return sprintf "%${width}s-%s", $prio, $rank;
330
338
sub sync_priority_rank($) {
331
339
my $xpd = shift || die;
340
my $prio = $xpd->timing_priority;
332
341
# The @rank array is ordered by priority of sync (good to bad)
342
# It is used when timing_priority is not defined (analog) or
334
345
($xpd->is_pri and defined($xpd->termtype) and $xpd->termtype eq 'TE'),
335
346
($xpd->is_bri and defined($xpd->termtype) and $xpd->termtype eq 'TE'),
347
($xpd->type eq 'FXO'),
337
($xpd->type eq 'FXO'),
339
350
($xpd->type eq 'FXS'),
341
for(my $i = 0; $i < @rank; $i++) {
342
return $i if $rank[$i];
353
for($i = 0; $i < @rank; $i++) {
356
return format_rank($i, $prio);
347
359
# An XPD sync priority comparator for sort()
348
360
sub sync_priority_compare() {
349
361
my $rank_a = sync_priority_rank($a);
350
362
my $rank_b = sync_priority_rank($b);
351
#print STDERR "DEBUG: $rank_a (", $a->fqn, ") $rank_b (", $b->fqn, ")\n";
352
return $a->fqn cmp $b->fqn if $rank_a == $rank_b;
353
return $rank_a <=> $rank_b;
363
#print STDERR "DEBUG(rank): $rank_a (", $a->fqn, ") $rank_b (", $b->fqn, ")\n";
364
return $rank_a cmp $rank_b; # The easy case
356
367
# For debugging: show a list of XPD's with relevant sync info.
358
369
print STDERR "XPD's by rank\n";
359
370
foreach my $xpd (@_) {
360
371
my $type = $xpd->type;
361
373
my $rank = sync_priority_rank($xpd);
362
374
if($xpd->is_digital) {
363
$type .= " (TERMTYPE " . ($xpd->termtype || "UNKNOWN") . ")";
375
$extra .= " termtype " . ($xpd->termtype || "UNKNOWN");
365
printf STDERR "%3d %-15s %s\n", $rank, $xpd->fqn, $type;
377
printf STDERR "%3s %-15s %s\n", $rank, $xpd->fqn, $extra;