OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Data Structures | Functions | Variables
settingsgen.cpp File Reference

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.

## Detailed Description

Tool to create computer-readable settings.

Definition in file settingsgen.cpp.

## Function Documentation

static bool CompareFiles | ( | const char * | n1,
|  | const char * | n2
| ) |  |
| static

Compare two files for identity.

Parameters

  n1 | First file.
  n2 | Second file.

Returns
  True if both files are identical.

Definition at line 369 of file settingsgen.cpp.

References error().

Referenced by HeaderFileWriter::Finalise(), and main().

static void CopyFile | ( | const char * | fname,
|  | FILE * | out_fp
| ) |  |
| static

Copy a file to the output.

Parameters

  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 void DumpGroup | ( | IniLoadFile * | ifile,
|  | const char *const | group_name
| ) |  |
| static

Dump a IGT_SEQUENCE group into _stored_output.

Parameters

  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 void DumpSections | ( | IniLoadFile * | ifile | ) |
| static

Output all non-special sections through the template / template variable expansion system.

Parameters

  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.

Parameters

  s | Format string.

Note
  Function does not return.

Definition at line 40 of file settingsgen.cpp.

References lastof, and vseprintf().

static const char* FindItemValue | ( | const char * | name,
|  | IniGroup * | grp,
|  | IniGroup * | defaults
| ) |  |
| static

Find the value of a template variable.

Parameters

  name | Name of the item to find.
  grp | Group currently being expanded (searched first).
  defaults | Fallback group to search, `NULL` skips the search.

Returns
  Text of the item if found, else `NULL`.

Definition at line 245 of file settingsgen.cpp.

References IniGroup::GetItem(), and IniItem::value.

Referenced by DumpSections().

static IniLoadFile* LoadIniFile | ( | const char * | filename | ) |
| static

Load the INI file.

Parameters

  filename | Name of the file to load.
  subdir | The subdirectory to load from.

Returns
  Loaded INI data.

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?)

Parameters

  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 void ProcessIniFile | ( | const char * | fname | ) |
| 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.

Parameters

  fname | Ini file to process.

Returns
  Exit status of the processing.

Definition at line 427 of file settingsgen.cpp.

References DumpGroup(), DumpSections(), LoadIniFile(), POSTAMBLE_GROUP_NAME, and PREAMBLE_GROUP_NAME.

Referenced by main().

## Variable Documentation

const OptionData _opts[]
| static

Initial value:
{
GETOPT_NOVAL( 'v', "--version"),
GETOPT_NOVAL( 'h', "--help"),
GETOPT_GENERAL('h', '?', NULL, ODF_NO_VALUE),
GETOPT_VALUE( 'o', "--output"),
GETOPT_VALUE( 'b', "--before"),
GETOPT_VALUE( 'a', "--after"),
GETOPT_END(),
}

Options of settingsgen.

Definition at line 397 of file settingsgen.cpp.