Freeciv21
Develop your civilization from humble roots to a global empire
comments.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 // utility
15 #include "log.h"
16 #include "registry.h"
17 #include "registry_ini.h"
18 #include "section_file.h"
19 #include "shared.h"
20 
21 #include "comments.h"
22 
23 static struct {
24  char *file_header;
25  char *buildings;
26  char *tech_classes;
27  char *techs;
28  char *govs;
29  char *policies;
30  char *uclasses;
31  char *utypes;
32  char *terrains;
33  char *resources;
34  char *extras;
35  char *bases;
36  char *roads;
37  char *styles;
38  char *citystyles;
39  char *musicstyles;
40  char *effects;
41  char *disasters;
42  char *achievements;
43  char *goods;
44  char *enablers;
45  char *specialists;
46  char *nations;
47  char *nationgroups;
48  char *nationsets;
49  char *clauses;
51 
56 {
57  struct section_file *comment_file;
58  QString fullpath;
59 
60  fullpath = fileinfoname(get_data_dirs(), "ruledit/" COMMENTS_FILE_NAME);
61 
62  if (fullpath.isEmpty()) {
63  return false;
64  }
65 
66  comment_file = secfile_load(fullpath, false);
67  if (comment_file == nullptr) {
68  return false;
69  }
70 
71 #define comment_load(target, comment_file, comment_path) \
72  { \
73  const char *comment; \
74  \
75  if ((comment = secfile_lookup_str(comment_file, comment_path))) { \
76  target = fc_strdup(comment); \
77  } else { \
78  secfile_destroy(comment_file); \
79  return false; \
80  } \
81  }
82 
83  comment_load(comments_storage.file_header, comment_file, "common.header");
84  comment_load(comments_storage.buildings, comment_file,
85  "typedoc.buildings");
86  comment_load(comments_storage.tech_classes, comment_file,
87  "typedoc.tech_classes");
88  comment_load(comments_storage.techs, comment_file, "typedoc.techs");
89  comment_load(comments_storage.govs, comment_file, "typedoc.governments");
90  comment_load(comments_storage.policies, comment_file, "typedoc.policies");
91  comment_load(comments_storage.uclasses, comment_file, "typedoc.uclasses");
92  comment_load(comments_storage.utypes, comment_file, "typedoc.utypes");
93  comment_load(comments_storage.terrains, comment_file, "typedoc.terrains");
94  comment_load(comments_storage.resources, comment_file,
95  "typedoc.resources");
96  comment_load(comments_storage.extras, comment_file, "typedoc.extras");
97  comment_load(comments_storage.bases, comment_file, "typedoc.bases");
98  comment_load(comments_storage.roads, comment_file, "typedoc.roads");
99  comment_load(comments_storage.styles, comment_file, "typedoc.styles");
100  comment_load(comments_storage.citystyles, comment_file,
101  "typedoc.citystyles");
102  comment_load(comments_storage.musicstyles, comment_file,
103  "typedoc.musicstyles");
104  comment_load(comments_storage.effects, comment_file, "typedoc.effects");
105  comment_load(comments_storage.disasters, comment_file,
106  "typedoc.disasters");
107  comment_load(comments_storage.achievements, comment_file,
108  "typedoc.achievements");
109  comment_load(comments_storage.goods, comment_file, "typedoc.goods");
110  comment_load(comments_storage.enablers, comment_file, "typedoc.enablers");
111  comment_load(comments_storage.specialists, comment_file,
112  "typedoc.specialists");
113  comment_load(comments_storage.nations, comment_file, "typedoc.nations");
114  comment_load(comments_storage.nationgroups, comment_file,
115  "typedoc.nationgroups");
116  comment_load(comments_storage.nationsets, comment_file,
117  "typedoc.nationsets");
118  comment_load(comments_storage.clauses, comment_file, "typedoc.clauses");
119 
120  secfile_check_unused(comment_file);
121  secfile_destroy(comment_file);
122 
123  return true;
124 }
125 
129 void comments_free() { free(comments_storage.file_header); }
130 
134 static void comment_write(struct section_file *sfile, const char *comment,
135  const char *name)
136 {
137  if (comment == nullptr) {
138  qCritical("Comment for %s missing.", name);
139  return;
140  }
141 
142  secfile_insert_long_comment(sfile, comment);
143 }
144 
149 {
150  comment_write(sfile, comments_storage.file_header, "File header");
151 }
152 
156 void comment_buildings(struct section_file *sfile)
157 {
158  comment_write(sfile, comments_storage.buildings, "Buildings");
159 }
160 
165 {
166  comment_write(sfile, comments_storage.tech_classes, "Tech Classes");
167 }
168 
172 void comment_techs(struct section_file *sfile)
173 {
174  comment_write(sfile, comments_storage.techs, "Techs");
175 }
176 
180 void comment_govs(struct section_file *sfile)
181 {
182  comment_write(sfile, comments_storage.govs, "Governments");
183 }
184 
188 void comment_policies(struct section_file *sfile)
189 {
190  comment_write(sfile, comments_storage.policies, "Policies");
191 }
192 
196 void comment_uclasses(struct section_file *sfile)
197 {
198  comment_write(sfile, comments_storage.uclasses, "Unit classes");
199 }
200 
204 void comment_utypes(struct section_file *sfile)
205 {
206  comment_write(sfile, comments_storage.utypes, "Unit types");
207 }
208 
212 void comment_terrains(struct section_file *sfile)
213 {
214  comment_write(sfile, comments_storage.terrains, "Terrains");
215 }
216 
220 void comment_resources(struct section_file *sfile)
221 {
222  comment_write(sfile, comments_storage.resources, "Resources");
223 }
224 
228 void comment_extras(struct section_file *sfile)
229 {
230  comment_write(sfile, comments_storage.extras, "Extras");
231 }
232 
236 void comment_bases(struct section_file *sfile)
237 {
238  comment_write(sfile, comments_storage.bases, "Bases");
239 }
240 
244 void comment_roads(struct section_file *sfile)
245 {
246  comment_write(sfile, comments_storage.roads, "Roads");
247 }
248 
252 void comment_styles(struct section_file *sfile)
253 {
254  comment_write(sfile, comments_storage.styles, "Styles");
255 }
256 
260 void comment_citystyles(struct section_file *sfile)
261 {
262  comment_write(sfile, comments_storage.citystyles, "City Styles");
263 }
264 
269 {
270  comment_write(sfile, comments_storage.musicstyles, "Music Styles");
271 }
272 
276 void comment_effects(struct section_file *sfile)
277 {
278  comment_write(sfile, comments_storage.effects, "Effects");
279 }
280 
284 void comment_disasters(struct section_file *sfile)
285 {
286  comment_write(sfile, comments_storage.disasters, "Disasters");
287 }
288 
293 {
294  comment_write(sfile, comments_storage.achievements, "Achievements");
295 }
296 
300 void comment_goods(struct section_file *sfile)
301 {
302  comment_write(sfile, comments_storage.goods, "Goods");
303 }
304 
308 void comment_enablers(struct section_file *sfile)
309 {
310  comment_write(sfile, comments_storage.enablers, "Action Enablers");
311 }
312 
317 {
318  comment_write(sfile, comments_storage.specialists, "Specialists");
319 }
320 
324 void comment_nations(struct section_file *sfile)
325 {
326  comment_write(sfile, comments_storage.nations, "Nations");
327 }
328 
333 {
334  comment_write(sfile, comments_storage.nationgroups, "Nationgroups");
335 }
336 
340 void comment_nationsets(struct section_file *sfile)
341 {
342  comment_write(sfile, comments_storage.nationsets, "Nationsets");
343 }
344 
348 void comment_clauses(struct section_file *sfile)
349 {
350  comment_write(sfile, comments_storage.clauses, "Clauses");
351 }
static struct @160 comments_storage
char * nationgroups
Definition: comments.cpp:47
bool comments_load()
Load comments to add to the saved rulesets.
Definition: comments.cpp:55
char * resources
Definition: comments.cpp:33
void comments_free()
Free comments.
Definition: comments.cpp:129
void comment_roads(struct section_file *sfile)
Write roads header.
Definition: comments.cpp:244
void comment_uclasses(struct section_file *sfile)
Write unit classes header.
Definition: comments.cpp:196
char * goods
Definition: comments.cpp:43
char * specialists
Definition: comments.cpp:45
char * achievements
Definition: comments.cpp:42
char * terrains
Definition: comments.cpp:32
char * styles
Definition: comments.cpp:37
void comment_citystyles(struct section_file *sfile)
Write city styles header.
Definition: comments.cpp:260
char * extras
Definition: comments.cpp:34
void comment_govs(struct section_file *sfile)
Write governments header.
Definition: comments.cpp:180
char * enablers
Definition: comments.cpp:44
void comment_bases(struct section_file *sfile)
Write bases header.
Definition: comments.cpp:236
void comment_terrains(struct section_file *sfile)
Write terrains header.
Definition: comments.cpp:212
char * file_header
Definition: comments.cpp:24
static void comment_write(struct section_file *sfile, const char *comment, const char *name)
Generic comment writing function with some error checking.
Definition: comments.cpp:134
void comment_file_header(struct section_file *sfile)
Write file header.
Definition: comments.cpp:148
char * policies
Definition: comments.cpp:29
void comment_effects(struct section_file *sfile)
Write effects header.
Definition: comments.cpp:276
char * effects
Definition: comments.cpp:40
void comment_disasters(struct section_file *sfile)
Write disasters header.
Definition: comments.cpp:284
void comment_clauses(struct section_file *sfile)
Write clauses header.
Definition: comments.cpp:348
void comment_goods(struct section_file *sfile)
Write goods header.
Definition: comments.cpp:300
void comment_extras(struct section_file *sfile)
Write extras header.
Definition: comments.cpp:228
char * utypes
Definition: comments.cpp:31
char * clauses
Definition: comments.cpp:49
char * nationsets
Definition: comments.cpp:48
void comment_techs(struct section_file *sfile)
Write techs header.
Definition: comments.cpp:172
void comment_nations(struct section_file *sfile)
Write nations header.
Definition: comments.cpp:324
char * disasters
Definition: comments.cpp:41
char * govs
Definition: comments.cpp:28
void comment_nationgroups(struct section_file *sfile)
Write nationgroups header.
Definition: comments.cpp:332
char * roads
Definition: comments.cpp:36
char * bases
Definition: comments.cpp:35
void comment_specialists(struct section_file *sfile)
Write specialists header.
Definition: comments.cpp:316
void comment_musicstyles(struct section_file *sfile)
Write music styles header.
Definition: comments.cpp:268
char * buildings
Definition: comments.cpp:25
void comment_resources(struct section_file *sfile)
Write resources header.
Definition: comments.cpp:220
void comment_tech_classes(struct section_file *sfile)
Write tech classess header.
Definition: comments.cpp:164
char * tech_classes
Definition: comments.cpp:26
char * nations
Definition: comments.cpp:46
void comment_utypes(struct section_file *sfile)
Write unit types header.
Definition: comments.cpp:204
#define comment_load(target, comment_file, comment_path)
char * musicstyles
Definition: comments.cpp:39
void comment_policies(struct section_file *sfile)
Write policies header.
Definition: comments.cpp:188
void comment_achievements(struct section_file *sfile)
Write achievements header.
Definition: comments.cpp:292
char * citystyles
Definition: comments.cpp:38
void comment_styles(struct section_file *sfile)
Write styles header.
Definition: comments.cpp:252
char * techs
Definition: comments.cpp:27
void comment_buildings(struct section_file *sfile)
Write buildings header.
Definition: comments.cpp:156
void comment_enablers(struct section_file *sfile)
Write action enablers header.
Definition: comments.cpp:308
void comment_nationsets(struct section_file *sfile)
Write nationsets header.
Definition: comments.cpp:340
char * uclasses
Definition: comments.cpp:30
#define COMMENTS_FILE_NAME
Definition: comments.h:16
const char * name
Definition: inputfile.cpp:118
struct section_file * secfile_load(const QString &filename, bool allow_duplicates)
Create a section file from a file.
Definition: registry.cpp:21
void secfile_destroy(struct section_file *secfile)
Free a section file.
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,...
struct section * secfile_insert_long_comment(struct section_file *secfile, const char *comment)
Insert a long comment entry.
const QStringList & get_data_dirs()
Returns a list of data directory paths, in the order in which they should be searched.
Definition: shared.cpp:533
QString fileinfoname(const QStringList &dirs, const QString &filename)
Returns a filename to access the specified file from a directory by searching all specified directori...
Definition: shared.cpp:661