From e0dae934845998efe47c93775c39d81551e492f9 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Sat, 17 Feb 2024 15:03:05 -0500 Subject: [PATCH 1/2] support aliases via ABB tag --- src/main.rs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 080d18d..d0b5a3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,6 +96,7 @@ pub struct Pcc { config: PccConfig, dict: HashMap, pcc_schema: HashMap, + aliases: HashMap, } fn dir_from_path(full_path: &str) -> Option { @@ -175,6 +176,7 @@ impl Pcc { config: config.clone(), dict: HashMap::new(), pcc_schema: new_pcc_schema(), + aliases: HashMap::new(), } } @@ -188,11 +190,20 @@ impl Pcc { // the ".MOD" suffix triggers update of existing elem let is_mod = raw_ident.ends_with(".MOD"); - let ident; + let mut ident; if is_mod { - ident = &raw_ident[0..(raw_ident.len() - 4)]; + ident = String::from(&raw_ident[0..(raw_ident.len() - 4)]); } else { - ident = &raw_ident; + ident = String::from(raw_ident); + } + + // if ident is an alias, lookup true ident + match self.aliases.get(&ident) { + None => {} + Some(alias) => { + println!("ALIAS MATCH: {} => {}", ident, alias); + ident = alias.clone(); + } } println!("ID={}, is_mod={}", ident, is_mod); @@ -214,15 +225,27 @@ impl Pcc { } } + // pre-processing + for (key, val) in &attribs { + match key.as_str() { + "ABB" => { + println!("ALIAS: {}={}", val, ident); + self.aliases.insert(val.to_string(), ident.clone()); + } + + _ => {} + } + } + // grab ref to list inside datum, for update let lst = datum.as_mut_list().unwrap(); // remove Elem for update, or create new if nonexistent let mut obj; - if lst.props.contains_key(ident) { - obj = lst.props.remove(ident).unwrap(); + if lst.props.contains_key(&ident) { + obj = lst.props.remove(&ident).unwrap(); } else { - obj = PccElem::new(ident); + obj = PccElem::new(&ident); } // merge new attribs into master attrib list From e21ddcd3379a62a45b25e18063e98312db93bdfb Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Sat, 17 Feb 2024 15:15:51 -0500 Subject: [PATCH 2/2] Support key renaming via KEY tag --- src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.rs b/src/main.rs index d0b5a3e..b93a39c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -233,6 +233,11 @@ impl Pcc { self.aliases.insert(val.to_string(), ident.clone()); } + "KEY" => { + println!("KEY: {}={}", val, ident); + ident = val.to_string(); + } + _ => {} } }