Produce first output
This commit is contained in:
parent
4b69d678e8
commit
888a6247a9
|
@ -1,4 +1,6 @@
|
|||
**/target
|
||||
Input/**
|
||||
Output/**
|
||||
*.lock
|
||||
*.lock
|
||||
|
||||
**/Tests/Test_*.cpp
|
|
@ -2,6 +2,6 @@ export PATH := $(HOME)/.cargo/bin/:$(PATH)
|
|||
|
||||
test_cpp_out: always
|
||||
@cargo build --manifest-path ../cpp_out/Cargo.toml --release
|
||||
@echo "Planschbecken" | ./../cpp_out/target/release/cpp_out -o "Planschbecken.cpp"
|
||||
@echo "Planschbecken" | ./../cpp_out/target/release/cpp_out -o "Test_Planschbecken.cpp"
|
||||
|
||||
always: ;
|
|
@ -1,6 +1,13 @@
|
|||
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()))
|
||||
fn write_cpp(_input: Input, output: &mut Output, line_feed: &str) -> Result<()> {
|
||||
Error::try_with(write!(output, "const char data[] = {{{}", line_feed))?;
|
||||
Error::try_with(write!(output, "}};"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn convert(_input: Input, mut output: Output) -> Result<()> {
|
||||
write_cpp(_input, &mut output, "\r\n")
|
||||
}
|
|
@ -14,33 +14,35 @@ impl Error {
|
|||
Error{exit_code, text}
|
||||
}
|
||||
|
||||
pub fn from_io_result_with_code<T>(result: std::result::Result<T, std::io::Error>, exit_code: Option<i32>) -> Result<T> {
|
||||
pub fn try_with_code<T, S>(result: std::result::Result<T, S>, exit_code: Option<i32>) -> Result<T> where S: std::fmt::Display {
|
||||
match result {
|
||||
Ok(value) => Ok(value),
|
||||
Err(error) => Err(Error::new({
|
||||
match exit_code {
|
||||
Some(exit_code) => exit_code,
|
||||
None => -1,
|
||||
}
|
||||
}, error.to_string())),
|
||||
Err(error) => Err(Error::new(Self::get_exit_code(exit_code), error.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_io_result<T>(result: std::result::Result<T, std::io::Error>) -> Result<T> {
|
||||
Self::from_io_result_with_code(result, None)
|
||||
pub fn try_with<T, S>(result: std::result::Result<T, S>) -> Result<T> where S: std::fmt::Display {
|
||||
Self::try_with_code(result, None)
|
||||
}
|
||||
|
||||
fn get_exit_code(exit_code: Option<i32>) -> i32 {
|
||||
match exit_code {
|
||||
Some(exit_code) => exit_code,
|
||||
None => -1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_output(output_file: Option<PathBuf>) -> Result<Output> {
|
||||
match output_file {
|
||||
Some(output_path) => Ok(Box::new(Error::from_io_result(std::fs::File::create(output_path))?)),
|
||||
Some(output_path) => Ok(Box::new(Error::try_with(std::fs::File::create(output_path))?)),
|
||||
None => Ok(Box::new(std::io::stdout())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input> {
|
||||
match input_file {
|
||||
Some(input_path) => Ok(Box::new(Error::from_io_result(std::fs::File::open(input_path))?)),
|
||||
Some(input_path) => Ok(Box::new(Error::try_with(std::fs::File::open(input_path))?)),
|
||||
None => Ok(Box::new(std::io::stdin())),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue