// 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