@@ -960,7 +960,7 @@ static void LoadIGCFlagsFromRegistry(const std::string &options = "", bool *RegF
960960 }
961961}
962962
963- static void LoadIGCFlagsFromOptionsString (const std::string_view &options, bool *parseError) {
963+ static void LoadIGCFlagsFromOptionsString (const std::string_view &options, std::string *parseError) {
964964 std::string_view allSeparators = " , \v\f\t\r\n " ;
965965
966966 for (IGCFlag &igcFlag : g_IGCFlagsArray) {
@@ -993,19 +993,28 @@ static void LoadIGCFlagsFromOptionsString(const std::string_view &options, bool
993993 igcFlag.m_Value = parsedInt;
994994 igcFlag.isSet = true ;
995995 } else {
996- std::cerr << " Failed to parse flag '" << igcFlag.name << " ' as an unsigned integer. Token: '" << token << " \n " ;
996+ std::string msg = " Failed to parse flag '" + std::string (igcFlag.name ) + " ' as an unsigned integer. Token: '" +
997+ std::string (token) + " '\n " ;
998+ if (parseError)
999+ *parseError += msg;
9971000 setError = true ;
9981001 }
9991002 } else { // IsString
10001003 size_t foundEqual = token.find (' =' );
10011004 if (foundEqual != std::string::npos) {
1002- std::cerr << " Failed to parse flag '" << igcFlag.name << " ', found an unexpected '=' character in token: '"
1003- << token << " '. Make sure to use comma , separator in igc_opts.\n " ;
1005+ std::string msg = " Failed to parse flag '" + std::string (igcFlag.name ) +
1006+ " ', found an unexpected '=' character in token: '" + std::string (token) +
1007+ " '. Make sure to use comma , separator in igc_opts.\n " ;
1008+ if (parseError)
1009+ *parseError += msg;
10041010 setError = true ;
10051011 }
10061012
10071013 if (!setError && sizeof (igcFlag.m_string ) <= token.size ()) {
1008- std::cerr << " Failed to parse flag '" << igcFlag.name << " ' due to max length limit overflow.\n " ;
1014+ std::string msg =
1015+ " Failed to parse flag '" + std::string (igcFlag.name ) + " ' due to max length limit overflow.\n " ;
1016+ if (parseError)
1017+ *parseError += msg;
10091018 setError = true ;
10101019 }
10111020
@@ -1014,13 +1023,10 @@ static void LoadIGCFlagsFromOptionsString(const std::string_view &options, bool
10141023 igcFlag.isSet = true ;
10151024 }
10161025 }
1017-
1018- if (setError && parseError != nullptr )
1019- *parseError = true ;
10201026 }
10211027}
10221028
1023- static void PrintIGCFlags () {
1029+ [[maybe_unused]] static void PrintIGCFlags () {
10241030 if (IGC_IS_FLAG_ENABLED (PrintDebugSettings)) {
10251031 for (IGCFlag &igcFlag : g_IGCFlagsArray) {
10261032 if (igcFlag.IsSetToNonDefaultValue ()) {
@@ -1072,7 +1078,30 @@ void InitializeRegKeys() {
10721078 }
10731079}
10741080
1075- void LoadRegistryKeys (const std::string &options, bool *optionsParseError) {
1081+ static std::string ExtractIGCOptsFromOptions (const std::string &options, std::string *errorString) {
1082+ std::string result;
1083+ std::string_view remaining = options;
1084+ while (!remaining.empty ()) {
1085+ std::size_t found = remaining.find (" -igc_opts" );
1086+ if (found == std::string_view::npos)
1087+ break ;
1088+
1089+ std::size_t firstQuote = remaining.find (' \' ' , found);
1090+ std::size_t secondQuote =
1091+ (firstQuote != std::string_view::npos) ? remaining.find (' \' ' , firstQuote + 1 ) : std::string_view::npos;
1092+ if (firstQuote == std::string_view::npos || secondQuote == std::string_view::npos) {
1093+ if (errorString)
1094+ *errorString += " Missing single quotes for -igc_opts\n " ;
1095+ break ;
1096+ }
1097+ result += remaining.substr (firstQuote + 1 , secondQuote - firstQuote - 1 );
1098+ result += ' ,' ;
1099+ remaining = remaining.substr (secondQuote + 1 );
1100+ }
1101+ return result;
1102+ }
1103+
1104+ void LoadRegistryKeys (const std::string &options, std::string *optionsParseError) {
10761105 // only load the debug flags once before compiling to avoid any multi-threading issue
10771106 static std::mutex loadFlags;
10781107 static volatile bool flagsSet = false ;
@@ -1081,8 +1110,15 @@ void LoadRegistryKeys(const std::string &options, bool *optionsParseError) {
10811110 if (!flagsSet) {
10821111 flagsSet = true ;
10831112 LoadIGCFlagsFromRegistry ();
1084- LoadIGCFlagsFromOptionsString (options, optionsParseError);
1113+
1114+ std::string igcOpts = ExtractIGCOptsFromOptions (options, optionsParseError);
1115+ if (!igcOpts.empty ()) {
1116+ LoadIGCFlagsFromOptionsString (igcOpts, optionsParseError);
1117+ }
1118+
1119+ #if !defined(IGC_FCL_BUILD)
10851120 PrintIGCFlags ();
1121+ #endif
10861122 InitializeRegKeys ();
10871123 }
10881124}
@@ -1149,28 +1185,3 @@ void GetKeysSetExplicitly(std::string *KeyValuePairs, std::string *OptionKeys) {
11491185 }
11501186}
11511187#endif
1152-
1153- std::string ExtractIGCOptsFromOptions (const char *pOptions, std::string &errorString) {
1154- std::string result;
1155- if (pOptions == nullptr )
1156- return result;
1157-
1158- std::string_view remaining = pOptions;
1159- while (!remaining.empty ()) {
1160- std::size_t found = remaining.find (" -igc_opts" );
1161- if (found == std::string_view::npos)
1162- break ;
1163-
1164- std::size_t firstQuote = remaining.find (' \' ' , found);
1165- std::size_t secondQuote =
1166- (firstQuote != std::string_view::npos) ? remaining.find (' \' ' , firstQuote + 1 ) : std::string_view::npos;
1167- if (firstQuote == std::string_view::npos || secondQuote == std::string_view::npos) {
1168- errorString = " Missing single quotes for -igc_opts" ;
1169- break ;
1170- }
1171- result += remaining.substr (firstQuote + 1 , secondQuote - firstQuote - 1 );
1172- result += ' ,' ;
1173- remaining = remaining.substr (secondQuote + 1 );
1174- }
1175- return result;
1176- }
0 commit comments