Produce first output
This commit is contained in:
parent
f87fbe96e9
commit
0e38801bd5
|
@ -2,3 +2,5 @@
|
||||||
Input/**
|
Input/**
|
||||||
Output/**
|
Output/**
|
||||||
*.lock
|
*.lock
|
||||||
|
|
||||||
|
**/Tests/Test_*.cpp
|
|
@ -2,6 +2,6 @@ export PATH := $(HOME)/.cargo/bin/:$(PATH)
|
||||||
|
|
||||||
test_cpp_out: always
|
test_cpp_out: always
|
||||||
@cargo build --manifest-path ../cpp_out/Cargo.toml --release
|
@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: ;
|
always: ;
|
|
@ -1,6 +1,13 @@
|
||||||
use tool_helper::{Input, Output, Result};
|
use tool_helper::{Input, Output, Result};
|
||||||
pub use tool_helper::Error;
|
pub use tool_helper::Error;
|
||||||
|
|
||||||
pub fn convert(_input: Input, _output: Output) -> Result<()> {
|
fn write_cpp(_input: Input, output: &mut Output, line_feed: &str) -> Result<()> {
|
||||||
Err(Error::new(-1, "Not implemented yet".to_owned()))
|
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}
|
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 {
|
match result {
|
||||||
Ok(value) => Ok(value),
|
Ok(value) => Ok(value),
|
||||||
Err(error) => Err(Error::new({
|
Err(error) => Err(Error::new(Self::get_exit_code(exit_code), error.to_string())),
|
||||||
match exit_code {
|
|
||||||
Some(exit_code) => exit_code,
|
|
||||||
None => -1,
|
|
||||||
}
|
|
||||||
}, error.to_string())),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_io_result<T>(result: std::result::Result<T, std::io::Error>) -> Result<T> {
|
pub fn try_with<T, S>(result: std::result::Result<T, S>) -> Result<T> where S: std::fmt::Display {
|
||||||
Self::from_io_result_with_code(result, None)
|
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> {
|
pub fn open_output(output_file: Option<PathBuf>) -> Result<Output> {
|
||||||
match output_file {
|
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())),
|
None => Ok(Box::new(std::io::stdout())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input> {
|
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input> {
|
||||||
match input_file {
|
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())),
|
None => Ok(Box::new(std::io::stdin())),
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue