diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index eb787b11da5..15238e39bc4 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -64,20 +64,41 @@ fn pad_and_print(result: &str, left: bool, width: usize, padding: Padding) { }; } -macro_rules! print_adjusted { - ($str: ident, $left: expr, $width: expr, $padding: expr) => { - let field_width = cmp::max($width, $str.len()); - pad_and_print(&$str, $left, field_width, $padding); - }; - ($str: ident, $left: expr, $need_prefix: expr, $prefix: expr, $width: expr, $padding: expr) => { - let mut field_width = cmp::max($width, $str.len()); - if $need_prefix { - field_width -= $prefix.len(); +fn print_adjusted( + s: &str, + left: bool, + need_prefix: Option, + prefix: Option<&str>, + width: usize, + padding: Padding, +) { + let mut field_width = cmp::max(width, s.len()); + if let Some(p) = prefix { + if let Some(needprefix) = need_prefix { + if needprefix { + field_width -= p.len(); + } } - pad_and_print(&$str, $left, field_width, $padding); - }; + pad_and_print(s, left, field_width, padding); + } else { + pad_and_print(s, left, field_width, padding); + } } +//macro_rules! print_adjusted { +//($str: ident, $left: expr, $width: expr, $padding: expr) => { +//let field_width = cmp::max($width, $str.len()); +//pad_and_print(&$str, $left, field_width, $padding); +//}; +//($str: ident, $left: expr, $need_prefix: expr, $prefix: expr, $width: expr, $padding: expr) => { +//let mut field_width = cmp::max($width, $str.len()); +//if $need_prefix { +//field_width -= $prefix.len(); +//} +//pad_and_print(&$str, $left, field_width, $padding); +//}; +//} + static ABOUT: &str = "Display file or file system status."; const USAGE: &str = "{} [OPTION]... FILE..."; @@ -286,7 +307,7 @@ fn print_it(arg: &str, output_type: &OutputType, flag: u8, width: usize, precisi } else { arg }; - print_adjusted!(s, left_align, width, Padding::Space); + print_adjusted(s, left_align, None, None, width, Padding::Space); } OutputType::Integer => { let arg = if has!(flag, F_GROUP) { @@ -296,7 +317,14 @@ fn print_it(arg: &str, output_type: &OutputType, flag: u8, width: usize, precisi }; let min_digits = cmp::max(precision, arg.len() as i32) as usize; let extended: Cow = extend_digits(arg.as_ref(), min_digits); - print_adjusted!(extended, left_align, has_sign, prefix, width, padding_char); + print_adjusted( + extended.as_ref(), + left_align, + Some(has_sign), + Some(prefix), + width, + padding_char, + ); } OutputType::Unsigned => { let arg = if has!(flag, F_GROUP) { @@ -306,30 +334,37 @@ fn print_it(arg: &str, output_type: &OutputType, flag: u8, width: usize, precisi }; let min_digits = cmp::max(precision, arg.len() as i32) as usize; let extended: Cow = extend_digits(arg.as_ref(), min_digits); - print_adjusted!(extended, left_align, width, padding_char); + print_adjusted( + extended.as_ref(), + left_align, + None, + None, + width, + padding_char, + ); } OutputType::UnsignedOct => { let min_digits = cmp::max(precision, arg.len() as i32) as usize; let extended: Cow = extend_digits(arg, min_digits); - print_adjusted!( - extended, + print_adjusted( + extended.as_ref(), left_align, - should_alter, - prefix, + Some(should_alter), + Some(prefix), width, - padding_char + padding_char, ); } OutputType::UnsignedHex => { let min_digits = cmp::max(precision, arg.len() as i32) as usize; let extended: Cow = extend_digits(arg, min_digits); - print_adjusted!( - extended, + print_adjusted( + extended.as_ref(), left_align, - should_alter, - prefix, + Some(should_alter), + Some(prefix), width, - padding_char + padding_char, ); } _ => unreachable!(),