Freeciv21
Develop your civilization from humble roots to a global empire
registry_ini.cpp File Reference

the idea with this file is to create something similar to the ms-windows .ini files functions. More...

#include <KFilterDev>
#include "bugs.h"
#include "deprecations.h"
#include "fcintl.h"
#include "inputfile.h"
#include "log.h"
#include "registry.h"
#include "section_file.h"
#include "shared.h"
#include "support.h"
#include "registry_ini.h"
+ Include dependency graph for registry_ini.cpp:

Go to the source code of this file.

Classes

struct  entry
 

Macros

#define MAX_LEN_SECPATH   1024
 
#define SAVE_TABLES   true
 

Functions

static bool entry_used (const struct entry *pentry)
 Returns TRUE if this entry has been used. More...
 
static void entry_use (struct entry *pentry)
 Increase the used count. More...
 
static bool entry_to_file (const struct entry *pentry, QIODevice *fs)
 Push an entry into a file stream. More...
 
static void entry_from_inf_token (struct section *psection, const QString &name, const QString &tok, struct inputfile *inf)
 Creates a new entry from the token. More...
 
static struct entrysection_entry_filereference_new (struct section *psection, const char *name, const char *value)
 Returns a new entry of type ENTRY_FILEREFERENCE. More...
 
static QString datafilename (const QString &filename)
 Simplification of fileinfoname(). More...
 
static bool is_secfile_entry_name_valid (const QString &name)
 Ensure name is correct to use it as section or entry name. More...
 
static bool secfile_hash_insert (struct section_file *secfile, struct entry *pentry)
 Insert an entry into the hash table. More...
 
static bool secfile_hash_delete (struct section_file *secfile, struct entry *pentry)
 Delete an entry from the hash table. More...
 
static struct section_filesecfile_from_input_file (struct inputfile *inf, const QString &filename, const QString &section, bool allow_duplicates)
 Base function to load a section file. More...
 
struct section_filesecfile_load_section (const QString &filename, const QString &section, bool allow_duplicates)
 Create a section file from a file, read only one particular section. More...
 
struct section_filesecfile_from_stream (QIODevice *stream, bool allow_duplicates)
 Create a section file from a stream. More...
 
static bool is_legal_table_entry_name (char c, bool num)
 Returns TRUE iff the character is legal in a table entry name. More...
 
bool secfile_save (const struct section_file *secfile, QString filename)
 Save the previously filled in section_file to disk. More...
 
void secfile_check_unused (const struct section_file *secfile)
 Print log messages for any entries in the file which have not been looked up – ie, unused or unrecognised entries. More...
 
const char * secfile_name (const struct section_file *secfile)
 Return the filename the section file was loaded as, or "(anonymous)" if this sectionfile was created rather than loaded from file. More...
 
static struct sectionsecfile_insert_base (struct section_file *secfile, const char *path, const char **pent_name)
 Seperates the section and entry names. More...
 
struct entrysecfile_insert_bool_full (struct section_file *secfile, bool value, const char *comment, bool allow_replace, const char *path,...)
 Insert a boolean entry. More...
 
size_t secfile_insert_bool_vec_full (struct section_file *secfile, const bool *values, size_t dim, const char *comment, bool allow_replace, const char *path,...)
 Insert 'dim' boolean entries at 'path,0', 'path,1' etc. More...
 
struct entrysecfile_insert_int_full (struct section_file *secfile, int value, const char *comment, bool allow_replace, const char *path,...)
 Insert a integer entry. More...
 
size_t secfile_insert_int_vec_full (struct section_file *secfile, const int *values, size_t dim, const char *comment, bool allow_replace, const char *path,...)
 Insert 'dim' integer entries at 'path,0', 'path,1' etc. More...
 
struct entrysecfile_insert_float_full (struct section_file *secfile, float value, const char *comment, bool allow_replace, const char *path,...)
 Insert a floating entry. More...
 
struct sectionsecfile_insert_include (struct section_file *secfile, const char *filename)
 Insert a include entry. More...
 
struct sectionsecfile_insert_long_comment (struct section_file *secfile, const char *comment)
 Insert a long comment entry. More...
 
struct entrysecfile_insert_str_full (struct section_file *secfile, const char *str, const char *comment, bool allow_replace, bool no_escape, enum entry_special_type stype, const char *path,...)
 Insert a string entry. More...
 
size_t secfile_insert_str_vec_full (struct section_file *secfile, const char *const *strings, size_t dim, const char *comment, bool allow_replace, bool no_escape, const char *path,...)
 Insert 'dim' string entries at 'path,0', 'path,1' etc. More...
 
size_t secfile_insert_str_vec_full (struct section_file *secfile, const QVector< QString > &strings, size_t dim, const char *comment, bool allow_replace, bool no_escape, const char *path,...)
 Insert up to 'dim' string entries at 'path,0', 'path,1' etc. More...
 
struct entrysecfile_insert_filereference (struct section_file *secfile, const char *filename, const char *path,...)
 Insert a read-from-a-file string entry. More...
 
struct entrysecfile_insert_plain_enum_full (struct section_file *secfile, int enumerator, secfile_enum_name_fn_t name_fn, const char *comment, bool allow_replace, const char *path,...)
 Insert a enumerator entry. More...
 
