Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / tests / ovsdb-monitor-sort.pl
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 # Breaks lines read from <STDIN> into groups using blank lines as
7 # group separators, then sorts lines within the groups for
8 # reproducibility.
9
10 sub compare_lines {
11     my ($a, $b) = @_;
12
13     my $u = '[0-9a-fA-F]';
14     my $uuid_re = "${u}{8}-${u}{4}-${u}{4}-${u}{4}-${u}{12}";
15     if ($a =~ /^$uuid_re/) {
16         if ($b =~ /^$uuid_re/) {
17             return substr($a, 36) cmp substr($b, 36);
18         } else {
19             return 1;
20         }
21     } elsif ($b =~ /^$uuid_re/) {
22         return -1;
23     } else {
24         return $a cmp $b;
25     }
26 }
27
28 sub output_group {
29     my (@group) = @_;
30     print "$_\n" foreach sort { compare_lines($a, $b) } @group;
31 }
32
33 my @group = ();
34 while (<STDIN>) {
35     chomp;
36     if ($_ eq '') {
37         output_group(@group);
38         @group = ();
39         print "\n";
40     } else {
41         if (/^,/ && @group) {
42             $group[$#group] .= "\n" . $_;
43         } else {
44             push(@group, $_);
45         }
46     }
47 }
48
49 output_group(@group) if @group;