fix buffersize bug, misc. display bugs
This commit is contained in:
parent
66d85edd8f
commit
35a34622c8
15
hdinfo.rs
15
hdinfo.rs
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user