Commit | Line | Data |
---|---|---|
4a591814 AC |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | ||
5 | =head1 NAME | |
6 | ||
7 | Porting/manifest_lib.pl - functions for managing manifests | |
8 | ||
9 | =head1 SYNOPSIS | |
10 | ||
11 | require './Porting/manifest_lib.pl'; | |
12 | ||
13 | =head1 DESCRIPTION | |
14 | ||
76f5a288 JK |
15 | This file makes available one function, C<sort_manifest()>. |
16 | ||
4a591814 AC |
17 | =head2 C<sort_manifest> |
18 | ||
19 | Treats its arguments as (chomped) lines from a MANIFEST file, and returns that | |
20 | listed sorted appropriately. | |
21 | ||
22 | =cut | |
23 | ||
24 | # Try to get a sane sort. case insensitive, more or less | |
25 | # sorted such that path components are compared independently, | |
26 | # and so that lib/Foo/Bar sorts before lib/Foo-Alpha/Baz | |
27 | # and so that lib/Foo/Bar.pm sorts before lib/Foo/Bar/Alpha.pm | |
28 | # and so that configure and Configure sort together. | |
29 | sub sort_manifest { | |
30 | return | |
31 | # case insensitive sorting of directory components independently. | |
32 | map { $_->[0] } # extract the full line | |
33 | sort { | |
34 | $a->[1] cmp $b->[1] || # sort in order of munged filename | |
35 | $a->[0] cmp $b->[0] # then by the exact text in full line | |
36 | } | |
37 | map { | |
38 | # split out the filename and the description | |
39 | my ($f) = split /\s+/, $_, 2; | |
40 | # lc the filename so Configure and configure sort together in the list | |
41 | my $m= lc $f; # $m for munged | |
42 | # replace slashes by nulls, this makes short directory names sort before | |
43 | # longer ones, such as "foo/" sorting before "foo-bar/" | |
44 | $m =~ s!/!\0!g; | |
45 | # replace the extension (only one) by null null extension. | |
46 | # this puts any foo/blah.ext before any files in foo/blah/ | |
95effda0 MS |
47 | $m =~ s{(?<!\A)(\.[^.]+\z)}{\0\0$1}; |
48 | ||
4a591814 AC |
49 | # return the original string, and the munged filename |
50 | [ $_, $m ]; | |
51 | } @_; | |
52 | } | |
53 | ||
54 | 1; | |
55 | ||
56 | # ex: set ts=8 sts=4 sw=4 et: |