From ce5c445fd431f108e73bbe62b0ee73b8418d85c1 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 6 Aug 2023 17:22:53 +0200 Subject: Make the -e flag work as intended --- src/main.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index bc00355..23a0bf6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,12 +5,14 @@ use std::{ ffi::OsString, fs, hash::{Hash, Hasher}, - io::{self, BufRead, BufReader, BufWriter, Write}, + io::{self, BufRead, BufReader, BufWriter, Read, Write}, iter, path::{Component, Path, PathBuf}, process::{self, Command, Stdio}, }; +use itertools::Itertools; + use { cerm::{err, warn}, tempfile::tempdir, @@ -48,14 +50,22 @@ fn work() -> Result<(), io::Error> { let (cmd, args) = rest.split_first().unwrap_or_else(|| usage(None)); // Collect sources from standard input - let srcs: Vec<_> = io::stdin() - .lines() - .map(|x| match x { - Err(e) => { err!("{e}"); }, - Ok(l) if l.is_empty() => usage(None), - Ok(l) => l, + let srcs = io::stdin() + .bytes() + .map(|x| { + x.unwrap_or_else(|e| { + err!("{e}"); + }) }) - .collect(); + .group_by(|b| *b == (b'\0' + b'\n' * !flags.nul as u8)); + let srcs = srcs + .into_iter() + .filter(|(x, _)| !x) + .map(|(_, x)| String::from_utf8(x.collect_vec())) + .collect::, _>>() + .unwrap_or_else(|e| { + err!("{e}"); + }); // Spawn the child process let mut child = Command::new(cmd) -- cgit v1.2.3