"Fossies" - the Fresh Open Source Software Archive

Member "ferm-2.6/test/sort.pl" (30 Jan 2021, 1719 Bytes) of package /linux/privat/ferm-2.6.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "sort.pl": 2.5.1_vs_2.6.

    1 #!/usr/bin/perl -w
    2 
    3 #
    4 # ferm, a firewall setup program that makes firewall rules easy!
    5 #
    6 # Copyright 2001-2021 Max Kellermann
    7 #
    8 # Bug reports and patches for this program may be sent to the GitHub
    9 # repository: L<https://github.com/MaxKellermann/ferm>
   10 #
   11 
   12 # This script sorts the tables and chains in ferm output so the
   13 # unit test suite can use "diff" to verify it.  It's a kludge that is
   14 # necessary because ferm outputs these in random order (because Perl
   15 # does).
   16 
   17 use strict;
   18 
   19 my %rules;
   20 my $table;
   21 
   22 sub flush_output() {
   23     foreach my $key (sort keys %rules) {
   24         foreach my $line (@{$rules{$key}}) {
   25             print $line;
   26         }
   27     }
   28     undef %rules;
   29     undef $table;
   30 }
   31 
   32 while (<>) {
   33     if (/^(# Generated .+) on .+/) {
   34         flush_output;
   35         print $1, "\n";
   36     } elsif (/^#/) {
   37         next;
   38     } elsif (/^(\w+)tables -t (\w+) -([NAP]) (\S+)/ or
   39           /^(\w+)tables(?: --atomic-file \w+)? -t (\w+) -([FX])()$/) {
   40         my $key = $3 eq 'P' ? "$1 $2  $4" : "$1 $2 $4";
   41         $key .= ' z' if $4 eq '';
   42         my $array = $rules{$key} ||= [];
   43         push @$array, $_;
   44     } elsif (/^\*(\S+)/) {
   45         $table = $1;
   46         my $key = $table;
   47         my $array = $rules{$key} ||= [];
   48         push @$array, $_;
   49     } elsif (/^COMMIT/) {
   50         my $key = $table . 'z';
   51         my $array = $rules{$key} ||= [];
   52         push @$array, $_;
   53     } elsif (/^(:)(\S+)/ or /^-(A) (\S+)/) {
   54         my $key = $table . $1 . $2;
   55         my $array = $rules{$key} ||= [];
   56         push @$array, $_;
   57     } elsif (/^ebtables -t (\w+) --atomic-file (\S+) (\N+)/) {
   58         my $key = $2;
   59         my $array = $rules{$key} ||= [];
   60         push @$array, $_;
   61     } else {
   62         die;
   63     }
   64 }
   65 flush_output;