Freeciv-3.1
Loading...
Searching...
No Matches
comments.c
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20#include "mem.h"
21#include "registry.h"
22#include "section_file.h"
23
24#include "comments.h"
25
26static struct {
28 char *buildings;
30 char *techs;
31 char *govs;
32 char *policies;
33 char *uclasses;
34 char *utypes;
35 char *terrains;
36 char *resources;
37 char *extras;
38 char *bases;
39 char *roads;
40 char *styles;
43 char *effects;
44 char *disasters;
47 char *goods;
48 char *enablers;
50 char *nations;
53 char *clauses;
54
55 /* Other section entries */
58
59/**********************************************************************/
62bool comments_load(void)
63{
64 struct section_file *comment_file;
65 const char *fullpath;
66
67 fullpath = fileinfoname(get_data_dirs(), "ruledit/" COMMENTS_FILE_NAME);
68
69 if (fullpath == NULL) {
70 log_error(_("Can't find the comments file"));
71 return FALSE;
72 }
73
74 comment_file = secfile_load(fullpath, FALSE);
75 if (comment_file == NULL) {
76 log_error(_("Can't parse the comments file"));
77 return FALSE;
78 }
79
80#define comment_load(target, comment_file, comment_path) \
81{ \
82 const char *comment; \
83 \
84 if ((comment = secfile_lookup_str(comment_file, comment_path))) { \
85 target = fc_strdup(comment); \
86 } else { \
87 log_error(_("Can't read %s from comments file"), comment_path); \
88 return FALSE; \
89 } \
90}
91
92 comment_load(comments_storage.file_header, comment_file, "common.header");
94 comment_file, "typedoc.buildings");
95 comment_load(comments_storage.tech_classes,
96 comment_file, "typedoc.tech_classes");
97 comment_load(comments_storage.techs, comment_file, "typedoc.techs");
98 comment_load(comments_storage.govs, comment_file, "typedoc.governments");
99 comment_load(comments_storage.policies, comment_file, "typedoc.policies");
100 comment_load(comments_storage.uclasses, comment_file, "typedoc.uclasses");
101 comment_load(comments_storage.utypes, comment_file, "typedoc.utypes");
102 comment_load(comments_storage.terrains, comment_file, "typedoc.terrains");
104 comment_file, "typedoc.resources");
105 comment_load(comments_storage.extras, comment_file, "typedoc.extras");
106 comment_load(comments_storage.bases, comment_file, "typedoc.bases");
107 comment_load(comments_storage.roads, comment_file, "typedoc.roads");
108 comment_load(comments_storage.styles, comment_file, "typedoc.styles");
110 comment_file, "typedoc.citystyles");
111 comment_load(comments_storage.musicstyles,
112 comment_file, "typedoc.musicstyles");
113 comment_load(comments_storage.effects, comment_file, "typedoc.effects");
115 comment_file, "typedoc.disasters");
116 comment_load(comments_storage.achievements,
117 comment_file, "typedoc.achievements");
118 comment_load(comments_storage.trade_settings,
119 comment_file, "typedoc.trade_settings");
120 comment_load(comments_storage.goods, comment_file, "typedoc.goods");
121 comment_load(comments_storage.enablers, comment_file, "typedoc.enablers");
122 comment_load(comments_storage.specialists,
123 comment_file, "typedoc.specialists");
124 comment_load(comments_storage.nations, comment_file, "typedoc.nations");
125 comment_load(comments_storage.nationgroups,
126 comment_file, "typedoc.nationgroups");
128 comment_file, "typedoc.nationsets");
129 comment_load(comments_storage.clauses, comment_file, "typedoc.clauses");
130
131 comment_load(comments_storage.nations_ruledit, comment_file,
132 "sectiondoc.nations_ruledit");
133
134 secfile_check_unused(comment_file);
135 secfile_destroy(comment_file);
136
137 return TRUE;
138}
139
140/**********************************************************************/
144{
145 free(comments_storage.file_header);
146}
147
148/**********************************************************************/
151static void comment_write(struct section_file *sfile, const char *comment,
152 const char *name)
153{
154 if (comment == NULL) {
155 log_error(_("Comment for %s missing."), name);
156 return;
157 }
158
159 secfile_insert_long_comment(sfile, comment);
160}
161
162/**********************************************************************/
166{
167 comment_write(sfile, comments_storage.file_header, "File header");
168}
169
170/**********************************************************************/
174{
175 comment_write(sfile, comments_storage.buildings, "Buildings");
176}
177
178/**********************************************************************/
182{
183 comment_write(sfile, comments_storage.tech_classes, "Tech Classes");
184}
185
186/**********************************************************************/
189void comment_techs(struct section_file *sfile)
190{
191 comment_write(sfile, comments_storage.techs, "Techs");
192}
193
194/**********************************************************************/
197void comment_govs(struct section_file *sfile)
198{
199 comment_write(sfile, comments_storage.govs, "Governments");
200}
201
202/**********************************************************************/
206{
207 comment_write(sfile, comments_storage.policies, "Policies");
208}
209
210/**********************************************************************/
214{
215 comment_write(sfile, comments_storage.uclasses, "Unit classes");
216}
217
218/**********************************************************************/
221void comment_utypes(struct section_file *sfile)
222{
223 comment_write(sfile, comments_storage.utypes, "Unit types");
224}
225
226/**********************************************************************/
230{
231 comment_write(sfile, comments_storage.terrains, "Terrains");
232}
233
234/**********************************************************************/
238{
239 comment_write(sfile, comments_storage.resources, "Resources");
240}
241
242/**********************************************************************/
245void comment_extras(struct section_file *sfile)
246{
247 comment_write(sfile, comments_storage.extras, "Extras");
248}
249
250/**********************************************************************/
253void comment_bases(struct section_file *sfile)
254{
255 comment_write(sfile, comments_storage.bases, "Bases");
256}
257
258/**********************************************************************/
261void comment_roads(struct section_file *sfile)
262{
263 comment_write(sfile, comments_storage.roads, "Roads");
264}
265
266/**********************************************************************/
269void comment_styles(struct section_file *sfile)
270{
271 comment_write(sfile, comments_storage.styles, "Styles");
272}
273
274/**********************************************************************/
278{
279 comment_write(sfile, comments_storage.citystyles, "City Styles");
280}
281
282/**********************************************************************/
286{
287 comment_write(sfile, comments_storage.musicstyles, "Music Styles");
288}
289
290/**********************************************************************/
293void comment_effects(struct section_file *sfile)
294{
295 comment_write(sfile, comments_storage.effects, "Effects");
296}
297
298/**********************************************************************/
302{
303 comment_write(sfile, comments_storage.disasters, "Disasters");
304}
305
306/**********************************************************************/
310{
311 comment_write(sfile, comments_storage.achievements, "Achievements");
312}
313
314/**********************************************************************/
318{
319 comment_write(sfile, comments_storage.trade_settings, "Trade settings");
320}
321
322/**********************************************************************/
325void comment_goods(struct section_file *sfile)
326{
327 comment_write(sfile, comments_storage.goods, "Goods");
328}
329
330/**********************************************************************/
334{
335 comment_write(sfile, comments_storage.enablers, "Action Enablers");
336}
337
338/**********************************************************************/
342{
343 comment_write(sfile, comments_storage.specialists, "Specialists");
344}
345
346/**********************************************************************/
349void comment_nations(struct section_file *sfile)
350{
351 comment_write(sfile, comments_storage.nations, "Nations");
352}
353
354/**********************************************************************/
358{
359 comment_write(sfile, comments_storage.nationgroups, "Nationgroups");
360}
361
362/**********************************************************************/
366{
367 comment_write(sfile, comments_storage.nationsets, "Nationsets");
368}
369
370/**********************************************************************/
373void comment_clauses(struct section_file *sfile)
374{
375 comment_write(sfile, comments_storage.clauses, "Clauses");
376}
377
378/**********************************************************************/
382{
383 comment_write(sfile, comments_storage.nations_ruledit, "Ruledit");
384}
void comments_free(void)
Definition comments.c:143
char * nationgroups
Definition comments.c:51
char * resources
Definition comments.c:36
char * nations_ruledit
Definition comments.c:56
void comment_roads(struct section_file *sfile)
Definition comments.c:261
void comment_uclasses(struct section_file *sfile)
Definition comments.c:213
char * goods
Definition comments.c:47
char * specialists
Definition comments.c:49
char * achievements
Definition comments.c:45
char * terrains
Definition comments.c:35
char * styles
Definition comments.c:40
void comment_citystyles(struct section_file *sfile)
Definition comments.c:277
char * extras
Definition comments.c:37
void comment_govs(struct section_file *sfile)
Definition comments.c:197
char * enablers
Definition comments.c:48
void comment_bases(struct section_file *sfile)
Definition comments.c:253
void comment_terrains(struct section_file *sfile)
Definition comments.c:229
char * file_header
Definition comments.c:27
static void comment_write(struct section_file *sfile, const char *comment, const char *name)
Definition comments.c:151
void comment_file_header(struct section_file *sfile)
Definition comments.c:165
char * policies
Definition comments.c:32
void comment_effects(struct section_file *sfile)
Definition comments.c:293
char * effects
Definition comments.c:43
void comment_disasters(struct section_file *sfile)
Definition comments.c:301
void comment_clauses(struct section_file *sfile)
Definition comments.c:373
void comment_goods(struct section_file *sfile)
Definition comments.c:325
void comment_extras(struct section_file *sfile)
Definition comments.c:245
char * utypes
Definition comments.c:34
static struct @272 comments_storage
char * clauses
Definition comments.c:53
char * nationsets
Definition comments.c:52
void comment_techs(struct section_file *sfile)
Definition comments.c:189
void comment_nations(struct section_file *sfile)
Definition comments.c:349
void comment_trade_settings(struct section_file *sfile)
Definition comments.c:317
char * disasters
Definition comments.c:44
void comment_nations_ruledit(struct section_file *sfile)
Definition comments.c:381
char * govs
Definition comments.c:31
void comment_nationgroups(struct section_file *sfile)
Definition comments.c:357
char * roads
Definition comments.c:39
char * bases
Definition comments.c:38
void comment_specialists(struct section_file *sfile)
Definition comments.c:341
void comment_musicstyles(struct section_file *sfile)
Definition comments.c:285
char * buildings
Definition comments.c:28
void comment_resources(struct section_file *sfile)
Definition comments.c:237
void comment_tech_classes(struct section_file *sfile)
Definition comments.c:181
char * tech_classes
Definition comments.c:29
char * nations
Definition comments.c:50
void comment_utypes(struct section_file *sfile)
Definition comments.c:221
#define comment_load(target, comment_file, comment_path)
bool comments_load(void)
Definition comments.c:62
char * musicstyles
Definition comments.c:42
void comment_policies(struct section_file *sfile)
Definition comments.c:205
void comment_achievements(struct section_file *sfile)
Definition comments.c:309
char * trade_settings
Definition comments.c:46
char * citystyles
Definition comments.c:41
void comment_styles(struct section_file *sfile)
Definition comments.c:269
char * techs
Definition comments.c:30
void comment_buildings(struct section_file *sfile)
Definition comments.c:173
void comment_enablers(struct section_file *sfile)
Definition comments.c:333
void comment_nationsets(struct section_file *sfile)
Definition comments.c:365
char * uclasses
Definition comments.c:33
#define COMMENTS_FILE_NAME
Definition comments.h:20
#define _(String)
Definition fcintl.h:67
const char * name
Definition inputfile.c:127
#define log_error(message,...)
Definition log.h:103
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:50
void secfile_destroy(struct section_file *secfile)
void secfile_check_unused(const struct section_file *secfile)
struct section * secfile_insert_long_comment(struct section_file *secfile, const char *comment)
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
const struct strvec * get_data_dirs(void)
Definition shared.c:886
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47