From 1a73036cd3337b49c23b3ceb67ec09408dff5734 Mon Sep 17 00:00:00 2001 From: Matthias Gatto Date: Thu, 25 Jul 2024 15:10:07 +0200 Subject: [PATCH] oapi-cli: support --Filters.VmIds.X alongside --Filters.VmIds[] Signed-off-by: Matthias Gatto --- cognac_gen.sh | 34 +++++++++++++++++++++++++++++----- main-helper.h | 14 +++++++++++--- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/cognac_gen.sh b/cognac_gen.sh index 248f9e0..342372d 100755 --- a/cognac_gen.sh +++ b/cognac_gen.sh @@ -95,15 +95,39 @@ EOF elif [ 'array integer' == "$type" -o 'array string' == "$type" -o 'array double' == "$type" ]; then - convertor="" + local convertor="" + local null_val='""' if [ 'array integer' == "$type" ]; then convertor=atoi + null_val=0 elif [ 'array double' == "$type" ]; then convertor=atof + null_val=0.0 fi cat <${snake_a}_str = aa; +${indent_plus} if (aret == '.') { +${indent_plus} int pos; +${indent_plus} char *endptr; +${indent_plus} int last = 0; +${indent_plus} char *dot_pos = strchr(str, '.'); + +${indent_plus} TRY(!(dot_pos++), "$a argument missing\n"); +${indent_plus} pos = strtoul(dot_pos, &endptr, 0); +${indent_plus} TRY(endptr == dot_pos, "$a require an index\n"); +${indent_plus} if (s->${snake_a}) { +${indent_plus} for (; s->${snake_a}[last]; ++last); +${indent_plus} } +${indent_plus} if (pos < last) { +${indent_plus} s->${snake_a}[pos] = ${convertor}(aa); +${indent_plus} } else { +${indent_plus} for (int i = last; i < pos; ++i) +${indent_plus} SET_NEXT(s->${snake_a}, $null_val, pa); +${indent_plus} SET_NEXT(s->${snake_a}, ${convertor}(aa), pa); +${indent_plus} } +${indent_plus} } else { +${indent_plus} TRY(!aa, "$a argument missing\n"); +${indent_plus} s->${snake_a}_str = aa; +${indent_plus} } $indent_base } else if (!(aret = strcmp(str, "$a[]")) || aret == '=') { ${indent_plus} TRY(!aa, "$a[] argument missing\n"); ${indent_plus} SET_NEXT(s->${snake_a}, ${convertor}(aa), pa); @@ -287,7 +311,7 @@ EOF t=$(get_type2 "$s" "$a") snake_n=$(to_snakecase <<< $a) - echo " if ((aret = argcmp(str, \"$a\")) == 0 || aret == '=') {" + echo " if ((aret = strcmp(str, \"$a\")) == 0 || aret == '=' || aret == '.') {" cli_c_type_parser "$a" "$t" " " done cat <ptrs[idx] = realloc(a, (cnt + 1 + 64) * sizeof(v)); \ + pa->ptrs[idx] = realloc(a, (cnt + 1 + 64) * OBJ_SIZE); \ if (!pa->ptrs[idx]) { free(a); break; } \ a = pa->ptrs[idx]; \ - memset(a + cnt + 1, 0, 64 * sizeof(v)); \ + memset(a + cnt + 1, 0, 64 * OBJ_SIZE); \ } \ a[cnt] = v; \ } while (0)