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