]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/configparser.h
Add <config:format> to avoid breaking existing configuration files with XML entity...
[user/henk/code/inspircd.git] / include / configparser.h
1 struct fpos
2 {
3         std::string filename;
4         int line;
5         int col;
6         fpos(const std::string& name, int l = 1, int c = 1) : filename(name), line(l), col(c) {}
7         std::string str()
8         {
9                 return filename + ":" + ConvToStr(line) + ":" + ConvToStr(col);
10         }
11 };
12
13 enum ParseFlags
14 {
15         FLAG_USE_XML = 1,
16         FLAG_NO_EXEC = 2,
17         FLAG_NO_INC = 4
18 };
19
20 struct ParseStack
21 {
22         std::vector<std::string> reading;
23         std::map<std::string, std::string> vars;
24         ConfigDataHash& output;
25         std::stringstream& errstr;
26
27         ParseStack(ServerConfig* conf)
28                 : output(conf->config_data), errstr(conf->errstr)
29         {
30                 vars["amp"] = "&";
31                 vars["quot"] = "\"";
32                 vars["newline"] = vars["nl"] = "\n";
33         }
34         bool ParseFile(const std::string& name, int flags);
35         bool ParseExec(const std::string& name, int flags);
36         void DoInclude(ConfigTag* includeTag, int flags);
37 };
38
39 /** RAII wrapper on FILE* to close files on exceptions */
40 struct FileWrapper
41 {
42         FILE* const f;
43         FileWrapper(FILE* file) : f(file) {}
44         operator bool() { return f; }
45         operator FILE*() { return f; }
46         ~FileWrapper()
47         {
48                 if (f)
49                         fclose(f);
50         }
51 };
52
53