size_t secfile_insert_plain_enum_vec_full (struct section_file *secfile, const int *enumurators, size_t dim, secfile_enum_name_fn_t name_fn, const char *comment, bool allow_replace, const char *path,...)
 Insert 'dim' string entries at 'path,0', 'path,1' etc. More...
 
struct entrysecfile_insert_bitwise_enum_full (struct section_file *secfile, int bitwise_val, secfile_enum_name_fn_t name_fn, secfile_enum_iter_fn_t begin_fn, secfile_enum_iter_fn_t end_fn, secfile_enum_next_fn_t next_fn, const char *comment, bool allow_replace, const char *path,...)
 Insert a bitwise value entry. More...
 
size_t secfile_insert_bitwise_enum_vec_full (struct section_file *secfile, const int *bitwise_vals, size_t dim, secfile_enum_name_fn_t name_fn, secfile_enum_iter_fn_t begin_fn, secfile_enum_iter_fn_t end_fn, secfile_enum_next_fn_t next_fn, const char *comment, bool allow_replace, const char *path,...)
 Insert 'dim' string entries at 'path,0', 'path,1' etc. More...
 
struct entrysecfile_insert_enum_data_full (struct section_file *secfile, int value, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *comment, bool allow_replace, const char *path,...)
 Insert an enumerator value entry that we only have a name accessor function. More...
 
size_t secfile_insert_enum_vec_data_full (struct section_file *secfile, const int *values, size_t dim, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *comment, bool allow_replace, const char *path,...)
 Insert 'dim' entries at 'path,0', 'path,1' etc. More...
 
struct entrysecfile_entry_by_path (const struct section_file *secfile, const char *path)
 Returns the entry by the name or nullptr if not matched. More...
 
bool secfile_entry_delete (struct section_file *secfile, const char *path,...)
 Delete an entry. More...
 
struct entrysecfile_entry_lookup (const struct section_file *secfile, const char *path,...)
 Returns the entry at "fullpath" or nullptr if not matched. More...
 
bool secfile_lookup_bool (const struct section_file *secfile, bool *bval, const char *path,...)
 Lookup a boolean value in the secfile. More...
 
bool secfile_lookup_bool_default (const struct section_file *secfile, bool def, const char *path,...)
 Lookup a boolean value in the secfile. More...
 
bool secfile_lookup_int (const struct section_file *secfile, int *ival, const char *path,...)
 Lookup a integer value in the secfile. More...
 
int secfile_lookup_int_default (const struct section_file *secfile, int def, const char *path,...)
 Lookup a integer value in the secfile. More...
 
int secfile_lookup_int_def_min_max (const struct section_file *secfile, int defval, int minval, int maxval, const char *path,...)
 Lookup a integer value in the secfile. More...
 
int * secfile_lookup_int_vec (const struct section_file *secfile, size_t *dim, const char *path,...)
 Lookup a integer vector in the secfile. More...
 
const char * secfile_lookup_str (const struct section_file *secfile, const char *path,...)
 Lookup a string value in the secfile. More...
 
const char * secfile_lookup_str_default (const struct section_file *secfile, const char *def, const char *path,...)
 Lookup a string value in the secfile. More...
 
const char ** secfile_lookup_str_vec (const struct section_file *secfile, size_t *dim, const char *path,...)
 Lookup a string vector in the secfile. More...
 
bool secfile_lookup_plain_enum_full (const struct section_file *secfile, int *penumerator, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...)
 Lookup an enumerator value in the secfile. More...
 
int secfile_lookup_plain_enum_default_full (const struct section_file *secfile, int defval, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...)
 Lookup an enumerator value in the secfile. More...
 
int * secfile_lookup_plain_enum_vec_full (const struct section_file *secfile, size_t *dim, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...)
 Lookup a enumerator vector in the secfile. More...
 
bool secfile_lookup_bitwise_enum_full (const struct section_file *secfile, int *penumerator, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...)
 Lookup a bitwise enumerator value in the secfile. More...
 
int secfile_lookup_bitwise_enum_default_full (const struct section_file *secfile, int defval, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...)
 Lookup an enumerator value in the secfile. More...
 
int * secfile_lookup_bitwise_enum_vec_full (const struct section_file *secfile, size_t *dim, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...)
 Lookup a enumerator vector in the secfile. More...
 
bool secfile_lookup_enum_data (const struct section_file *secfile, int *pvalue, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *path,...)
 Lookup a value saved as string in the secfile. More...
 
int secfile_lookup_enum_default_data (const struct section_file *secfile, int defval, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *path,...)
 Lookup a value saved as string in the secfile. More...
 
struct sectionsecfile_section_by_name (const struct section_file *secfile, const QString &name)
 Returns the first section matching the name. More...
 
struct sectionsecfile_section_lookup (const struct section_file *secfile, const char *path,...)
 Find a section by path. More...
 
const struct section_list * secfile_sections (const struct section_file *secfile)
 Returns the list of sections. More...
 
struct section_list * secfile_sections_by_name_prefix (const struct section_file *secfile, const char *prefix)
 Returns the list of sections which match the name prefix. More...
 
struct sectionsecfile_section_new (struct section_file *secfile, const QString &name)
 Create a new section in the secfile. More...
 
void section_destroy (struct section *psection)
 Remove this section from the secfile. More...
 
void section_clear_all (struct section *psection)
 Remove all entries. More...
 
const struct entry_list * section_entries (const struct section *psection)
 Returns a list containing all the entries. More...
 
