/****************************************************************************** * This program reads bytes from a file and prints them in decimal format. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::env; use std::error; use std::sync::Arc; fn readBinaryFile(filespec:&str) -> Result<(), Arc> { binmode(ifh); let mut c:u8 = 0; let mut count:isize = 0; while getbyte(c,ifh) { print!("{} ", c); count += 1; if count % 20 == 0 { println!(""); } } if count % 20 != 0 { println!(""); } close(ifh)?; } fn main() { let args: Vec = env::args().collect(); if args.len() != 2 { println!("Syntax: {} {{filename}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut filespec:String = args[1]; match (|| -> Result<(), Arc>{ readBinaryFile(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }