fix buffersize bug, misc. display bugs

This commit is contained in:
corey 2024-01-09 10:43:28 -06:00
parent 66d85edd8f
commit 35a34622c8
2 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,5 @@
// Contain information for hexdump
const BUFFERSIZE:usize=4096;
pub struct Hdinfo
{
pub columns:usize,
@ -104,7 +103,7 @@ impl Hdinfo
for j in 0..self.columns
{
if i+j>=length {break;}
if (buffer[i+j] as u32 > 32) && (buffer[i+j] as u32) < 128
if (buffer[i+j] as u32 > 32) && (buffer[i+j] as u32) < 127
{
print!("{}",buffer[i+j] as char);
}
@ -119,17 +118,21 @@ impl Hdinfo
i+=self.columns;
}
self.offset+=length;
print!("\n");
}
pub fn hexdump_filenames_or_stdin(&mut self,filenames:&Vec<String>)
{
// Round up to nearest multiple of self.columns
let buffersize:usize=(BUFFERSIZE+self.columns)-(BUFFERSIZE%self.columns);
// Hexdump each argument previously
// identified as a filename
if filenames.len()==0
{
let mut buffer:Vec<u8>=vec![0;BUFFERSIZE];
let mut buffer:Vec<u8>=vec![0;buffersize];
let mut file=std::io::stdin().lock();
// Hexdump input
loop
{
let n_read=match std::io::Read::read(&mut file,&mut buffer)
@ -157,7 +160,7 @@ impl Hdinfo
print!("{}:\n",filename);
}
let mut buffer:Vec<u8>=vec![0;BUFFERSIZE];
let mut buffer:Vec<u8>=vec![0;buffersize];
let mut file=match std::fs::File::open(filename)
{
Ok(ff)=>ff,
@ -166,6 +169,8 @@ impl Hdinfo
std::process::exit(1);
}
};
// Hexdump file
loop
{
let n_read=match std::io::Read::read(&mut file,&mut buffer)

View File

@ -3,8 +3,8 @@ mod hdinfo;
fn main()
{
let mut filenames:Vec<String>=vec!();
let mut state:hdinfo::Hdinfo=parseargs(&mut filenames);
let mut filenames=vec!();
let mut state=parseargs(&mut filenames);
state.hexdump_filenames_or_stdin(&filenames);
}