From 6e161eca5f6bb8dd7ab3d35f47d201de24133eb3 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 Jan 2024 18:08:56 +0100 Subject: [PATCH 01/14] hedu data_idx offset fix fixes #56 --- Cargo.toml | 4 ++-- members/libpt-bintols/src/hedu/mod.rs | 7 +++++++ scripts/publish.sh | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4b71de0..9147040 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ authors = ["Christoph J. Scherr "] license = "MIT" description = "Personal multitool" readme = "README.md" -homepage = "https://git.cscherr.de/PlexSheep/libpt" -repository = "https://git.cscherr.de/PlexSheep/libpt" +homepage = "https://git.cscherr.de/PlexSheep/pt" +repository = "https://git.cscherr.de/PlexSheep/pt" keywords = ["cli", "library"] categories = [ "command-line-utilities", diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index 1428a96..c42abf1 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -69,6 +69,7 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { if config.skip > 0 { data.skip(config.skip)?; config.data_idx += config.skip; + adjust_data_idx(&mut config); debug!("Skipped {}", humanbytes(config.skip)); } @@ -157,6 +158,11 @@ fn mask_chars(c: char) -> char { } } +#[inline] +fn adjust_data_idx(config: &mut HeduConfig) { + config.data_idx += BYTES_PER_LINE - config.data_idx % BYTES_PER_LINE; +} + fn rd_data(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { match data.read(&mut config.buf[config.alt_buf]) { Ok(mut len) => { @@ -177,6 +183,7 @@ fn rd_data(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { config.len = len; config.rd_counter += config.len; config.data_idx += config.len; + adjust_data_idx(config); return Ok(()); } Err(err) => { diff --git a/scripts/publish.sh b/scripts/publish.sh index 84036cb..db3c89a 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -6,5 +6,5 @@ NEW_VERSION=$(cat Cargo.toml | rg '^\s*version\s*=\s*"([^"]*)"\s*$' -or '$1') bash scripts/set_all_versions.sh $NEW_VERSION git add -A git commit -m "Release v$NEW_VERSION" -cargo ws publish --registry cscherr --amend --publish-as-is || cargo publish --registry cscherr -p libpt +cargo ws publish --registry cscherr --no-git-push --publish-as-is || cargo publish --registry cscherr -p libpt git push From 6c7c6c398dccb0408529c1150af7b464cced775a Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 Jan 2024 18:13:56 +0100 Subject: [PATCH 02/14] remove CD --- .gitea/workflows/cargo-publish.yaml | 34 ----------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .gitea/workflows/cargo-publish.yaml diff --git a/.gitea/workflows/cargo-publish.yaml b/.gitea/workflows/cargo-publish.yaml deleted file mode 100644 index a76d7bf..0000000 --- a/.gitea/workflows/cargo-publish.yaml +++ /dev/null @@ -1,34 +0,0 @@ -# name: Cargo Check, Format, Fix, Test and publish -# on: -# push: -# branches: -# - master -# -# jobs: -# format: -# name: cargo CI -# permissions: -# # Give the default GITHUB_TOKEN write permission to commit and push the -# # added or changed files to the repository. -# contents: write -# package: write -# steps: -# - name: get repo -# uses: actions/checkout@v4 -# - name: install rust -# uses: dtolnay/rust-toolchain@stable -# run: cargo install cargo-workspaces -# - name: config custom registry -# run: | -# mkdir -p ~/.cargo/ -# echo "" > ~/.cargo/config.toml -# echo "[registry]" >> ~/.cargo/config.toml -# # echo 'token = "Bearer ${{ secrets.CARGO_PUBLISH_CRATESIO }}"' >> ~/.cargo/config.toml -# echo 'cscherr = "cscherr"' >> ~/.cargo/config.toml -# echo '[registries.cscherr]' >> ~/.cargo/config.toml -# echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml -# echo 'token = "Bearer ${{ GITEA_TOKEN }}"' >> ~/.cargo/config.toml -# cat ~/.cargo/config.toml -# - name: publish crates on git.cscherr.de -# run: | -# cargo workspaces publish --registry cscherr patch From f4a7aeaf87b7b82bc4e5ef7eed014bb2af2dc2cd Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 Jan 2024 19:24:30 +0100 Subject: [PATCH 03/14] change how hedu prints --- members/libpt-bintols/src/hedu/mod.rs | 47 +++++++++++++++++---------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index c42abf1..2730ecc 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -13,6 +13,7 @@ use std::io::{prelude::*, Read, SeekFrom}; const BYTES_PER_LINE: usize = 16; const LINE_SEP_HORIZ: char = '─'; const LINE_SEP_VERT: char = '│'; +const CHAR_BORDER: &'static str = "|"; #[derive(Debug)] pub struct HeduConfig { @@ -26,6 +27,7 @@ pub struct HeduConfig { rd_counter: usize, buf: [[u8; BYTES_PER_LINE]; 2], alt_buf: usize, + display_buf: String, } impl HeduConfig { @@ -41,8 +43,14 @@ impl HeduConfig { rd_counter: usize::MIN, buf: [[0; BYTES_PER_LINE]; 2], alt_buf: 0, + display_buf: String::new(), } } + #[inline] + fn display(&mut self) { + println!("{}", self.display_buf); + self.display_buf = String::new(); + } } pub trait DataSource: Read { @@ -74,44 +82,46 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { } // print the head - print!("DATA IDX {LINE_SEP_VERT} DATA AS HEX"); + config.display_buf += &format!("DATA IDX {LINE_SEP_VERT} DATA AS HEX"); if config.chars { - print!("{:width$} {LINE_SEP_VERT} FOO", "", width = 37); + config.display_buf += &format!("{:width$} {LINE_SEP_VERT}", "", width = 37); } - println!(); + config.display(); if config.chars { - println!("{}", format!("{LINE_SEP_HORIZ}").repeat(80)); + config.display_buf += &format!("{LINE_SEP_HORIZ}").repeat(80); } else { - println!("{}", format!("{LINE_SEP_HORIZ}").repeat(59)); + config.display_buf += &format!("{LINE_SEP_HORIZ}").repeat(59); } + config.display(); // data dump loop rd_data(data, &mut config)?; while config.len > 0 { - print!("{:08X} {LINE_SEP_VERT} ", config.data_idx); + config.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", config.data_idx); for i in 0..config.len { if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { - print!(" "); + config.display_buf += " "; } - print!("{:02X} ", config.buf[config.alt_buf][i]); + config.display_buf += &format!("{:02X} ", config.buf[config.alt_buf][i]); } if config.len == BYTES_PER_LINE / 2 { - print!(" ") + config.display_buf += " " } for i in 0..(BYTES_PER_LINE - config.len) { if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { - print!(" "); + config.display_buf += " "; } - print!(" "); + config.display_buf += " "; } if config.chars { - print!("{LINE_SEP_VERT} |"); + config.display_buf += &format!("{LINE_SEP_VERT} |"); for i in 0..config.len { - print!("{}", mask_chars(config.buf[config.alt_buf][i] as char)); + config.display_buf += + &format!("{}", mask_chars(config.buf[config.alt_buf][i] as char)); } - print!("|"); + config.display_buf += CHAR_BORDER; } - println!(); + config.display(); // loop breaker logic if config.stop { @@ -130,12 +140,13 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { let start_line = config.data_idx; while config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE { rd_data(data, &mut config)?; - config.data_idx += BYTES_PER_LINE; + config.data_idx += BYTES_PER_LINE; // FIXME: incorrect logic #59 } - println!( + config.display_buf += &format!( "^^^^^^^^ {LINE_SEP_VERT} (repeats {} lines)", - config.data_idx - start_line + (config.data_idx - start_line) / (BYTES_PER_LINE * 2) ); + config.display(); } // switch to the second half of the buf, the original half is stored the old buffer // We detect duplicate lines with this From 15b1776def63374695e238e68f5b750c4ee93a29 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 Jan 2024 19:37:00 +0100 Subject: [PATCH 04/14] fix data index for #59 --- members/libpt-bintols/src/hedu/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index 2730ecc..b7ccd23 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -139,8 +139,7 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { ); let start_line = config.data_idx; while config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE { - rd_data(data, &mut config)?; - config.data_idx += BYTES_PER_LINE; // FIXME: incorrect logic #59 + rd_data(data, &mut config)?; // FIXME: incorrect logic #59 } config.display_buf += &format!( "^^^^^^^^ {LINE_SEP_VERT} (repeats {} lines)", From ee62e1e578fac05d5aaac599ef4796a4fe9b4f7c Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 Jan 2024 18:39:03 +0000 Subject: [PATCH 05/14] automatic cargo CI changes --- members/libpt-bintols/src/hedu/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index b7ccd23..fa32521 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -139,7 +139,7 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { ); let start_line = config.data_idx; while config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE { - rd_data(data, &mut config)?; // FIXME: incorrect logic #59 + rd_data(data, &mut config)?; // FIXME: incorrect logic #59 } config.display_buf += &format!( "^^^^^^^^ {LINE_SEP_VERT} (repeats {} lines)", From fd0d1e3c22c49192a1e979c30627f1707a2146da Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 Jan 2024 22:28:11 +0100 Subject: [PATCH 06/14] add toggle of alt_buf after line skip #59 --- members/libpt-bintols/src/hedu/mod.rs | 7 ++++++- src/hedu/mod.rs | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index fa32521..efe0bf0 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -139,12 +139,17 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { ); let start_line = config.data_idx; while config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE { - rd_data(data, &mut config)?; // FIXME: incorrect logic #59 + rd_data(data, &mut config)?; } + config.alt_buf ^= 1; // toggle the alt buf (now that we have a not same line) config.display_buf += &format!( "^^^^^^^^ {LINE_SEP_VERT} (repeats {} lines)", (config.data_idx - start_line) / (BYTES_PER_LINE * 2) ); + trace!( + buf = format!("{:X?}", config.buf), + "dumping buf after line skip" + ); config.display(); } // switch to the second half of the buf, the original half is stored the old buffer diff --git a/src/hedu/mod.rs b/src/hedu/mod.rs index 4e72881..84cf0e6 100644 --- a/src/hedu/mod.rs +++ b/src/hedu/mod.rs @@ -86,6 +86,7 @@ pub struct Cli { /// a data source, probably a file. /// /// If left empty or set as "-", the program will read from stdin. + // TODO: take many sources #60 pub data_source: Option, } From 2bc75970a4465048dd7751f84795d195f7ac1ed6 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 Jan 2024 23:02:41 +0100 Subject: [PATCH 07/14] read from multiple sources implements #60 --- members/libpt-bintols/src/hedu/mod.rs | 20 +++++---- src/hedu/mod.rs | 58 ++++++++++++++++----------- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index efe0bf0..0b99706 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -10,10 +10,10 @@ use anyhow::{bail, Result}; use libpt_log::{debug, error, trace, warn}; use std::io::{prelude::*, Read, SeekFrom}; -const BYTES_PER_LINE: usize = 16; -const LINE_SEP_HORIZ: char = '─'; -const LINE_SEP_VERT: char = '│'; -const CHAR_BORDER: &'static str = "|"; +pub const BYTES_PER_LINE: usize = 16; +pub const LINE_SEP_HORIZ: char = '─'; +pub const LINE_SEP_VERT: char = '│'; +pub const CHAR_BORDER: &'static str = "|"; #[derive(Debug)] pub struct HeduConfig { @@ -70,14 +70,12 @@ impl DataSource for std::fs::File { } } -pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { - // prepare some variables - +pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { // skip a given number of bytes if config.skip > 0 { data.skip(config.skip)?; config.data_idx += config.skip; - adjust_data_idx(&mut config); + adjust_data_idx(config); debug!("Skipped {}", humanbytes(config.skip)); } @@ -95,7 +93,7 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { config.display(); // data dump loop - rd_data(data, &mut config)?; + rd_data(data, config)?; while config.len > 0 { config.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", config.data_idx); for i in 0..config.len { @@ -129,7 +127,7 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { } // after line logic - rd_data(data, &mut config)?; + rd_data(data, config)?; config.alt_buf ^= 1; // toggle the alt buf if config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE && !config.show_identical { @@ -139,7 +137,7 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> { ); let start_line = config.data_idx; while config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE { - rd_data(data, &mut config)?; + rd_data(data, config)?; } config.alt_buf ^= 1; // toggle the alt buf (now that we have a not same line) config.display_buf += &format!( diff --git a/src/hedu/mod.rs b/src/hedu/mod.rs index 84cf0e6..f8f8165 100644 --- a/src/hedu/mod.rs +++ b/src/hedu/mod.rs @@ -18,7 +18,7 @@ use libpt::{bintols::hedu::*, log::*}; use clap::Parser; use clap_verbosity_flag::{InfoLevel, Verbosity}; -use std::{fs::File, io::IsTerminal}; +use std::{fs::File, io::IsTerminal, path::PathBuf}; //// TYPES ///////////////////////////////////////////////////////////////////////////////////////// @@ -87,7 +87,7 @@ pub struct Cli { /// /// If left empty or set as "-", the program will read from stdin. // TODO: take many sources #60 - pub data_source: Option, + pub data_source: Vec, } //// IMPLEMENTATION //////////////////////////////////////////////////////////////////////////////// @@ -96,36 +96,46 @@ pub struct Cli { //// PRIVATE FUNCTIONS ///////////////////////////////////////////////////////////////////////////// fn main() { - let cli = cli_parse(); - let mut source: Box; - if cli.data_source.is_some() && cli.data_source.clone().is_some_and(|val| val != "-") { - let data_source = cli.data_source.unwrap(); - trace!("Trying to open '{}'", data_source); - source = match File::open(&data_source) { - Ok(file) => Box::new(file), - Err(err) => { - error!("Could not open file '{}': {err}", data_source); - std::process::exit(1); + let mut cli = cli_parse(); + let mut sources: Vec> = Vec::new(); + if cli.data_source.len() > 0 && cli.data_source[0] != "-" { + for data_source in &cli.data_source { + let data_source: PathBuf = PathBuf::from(data_source); + if !data_source.is_file() { + debug!("Not a regular file'{:?}'", data_source); + // std::process::exit(1); + continue } - }; + trace!("Trying to open '{:?}'", data_source); + match File::open(&data_source) { + Ok(file) => sources.push(Box::new(file)), + Err(err) => { + error!("Could not open '{:?}': {err}", data_source); + std::process::exit(1); + } + }; + } } else { - trace!("Trying to open stdout"); + trace!("Trying to open stdin"); let stdin = std::io::stdin(); if stdin.is_terminal() { warn!("Refusing to dump from interactive terminal"); std::process::exit(2) } - source = Box::new(stdin); + // just for the little header + cli.data_source = Vec::new(); + cli.data_source.push(format!("stdin")); + sources.push(Box::new(stdin)); } - - match dump( - &mut *source, - HeduConfig::new(cli.chars, cli.skip, cli.show_identical, cli.limit), - ) { - Ok(_) => (), - Err(err) => { - error!("Could not dump data of file: {err}"); - std::process::exit(3); + for (i, source) in sources.iter_mut().enumerate() { + println!("{:=^59}", format!(" {} ", cli.data_source[i])); + let mut config = HeduConfig::new(cli.chars, cli.skip, cli.show_identical, cli.limit); + match dump(&mut **source, &mut config) { + Ok(_) => (), + Err(err) => { + error!("Could not dump data of file: {err}"); + std::process::exit(3); + } } } } From 7e9d33700595cd6c4ddd157c013e5690a4ac1bab Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 Jan 2024 23:48:41 +0100 Subject: [PATCH 08/14] #60 #61 improvements and bugfixes --- members/libpt-bintols/src/hedu/mod.rs | 68 ++++++++++++++++++++------- src/hedu/mod.rs | 14 +++++- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index 0b99706..6ffa67a 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -27,7 +27,7 @@ pub struct HeduConfig { rd_counter: usize, buf: [[u8; BYTES_PER_LINE]; 2], alt_buf: usize, - display_buf: String, + pub display_buf: String, } impl HeduConfig { @@ -38,7 +38,7 @@ impl HeduConfig { show_identical, limit, stop: false, - len: usize::MIN, + len: BYTES_PER_LINE, data_idx: usize::MIN, rd_counter: usize::MIN, buf: [[0; BYTES_PER_LINE]; 2], @@ -47,10 +47,24 @@ impl HeduConfig { } } #[inline] - fn display(&mut self) { + pub fn display(&mut self) { println!("{}", self.display_buf); self.display_buf = String::new(); } + #[inline] + pub fn sep(&mut self) { + if self.chars { + self.display_buf += &format!("{LINE_SEP_HORIZ}").repeat(80); + } else { + self.display_buf += &format!("{LINE_SEP_HORIZ}").repeat(59); + } + self.display(); + } + #[inline] + pub fn newline(&mut self) { + self.display_buf += "\n"; + self.display(); + } } pub trait DataSource: Read { @@ -82,20 +96,15 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { // print the head config.display_buf += &format!("DATA IDX {LINE_SEP_VERT} DATA AS HEX"); if config.chars { - config.display_buf += &format!("{:width$} {LINE_SEP_VERT}", "", width = 37); - } - config.display(); - if config.chars { - config.display_buf += &format!("{LINE_SEP_HORIZ}").repeat(80); - } else { - config.display_buf += &format!("{LINE_SEP_HORIZ}").repeat(59); + config.display_buf += &format!("{:width$} {LINE_SEP_VERT} DATA AS CHAR", "", width = 37); } config.display(); + config.sep(); // data dump loop - rd_data(data, config)?; while config.len > 0 { config.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", config.data_idx); + rd_data(data, config)?; for i in 0..config.len { if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { config.display_buf += " "; @@ -127,7 +136,6 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { } // after line logic - rd_data(data, config)?; config.alt_buf ^= 1; // toggle the alt buf if config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE && !config.show_identical { @@ -139,11 +147,14 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { while config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE { rd_data(data, config)?; } - config.alt_buf ^= 1; // toggle the alt buf (now that we have a not same line) config.display_buf += &format!( - "^^^^^^^^ {LINE_SEP_VERT} (repeats {} lines)", - (config.data_idx - start_line) / (BYTES_PER_LINE * 2) + "^^^^^^^^ {LINE_SEP_VERT} (repeats {} lines){:32}", + (config.data_idx - start_line) / (BYTES_PER_LINE * 2), + "" ); + if config.chars { + config.display_buf += &format!("{LINE_SEP_VERT}"); + } trace!( buf = format!("{:X?}", config.buf), "dumping buf after line skip" @@ -154,6 +165,31 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { // We detect duplicate lines with this config.alt_buf ^= 1; // toggle the alt buf } + config.data_idx += config.len; + + config.sep(); + config.display_buf += &format!( + "{:08X} {LINE_SEP_VERT} dumped total:\t{:<8} {:<16}{:3}", + config.rd_counter, + humanbytes(config.rd_counter), + format!("({} B)",config.rd_counter), + "" + ); + if config.chars { + config.display_buf += &format!("{LINE_SEP_VERT}"); + } + config.display(); + config.display_buf += &format!( + "{:08X} {LINE_SEP_VERT} read total:\t\t{:<8} {:<16}{:3}", + config.data_idx, + humanbytes(config.data_idx), + format!("({} B)",config.data_idx), + "" + ); + if config.chars { + config.display_buf += &format!("{LINE_SEP_VERT}"); + } + config.display(); Ok(()) } @@ -173,7 +209,7 @@ fn mask_chars(c: char) -> char { #[inline] fn adjust_data_idx(config: &mut HeduConfig) { - config.data_idx += BYTES_PER_LINE - config.data_idx % BYTES_PER_LINE; + config.data_idx -= config.data_idx % BYTES_PER_LINE; } fn rd_data(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { diff --git a/src/hedu/mod.rs b/src/hedu/mod.rs index f8f8165..52547c0 100644 --- a/src/hedu/mod.rs +++ b/src/hedu/mod.rs @@ -104,7 +104,7 @@ fn main() { if !data_source.is_file() { debug!("Not a regular file'{:?}'", data_source); // std::process::exit(1); - continue + continue; } trace!("Trying to open '{:?}'", data_source); match File::open(&data_source) { @@ -128,8 +128,15 @@ fn main() { sources.push(Box::new(stdin)); } for (i, source) in sources.iter_mut().enumerate() { - println!("{:=^59}", format!(" {} ", cli.data_source[i])); let mut config = HeduConfig::new(cli.chars, cli.skip, cli.show_identical, cli.limit); + match config.chars { + false => { + println!("{:─^59}", format!(" {} ", cli.data_source[i])); + } + true => { + println!("{:─^80}", format!(" {} ", cli.data_source[i])); + } + } match dump(&mut **source, &mut config) { Ok(_) => (), Err(err) => { @@ -137,6 +144,9 @@ fn main() { std::process::exit(3); } } + if i < cli.data_source.len() - 1 { + config.newline(); + } } } //////////////////////////////////////////////////////////////////////////////////////////////////// From ca50a038dab384f9d1966f26825a86262fa48acf Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 18 Jan 2024 00:03:19 +0100 Subject: [PATCH 09/14] hedu cli now works with 0 byte input streams --- members/libpt-bintols/src/hedu/mod.rs | 60 ++++++++++++++++----------- src/hedu/mod.rs | 2 +- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index 6ffa67a..a035c16 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -28,6 +28,7 @@ pub struct HeduConfig { buf: [[u8; BYTES_PER_LINE]; 2], alt_buf: usize, pub display_buf: String, + first_iter: bool, } impl HeduConfig { @@ -38,12 +39,13 @@ impl HeduConfig { show_identical, limit, stop: false, - len: BYTES_PER_LINE, - data_idx: usize::MIN, - rd_counter: usize::MIN, + len: 0, + data_idx: 0, + rd_counter: 0, buf: [[0; BYTES_PER_LINE]; 2], alt_buf: 0, display_buf: String::new(), + first_iter: true, } } #[inline] @@ -102,36 +104,45 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { config.sep(); // data dump loop - while config.len > 0 { + while config.len > 0 || config.first_iter { config.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", config.data_idx); rd_data(data, config)?; - for i in 0..config.len { - if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { - config.display_buf += " "; + if config.len != 0 && config.first_iter { + for i in 0..config.len { + if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { + config.display_buf += " "; + } + config.display_buf += &format!("{:02X} ", config.buf[config.alt_buf][i]); } - config.display_buf += &format!("{:02X} ", config.buf[config.alt_buf][i]); - } - if config.len == BYTES_PER_LINE / 2 { - config.display_buf += " " - } - for i in 0..(BYTES_PER_LINE - config.len) { - if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { - config.display_buf += " "; + if config.len == BYTES_PER_LINE / 2 { + config.display_buf += " " } - config.display_buf += " "; + for i in 0..(BYTES_PER_LINE - config.len) { + if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { + config.display_buf += " "; + } + config.display_buf += " "; + } + } else { + config.display_buf += &format!("(no data){:40}", ""); } if config.chars { - config.display_buf += &format!("{LINE_SEP_VERT} |"); - for i in 0..config.len { - config.display_buf += - &format!("{}", mask_chars(config.buf[config.alt_buf][i] as char)); + config.display_buf += &format!("{LINE_SEP_VERT} "); + if config.len != 0 && config.first_iter { + config.display_buf += CHAR_BORDER; + for i in 0..config.len { + config.display_buf += + &format!("{}", mask_chars(config.buf[config.alt_buf][i] as char)); + } + config.display_buf += CHAR_BORDER; + } else { + config.display_buf += &format!("(no data)"); } - config.display_buf += CHAR_BORDER; } config.display(); // loop breaker logic - if config.stop { + if config.stop || config.len == 0 { break; } @@ -160,6 +171,7 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { "dumping buf after line skip" ); config.display(); + config.first_iter = false; } // switch to the second half of the buf, the original half is stored the old buffer // We detect duplicate lines with this @@ -172,7 +184,7 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { "{:08X} {LINE_SEP_VERT} dumped total:\t{:<8} {:<16}{:3}", config.rd_counter, humanbytes(config.rd_counter), - format!("({} B)",config.rd_counter), + format!("({} B)", config.rd_counter), "" ); if config.chars { @@ -183,7 +195,7 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { "{:08X} {LINE_SEP_VERT} read total:\t\t{:<8} {:<16}{:3}", config.data_idx, humanbytes(config.data_idx), - format!("({} B)",config.data_idx), + format!("({} B)", config.data_idx), "" ); if config.chars { diff --git a/src/hedu/mod.rs b/src/hedu/mod.rs index 52547c0..872a581 100644 --- a/src/hedu/mod.rs +++ b/src/hedu/mod.rs @@ -102,7 +102,7 @@ fn main() { for data_source in &cli.data_source { let data_source: PathBuf = PathBuf::from(data_source); if !data_source.is_file() { - debug!("Not a regular file'{:?}'", data_source); + warn!("Not a regular file {:?}, skipping", data_source); // std::process::exit(1); continue; } From 62fa938b1cda6b2c36e718883a30f6fa21766c59 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 18 Jan 2024 09:53:27 +0100 Subject: [PATCH 10/14] add a fixme --- src/hedu/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hedu/mod.rs b/src/hedu/mod.rs index 872a581..301fd42 100644 --- a/src/hedu/mod.rs +++ b/src/hedu/mod.rs @@ -129,6 +129,8 @@ fn main() { } for (i, source) in sources.iter_mut().enumerate() { let mut config = HeduConfig::new(cli.chars, cli.skip, cli.show_identical, cli.limit); + // FIXME: find a better way to get the file name + // Currently, skipped sources make an extra newline here. match config.chars { false => { println!("{:─^59}", format!(" {} ", cli.data_source[i])); From 55e7bf0f866ab985dceed37e1c217233182fde4d Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 18 Jan 2024 10:55:38 +0100 Subject: [PATCH 11/14] fix no data #62 and make #63 even worse --- members/libpt-bintols/src/hedu/mod.rs | 55 +++++++++++---------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index a035c16..27742f4 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -90,9 +90,12 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { // skip a given number of bytes if config.skip > 0 { data.skip(config.skip)?; - config.data_idx += config.skip; - adjust_data_idx(config); - debug!("Skipped {}", humanbytes(config.skip)); + config.rd_counter += config.skip; + debug!( + data_idx = config.data_idx, + "Skipped {}", + humanbytes(config.skip) + ); } // print the head @@ -104,10 +107,12 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { config.sep(); // data dump loop + rd_data(data, config)?; + config.data_idx = 0; while config.len > 0 || config.first_iter { + config.first_iter = false; config.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", config.data_idx); - rd_data(data, config)?; - if config.len != 0 && config.first_iter { + if config.len != 0 { for i in 0..config.len { if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { config.display_buf += " "; @@ -128,7 +133,7 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { } if config.chars { config.display_buf += &format!("{LINE_SEP_VERT} "); - if config.len != 0 && config.first_iter { + if config.len != 0 { config.display_buf += CHAR_BORDER; for i in 0..config.len { config.display_buf += @@ -147,7 +152,6 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { } // after line logic - config.alt_buf ^= 1; // toggle the alt buf if config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE && !config.show_identical { trace!( @@ -170,21 +174,19 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { buf = format!("{:X?}", config.buf), "dumping buf after line skip" ); + config.alt_buf ^= 1; // read into the other buf, so we can check for sameness config.display(); - config.first_iter = false; } - // switch to the second half of the buf, the original half is stored the old buffer - // We detect duplicate lines with this - config.alt_buf ^= 1; // toggle the alt buf + rd_data(data, config)?; } config.data_idx += config.len; config.sep(); config.display_buf += &format!( "{:08X} {LINE_SEP_VERT} dumped total:\t{:<8} {:<16}{:3}", - config.rd_counter, - humanbytes(config.rd_counter), - format!("({} B)", config.rd_counter), + config.data_idx, + humanbytes(config.data_idx), + format!("({} B)", config.data_idx), "" ); if config.chars { @@ -193,9 +195,9 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { config.display(); config.display_buf += &format!( "{:08X} {LINE_SEP_VERT} read total:\t\t{:<8} {:<16}{:3}", - config.data_idx, - humanbytes(config.data_idx), - format!("({} B)", config.data_idx), + config.rd_counter, + humanbytes(config.rd_counter), + format!("({} B)", config.rd_counter), "" ); if config.chars { @@ -220,31 +222,20 @@ fn mask_chars(c: char) -> char { } #[inline] -fn adjust_data_idx(config: &mut HeduConfig) { - config.data_idx -= config.data_idx % BYTES_PER_LINE; +fn adjust_counters(config: &mut HeduConfig) { + config.rd_counter += config.len; + config.data_idx += config.len; } fn rd_data(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { match data.read(&mut config.buf[config.alt_buf]) { Ok(mut len) => { - trace!( - conf = format!("{:?}", config), - eval = config.limit != 0 && config.rd_counter >= config.limit, - "reached limit?" - ); if config.limit != 0 && config.rd_counter + (BYTES_PER_LINE - 1) >= config.limit { - trace!( - conf = format!("{:?}", config), - nlen = (config.limit % BYTES_PER_LINE), - "byte counter is farther than limit" - ); len = config.limit % BYTES_PER_LINE; config.stop = true; } config.len = len; - config.rd_counter += config.len; - config.data_idx += config.len; - adjust_data_idx(config); + adjust_counters(config); return Ok(()); } Err(err) => { From 73bd34c78dfa6112220aaa39af7b518840a1cc45 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 18 Jan 2024 12:04:20 +0100 Subject: [PATCH 12/14] fix line counter for skipped lines --- members/libpt-bintols/src/hedu/mod.rs | 21 ++++----------------- src/hedu/mod.rs | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index 27742f4..a9b50f3 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -150,6 +150,7 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { if config.stop || config.len == 0 { break; } + rd_data(data, config)?; // after line logic if config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE && !config.show_identical @@ -164,7 +165,7 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { } config.display_buf += &format!( "^^^^^^^^ {LINE_SEP_VERT} (repeats {} lines){:32}", - (config.data_idx - start_line) / (BYTES_PER_LINE * 2), + (config.data_idx - start_line) / (BYTES_PER_LINE) + 1, "" ); if config.chars { @@ -177,28 +178,14 @@ pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { config.alt_buf ^= 1; // read into the other buf, so we can check for sameness config.display(); } - rd_data(data, config)?; } - config.data_idx += config.len; config.sep(); config.display_buf += &format!( - "{:08X} {LINE_SEP_VERT} dumped total:\t{:<8} {:<16}{:3}", - config.data_idx, - humanbytes(config.data_idx), - format!("({} B)", config.data_idx), - "" - ); - if config.chars { - config.display_buf += &format!("{LINE_SEP_VERT}"); - } - config.display(); - config.display_buf += &format!( - "{:08X} {LINE_SEP_VERT} read total:\t\t{:<8} {:<16}{:3}", + "{:08X} {LINE_SEP_VERT} read total:\t\t {:<8} {:<15}", config.rd_counter, humanbytes(config.rd_counter), - format!("({} B)", config.rd_counter), - "" + format!("({} B)", config.rd_counter) ); if config.chars { config.display_buf += &format!("{LINE_SEP_VERT}"); diff --git a/src/hedu/mod.rs b/src/hedu/mod.rs index 301fd42..05b5d34 100644 --- a/src/hedu/mod.rs +++ b/src/hedu/mod.rs @@ -101,8 +101,8 @@ fn main() { if cli.data_source.len() > 0 && cli.data_source[0] != "-" { for data_source in &cli.data_source { let data_source: PathBuf = PathBuf::from(data_source); - if !data_source.is_file() { - warn!("Not a regular file {:?}, skipping", data_source); + if data_source.is_dir() { + warn!("Not a file {:?}, skipping", data_source); // std::process::exit(1); continue; } From 751442cec1be5273924670900da44334727b43d6 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 18 Jan 2024 13:19:22 +0100 Subject: [PATCH 13/14] hedu to struct --- members/libpt-bintols/src/hedu/mod.rs | 273 +++++++++++++------------- src/hedu/mod.rs | 4 +- 2 files changed, 140 insertions(+), 137 deletions(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index a9b50f3..b31ebbe 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -16,7 +16,7 @@ pub const LINE_SEP_VERT: char = '│'; pub const CHAR_BORDER: &'static str = "|"; #[derive(Debug)] -pub struct HeduConfig { +pub struct Hedu { pub chars: bool, pub skip: usize, pub show_identical: bool, @@ -31,9 +31,9 @@ pub struct HeduConfig { first_iter: bool, } -impl HeduConfig { +impl Hedu { pub fn new(chars: bool, skip: usize, show_identical: bool, limit: usize) -> Self { - HeduConfig { + Hedu { chars, skip, show_identical, @@ -67,6 +67,141 @@ impl HeduConfig { self.display_buf += "\n"; self.display(); } + fn dump_a_line(&mut self) { + self.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", self.data_idx); + if self.len != 0 { + for i in 0..self.len { + if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { + self.display_buf += " "; + } + self.display_buf += &format!("{:02X} ", self.buf[self.alt_buf][i]); + } + if self.len == BYTES_PER_LINE / 2 { + self.display_buf += " " + } + for i in 0..(BYTES_PER_LINE - self.len) { + if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { + self.display_buf += " "; + } + self.display_buf += " "; + } + } else { + self.display_buf += &format!("{:49}", ""); + } + if self.chars { + self.display_buf += &format!("{LINE_SEP_VERT} "); + if self.len != 0 { + self.display_buf += CHAR_BORDER; + for i in 0..self.len { + self.display_buf += + &format!("{}", mask_chars(self.buf[self.alt_buf][i] as char)); + } + self.display_buf += CHAR_BORDER; + } else { + self.display_buf += &format!("{:^8}", ""); + } + } + self.display(); + } + + fn skip_lines(&mut self, data: &mut dyn DataSource) -> Result<()> { + trace!(buf = format!("{:?}", self.buf), "found a duplicating line"); + let start_line = self.data_idx; + while self.buf[0] == self.buf[1] && self.len == BYTES_PER_LINE { + self.rd_data(data)?; + } + self.display_buf += &format!( + "******** {LINE_SEP_VERT} {:<49}", + format!("(repeats {} lines)", self.data_idx - start_line / (BYTES_PER_LINE) + 1) + ); + if self.chars { + self.display_buf += &format!("{LINE_SEP_VERT}"); + } + trace!( + buf = format!("{:X?}", self.buf), + "dumping buf after line skip" + ); + self.alt_buf ^= 1; // read into the other buf, so we can check for sameness + self.display(); + Ok(()) + } + pub fn dump(&mut self, data: &mut dyn DataSource) -> Result<()> { + // skip a given number of bytes + if self.skip > 0 { + data.skip(self.skip)?; + self.rd_counter += self.skip; + debug!( + data_idx = self.data_idx, + "Skipped {}", + humanbytes(self.skip) + ); + } + + // print the head + self.display_buf += &format!("DATA IDX {LINE_SEP_VERT} DATA AS HEX"); + if self.chars { + self.display_buf += &format!("{:width$} {LINE_SEP_VERT} DATA AS CHAR", "", width = 37); + } + self.display(); + self.sep(); + + // data dump loop + self.rd_data(data)?; + self.data_idx = 0; + while self.len > 0 || self.first_iter { + self.first_iter = false; + + self.dump_a_line(); + + // loop breaker logic + if self.stop || self.len < BYTES_PER_LINE { + break; + } + self.rd_data(data)?; + + // after line logic + if self.buf[0] == self.buf[1] && self.len == BYTES_PER_LINE && !self.show_identical { + self.skip_lines(data)?; + } + } + self.data_idx += BYTES_PER_LINE; + + self.sep(); + self.display_buf += &format!( + "{:08X} {LINE_SEP_VERT} read total:\t\t {:<8} {:<15}", + self.rd_counter, + humanbytes(self.rd_counter), + format!("({} B)", self.rd_counter) + ); + if self.chars { + self.display_buf += &format!("{LINE_SEP_VERT}"); + } + self.display(); + Ok(()) + } + #[inline] + fn adjust_counters(&mut self) { + self.rd_counter += self.len; + self.data_idx += self.len; + } + + fn rd_data(&mut self, data: &mut dyn DataSource) -> Result<()> { + match data.read(&mut self.buf[self.alt_buf]) { + Ok(mut len) => { + if self.limit != 0 && self.rd_counter + (BYTES_PER_LINE - 1) >= self.limit { + len = self.limit % BYTES_PER_LINE; + self.stop = true; + } + self.len = len; + self.adjust_counters(); + return Ok(()); + } + Err(err) => { + error!("error while reading data: {err}"); + bail!(err) + } + } + } } pub trait DataSource: Read { @@ -86,114 +221,6 @@ impl DataSource for std::fs::File { } } -pub fn dump(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { - // skip a given number of bytes - if config.skip > 0 { - data.skip(config.skip)?; - config.rd_counter += config.skip; - debug!( - data_idx = config.data_idx, - "Skipped {}", - humanbytes(config.skip) - ); - } - - // print the head - config.display_buf += &format!("DATA IDX {LINE_SEP_VERT} DATA AS HEX"); - if config.chars { - config.display_buf += &format!("{:width$} {LINE_SEP_VERT} DATA AS CHAR", "", width = 37); - } - config.display(); - config.sep(); - - // data dump loop - rd_data(data, config)?; - config.data_idx = 0; - while config.len > 0 || config.first_iter { - config.first_iter = false; - config.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", config.data_idx); - if config.len != 0 { - for i in 0..config.len { - if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { - config.display_buf += " "; - } - config.display_buf += &format!("{:02X} ", config.buf[config.alt_buf][i]); - } - if config.len == BYTES_PER_LINE / 2 { - config.display_buf += " " - } - for i in 0..(BYTES_PER_LINE - config.len) { - if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { - config.display_buf += " "; - } - config.display_buf += " "; - } - } else { - config.display_buf += &format!("(no data){:40}", ""); - } - if config.chars { - config.display_buf += &format!("{LINE_SEP_VERT} "); - if config.len != 0 { - config.display_buf += CHAR_BORDER; - for i in 0..config.len { - config.display_buf += - &format!("{}", mask_chars(config.buf[config.alt_buf][i] as char)); - } - config.display_buf += CHAR_BORDER; - } else { - config.display_buf += &format!("(no data)"); - } - } - config.display(); - - // loop breaker logic - if config.stop || config.len == 0 { - break; - } - rd_data(data, config)?; - - // after line logic - if config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE && !config.show_identical - { - trace!( - buf = format!("{:?}", config.buf), - "found a duplicating line" - ); - let start_line = config.data_idx; - while config.buf[0] == config.buf[1] && config.len == BYTES_PER_LINE { - rd_data(data, config)?; - } - config.display_buf += &format!( - "^^^^^^^^ {LINE_SEP_VERT} (repeats {} lines){:32}", - (config.data_idx - start_line) / (BYTES_PER_LINE) + 1, - "" - ); - if config.chars { - config.display_buf += &format!("{LINE_SEP_VERT}"); - } - trace!( - buf = format!("{:X?}", config.buf), - "dumping buf after line skip" - ); - config.alt_buf ^= 1; // read into the other buf, so we can check for sameness - config.display(); - } - } - - config.sep(); - config.display_buf += &format!( - "{:08X} {LINE_SEP_VERT} read total:\t\t {:<8} {:<15}", - config.rd_counter, - humanbytes(config.rd_counter), - format!("({} B)", config.rd_counter) - ); - if config.chars { - config.display_buf += &format!("{LINE_SEP_VERT}"); - } - config.display(); - Ok(()) -} - fn mask_chars(c: char) -> char { if c.is_ascii_graphic() { return c; @@ -207,27 +234,3 @@ fn mask_chars(c: char) -> char { return '�'; } } - -#[inline] -fn adjust_counters(config: &mut HeduConfig) { - config.rd_counter += config.len; - config.data_idx += config.len; -} - -fn rd_data(data: &mut dyn DataSource, config: &mut HeduConfig) -> Result<()> { - match data.read(&mut config.buf[config.alt_buf]) { - Ok(mut len) => { - if config.limit != 0 && config.rd_counter + (BYTES_PER_LINE - 1) >= config.limit { - len = config.limit % BYTES_PER_LINE; - config.stop = true; - } - config.len = len; - adjust_counters(config); - return Ok(()); - } - Err(err) => { - error!("error while reading data: {err}"); - bail!(err) - } - } -} diff --git a/src/hedu/mod.rs b/src/hedu/mod.rs index 05b5d34..83d5309 100644 --- a/src/hedu/mod.rs +++ b/src/hedu/mod.rs @@ -128,7 +128,7 @@ fn main() { sources.push(Box::new(stdin)); } for (i, source) in sources.iter_mut().enumerate() { - let mut config = HeduConfig::new(cli.chars, cli.skip, cli.show_identical, cli.limit); + let mut config = Hedu::new(cli.chars, cli.skip, cli.show_identical, cli.limit); // FIXME: find a better way to get the file name // Currently, skipped sources make an extra newline here. match config.chars { @@ -139,7 +139,7 @@ fn main() { println!("{:─^80}", format!(" {} ", cli.data_source[i])); } } - match dump(&mut **source, &mut config) { + match config.dump(&mut **source) { Ok(_) => (), Err(err) => { error!("Could not dump data of file: {err}"); From 782e2114483057b084a8779914edc14efa20e51b Mon Sep 17 00:00:00 2001 From: cscherrNT Date: Thu, 18 Jan 2024 12:25:51 +0000 Subject: [PATCH 14/14] automatic cargo CI changes --- members/libpt-bintols/src/hedu/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/members/libpt-bintols/src/hedu/mod.rs b/members/libpt-bintols/src/hedu/mod.rs index b31ebbe..7d3e8a2 100644 --- a/members/libpt-bintols/src/hedu/mod.rs +++ b/members/libpt-bintols/src/hedu/mod.rs @@ -112,7 +112,10 @@ impl Hedu { } self.display_buf += &format!( "******** {LINE_SEP_VERT} {:<49}", - format!("(repeats {} lines)", self.data_idx - start_line / (BYTES_PER_LINE) + 1) + format!( + "(repeats {} lines)", + self.data_idx - start_line / (BYTES_PER_LINE) + 1 + ) ); if self.chars { self.display_buf += &format!("{LINE_SEP_VERT}");