Integrate all the progress into master #6

Merged
jaby merged 595 commits from ToolBox into main 2025-01-01 13:17:44 +00:00
3 changed files with 24 additions and 13 deletions
Showing only changes of commit f21210c042 - Show all commits

View File

@ -2,20 +2,22 @@ pub mod types;
use tool_helper::{Error, Input};
use std::io::BufRead;
use types::{Content, Section};
use types::{Content, MemoryMapInfo, Section};
pub fn scan(input: Input) -> Result<Vec<Section>, Error> {
let sections = process(input.lines().map(|l| l.unwrap()).into_iter())?;
pub fn scan(input: Input) -> Result<MemoryMapInfo, Error> {
let (sections, highest_address) = process(input.lines().map(|l| l.unwrap()).into_iter())?;
Ok(sections)
Ok(MemoryMapInfo{sections, highest_address: highest_address})
}
fn process<F: std::iter::Iterator<Item=String>>(mut line_iter:F) -> Result<Vec<Section>, Error> {
let mut sections = Vec::new();
fn process<F: std::iter::Iterator<Item=String>>(mut line_iter:F) -> Result<(Vec<Section>, u64), Error> {
let mut sections = Vec::new();
let mut highest_address = 0u64;
while let Some(mut line) = line_iter.next() {
loop {
if line.starts_with(".") {
let (new_line, new_section) = process_section(line, &mut line_iter)?;
let (new_line, new_section) = process_section(&mut highest_address, line, &mut line_iter)?;
sections.push(new_section);
line = new_line;
@ -30,19 +32,19 @@ fn process<F: std::iter::Iterator<Item=String>>(mut line_iter:F) -> Result<Vec<S
sections.sort_by(|left, right| {
left.adr.cmp(&right.adr)
});
Ok(sections)
Ok((sections, highest_address))
}
fn process_section<F: std::iter::Iterator<Item=String>>(line: String, line_iter:&mut F) -> Result<(String, Section), Error> {
fn process_section<F: std::iter::Iterator<Item=String>>(highest_address: &mut u64, line: String, line_iter:&mut F) -> Result<(String, Section), Error> {
let mut next_line_closure = || {
line_iter.next().ok_or(Error::from_str("Unexpected end of file"))
};
let (mut section, line) = read_section(line, &mut next_line_closure)?;
Ok((process_subsection(&mut section, line, &mut next_line_closure)?, section))
Ok((process_subsection(&mut section, highest_address, line, &mut next_line_closure)?, section))
}
fn process_subsection<F:FnMut()-> Result<String, Error>>(section: &mut Section, line: Option<String>, next_line: &mut F) -> Result<String, Error> {
fn process_subsection<F:FnMut()-> Result<String, Error>>(section: &mut Section, highest_address: &mut u64, line: Option<String>, next_line: &mut F) -> Result<String, Error> {
fn push_sub_section(section: &mut Section, sub_section: Option<Section>) {
if let Some(sub_section) = sub_section {
section.content.push(Content::Section(sub_section));
@ -105,6 +107,10 @@ fn process_subsection<F:FnMut()-> Result<String, Error>>(section: &mut Section,
else if line.starts_with(" 0x") {
if let Some(symbol) = parse_symbol(read_symbol(line)?) {
if symbol.adr > *highest_address {
*highest_address = symbol.adr;
}
sub_section = add_element(sub_section, section, symbol, |section, symbol| {
section.content.push(Content::Symbol(symbol));
});

View File

@ -1,5 +1,10 @@
use std::default::Default;
pub struct MemoryMapInfo {
pub sections: Vec<Section>,
pub highest_address: u64,
}
#[derive(Default)]
pub struct Section {
pub name: String,

View File

@ -1,5 +1,5 @@
use crossterm::event::KeyCode;
use readmap::types::Section;
use readmap::types::MemoryMapInfo;
use std::path::PathBuf;
use tool_helper::Error;
use tui::{
@ -211,6 +211,6 @@ impl ConsoleUI {
}
}
pub fn load_memory_map(file_path: Option<PathBuf>) -> Result<Vec<Section>, Error> {
pub fn load_memory_map(file_path: Option<PathBuf>) -> Result<MemoryMapInfo, Error> {
readmap::scan(tool_helper::open_input(file_path)?)
}