void img_parser_init(void) { unsigned int index, mod_num; /* Initialise internal variables to invalid state */ for (index = 0; index < IMG_MAX_TYPES; index++) { parser_lib_indices[index] = INVALID_IDX; } /* Calculate how many image parsers are registered. At least one parser * must be present */ mod_num = PARSER_LIB_DESCS_END - PARSER_LIB_DESCS_START; mod_num /= sizeof(img_parser_lib_desc_t); assert(mod_num > 0); parser_lib_descs = (img_parser_lib_desc_t *) PARSER_LIB_DESCS_START; for (index = 0; index < mod_num; index++) { /* Check that the image parser library descriptor is valid */ validate_desc(&parser_lib_descs[index]); /* Initialize image parser */ parser_lib_descs[index].init(); /* Ensure only one parser is registered for each image type */ assert(parser_lib_indices[parser_lib_descs[index].img_type] == INVALID_IDX); /* Keep the index of this hash calculator */ parser_lib_indices[parser_lib_descs[index].img_type] = index; } }
int main(int argc, char **argv) { game_params *p; game_state *s; char *id = NULL, *desc, *err; int grade = FALSE; int ret, diff, really_show_working = FALSE; while (--argc > 0) { char *p = *++argv; if (!strcmp(p, "-v")) { really_show_working = TRUE; } else if (!strcmp(p, "-g")) { grade = TRUE; } else if (*p == '-') { fprintf(stderr, "%s: unrecognised option `%s'\n", argv[0], p); return 1; } else { id = p; } } if (!id) { fprintf(stderr, "usage: %s [-g | -v] <game_id>\n", argv[0]); return 1; } desc = strchr(id, ':'); if (!desc) { fprintf(stderr, "%s: game id expects a colon in it\n", argv[0]); return 1; } *desc++ = '\0'; p = default_params(); decode_params(p, id); err = validate_desc(p, desc); if (err) { fprintf(stderr, "%s: %s\n", argv[0], err); return 1; } s = new_game(NULL, p, desc); /* * When solving an Easy puzzle, we don't want to bother the * user with Hard-level deductions. For this reason, we grade * the puzzle internally before doing anything else. */ ret = -1; /* placate optimiser */ solver_show_working = FALSE; for (diff = 0; diff < DIFFCOUNT; diff++) { memcpy(s->grid, s->clues->immutable, p->w * p->w); ret = solver(p->w, s->clues->clues, s->grid, diff); if (ret <= diff) break; } if (diff == DIFFCOUNT) { if (grade) printf("Difficulty rating: ambiguous\n"); else printf("Unable to find a unique solution\n"); } else { if (grade) { if (ret == diff_impossible) printf("Difficulty rating: impossible (no solution exists)\n"); else printf("Difficulty rating: %s\n", towers_diffnames[ret]); } else { solver_show_working = really_show_working; memcpy(s->grid, s->clues->immutable, p->w * p->w); ret = solver(p->w, s->clues->clues, s->grid, diff); if (ret != diff) printf("Puzzle is inconsistent\n"); else fputs(game_text_format(s), stdout); } } return 0; }