From 3d44f04926cbfbb77ff7a2d13965a2ef1a44669e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 23 Jun 2024 21:18:30 +0200 Subject: [PATCH] Adds helper functions --- src/makepdf.rs | 9 ++++++--- src/makepdf_functions.rs | 43 ++++++++++++++++++++++++++++++++++++++-- src/makepdf_structs.rs | 1 + 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/makepdf.rs b/src/makepdf.rs index 2966b7a..edd9529 100644 --- a/src/makepdf.rs +++ b/src/makepdf.rs @@ -66,15 +66,18 @@ pub(crate) fn make_pdf(args: &MakeConfig, _config: &Config) -> Result<()> { ); }; - // Make the target to build - let file = make_file(args); // Identify special targets: Clean, Glossaries, All, List etc. match args.target { - Some(MakeTargets::All) => make_all(args, file), + Some(MakeTargets::All) => { + // Make the target to build + let file = make_file(args); + make_all(args, file) + } Some(MakeTargets::List) => make_list(args), Some(MakeTargets::Glossaries) => make_glossaries(args), Some(MakeTargets::Clean) => make_clean(args), None => { + let file = make_file(args); launch_subprocess(args, file).unwrap(); } } diff --git a/src/makepdf_functions.rs b/src/makepdf_functions.rs index 2a9dc25..a5d2224 100644 --- a/src/makepdf_functions.rs +++ b/src/makepdf_functions.rs @@ -5,6 +5,7 @@ use std::{ fs::File, io::{Read, Write}, path::{Path, PathBuf}, + process::Command, sync::LazyLock, }; @@ -182,10 +183,48 @@ pub(crate) fn simplify_add( /// Make the glossaries pub(crate) fn make_glossaries(args: &MakeConfig) { - todo!() + use std::str; + match Command::new("makeglossaries") + .arg(format!("{:?}", target_name(&args.filename))) + .output() + { + Err(e) => { + println!( + "An error has occured while trying to build the glossaries\n{:#?}", + e + ) + } + Ok(o) => { + println!("Program exited with status {}", o.status); + if !o.stdout.is_empty() { + println!("{:?}", str::from_utf8(&o.stdout)); + } + if !o.stderr.is_empty() { + println!("{:?}", str::from_utf8(&o.stderr)); + } + } + } } /// Make the working directory clean, by eliminating all temporary files pub(crate) fn make_clean(args: &MakeConfig) { - todo!() + let _ = args; + let target = format!("{:?}", Path::new(&args.filename).file_stem().unwrap()); + let list_suff = [ + ".aux", ".glg", ".glo", ".gls", ".ist", ".log", ".out", ".tex", ".toc", + ]; + 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!("{}_build{}", &target[1..target.len() - 1], ".tex")); + + if let Err(e) = cmd.output() { + println!( + "[ERRR] An error has occured when executing the clean target \n {:#?}", + e + ) + } } diff --git a/src/makepdf_structs.rs b/src/makepdf_structs.rs index 2cd6d4d..5dadd96 100644 --- a/src/makepdf_structs.rs +++ b/src/makepdf_structs.rs @@ -183,6 +183,7 @@ pub(crate) enum LineType { StartingSequence, /// Strange end sequence + #[token("{/usr/share")] #[token(" ){/")] EndSequence,