summaryrefslogtreecommitdiff
path: root/tools/slang-fiddle/slang-fiddle-options.h
blob: ae6412ca09c4a230d65961fe018dd3b9e4d9b49f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// slang-fiddle-options.h
#pragma once

#include "slang-fiddle-diagnostics.h"

namespace fiddle
{
using namespace Slang;

//

struct Options
{
public:
    static const char* expectArg(char const* const*& cursor, char const* const* end)
    {
        if (cursor != end)
            return *cursor++;
        return nullptr;
    }

    void parse(DiagnosticSink& sink, int argc, char const* const* argv)
    {
        auto argCursor = argv++;
        auto argEnd = argCursor + argc;

        if (argCursor != argEnd)
        {
            appName = *argCursor++;
        }

        while (argCursor != argEnd)
        {
            UnownedTerminatedStringSlice arg = *argCursor++;
            if (arg[0] != '-')
            {
                inputPaths.add(String(arg));
                continue;
            }

            if (arg == UnownedTerminatedStringSlice("-i"))
            {
                inputPathPrefix = expectArg(argCursor, argEnd);
            }
            else if (arg == UnownedTerminatedStringSlice("-o"))
            {
                outputPathPrefix = expectArg(argCursor, argEnd);
            }
            else
            {
                sink.diagnose(SourceLoc(), Diagnostics::unknownOption, arg);
            }
        }
    }

    String appName = "slang-fiddle";
    String inputPathPrefix = "";
    String outputPathPrefix = "";
    List<String> inputPaths;
};
} // namespace fiddle