add debug check that all modes and rawmodes are defined

This commit is contained in:
Yay295 2024-04-25 19:29:02 -05:00
parent 0d3c59e277
commit c3c968e025

View File

@ -1,6 +1,10 @@
#include "Mode.h"
#include <string.h>
#ifdef NDEBUG
#include <stdio.h>
#include <stdlib.h>
#endif
const ModeData MODES[] = {
[IMAGING_MODE_UNKNOWN] = {""},
@ -39,6 +43,11 @@ const ModeID findModeID(const char * const name) {
return IMAGING_MODE_UNKNOWN;
}
for (size_t i = 0; i < sizeof(MODES) / sizeof(*MODES); i++) {
#ifdef NDEBUG
if (MODES[i].name == NULL) {
fprintf(stderr, "Mode ID %zu is not defined.\n", (size_t)i);
} else
#endif
if (strcmp(MODES[i].name, name) == 0) {
return (ModeID)i;
}
@ -238,6 +247,11 @@ const RawModeID findRawModeID(const char * const name) {
return IMAGING_RAWMODE_UNKNOWN;
}
for (size_t i = 0; i < sizeof(RAWMODES) / sizeof(*RAWMODES); i++) {
#ifdef NDEBUG
if (RAWMODES[i].name == NULL) {
fprintf(stderr, "Rawmode ID %zu is not defined.\n", (size_t)i);
} else
#endif
if (strcmp(RAWMODES[i].name, name) == 0) {
return (RawModeID)i;
}