struct entrysection_entry_by_name (const struct section *psection, const QString &name)
 Returns the first entry matching the name. More...
 
static entryentry_new (struct section *psection, const QString &name)
 Returns a new entry. More...
 
struct entrysection_entry_int_new (struct section *psection, const QString &name, int value)
 Returns a new entry of type ENTRY_INT. More...
 
struct entrysection_entry_bool_new (struct section *psection, const QString &name, bool value)
 Returns a new entry of type ENTRY_BOOL. More...
 
struct entrysection_entry_float_new (struct section *psection, const QString &name, float value)
 Returns a new entry of type ENTRY_FLOAT. More...
 
struct entrysection_entry_str_new (struct section *psection, const QString &name, const QString &value, bool escaped)
 Returns a new entry of type ENTRY_STR. More...
 
void entry_destroy (struct entry *pentry)
 Entry structure destructor. More...
 
struct sectionentry_section (const struct entry *pentry)
 Returns the parent section of this entry. More...
 
enum entry_type entry_type_get (const struct entry *pentry)
 Returns the type of this entry or ENTRY_ILLEGAL or error. More...
 
int entry_path (const struct entry *pentry, char *buf, size_t buf_len)
 Build the entry path. More...
 
const char * entry_name (const struct entry *pentry)
 Returns the name of this entry. More...
 
bool entry_set_name (struct entry *pentry, const char *name)
 Sets the name of the entry. More...
 
const char * entry_comment (const struct entry *pentry)
 Returns the comment associated to this entry. More...
 
void entry_set_comment (struct entry *pentry, const QString &comment)
 Sets a comment for the entry. More...
 
bool entry_bool_get (const struct entry *pentry, bool *value)
 Gets an boolean value. More...
 
bool entry_bool_set (struct entry *pentry, bool value)
 Sets an boolean value. More...
 
bool entry_float_get (const struct entry *pentry, float *value)
 Gets an floating value. More...
 
bool entry_float_set (struct entry *pentry, float value)
 Sets an floating value. More...
 
bool entry_int_get (const struct entry *pentry, int *value)
 Gets an integer value. More...
 
bool entry_int_set (struct entry *pentry, int value)
 Sets an integer value. More...
 
bool entry_str_get (const struct entry *pentry, const char **value)
 Gets an string value. More...
 
bool entry_str_set (struct entry *pentry, const char *value)
 Sets an string value. More...
 
bool entry_str_set_gt_marking (struct entry *pentry, bool gt_marking)
 Sets if the string should get gettext marking. More...
 

Detailed Description

the idea with this file is to create something similar to the ms-windows .ini files functions.

however the interface is nice. ie: secfile_lookup_str(file, "player%d.unit%d.name", plrno, unitno);

Description of the file format

(This is based on a format by the original authors, with various incremental extensions. –dwp)

  • Whitespace lines are ignored, as are lines where the first non-whitespace character is ';' (comment lines). Optionally '#' can also be used for comments.
  • A line of the form: include "filename" includes the named file at that point. (The '' must be the first character on the line.) The file is found by looking in FREECIV_DATA_PATH. Non-infinite recursive includes are allowed.
  • A line with "[name]" labels the start of a section with that name; one of these must be the first non-comment line in the file. Any spaces within the brackets are included in the name, but this feature (?) should probably not be used...
  • Within a section, lines have one of the following forms: subname = "stringvalue" subname = -digits subname = digits subname = TRUE sunname = FALSE for a value with given name and string, negative integer, and positive integer values, respectively. These entries are referenced in the following functions as "sectionname.subname". The section name should not contain any dots ('.'); the subname can, but they have no particular significance. There can be optional whitespace before and/or after the equals sign. You can put a newline after (but not before) the equals sign.

    Backslash is an escape character in strings (double-quoted strings only, not names); recognised escapes are \n, \\, and \". (Any other \<char> is just treated as <char>.)

  • Gettext markings: You can surround strings like so:

    foo = _("stringvalue")

    The registry just ignores these extra markings, but this is useful for marking strings for translations via gettext tools.

  • Multiline strings: Strings can have embeded newlines, eg:

    foo = _(" This is a string over multiple lines ")

    This is equivalent to:

    foo = _("\\nThis is a string\\nover multiple lines\\n")

    Note that if you missplace the trailing doublequote you can easily end up with strange errors reading the file...

  • Strings read from a file: A file can be read as a string value: foo = filename.txt
  • Vector format: An entry can have multiple values separated by commas, eg: foo = 10, 11, "x" These are accessed by names "foo", "foo,1" and "foo,2" (with section prefix as above). So the above is equivalent to: foo = 10 foo,1 = 11 foo,2 = "x" As in the example, in principle you can mix integers and strings, but the calling program will probably require elements to be the same type. Note that the first element of a vector is not "foo,0", in order that the name of the first element is the same whether or not there are subsequent elements. However as a convenience, if you try to lookup "foo,0" then you get back "foo". (So you should never have "foo,0" as a real name in the datafile.)
  • Tabular format: The lines: foo = { "bar", "baz", "bax" "wow", 10, -5 "cool", "str" "hmm", 314, 99, 33, 11 } are equivalent to the following: foo0.bar = "wow" foo0.baz = 10 foo0.bax = -5 foo1.bar = "cool" foo1.baz = "str" foo2.bar = "hmm" foo2.baz = 314 foo2.bax = 99 foo2.bax,1 = 33 foo2.bax,2 = 11 The first line specifies the base name and the column names, and the subsequent lines have data. Again it is possible to mix string and integer values in a column, and have either more or less values in a row than there are column headings, but the code which uses this information (via the registry) may set more stringent conditions. If a row has more entries than column headings, the last column is treated as a vector (as above). You can optionally put a newline after '=' and/or after '{'.

    The equivalence above between the new and old formats is fairly direct: internally, data is converted to the old format. In principle it could be a good idea to represent the data as a table (2-d array) internally, but the current method seems sufficient and relatively simple...

    There is a limited ability to save data in tabular: So long as the section_file is constructed in an expected way, tabular data (with no missing or extra values) can be saved in tabular form. (See section_file_save().)

  • Multiline vectors: if the last non-comment non-whitespace character in a line is a comma, the line is considered to continue on to the next line. Eg: foo = 10, 11, "x" This is equivalent to the original "vector format" example above. Such multi-lines can occur for column headings, vectors, or table rows, again with some potential for strange errors...

