From 1924b3ee49a7268f24f5b39693d4e22eca418a24 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 21 Jul 2024 00:24:53 +0200 Subject: Cleanup --- bxgen.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/bxgen.c b/bxgen.c index f6ad60b..743f75a 100755 --- a/bxgen.c +++ b/bxgen.c @@ -554,12 +554,32 @@ c8 *bx_find_char(c8 *s, c8 *s_end, c8 c) { BX_CHECK(s != NULL, "Invalid arguments", NULL); BX_CHECK(s_end != NULL, "Invalid arguments", NULL); - while (s != s_end && *s != c) + while (s < s_end && *s != c) ++s; return *s == c ? s : NULL; } +c8 *bx_find_str(c8 *s, c8 *s_end, c8 *sub, c8 *sub_end) { + BX_CHECK(s != NULL, "Invalid arguments", NULL); + BX_CHECK(s_end != NULL, "Invalid arguments", NULL); + BX_CHECK(sub != NULL, "Invalid arguments", NULL); + BX_CHECK(sub_end != NULL, "Invalid arguments", NULL); + + while (sub_end - sub <= s_end - s && s < s_end) { + c8 *q = s; + c8 *p = sub; + for (; q < s_end && p < sub_end; ++q, ++p) + if (*q != *p) + break; + if (p == sub_end) + return s; + ++s; + } + + return NULL; +} + i64 bx_i64_from_str(c8 *s, c8 *s_end) { BX_CHECK(s != NULL && s_end != NULL, "Invalid arguments", 0); BX_CHECK(s < s_end, "Buffer overflow", 0); @@ -2220,8 +2240,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data // ========================================================== // // Resolve undefined symbols - //if (0) - { + sec_index_global = 0; for (i64 elf_index = 0; elf_index < num_obj_files; ++elf_index) { @@ -2304,7 +2323,6 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data sec_index_global += elf_section_headers(buf).num - 1; } - } // ============================================================== // @@ -2315,9 +2333,6 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data for (i64 elf_index = 0; elf_index < num_obj_files; ++elf_index) { Buffer_Context buf = elf_buffer_context(pool, num_obj_files, elf_index); - elf_checks(buf); - elf_dump(VERBOSE, buf); - Offset_Num headers = elf_section_headers(buf); for (i64 sec_index = 1; sec_index < headers.num; ++sec_index, ++sec_index_global) -- cgit v1.2.3