From 562fc84575d19ab09980bff2cb1c7ca92c15b109 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 14 May 2024 04:47:54 +0100 Subject: [PATCH 1/1] report: Sort more sensibly. --- report | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/report b/report index b44c6fb..566c162 100755 --- a/report +++ b/report @@ -64,9 +64,26 @@ sub set_box ($) { if ($box ne $lastbox) { print "!box $box\n"; $lastbox = $box; } } +sub path_key ($) { + my ($p) = @_; + if ($p =~ m{^ ([a-z]) / ([^/]+) ((?: / .*)?) $}ix) { + my $init = $1; + my $focus = $2; + my $tail = $3; + my $head = undef; + if ($focus =~ /^ (the | a ) \s+ (\S .*) $/x) + { $head = $1; $focus = $2; } + if (lc $init ne lc substr($focus, 0, 1) && + $focus =~ /^ (.*) \s+ ($init .*) $/x) + { $head .= (defined $head && " ") . $1; $focus = $2; } + if (defined $head) { return "$init/$focus, $head$tail"; } + } + return $p; +} + for my $name (sort { my $pa = $set_path{$a}[0]; my $ba = $box{$pa} // "~~~"; my $pb = $set_path{$b}[0]; my $bb = $box{$pb} // "~~~"; - $ba cmp $bb || $pa cmp $pb } + $ba cmp $bb || path_key $pa cmp path_key $pb } keys %set_path) { my $paths = $set_path{$name}; my @unk; -- 2.11.0