aboutsummaryrefslogtreecommitdiff
path: root/deps/sysobj_early/data/sort_vendors.pl
blob: 6ed69e582cd339161285d8a270d1e10ac526328f (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
36
37
38
39
40
41
42
43
#!/usr/bin/perl

# Usage:
#   sort_vendors.pl <some_path/vendor.ids>
# Output goes to stdout.

use utf8;
use strict;
#use File::Slurp::Unicode qw(read_file);
sub read_file {
    my $file = shift;
    return do {
        local $/ = undef;
        open my $fh, "<", $file || die "Could not open $file: $!";
        <$fh>;
    };
}

my $file = shift;
die "Invalid file: $file" unless (-f $file && -r $file);
my $raw = read_file($file);
$raw =~ s/^\n*|\n*$//g;

my $c = 0;
my @coms = ();
my %vendors = ();
SEC: foreach my $s (split(/\n{2,}/, $raw)) {
    my @lines = split(/\n/, $s);
    foreach my $l (@lines) {
        if ($l =~ /^name\s+(.*)/) {
            $vendors{"$1_$c"} = $s;
            $c++;
            next SEC;
        }
    }
    push @coms, $s;
}
foreach (@coms) {
    print "$_\n\n";
}
foreach (sort { lc $a cmp lc $b } keys %vendors) {
    print "$vendors{$_}\n\n";
}