/* See LICENSE file for copyright and license details. */ #include "libautomata.h" #include #include #include #define sizeof_flexstruct(STRUCT, MEMBER, COUNT)\ (offsetof(STRUCT, MEMBER) + (COUNT) * sizeof(*((STRUCT *)NULL)->MEMBER)) #define sizeof_kmp_automaton(LENGTH, ELEMSIZE)\ (sizeof_flexstruct(struct libautomata_kmp_automaton, next, (LENGTH) + 1U) + (LENGTH) * (ELEMSIZE)) struct libautomata_kmp_automaton { size_t position; size_t length; size_t elemsize; size_t next[/* .length + 1U */]; /* char pattern[.length * .elemsize] */ }; #define sizeof_mp_automaton(LENGTH, ELEMSIZE)\ (sizeof_flexstruct(struct libautomata_mp_automaton, next, (LENGTH) + 1U) + (LENGTH) * (ELEMSIZE)) struct libautomata_mp_automaton { size_t position; size_t length; size_t elemsize; size_t next[/* .length + 1U */]; /* char pattern[.length * .elemsize] */ }; #ifdef TEST # include # define MEM(STR) STR, (sizeof(STR) - 1U) # define EXPECT(EXPR)\ do {\ if (EXPR)\ break;\ fprintf(stderr, "Assertion failed at %s:%i: %s\n", __FILE__, __LINE__, #EXPR);\ exit(1);\ } while (0) #endif