1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 13:37:48 +00:00

od: fix build

Just the minimal stuff needed to make od build again.  I have restrained
myself from making more invasive changes.
This commit is contained in:
Keunwoo Lee 2015-01-24 23:56:10 -08:00
parent 3739c82c95
commit 2d8e7f6dec

View file

@ -18,7 +18,7 @@ use std::io::File;
#[deriving(Show)] #[deriving(Show)]
enum Radix { Decimal, Hexadecimal, Octal, Binary } enum Radix { Decimal, Hexadecimal, Octal, Binary }
pub fn uumain(args: Vec<String>) -> int { pub fn uumain(args: Vec<String>) -> isize {
let opts = [ let opts = [
getopts::optopt("A", "address-radix", "Select the base in which file offsets are printed.", "RADIX"), getopts::optopt("A", "address-radix", "Select the base in which file offsets are printed.", "RADIX"),
getopts::optopt("j", "skip-bytes", "Skip bytes input bytes before formatting and writing.", "BYTES"), getopts::optopt("j", "skip-bytes", "Skip bytes input bytes before formatting and writing.", "BYTES"),
@ -31,23 +31,23 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("v", "version", "output version information and exit."), getopts::optflag("v", "version", "output version information and exit."),
]; ];
let matches = match getopts::getopts(args.tail(), opts) { let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m, Ok(m) => m,
Err(f) => fail!("Invalid options\n{}", f) Err(f) => panic!("Invalid options\n{}", f)
}; };
let mut rad = Octal; let mut rad = Radix::Octal;
if matches.opt_present("A") { if matches.opt_present("A") {
rad = parse_radix(matches.opt_str("A")); rad = parse_radix(matches.opt_str("A"));
} else { } else {
println!("{}", getopts::usage("od", opts)); println!("{}", getopts::usage("od", &opts));
} }
let mut fname; let mut fname;
match args.last() { match args.last() {
Some(n) => fname = n, Some(n) => fname = n,
None => { fail!("Need fname for now") ; } None => { panic!("Need fname for now") ; }
}; };
main(rad, fname.clone()); main(rad, fname.clone());
@ -58,22 +58,22 @@ pub fn uumain(args: Vec<String>) -> int {
fn main(radix: Radix, fname: String) { fn main(radix: Radix, fname: String) {
let mut f = match File::open(&Path::new(fname)) { let mut f = match File::open(&Path::new(fname)) {
Ok(f) => f, Ok(f) => f,
Err(e) => fail!("file error: {}", e) Err(e) => panic!("file error: {}", e)
}; };
let mut addr = 0; let mut addr = 0;
let mut bytes = [0, .. 16]; let bytes = &mut [b'\x00'; 16];
loop { loop {
match f.read(bytes) { match f.read(bytes) {
Ok(n) => { Ok(n) => {
print!("{:07o}", addr); print!("{:07o}", addr);
match radix { match radix {
Decimal => { Radix::Decimal => {
}, },
Octal => { Radix::Octal => {
for b in range(0, n/std::u16::BYTES) { for b in range(0, n/std::u16::BYTES) {
let bs = bytes.slice(2*b, 2*b+2); let bs = bytes.slice(2*b, 2*b+2);
let p: u16 = bs[1] as u16 << 8 | bs[0] as u16; let p: u16 = (bs[1] as u16) << 8 | bs[0] as u16;
print!(" {:06o}", p); print!(" {:06o}", p);
} }
if n % std::u16::BYTES == 1 { if n % std::u16::BYTES == 1 {
@ -95,23 +95,23 @@ fn parse_radix(radix_str: Option<String>) -> Radix {
Some(s) => { Some(s) => {
let st = s.into_bytes(); let st = s.into_bytes();
if st.len() != 1 { if st.len() != 1 {
fail!("Radix must be one of [d, o, b, x]\n"); panic!("Radix must be one of [d, o, b, x]\n");
} }
let radix: char = *st.get(0) as char; let radix: char = *(st.get(0).expect("byte string of length 1 lacks a 0th elem")) as char;
if radix == 'd' { if radix == 'd' {
Decimal Radix::Decimal
} else if radix == 'x' { } else if radix == 'x' {
Hexadecimal Radix::Hexadecimal
} else if radix == 'o' { } else if radix == 'o' {
Octal Radix::Octal
} else if radix == 'b' { } else if radix == 'b' {
Binary Radix::Binary
} else { } else {
fail!("Radix must be one of [d, o, b, x]\n"); panic!("Radix must be one of [d, o, b, x]\n");
} }
}, },
None => Octal None => Radix::Octal
}; };
rad rad