File diff r24215:bbed7b4a4c4c → r24216:bee2183ce93e
src/settingsgen/settingsgen.cpp
Show inline comments
 
@@ -211,17 +211,17 @@ static IniLoadFile *LoadIniFile(const ch
 
 * Dump a #IGT_SEQUENCE group into #_stored_output.
 
 * @param ifile      Loaded INI data.
 
 * @param group_name Name of the group to copy.
 
 */
 
static void DumpGroup(IniLoadFile *ifile, const char * const group_name)
 
{
 
	IniGroup *grp = ifile->GetGroup(group_name, 0, false);
 
	IniGroup *grp = ifile->GetGroup(group_name, false);
 
	if (grp != nullptr && grp->type == IGT_SEQUENCE) {
 
		for (IniItem *item = grp->item; item != nullptr; item = item->next) {
 
			if (item->name) {
 
				_stored_output.Add(item->name);
 
			if (!item->name.empty()) {
 
				_stored_output.Add(item->name.c_str());
 
				_stored_output.Add("\n", 1);
 
			}
 
		}
 
	}
 
}
 

	
 
@@ -233,38 +233,38 @@ static void DumpGroup(IniLoadFile *ifile
 
 * @return Text of the item if found, else \c nullptr.
 
 */
 
static const char *FindItemValue(const char *name, IniGroup *grp, IniGroup *defaults)
 
{
 
	IniItem *item = grp->GetItem(name, false);
 
	if (item == nullptr && defaults != nullptr) item = defaults->GetItem(name, false);
 
	if (item == nullptr || item->value == nullptr) return nullptr;
 
	return item->value;
 
	if (item == nullptr || !item->value.has_value()) return nullptr;
 
	return item->value->c_str();
 
}
 

	
 
/**
 
 * Output all non-special sections through the template / template variable expansion system.
 
 * @param ifile Loaded INI data.
 
 */
 
static void DumpSections(IniLoadFile *ifile)
 
{
 
	static const int MAX_VAR_LENGTH = 64;
 
	static const char * const special_group_names[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, DEFAULTS_GROUP_NAME, TEMPLATES_GROUP_NAME, nullptr};
 

	
 
	IniGroup *default_grp = ifile->GetGroup(DEFAULTS_GROUP_NAME, 0, false);
 
	IniGroup *templates_grp  = ifile->GetGroup(TEMPLATES_GROUP_NAME, 0, false);
 
	IniGroup *default_grp = ifile->GetGroup(DEFAULTS_GROUP_NAME, false);
 
	IniGroup *templates_grp  = ifile->GetGroup(TEMPLATES_GROUP_NAME, false);
 
	if (templates_grp == nullptr) return;
 

	
 
	/* Output every group, using its name as template name. */
 
	for (IniGroup *grp = ifile->group; grp != nullptr; grp = grp->next) {
 
		const char * const *sgn;
 
		for (sgn = special_group_names; *sgn != nullptr; sgn++) if (strcmp(grp->name, *sgn) == 0) break;
 
		for (sgn = special_group_names; *sgn != nullptr; sgn++) if (grp->name == *sgn) break;
 
		if (*sgn != nullptr) continue;
 

	
 
		IniItem *template_item = templates_grp->GetItem(grp->name, false); // Find template value.
 
		if (template_item == nullptr || template_item->value == nullptr) {
 
			fprintf(stderr, "settingsgen: Warning: Cannot find template %s\n", grp->name);
 
		if (template_item == nullptr || !template_item->value.has_value()) {
 
			fprintf(stderr, "settingsgen: Warning: Cannot find template %s\n", grp->name.c_str());
 
			continue;
 
		}
 

	
 
		/* Prefix with #if/#ifdef/#ifndef */
 
		static const char * const pp_lines[] = {"if", "ifdef", "ifndef", nullptr};
 
		int count = 0;
 
@@ -278,13 +278,13 @@ static void DumpSections(IniLoadFile *if
 
				_stored_output.Add("\n", 1);
 
				count++;
 
			}
 
		}
 

	
 
		/* Output text of the template, except template variables of the form '$[_a-z0-9]+' which get replaced by their value. */
 
		const char *txt = template_item->value;
 
		const char *txt = template_item->value->c_str();
 
		while (*txt != '\0') {
 
			if (*txt != '$') {
 
				_stored_output.Add(txt, 1);
 
				txt++;
 
				continue;
 
			}