OpenTTD
|
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/smallvec_type.hpp"
#include <stdarg.h>
#include <unistd.h>
#include <sys/stat.h>
#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 NORETURN CDECL | error (const char *s,...) |
Report a fatal error. | |
static IniLoadFile * | LoadIniFile (const char *filename) |
Load the INI file. | |
static void | DumpGroup (IniLoadFile *ifile, const char *const group_name) |
Dump a IGT_SEQUENCE group into _stored_output. | |
static const char * | FindItemValue (const char *name, IniGroup *grp, IniGroup *defaults) |
Find the value of a template variable. | |
static void | DumpSections (IniLoadFile *ifile) |
Output all non-special sections through the template / template variable expansion system. | |
static void | CopyFile (const char *fname, FILE *out_fp) |
Copy a file to the output. | |
static bool | CompareFiles (const char *n1, const char *n2) |
Compare two files for identity. | |
static void | ProcessIniFile (const char *fname) |
Process a single INI file. | |
int CDECL | main (int argc, char *argv[]) |
And the main program (what else?) |
Variables | |
static const int | OUTPUT_BLOCK_SIZE = 16000 |
Block size of the buffer in OutputBuffer. | |
OutputStore | _stored_output |
Temporary storage of the output, until all processing is done. | |
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 * | DEFAULTS_GROUP_NAME = "defaults" |
Name of the group containing default values for the template variables. | |
static const OptionData | _opts [] |
Options of settingsgen. |
Tool to create computer-readable settings.
Definition in file settingsgen.cpp.
|
static |
Compare two files for identity.
n1 | First file. |
n2 | Second file. |
Definition at line 369 of file settingsgen.cpp.
References error().
Referenced by HeaderFileWriter::Finalise(), and main().
|
static |
Copy a file to the output.
fname | Filename of file to copy. |
out_fp | Output stream to write to. |
Definition at line 340 of file settingsgen.cpp.
References lengthof.
Referenced by main().
|
static |
Dump a IGT_SEQUENCE group into _stored_output.
ifile | Loaded INI data. |
group_name | Name of the group to copy. |
Definition at line 225 of file settingsgen.cpp.
References OutputStore::Add(), IniLoadFile::GetGroup(), IGT_SEQUENCE, IniGroup::item, IniItem::next, and IniGroup::type.
Referenced by ProcessIniFile().
|
static |
Output all non-special sections through the template / template variable expansion system.
ifile | Loaded INI data. |
Definition at line 257 of file settingsgen.cpp.
References OutputStore::Add(), DEFAULTS_GROUP_NAME, FindItemValue(), IniLoadFile::GetGroup(), IniGroup::GetItem(), IniLoadFile::group, IniGroup::next, POSTAMBLE_GROUP_NAME, PREAMBLE_GROUP_NAME, TEMPLATES_GROUP_NAME, and IniItem::value.
Referenced by ProcessIniFile().
void NORETURN CDECL error | ( | const char * | s, |
... | |||
) |
Report a fatal error.
s | Format string. |
Definition at line 40 of file settingsgen.cpp.
References lastof, and vseprintf().
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, NULL skips the search. |
NULL
. Definition at line 245 of file settingsgen.cpp.
References IniGroup::GetItem(), and IniItem::value.
Referenced by DumpSections().
|
static |
Load the INI file.
filename | Name of the file to load. |
subdir | The subdirectory to load from. |
Definition at line 211 of file settingsgen.cpp.
References IniLoadFile::LoadFromDisk(), NO_DIRECTORY, POSTAMBLE_GROUP_NAME, and PREAMBLE_GROUP_NAME.
Referenced by ProcessIniFile().
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 441 of file settingsgen.cpp.
References GetOptData::argv, OutputStore::Clear(), CompareFiles(), CopyFile(), error(), GetOptData::GetOpt(), GetOptData::numleft, GetOptData::opt, ProcessIniFile(), and OutputStore::Write().
|
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 427 of file settingsgen.cpp.
References DumpGroup(), DumpSections(), LoadIniFile(), POSTAMBLE_GROUP_NAME, and PREAMBLE_GROUP_NAME.
Referenced by main().
|
static |
Options of settingsgen.
Definition at line 397 of file settingsgen.cpp.