From 4c6ac6b1c3e9f7ac04b5f6ba0b30eb8eacfcce9c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 4 Aug 2019 22:00:04 +0200 Subject: Factor out parsing test options --- test/test_utils.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'test/test_utils.h') diff --git a/test/test_utils.h b/test/test_utils.h index bf058ac..f4f6c31 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -19,11 +19,21 @@ #include #include #include +#include typedef struct { double lastReportTime; } PuglFpsPrinter; +typedef struct { + int samples; + int doubleBuffer; + bool continuous; + bool help; + bool ignoreKeyRepeat; + bool resizable; +} PuglTestOptions; + static const float cubeStripVertices[] = { -1.0f, 1.0f, 1.0f, // Front top left 1.0f, 1.0f, 1.0f, // Front top right @@ -142,6 +152,54 @@ printEvent(const PuglEvent* event, const char* prefix) return 0; } +static inline void +puglPrintTestUsage(const char* prog, const char* posHelp) +{ + printf("Usage: %s [OPTION]... %s\n\n" + " -a Enable anti-aliasing\n" + " -c Continuously animate and draw\n" + " -d Enable double-buffering\n" + " -h Display this help\n" + " -i Ignore key repeat\n" + " -r Resizable window\n", + prog, posHelp); +} + +static inline PuglTestOptions +puglParseTestOptions(int* pargc, char*** pargv) +{ + PuglTestOptions opts = { 0, 0, false, false, false, false }; + + char** const argv = *pargv; + int i = 1; + for (; i < *pargc; ++i) { + if (!strcmp(argv[i], "-a")) { + opts.samples = 4; + } else if (!strcmp(argv[i], "-c")) { + opts.continuous = true; + } else if (!strcmp(argv[i], "-d")) { + opts.doubleBuffer = PUGL_TRUE; + } else if (!strcmp(argv[i], "-h")) { + opts.help = true; + return opts; + } else if (!strcmp(argv[i], "-i")) { + opts.ignoreKeyRepeat = true; + } else if (!strcmp(argv[i], "-r")) { + opts.resizable = true; + } else if (argv[i][0] != '-') { + break; + } else { + opts.help = true; + fprintf(stderr, "error: Unknown option: %s\n", argv[i]); + } + } + + *pargc -= i; + *pargv += i; + + return opts; +} + static inline void puglPrintFps(const PuglWorld* world, PuglFpsPrinter* printer, -- cgit v1.2.1