From bae01255755442c328bcb029937d9ddb9466ea3f Mon Sep 17 00:00:00 2001 From: Hossain Khademian Date: Fri, 23 Feb 2024 11:06:13 +0100 Subject: [PATCH 1/2] refactor bundle byte print in rows the operation of printing full rows and the last reminder row can both happen in a single impl. the inner loop checks for both ROW count and also preserve overall SIZE limit. --- nob.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/nob.c b/nob.c index 9c88019..a498176 100644 --- a/nob.c +++ b/nob.c @@ -132,19 +132,9 @@ bool generate_resource_bundle(void) genf(out, "unsigned char bundle[] = {"); size_t row_size = 20; - for (size_t row = 0; row < bundle.count/row_size; ++row){ + for (size_t i = 0; i < bundle.count; ++i){ fprintf(out, " "); - for (size_t col = 0; col < row_size; ++col) { - size_t i = row*row_size + col; - fprintf(out, "0x%02X, ", (unsigned char)bundle.items[i]); - } - genf(out, ""); - } - size_t remainder = bundle.count%row_size; - if (remainder > 0) { - fprintf(out, " "); - for (size_t col = 0; col < remainder; ++col) { - size_t i = bundle.count/row_size*row_size + col; + for (size_t col = 0; col < row_size && i < bundle.count; ++col, ++i) { fprintf(out, "0x%02X, ", (unsigned char)bundle.items[i]); } genf(out, ""); From 5e6b389213138879d852e6d1ad9d11cb8ef5e44e Mon Sep 17 00:00:00 2001 From: Hossain Khademian Date: Fri, 23 Feb 2024 17:19:14 +0100 Subject: [PATCH 2/2] fix extra ittr step --- nob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nob.c b/nob.c index a498176..b1339cc 100644 --- a/nob.c +++ b/nob.c @@ -132,7 +132,7 @@ bool generate_resource_bundle(void) genf(out, "unsigned char bundle[] = {"); size_t row_size = 20; - for (size_t i = 0; i < bundle.count; ++i){ + for (size_t i = 0; i < bundle.count; ){ fprintf(out, " "); for (size_t col = 0; col < row_size && i < bundle.count; ++col, ++i) { fprintf(out, "0x%02X, ", (unsigned char)bundle.items[i]);