gendata.c (1222B)
1 #include "../tool.h" 2 #include "../expected_distributions.h" 3 4 char *solver; 5 uint64_t *expected; 6 7 static void 8 run(void) { 9 int64_t size; 10 bool consistent, expected; 11 char filename[1024], dataid[NISSY_SIZE_DATAID]; 12 unsigned char *buf; 13 14 size = generatetable(solver, &buf, dataid); 15 switch (size) { 16 case -1: 17 return; 18 case -2: 19 goto gendata_run_finish; 20 default: 21 nissy_datainfo(size, buf); 22 consistent = nissy_checkdata(size, buf) == 0; 23 expected = check_distribution(solver, size, buf); 24 if (consistent && expected) { 25 printf("\n"); 26 printf("Generated %" PRId64 " bytes.\n", size); 27 sprintf(filename, "tables/%s", dataid); 28 writetable(buf, size, filename); 29 } 30 if (!consistent) 31 printf("Error: table is not consistent with info" 32 " (nissy_checkdata() failed)\n"); 33 if (!expected) 34 printf("Error: distribution is not as expected\n"); 35 break; 36 } 37 38 gendata_run_finish: 39 free(buf); 40 } 41 42 int main(int argc, char **argv) { 43 uint8_t h, k; 44 45 if (argc < 2) { 46 printf("Error: not enough arguments. " 47 "A solver must be given.\n"); 48 return 1; 49 } 50 51 solver = argv[1]; 52 parse_h48_solver(solver, &h, &k); 53 expected = expected_h48[h][k]; 54 55 nissy_setlogger(log_stderr, NULL); 56 57 timerun(run); 58 59 return 0; 60 }