m4: Fix check for yajl.pc
[libvirt/ericb.git] / src / check-symsorting.pl
blob51e38bdedb125e916144c28088a4b9a10ad71279
1 #!/usr/bin/env perl
3 # Copyright (C) 2012-2013 Red Hat, Inc.
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library. If not, see
17 # <http://www.gnu.org/licenses/>.
19 use strict;
20 use warnings;
22 die "syntax: $0 SRCDIR SYMFILE..." unless int(@ARGV) >= 2;
24 my $ret = 0;
25 my $srcdir = shift;
26 my $lastgroup = undef;
27 foreach my $symfile (@ARGV) {
28 open SYMFILE, $symfile or die "cannot read $symfile: $!";
30 my $line = 0;
31 my $groupfile = "";
32 my @group;
34 while (<SYMFILE>) {
35 chomp;
37 if (/^#\s*((\w+\/)*(\w+\.h))\s*$/) {
38 $groupfile = $1;
39 } elsif (/^#/) {
40 # Ignore comments
41 } elsif (/^\s*$/) {
42 if (@group) {
43 &check_sorting(\@group, $symfile, $line, $groupfile);
45 @group = ();
46 $line = $.;
47 } else {
48 $_ =~ s/;//;
49 push @group, $_;
53 close SYMFILE;
54 if (@group) {
55 &check_sorting(\@group, $symfile, $line, $groupfile);
57 $lastgroup = undef;
60 sub check_sorting {
61 my $group = shift;
62 my $symfile = shift;
63 my $line = shift;
64 my $groupfile = shift;
66 my @group = @{$group};
67 my @sorted = sort { lc $a cmp lc $b } @group;
68 my $sorted = 1;
69 my $first;
70 my $last;
72 # Check that groups are in order and groupfile exists
73 if (defined $lastgroup && lc $lastgroup ge lc $groupfile) {
74 print "Symbol block at $symfile:$line: block not sorted\n";
75 print "Move $groupfile block before $lastgroup block\n";
76 print "\n";
77 $ret = 1;
79 if (! -e "$srcdir/$groupfile") {
80 print "Symbol block at $symfile:$line: $groupfile not found\n";
81 print "\n";
82 $ret = 1;
84 $lastgroup = $groupfile;
86 # Check that symbols within a group are in order
87 for (my $i = 0 ; $i <= $#sorted ; $i++) {
88 if ($sorted[$i] ne $group[$i]) {
89 $first = $i unless defined $first;
90 $last = $i;
91 $sorted = 0;
94 if (!$sorted) {
95 @group = splice @group, $first, ($last-$first+1);
96 @sorted = splice @sorted, $first, ($last-$first+1);
97 print "Symbol block at $symfile:$line: symbols not sorted\n";
98 print map { " " . $_ . "\n" } @group;
99 print "Correct ordering\n";
100 print map { " " . $_ . "\n" } @sorted;
101 print "\n";
102 $ret = 1;
106 exit $ret;