diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index dff712e92..db0d3729b 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -60,8 +60,9 @@ impl Input { let print_level = parseargs::parse_status_level(matches)?; let cflags = parseargs::parse_conv_flag_input(matches)?; let iflags = parseargs::parse_iflags(matches)?; - let skip = parseargs::parse_skip_amt(&ibs, &iflags, matches)?; - let iseek = parseargs::parse_iseek_amt(&ibs, &iflags, matches)?; + let skip = parseargs::parse_seek_skip_amt(&ibs, iflags.skip_bytes, matches, options::SKIP)?; + let iseek = + parseargs::parse_seek_skip_amt(&ibs, iflags.skip_bytes, matches, options::ISEEK)?; let count = parseargs::parse_count(&iflags, matches)?; let mut i = Self { @@ -134,8 +135,9 @@ impl Input { let print_level = parseargs::parse_status_level(matches)?; let cflags = parseargs::parse_conv_flag_input(matches)?; let iflags = parseargs::parse_iflags(matches)?; - let skip = parseargs::parse_skip_amt(&ibs, &iflags, matches)?; - let iseek = parseargs::parse_iseek_amt(&ibs, &iflags, matches)?; + let skip = parseargs::parse_seek_skip_amt(&ibs, iflags.skip_bytes, matches, options::SKIP)?; + let iseek = + parseargs::parse_seek_skip_amt(&ibs, iflags.skip_bytes, matches, options::ISEEK)?; let count = parseargs::parse_count(&iflags, matches)?; if let Some(fname) = matches.value_of(options::INFILE) { @@ -298,8 +300,9 @@ impl OutputTrait for Output { let obs = parseargs::parse_obs(matches)?; let cflags = parseargs::parse_conv_flag_output(matches)?; let oflags = parseargs::parse_oflags(matches)?; - let seek = parseargs::parse_seek_amt(&obs, &oflags, matches)?; - let oseek = parseargs::parse_oseek_amt(&obs, &oflags, matches)?; + let seek = parseargs::parse_seek_skip_amt(&obs, oflags.seek_bytes, matches, options::SEEK)?; + let oseek = + parseargs::parse_seek_skip_amt(&obs, oflags.seek_bytes, matches, options::OSEEK)?; let mut dst = io::stdout(); @@ -517,8 +520,9 @@ impl OutputTrait for Output { let obs = parseargs::parse_obs(matches)?; let cflags = parseargs::parse_conv_flag_output(matches)?; let oflags = parseargs::parse_oflags(matches)?; - let seek = parseargs::parse_seek_amt(&obs, &oflags, matches)?; - let oseek = parseargs::parse_oseek_amt(&obs, &oflags, matches)?; + let seek = parseargs::parse_seek_skip_amt(&obs, oflags.seek_bytes, matches, options::SEEK)?; + let oseek = + parseargs::parse_seek_skip_amt(&obs, oflags.seek_bytes, matches, options::OSEEK)?; if let Some(fname) = matches.value_of(options::OUTFILE) { let mut dst = open_dst(Path::new(&fname), &cflags, &oflags) diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index db2df4132..75703b629 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -740,15 +740,15 @@ pub fn parse_oflags(matches: &Matches) -> Result { Ok(oflags) } -/// Parse the amount of the input file to skip. -pub fn parse_skip_amt( +pub fn parse_seek_skip_amt( ibs: &usize, - iflags: &IFlags, + bytes: bool, matches: &Matches, + option: &str, ) -> Result, ParseError> { - if let Some(amt) = matches.value_of(options::SKIP) { + if let Some(amt) = matches.value_of(option) { let n = parse_bytes_with_opt_multiplier(amt)?; - if iflags.skip_bytes { + if bytes { Ok(Some(n)) } else { Ok(Some(*ibs as u64 * n)) @@ -758,60 +758,6 @@ pub fn parse_skip_amt( } } -/// Parse the amount of the output file to seek. -pub fn parse_seek_amt( - obs: &usize, - oflags: &OFlags, - matches: &Matches, -) -> Result, ParseError> { - if let Some(amt) = matches.value_of(options::SEEK) { - let n = parse_bytes_with_opt_multiplier(amt)?; - if oflags.seek_bytes { - Ok(Some(n)) - } else { - Ok(Some(*obs as u64 * n)) - } - } else { - Ok(None) - } -} - -/// Parse the amount of the input file to seek. -pub fn parse_iseek_amt( - ibs: &usize, - iflags: &IFlags, - matches: &Matches, -) -> Result, ParseError> { - if let Some(amt) = matches.value_of(options::ISEEK) { - let n = parse_bytes_with_opt_multiplier(amt)?; - if iflags.skip_bytes { - Ok(Some(n)) - } else { - Ok(Some(*ibs as u64 * n)) - } - } else { - Ok(None) - } -} - -/// Parse the amount of the input file to seek. -pub fn parse_oseek_amt( - obs: &usize, - oflags: &OFlags, - matches: &Matches, -) -> Result, ParseError> { - if let Some(amt) = matches.value_of(options::OSEEK) { - let n = parse_bytes_with_opt_multiplier(amt)?; - if oflags.seek_bytes { - Ok(Some(n)) - } else { - Ok(Some(*obs as u64 * n)) - } - } else { - Ok(None) - } -} - /// Parse the value of count=N and the type of N implied by iflags pub fn parse_count(iflags: &IFlags, matches: &Matches) -> Result, ParseError> { if let Some(amt) = matches.value_of(options::COUNT) { diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index a29008c2c..5fae63c73 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -142,25 +142,25 @@ fn test_all_top_level_args_no_leading_dashes() { ); assert_eq!( 200, - parse_skip_amt(&100, &IFlags::default(), &matches) + parse_seek_skip_amt(&100, IFlags::default().skip_bytes, &matches, options::SKIP) .unwrap() .unwrap() ); assert_eq!( 200, - parse_seek_amt(&100, &OFlags::default(), &matches) + parse_seek_skip_amt(&100, OFlags::default().seek_bytes, &matches, options::SEEK) .unwrap() .unwrap() ); assert_eq!( 200, - parse_iseek_amt(&100, &IFlags::default(), &matches) + parse_seek_skip_amt(&100, IFlags::default().skip_bytes, &matches, options::ISEEK) .unwrap() .unwrap() ); assert_eq!( 200, - parse_oseek_amt(&100, &OFlags::default(), &matches) + parse_seek_skip_amt(&100, OFlags::default().seek_bytes, &matches, options::OSEEK) .unwrap() .unwrap() ); @@ -241,25 +241,25 @@ fn test_all_top_level_args_with_leading_dashes() { ); assert_eq!( 200, - parse_skip_amt(&100, &IFlags::default(), &matches) + parse_seek_skip_amt(&100, IFlags::default().skip_bytes, &matches, options::SKIP) .unwrap() .unwrap() ); assert_eq!( 200, - parse_seek_amt(&100, &OFlags::default(), &matches) + parse_seek_skip_amt(&100, OFlags::default().seek_bytes, &matches, options::SEEK) .unwrap() .unwrap() ); assert_eq!( 200, - parse_iseek_amt(&100, &IFlags::default(), &matches) + parse_seek_skip_amt(&100, IFlags::default().skip_bytes, &matches, options::ISEEK) .unwrap() .unwrap() ); assert_eq!( 200, - parse_oseek_amt(&100, &OFlags::default(), &matches) + parse_seek_skip_amt(&100, OFlags::default().seek_bytes, &matches, options::OSEEK) .unwrap() .unwrap() ); @@ -413,7 +413,7 @@ fn test_override_multiple_options() { // skip assert_eq!( 200, - parse_skip_amt(&100, &IFlags::default(), &matches) + parse_seek_skip_amt(&100, IFlags::default().skip_bytes, &matches, options::SKIP) .unwrap() .unwrap() ); @@ -421,7 +421,7 @@ fn test_override_multiple_options() { // seek assert_eq!( 200, - parse_seek_amt(&100, &OFlags::default(), &matches) + parse_seek_skip_amt(&100, OFlags::default().seek_bytes, &matches, options::SEEK) .unwrap() .unwrap() ); @@ -429,7 +429,7 @@ fn test_override_multiple_options() { // iseek assert_eq!( 200, - parse_iseek_amt(&100, &IFlags::default(), &matches) + parse_seek_skip_amt(&100, IFlags::default().skip_bytes, &matches, options::ISEEK) .unwrap() .unwrap() ); @@ -437,7 +437,7 @@ fn test_override_multiple_options() { // oseek assert_eq!( 200, - parse_oseek_amt(&100, &OFlags::default(), &matches) + parse_seek_skip_amt(&100, OFlags::default().seek_bytes, &matches, options::OSEEK) .unwrap() .unwrap() );