summaryrefslogtreecommitdiffstats
path: root/tools/render-test/options.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-09 11:34:21 -0700
committerTim Foley <tfoley@nvidia.com>2017-06-09 13:44:59 -0700
commitfcf83dbf9effab3bd98bad2b83b2468b7eb05cfd (patch)
tree41047c94883b86ec085a81597391ce3ef557cd43 /tools/render-test/options.cpp
parent52e8d4b9a27ab0060f874c3a63ab531847be35c0 (diff)
Initial import of code.
Diffstat (limited to 'tools/render-test/options.cpp')
-rw-r--r--tools/render-test/options.cpp95
1 files changed, 95 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+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