+ ++$cfg{startperl}; # Cheat.
+
+ while (<$fh>) {
+ next if /^\#/ || /^\s*$/ || /^\:/;
+ s/(\s*!.*|\s*)$//; # remove trailing comments or whitespace
+ ++$cfg{$1} if /^\$\s+WC "(\w+)='(?:.*)'"$/;
+ }
+ } else {
+ while (<$fh>) {
+ if ($_ =~ $first) {
+ die "$cfg:$.:section=$section:$_" unless $section == 0;
+ $section = 1;
+ }
+ push @{$lines[$section]}, $_;
+ next if /^\#/ || /^\s*$/ || /^\:/;
+ if ($_ =~ $last) {
+ die "$cfg:$.:section=$section:$_" unless $section == 1;
+ $section = 2;
+ }
+ # foo='bar'
+ # foo=bar
+ # (optionally with a trailing comment)
+ if (/^(\w+)=(?:'.*'|[^'].*)(?: #.*)?$/) {
+ ++$cfg{$1};
+ } else {
+ warn "$cfg:$.:$_";
+ }
+ }
+ }
+ close $fh;
+
+ ++$test;
+ my $missing;
+ if ($cfg eq 'configure.com') {
+ print "ok $test # skip $cfg doesn't need to be sorted\n"
+ if $tap;
+ } elsif (join("", @{$lines[1]}) eq join("", sort @{$lines[1]})) {
+ print "ok $test - $cfg sorted\n"
+ if $tap;
+ } elsif ($tap) {
+ print "not ok $test - $cfg is not sorted\n";
+ } elsif ($opt_r || $opt_l) {
+ # A reference to an empty array is true, hence this flags the
+ # file for later attention by --regen and --list, even if
+ # nothing is missing. Actual sort and output are done later.
+ $missing = [];
+ } else {
+ print "$cfg: unsorted\n"
+ }
+
+ for my $v (@MASTER_CFG) {
+ # This only creates a reference in $missing if something is missing:
+ push @$missing, $v unless exists $cfg{$v};