1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

od: improve/extend --help text

This commit is contained in:
Wim Hueskes 2016-08-19 22:43:52 +02:00
parent 2f12b06ba1
commit d705dc46ce
3 changed files with 45 additions and 10 deletions

1
Cargo.lock generated
View file

@ -666,7 +666,6 @@ dependencies = [
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"unindent 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uucore 0.0.1", "uucore 0.0.1",
] ]

View file

@ -10,7 +10,6 @@ path = "od.rs"
[dependencies] [dependencies]
getopts = "*" getopts = "*"
libc = "*" libc = "*"
unindent = "*"
byteorder = "*" byteorder = "*"
uucore = { path="../uucore" } uucore = { path="../uucore" }

View file

@ -10,7 +10,6 @@
*/ */
extern crate getopts; extern crate getopts;
extern crate unindent;
extern crate byteorder; extern crate byteorder;
#[macro_use] #[macro_use]
@ -32,7 +31,6 @@ mod mockstream;
use std::cmp; use std::cmp;
use std::io::Write; use std::io::Write;
use unindent::*;
use byteorder_io::*; use byteorder_io::*;
use multifilereader::*; use multifilereader::*;
use partialreader::*; use partialreader::*;
@ -50,6 +48,50 @@ const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum Radix { Decimal, Hexadecimal, Octal, NoPrefix } enum Radix { Decimal, Hexadecimal, Octal, NoPrefix }
static USAGE: &'static str =
r#"Usage:
od [OPTION]... [--] [FILENAME]...
od [-abcdDefFhHiIlLoOsxX] [FILENAME] [[+][0x]OFFSET[.][b]]
od --traditional [OPTION]... [FILENAME] [[+][0x]OFFSET[.][b] [[+][0x]LABEL[.][b]]]
Displays data in various human-readable formats. If multiple formats are
specified, the output will contain all formats in the order they appear on the
commandline. Each format will be printed on a new line. Only the line
containing the first format will be prefixed with the offset.
If no filename is specified, or it is "-", stdin will be used. After a "--", no
more options will be recognised. This allows for filenames starting with a "-".
If a filename is a valid number which can be used as an offset in the second
form, you can force it to be recognised as a filename if you include an option
like "-j0", which is only valid in the first form.
RADIX is one of o,d,x,n for octal, decimal, hexadecimal or none.
BYTES is decimal by default, octal if prefixed with a "0", or hexadecimal if
prefixed with "0x". The suffixes b, KB, K, MB, M, GB, G, will multiply the
number with 512, 1000, 1024, 1000^2, 1024^2, 1000^3, 1024^3, 1000^2, 1024^2.
OFFSET and LABEL are octal by default, hexadecimal if prefixed with "0x" or
decimal if a "." suffix is added. The "b" suffix will multiply with 512.
TYPE contains one or more format specifications consisting of:
a for printable 7-bits ASCII
c for utf-8 characters or octal for undefined characters
d[SIZE] for signed decimal
f[SIZE] for floating point
o[SIZE] for octal
u[SIZE] for unsigned decimal
x[SIZE] for hexadecimal
SIZE is the number of bytes which can be the number 1, 2, 4, 8 or 16,
or C, I, S, L for 1, 2, 4, 8 bytes for integer types,
or F, D, L for 4, 8, 16 bytes for floating point.
Any type specification can have a "z" suffic, which will add a ASCII dump at
the end of the line.
If an error occurred, a diagnostic message will be printed to stderr, and the
exitcode will be non-zero."#;
pub fn uumain(args: Vec<String>) -> i32 { pub fn uumain(args: Vec<String>) -> i32 {
let mut opts = getopts::Options::new(); let mut opts = getopts::Options::new();
@ -106,12 +148,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
}; };
if matches.opt_present("h") { if matches.opt_present("h") {
let msg = unindent(&format!(" println!("{}", opts.usage(&USAGE));
Usage:
{0} [OPTION]... [FILENAME]...
Displays data in various human-readable formats.", executable!()));
println!("{}", opts.usage(&msg));
return 0; return 0;
} }
if matches.opt_present("version") { if matches.opt_present("version") {