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");
1635 for (
i = 1;
i <
dim;
i++) {
1638 "%s,%d",
fullpath, (
int)
i) !=
nullptr) {
1650 const char *filename,
1651 const char *path, ...)
1671 log_error(
"Tried to insert normal entry to different kind of section");
1690 const char *path, ...)
1747 const char *path, ...)
1769 for (
i = 1;
i <
dim;
i++) {
1796 const char *path, ...)
1816 if (
'\0' ==
str[0]) {
1872 const char *path, ...)
1898 for (
i = 1;
i <
dim;
i++) {
1916 int value,
bool bitwise,
1921 const char *path, ...)
1939 if (
'\0' ==
str[0]) {
1995 const int *values,
size_t dim,
2001 const char *path, ...)
2023 for (
i = 1;
i <
dim;
i++) {
2086 const char *path, ...)
2112 const char *path, ...)
2130 const char *path, ...)
2156 bool def,
const char *path, ...)
2186 size_t *
dim,
const char *path, ...)
2213 for (
i = 0;
i < *
dim;
i++) {
2216 "An error occurred when looking up to \"%s,%d\" entry.",
2232 const char *path, ...)
2258 const char *path, ...)
2289 const char *path, ...)
2312 "\"%s\" should be in the interval [%d, %d] but is %d;"
2313 "using the minimal value.",
2320 "\"%s\" should be in the interval [%d, %d] but is %d;"
2321 "using the maximal value.",
2335 size_t *
dim,
const char *path, ...)
2363 for (
i = 0;
i < *
dim;
i++) {
2366 "An error occurred when looking up to \"%s,%d\" entry.",
2381 const char *path, ...)
2406 float def,
const char *path, ...)
2434 const char *path, ...)
2465 const char *path, ...)
2498 size_t *
dim,
const char *path, ...)
2525 for (
i = 0;
i < *
dim;
i++) {
2529 "An error occurred when looking up to \"%s,%d\" entry.",
2547 const char *path, ...)
2578 "Entry \"%s\": no match for \"%s\".",
2592 const char *path, ...)
2635 const char *path, ...)
2664 for (
i = 0;
i < *
dim;
i++) {
2669 "An error occurred when looking up to \"%s,%d\" entry.",
2687 const char *path, ...)
2691 const char *
str, *p;
2715 if (
'\0' ==
str[0]) {
2734 "Entry \"%s\": no match for \"%s\".",
2740 }
while (p !=
nullptr);
2754 const char *path, ...)
2758 const char *
str, *p;
2779 if (
'\0' ==
str[0]) {
2802 }
while (p !=
nullptr);
2818 const char *path, ...)
2847 for (
i = 0;
i < *
dim;
i++) {
2852 "An error occurred when looking up to \"%s,%d\" entry.",
2868 int *pvalue,
bool bitwise,
2898 if (
'\0' ==
str[0]) {
2914 for (val = 0; (
name =
name_fn(data, val)); val++) {
2919 if (
name ==
nullptr) {
2921 "Entry \"%s\": no match for \"%s\".",
2925 *pvalue |= 1 << val;
2927 }
while (p !=
nullptr);
2929 for (val = 0; (
name =
name_fn(data, val)); val++) {
2935 if (
name ==
nullptr) {
2937 "Entry \"%s\": no match for \"%s\".",
2950 int defval,
bool bitwise,
2953 const char *path, ...)
2980 if (
'\0' ==
str[0]) {
2996 for (val = 0; (
name =
name_fn(data, val)); val++) {
3001 if (
name ==
nullptr) {
3003 "Entry \"%s\": no match for \"%s\".",
3009 }
while (p !=
nullptr);
3011 for (val = 0; (
name =
name_fn(data, val)); val++) {
3017 if (
name ==
nullptr) {
3019 "Entry \"%s\": no match for \"%s\".",
3033 size_t *
dim,
bool bitwise,
3063 for (
i = 0;
i < *
dim;
i++) {
3067 "An error occurred when looking up to \"%s,%d\" entry.",
3100 const char *path, ...)
3121 return (secfile !=
nullptr ? secfile->
sections :
nullptr);
3191 if (
name ==
nullptr ||
'\0' ==
name[0]) {
3236 if ((secfile = psection->
secfile)) {
3264 "After clearing all, %d entries are still remaining.",
3281 if (
name ==
nullptr ||
'\0' ==
name[0]) {
3289 "\"%s\" is not a valid section name for section \"%s\".",
3334 return (psection !=
nullptr ? psection->
entries :
nullptr);
3359 const char *path, ...)
3397 if (
name ==
nullptr ||
'\0' ==
name[0]) {
3422 pentry->comment =
nullptr;
3548 if ((psection =
pentry->psection)) {
3581 if (
pentry->comment !=
nullptr) {
3592 return (
pentry !=
nullptr ?
pentry->psection :
nullptr);
3630 psection =
pentry->psection;
3635 if (
name ==
nullptr ||
'\0' ==
name[0]) {
3636 SECFILE_LOG(secfile, psection,
"No new name for entry \"%s\".",
3643 "\"%s\" is not a valid entry name for entry \"%s\".",
3674 return (
pentry !=
nullptr ?
pentry->comment :
nullptr);
3686 if (
pentry->comment !=
nullptr) {
3698 return (0 <
pentry->used);
3718 && (
pentry->integer.value == 0
3719 ||
pentry->integer.value == 1)
3720 &&
pentry->psection !=
nullptr
3721 &&
pentry->psection->secfile !=
nullptr
3722 &&
pentry->psection->secfile->allow_digital_boolean) {
3728 ?
pentry->psection->secfile :
nullptr,
3732 if (
value !=
nullptr) {
3761 if (
value !=
nullptr) {
3791 if (
value !=
nullptr) {
3820 if (
value !=
nullptr) {
3858 return pentry->string.escaped;
3885 if (
pentry->string.value[0] !=
'\0') {
3905 while (*
str !=
'\0' && dest < max) {
3919 static char buf[8192];
3920 char *
dot =
nullptr;
3932 for (
i = 0;
buf[
i] !=
'\0' ;
i++) {
3933 if (
buf[
i] ==
'.') {
3938 if (
dot ==
nullptr) {
3947 if (
pentry->string.escaped) {
3949 if (
pentry->string.gt_marking) {
3954 }
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_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,...)
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,...)
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_)