diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 9d98cc9..2f608df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,26 @@ macro_rules! unwrap { }; } +macro_rules! debug { + ($($arg:tt)*) => { + if debug_enabled() { + use std::io::Write; + let stderr = ::std::io::stderr(); + let mut lock = stderr.lock(); + write!(lock, "[d] "); + writeln!(lock, $($arg)*); + } + } +} + +static mut DEBUG_ENABLED: bool = false; + +/// Return whether or not debug output should be enabled. +#[inline] +fn debug_enabled() -> bool { + unsafe { DEBUG_ENABLED } +} + /// A program that allows you to search through all your evtc logs for specific /// people. #[derive(StructOpt, Debug)] @@ -65,6 +85,10 @@ pub struct Opt { #[structopt(long = "no-color")] no_color: bool, + /// Print more debugging information to stderr. + #[structopt(long = "debug")] + debug: bool, + /// The regular expression to search for. #[structopt(name = "EXPR")] expression: Regex, @@ -162,6 +186,11 @@ fn main() { colored::control::set_override(false); } + if opt.debug { + // We haven't started any threads here yet, so this is fine. + unsafe { DEBUG_ENABLED = true }; + } + let result = grep(&opt); match result { Ok(_) => {} @@ -216,6 +245,7 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeE let log = if let Some(e) = parsed { e } else { + debug!("log file cannot be parsed: {:?}", entry.path()); return Ok(None); }; @@ -233,9 +263,10 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeE /// Extract human-readable information from the given log file. fn extract_info(entry: &DirEntry, log: &Log) -> LogResult { let bosses = log.boss_agents(); - let boss_name = if bosses.len() == 1 { + let boss_name = if bosses.len() >= 1 { unwrap! { AgentName::Single(s) = bosses[0].name() => { s } } } else { + debug!("log file no boss agents: {:?}", entry.path()); "<unknown>" }.into(); @@ -324,6 +355,9 @@ fn get_profession_name(profession: u32, elite: u32) -> &'static str { (8, 60) => "Scourge", (9, 63) => "Renegade", - _ => "Unknown", + _ => { + debug!("Unknown spec (prof: {}, elite: {})", profession, elite); + "Unknown" + }, } } |