extern crate regex; extern crate yaml_rust; extern crate walkdir; use walkdir::WalkDir; use std::io::prelude::*; use std::fs::File; use std::env; use std::path::Path; use std::collections::HashMap; mod pre_process; use pre_process::Section; mod config; use config::Config; fn main() { let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); let base_path = Path::new(&raw_files); let cfg = Config::from_file("config.yml"); let mut sections: Vec
= vec![]; for (name, sec) in &cfg.sections { sections.push(Section::new(&name, &sec.pattern, sec.groups.clone())); } for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { let mut f = File::open(entry.path()).expect("could not open file"); let mut buf = String::new(); if let Err(_) = f.read_to_string(&mut buf) { println!("invalid file: {}", entry.path().to_str().unwrap()); continue; } let buf = pre_process::strip_irrelevant_content(&buf); pre_process::split_sections(&buf, &mut sections); let mut char: HashMap> = HashMap::new(); for s in §ions { char.insert(s.name.clone(), s.data.clone()); } println!("{:?}", char); } }