@@ -122,121 +122,135 @@ bool ConfigGenerator::passConfigureFile()
122122 m_isLibav = true ;
123123 m_projectName = " LIBAV" ;
124124 }
125- // Move to end of header guard (+1 for new line)
126- startPos += 24 - static_cast <uint>(m_isLibav);
125+ // Move to end of header guard
126+ startPos += 23 - static_cast <uint>(m_isLibav);
127127
128128 // Build default value list
129129 DefaultValuesList defaultValues;
130130 buildFixedValues (defaultValues);
131131
132- // Get each defined option till EOF
133- startPos = m_configureFile.find (" #define" , startPos);
134- uint configEnd = m_configureFile.find (" EOF" , startPos);
135- if (configEnd == string::npos) {
136- outputError (" Failed finding config.h parameters end" );
137- return false ;
138- }
139- uint endPos = configEnd;
140- while ((startPos != string::npos) && (startPos < configEnd)) {
141- // Skip white space
142- startPos = m_configureFile.find_first_not_of (g_whiteSpace, startPos + 7 );
143- // Get first string
144- endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
145- const string configName = m_configureFile.substr (startPos, endPos - startPos);
146- // Get second string
147- startPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
148- endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
149- string configValue = m_configureFile.substr (startPos, endPos - startPos);
150- // Check if the value is a variable
151- const uint startPos2 = configValue.find (' $' );
152- if (startPos2 != string::npos) {
153- // Check if it is a function call
154- if (configValue.at (startPos2 + 1 ) == ' (' ) {
155- endPos = m_configureFile.find (' )' , startPos);
156- configValue = m_configureFile.substr (startPos, endPos - startPos + 1 );
157- }
158- // Remove any quotes from the tag if there are any
159- const uint endPos2 =
160- (configValue.at (configValue.length () - 1 ) == ' "' ) ? configValue.length () - 1 : configValue.length ();
161- // Find and replace the value
162- auto val = defaultValues.find (configValue.substr (startPos2, endPos2 - startPos2));
163- if (val == defaultValues.end ()) {
164- outputError (" Unknown configuration operation found (" +
165- configValue.substr (startPos2, endPos2 - startPos2) + " )" );
166- return false ;
167- }
168- // Check if we need to add the quotes back
169- if (configValue.at (0 ) == ' "' ) {
170- // Replace the value with the default option in quotations
171- configValue = ' "' + val->second + ' "' ;
172- } else {
173- // Replace the value with the default option
174- configValue = val->second ;
175- }
132+ for (uint searches = 0 ; searches < 2 ; ++searches) {
133+ // Get each defined option till EOF
134+ uint configEnd = m_configureFile.find (" EOF" , startPos + 1 );
135+ startPos = m_configureFile.find (" #define" , startPos + 1 );
136+ if (configEnd == string::npos) {
137+ outputError (" Failed finding config.h parameters end" );
138+ return false ;
176139 }
140+ uint endPos = configEnd;
141+ while ((startPos != string::npos) && (startPos < configEnd)) {
142+ // Skip white space
143+ startPos = m_configureFile.find_first_not_of (g_whiteSpace, startPos + 7 );
144+ // Get first string
145+ endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
146+ const string configName = m_configureFile.substr (startPos, endPos - startPos);
147+ // Get second string
148+ startPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
149+ endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
150+ string configValue = m_configureFile.substr (startPos, endPos - startPos);
151+ // Check if the value is a variable
152+ const uint startPos2 = configValue.find (' $' );
153+ if (startPos2 != string::npos) {
154+ // Check if it is a function call
155+ if (configValue.at (startPos2 + 1 ) == ' (' ) {
156+ endPos = m_configureFile.find (' )' , startPos);
157+ configValue = m_configureFile.substr (startPos, endPos - startPos + 1 );
158+ }
159+ // Remove any quotes from the tag if there are any
160+ const uint endPos2 =
161+ (configValue.at (configValue.length () - 1 ) == ' "' ) ? configValue.length () - 1 : configValue.length ();
162+ // Find and replace the value
163+ auto val = defaultValues.find (configValue.substr (startPos2, endPos2 - startPos2));
164+ if (val == defaultValues.end ()) {
165+ outputError (" Unknown configuration operation found (" +
166+ configValue.substr (startPos2, endPos2 - startPos2) + " )" );
167+ return false ;
168+ }
169+ // Check if we need to add the quotes back
170+ if (configValue.at (0 ) == ' "' ) {
171+ // Replace the value with the default option in quotations
172+ configValue = ' "' + val->second + ' "' ;
173+ } else {
174+ // Replace the value with the default option
175+ configValue = val->second ;
176+ }
177+ }
177178
178- // Add to the list
179- m_fixedConfigValues.push_back (ConfigPair (configName, " " , configValue));
180-
181- // Find next
182- startPos = m_configureFile.find (" #define" , endPos + 1 );
183- }
179+ // Add to the list
180+ m_fixedConfigValues.push_back (ConfigPair (configName, " " , configValue));
184181
185- // Find the end of this section
186- configEnd = m_configureFile.find (" #endif" , configEnd + 1 );
187- if (configEnd == string::npos) {
188- outputError (" Failed finding config.h header end" );
189- return false ;
190- }
182+ // Find next
183+ startPos = m_configureFile.find (" #define" , endPos + 1 );
184+ }
191185
192- // Get the additional config values
193- startPos = m_configureFile.find (" print_config" , endPos + 3 );
194- while ((startPos != string::npos) && (startPos < configEnd)) {
195- // Add these to the config list
196- // Find prefix
197- startPos = m_configureFile.find_first_not_of (g_whiteSpace, startPos + 12 );
198- endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
199- string prefix = m_configureFile.substr (startPos, endPos - startPos);
200- // Skip unneeded var
201- startPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
202- endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
203-
204- // Find option list
205- startPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
206- endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
207- string sList = m_configureFile.substr (startPos, endPos - startPos);
208- // Strip the variable prefix from start
209- sList .erase (0 , 1 );
210-
211- // Create option list
212- if (!passConfigList (prefix, " " , sList )) {
186+ // Find the end of this section
187+ configEnd = m_configureFile.find (" #endif" , configEnd + 1 );
188+ if (configEnd == string::npos) {
189+ outputError (" Failed finding config.h header end" );
213190 return false ;
214191 }
215192
216- // Check if multiple lines
217- endPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
218- while (m_configureFile.at (endPos) == ' \\ ' ) {
219- // Skip newline
220- ++endPos;
221- startPos = m_configureFile.find_first_not_of (" \t " , endPos + 1 );
222- // Check for blank line
223- if (m_configureFile.at (startPos) == ' \n ' ) {
224- break ;
225- }
193+ // Get the additional config values
194+ startPos = m_configureFile.find (" print_config" , endPos + 3 );
195+ while ((startPos != string::npos) && (startPos < configEnd)) {
196+ // Add these to the config list
197+ // Find prefix
198+ startPos = m_configureFile.find_first_not_of (g_whiteSpace, startPos + 12 );
199+ endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
200+ string prefix = m_configureFile.substr (startPos, endPos - startPos);
201+ // Skip unneeded var
202+ startPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
203+ endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
204+
205+ // Find option list
206+ startPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
226207 endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
227- string list = m_configureFile.substr (startPos, endPos - startPos);
208+ string sList = m_configureFile.substr (startPos, endPos - startPos);
228209 // Strip the variable prefix from start
229- list .erase (0 , 1 );
210+ sList .erase (0 , 1 );
230211
231212 // Create option list
232- if (!passConfigList (prefix, " " , list )) {
213+ if (!passConfigList (prefix, " " , sList )) {
233214 return false ;
234215 }
216+
217+ // Check if multiple lines
235218 endPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
219+ while (m_configureFile.at (endPos) == ' \\ ' ) {
220+ // Skip newline
221+ ++endPos;
222+ startPos = m_configureFile.find_first_not_of (" \t " , endPos + 1 );
223+ // Check for blank line
224+ if (m_configureFile.at (startPos) == ' \n ' ) {
225+ break ;
226+ }
227+ endPos = m_configureFile.find_first_of (g_whiteSpace, startPos + 1 );
228+ string list = m_configureFile.substr (startPos, endPos - startPos);
229+ // Strip the variable prefix from start
230+ list.erase (0 , 1 );
231+
232+ // Create option list
233+ if (!passConfigList (prefix, " " , list)) {
234+ return false ;
235+ }
236+ endPos = m_configureFile.find_first_not_of (g_whiteSpace, endPos + 1 );
237+ }
238+
239+ // Get next
240+ startPos = m_configureFile.find (" print_config" , startPos + 1 );
236241 }
237242
238- // Get next
239- startPos = m_configureFile.find (" print_config" , startPos + 1 );
243+ if (searches == 0 ) {
244+ // Search for newer config_components.h
245+ startPos = m_configureFile.find (" #define FFMPEG_CONFIG_COMPONENTS_H" );
246+ if (startPos == string::npos) {
247+ break ;
248+ }
249+ // Move to end of header guard
250+ startPos += 34 ;
251+ // Set start of component section
252+ m_configComponentsStart = m_configValues.size ();
253+ }
240254 }
241255 // Mark the end of the config list. Any elements added after this are considered temporary and should not be
242256 // exported
@@ -822,20 +836,21 @@ bool ConfigGenerator::outputConfig()
822836 string configureFileASM = header2 + ' \n ' ;
823837
824838 // Output all internal options
825- for (const auto & i : m_configValues) {
826- string sTagName = i.m_prefix + i.m_option ;
839+ auto endConfig = (m_configComponentsStart > 0 ) ? m_configComponentsStart : m_configValuesEnd;
840+ for (auto i = m_configValues.begin (); i < m_configValues.begin () + endConfig; ++i) {
841+ string sTagName = i->m_prefix + i->m_option ;
827842 // Check for forced replacement (only if attribute is not disabled)
828843 string addConfig;
829- if ((i. m_value != " 0" ) && (m_replaceList.find (sTagName ) != m_replaceList.end ())) {
844+ if ((i-> m_value != " 0" ) && (m_replaceList.find (sTagName ) != m_replaceList.end ())) {
830845 addConfig = m_replaceList[sTagName ];
831846 } else {
832- addConfig = " #define " + sTagName + ' ' + i. m_value ;
847+ addConfig = " #define " + sTagName + ' ' + i-> m_value ;
833848 }
834849 configureFile += addConfig + ' \n ' ;
835- if ((i. m_value != " 0" ) && (m_replaceListASM.find (sTagName ) != m_replaceListASM.end ())) {
850+ if ((i-> m_value != " 0" ) && (m_replaceListASM.find (sTagName ) != m_replaceListASM.end ())) {
836851 configureFileASM += m_replaceListASM[sTagName ] + ' \n ' ;
837852 } else {
838- configureFileASM += " %define " + sTagName + ' ' + i. m_value + ' \n ' ;
853+ configureFileASM += " %define " + sTagName + ' ' + i-> m_value + ' \n ' ;
839854 }
840855 }
841856
@@ -853,6 +868,34 @@ bool ConfigGenerator::outputConfig()
853868 return false ;
854869 }
855870
871+ if (m_configComponentsStart > 0 ) {
872+ // Output config_components.h
873+ outputLine (" Outputting config_components.h..." );
874+ string componentsFile = fileHeader;
875+ componentsFile += " \n #ifndef FFMPEG_CONFIG_COMPONENTS_H\n " ;
876+ componentsFile += " #define FFMPEG_CONFIG_COMPONENTS_H\n " ;
877+ for (auto i = m_configValues.begin () + m_configComponentsStart; i < m_configValues.begin () + m_configValuesEnd;
878+ ++i) {
879+ string sTagName = i->m_prefix + i->m_option ;
880+ // Check for forced replacement (only if attribute is not disabled)
881+ string addConfig;
882+ if ((i->m_value != " 0" ) && (m_replaceList.find (sTagName ) != m_replaceList.end ())) {
883+ addConfig = m_replaceList[sTagName ];
884+ } else {
885+ addConfig = " #define " + sTagName + ' ' + i->m_value ;
886+ }
887+ componentsFile += addConfig + ' \n ' ;
888+ }
889+ // Output end header guard
890+ componentsFile += " #endif /* FFMPEG_CONFIG_COMPONENTS_H */\n " ;
891+ // Write output files
892+ configFile = m_solutionDirectory + " config_components.h" ;
893+ if (!writeToFile (configFile, componentsFile)) {
894+ outputError (" Failed opening output configure file (" + configFile + " )" );
895+ return false ;
896+ }
897+ }
898+
856899 // Output avconfig.h
857900 outputLine (" Outputting avconfig.h..." );
858901 if (!makeDirectory (m_solutionDirectory + " libavutil" )) {
0 commit comments