diff --git a/src/libfsm/print/go.c b/src/libfsm/print/go.c index 84942ea22..43caa7712 100644 --- a/src/libfsm/print/go.c +++ b/src/libfsm/print/go.c @@ -232,6 +232,21 @@ print_fetch(FILE *f, const struct fsm_options *opt) } } +static void +print_ret(FILE *f, const unsigned *ids, size_t count) +{ + size_t i; + + fprintf(f, "[]uint{"); + for (i = 0; i < count; i++) { + fprintf(f, "%u", ids[i]); + if (i + 1 < count) { + fprintf(f, ", "); + } + } + fprintf(f, "}"); +} + /* TODO: eventually to be non-static */ static int fsm_print_gofrag(FILE *f, @@ -372,14 +387,9 @@ fsm_print_go(FILE *f, if (opt->ambig == AMBIG_MULTIPLE) { for (size_t i = 0; i < retlist->count; i++) { - fprintf(f, "var ret%zu []uint = []uint{", i); - for (size_t j = 0; j < retlist->a[i].count; j++) { - fprintf(f, "%u", retlist->a[i].ids[j]); - if (j + 1 < retlist->a[i].count) { - fprintf(f, ", "); - } - } - fprintf(f, "}\n"); + fprintf(f, "var ret%zu []uint = ", i); + print_ret(f, retlist->a[i].ids, retlist->a[i].count); + fprintf(f, "\n"); } fprintf(f, "\n"); } diff --git a/src/libfsm/print/rust.c b/src/libfsm/print/rust.c index b20d09e4d..96dca94f0 100644 --- a/src/libfsm/print/rust.c +++ b/src/libfsm/print/rust.c @@ -212,6 +212,21 @@ print_fetch(FILE *f) fprintf(f, "bytes.next()"); } +static void +print_ret(FILE *f, const unsigned *ids, size_t count) +{ + size_t i; + + fprintf(f, "["); + for (i = 0; i < count; i++) { + fprintf(f, "%u", ids[i]); + if (i + 1 < count) { + fprintf(f, ", "); + } + } + fprintf(f, "];"); +} + /* TODO: eventually to be non-static */ static int fsm_print_rustfrag(FILE *f, @@ -234,14 +249,9 @@ fsm_print_rustfrag(FILE *f, if (opt->ambig == AMBIG_MULTIPLE) { for (size_t i = 0; i < retlist->count; i++) { - fprintf(f, " static RET%zu: [u32; %zu] = [", i, retlist->a[i].count); - for (size_t j = 0; j < retlist->a[i].count; j++) { - fprintf(f, "%u", retlist->a[i].ids[j]); - if (j + 1 < retlist->a[i].count) { - fprintf(f, ", "); - } - } - fprintf(f, "];\n"); + fprintf(f, " static RET%zu: [u32; %zu] = ", i, retlist->a[i].count); + print_ret(f, retlist->a[i].ids, retlist->a[i].count); + fprintf(f, "\n"); } fprintf(f, "\n"); } diff --git a/src/libfsm/print/vmops.c b/src/libfsm/print/vmops.c index dec2ea652..3cfc1d7b6 100644 --- a/src/libfsm/print/vmops.c +++ b/src/libfsm/print/vmops.c @@ -201,6 +201,21 @@ print_fetch(FILE *f, const struct fsm_options *opt, const char *prefix) return 0; } +static void +print_ret(FILE *f, const unsigned *ids, size_t count) +{ + size_t i; + + fprintf(f, "{ (const unsigned []) { "); + for (i = 0; i < count; i++) { + fprintf(f, "%u", ids[i]); + if (i + 1 < count) { + fprintf(f, ", "); + } + } + fprintf(f, " }, %zu }", count); +} + int fsm_print_vmops_c(FILE *f, const struct fsm_options *opt, @@ -235,14 +250,9 @@ fsm_print_vmops_c(FILE *f, if (opt->ambig != AMBIG_NONE) { fprintf(f, "struct %sret %sRet[] = {\n", prefix, prefix); for (size_t i = 0; i < retlist->count; i++) { - fprintf(f, "\t{ (const unsigned []) { "); - for (size_t j = 0; j < retlist->a[i].count; j++) { - fprintf(f, "%u", retlist->a[i].ids[j]); - if (j + 1 < retlist->a[i].count) { - fprintf(f, ", "); - } - } - fprintf(f, " }, %zu },\n", retlist->a[i].count); + fprintf(f, "\t"); + print_ret(f, retlist->a[i].ids, retlist->a[i].count); + fprintf(f, ",\n"); } fprintf(f, "};\n"); fprintf(f, "const size_t %sRet_count = sizeof %sRet / sizeof *%sRet;\n", prefix, prefix, prefix);