diff --git a/Makefile b/Makefile index f9be24f..adef96d 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +# Options (e.g. `CFLAGS=-DUSE_ARGP make`) +# USE_ARGP: use `argp` for argument parsing. + VERSION ?= 9.0.1 prefix ?= /usr/local @@ -37,6 +40,7 @@ WFLAGS := \ -Wextra \ -Wformat-security \ -Wno-ignored-optimization-argument \ + -Wno-missing-field-initializers \ -Wno-unknown-warning-option \ -Wsuggest-attribute=const \ -Wsuggest-attribute=format \ diff --git a/glxgears.c b/glxgears.c index 1d5e99a..2eaf818 100644 --- a/glxgears.c +++ b/glxgears.c @@ -12,6 +12,9 @@ * Other modifications by Lexxy Fox. */ +#ifdef USE_ARGP + #include +#endif #include #include #include @@ -364,25 +367,55 @@ static void visible(int vis) { static char *window_title = "Gears"; -static void parse_args(int argc, char *argv[]) { #ifdef USE_ARGP +static const struct argp_option options[] = { + {"info", 256, 0, 0, "Display OpenGL renderer information"}, + {"exit", 257, 0, 0, "Automatically exit after 30 seconds"}, + {"noanim", 258, 0, 0, "Don't start animation"}, + {"title", 259, "title", 0, "Set window title (defaults to \"Gears\")"}, + {0}}; +static error_t parse_opt(int key, char *val, struct argp_state *) { + switch (key) { + case 256: + print_glinfo = GL_TRUE; + break; + case 257: + autoexit = 30; + break; + case 258: + Animate = GL_FALSE; + break; + case 259: + window_title = val; + break; + } + return 0; +} + +static const struct argp argp = { + options, parse_opt, 0, "Universal rights are universal."}; #else +static void parse_args(int argc, char *argv[]) { for (GLint i = 1; i < argc; i++) if (strcmp(argv[i], "-exit") == 0) { autoexit = 30; - printf("Auto Exit after %i seconds.\n", autoexit); + printf("Auto exiting after %i seconds.\n", autoexit); fflush(stdout); } else if (strcmp(argv[i], "-info") == 0) print_glinfo = GL_TRUE; else if (strcmp(argv[i], "-noanim") == 0) Animate = GL_FALSE; -#endif } +#endif int main(int argc, char *argv[]) { glutInit(&argc, argv); +#ifdef USE_ARGP + argp_parse(&argp, argc, argv, ARGP_LONG_ONLY, 0, 0); +#else parse_args(argc, argv); +#endif glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); win = glutCreateWindow(window_title); init_scene();