From e6fd22db8d26923ac244f16783d548726505a5a1 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 23 Jun 2024 05:12:29 +0200 Subject: [PATCH 1/2] Adds targets, fix help message --- src/makepdf.rs | 53 +++++++++++++++++++++++++++++++++++------- src/makepdf_structs.rs | 13 +++++++---- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/makepdf.rs b/src/makepdf.rs index 7edad04..c92f20a 100644 --- a/src/makepdf.rs +++ b/src/makepdf.rs @@ -15,32 +15,66 @@ use clap::Args; use std::process::Stdio; use crate::makepdf_structs::{ - BuildInfo, LineType, Status, VerboseLevel, COL_NORMAL, TXT_BOXX, TXT_CNTX, TXT_CRIT, TXT_ERRR, - TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN, + BuildInfo, LineType, Status, VerboseLevel, COL_NORMAL, MAKE_VERBOSITY_LEVEL, TXT_BOXX, + TXT_CNTX, TXT_CRIT, TXT_ERRR, TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN, }; use crate::Config; #[derive(Args, Debug, Clone)] +#[command(after_help = format!("{} {}","VERBOSITY:",MAKE_VERBOSITY_LEVEL.as_str()))] /// The configuration struct for the PdfMaker pub(crate) struct MakeConfig { /// The filename to compile - pub(crate) filename: String, + pub(crate) target: String, + /// The verbosity level #[arg(short, long, default_value = "warning")] pub(crate) verbosity: VerboseLevel, - // /// The list of whitelisted verbosity levels - // pub(crate) whitelist: Vec, - // /// The list of blacklisted verbosity levels - // pub(crate) blacklist: Vec, + + /// switch to non interactive mode + #[arg(short = 'N', long, default_value_t = false)] + pub(crate) non_interactive: bool, + + /// Select only these targets + #[arg(short, long, value_name = "FILE", group = "select")] + pub(crate) only: Vec, + + /// Deselect these targets + #[arg(short, long, value_name = "FILE", group = "select")] + pub(crate) no: Vec, } /// Make a pdf spawning a subprocess pub(crate) fn make_pdf(args: &MakeConfig, config: &Config) -> Result<()> { let _ = config; + // Identify special targets: Clean, Glossaries, All, List etc. + match args.target.as_str() { + "all" => make_all(args), + "clean" => make_clean(args), + "list" => make_list(args), + "glossaries" => make_glossaries(args), + _ => (), + } launch_subprocess(args).unwrap(); Ok(()) } +fn make_list(args: &MakeConfig) { + todo!() +} + +fn make_glossaries(args: &MakeConfig) { + todo!() +} + +fn make_all(args: &MakeConfig) { + todo!() +} + +fn make_clean(args: &MakeConfig) { + todo!() +} + #[tokio::main] /// Pdfreading and curating async fn launch_subprocess(args: &MakeConfig) -> Result { @@ -54,7 +88,10 @@ async fn launch_subprocess(args: &MakeConfig) -> Result { let mut built = 0; let to_build = last_run.lines_parsed; - cmd.arg(&args.filename); + cmd.arg(&args.target); + if args.non_interactive { + cmd.arg("--interaction=batchmode"); + } cmd.env("max_print_line", "3000"); // Specify that we want the command's standard output piped back to us. cmd.stdout(Stdio::piped()); diff --git a/src/makepdf_structs.rs b/src/makepdf_structs.rs index a4ea9e7..ab90597 100644 --- a/src/makepdf_structs.rs +++ b/src/makepdf_structs.rs @@ -92,16 +92,21 @@ static STR_TO_TARGET: phf::Map<&'static str, VerboseLevel> = phf_map! { "critical" => VerboseLevel::Critical, }; +/// List all targets +pub(crate) static MAKE_VERBOSITY_LEVEL: LazyLock = LazyLock::new(|| { + let mut targets = STR_TO_TARGET.values().collect::>(); + targets.sort(); + format!("{:?}", targets) +}); + impl From<&str> for VerboseLevel { fn from(value: &str) -> Self { if let Some(target) = STR_TO_TARGET.get(&value.to_lowercase()).cloned() { target } else { - let mut targets = STR_TO_TARGET.values().collect::>(); - targets.sort(); panic!( "Invalid debug level {}. The debug level available are (from highest verbosity to lowest): {:?}", - value, targets + value, MAKE_VERBOSITY_LEVEL ) } } @@ -128,7 +133,7 @@ impl BuildInfo { /// Create a new empty run pub fn new(args: &MakeConfig) -> Self { Self { - filename: args.filename.clone(), + filename: args.target.clone(), // options: args.update_from_arg_matches, options: Vec::new(), lines_parsed: 0, -- 2.45.1 From fb8b8b0dbf1f958a8be6a63c3a3255ad3440af98 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 23 Jun 2024 05:27:17 +0200 Subject: [PATCH 2/2] Fixes the nonstopmode, adds false negatives --- src/makepdf.rs | 4 ++-- src/makepdf_structs.rs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/makepdf.rs b/src/makepdf.rs index c92f20a..5be971b 100644 --- a/src/makepdf.rs +++ b/src/makepdf.rs @@ -88,10 +88,10 @@ async fn launch_subprocess(args: &MakeConfig) -> Result { let mut built = 0; let to_build = last_run.lines_parsed; - cmd.arg(&args.target); if args.non_interactive { - cmd.arg("--interaction=batchmode"); + cmd.arg("--interaction=nonstopmode"); } + cmd.arg(&args.target); cmd.env("max_print_line", "3000"); // Specify that we want the command's standard output piped back to us. cmd.stdout(Stdio::piped()); diff --git a/src/makepdf_structs.rs b/src/makepdf_structs.rs index ab90597..8d206b5 100644 --- a/src/makepdf_structs.rs +++ b/src/makepdf_structs.rs @@ -220,7 +220,8 @@ pub(crate) enum LineType { MissingReference(String), /// Generic Latex Warning - #[regex(r"(LaTex |Warning:){2}[^\n]+", |lex| lex.slice()[14..].to_string())] + // TODO: Just use a Prs like the others + #[regex(r"(LaTex |Warning:)+[^\n]+", |lex| lex.slice()[14..].to_string())] Warning(String), // /// Runaway argument @@ -232,6 +233,7 @@ pub(crate) enum LineType { /// Context, mosty for boxes // TODO: False positives / Reparsing Context("10") )) [107] (./Ecoles/Protecteur.tex + // TODO: uncaught: [UKNW] [3] [4] (./Chapters/Intro.tex (/usr/share/texmf/tex/latex/lm/ot1lmr.fd) (/usr/share/texmf/tex/latex/lm/omllmm.fd) (/usr/share/texmf/tex/latex/lm/omslmsy.fd) (/usr/share/texmf/tex/latex/lm/omxlmex.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/microtype/mt-msa.cfg) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) (/usr/share/texlive/texmf-dist/tex/latex/microtype/mt-msb.cfg) (/usr/share/texmf/tex/latex/lm/ts1lmr.fd)) [5 <./Images//Ico/LogoNoush.jpg>] [6] #[regex(r"\[\d[^\]]+", |lex| lex.slice()[1..lex.slice().len()-1].to_string())] Context(String), @@ -388,8 +390,9 @@ pub(crate) struct Status { impl Status { /// Add a recoverable error to the list of errors + // TODO: Print this at the end of the parse pub(crate) fn add_error(&mut self, error_msg: String) { - self.errors += 1; + // self.errors += 1; self.v_errors.push(error_msg); } } -- 2.45.1