yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
3.1 KiB141 linesraw
1// slang-command-line.cpp
2#include "slang-command-line.h"
3
4#include "slang-com-helper.h"
5#include "slang-process.h"
6#include "slang-string-escape-util.h"
7#include "slang-string-util.h"
8#include "slang-string.h"
9
10namespace Slang
11{
12
13/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ExecutableLocation !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14 */
15
16void ExecutableLocation::set(const String& dir, const String& name)
17{
18    if (dir.getLength() == 0)
19    {
20        set(name);
21    }
22    else
23    {
24        set(Path::combine(dir, name));
25    }
26}
27
28void ExecutableLocation::set(const String& nameOrPath)
29{
30    // See if input looks like a path
31    if (Path::hasPath(nameOrPath))
32    {
33        // If it is a path we may want to add a suffix
34        const auto suffix = Process::getExecutableSuffix();
35
36        if (suffix.getLength() == 0 || nameOrPath.endsWith(suffix))
37        {
38            setPath(nameOrPath);
39        }
40        else
41        {
42            // If on target that has suffix make sure name has the suffix
43            StringBuilder builder;
44            builder << nameOrPath;
45            builder << suffix;
46            setPath(builder.produceString());
47        }
48    }
49    else
50    {
51        // If we don't have a parent, we assume it is just a naem
52        setName(nameOrPath);
53    }
54}
55
56void ExecutableLocation::append(StringBuilder& out) const
57{
58    if (m_type == Type::Unknown)
59    {
60        out << "(unknown)";
61    }
62    else
63    {
64        auto escapeHandler = Process::getEscapeHandler();
65        StringEscapeUtil::appendMaybeQuoted(escapeHandler, m_pathOrName.getUnownedSlice(), out);
66    }
67}
68
69/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CommandLine !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
70
71void CommandLine::addPrefixPathArg(const char* prefix, const String& path, const char* pathPostfix)
72{
73    StringBuilder builder;
74    builder << prefix;
75
76    // TODO(JS): The assumption here is that quoting will be added as necessary and
77    // -prefixSomething Else
78    // is okay as
79    // "-prefixSomething Else" rather than
80    // -prefix"Something Else"
81
82    builder << path;
83
84    if (pathPostfix)
85    {
86        // Work out the path with the postfix
87        builder << pathPostfix;
88    }
89    addArg(builder.produceString());
90}
91
92void CommandLine::append(StringBuilder& out) const
93{
94    m_executableLocation.append(out);
95
96    if (m_args.getCount())
97    {
98        out << " ";
99        appendArgs(out);
100    }
101}
102
103void CommandLine::appendArgs(StringBuilder& out) const
104{
105    auto escapeHandler = Process::getEscapeHandler();
106
107    const Int argCount = m_args.getCount();
108    for (Index i = 0; i < argCount; ++i)
109    {
110        const auto& arg = m_args[i];
111        if (i > 0)
112        {
113            out << " ";
114        }
115        StringEscapeUtil::appendMaybeQuoted(escapeHandler, arg.getUnownedSlice(), out);
116    }
117}
118
119void CommandLine::addArgIfNotFound(const String& in)
120{
121    if (m_args.indexOf(in) < 0)
122    {
123        addArg(in);
124    }
125}
126
127String CommandLine::toString() const
128{
129    StringBuilder buf;
130    append(buf);
131    return buf.produceString();
132}
133
134String CommandLine::toStringArgs() const
135{
136    StringBuilder buf;
137    appendArgs(buf);
138    return buf.produceString();
139}
140
141} // namespace Slang