From f87fbe96e95a02fb41dc0c7a9f2799740f41e872 Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 13 Sep 2022 21:19:42 +0200 Subject: [PATCH] Prepare convert function --- src/Tools/Tests/Planschbecken.cpp | 0 src/Tools/cpp_out/src/lib.rs | 14 ++++++-------- src/Tools/cpp_out/src/main.rs | 8 +++++--- src/Tools/tool_helper/src/lib.rs | 16 ++++++++++++---- 4 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 src/Tools/Tests/Planschbecken.cpp diff --git a/src/Tools/Tests/Planschbecken.cpp b/src/Tools/Tests/Planschbecken.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/Tools/cpp_out/src/lib.rs b/src/Tools/cpp_out/src/lib.rs index 1b4a90c9..9c0c550a 100644 --- a/src/Tools/cpp_out/src/lib.rs +++ b/src/Tools/cpp_out/src/lib.rs @@ -1,8 +1,6 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -} +use tool_helper::{Input, Output, Result}; +pub use tool_helper::Error; + +pub fn convert(_input: Input, _output: Output) -> Result<()> { + Err(Error::new(-1, "Not implemented yet".to_owned())) +} \ No newline at end of file diff --git a/src/Tools/cpp_out/src/main.rs b/src/Tools/cpp_out/src/main.rs index 5dda9caf..50f7ae01 100644 --- a/src/Tools/cpp_out/src/main.rs +++ b/src/Tools/cpp_out/src/main.rs @@ -14,8 +14,10 @@ struct CommandLine { fn run_main() -> tool_helper::Result<()> { match CommandLine::try_parse() { Ok(cmd) => { - let _output = tool_helper::open_output(cmd.input_file)?; - return Ok(()); + let input = tool_helper::open_input(cmd.input_file)?; + let output = tool_helper::open_output(Some(cmd.output_file))?; + + return cpp_out::convert(input, output); }, Err(error) => Err(tool_helper::Error::new(-1, error.to_string())) } @@ -23,7 +25,7 @@ fn run_main() -> tool_helper::Result<()> { fn main() { match run_main() { - Ok(_) => println!("All good"), + Ok(_) => (), Err(error) => { eprintln!("{}", error.text); std::process::exit(error.exit_code); diff --git a/src/Tools/tool_helper/src/lib.rs b/src/Tools/tool_helper/src/lib.rs index a161a427..4169063f 100644 --- a/src/Tools/tool_helper/src/lib.rs +++ b/src/Tools/tool_helper/src/lib.rs @@ -1,6 +1,7 @@ -use std::{boxed::Box, io::Write, path::PathBuf}; +use std::{boxed::Box, io::{Read, Write}, path::PathBuf}; pub type Output = Box; +pub type Input = Box; pub type Result = std::result::Result; pub struct Error { @@ -30,9 +31,16 @@ impl Error { } } -pub fn open_output(input_file: Option) -> Result { +pub fn open_output(output_file: Option) -> Result { + match output_file { + Some(output_path) => Ok(Box::new(Error::from_io_result(std::fs::File::create(output_path))?)), + None => Ok(Box::new(std::io::stdout())), + } +} + +pub fn open_input(input_file: Option) -> Result { match input_file { - Some(input_path) => Ok(Box::new(Error::from_io_result(std::fs::File::create(input_path))?)), - None => Ok(Box::new(std::io::stdout())), + Some(input_path) => Ok(Box::new(Error::from_io_result(std::fs::File::open(input_path))?)), + None => Ok(Box::new(std::io::stdin())), } } \ No newline at end of file