parse, but ignore, <? ?> tags - eliminated duplicate code ala FixSeparator() - fix...
[reactos.git] / reactos / tools / rbuild / project.cpp
1
2 #include "pch.h"
3 #include <assert.h>
4
5 #include "rbuild.h"
6
7 using std::string;
8 using std::vector;
9
10 Project::Project()
11 {
12 }
13
14 Project::Project ( const string& filename )
15 {
16 if ( !xmlfile.open ( filename ) )
17 throw FileNotFoundException ( filename );
18 ReadXml();
19 }
20
21 Project::~Project ()
22 {
23 for ( size_t i = 0; i < modules.size (); i++ )
24 delete modules[i];
25 delete head;
26 }
27
28 void
29 Project::ReadXml ()
30 {
31 Path path;
32
33 do
34 {
35 head = XMLParse ( xmlfile, path );
36 if ( !head )
37 throw InvalidBuildFileException ( "Document contains no 'project' tag." );
38 } while ( head->name != "project" );
39
40 this->ProcessXML ( *head, "." );
41 }
42
43 void
44 Project::ProcessXML ( const XMLElement& e, const string& path )
45 {
46 const XMLAttribute *att;
47 string subpath(path);
48 if ( e.name == "project" )
49 {
50 att = e.GetAttribute ( "name", false );
51 if ( !att )
52 name = "Unnamed";
53 else
54 name = att->value;
55
56 att = e.GetAttribute ( "makefile", true );
57 assert(att);
58 makefile = att->value;
59 }
60 else if ( e.name == "module" )
61 {
62 att = e.GetAttribute ( "name", true );
63 assert(att);
64 Module* module = new Module ( this, e, att->value, path );
65 modules.push_back ( module );
66 module->ProcessXML ( e, path );
67 return;
68 }
69 else if ( e.name == "directory" )
70 {
71 const XMLAttribute* att = e.GetAttribute ( "name", true );
72 assert(att);
73 subpath = path + CSEP + att->value;
74 }
75 for ( size_t i = 0; i < e.subElements.size (); i++ )
76 ProcessXML ( *e.subElements[i], subpath );
77 }
78
79 Module*
80 Project::LocateModule ( string name )
81 {
82 for ( size_t i = 0; i < modules.size (); i++ )
83 {
84 if (modules[i]->name == name)
85 return modules[i];
86 }
87
88 return NULL;
89 }