aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/sortdin
blob: dafb329ff98c9a0b3bca14975ea875e2a4cb0081 (plain)
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
#!/usr/bin/perl

my %data = ();
my %code = ();

my @out = ();

my $fn = $ARGV[0];

while (<>) {
    push(@out, $_);
    /^\s*exports/i and last;
}

while (<>) {
    my $key;
    $arr = /\sDATA\s*$/o ? \%data : \%code;
    $_ =~ s/^\s+//;
    my $key = (split(' ', $_))[0];
    substr($key, 0, 1) = '' while $key =~ /^_/o;
    chomp $key;
    $arr->{$key}->{$_} = 1;
}

for my $k (sort keys %data) {
    push(@out, sort {$b cmp $a} keys %{$data{$k}});
}

for my $k (sort keys %code) {
    push(@out, sort {$b cmp $a} keys %{$code{$k}});
}

open(R, '>', $fn);
print R @out;
close R;