add a 'unicode' property to modules (not yet supported by mingw, need to add a librar...
[reactos.git] / reactos / tools / rbuild / XML.h
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #ifndef XML_H
19 #define XML_H
20
21 #include "pch.h"
22
23 class XMLElement;
24
25 extern std::string working_directory;
26
27 void
28 InitWorkingDirectory();
29
30 #ifdef _MSC_VER
31 unsigned __int64
32 #else
33 unsigned long long
34 #endif
35 filelen ( FILE* f );
36
37 class Path
38 {
39 std::vector<std::string> path;
40 public:
41 Path(); // initializes path to getcwd();
42 Path ( const Path& cwd, const std::string& filename );
43 std::string Fixup ( const std::string& filename, bool include_filename ) const;
44
45 std::string RelativeFromWorkingDirectory ();
46 static std::string RelativeFromWorkingDirectory ( const std::string& path );
47 static std::string RelativeFromDirectory ( const std::string& path, const std::string& base_directory);
48
49 static void Split ( std::vector<std::string>& out,
50 const std::string& path,
51 bool include_last );
52 };
53
54 class XMLInclude
55 {
56 public:
57 XMLElement *e;
58 Path path;
59 std::string topIncludeFilename;
60 bool fileExists;
61
62 XMLInclude ( XMLElement* e_, const Path& path_, const std::string topIncludeFilename_ )
63 : e ( e_ ), path ( path_ ), topIncludeFilename ( topIncludeFilename_ )
64 {
65 }
66 };
67
68 class XMLIncludes : public std::vector<XMLInclude*>
69 {
70 public:
71 ~XMLIncludes();
72 };
73
74 class XMLFile
75 {
76 friend class XMLElement;
77 public:
78 XMLFile();
79 void close();
80 bool open(const std::string& filename);
81 void next_token();
82 bool next_is_text();
83 bool more_tokens();
84 bool get_token(std::string& token);
85 const std::string& filename() { return _filename; }
86 std::string Location() const;
87
88 private:
89 std::string _buf, _filename;
90
91 const char *_p, *_end;
92 };
93
94
95 class XMLAttribute
96 {
97 public:
98 std::string name;
99 std::string value;
100
101 XMLAttribute();
102 XMLAttribute ( const std::string& name_, const std::string& value_ );
103 XMLAttribute ( const XMLAttribute& );
104 XMLAttribute& operator = ( const XMLAttribute& );
105 };
106
107
108 class XMLElement
109 {
110 public:
111 XMLFile* xmlFile;
112 std::string location;
113 std::string name;
114 std::vector<XMLAttribute*> attributes;
115 XMLElement* parentElement;
116 std::vector<XMLElement*> subElements;
117 std::string value;
118
119 XMLElement ( XMLFile* xmlFile,
120 const std::string& location );
121 ~XMLElement();
122 bool Parse(const std::string& token,
123 bool& end_tag);
124 void AddSubElement ( XMLElement* e );
125 XMLAttribute* GetAttribute ( const std::string& attribute,
126 bool required);
127 const XMLAttribute* GetAttribute ( const std::string& attribute,
128 bool required) const;
129 };
130
131 XMLElement*
132 XMLLoadFile ( const std::string& filename,
133 const Path& path,
134 XMLIncludes& includes );
135
136 #endif // XML_H