# HG changeset patch # User Florian Pose # Date 1157966565 0 # Node ID f557be43b8c78d41c2a9d3ee9884e4dc451401dc # Parent 277de5572f99c3887be5c1ccb86fa198ef1fc2ed lsec: advanced number formatting; no-lines option. diff -r 277de5572f99 -r f557be43b8c7 script/lsec.pl --- a/script/lsec.pl Mon Sep 11 08:52:41 2006 +0000 +++ b/script/lsec.pl Mon Sep 11 09:22:45 2006 +0000 @@ -42,6 +42,7 @@ use strict; use Getopt::Std; +my %opt; my $master_index; my $master_dir; my $term_width; @@ -55,27 +56,6 @@ #------------------------------------------------------------------------------ -sub get_terminal_width -{ - my $winsize; - die "no TIOCGWINSZ " unless defined &TIOCGWINSZ; - open(TTY, "+{'ring_position'} <=> $b->{'ring_position'} } @slaves; - print "EtherCAT bus listing for master $master_index:\n"; + $ring_cols = 0; + $adv_cols = 0; for $slave (@slaves) { - print_line if $slave->{'coupler'} eq "yes"; - $abs = sprintf "%i", $slave->{'ring_position'}; - printf(" %3s %8s %-6s %s\n", - $abs, $slave->{'advanced_position'}, + $cols = length $slave->{'ring_position'}; + $ring_cols = $cols if ($cols > $ring_cols); + $cols = length $slave->{'advanced_position'}; + $adv_cols = $cols if ($cols > $adv_cols); + } + $fmt = sprintf " %%%is %%-%is %%-6s %%s\n", $ring_cols, $adv_cols; + + for $slave (@slaves) { + &print_line if $slave->{'coupler'} eq "yes" and !defined $opt{n}; + printf($fmt, $slave->{'ring_position'}, $slave->{'advanced_position'}, $slave->{'state'}, $slave->{'name'}); } } @@ -146,18 +137,15 @@ sub get_options { - my %opt; - my $optret; + my $optret = getopts "m:nh", \%opt; - $optret = getopts "m:h", \%opt; + &print_usage if defined $opt{h} or $#ARGV > -1 or !$optret; - &print_usage if defined $opt{'h'} or $#ARGV > -1 or !$optret; - - if (defined $opt{'m'}) { - $master_index = $opt{'m'}; + if (defined $opt{m}) { + $master_index = $opt{m}; } else { - $master_index = 0; + $master_index = 0; } } @@ -165,12 +153,34 @@ sub print_usage { - my $cmd = `basename $0`; - chomp $cmd; + my $cmd = `basename $0`; + chomp $cmd; print "Usage: $cmd [OPTIONS]\n"; print " -m Query master .\n"; + print " -n Display no coupler lines.\n"; print " -h Show this help.\n"; exit 0; } #------------------------------------------------------------------------------ + +sub get_terminal_width +{ + my $winsize; + die "no TIOCGWINSZ " unless defined &TIOCGWINSZ; + open(TTY, "+