Hashing registry lookups

(by dwp)

  • Have a hash table direct to entries, bypassing sections division.
  • For convenience, store the key (the full section+entry name) in the hash table (some memory overhead).
  • The number of entries is fixed when the hash table is built.
  • Now uses hash.c

Definition in file registry_ini.cpp.

Macro Definition Documentation

◆ MAX_LEN_SECPATH

#define MAX_LEN_SECPATH   1024

Definition at line 173 of file registry_ini.cpp.

◆ SAVE_TABLES

#define SAVE_TABLES   true

Definition at line 176 of file registry_ini.cpp.

Function Documentation

◆ datafilename()

static QString datafilename ( const QString &  filename)
static

Simplification of fileinfoname().

Definition at line 226 of file registry_ini.cpp.

Referenced by secfile_from_stream(), and secfile_load_section().

◆ entry_bool_get()

bool entry_bool_get ( const struct entry pentry,
bool *  value 
)

Gets an boolean value.

Returns TRUE on success. On old saved files, 0 and 1 can also be considered as bool.

Definition at line 3111 of file registry_ini.cpp.

Referenced by lookup_req_list(), secfile_lookup_bool(), secfile_lookup_bool_default(), and settable_options_load().

◆ entry_bool_set()

bool entry_bool_set ( struct entry pentry,
bool  value 
)

Sets an boolean value.

Returns TRUE on success.

Definition at line 3136 of file registry_ini.cpp.

Referenced by secfile_insert_bool_full().

◆ entry_comment()

const char* entry_comment ( const struct entry pentry)

Returns the comment associated to this entry.

Definition at line 3076 of file registry_ini.cpp.

Referenced by secfile_save().

◆ entry_destroy()

◆ entry_float_get()

bool entry_float_get ( const struct entry pentry,
float *  value 
)

Gets an floating value.

Returns TRUE on success.

Definition at line 3149 of file registry_ini.cpp.

◆ entry_float_set()

bool entry_float_set ( struct entry pentry,
float  value 
)

Sets an floating value.

Returns TRUE on success.

Definition at line 3165 of file registry_ini.cpp.

Referenced by secfile_insert_float_full().

◆ entry_from_inf_token()

static void entry_from_inf_token ( struct section psection,
const QString &  name,
const QString &  tok,
struct inputfile file 
)
static

Creates a new entry from the token.

Definition at line 3310 of file registry_ini.cpp.

Referenced by secfile_from_input_file().

◆ entry_int_get()

bool entry_int_get ( const struct entry pentry,
int *  value 
)

Gets an integer value.

Returns TRUE on success.

Definition at line 3179 of file registry_ini.cpp.

Referenced by load_action_range_max(), lookup_req_list(), secfile_lookup_int(), secfile_lookup_int_def_min_max(), secfile_lookup_int_default(), and settable_options_load().

◆ entry_int_set()

bool entry_int_set ( struct entry pentry,
int  value 
)

Sets an integer value.

Returns TRUE on success.

Definition at line 3194 of file registry_ini.cpp.

Referenced by secfile_insert_int_full().

◆ entry_name()

◆ entry_new()

static entry* entry_new ( struct section psection,
const QString &  name 
)
static

◆ entry_path()

int entry_path ( const struct entry pentry,
char *  buf,
size_t  buf_len 
)

Build the entry path.

Returns like snprintf().

Definition at line 3010 of file registry_ini.cpp.

Referenced by secfile_hash_delete(), and secfile_hash_insert().

◆ entry_section()

struct section* entry_section ( const struct entry pentry)

◆ entry_set_comment()

void entry_set_comment ( struct entry pentry,
const QString &  comment 
)

◆ entry_set_name()

bool entry_set_name ( struct entry pentry,
const char *  name 
)

Sets the name of the entry.

Returns TRUE on success.

Definition at line 3028 of file registry_ini.cpp.

Referenced by compat_load_020400().

◆ entry_str_get()

◆ entry_str_set()

bool entry_str_set ( struct entry pentry,
const char *  value 
)

Sets an string value.

Returns TRUE on success.

Definition at line 3222 of file registry_ini.cpp.

Referenced by secfile_insert_bitwise_enum_full(), secfile_insert_enum_data_full(), secfile_insert_plain_enum_full(), and secfile_insert_str_full().

◆ entry_str_set_gt_marking()

