wesnoth/utils/codelist
2006-01-17 14:52:24 +00:00

25 lines
636 B
Perl
Executable File

#!/usr/bin/perl -n
# codelist
# given list of integers, one per line, outputs a minimal list of ranges
# describing the list
# this is useful for codepoints that are in a font, based on list of codes
# output format is suitable for codepoints="" in Wesnoth fonts.cfg
#push @n, hex;
chomp; push @n, $_;
END {
foreach (sort { $a <=> $b } @n) {
if ($_ == $last + 1) {
$last = $_;
} else {
push @r, ($first == $last) ? "$first" : "$first-$last";
$first = $last = $_;
}
}
push @r, ($first == $last) ? "$first" : "$first-$last";
shift @r; # get rid of blank first element
print join(",", @r), "\n";
}