Repository navigation
Expand file tree
/
Copy pathmkrange.pl
More file actions
executable file
·86 lines (80 loc) · 2.33 KB
/
Copy pathmkrange.pl
File metadata and controls
executable file
·86 lines (80 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl
# Written by Dr. Ken Lunde (lunde@adobe.com)
# Senior Computer Scientist 2, Adobe Inc.
# Version 2019-03-27
#
# This script takes a list of integer values as STDIN and outputs to
# STDOUT the same list, but as ranges of contiguous integer values
# using a hyphen as the separator. No sorting is performed, and the
# integer values can be prefixed with a slash (the use of a slash
# prefix explicitly specifies CID values, as opposed to GID values,
# which is useful for CID-keyed font development). Hexadecimal values
# are supported if the "-h" command-line option is specified.
#
# The "-s" command-line option will output the single values and
# ranges as a single line that uses a comma as a separator.
#
# Tool Dependencies: None
$second = $dohex = 0;
$prefix = "";
$sep = "\n";
while ($ARGV[0]) {
if ($ARGV[0] =~ /^-[sS]/) {
$sep = ",";
shift;
} elsif ($ARGV[0] =~ /^-[hH]/) {
$dohex = 1;
shift;
} else {
print STDERR "Invalid option: $ARGV[0]! Skipping...\n";
shift;
}
}
while(defined($line = <STDIN>)) {
chomp $line;
if ($line =~ m#^/#) {
$line =~ s#^/##;
$prefix = "/";
}
if (not $second) {
$orig = $previous = $line;
$second = 1;
next;
}
if ($dohex) {
if (hex($line) != hex($previous) + 1) {
if ($orig eq $previous) {
print STDOUT $prefix . $orig . $sep;
} else {
print STDOUT $prefix . $orig . "-" . $prefix . $previous . $sep;
}
$orig = $previous = $line;
} else {
$previous = $line;
}
} else {
if ($line != $previous + 1) {
if ($orig == $previous) {
print STDOUT $prefix . $orig . $sep;
} else {
print STDOUT $prefix . $orig . "-" . $prefix . $previous . $sep;
}
$orig = $previous = $line;
} else {
$previous = $line;
}
}
}
if ($dohex) {
if ($orig eq $previous) {
print STDOUT $prefix . $orig . "\n";
} else {
print STDOUT $prefix . $orig . "-" . $prefix . $previous . "\n";
}
} else {
if ($orig == $previous) {
print STDOUT $prefix . $orig . "\n";
} else {
print STDOUT $prefix . $orig . "-" . $prefix . $previous . "\n";
}
}