]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/configparser.h
Handle database not present a bit better, add missing MySQL rehash on init
[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         ConfigFileCache& FilesOutput;
26         std::stringstream& errstr;
27
28         ParseStack(ServerConfig* conf)
29                 : output(conf->config_data), FilesOutput(conf->Files), errstr(conf->errstr)
30         {
31                 vars["amp"] = "&";
32                 vars["quot"] = "\"";
33                 vars["newline"] = vars["nl"] = "\n";
34         }
35         bool ParseFile(const std::string& name, int flags);
36         bool ParseExec(const std::string& name, int flags);
37         void DoInclude(ConfigTag* includeTag, int flags);
38         void DoReadFile(const std::string& key, const std::string& file, int flags, bool exec);
39 };
40
41 /** RAII wrapper on FILE* to close files on exceptions */
42 struct FileWrapper
43 {
44         FILE* const f;
45         FileWrapper(FILE* file) : f(file) {}
46         operator bool() { return f; }
47         operator FILE*() { return f; }
48         ~FileWrapper()
49         {
50                 if (f)
51                         fclose(f);
52         }
53 };
54
55