152#include <fc_config.h>
176#define MAX_LEN_SECPATH 1024
181#define MAX_LINE_LEN 72
184#define SAVE_TABLES TRUE
186#define SPECVEC_TAG astring
248 static const char *
const allowed =
"_.,-[]";
250 while (
'\0' != *
name) {
280 "Tried to insert same value twice: %s",
buf);
310 const char *filename,
315 struct section *psection =
nullptr;
336 secfile->
name =
nullptr;
342 log_verbose(
"Reading registry from \"%s\"", filename);
475 if (
tok[0] !=
'\"') {
485 for (j =
i + 1; j <
n_prev; j++) {
489 for (j =
n_prev; j <
i + 1; j++) {
542 "Finished registry before end of table");
642 return (
ch !=
'%' &&
ch !=
'.' &&
ch !=
',' &&
ch !=
'?'
643 &&
ch !=
'!' &&
ch !=
';' &&
ch !=
':' &&
ch !=
')');
831 if (
pentry->string.gt_marking) {
873 if (filename ==
nullptr) {
874 filename = secfile->
name;
927 char *c, *first,
base[64];
962 first[offset - 2] =
'\0';
964 first[offset - 2] =
'0';
1007 "an attempt to insert comment in the middle of table row.",
1030 "%s.%s (or the entries are out of order). This means\n"
1031 "a less efficient non-tabular format will be used.\n"
1032 "To avoid this make sure all rows of a table are\n"
1033 "filled out with an entry for every column.",
1140 SECFILE_LOG(secfile,
nullptr,
"Error before closing %s: %s",
1167 if (!any && secfile->
name) {
1173 secfile->
name !=
nullptr ? secfile->
name :
"nameless",
1176#ifdef FREECIV_TESTMATIC
1178 secfile->
name !=
nullptr ? secfile->
name :
"nameless",
1198 if (secfile ==
nullptr) {
1200 }
else if (secfile->
name) {
1201 return secfile->
name;
1203 return "(anonymous)";
1223 "Section and entry names must be separated by a dot.");
1244 const char *path, ...)
1293 const bool *values,
size_t dim,
1295 const char *path, ...)
1314 for (
i = 1;
i <
dim;
i++) {
1331 const char *path, ...)
1380 const int *values,
size_t dim,
1382 const char *path, ...)
1401 for (
i = 1;
i <
dim;
i++) {
1418 const char *path, ...)
1466 const char *filename)
1490 const char *comment)
1519 const char *path, ...)
1539 log_error(
"Tried to insert wrong type of entry to section");
1577 const char *path, ...)
1599 log_error(
"Tried to insert wrong type of entry to section");
1616 const char *path, ...)
1643 for (
i = 1;
i <
dim;
i++) {
1663 const char *filename,
1664 const char *path, ...)
1684 log_error(
"Tried to insert normal entry to different kind of section");
1703 const char *path, ...)
1760 const char *path, ...)
1782 for (
i = 1;
i <
dim;
i++) {
1809 const char *path, ...)
1829 if (
'\0' ==
str[0]) {
1885 const char *path, ...)
1911 for (
i = 1;
i <
dim;
i++) {
1929 int value,
bool bitwise,
1934 const char *path, ...)
1952 if (
'\0' ==
str[0]) {
2008 const int *values,
size_t dim,
2014 const char *path, ...)
2036 for (
i = 1;
i <
dim;
i++) {
2099 const char *path, ...)
2125 const char *path, ...)
2143 const char *path, ...)
2169 bool def,
const char *path, ...)
2199 size_t *
dim,
const char *path, ...)
2226 for (
i = 0;
i < *
dim;
i++) {
2229 "An error occurred when looking up to \"%s,%d\" entry.",
2245 const char *path, ...)
2271 const char *path, ...)
2302 const char *path, ...)
2325 "\"%s\" should be in the interval [%d, %d] but is %d;"
2326 "using the minimal value.",
2333 "\"%s\" should be in the interval [%d, %d] but is %d;"
2334 "using the maximal value.",
2348 size_t *
dim,
const char *path, ...)
2376 for (
i = 0;
i < *
dim;
i++) {
2379 "An error occurred when looking up to \"%s,%d\" entry.",
2394 const char *path, ...)
2419 float def,
const char *path, ...)
2447 const char *path, ...)
2478 const char *path, ...)
2511 size_t *
dim,
const char *path, ...)
2538 for (
i = 0;
i < *
dim;
i++) {
2542 "An error occurred when looking up to \"%s,%d\" entry.",
2560 const char *path, ...)
2591 "Entry \"%s\": no match for \"%s\".",
2605 const char *path, ...)
2648 const char *path, ...)
2677 for (
i = 0;
i < *
dim;
i++) {
2682 "An error occurred when looking up to \"%s,%d\" entry.",
2700 const char *path, ...)
2704 const char *
str, *p;
2728 if (
'\0' ==
str[0]) {
2747 "Entry \"%s\": no match for \"%s\".",
2753 }
while (p !=
nullptr);
2767 const char *path, ...)
2771 const char *
str, *p;
2792 if (
'\0' ==
str[0]) {
2815 }
while (p !=
nullptr);
2831 const char *path, ...)
2860 for (
i = 0;
i < *
dim;
i++) {
2865 "An error occurred when looking up to \"%s,%d\" entry.",
2881 int *pvalue,
bool bitwise,
2911 if (
'\0' ==
str[0]) {
2927 for (val = 0; (
name =
name_fn(data, val)); val++) {
2932 if (
name ==
nullptr) {
2934 "Entry \"%s\": no match for \"%s\".",
2938 *pvalue |= 1 << val;
2940 }
while (p !=
nullptr);
2942 for (val = 0; (
name =
name_fn(data, val)); val++) {
2948 if (
name ==
nullptr) {
2950 "Entry \"%s\": no match for \"%s\".",
2963 int defval,
bool bitwise,
2966 const char *path, ...)
2993 if (
'\0' ==
str[0]) {
3009 for (val = 0; (
name =
name_fn(data, val)); val++) {
3014 if (
name ==
nullptr) {
3016 "Entry \"%s\": no match for \"%s\".",
3022 }
while (p !=
nullptr);
3024 for (val = 0; (
name =
name_fn(data, val)); val++) {
3030 if (
name ==
nullptr) {
3032 "Entry \"%s\": no match for \"%s\".",
3046 size_t *
dim,
bool bitwise,
3076 for (
i = 0;
i < *
dim;
i++) {
3080 "An error occurred when looking up to \"%s,%d\" entry.",
3113 const char *path, ...)
3134 return (secfile !=
nullptr ? secfile->
sections :
nullptr);
3204 if (
name ==
nullptr ||
'\0' ==
name[0]) {
3249 if ((secfile = psection->
secfile)) {
3277 "After clearing all, %d entries are still remaining.",
3294 if (
name ==
nullptr ||
'\0' ==
name[0]) {
3302 "\"%s\" is not a valid section name for section \"%s\".",
3347 return (psection !=
nullptr ? psection->
entries :
nullptr);
3372 const char *path, ...)
3410 if (
name ==
nullptr ||
'\0' ==
name[0]) {
3435 pentry->comment =
nullptr;
3561 if ((psection =
pentry->psection)) {
3594 if (
pentry->comment !=
nullptr) {
3605 return (
pentry !=
nullptr ?
pentry->psection :
nullptr);
3643 psection =
pentry->psection;
3648 if (
name ==
nullptr ||
'\0' ==
name[0]) {
3649 SECFILE_LOG(secfile, psection,
"No new name for entry \"%s\".",
3656 "\"%s\" is not a valid entry name for entry \"%s\".",
3687 return (
pentry !=
nullptr ?
pentry->comment :
nullptr);
3699 if (
pentry->comment !=
nullptr) {
3711 return (0 <
pentry->used);
3731 && (
pentry->integer.value == 0
3732 ||
pentry->integer.value == 1)
3733 &&
pentry->psection !=
nullptr
3734 &&
pentry->psection->secfile !=
nullptr
3735 &&
pentry->psection->secfile->allow_digital_boolean) {
3741 ?
pentry->psection->secfile :
nullptr,
3745 if (
value !=
nullptr) {
3774 if (
value !=
nullptr) {
3804 if (
value !=
nullptr) {
3833 if (
value !=
nullptr) {
3871 return pentry->string.escaped;
3898 if (
pentry->string.value[0] !=
'\0') {
3918 while (*
str !=
'\0' && dest < max) {
3932 static char buf[8192];
3933 char *
dot =
nullptr;
3945 for (
i = 0;
buf[
i] !=
'\0' ;
i++) {
3946 if (
buf[
i] ==
'.') {
3951 if (
dot ==
nullptr) {
3960 if (
pentry->string.escaped) {
3962 if (
pentry->string.gt_marking) {
3967 }
else if (
pentry->string.raw) {
void astr_free(struct astring *astr)
void astr_set(struct astring *astr, const char *format,...)
void astr_init(struct astring *astr)
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
void bugreport_request(const char *reason_format,...)
struct canvas int int struct sprite int int int width
bool are_deprecation_warnings_enabled(void)
#define log_deprecation_always(message,...)
static void base(QVariant data1, QVariant data2)
int fz_fprintf(fz_FILE *fp, const char *format,...)
fz_FILE * fz_from_file(const char *filename, const char *in_mode, enum fz_method method, int compress_level)
const char * fz_strerror(fz_FILE *fp)
int fz_fclose(fz_FILE *fp)
int fz_ferror(fz_FILE *fp)
#define log_verbose(message,...)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_error(message,...)
#define log_testmatic(message,...)
#define fc_realloc(ptr, sz)
struct section_file * secfile_new(bool allow_duplicates)
const char * section_name(const struct section *psection)
void secfile_destroy(struct section_file *secfile)
static struct entry * entry_new(struct section *psection, const char *name)
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,...)
void entry_set_comment(struct entry *pentry, const char *comment)
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,...)
bool entry_bool_get(const struct entry *pentry, bool *value)
void section_destroy(struct section *psection)
bool secfile_lookup_float(const struct section_file *secfile, float *fval, const char *path,...)
void secfile_check_unused(const struct section_file *secfile)
int entry_path(const struct entry *pentry, char *buf, size_t buf_len)
bool secfile_lookup_int(const struct section_file *secfile, int *ival, const char *path,...)
struct section * secfile_insert_long_comment(struct section_file *secfile, const char *comment)
static struct entry * section_entry_filereference_new(struct section *psection, const char *name, const char *value)
static void make_escapes_quotes(const char *str, char *buf, size_t buf_len)
bool secfile_entry_delete(struct section_file *secfile, const char *path,...)
bool entry_set_name(struct entry *pentry, const char *name)
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,...)
static bool secfile_hash_insert(struct section_file *secfile, struct entry *pentry)
bool entry_str_escaped(const struct entry *pentry)
struct entry * section_entry_int_new(struct section *psection, const char *name, int value)
struct entry * secfile_insert_bool_full(struct section_file *secfile, bool value, const char *comment, bool allow_replace, const char *path,...)
struct entry * secfile_insert_comment(struct section_file *secfile, const char *str, const char *path,...)
struct entry * secfile_insert_int_full(struct section_file *secfile, int value, const char *comment, bool allow_replace, const char *path,...)
struct section * entry_section(const struct entry *pentry)
static struct entry * section_entry_comment_new(struct section *psection, const char *comment)
struct section_list * secfile_sections_by_name_prefix(const struct section_file *secfile, const char *prefix)
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,...)
const struct entry_list * section_entries(const struct section *psection)
struct section_file * secfile_load_section(const char *filename, const char *section, bool allow_duplicates)
bool entry_bool_set(struct entry *pentry, bool value)
struct section_file * secfile_from_stream(fz_FILE *stream, bool allow_duplicates)
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,...)
static void entry_to_file(const struct entry *pentry, fz_FILE *fs)
static void entry_from_inf_token(struct section *psection, const char *name, const char *tok, struct inputfile *file)
bool entry_float_get(const struct entry *pentry, float *value)
const char ** secfile_lookup_str_vec(const struct section_file *secfile, size_t *dim, const char *path,...)
bool entry_str_set_escaped(struct entry *pentry, bool escaped)
const char * entry_name(const struct entry *pentry)
struct entry * secfile_entry_lookup(const struct section_file *secfile, const char *path,...)
bool entry_str_get(const struct entry *pentry, const char **value)
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,...)
bool entry_str_set_gt_marking(struct entry *pentry, bool gt_marking)
bool secfile_save(const struct section_file *secfile, const char *filename, int compression_level, enum fz_method compression_method, bool do_formatting)
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,...)
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
void entry_destroy(struct entry *pentry)
static bool entry_used(const struct entry *pentry)
void section_clear_all(struct section *psection)
int * secfile_lookup_int_vec(const struct section_file *secfile, size_t *dim, const char *path,...)
bool entry_float_set(struct entry *pentry, float value)
float secfile_lookup_float_default(const struct section_file *secfile, float def, const char *path,...)
bool * secfile_lookup_bool_vec(const struct section_file *secfile, size_t *dim, const char *path,...)
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,...)
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,...)
struct entry * secfile_insert_float_full(struct section_file *secfile, float value, const char *comment, bool allow_replace, const char *path,...)
struct section * secfile_insert_include(struct section_file *secfile, const char *filename)
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,...)
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
bool entry_int_set(struct entry *pentry, int value)
static bool is_secfile_entry_name_valid(const char *name)
struct entry * section_entry_by_name(const struct section *psection, const char *name)
const struct section_list * secfile_sections(const struct section_file *secfile)
static bool is_delim(char ch)
static int word_wrap_internal(char *new_buf, int indent, bool is_counting)
struct entry * secfile_insert_filereference(struct section_file *secfile, const char *filename, const char *path,...)
bool section_set_name(struct section *psection, const char *name)
struct entry * section_entry_str_new(struct section *psection, const char *name, const char *value, bool escaped)
struct entry * section_entry_float_new(struct section *psection, const char *name, float value)
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
struct entry * section_entry_lookup(const struct section *psection, const char *path,...)
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, bool gt_marking, const char *path,...)
bool entry_int_get(const struct entry *pentry, int *value)
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,...)
static void entry_use(struct entry *pentry)
int * secfile_lookup_enum_vec_data(const struct section_file *secfile, size_t *dim, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *path,...)
struct entry * section_entry_bool_new(struct section *psection, const char *name, bool value)
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,...)
const char * secfile_name(const struct section_file *secfile)
struct section * secfile_section_new(struct section_file *secfile, const char *name)
const char * entry_comment(const struct entry *pentry)
static bool secfile_hash_delete(struct section_file *secfile, struct entry *pentry)
struct entry * secfile_entry_by_path(const struct section_file *secfile, const char *path)
static struct section_file * secfile_from_input_file(struct inputfile *inf, const char *filename, const char *section, bool allow_duplicates)
struct section * secfile_section_by_name(const struct section_file *secfile, const char *name)
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,...)
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,...)
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,...)
static size_t entry_str_length(struct entry *pentry)
struct section * secfile_section_lookup(const struct section_file *secfile, const char *path,...)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
bool secfile_section_prefix_present(const struct section_file *secfile, const char *prefix)
static bool is_legal_table_entry_name(char c, bool num)
bool entry_str_set(struct entry *pentry, const char *value)
static void format_entry_string(struct entry *pentry, int indent)
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,...)
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,...)
bool secfile_lookup_bool(const struct section_file *secfile, bool *bval, const char *path,...)
static const char * datafilename(const char *filename)
int secfile_lookup_int_def_min_max(const struct section_file *secfile, int defval, int minval, int maxval, const char *path,...)
static void find_next_delims(char *start_ptr, int *delim1_offset, int *delim2_offset)
static struct section * secfile_insert_base(struct section_file *secfile, const char *path, const char **pent_name)
enum entry_type entry_type_get(const struct entry *pentry)
int(* secfile_enum_iter_fn_t)(void)
const char *(* secfile_enum_name_data_fn_t)(secfile_data_t data, int enumerator)
#define section_list_iterate(seclist, psection)
#define entry_list_iterate_end
bool(* secfile_enum_is_valid_fn_t)(int enumerator)
const char *(* secfile_enum_name_fn_t)(int enumerator)
#define section_list_iterate_end
#define entry_list_iterate(entlist, pentry)
int(* secfile_enum_by_name_fn_t)(const char *enum_name, int(*strcmp_fn)(const char *, const char *))
int(* secfile_enum_next_fn_t)(int enumerator)
const void * secfile_data_t
bool entry_from_token(struct section *psection, const char *name, const char *tok)
#define SECFILE_LOG(secfile, psection, format,...)
#define SECFILE_RETURN_VAL_IF_FAIL(secfile, psection, condition, value)
#define SECFILE_RETURN_IF_FAIL(secfile, psection, condition)
const char * fileinfoname(const struct strvec *dirs, const char *filename)
void interpret_tilde(char *buf, size_t buf_size, const char *filename)
void remove_leading_trailing_spaces(char *s)
const struct strvec * get_data_dirs(void)
struct section * psection
struct entry_hash * entries
struct section_file::@8 hash
struct section_list * sections
unsigned int num_includes
unsigned int num_long_comments
struct entry_list * entries
enum entry_special_type special
struct section_file * secfile
int fc_snprintf(char *str, size_t n, const char *format,...)
size_t fc_strlcpy(char *dest, const char *src, size_t n)
int fc_strcasecmp(const char *str0, const char *str1)
int cat_snprintf(char *str, size_t n, const char *format,...)
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
#define sz_strlcpy(dest, src)
#define sz_strlcat(dest, src)
#define fc_strncmp(_s1_, _s2_, _len_)