#include #include #include #include int main(int argc, char* argv[]) { char c; int width = 0, height = 0; char const *filename = NULL; struct poptOption options_table[] = { { "width", 'w', POPT_ARG_INT, &width, 0, "Width of the maze", "BLOCKS" }, { "height", 'h', POPT_ARG_INT, &height, 0, "Height of the maze", "BLOCKS" }, POPT_AUTOHELP { NULL, 0, 0, NULL, 0 } }; poptContext ctx = poptGetContext(NULL, argc, (const char**) argv, options_table, 0); poptSetOtherOptionHelp(ctx, "OUTPUT"); if (argc < 2) { poptPrintUsage(ctx, stderr, 0); exit(1); } while ((c = poptGetNextOpt(ctx)) >= 0) /* noop */ ; if (c < -1) { fprintf(stderr, "%s: %s\n", poptBadOption(ctx, POPT_BADOPTION_NOALIAS), poptStrerror(c)); return 1; } filename = poptGetArg(ctx); if ((width == 0) || (height == 0)) { fprintf(stderr, "Positive values for width (-w) and height (-h) are required.\n"); return 1; } if (filename == NULL) { fprintf(stderr, "An output filename is required.\n"); return 1; } mazegrid_t maze; mazemaker_generate_maze(width, height, &maze); mazemaker_maze_to_png(&maze, filename); mazemaker_free_maze(&maze); poptFreeContext(ctx); }