early hedu
Cargo Check, Format, Fix and Test / cargo CI (push) Successful in 2m20s Details

This commit is contained in:
Christoph J. Scherr 2024-01-16 11:31:05 +01:00
parent b7fbef73b4
commit 3f59e99b88
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
5 changed files with 199 additions and 40 deletions

View File

@ -1,20 +1,16 @@
[workspace]
resolver = "2"
members = [
".",
"members/libpt-core",
"members/libpt-bintols",
"members/libpt-math",
"members/libpt-bin",
"members/libpt-log",
"members/libpt-net",
"members/libpt-hedu",
]
default-members = [
".",
"members/libpt-bin",
"members/libpt-core",
".",
"members/libpt-core",
"members/libpt-bintols",
"members/libpt-math",
"members/libpt-bin",
"members/libpt-log",
"members/libpt-net",
"members/libpt-hedu",
]
default-members = [".", "members/libpt-bin", "members/libpt-core"]
[workspace.package]
publish = true
version = "0.1.7"
@ -26,7 +22,11 @@ readme = "README.md"
homepage = "https://git.cscherr.de/PlexSheep/libpt"
repository = "https://git.cscherr.de/PlexSheep/libpt"
keywords = ["cli", "library"]
categories = ["command-line-utilities", "development-tools", "development-tools::ffi"]
categories = [
"command-line-utilities",
"development-tools",
"development-tools::ffi",
]
[workspace.dependencies]
anyhow = "1.0.79"
@ -47,39 +47,32 @@ keywords.workspace = true
categories.workspace = true
[features]
default = ["log"]
all = [
"default",
"math",
"log",
"bintols",
"net",
"ccc",
"hedu"
]
fw = []
math = []
log = []
default = ["log", "core"]
all = ["default", "math", "log", "bintols", "net", "ccc", "hedu", "core"]
core = []
fw = []
math = []
log = []
bintols = []
net = []
ccc = ["math"]
hedu = ["bintols"]
net = []
ccc = ["math"]
hedu = ["bintols"]
[lib]
name = "libpt"
crate-type = [
"dylib", # .dll, .so, .dynlib
"staticlib", # .lib, .a
"rlib"
"dylib", # .dll, .so, .dynlib
"staticlib", # .lib, .a
"rlib",
]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libpt-bintols = { path = "members/libpt-bintols" }
libpt-core = { path = "members/libpt-core" }
libpt-hedu = { path = "members/libpt-hedu" }
libpt-log = { path = "members/libpt-log" }
libpt-math = { path = "members/libpt-math" }
libpt-net = { path = "members/libpt-net" }
libpt-ccc = { path = "members/libpt-ccc" }
libpt-bintols = { path = "members/libpt-bintols" }
libpt-core = { path = "members/libpt-core" }
libpt-hedu = { path = "members/libpt-hedu" }
libpt-log = { path = "members/libpt-log" }
libpt-math = { path = "members/libpt-math" }
libpt-ccc = { path = "members/libpt-ccc" }
libpt-net = { path = "members/libpt-net" }

View File

@ -19,6 +19,10 @@ categories.workspace = true
name = "ccc"
path = "src/ccc/mod.rs"
[[bin]]
name = "hedu"
path = "src/hedu/mod.rs"
[[bin]]
name = "libpt"
path = "src/main/mod.rs"

View File

@ -0,0 +1,142 @@
//! # Executable for the hedu submodule
//!
//! Dump data to a fancy format.
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
use libpt::{hedu::*, log::*};
use clap::Parser;
use clap_verbosity_flag::{InfoLevel, Verbosity};
use std::{
fs::File,
io::{BufRead, BufReader},
path::PathBuf,
};
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
/// short about section displayed in help
const ABOUT_ROOT: &'static str = r##"
Dumps data in fancy formats
"##;
/// longer about section displayed in help, is combined with [the short help](ABOUT_ROOT)
static LONG_ABOUT_ROOT: &'static str = r##"
libpt is a personal general purpose library, offering this executable, a python module and a
dynamic library.
"##;
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
/// defines CLI interface
#[derive(Debug, Clone, Parser)]
#[command(
author,
version,
about = ABOUT_ROOT,
long_about = format!("{}{}", ABOUT_ROOT ,LONG_ABOUT_ROOT),
help_template =
r#"libpt: {version}{about-section}Author:
{author-with-newline}
{usage-heading} {usage}{all-args}{tab}"#
)]
pub struct Cli {
// clap_verbosity_flag seems to make this a global option implicitly
/// set a verbosity, multiple allowed (f.e. -vvv)
#[command(flatten)]
pub verbose: Verbosity<InfoLevel>,
/// show logger meta
#[arg(short, long, global = true)]
pub log_meta: bool,
/// a data source, probably a file
pub data_source: String,
}
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
fn main() {
let cli = cli_parse();
debug!("Trying to open '{}'", cli.data_source);
let file = match File::open(cli.data_source.clone()) {
Ok(file) => file,
Err(err) => {
error!("Could not open file '{}': {err}", cli.data_source);
std::process::exit(1);
}
};
match dump(BufReader::new(file)){
Ok(_) => (),
Err(err) => {
error!("Could not dump data of file: {err}");
std::process::exit(2);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
fn cli_parse() -> Cli {
let cli = Cli::parse();
let ll: Level = match cli.verbose.log_level().unwrap().as_str() {
"TRACE" => Level::TRACE,
"DEBUG" => Level::DEBUG,
"INFO" => Level::INFO,
"WARN" => Level::WARN,
"ERROR" => Level::ERROR,
_ => {
eprintln!("'{}' is not a valid loglevel", cli.verbose.to_string());
std::process::exit(1);
}
};
if cli.log_meta {
Logger::init_customized(
false,
PathBuf::from("/dev/null"),
true,
false,
true,
true,
ll,
false,
false,
false,
)
.expect("could not initialize Logger");
} else {
// less verbose version
Logger::init_customized(
false,
PathBuf::from("/dev/null"),
true,
false,
true,
false,
ll,
false,
false,
false,
)
.expect("could not initialize Logger");
}
return cli;
}

View File

@ -15,3 +15,5 @@ categories.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = { workspace = true }
thiserror = { workspace = true }

View File

@ -4,3 +4,21 @@
//! module.
//!
//! This crate is currently empty.
use std::{fmt::Debug, io::{BufReader, BufRead, prelude::*, Bytes}};
use anyhow::Result;
pub fn dump<T>(mut data: BufReader<T>) -> Result<()>
where T: Read
{
for (i, b) in data.bytes().enumerate() {
if i % 8 == 0 {
print!("{:08X}\t", i);
}
print!("{:02X?} ", b.unwrap());
if i % 8 == 7 {
println!();
}
}
Ok(())
}