From 660faeb1a2605cde8431784e4b0882bf878b7806 Mon Sep 17 00:00:00 2001 From: jaby Date: Sun, 25 Jun 2023 15:58:23 +0200 Subject: [PATCH] Introduce types for readmap --- src/Tools/Tools.code-workspace | 2 +- src/Tools/readmap/Cargo.toml | 2 ++ src/Tools/readmap/src/lib.rs | 16 ++++------- src/Tools/readmap/src/main.rs | 31 ++++++++++++++++++++ src/Tools/readmap/src/types/mod.rs | 45 ++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 src/Tools/readmap/src/types/mod.rs diff --git a/src/Tools/Tools.code-workspace b/src/Tools/Tools.code-workspace index a1732433..dd890969 100644 --- a/src/Tools/Tools.code-workspace +++ b/src/Tools/Tools.code-workspace @@ -59,7 +59,7 @@ { "id": "project", "type": "pickString", - "options": ["cdtypes", "cpp_out", "jaby_engine_fconv", "mkoverlay", "psxcdgen", "psxcdgen_ex", "psxcdread", "tool_helper", "wslpath"], + "options": ["cdtypes", "cpp_out", "jaby_engine_fconv", "mkoverlay", "psxcdgen", "psxcdgen_ex", "psxcdread", "readmap", "tool_helper", "wslpath"], "description": "project to build" }, { diff --git a/src/Tools/readmap/Cargo.toml b/src/Tools/readmap/Cargo.toml index 7788a76d..2dc9112b 100644 --- a/src/Tools/readmap/Cargo.toml +++ b/src/Tools/readmap/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = {version = "*", features = ["derive"]} +tool_helper = {path = "../tool_helper"} \ No newline at end of file diff --git a/src/Tools/readmap/src/lib.rs b/src/Tools/readmap/src/lib.rs index 7d12d9af..0b8d4e9c 100644 --- a/src/Tools/readmap/src/lib.rs +++ b/src/Tools/readmap/src/lib.rs @@ -1,14 +1,8 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} +pub mod types; -#[cfg(test)] -mod tests { - use super::*; +use tool_helper::{Error, Input}; +use types::Section; - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +pub fn scan(input: Input) -> Result, Error> { + Err(Error::not_implemented("readmap::scan")) } diff --git a/src/Tools/readmap/src/main.rs b/src/Tools/readmap/src/main.rs index e69de29b..bbc4b0e9 100644 --- a/src/Tools/readmap/src/main.rs +++ b/src/Tools/readmap/src/main.rs @@ -0,0 +1,31 @@ +use clap::Parser; +use tool_helper::{Error, exit_with_error}; +use std::path::PathBuf; + +#[derive(Parser)] +#[clap(about = "Opens and scans a MAP file to print extended information", long_about = None)] +struct CommandLine { + #[clap(value_parser, help="Input MAP file for scannning")] + input: Option +} + +fn run_main(cmd: CommandLine) -> Result<(), Error> { + let _sections = readmap::scan(tool_helper::open_input(cmd.input)?)?; + + println!("Found sections!"); + Ok(()) +} + +pub fn main() { + match CommandLine::try_parse() { + Ok(cmd_line) => { + match run_main(cmd_line) { + Ok(_) => (), + Err(error) => exit_with_error(error) + } + }, + Err(error) => { + exit_with_error(Error::from_error(error)); + } + } +} \ No newline at end of file diff --git a/src/Tools/readmap/src/types/mod.rs b/src/Tools/readmap/src/types/mod.rs new file mode 100644 index 00000000..d599e196 --- /dev/null +++ b/src/Tools/readmap/src/types/mod.rs @@ -0,0 +1,45 @@ +use std::default::Default; + +#[derive(Default)] +pub struct Section { + name: String, + adr: u64, + size: usize, + content: Vec +} + +#[derive(Default)] +pub struct Symbol { + name: String, + adr: u64, +} + +#[derive(Default)] +pub struct Fill { + adr: u64, + size: usize, +} + +pub enum Content { + Fill, + Section(Section), + Symbol(Symbol), +} + +impl Section { + pub fn new(name: String, adr: u64, size: usize) -> Section { + Section{name, adr, size, content: Vec::new()} + } +} + +impl Symbol { + pub fn new(name: String, adr: u64) -> Symbol { + Symbol{name, adr} + } +} + +impl Fill { + pub fn new(adr: u64, size: usize) -> Fill { + Fill{adr, size} + } +} \ No newline at end of file