Parse with weird printf bug
This commit is contained in:
parent
947177661a
commit
59472a3f31
|
@ -1,8 +1,46 @@
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
use types::MemoryMap;
|
use types::{MemoryMap, Section};
|
||||||
|
|
||||||
pub fn scan<F: FnMut() -> Option<String>>(_next_line: F) -> Result<MemoryMap, Error> {
|
pub fn scan<F: FnMut() -> Option<String>>(mut next_line: F) -> Result<MemoryMap, Error> {
|
||||||
|
const SECTION_IDENTIFIER:&'static str = "Sections:";
|
||||||
|
const SYMBOL_TABLE_IDENTIFIER:&'static str = "SYMBOL TABLE:";
|
||||||
|
|
||||||
|
while let Some(line) = next_line() {
|
||||||
|
if line == SECTION_IDENTIFIER {
|
||||||
|
scan_sections(&mut next_line)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if line == SYMBOL_TABLE_IDENTIFIER {}
|
||||||
|
}
|
||||||
Err(Error::not_implemented("scan"))
|
Err(Error::not_implemented("scan"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scan_sections<F: FnMut() -> Option<String>>(next_line: &mut F) -> Result<Vec<Section>, Error> {
|
||||||
|
while let Some(_) = next_line() {
|
||||||
|
// We read every other line
|
||||||
|
let line = next_line().ok_or(Error::from_str("Failed skipping section line"))?;
|
||||||
|
let mut split_line = line.split_whitespace();
|
||||||
|
if let Ok(_) = split_line_radix(&mut split_line, 10, "") {
|
||||||
|
let name = split_line.next().ok_or(Error::from_str("Failed reading Section Name"))?;
|
||||||
|
let size = split_line_radix(&mut split_line, 16, "Section Size")?;
|
||||||
|
let adr = split_line_radix(&mut split_line, 16, "Section Address")?;
|
||||||
|
|
||||||
|
println!("\"{}\" @0x{:X} -> 0x{:X}", name, adr, (adr + size));
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
return Err(Error::from_str("<No proper return value yet>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(Error::not_implemented("scan"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn split_line_radix<'a>(split_line: &mut std::str::SplitWhitespace<'a>, radix: u32, value_name: &str) -> Result<u64, Error> {
|
||||||
|
match u64::from_str_radix(split_line.next().ok_or(Error::from_text(format!("Failed reading: {}", value_name)))?, radix) {
|
||||||
|
Ok(value) => Ok(value),
|
||||||
|
Err(error) => Err(Error::from_text(format!("Converting value for {} failed with: {}", value_name, error)))
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue