]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/configparser.h
Split up configreader.cpp, it's a bit large
[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_NO_EXEC = 1,
16         FLAG_NO_INC = 2
17 };
18
19 struct ParseStack
20 {
21         std::vector<std::string> reading;
22         std::map<std::string, std::string> vars;
23         ConfigDataHash& output;
24         std::stringstream& errstr;
25
26         ParseStack(ServerConfig* conf)
27                 : output(conf->config_data), errstr(conf->errstr)
28         {
29                 vars["amp"] = "&";
30                 vars["quot"] = "\"";
31                 vars["newline"] = vars["nl"] = "\n";
32         }
33         bool ParseFile(const std::string& name, int flags);
34         bool ParseExec(const std::string& name, int flags);
35         void DoInclude(ConfigTag* includeTag, int flags);
36 };
37
38 /** RAII wrapper on FILE* to close files on exceptions */
39 struct FileWrapper
40 {
41         FILE* const f;
42         FileWrapper(FILE* file) : f(file) {}
43         operator bool() { return f; }
44         operator FILE*() { return f; }
45         ~FileWrapper()
46         {
47                 if (f)
48                         fclose(f);
49         }
50 };
51
52