From b71b3b4479177fe9d3f28a7a4eff309ca80a3b9f Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Tue, 1 Dec 2020 16:09:21 +0100 Subject: [PATCH] generates the wrapper correctly --- generator/src/main.c | 31 ++++++++++++++++++++----------- generator/src/tstring.c | 28 +++++++++++++++++----------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/generator/src/main.c b/generator/src/main.c index 4d2a24c..4eb15b0 100644 --- a/generator/src/main.c +++ b/generator/src/main.c @@ -5,19 +5,28 @@ void generator( tstring* source_filename, tstring* prefix, tstring* bucket_count, - tstring* K_size, tstring* K_comp_pred, tstring* K_hash_func, + tstring* K_size, + tstring* K_comp_pred, + tstring* K_hash_func, tstring* V_size ); -int main() { +int main(int argc, char** argv) { + if(argc <= 8) { + printf( + "> LHM wrapper generator\n" + "%s generated_header generated_source prefix bucket_count key_byte_size comparison_func hash_func value_byte_size\n" + , argv[0] + ); + } else generator( - cstring_to_tstring("./generated_header.h"), - cstring_to_tstring("./generated_source.cpp"), - cstring_to_tstring("test"), - cstring_to_tstring("8000"), - cstring_to_tstring("8"), - cstring_to_tstring("test_key_comp"), - cstring_to_tstring("test_key_hash"), - cstring_to_tstring("128") + cstring_to_tstring(argv[1]), + cstring_to_tstring(argv[2]), + cstring_to_tstring(argv[3]), + cstring_to_tstring(argv[4]), + cstring_to_tstring(argv[5]), + cstring_to_tstring(argv[6]), + cstring_to_tstring(argv[7]), + cstring_to_tstring(argv[8]) ); -} \ No newline at end of file +} diff --git a/generator/src/tstring.c b/generator/src/tstring.c index 57e3a78..1f78d3c 100644 --- a/generator/src/tstring.c +++ b/generator/src/tstring.c @@ -28,8 +28,10 @@ tstring* cstring_to_tstring(char* src) { tstring* integer_to_tstring(int64_t val) { char conversion[20]; - bool sign = val < 0; + int sign = val < 0; char* it = conversion; + tstring* ret; + char* dest_it; if(sign) { val *= -1; @@ -43,8 +45,8 @@ tstring* integer_to_tstring(int64_t val) { *(it++) = val%10+'0'; val/=10; } - tstring* ret = tstring_create((it-conversion) + sign); - char* dest_it = ret->data; + ret = tstring_create((it-conversion) + sign); + dest_it = ret->data; if(sign) { *(dest_it++) = '-'; } @@ -63,16 +65,18 @@ tstring* tstring_concatenate(tstring* lhs, tstring* rhs) { tstring* tstring_n_concatenate(size_t count, ...) { va_list strs; - va_start(strs, count); size_t tot_sz = 0; size_t idx; + char* it; + tstring* ret; + va_start(strs, count); for(idx = 0; idx < count; idx++) { tot_sz += va_arg(strs, tstring*)->size; } - tstring* ret = tstring_create(tot_sz); + ret = tstring_create(tot_sz); va_end(strs); va_start(strs, count); - char* it = ret->data; + it = ret->data; for(idx = 0; idx < count; idx++) { tstring* curr = va_arg(strs, tstring*); memcpy(it, curr->data, curr->size); @@ -85,8 +89,8 @@ tstring* tstring_n_concatenate(size_t count, ...) { int tstring_n_write(FILE* file, size_t count, ...) { va_list strs; - va_start(strs, count); size_t idx; + va_start(strs, count); for(idx = 0; idx < count; idx++) { tstring* curr = va_arg(strs, tstring*); if(fwrite(curr->data,1, curr->size, file) != curr->size) { @@ -99,10 +103,12 @@ int tstring_n_write(FILE* file, size_t count, ...) { tstring* tstring_n_compose(const char* count, ...) { va_list strs; - size_t nb = strlen(count); - va_start(strs, count); size_t tot_sz = 0; size_t idx; + size_t nb = strlen(count); + tstring* ret; + char* it; + va_start(strs, count); for(idx = 0; idx < nb; idx++) { switch(count[idx]){ case 't': @@ -118,8 +124,8 @@ tstring* tstring_n_compose(const char* count, ...) { break; } } - tstring* ret = tstring_create(tot_sz); - char* it = ret->data; + ret = tstring_create(tot_sz); + it = ret->data; va_end(strs); va_start(strs, count); for(idx = 0; idx < nb; idx++) {