-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
od: add support for -S #8849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
od: add support for -S #8849
Conversation
GNU testsuite comparison:
|
// Test with -S10 to filter out short strings | ||
new_ucmd!() | ||
.arg("-S10") | ||
.pipe_in(b"\x01 \x00 \x00") | ||
.succeeds() | ||
.stdout_is("0000001 \n0000014 \n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a disconnect between the comment and the code: there are no short strings in the piped in data that could be filtered out ;-)
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
GNU testsuite comparison:
|
let expected = format!("0000000 {}\n", " ".repeat(100)); | ||
new_ucmd!() | ||
.arg("-N100") | ||
.arg("-S1") | ||
.pipe_in([b' '; 100]) | ||
.succeeds() | ||
.stdout_is(&expected); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could show the same with a single-digit -N
value.
translate!("od-error-invalid-argument", "option" => "-S", "value" => s.quote()), | ||
) | ||
})?; | ||
if n == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GNU od
allows 0
:
$ printf "hello\x0world\x0" | od -S0
0000000 hello
0000006 world
Ok(n) => Some(n), | ||
Err(e) => { | ||
Some(s) => { | ||
let n = s.parse::<usize>().map_err(|_| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have to use I think you can use parse_number_of_bytes
here.parse_bytes_option
to handle options::STRINGS
.
line_bytes: usize, | ||
output_duplicates: bool, | ||
radix: Radix, | ||
string_min_length: Option<usize>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Probably yes, you seem to use it to mark a "strings mode".string_min_length
have to be an Option
?
"output strings of at least BYTES graphic chars. 3 is assumed when \ | ||
BYTES is not specified.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of just modifying the string, you could move it to the ftl files and use translate!
here.
} | ||
|
||
/// String search mode for od -S option | ||
fn strings_mode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there is a better name for this function?
if radix == Radix::NoPrefix { | ||
println!("{string_content}"); | ||
} else { | ||
let offset_str = match radix { | ||
Radix::Decimal => format!("{offset:07}"), | ||
Radix::Hexadecimal => format!("{offset:07x}"), | ||
Radix::Octal => format!("{offset:07o}"), | ||
Radix::NoPrefix => unreachable!(), | ||
}; | ||
println!("{offset_str} {string_content}"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it might be an option to do everything in the match
to get rid of the unreachable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
should fix tests/od/od-N