diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-06-03 16:09:36 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-06-03 16:09:36 +0100 |
commit | fd74dae4817aedeecbb5a2b9782378db1a3d9e3d (patch) | |
tree | f7750555bcb1e359ed5481c10bd803002bfcecfd | |
parent | a88ad680422949dfe2d16a544a529649c6d07109 (diff) | |
download | pack-fd74dae4817aedeecbb5a2b9782378db1a3d9e3d.tar.gz pack-fd74dae4817aedeecbb5a2b9782378db1a3d9e3d.tar.xz pack-fd74dae4817aedeecbb5a2b9782378db1a3d9e3d.zip |
test_gen: remove enum fmt
Not sure why the code was written that way, seems fragile in retrospect.
-rw-r--r-- | test_gen.c | 41 |
1 files changed, 13 insertions, 28 deletions
@@ -19,21 +19,6 @@ struct { { LITTLE, "<" }, }; -enum fmt { - FMT_b, - FMT_B, - FMT_h, - FMT_H, - FMT_i, - FMT_I, - FMT_l, - FMT_L, - FMT_q, - FMT_Q, - FMT_END, - FMT_BEGIN = FMT_b, -}; - struct fmtinfo { char fmt; char *type; @@ -41,16 +26,16 @@ struct fmtinfo { uintmax_t max; size_t size; } fmtinfo[] = { - [FMT_b] = { 'b', "signed char", INTMAX_C( -128), UINTMAX_C( 127), 1 }, - [FMT_B] = { 'B', "unsigned char", INTMAX_C( 0), UINTMAX_C( 255), 1 }, - [FMT_h] = { 'h', "signed short", INTMAX_C( -32768), UINTMAX_C( 32767), 2 }, - [FMT_H] = { 'H', "unsigned short", INTMAX_C( 0), UINTMAX_C( 65535), 2 }, - [FMT_i] = { 'i', "signed int", INTMAX_C( -32768), UINTMAX_C( 32767), 2 }, - [FMT_I] = { 'I', "unsigned int", INTMAX_C( 0), UINTMAX_C( 65535), 2 }, - [FMT_l] = { 'l', "signed long", INTMAX_C( -2147483648), UINTMAX_C( 2147483647), 4 }, - [FMT_L] = { 'L', "unsigned long", INTMAX_C( 0), UINTMAX_C( 4294967295), 4 }, - [FMT_q] = { 'q', "signed long long", -INTMAX_C(9223372036854775807) - 1, UINTMAX_C( 9223372036854775807), 8 }, - [FMT_Q] = { 'Q', "unsigned long long", INTMAX_C( 0), UINTMAX_C(18446744073709551615), 8 }, + { 'b', "signed char", INTMAX_C( -128), UINTMAX_C( 127), 1 }, + { 'B', "unsigned char", INTMAX_C( 0), UINTMAX_C( 255), 1 }, + { 'h', "signed short", INTMAX_C( -32768), UINTMAX_C( 32767), 2 }, + { 'H', "unsigned short", INTMAX_C( 0), UINTMAX_C( 65535), 2 }, + { 'i', "signed int", INTMAX_C( -32768), UINTMAX_C( 32767), 2 }, + { 'I', "unsigned int", INTMAX_C( 0), UINTMAX_C( 65535), 2 }, + { 'l', "signed long", INTMAX_C( -2147483648), UINTMAX_C( 2147483647), 4 }, + { 'L', "unsigned long", INTMAX_C( 0), UINTMAX_C( 4294967295), 4 }, + { 'q', "signed long long", -INTMAX_C(9223372036854775807) - 1, UINTMAX_C( 9223372036854775807), 8 }, + { 'Q', "unsigned long long", INTMAX_C( 0), UINTMAX_C(18446744073709551615), 8 }, }; static char cchar(char c) @@ -137,13 +122,13 @@ static void unpack_unsigned(FILE *out, const struct fmtinfo *fi, enum endian e, fprintf(out, "\tCHECK_EQUAL(PRIdMAX, (uintmax_t)v[%d], UINTMAX_C(%" PRIuMAX "));\n", i, testval); } -static void unpack_gen(FILE *out, enum fmt fmt, int arraysize) +static void unpack_gen(FILE *out, size_t fmt, int arraysize) { int realsize = arraysize == 0 ? 1 : arraysize; struct fmtinfo *fi; bool sign; - assert(fmt < FMT_END); + assert(fmt < sizeof fmtinfo / sizeof fmtinfo[0]); fi = &fmtinfo[fmt]; @@ -172,7 +157,7 @@ static void unpack_gen(FILE *out, enum fmt fmt, int arraysize) int main(void) { FILE *out = stdout; - for (enum fmt fmt = FMT_BEGIN; fmt < FMT_END; fmt++) { + for (size_t fmt = 0; fmt < sizeof fmtinfo / sizeof fmtinfo[0]; fmt++) { unpack_gen(out, fmt, 0); for (int i = 2; i < 4; i++) unpack_gen(out, fmt, i); |