generated from PlexSheep/baserepo
hedu fix byte counter
cargo devel CI / cargo CI (push) Successful in 2m9s
Details
cargo devel CI / cargo CI (push) Successful in 2m9s
Details
This commit is contained in:
parent
e78645ab82
commit
23910f122e
12
Cargo.toml
12
Cargo.toml
|
@ -10,7 +10,7 @@ members = [
|
||||||
default-members = [".", "members/libpt-core"]
|
default-members = [".", "members/libpt-core"]
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
publish = true
|
publish = true
|
||||||
version = "0.3.3-alpha.0"
|
version = "0.3.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -28,11 +28,11 @@ categories = [
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1.0.79"
|
anyhow = "1.0.79"
|
||||||
thiserror = "1.0.56"
|
thiserror = "1.0.56"
|
||||||
libpt-core = { version = "0.3.0", path = "members/libpt-core", registry = "cscherr" }
|
libpt-core = { version = "0.3.3", path = "members/libpt-core", registry = "cscherr" }
|
||||||
libpt-bintols = { version = "0.3.0", path = "members/libpt-bintols", registry = "cscherr" }
|
libpt-bintols = { version = "0.3.3", path = "members/libpt-bintols", registry = "cscherr" }
|
||||||
libpt-log = { version = "0.3.0", path = "members/libpt-log", registry = "cscherr" }
|
libpt-log = { version = "0.3.3", path = "members/libpt-log", registry = "cscherr" }
|
||||||
libpt-math = { version = "0.3.0", path = "members/libpt-math", registry = "cscherr" }
|
libpt-math = { version = "0.3.3", path = "members/libpt-math", registry = "cscherr" }
|
||||||
libpt-net = { version = "0.3.0", path = "members/libpt-net", registry = "cscherr" }
|
libpt-net = { version = "0.3.3", path = "members/libpt-net", registry = "cscherr" }
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "libpt"
|
name = "libpt"
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
//!
|
//!
|
||||||
//! This crate is currently empty.
|
//! This crate is currently empty.
|
||||||
|
|
||||||
use crate::display::{bytes_to_bin, humanbytes};
|
use crate::display::humanbytes;
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use libpt_log::{debug, error, info, trace, warn};
|
use libpt_log::{debug, trace, warn, error};
|
||||||
use std::io::{prelude::*, BufReader, Read, SeekFrom};
|
use std::io::{prelude::*, Read, SeekFrom};
|
||||||
|
|
||||||
const BYTES_PER_LINE: usize = 16;
|
const BYTES_PER_LINE: usize = 16;
|
||||||
const LINE_SEP_HORIZ: char = '─';
|
const LINE_SEP_HORIZ: char = '─';
|
||||||
|
@ -20,6 +20,7 @@ pub struct HeduConfig {
|
||||||
pub show_identical: bool,
|
pub show_identical: bool,
|
||||||
pub limit: usize,
|
pub limit: usize,
|
||||||
stop: bool,
|
stop: bool,
|
||||||
|
len: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeduConfig {
|
impl HeduConfig {
|
||||||
|
@ -28,8 +29,9 @@ impl HeduConfig {
|
||||||
chars,
|
chars,
|
||||||
skip,
|
skip,
|
||||||
show_identical,
|
show_identical,
|
||||||
limit: limit,
|
limit,
|
||||||
stop: false,
|
stop: false,
|
||||||
|
len: usize::MIN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +58,6 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> {
|
||||||
let mut buf: [[u8; BYTES_PER_LINE]; 2] = [[0; BYTES_PER_LINE]; 2];
|
let mut buf: [[u8; BYTES_PER_LINE]; 2] = [[0; BYTES_PER_LINE]; 2];
|
||||||
let mut alt_buf = 0usize;
|
let mut alt_buf = 0usize;
|
||||||
let mut byte_counter: usize = 0;
|
let mut byte_counter: usize = 0;
|
||||||
let mut len: usize;
|
|
||||||
|
|
||||||
// skip a given number of bytes
|
// skip a given number of bytes
|
||||||
if config.skip > 0 {
|
if config.skip > 0 {
|
||||||
|
@ -78,19 +79,19 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// data dump loop
|
// data dump loop
|
||||||
len = rd_data(data, &mut buf, &mut alt_buf, &mut byte_counter, &mut config).unwrap();
|
rd_data(data, &mut buf, &mut alt_buf, &mut byte_counter, &mut config)?;
|
||||||
while len > 0 {
|
while config.len > 0 {
|
||||||
print!("{:08X} {LINE_SEP_VERT} ", byte_counter);
|
print!("{:08X} {LINE_SEP_VERT} ", byte_counter);
|
||||||
for i in 0..len {
|
for i in 0..config.len {
|
||||||
if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 {
|
if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
}
|
}
|
||||||
print!("{:02X} ", buf[alt_buf][i]);
|
print!("{:02X} ", buf[alt_buf][i]);
|
||||||
}
|
}
|
||||||
if len == BYTES_PER_LINE / 2 {
|
if config.len == BYTES_PER_LINE / 2 {
|
||||||
print!(" ")
|
print!(" ")
|
||||||
}
|
}
|
||||||
for i in 0..(BYTES_PER_LINE - len) {
|
for i in 0..(BYTES_PER_LINE - config.len) {
|
||||||
if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 {
|
if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
}
|
}
|
||||||
|
@ -98,7 +99,7 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> {
|
||||||
}
|
}
|
||||||
if config.chars {
|
if config.chars {
|
||||||
print!("{LINE_SEP_VERT} |");
|
print!("{LINE_SEP_VERT} |");
|
||||||
for i in 0..len {
|
for i in 0..config.len {
|
||||||
print!("{}", mask_chars(buf[alt_buf][i] as char));
|
print!("{}", mask_chars(buf[alt_buf][i] as char));
|
||||||
}
|
}
|
||||||
print!("|");
|
print!("|");
|
||||||
|
@ -111,14 +112,13 @@ pub fn dump(data: &mut dyn DataSource, mut config: HeduConfig) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// after line logic
|
// after line logic
|
||||||
len = rd_data(data, &mut buf, &mut alt_buf, &mut byte_counter, &mut config).unwrap();
|
rd_data(data, &mut buf, &mut alt_buf, &mut byte_counter, &mut config)?;
|
||||||
alt_buf ^= 1; // toggle the alt buf
|
alt_buf ^= 1; // toggle the alt buf
|
||||||
if buf[0] == buf[1] && len == BYTES_PER_LINE && !config.show_identical {
|
if buf[0] == buf[1] && config.len == BYTES_PER_LINE && !config.show_identical {
|
||||||
trace!(buf = format!("{:?}", buf), "found a duplicating line");
|
trace!(buf = format!("{:?}", buf), "found a duplicating line");
|
||||||
let start_line = byte_counter;
|
let start_line = byte_counter;
|
||||||
while buf[0] == buf[1] && len == BYTES_PER_LINE {
|
while buf[0] == buf[1] && config.len == BYTES_PER_LINE {
|
||||||
len =
|
rd_data(data, &mut buf, &mut alt_buf, &mut byte_counter, &mut config)?;
|
||||||
rd_data(data, &mut buf, &mut alt_buf, &mut byte_counter, &mut config).unwrap();
|
|
||||||
byte_counter += BYTES_PER_LINE;
|
byte_counter += BYTES_PER_LINE;
|
||||||
}
|
}
|
||||||
println!(
|
println!(
|
||||||
|
@ -153,10 +153,10 @@ fn rd_data(
|
||||||
alt_buf: &mut usize,
|
alt_buf: &mut usize,
|
||||||
byte_counter: &mut usize,
|
byte_counter: &mut usize,
|
||||||
config: &mut HeduConfig,
|
config: &mut HeduConfig,
|
||||||
) -> Result<usize> {
|
) -> Result<()> {
|
||||||
|
*byte_counter += config.len;
|
||||||
match data.read(&mut buf[*alt_buf]) {
|
match data.read(&mut buf[*alt_buf]) {
|
||||||
Ok(mut len) => {
|
Ok(mut len) => {
|
||||||
*byte_counter += len; // FIXME: incremented too early! dump always starts at 0x10
|
|
||||||
if config.limit != 0 && *byte_counter >= config.limit {
|
if config.limit != 0 && *byte_counter >= config.limit {
|
||||||
trace!(
|
trace!(
|
||||||
byte_counter,
|
byte_counter,
|
||||||
|
@ -168,7 +168,8 @@ fn rd_data(
|
||||||
len = config.limit % BYTES_PER_LINE;
|
len = config.limit % BYTES_PER_LINE;
|
||||||
config.stop = true;
|
config.stop = true;
|
||||||
}
|
}
|
||||||
return Ok(len);
|
config.len = len;
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("error while reading data: {err}");
|
error!("error while reading data: {err}");
|
||||||
|
|
Reference in New Issue