diff --git a/Cargo.lock b/Cargo.lock index a0401cb..e5e9db8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,11 +2,20 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540" dependencies = [ "anstyle", "anstyle-parse", @@ -52,9 +61,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" dependencies = [ "clap_builder", "clap_derive", @@ -62,9 +71,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" dependencies = [ "anstream", "anstyle", @@ -96,23 +105,66 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "itoa" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + [[package]] name = "pcgtools" version = "0.1.0" dependencies = [ "clap", + "env_logger", + "log", "serde", "serde_json", ] @@ -135,6 +187,35 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "ryu" version = "1.0.16" diff --git a/Cargo.toml b/Cargo.toml index 075072b..dcbd9e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,7 @@ description = "pcgtools: tools for reading PCgen PCC and LST data files" [dependencies] clap = { version = "4", features = ["derive"] } +env_logger = "0.11" +log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/main.rs b/src/main.rs index b93a39c..d7dcdbb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ // SPDX-License-Identifier: MIT extern crate clap; +extern crate log; use clap::Parser; use serde::{Deserialize, Serialize}; @@ -201,12 +202,12 @@ impl Pcc { match self.aliases.get(&ident) { None => {} Some(alias) => { - println!("ALIAS MATCH: {} => {}", ident, alias); + log::debug!("ALIAS MATCH: {} => {}", ident, alias); ident = alias.clone(); } } - println!("ID={}, is_mod={}", ident, is_mod); + log::debug!("ID={}, is_mod={}", ident, is_mod); // gather key=value attribs into a list let mut attribs: Vec<(String, String)> = Vec::new(); @@ -214,12 +215,12 @@ impl Pcc { match token.split_once(':') { None => { if !token.trim().is_empty() { - println!("\t{}", token); + log::debug!("\t{}", token); attribs.push((token.to_string(), String::from(""))); } } Some((akey, aval)) => { - println!("\t{}={}", akey, aval); + log::debug!("\t{}={}", akey, aval); attribs.push((akey.to_string(), aval.to_string())); } } @@ -229,12 +230,12 @@ impl Pcc { for (key, val) in &attribs { match key.as_str() { "ABB" => { - println!("ALIAS: {}={}", val, ident); + log::debug!("ALIAS: {}={}", val, ident); self.aliases.insert(val.to_string(), ident.clone()); } "KEY" => { - println!("KEY: {}={}", val, ident); + log::debug!("KEY: {}={}", val, ident); ident = val.to_string(); } @@ -297,7 +298,7 @@ impl Pcc { } } - println!("Pcc.read_lst({}, {}, \"{}\")", pcc_tag, fpath, lstopts); + log::debug!("Pcc.read_lst({}, {}, \"{}\")", pcc_tag, fpath, lstopts); let mut datum; @@ -436,7 +437,7 @@ impl Pcc { let basedir = dir_from_path(&fpath).unwrap(); - println!("Pcc.read({})", fpath); + log::debug!("Pcc.read({})", fpath); let file = File::open(fpath)?; let rdr = BufReader::new(file); @@ -463,6 +464,8 @@ impl Pcc { } fn main() { + env_logger::builder().format_timestamp(None).init(); + // parse command line options let args = Args::parse();