Introduce types for readmap

This commit is contained in:
Jaby Blubb 2023-06-25 15:58:23 +02:00
parent b7b5490d0c
commit d342f6ebc4
5 changed files with 84 additions and 12 deletions

View File

@ -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"
},
{

View File

@ -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"}

View File

@ -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<Vec<Section>, Error> {
Err(Error::not_implemented("readmap::scan"))
}

View File

@ -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<PathBuf>
}
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));
}
}
}

View File

@ -0,0 +1,45 @@
use std::default::Default;
#[derive(Default)]
pub struct Section {
name: String,
adr: u64,
size: usize,
content: Vec<Content>
}
#[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}
}
}