Change name of variable
This commit is contained in:
parent
640f220b98
commit
db897e0f3d
|
@ -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 "Test_Planschbecken.cpp"
|
||||
@echo "Planschbecken" | ./../cpp_out/target/release/cpp_out --name Dino -o "Test_Planschbecken.cpp"
|
||||
|
||||
always: ;
|
|
@ -1,4 +1,4 @@
|
|||
use tool_helper::{Input, Output, Result};
|
||||
use tool_helper::{Input, Output};
|
||||
use std::io::Read;
|
||||
pub use tool_helper::Error;
|
||||
|
||||
|
@ -32,31 +32,31 @@ const WINDOWS_LINEFEED: &'static str = "\r\n";
|
|||
const C_VARIABLES: FileVariables = FileVariables{include: "", var_type: "char"};
|
||||
const CPP_VARIABLES: FileVariables = FileVariables{include: "#include <stdint.h>", var_type: "uint8_t"};
|
||||
|
||||
fn write_source_file(variables: &FileVariables, input: Input, output: &mut Output, line_feed: &str) -> Result<()> {
|
||||
Error::try_or_new(write!(output, "{}{}{}", variables.include, line_feed, line_feed), None)?;
|
||||
Error::try_or_new(write!(output, "const {} data[] = {{{}", variables.var_type, line_feed), None)?;
|
||||
fn write_source_file(input: Input, output: &mut Output, variables: &FileVariables, data_name: String, line_feed: &str) -> Result<(), std::io::Error> {
|
||||
write!(output, "{}{}{}", variables.include, line_feed, line_feed)?;
|
||||
write!(output, "const {} {}[] = {{{}", variables.var_type, data_name, line_feed)?;
|
||||
|
||||
let mut byte_line_count = 1;
|
||||
let mut bytes = input.bytes();
|
||||
|
||||
if let Some(byte) = bytes.next() {
|
||||
Error::try_or_new(write!(output, "\t{:#04X}", Error::try_or_new(byte, None)?), None)?;
|
||||
write!(output, "\t{:#04X}", byte?)?;
|
||||
|
||||
for byte in bytes {
|
||||
Error::try_or_new(write!(output, ", {:#04X}", Error::try_or_new(byte, None)?), None)?;
|
||||
write!(output, ", {:#04X}", byte?)?;
|
||||
byte_line_count += 1;
|
||||
|
||||
if byte_line_count >= 16 {
|
||||
Error::try_or_new(write!(output, "{}\t", line_feed), None)?;
|
||||
write!(output, "{}\t", line_feed)?;
|
||||
byte_line_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Error::try_or_new(write!(output, "{}}};", line_feed), None)?;
|
||||
write!(output, "{}}};", line_feed)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn convert(cfg: Configuration, input: Input, mut output: Output) -> Result<()> {
|
||||
pub fn convert(cfg: Configuration, input: Input, mut output: Output) -> Result<(), Error> {
|
||||
let line_feed = {
|
||||
match cfg.line_feed {
|
||||
LineFeed::Windows => WINDOWS_LINEFEED,
|
||||
|
@ -71,5 +71,5 @@ pub fn convert(cfg: Configuration, input: Input, mut output: Output) -> Result<(
|
|||
}
|
||||
};
|
||||
|
||||
write_source_file(source_variables, input, &mut output, line_feed)
|
||||
Error::try_or_new(write_source_file(input, &mut output, source_variables, cfg.data_name, line_feed), None)
|
||||
}
|
|
@ -8,11 +8,14 @@ struct CommandLine {
|
|||
#[clap(short='f', long="file")]
|
||||
input_file: Option<PathBuf>,
|
||||
|
||||
#[clap(short='n', long="name")]
|
||||
data_name: String,
|
||||
|
||||
#[clap(short='o')]
|
||||
output_file: PathBuf,
|
||||
}
|
||||
|
||||
fn configurate(cmd: &CommandLine) -> tool_helper::Result<Configuration> {
|
||||
fn configurate(cmd: &mut CommandLine) -> tool_helper::Result<Configuration> {
|
||||
let file_name = tool_helper::get_file_name_from_path_buf(&cmd.output_file, "output")?;
|
||||
let extension = tool_helper::os_str_to_string(Error::ok_or_new(cmd.output_file.extension(), ||"File extension required for output".to_owned(), None)?, "extension")?.to_ascii_lowercase();
|
||||
let file_type = Error::ok_or_new({
|
||||
|
@ -25,13 +28,13 @@ fn configurate(cmd: &CommandLine) -> tool_helper::Result<Configuration> {
|
|||
}
|
||||
}, ||format!("{} unkown file extension", extension), None)?;
|
||||
|
||||
Ok(Configuration{file_name, data_name: "Planschbecken".to_owned(), line_feed: cpp_out::LineFeed::Windows, file_type})
|
||||
Ok(Configuration{file_name, data_name: std::mem::take(&mut cmd.data_name), line_feed: cpp_out::LineFeed::Windows, file_type})
|
||||
}
|
||||
|
||||
fn run_main() -> tool_helper::Result<()> {
|
||||
match CommandLine::try_parse() {
|
||||
Ok(cmd) => {
|
||||
let cfg = configurate(&cmd)?;
|
||||
Ok(mut cmd) => {
|
||||
let cfg = configurate(&mut cmd)?;
|
||||
let input = tool_helper::open_input(cmd.input_file)?;
|
||||
let output = tool_helper::open_output(Some(cmd.output_file))?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue