From b0b654b056b0a838221ca4be5efec416a10a04e1 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 23 Jun 2024 21:55:36 +0200 Subject: [PATCH] Corrects utilities and timing --- src/makepdf_functions.rs | 31 ++++++++++++++++++++++--------- src/makepdf_structs.rs | 9 ++++++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/makepdf_functions.rs b/src/makepdf_functions.rs index a5d2224..ea59379 100644 --- a/src/makepdf_functions.rs +++ b/src/makepdf_functions.rs @@ -136,6 +136,14 @@ pub(crate) fn target_name(target: &str) -> PathBuf { target_oss.into() } +/// Create a target suffix and by append _build +pub(crate) fn target_pref(target: &str) -> String { + let target = Path::new(target); + let target_oss = target.file_stem().unwrap().to_owned(); + let v = format!("{:?}", target_oss); + v[1..v.len() - 1].to_string() +} + /// Try to add a simplified entry to a list pub(crate) fn simplify_add( entry: String, @@ -184,8 +192,12 @@ pub(crate) fn simplify_add( /// Make the glossaries pub(crate) fn make_glossaries(args: &MakeConfig) { use std::str; + // let name = format!("{:?}", target_name(&args.filename)); + // let name = &name[1..name.len() - 1]; + // println!("{}", name); + let name = target_pref(&args.filename); match Command::new("makeglossaries") - .arg(format!("{:?}", target_name(&args.filename))) + .arg(format!("{}_build", name)) .output() { Err(e) => { @@ -197,10 +209,10 @@ pub(crate) fn make_glossaries(args: &MakeConfig) { Ok(o) => { println!("Program exited with status {}", o.status); if !o.stdout.is_empty() { - println!("{:?}", str::from_utf8(&o.stdout)); + println!("{}", str::from_utf8(&o.stdout).unwrap_or("")); } if !o.stderr.is_empty() { - println!("{:?}", str::from_utf8(&o.stderr)); + println!("{}", str::from_utf8(&o.stderr).unwrap_or("")); } } } @@ -209,18 +221,19 @@ pub(crate) fn make_glossaries(args: &MakeConfig) { /// Make the working directory clean, by eliminating all temporary files pub(crate) fn make_clean(args: &MakeConfig) { let _ = args; - let target = format!("{:?}", Path::new(&args.filename).file_stem().unwrap()); + // let target = format!("{:?}", Path::new(&args.filename).file_stem().unwrap()); + let target = target_pref(&args.filename); let list_suff = [ - ".aux", ".glg", ".glo", ".gls", ".ist", ".log", ".out", ".tex", ".toc", + ".aux", ".glg", ".glo", ".gls", ".ist", ".log", ".out", ".toc", ".pdf", ]; let mut cmd = Command::new("rm"); for s in list_suff { // The most ghetto *** I've done so far - cmd.arg(format!("{}{}", &target[1..target.len() - 1], s)); - cmd.arg(format!("{}_build{}", &target[1..target.len() - 1], s)); + cmd.arg(format!("{}{}", &target, s)); + cmd.arg(format!("{}_build{}", &target, s)); } - cmd.arg(format!("{}_build{}", &target[1..target.len() - 1], ".tex")); - + cmd.arg(format!("{}_build{}", &target, ".tex")); + // println!("{:?}", cmd); if let Err(e) = cmd.output() { println!( "[ERRR] An error has occured when executing the clean target \n {:#?}", diff --git a/src/makepdf_structs.rs b/src/makepdf_structs.rs index 5dadd96..43713cf 100644 --- a/src/makepdf_structs.rs +++ b/src/makepdf_structs.rs @@ -158,7 +158,14 @@ impl BuildInfo { /// Add a level to a chapter pub(crate) fn add_lap(&mut self, started: &Instant, chap: &String) { let _ = chap; - self.time_spent.push(started.elapsed()); + let a = if let Some(t) = self.time_spent.last() { + t + } else { + &Duration::from_secs(0) + }; + + self.time_spent + .push(started.elapsed().checked_sub(*a).unwrap()); } }