aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMosder <xmosder12@gmail.com>2026-07-23 19:54:27 +0200
committerMosder <xmosder12@gmail.com>2026-07-23 19:54:27 +0200
commitf6751b7ed605af54a78156fbaa9194accaa012dc (patch)
treed5692e3f55cea743e93dfe3343ab7b2642d1f65e
parent0e857163bc6746ebf2c8e793f0149c7f4290aff1 (diff)
feat: added printing to sygnalize out of range id to files generated from csvs
-rw-r--r--csv_table_gen.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/csv_table_gen.c b/csv_table_gen.c
index 9be57d0..0bfd51a 100644
--- a/csv_table_gen.c
+++ b/csv_table_gen.c
@@ -59,8 +59,9 @@ void create_c(char *path, char *h_path, char *from, char *to, char from_to_array
sprintf(arr_name, "%s_to_%s", from, to);
sprintf(arr_len_name, "%s_to_%s_len", from, to);
- // write include and beginning of array
+ // write includes and the beginning of array
fprintf(fp, "#include \"%s\"\n\n", strstr(h_path, CSV_PATH));
+ fprintf(fp, "#include <stdio.h>\n\n");
fprintf(fp, "static const char *%s[] = {\n", arr_name);
// write values
@@ -77,7 +78,10 @@ void create_c(char *path, char *h_path, char *from, char *to, char from_to_array
// write the getter
fprintf(fp, "const char *get_%s_from_%s(int %s) {\n", to, from, from);
- fprintf(fp, " return %s >= 0 && %s < %s ? %s[%s] : \"null\";\n", from, from, arr_len_name, arr_name, from);
+ fprintf(fp, " if (%s >= 0 && %s < %s)\n", from, from, arr_len_name);
+ fprintf(fp, " return %s[%s];\n", arr_name, from);
+ fprintf(fp, " printf(\"%s = %%d is outside of table range [0; %%d]\\n\", %s, %s - 1);\n", from, from, arr_len_name);
+ fprintf(fp, " return \"null\";\n");
fprintf(fp, "}");
fclose(fp);