- # If there is a range and doesn't need a single point range
- # output
- if ($start != $end && ! $range_size_1) {
- push @OUT, sprintf "%04X\t%04X", $start, $end;
- $OUT[-1] .= "\t$value" if $value ne "";
-
- # Add a comment with the size of the range, if requested.
- # Expand Tabs to make sure they all start in the same
- # column, and then unexpand to use mostly tabs.
- if (! $output_range_counts{$addr}) {
- $OUT[-1] .= "\n";
+ { # This bare block encloses the scope where we may need to
+ # split a range (when outputting deltas), and each time
+ # through we handle the next portion of the original by
+ # ending the block with a 'redo'. The values to use for
+ # that next time through are set up just below in the
+ # scalars whose names begin with '$next_'.
+
+ if ($use_delta_cp) {
+
+ # When converting to deltas, we can handle only single
+ # element ranges. Set up so that this time through
+ # the loop, we look at the first element, and the next
+ # time through, we start off with the remainder. Thus
+ # each time through we look at the first element of
+ # the range
+ if ($end != $start) {
+ $next_start = $start + 1;
+ $next_end = $end;
+ $next_value = $value;
+ $end = $start;
+ }
+
+ # The values for these tables is stored as hex
+ # strings. Get the delta by subtracting the code
+ # point.
+ $value = hex($value) - $start;
+
+ # If this range is adjacent to the previous one, and
+ # the values in each are the same, then this range
+ # really extends the previous one that is already in
+ # element $OUT[-1]. So we pop that element, and
+ # pretend that the range starts with whatever it
+ # started with.
+ if ($start == $previous_end + 1
+ && $value == $previous_value)
+ {
+ pop @OUT;
+ $start = $previous_start;
+ }
+
+ # Save the current values for the next time through
+ # the loop.
+ $previous_start = $start;
+ $previous_end = $end;
+ $previous_value = $value;