yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
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{ 18if (dir .getLength ()== 0 ) 19 { 20set (name ); 21 } 22else 23 { 24set (Path ::combine (dir ,name )); 25 } 26} 27 28void ExecutableLocation ::set (const String & nameOrPath ) 29{ 30// See if input looks like a path 31if (Path ::hasPath (nameOrPath )) 32 { 33// If it is a path we may want to add a suffix 34const auto suffix = Process ::getExecutableSuffix (); 35 36if (suffix .getLength ()== 0 || nameOrPath .endsWith (suffix )) 37 { 38setPath (nameOrPath ); 39 } 40else 41 { 42// If on target that has suffix make sure name has the suffix 43StringBuilder builder ; 44builder <<nameOrPath ; 45builder <<suffix ; 46setPath (builder .produceString ()); 47 } 48 } 49else 50 { 51// If we don't have a parent, we assume it is just a naem 52setName (nameOrPath ); 53 } 54} 55 56void ExecutableLocation ::append (StringBuilder & out )const 57{ 58if (m_type == Type ::Unknown ) 59 { 60out <<"(unknown)" ; 61 } 62else 63 { 64auto escapeHandler = Process ::getEscapeHandler (); 65StringEscapeUtil ::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{ 73StringBuilder builder ; 74builder <<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 82builder <<path ; 83 84if (pathPostfix ) 85 { 86// Work out the path with the postfix 87builder <<pathPostfix ; 88 } 89addArg (builder .produceString ()); 90} 91 92void CommandLine ::append (StringBuilder & out )const 93{ 94m_executableLocation .append (out ); 95 96if (m_args .getCount ()) 97 { 98out <<" " ; 99appendArgs (out ); 100 } 101} 102 103void CommandLine ::appendArgs (StringBuilder & out )const 104{ 105auto escapeHandler = Process ::getEscapeHandler (); 106 107const Int argCount = m_args .getCount (); 108for (Index i = 0 ;i < argCount ;++ i ) 109 { 110const auto & arg = m_args [i ]; 111if (i > 0 ) 112 { 113out <<" " ; 114 } 115StringEscapeUtil ::appendMaybeQuoted (escapeHandler ,arg .getUnownedSlice (),out ); 116 } 117} 118 119void CommandLine ::addArgIfNotFound (const String & in ) 120{ 121if (m_args .indexOf (in )< 0 ) 122 { 123addArg (in ); 124 } 125} 126 127String CommandLine ::toString ()const 128{ 129StringBuilder buf ; 130append (buf ); 131return buf .produceString (); 132} 133 134String CommandLine ::toStringArgs ()const 135{ 136StringBuilder buf ; 137appendArgs (buf ); 138return buf .produceString (); 139} 140 141}// namespace Slang