From 45f90c98cf44c0e81dedb7720b1aa48368033e63 Mon Sep 17 00:00:00 2001 From: ygor Date: Sun, 27 Oct 2024 20:47:14 -0300 Subject: [PATCH] avoid multiple underscores in module name --- src/build/project_creation.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/build/project_creation.c b/src/build/project_creation.c index 23d2cfb7e..03bd260bd 100644 --- a/src/build/project_creation.c +++ b/src/build/project_creation.c @@ -301,27 +301,35 @@ static const char *module_name(BuildOptions *build_options) scratch_buffer_clear(); size_t len = strlen(build_options->project_name); bool has_char = false; + bool appended_underscore = false; for (size_t i = 0; i < len; i++) { char c = build_options->project_name[i]; if (c >= '0' && c <= '9') { if (!has_char) scratch_buffer_append("m_"); - has_char = true; scratch_buffer_append_char(c); + has_char = true; + appended_underscore=false; continue; } if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { scratch_buffer_append_char(c | 0x20); has_char = true; + appended_underscore=false; continue; } - scratch_buffer_append_char('_'); + if (!appended_underscore) + { + scratch_buffer_append_char('_'); + appended_underscore = true; + } } if (!has_char) scratch_buffer_append("module"); return scratch_buffer_to_string(); } + static void create_file_or_fail(BuildOptions *build_options, const char *filename, const char *fmt, ...) { if (!fmt)