Freeciv-3.1: /fast/freeciv/nightly/S3_1/utility/section_file.h Source File

Freeciv-3.1

Loading...
Searching...
No Matches
section_file.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifndef FC__SECTION_FILE_H
14#define FC__SECTION_FILE_H
15
16/* This header contains internals of section_file that its users should
17 * not care about. This header should be included by source files implementing
18 * registry itself. */
19
20#ifdef __cplusplus
21extern "C" {
22#endif /* __cplusplus */
23
24/* utility */
25#include "support.h"
26
27/* Section structure. */
28 struct section {
29 struct section_file *secfile; /* Parent structure. */
30 enum entry_special_type special;
31 char *name; /* Name of the section. */
32 struct entry_list *entries; /* The list of the children. */
33};
34
35/* The section file struct itself. */
36 struct section_file {
37 char *name; /* Can be NULL. */
38 size_t num_entries;
39 /* num_includes should be size_t, but as there's no truly portable
40 * printf format for size_t and we need to construct string containing
41 * num_includes with fc_snprintf(), we set for unsigned int. */
42 unsigned int num_includes;
43 unsigned int num_long_comments;
44 struct section_list *sections;
45 bool allow_duplicates;
46 bool allow_digital_boolean;
47 struct {
48 struct section_hash *sections;
49 struct entry_hash *entries;
50 } hash;
51};
52
53 void secfile_log(const struct section_file *secfile,
54 const struct section *psection,
55 const char *file, const char *function, int line,
56 const char *format, ...)
57 fc__attribute((__format__(__printf__, 6, 7)));
58
59#define SECFILE_LOG(secfile, psection, format, ...) \
60 secfile_log(secfile, psection, __FILE__, __FUNCTION__, __FC_LINE__, \
61 format, ## __VA_ARGS__)
62#define SECFILE_RETURN_IF_FAIL(secfile, psection, condition) \
63 if (!(condition)) { \
64 SECFILE_LOG(secfile, psection, "Assertion '%s' failed.", #condition); \
65 return; \
66 }
67#define SECFILE_RETURN_VAL_IF_FAIL(secfile, psection, condition, value) \
68 if (!(condition)) { \
69 SECFILE_LOG(secfile, psection, "Assertion '%s' failed.", #condition); \
70 return value; \
71 }
72
73#define SPECHASH_TAG section
74#define SPECHASH_CSTR_KEY_TYPE
75#define SPECHASH_IDATA_TYPE struct section *
76#include "spechash.h"
77
78#define SPECHASH_TAG entry
79#define SPECHASH_ASTR_KEY_TYPE
80#define SPECHASH_IDATA_TYPE struct entry *
81#include "spechash.h"
82
83bool entry_from_token(struct section *psection, const char *name,
84 const char *tok);
85
86#ifdef __cplusplus
87}
88#endif /* __cplusplus */
89
90#endif /* FC__SECTION_FILE_H */
name
const char * name
Definition inputfile.c:127
entry_special_type
entry_special_type
Definition registry_ini.h:71
entry_from_token
bool entry_from_token(struct section *psection, const char *name, const char *tok)
Definition section_file.c:134
secfile_log
void secfile_log(const struct section_file *secfile, const struct section *psection, const char *file, const char *function, int line, const char *format,...) fc__attribute((__format__(__printf__
spechash.h
section_file
Definition section_file.h:36
section_file::entries
struct entry_hash * entries
Definition section_file.h:49
section_file::hash
struct section_file::@8 hash
section_file::name
char * name
Definition section_file.h:37
section_file::sections
struct section_list * sections
Definition section_file.h:44
section_file::allow_digital_boolean
bool allow_digital_boolean
Definition section_file.h:46
section_file::allow_duplicates
bool allow_duplicates
Definition section_file.h:45
section_file::sections
struct section_hash * sections
Definition section_file.h:48
section_file::num_includes
unsigned int num_includes
Definition section_file.h:42
section_file::num_long_comments
unsigned int num_long_comments
Definition section_file.h:43
section_file::num_entries
size_t num_entries
Definition section_file.h:38
section
Definition section_file.h:28
section::entries
struct entry_list * entries
Definition section_file.h:32
section::name
char * name
Definition section_file.h:31
section::special
enum entry_special_type special
Definition section_file.h:30
section::secfile
struct section_file * secfile
Definition section_file.h:29
support.h
fc__attribute
#define fc__attribute(x)
Definition support.h:89