From f89dc6585d859754ff25ec5c9f3bd61d0caab7d3 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Sun, 2 Jan 2022 10:33:41 -0500 Subject: [PATCH] unexpand: return UResult from uumain() function --- src/uu/unexpand/src/unexpand.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 95383b89d..1b227e4ce 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -17,6 +17,7 @@ use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Stdout, Write} use std::str::from_utf8; use unicode_width::UnicodeWidthChar; use uucore::display::Quotable; +use uucore::error::{FromIo, UResult}; use uucore::InvalidEncodingHandling; static NAME: &str = "unexpand"; @@ -90,16 +91,15 @@ impl Options { } } -pub fn uumain(args: impl uucore::Args) -> i32 { +#[uucore_procs::gen_uumain] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); let matches = uu_app().get_matches_from(args); - unexpand(Options::new(matches)); - - 0 + unexpand(Options::new(matches)).map_err_context(String::new) } pub fn uu_app() -> App<'static, 'static> { @@ -242,7 +242,7 @@ fn next_char_info(uflag: bool, buf: &[u8], byte: usize) -> (CharType, usize, usi (ctype, cwidth, nbytes) } -fn unexpand(options: Options) { +fn unexpand(options: Options) -> std::io::Result<()> { let mut output = BufWriter::new(stdout()); let ts = &options.tabstops[..]; let mut buf = Vec::new(); @@ -273,7 +273,7 @@ fn unexpand(options: Options) { init, true, ); - crash_if_err!(1, output.write_all(&buf[byte..])); + output.write_all(&buf[byte..])?; scol = col; break; } @@ -293,7 +293,7 @@ fn unexpand(options: Options) { }; if !tabs_buffered { - crash_if_err!(1, output.write_all(&buf[byte..byte + nbytes])); + output.write_all(&buf[byte..byte + nbytes])?; scol = col; // now printed up to this column } } @@ -318,7 +318,7 @@ fn unexpand(options: Options) { } else { 0 }; - crash_if_err!(1, output.write_all(&buf[byte..byte + nbytes])); + output.write_all(&buf[byte..byte + nbytes])?; scol = col; // we've now printed up to this column } } @@ -337,9 +337,9 @@ fn unexpand(options: Options) { init, true, ); - crash_if_err!(1, output.flush()); + output.flush()?; buf.truncate(0); // clear out the buffer } } - crash_if_err!(1, output.flush()) + output.flush() }