OpenTTD Source
20241108-master-g80f628063a
|
Tool to create computer-readable settings. More...
#include "../stdafx.h"
#include "../string_func.h"
#include "../strings_type.h"
#include "../misc/getoptdata.h"
#include "../ini_type.h"
#include "../core/mem_func.hpp"
#include "../error_func.h"
#include <filesystem>
#include "../safeguards.h"
Go to the source code of this file.
Data Structures | |
class | OutputBuffer |
Output buffer for a block of data. More... | |
class | OutputStore |
Temporarily store output. More... | |
struct | SettingsIniFile |
Derived class for loading INI files without going through Fio stuff. More... | |
Functions | |
void | FatalErrorI (const std::string &msg) |
Report a fatal error. More... | |
static void | DumpGroup (const IniLoadFile &ifile, const char *const group_name) |
Dump a IGT_SEQUENCE group into _stored_output. More... | |
static const char * | FindItemValue (const char *name, const IniGroup *grp, const IniGroup *defaults) |
Find the value of a template variable. More... | |
static void | DumpLine (const IniItem *item, const IniGroup *grp, const IniGroup *default_grp, OutputStore &output) |
Parse a single entry via a template and output this. More... | |
static void | DumpSections (const IniLoadFile &ifile) |
Output all non-special sections through the template / template variable expansion system. More... | |
static void | AppendFile (const char *fname, FILE *out_fp) |
Append a file to the output stream. More... | |
static bool | CompareFiles (const char *n1, const char *n2) |
Compare two files for identity. More... | |
static void | ProcessIniFile (const char *fname) |
Process a single INI file. More... | |
int CDECL | main (int argc, char *argv[]) |
And the main program (what else?) More... | |
Variables | |
static const size_t | OUTPUT_BLOCK_SIZE = 16000 |
Block size of the buffer in OutputBuffer. | |
OutputStore | _stored_output |
Temporary storage of the output, until all processing is done. | |
OutputStore | _post_amble_output |
Similar to _stored_output, but for the post amble. | |
static const char * | PREAMBLE_GROUP_NAME = "pre-amble" |
Name of the group containing the pre amble. | |
static const char * | POSTAMBLE_GROUP_NAME = "post-amble" |
Name of the group containing the post amble. | |
static const char * | TEMPLATES_GROUP_NAME = "templates" |
Name of the group containing the templates. | |
static const char * | VALIDATION_GROUP_NAME = "validation" |
Name of the group containing the validation statements. | |
static const char * | DEFAULTS_GROUP_NAME = "defaults" |
Name of the group containing default values for the template variables. | |
static const OptionData | _opts [] |
Options of settingsgen. More... | |
Tool to create computer-readable settings.
Definition in file settingsgen.cpp.
|
static |
Append a file to the output stream.
fname | Filename of file to append. |
out_fp | Output stream to write to. |
Definition at line 326 of file settingsgen.cpp.
References FileHandle::Open().
Referenced by main().
|
static |
Compare two files for identity.
n1 | First file. |
n2 | Second file. |
Definition at line 351 of file settingsgen.cpp.
References FileHandle::Open().
Referenced by HeaderFileWriter::Finalise().
|
static |
Dump a IGT_SEQUENCE group into _stored_output.
ifile | Loaded INI data. |
group_name | Name of the group to copy. |
Definition at line 193 of file settingsgen.cpp.
References _stored_output, OutputStore::Add(), IniLoadFile::GetGroup(), IGT_SEQUENCE, IniGroup::items, IniItem::name, and IniGroup::type.
Referenced by ProcessIniFile().
|
static |
Parse a single entry via a template and output this.
item | The template to use for the output. |
grp | Group current being used for template rendering. |
default_grp | Default values for items not set in @grp. |
output | Output to use for result. |
Definition at line 228 of file settingsgen.cpp.
References OutputStore::Add(), FindItemValue(), and IniItem::value.
|
static |
Output all non-special sections through the template / template variable expansion system.
ifile | Loaded INI data. |
Definition at line 292 of file settingsgen.cpp.
References DEFAULTS_GROUP_NAME, IniLoadFile::GetGroup(), IniGroup::GetItem(), IniLoadFile::groups, IniGroup::name, POSTAMBLE_GROUP_NAME, PREAMBLE_GROUP_NAME, TEMPLATES_GROUP_NAME, VALIDATION_GROUP_NAME, and IniItem::value.
Referenced by ProcessIniFile().
void FatalErrorI | ( | const std::string & | msg | ) |
Report a fatal error.
Error handling for fatal non-user errors.
s | Format string. |
Definition at line 27 of file settingsgen.cpp.
|
static |
Find the value of a template variable.
name | Name of the item to find. |
grp | Group currently being expanded (searched first). |
defaults | Fallback group to search, nullptr skips the search. |
nullptr
. Definition at line 213 of file settingsgen.cpp.
References IniGroup::GetItem(), and IniItem::value.
Referenced by DumpLine().
int CDECL main | ( | int | argc, |
char * | argv[] | ||
) |
And the main program (what else?)
argc | Number of command-line arguments including the program name itself. |
argv | Vector of the command-line arguments. |
Definition at line 422 of file settingsgen.cpp.
References _opts, _post_amble_output, _stored_output, AppendFile(), GetOptData::arguments, OutputStore::Clear(), GetOptData::GetOpt(), FileHandle::Open(), GetOptData::opt, ProcessIniFile(), and OutputStore::Write().
Referenced by GetSettingsTree().
|
static |
Process a single INI file.
The file should have a [templates] group, where each item is one template. Variables in a template have the form '$[a-z0-9]+' (a literal '$' followed by one or more '', lowercase letters, or lowercase numbers).
After loading, the [pre-amble] group is copied verbatim if it exists.
For every group with a name that matches a template name the template is written. It starts with a optional #if
line if an 'if' item exists in the group. The item value is used as condition. Similarly, #ifdef
and #ifndef
lines are also written. Below the macro processor directives, the value of the template is written at a line with its variables replaced by item values of the group being written. If the group has no item for the variable, the [defaults] group is tried as fall back. Finally, #endif
lines are written to match the macro processor lines.
Last but not least, the [post-amble] group is copied verbatim.
fname | Ini file to process. |
Definition at line 405 of file settingsgen.cpp.
References DumpGroup(), DumpSections(), IniLoadFile::LoadFromDisk(), NO_DIRECTORY, POSTAMBLE_GROUP_NAME, and PREAMBLE_GROUP_NAME.
Referenced by main().
|
static |
Options of settingsgen.
Definition at line 377 of file settingsgen.cpp.
Referenced by main().