diff --git a/src/Tools/Tools.code-workspace b/src/Tools/Tools.code-workspace index aed8c246..77ceba0c 100644 --- a/src/Tools/Tools.code-workspace +++ b/src/Tools/Tools.code-workspace @@ -82,7 +82,7 @@ "", "--help", "--list -o ../Tests/Test_Planschbecken psx bin-cue ../Tests/ISO_Planschbecken.xml", - "${workspaceFolder}/../../examples/PoolBox/application/bin/PSX-release/PoolBox.map" + "--wsl ../../../examples/PoolBox/application/bin/PSX-release/PoolBox.elf" ], "default": "", "description": "Argument options to pass to cargo run" diff --git a/src/Tools/readmap/src/main.rs b/src/Tools/readmap/src/main.rs index 91445a6f..f380a065 100644 --- a/src/Tools/readmap/src/main.rs +++ b/src/Tools/readmap/src/main.rs @@ -1,16 +1,53 @@ use clap::Parser; use readmap::types::{Content::*, Section}; use tool_helper::{Error, exit_with_error}; -use std::{fs::File, io::{BufWriter, Write}, path::PathBuf}; +use std::{fs::File, io::{BufRead, BufReader, BufWriter, Write}, path::PathBuf, process::{Child, Command, Stdio}}; #[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 + input: PathBuf, + #[clap(long="wsl", default_value_t=false)] + use_wsl: bool, +} + +fn run_objdump(use_wsl: bool, input: PathBuf) -> Result { + let command_list = ["wsl", "objdump", "-x"]; + let start_idx = { + if use_wsl { + 0 + } + + else { + 1 + } + }; + let mut process = Command::new(command_list[start_idx]); + + for arg in command_list.iter().skip(start_idx + 1) { + process.arg(arg); + } + process.arg(input.to_str().ok_or_else(||{Error::from_str("Failed converting input string")})?); + + println!("Miau: {:?}", process); + Ok(process.stdout(Stdio::piped()).spawn()?) } fn run_main(cmd: CommandLine) -> Result<(), Error> { + let mut child = run_objdump(cmd.use_wsl, cmd.input)?; + if let Some(stdout) = &mut child.stdout { + for line in BufReader::new(stdout).lines() { + if let Ok(line) = line { + println!("{}", line); + } + } + } + + Ok(()) +} + +fn _run_main(cmd: CommandLine) -> Result<(), Error> { fn value_to_hex(value: T) -> String { return format!("0x{:X}", value); } @@ -25,8 +62,8 @@ fn run_main(cmd: CommandLine) -> Result<(), Error> { } } - let sections = readmap::scan(tool_helper::open_input(cmd.input)?)?; - let mut file = tool_helper::open_output_file(&PathBuf::from("./planschi.txt"))?; + let sections = readmap::scan(tool_helper::open_input(Some(cmd.input))?)?; + let mut file = tool_helper::open_output_file(&PathBuf::from("./planschi.d"))?; for section in sections { fn print_content(tab_level: usize, file: &mut BufWriter, section: Section) -> Result<(), Error> {