#![cfg_attr(feature = "strict", deny(warnings))]
#![doc(html_logo_url = "https://gitlab.com/sprowell/hhh/-/raw/master/etc/logo.png")]
#![deny(missing_docs,
//missing_debug_implementations,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces,
unused_qualifications)]
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const HASH: &str = env!("SHORT_HASH");
pub mod generator;
pub mod options;
use std::{
fs::{DirBuilder, OpenOptions},
path::PathBuf,
};
use directories_next::ProjectDirs;
pub use generator::write_hexdump;
pub mod byte_data;
pub mod directive_def;
pub mod directives;
pub mod expression;
pub mod reader;
pub use reader::read_hexdump;
pub mod math;
pub mod read_configuration;
#[cfg(test)]
mod test;
pub fn get_config_directory() -> std::io::Result<PathBuf> {
let mut config = PathBuf::new();
if let Some(proj_dirs) = ProjectDirs::from("", "binary-tools", "hhh") {
config.push(proj_dirs.config_dir());
} else {
config.push(".");
}
DirBuilder::new().recursive(true).create(&config)?;
Ok(config)
}
pub fn get_config_file() -> std::io::Result<PathBuf> {
let mut path = get_config_directory()?;
path.push("hhh.config");
OpenOptions::new()
.write(true)
.create(true)
.open(path.clone())?;
Ok(path)
}
pub fn configure_logging() {
let mut builder = env_logger::Builder::new();
builder.filter_level(log::LevelFilter::Warn);
let env = env_logger::Env::new()
.filter("HHH_LOG")
.write_style("HHH_LOG_STYLE");
builder.parse_env(env);
builder.init();
}
#[cfg(test)]
mod lib_test {
use crate::{configure_logging, get_config_file};
#[test]
fn get_config_file_test() {
let file = get_config_file();
assert!(file.is_ok());
}
#[test]
fn configure_logging_test() {
configure_logging();
}
}