Freeciv21
Develop your civilization from humble roots to a global empire
inputfile.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 
12 /**********************************************************************
13  A low-level object for reading a registry-format file.
14  See comments in inputfile.c
15 ***********************************************************************/
16 
17 #pragma once
18 
19 // utility
20 #include "support.h" // bool type and fc__attribute
21 
22 #include <QString>
23 
24 class QIODevice;
25 struct inputfile; // opaque
26 
27 using datafilename_fn_t = QString (*)(const QString &filename);
28 
29 struct inputfile *inf_from_file(const QString &filename,
31 struct inputfile *inf_from_stream(QIODevice *stream,
33 void inf_close(struct inputfile *inf);
34 bool inf_at_eof(struct inputfile *inf);
35 
45 };
46 #define INF_TOK_FIRST INF_TOK_SECTION_NAME
47 
48 QString inf_token(struct inputfile *inf, enum inf_token_type type);
49 int inf_discard_tokens(struct inputfile *inf, enum inf_token_type type);
50 
51 QString inf_log_str(struct inputfile *inf, const char *message, ...)
52  fc__attribute((__format__(__printf__, 2, 3)));
struct inputfile * inf_from_stream(QIODevice *stream, datafilename_fn_t datafn)
Open the stream, and return an allocated, initialized structure.
Definition: inputfile.cpp:225
inf_token_type
Definition: inputfile.h:36
@ INF_TOK_EOL
Definition: inputfile.h:39
@ INF_TOK_COMMA
Definition: inputfile.h:42
@ INF_TOK_TABLE_END
Definition: inputfile.h:41
@ INF_TOK_VALUE
Definition: inputfile.h:43
@ INF_TOK_TABLE_START
Definition: inputfile.h:40
@ INF_TOK_ENTRY_NAME
Definition: inputfile.h:38
@ INF_TOK_LAST
Definition: inputfile.h:44
@ INF_TOK_SECTION_NAME
Definition: inputfile.h:37
QString inf_token(struct inputfile *inf, enum inf_token_type type)
Returns token of given type from given inputfile.
Definition: inputfile.cpp:536
QString inf_log_str(struct inputfile *inf, const char *message,...) fc__attribute((__format__(__printf__
bool inf_at_eof(struct inputfile *inf)
Return TRUE if current pos is at end of file.
Definition: inputfile.cpp:323
void inf_close(struct inputfile *inf)
Close the file and free associated memory, included any partially recursed included files,...
Definition: inputfile.cpp:285
int inf_discard_tokens(struct inputfile *inf, enum inf_token_type type)
Read as many tokens of specified type as possible, discarding the results; returns number of such tok...
Definition: inputfile.cpp:563
QString(*)(const QString &filename) datafilename_fn_t
Definition: inputfile.h:27
struct inputfile * inf_from_file(const QString &filename, datafilename_fn_t datafn)
Open the file, and return an allocated, initialized structure.
Definition: inputfile.cpp:202
QTextStream * stream
Definition: inputfile.cpp:85
QString filename
Definition: inputfile.cpp:83
datafilename_fn_t datafn
Definition: inputfile.cpp:93
int fc__attribute((nonnull(1, 3)))