From fcf83dbf9effab3bd98bad2b83b2468b7eb05cfd Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 9 Jun 2017 11:34:21 -0700 Subject: Initial import of code. --- tools/render-test/options.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 tools/render-test/options.cpp (limited to 'tools/render-test/options.cpp') diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp new file mode 100644 index 000000000..9cfbb81fb --- /dev/null +++ b/tools/render-test/options.cpp @@ -0,0 +1,95 @@ +// options.cpp + +#include "options.h" + +#include +#include +#include + +namespace renderer_test { + +Options gOptions; + +void parseOptions(int* argc, char** argv) +{ + int argCount = *argc; + char const* const* argCursor = argv; + char const* const* argEnd = argCursor + argCount; + + char const** writeCursor = (char const**) argv; + + // first argument is the application name + if( argCursor != argEnd ) + { + gOptions.appName = *argCursor++; + } + + // now iterate over arguments to collect options + while(argCursor != argEnd) + { + char const* arg = *argCursor++; + if( arg[0] != '-' ) + { + *writeCursor++ = arg; + continue; + } + + if( strcmp(arg, "--") == 0 ) + { + while(argCursor != argEnd) + { + char const* arg = *argCursor++; + *writeCursor++ = arg; + } + break; + } + else if( strcmp(arg, "-o") == 0 ) + { + if( argCursor == argEnd ) + { + fprintf(stderr, "expected argument for '%s' option\n", arg); + exit(1); + } + gOptions.outputPath = *argCursor++; + } + else if( strcmp(arg, "-hlsl") == 0 ) + { + gOptions.mode = Mode::HLSL; + } + else if( strcmp(arg, "-slang") == 0 ) + { + gOptions.mode = Mode::Slang; + } + else if( strcmp(arg, "-glsl-cross") == 0 ) + { + gOptions.mode = Mode::GLSLCrossCompile; + } + else + { + fprintf(stderr, "unknown option '%s'\n", arg); + exit(1); + } + } + + // any arguments left over were positional arguments + argCount = (int)(writeCursor - argv); + argCursor = argv; + argEnd = argCursor + argCount; + + // first positional argument is source shader path + if( argCursor != argEnd ) + { + gOptions.sourcePath = *argCursor++; + } + + // any remaining arguments represent an error + if(argCursor != argEnd) + { + fprintf(stderr, "unexpected arguments\n"); + exit(1); + } + + *argc = 0; +} + +} // renderer_test -- cgit v1.2.3