yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Theresa FoleyAdd Yet Another Source Code Generator (#6844)1e86f5657

master
1.4 KiB61 linesraw
1// slang-fiddle-options.h
2#pragma once
3
4#include "slang-fiddle-diagnostics.h"
5
6namespace fiddle
7{
8using namespace Slang;
9
10//
11
12struct Options
13{
14public:
15    static const char* expectArg(char const* const*& cursor, char const* const* end)
16    {
17        if (cursor != end)
18            return *cursor++;
19        return nullptr;
20    }
21
22    void parse(DiagnosticSink& sink, int argc, char const* const* argv)
23    {
24        auto argCursor = argv++;
25        auto argEnd = argCursor + argc;
26
27        if (argCursor != argEnd)
28        {
29            appName = *argCursor++;
30        }
31
32        while (argCursor != argEnd)
33        {
34            UnownedTerminatedStringSlice arg = *argCursor++;
35            if (arg[0] != '-')
36            {
37                inputPaths.add(String(arg));
38                continue;
39            }
40
41            if (arg == UnownedTerminatedStringSlice("-i"))
42            {
43                inputPathPrefix = expectArg(argCursor, argEnd);
44            }
45            else if (arg == UnownedTerminatedStringSlice("-o"))
46            {
47                outputPathPrefix = expectArg(argCursor, argEnd);
48            }
49            else
50            {
51                sink.diagnose(SourceLoc(), Diagnostics::unknownOption, arg);
52            }
53        }
54    }
55
56    String appName = "slang-fiddle";
57    String inputPathPrefix = "";
58    String outputPathPrefix = "";
59    List<String> inputPaths;
60};
61} // namespace fiddle