bool entry_str_set_gt_marking ( struct entry pentry,
bool  gt_marking 
)

Sets if the string should get gettext marking.

Returns TRUE on success.

Definition at line 3243 of file registry_ini.cpp.

Referenced by save_game_ruleset(), save_name_translation(), and sg_save_scenario().

◆ entry_to_file()

static bool entry_to_file ( const struct entry pentry,
QIODevice *  fs 
)
static

Push an entry into a file stream.

Definition at line 3257 of file registry_ini.cpp.

Referenced by secfile_save().

◆ entry_type_get()

◆ entry_use()

static void entry_use ( struct entry pentry)
inlinestatic

Increase the used count.

Definition at line 3105 of file registry_ini.cpp.

Referenced by secfile_entry_by_path(), secfile_hash_insert(), and section_entry_by_name().

◆ entry_used()

static bool entry_used ( const struct entry pentry)
inlinestatic

Returns TRUE if this entry has been used.

Definition at line 3097 of file registry_ini.cpp.

Referenced by secfile_check_unused().

◆ is_legal_table_entry_name()

static bool is_legal_table_entry_name ( char  c,
bool  num 
)
static

Returns TRUE iff the character is legal in a table entry name.

Definition at line 595 of file registry_ini.cpp.

Referenced by secfile_save().

◆ is_secfile_entry_name_valid()

static bool is_secfile_entry_name_valid ( const QString &  name)
static

Ensure name is correct to use it as section or entry name.

Definition at line 234 of file registry_ini.cpp.

Referenced by entry_new(), entry_set_name(), and secfile_section_new().

◆ secfile_check_unused()

void secfile_check_unused ( const struct section_file secfile)

Print log messages for any entries in the file which have not been looked up – ie, unused or unrecognised entries.

To mark an entry as used without actually doing anything with it, you could do something like: section_file_lookup(&file, "foo.bar"); / * unused * /

Definition at line 857 of file registry_ini.cpp.

Referenced by boot_help_texts(), comments_load(), load_command(), load_ruleset_buildings(), load_ruleset_cities(), load_ruleset_effects(), load_ruleset_governments(), load_ruleset_nations(), load_ruleset_techs(), load_ruleset_terrain(), load_ruleset_units(), load_rulesetdir(), scan_specfile(), and tileset_read_toplevel().

◆ secfile_entry_by_path()

◆ secfile_entry_delete()

bool secfile_entry_delete ( struct section_file secfile,
const char *  path,
  ... 
)

Delete an entry.

Definition at line 1765 of file registry_ini.cpp.

Referenced by compat_load_020400(), and compat_load_020600().

◆ secfile_entry_lookup()

◆ secfile_from_input_file()

static struct section_file* secfile_from_input_file ( struct inputfile inf,
const QString &  filename,
const QString &  section,
bool  allow_duplicates 
)
static

Base function to load a section file.

Note it closes the inputfile.

Definition at line 298 of file registry_ini.cpp.

Referenced by secfile_from_stream(), and secfile_load_section().

◆ secfile_from_stream()

struct section_file* secfile_from_stream ( QIODevice *  stream,
bool  allow_duplicates 
)

Create a section file from a stream.

Returns nullptr on error.

Definition at line 585 of file registry_ini.cpp.

Referenced by netfile_get_section_file(), and parse_metaserver_data().

◆ secfile_hash_delete()

static bool secfile_hash_delete ( struct section_file secfile,
struct entry pentry 
)
static

Delete an entry from the hash table.

Returns TRUE on success.

Definition at line 279 of file registry_ini.cpp.

Referenced by entry_destroy(), and entry_set_name().

◆ secfile_hash_insert()

static bool secfile_hash_insert ( struct section_file secfile,
struct entry pentry 
)
static

Insert an entry into the hash table.

Returns TRUE on success.

Definition at line 249 of file registry_ini.cpp.

Referenced by entry_new(), entry_set_name(), and secfile_from_input_file().

◆ secfile_insert_base()

static struct section* secfile_insert_base ( struct section_file secfile,
const char *  path,
const char **  pent_name 
)
static

◆ secfile_insert_bitwise_enum_full()

