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...


void NORETURN CDECL error (const char *s,...)
 Report a fatal error. More...
static IniLoadFileLoadIniFile (const char *filename)
 Load the INI file. More...
static void DumpGroup (IniLoadFile *ifile, const char *const group_name)
 Dump a IGT_SEQUENCE group into _stored_output. More...
static const char * FindItemValue (const char *name, IniGroup *grp, IniGroup *defaults)
 Find the value of a template variable. More...
static void DumpSections (IniLoadFile *ifile)
 Output all non-special sections through the template / template variable expansion system. More...
static void CopyFile (const char *fname, FILE *out_fp)
 Copy a file to the output. 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...


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. More...

Detailed Description

Tool to create computer-readable settings.

Definition in file settingsgen.cpp.

Function Documentation

◆ CompareFiles()

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

Compare two files for identity.

n1First file.
n2Second file.
True if both files are identical.

Definition at line 369 of file settingsgen.cpp.

◆ CopyFile()

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

Copy a file to the output.

fnameFilename of file to copy.
out_fpOutput stream to write to.

Definition at line 340 of file settingsgen.cpp.

Referenced by main().

◆ DumpGroup()

static void DumpGroup ( IniLoadFile ifile,
const char *const  group_name 

Dump a IGT_SEQUENCE group into _stored_output.

ifileLoaded INI data.
group_nameName 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().

◆ DumpSections()

static void DumpSections ( IniLoadFile ifile)

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

ifileLoaded 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().

◆ error()

void NORETURN CDECL error ( const char *  s,

Report a fatal error.

sFormat string.
Function does not return.

Definition at line 40 of file settingsgen.cpp.

References lastof, and vseprintf().

Referenced by SettingsIniFile::ReportFileError().

◆ FindItemValue()

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

Find the value of a template variable.

nameName of the item to find.
grpGroup currently being expanded (searched first).
defaultsFallback group to search, NULL skips the search.
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().

◆ LoadIniFile()

static IniLoadFile* LoadIniFile ( const char *  filename)

Load the INI file.

filenameName of the file to load.
subdirThe subdirectory to load from.
Loaded INI data.

Definition at line 211 of file settingsgen.cpp.


Referenced by ProcessIniFile().

◆ main()

int CDECL main ( int  argc,
char *  argv[] 

And the main program (what else?)

argcNumber of command-line arguments including the program name itself.
argvVector of the command-line arguments.

Definition at line 441 of file settingsgen.cpp.

References GetOptData::argv, OutputStore::Clear(), CopyFile(), GetOptData::GetOpt(), GetOptData::numleft, GetOptData::opt, ProcessIniFile(), and OutputStore::Write().

◆ ProcessIniFile()

static void ProcessIniFile ( const char *  fname)

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.

fnameIni file to process.
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

◆ _opts

const OptionData _opts[]
Initial value:
= {
GETOPT_NOVAL( 'v', "--version"),
GETOPT_NOVAL( 'h', "--help"),
GETOPT_VALUE( 'o', "--output"),
GETOPT_VALUE( 'b', "--before"),
GETOPT_VALUE( 'a', "--after"),
A plain option (no value attached to it).
Definition: getoptdata.h:17
#define GETOPT_VALUE(shortname, longname)
Short option with value.
Definition: getoptdata.h:78
#define GETOPT_GENERAL(id, shortname, longname, flags)
General macro for creating an option.
Definition: getoptdata.h:64
#define GETOPT_END()
Option terminator.
Definition: getoptdata.h:109
#define GETOPT_NOVAL(shortname, longname)
Short option without value.
Definition: getoptdata.h:71

Options of settingsgen.

Definition at line 397 of file settingsgen.cpp.