From 5c098cfc98af658e72247f983e7aa7aea60fa4f9 Mon Sep 17 00:00:00 2001 From: "adam@2khz.xyz" Date: Sun, 17 Aug 2025 01:00:16 +0100 Subject: [PATCH] 0.2.1: bug fix overwrite mode --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cfg.rs | 6 +++--- src/constants.rs | 4 ++++ src/main.rs | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf09fcd..360c89c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "bin2hpp" -version = "0.2.0" +version = "0.2.1" dependencies = [ "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 7aa17ee..018b2b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bin2hpp" -version = "0.2.0" +version = "0.2.1" authors = ["Adam Macdonald"] edition = "2024" license = "GPL-3.0-only" diff --git a/src/cfg.rs b/src/cfg.rs index 9925708..221f388 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -69,7 +69,7 @@ pub fn parse_config_from_args(args: &CliArgs) -> Result { - if s.chars().all(|c| c.is_ascii_alphanumeric()) { + if s.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { s.to_string() } else { return Err(ProgramConfigError::InvalidSymbolName(s.to_string())); @@ -101,7 +101,7 @@ pub fn parse_config_from_args(args: &CliArgs) -> Result { - if ns.chars().all(|c| c.is_ascii_alphanumeric()) { + if ns.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { Some(ns.to_string()) } else { return Err(ProgramConfigError::InvalidSymbolName(ns.to_string())); @@ -111,7 +111,7 @@ pub fn parse_config_from_args(args: &CliArgs) -> Result { - if guard.chars().all(|c| c.is_ascii_alphanumeric()) { + if guard.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { guard.clone() } else { return Err(ProgramConfigError::InvalidSymbolName(guard.to_string())); diff --git a/src/constants.rs b/src/constants.rs index d875060..5dff3f4 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -21,9 +21,11 @@ OUTPUT OPTIONS: --lf Use UNIX-style LF line endings (default) --crlf Use Windows-style CRLF line endings + --mutable Whether the symbol should not be marked as const --const Whether the symbol should be marked as const (default) --constexpr Whether the symbol should be marked as constexpr (C++ mode) + --symname NAME Symbol name --namespace NAME Namespace in which the symbol will exist (uses namespace example {} in C++ mode and prepends @@ -46,5 +48,7 @@ BYTES TYPES FOR ARRAYS: --u8 C/C++'s (std::)uint8_t type --i8 C/C++'s (std::)int8_t type +MISCELLANEOUS: + -h | --help Show this help text -v | --version Print the program's build & version information"; diff --git a/src/main.rs b/src/main.rs index e155675..0b0185d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,7 +87,7 @@ fn write_header(config: &Config) -> Result<(), HeaderGenerationError> { let out_file = OpenOptions::new() .write(true) .truncate(config.overwrite) - .create_new(!config.overwrite) + .create(true) .open(config.output_file_path.clone()) .expect("failed to open input file"); let mut writer = BufWriter::new(out_file);