struct entry* secfile_insert_bitwise_enum_full ( struct section_file secfile,
int  bitwise_val,
secfile_enum_name_fn_t  name_fn,
secfile_enum_iter_fn_t  begin_fn,
secfile_enum_iter_fn_t  end_fn,
secfile_enum_next_fn_t  next_fn,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert a bitwise value entry.

Definition at line 1486 of file registry_ini.cpp.

Referenced by secfile_insert_bitwise_enum_vec_full().

◆ secfile_insert_bitwise_enum_vec_full()

size_t secfile_insert_bitwise_enum_vec_full ( struct section_file secfile,
const int *  bitwise_vals,
size_t  dim,
secfile_enum_name_fn_t  name_fn,
secfile_enum_iter_fn_t  begin_fn,
secfile_enum_iter_fn_t  end_fn,
secfile_enum_next_fn_t  next_fn,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert 'dim' string entries at 'path,0', 'path,1' etc.

Returns the number of entries inserted or replaced.

Definition at line 1557 of file registry_ini.cpp.

◆ secfile_insert_bool_full()

struct entry* secfile_insert_bool_full ( struct section_file secfile,
bool  value,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert a boolean entry.

Definition at line 931 of file registry_ini.cpp.

Referenced by secfile_insert_bool_vec_full().

◆ secfile_insert_bool_vec_full()

size_t secfile_insert_bool_vec_full ( struct section_file secfile,
const bool *  values,
size_t  dim,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert 'dim' boolean entries at 'path,0', 'path,1' etc.

Returns the number of entries inserted or replaced.

Definition at line 982 of file registry_ini.cpp.

◆ secfile_insert_enum_data_full()

struct entry* secfile_insert_enum_data_full ( struct section_file secfile,
int  value,
bool  bitwise,
secfile_enum_name_data_fn_t  name_fn,
secfile_data_t  data,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert an enumerator value entry that we only have a name accessor function.

Definition at line 1603 of file registry_ini.cpp.

Referenced by secfile_insert_enum_vec_data_full().

◆ secfile_insert_enum_vec_data_full()

size_t secfile_insert_enum_vec_data_full ( struct section_file secfile,
const int *  values,
size_t  dim,
bool  bitwise,
secfile_enum_name_data_fn_t  name_fn,
secfile_data_t  data,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert 'dim' entries at 'path,0', 'path,1' etc.

Returns the number of entries inserted or replaced.

Definition at line 1678 of file registry_ini.cpp.

◆ secfile_insert_filereference()

struct entry* secfile_insert_filereference ( struct section_file secfile,
const char *  filename,
const char *  path,
  ... 
)

Insert a read-from-a-file string entry.

Definition at line 1351 of file registry_ini.cpp.

Referenced by save_game_ruleset().

◆ secfile_insert_float_full()

struct entry* secfile_insert_float_full ( struct section_file secfile,
float  value,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert a floating entry.

Definition at line 1109 of file registry_ini.cpp.

◆ secfile_insert_include()

struct section* secfile_insert_include ( struct section_file secfile,
const char *  filename 
)

Insert a include entry.

Definition at line 1159 of file registry_ini.cpp.

Referenced by save_nations_ruleset().

◆ secfile_insert_int_full()

struct entry* secfile_insert_int_full ( struct section_file secfile,
int  value,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert a integer entry.

Definition at line 1020 of file registry_ini.cpp.

Referenced by secfile_insert_int_vec_full().

◆ secfile_insert_int_vec_full()

size_t secfile_insert_int_vec_full ( struct section_file secfile,
const int *  values,
size_t  dim,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert 'dim' integer entries at 'path,0', 'path,1' etc.

Returns the number of entries inserted or replaced.

Definition at line 1071 of file registry_ini.cpp.

◆ secfile_insert_long_comment()

struct section* secfile_insert_long_comment ( struct section_file secfile,
const char *  comment 
)

Insert a long comment entry.

Definition at line 1184 of file registry_ini.cpp.

Referenced by comment_write().

◆ secfile_insert_plain_enum_full()

struct entry* secfile_insert_plain_enum_full ( struct section_file secfile,
int  enumerator,
secfile_enum_name_fn_t  name_fn,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert a enumerator entry.

Definition at line 1387 of file registry_ini.cpp.

Referenced by secfile_insert_plain_enum_vec_full().

◆ secfile_insert_plain_enum_vec_full()

size_t secfile_insert_plain_enum_vec_full ( struct section_file secfile,
const int *  enumurators,
size_t  dim,
secfile_enum_name_fn_t  name_fn,
const char *  comment,
bool  allow_replace,
const char *  path,
  ... 
)

Insert 'dim' string entries at 'path,0', 'path,1' etc.

Returns the number of entries inserted or replaced.

Definition at line 1444 of file registry_ini.cpp.

◆ secfile_insert_str_full()

struct entry* secfile_insert_str_full ( struct section_file secfile,
const char *  str,
const char *  comment,
bool  allow_replace,
bool  no_escape,
enum entry_special_type  stype,
const char *  path,
  ... 
)

Insert a string entry.

Definition at line 1210 of file registry_ini.cpp.

Referenced by secfile_insert_include(), secfile_insert_long_comment(), and secfile_insert_str_vec_full().

◆ secfile_insert_str_vec_full() [1/2]

size_t secfile_insert_str_vec_full ( struct section_file secfile,
const char *const *  strings,
size_t  dim,
const char *  comment,
bool  allow_replace,
bool  no_escape,
const char *  path,
  ... 
)

Insert 'dim' string entries at 'path,0', 'path,1' etc.

Returns the number of entries inserted or replaced.

Definition at line 1271 of file registry_ini.cpp.

◆ secfile_insert_str_vec_full() [2/2]

size_t secfile_insert_str_vec_full ( struct section_file secfile,
const QVector< QString > &  strings,
size_t  dim,
const char *  comment,
bool  allow_replace,
bool  no_escape,
const char *  path,
  ... 
)

Insert up to 'dim' string entries at 'path,0', 'path,1' etc.

Returns the number of entries inserted or replaced.

Definition at line 1311 of file registry_ini.cpp.

◆ secfile_load_section()

struct section_file* secfile_load_section ( const QString &  filename,
const QString &  section,
bool  allow_duplicates 
)

Create a section file from a file, read only one particular section.

Returns nullptr on error.

Definition at line 573 of file registry_ini.cpp.

Referenced by secfile_load(), show_scenarios(), page_load::slot_selection_changed(), and page_scenario::update_scenarios_page().

◆ secfile_lookup_bitwise_enum_default_full()

int secfile_lookup_bitwise_enum_default_full ( const struct section_file secfile,
int  defval,
secfile_enum_is_valid_fn_t  is_valid_fn,
secfile_enum_by_name_fn_t  by_name_fn,
const char *  path,
  ... 
)

Lookup an enumerator value in the secfile.

Returns 'defval' on error.

Definition at line 2330 of file registry_ini.cpp.

◆ secfile_lookup_bitwise_enum_full()

bool secfile_lookup_bitwise_enum_full ( const struct section_file secfile,
int *  penumerator,
secfile_enum_is_valid_fn_t  is_valid_fn,
secfile_enum_by_name_fn_t  by_name_fn,
const char *  path,
  ... 
)

Lookup a bitwise enumerator value in the secfile.

Returns FALSE on error.

Definition at line 2263 of file registry_ini.cpp.

Referenced by secfile_lookup_bitwise_enum_vec_full().

◆ secfile_lookup_bitwise_enum_vec_full()

int* secfile_lookup_bitwise_enum_vec_full ( const struct section_file secfile,
size_t *  dim,
secfile_enum_is_valid_fn_t  is_valid_fn,
secfile_enum_by_name_fn_t  by_name_fn,
const char *  path,
  ... 
)

Lookup a enumerator vector in the secfile.

Returns nullptr on error. This vector is not owned by the registry module, and should be free by the user.

Definition at line 2393 of file registry_ini.cpp.

◆ secfile_lookup_bool()

bool secfile_lookup_bool ( const struct section_file secfile,
bool *  bval,
const char *  path,
  ... 
)

◆ secfile_lookup_bool_default()

◆ secfile_lookup_enum_data()

bool secfile_lookup_enum_data ( const struct section_file secfile,
int *  pvalue,
bool  bitwise,
secfile_enum_name_data_fn_t  name_fn,
secfile_data_t  data,
const char *  path,
  ... 
)

Lookup a value saved as string in the secfile.

Returns FALSE on error.

Definition at line 2449 of file registry_ini.cpp.

Referenced by client_option_load(), compat_load_020500(), setting_ruleset_one(), and settings_game_load().

◆ secfile_lookup_enum_default_data()

int secfile_lookup_enum_default_data ( const struct section_file secfile,
int  defval,
bool  bitwise,
secfile_enum_name_data_fn_t  name_fn,
secfile_data_t  data,
const char *  path,
  ... 
)

Lookup a value saved as string in the secfile.

Returns 'defval' on error.

Definition at line 2531 of file registry_ini.cpp.

Referenced by settings_game_load().

◆ secfile_lookup_int()

◆ secfile_lookup_int_def_min_max()

int secfile_lookup_int_def_min_max ( const struct section_file secfile,
int  defval,
int  minval,
int  maxval,
const char *  path,
  ... 
)

Lookup a integer value in the secfile.

The value will be arranged to match the interval [minval, maxval]. On failure, use the default value.

Definition at line 1917 of file registry_ini.cpp.

Referenced by load_ruleset_game(), and tileset_read_toplevel().

◆ secfile_lookup_int_default()

◆ secfile_lookup_int_vec()

int* secfile_lookup_int_vec ( const struct section_file secfile,
size_t *  dim,
const char *  path,
  ... 
)

Lookup a integer vector in the secfile.

Returns nullptr on error. This vector is not owned by the registry module, and should be free by the user.

Definition at line 1964 of file registry_ini.cpp.

Referenced by load_ruleset_game(), load_ruleset_veteran(), and sg_load_researches().

◆ secfile_lookup_plain_enum_default_full()

int secfile_lookup_plain_enum_default_full ( const struct section_file secfile,
int  defval,
secfile_enum_is_valid_fn_t  is_valid_fn,
secfile_enum_by_name_fn_t  by_name_fn,
const char *  path,
  ... 
)

Lookup an enumerator value in the secfile.

Returns 'defval' on error.

Definition at line 2166 of file registry_ini.cpp.

◆ secfile_lookup_plain_enum_full()

bool secfile_lookup_plain_enum_full ( const struct section_file secfile,
int *  penumerator,
secfile_enum_is_valid_fn_t  is_valid_fn,
secfile_enum_by_name_fn_t  by_name_fn,
const char *  path,
  ... 
)

Lookup an enumerator value in the secfile.

Returns FALSE on error.

Definition at line 2122 of file registry_ini.cpp.

Referenced by secfile_lookup_plain_enum_vec_full().

◆ secfile_lookup_plain_enum_vec_full()

int* secfile_lookup_plain_enum_vec_full ( const struct section_file secfile,
size_t *  dim,
secfile_enum_is_valid_fn_t  is_valid_fn,
secfile_enum_by_name_fn_t  by_name_fn,
const char *  path,
  ... 
)

Lookup a enumerator vector in the secfile.

Returns nullptr on error. This vector is not owned by the registry module, and should be free by the user.

Definition at line 2208 of file registry_ini.cpp.

◆ secfile_lookup_str()

const char* secfile_lookup_str ( const struct section_file secfile,
const char *  path,
  ... 
)

◆ secfile_lookup_str_default()

◆ secfile_lookup_str_vec()

const char** secfile_lookup_str_vec ( const struct section_file secfile,
size_t *  dim,
const char *  path,
  ... 
)

Lookup a string vector in the secfile.

Returns nullptr on error. This vector is not owned by the registry module, and should be free by the user, but the string pointers stored inside the vector shouldn't be free.

Definition at line 2074 of file registry_ini.cpp.

Referenced by boot_help_texts(), load_city_name_list(), load_ruleset_buildings(), load_ruleset_game(), load_ruleset_nations(), load_ruleset_techs(), load_ruleset_terrain(), load_ruleset_units(), load_ruleset_veteran(), lookup_building_list(), lookup_strvec(), lookup_tech_list(), lookup_unit_list(), scan_specfile(), sg_load_player_main(), sg_load_savefile(), and tileset_read_toplevel().

◆ secfile_name()

const char* secfile_name ( const struct section_file secfile)

◆ secfile_save()

bool secfile_save ( const struct section_file secfile,
QString  filename 
)

Save the previously filled in section_file to disk.

There is now limited ability to save in the new tabular format (to give smaller savefiles). The start of a table is detected by an entry with name of the form: (alphabetical_component)(zero)(period)(alphanumeric_component) Eg: u0.id, or c0.id, in the freeciv savefile. The alphabetical component is taken as the "name" of the table, and the component after the period as the first column name. This should be followed by the other column values for u0, and then subsequent u1, u2, etc, in strict order with no omissions, and with all of the columns for all uN in the same order as for u0.

Definition at line 614 of file registry_ini.cpp.

Referenced by options_save(), save_luadata(), save_ruleset_file(), save_thread_run(), and send_client_wants_hack().

◆ secfile_section_by_name()

struct section* secfile_section_by_name ( const struct section_file secfile,
const QString &  name 
)

◆ secfile_section_lookup()

struct section* secfile_section_lookup ( const struct section_file secfile,
const char *  path,
  ... 
)

◆ secfile_section_new()

struct section* secfile_section_new ( struct section_file secfile,
const QString &  name 
)

Create a new section in the secfile.

Definition at line 2694 of file registry_ini.cpp.

Referenced by secfile_from_input_file(), secfile_insert_base(), secfile_insert_include(), and secfile_insert_long_comment().

◆ secfile_sections()

const struct section_list* secfile_sections ( const struct section_file secfile)

Returns the list of sections.

This list is owned by the registry module and shouldn't be modified and destroyed.

Definition at line 2652 of file registry_ini.cpp.

Referenced by secfile_check_unused().

◆ secfile_sections_by_name_prefix()

struct section_list* secfile_sections_by_name_prefix ( const struct section_file secfile,
const char *  prefix 
)

Returns the list of sections which match the name prefix.

Returns nullptr if no section was found. This list is not owned by the registry module and the user must destroy it when he finished to work with it.

Definition at line 2663 of file registry_ini.cpp.

Referenced by boot_help_texts(), load_building_names(), load_game_names(), load_government_names(), load_nation_names(), load_ruleset_buildings(), load_ruleset_cities(), load_ruleset_effects(), load_ruleset_game(), load_ruleset_governments(), load_ruleset_nations(), load_ruleset_styles(), load_ruleset_techs(), load_ruleset_units(), load_style_names(), load_tech_names(), load_terrain_names(), load_unit_names(), scan_specfile(), tileset_read_toplevel(), and tileset_setup_options().

◆ section_clear_all()

void section_clear_all ( struct section psection)

Remove all entries.

Definition at line 2766 of file registry_ini.cpp.

Referenced by section_destroy().

◆ section_destroy()

void section_destroy ( struct section psection)

Remove this section from the secfile.

Definition at line 2739 of file registry_ini.cpp.

Referenced by secfile_new().

◆ section_entries()

const struct entry_list* section_entries ( const struct section psection)

Returns a list containing all the entries.

This list is owned by the secfile, so don't modify or destroy it.

Definition at line 2784 of file registry_ini.cpp.

Referenced by compat_load_020400(), fcdb_load_config(), options_dialogs_load(), secfile_check_unused(), secfile_from_input_file(), secfile_save(), and settable_options_load().

◆ section_entry_bool_new()

struct entry* section_entry_bool_new ( struct section psection,
const QString &  name,
bool  value 
)

Returns a new entry of type ENTRY_BOOL.

Definition at line 2876 of file registry_ini.cpp.

Referenced by entry_from_token(), and secfile_insert_bool_full().

◆ section_entry_by_name()

struct entry* section_entry_by_name ( const struct section psection,
const QString &  name 
)

◆ section_entry_filereference_new()

static struct entry * section_entry_filereference_new ( struct section psection,
const char *  name,
const char *  value 
)
static

Returns a new entry of type ENTRY_FILEREFERENCE.

Definition at line 2929 of file registry_ini.cpp.

Referenced by secfile_insert_filereference().

◆ section_entry_float_new()

struct entry* section_entry_float_new ( struct section psection,
const QString &  name,
float  value 
)

Returns a new entry of type ENTRY_FLOAT.

Definition at line 2892 of file registry_ini.cpp.

Referenced by entry_from_token(), and secfile_insert_float_full().

◆ section_entry_int_new()

struct entry* section_entry_int_new ( struct section psection,
const QString &  name,
int  value 
)

Returns a new entry of type ENTRY_INT.

Definition at line 2860 of file registry_ini.cpp.

Referenced by entry_from_token(), and secfile_insert_int_full().

◆ section_entry_str_new()

struct entry* section_entry_str_new ( struct section psection,
const QString &  name,
const QString &  value,
bool  escaped 
)