/****************************************************************************** * This program simply copies one file to another, line by line. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::error; use std::sync::Arc; fn copyTextFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc> { utf8mode(ifh); utf8mode(ofh); let mut line:&str = ""; while getline(line,ifh) { printLine(line,ofh); } close(ifh); close(ofh)?; } fn main() { if args.len() != 3 { println!("Syntax: {} {{fromFilespec}} {{toFilespec}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut fromFilespec:String = args[1]; let mut toFilespec:String = args[2]; match (|| -> Result<(), Arc>{ copyTextFile(&fromFilespec, &toFilespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }