Corrects utilities and timing

This commit is contained in:
Dandaedre 2024-06-23 21:55:36 +02:00
parent 3d44f04926
commit b0b654b056
2 changed files with 30 additions and 10 deletions

View File

@ -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 {:#?}",

View File

@ -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());
}
}