summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@vyatta.com>2008-03-28 12:05:44 -0700
committerStig Thormodsrud <stig@vyatta.com>2008-03-28 12:05:44 -0700
commitb882a56f1861a43881d7cd11e7c85dfdd04b6502 (patch)
tree1bbf611247dea7f9174dfd6344261a23586659d8 /scripts
parent00950b2a56361cb71fb4bf3070667ae4bd593e5b (diff)
downloadvyatta-op-b882a56f1861a43881d7cd11e7c85dfdd04b6502.tar.gz
vyatta-op-b882a56f1861a43881d7cd11e7c85dfdd04b6502.zip
Fix 3062: "Show interfaces" displays interfaces in lexicographic, not numeric, order
Diffstat (limited to 'scripts')
-rw-r--r--scripts/vyatta-show-interfaces.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/vyatta-show-interfaces.pl b/scripts/vyatta-show-interfaces.pl
index 092f147..0ec5d3e 100644
--- a/scripts/vyatta-show-interfaces.pl
+++ b/scripts/vyatta-show-interfaces.pl
@@ -335,6 +335,39 @@ sub run_reset_intf {
}
}
+sub alphanum_split {
+ my ($str) = @_;
+ my @list = split m/(?=(?<=\D)\d|(?<=\d)\D)/, $str;
+ return @list;
+}
+
+sub natural_order {
+ my ($a, $b) = @_;
+ my @a = alphanum_split($a);
+ my @b = alphanum_split($b);
+
+ while (@a && @b) {
+ my $a_seg = shift @a;
+ my $b_seg = shift @b;
+ my $val;
+ if (($a_seg =~ /\d/) && ($b_seg =~ /\d/)) {
+ $val = $a_seg <=> $b_seg;
+ } else {
+ $val = $a_seg cmp $b_seg;
+ }
+ if ($val != 0) {
+ return $val;
+ }
+ }
+ return @a <=> @b;
+}
+
+sub intf_sort {
+ my @a = @_;
+ my @new_a = sort { natural_order($a,$b) } @a;
+ return @new_a;
+}
+
#
# main
@@ -369,6 +402,8 @@ if (! defined $action) {
$action = 'show';
}
+@intf_list = intf_sort(@intf_list);
+
my $func;
if (defined $action_hash{$action}) {
$func = $action_hash{$action};