parse, but ignore, <? ?> tags - eliminated duplicate code ala FixSeparator() - fix...
[reactos.git] / reactos / tools / rbuild / module.cpp
1 // module.cpp
2
3 #include "pch.h"
4 #include <assert.h>
5
6 #include "rbuild.h"
7
8 using std::string;
9 using std::vector;
10
11 string
12 FixSeparator ( const string& s )
13 {
14 string s2(s);
15 char* p = strchr ( &s2[0], CBAD_SEP );
16 while ( p )
17 {
18 *p++ = CSEP;
19 p = strchr ( p, CBAD_SEP );
20 }
21 return s2;
22 }
23
24 Module::Module ( Project* project,
25 const XMLElement& moduleNode,
26 const string& moduleName,
27 const string& modulePath )
28 : project(project),
29 node(moduleNode),
30 name(moduleName),
31 path(modulePath)
32 {
33 type = GetModuleType ( *moduleNode.GetAttribute ( "type", true ) );
34 }
35
36 Module::~Module ()
37 {
38 size_t i;
39 for ( i = 0; i < files.size(); i++ )
40 delete files[i];
41 for ( i = 0; i < libraries.size(); i++ )
42 delete libraries[i];
43 }
44
45 void
46 Module::ProcessXML ( const XMLElement& e,
47 const string& path )
48 {
49 string subpath ( path );
50 if ( e.name == "file" && e.value.size () )
51 {
52 files.push_back ( new File ( path + CSEP + e.value ) );
53 }
54 else if ( e.name == "library" && e.value.size () )
55 {
56 libraries.push_back ( new Library ( e.value ) );
57 }
58 else if ( e.name == "directory" )
59 {
60 const XMLAttribute* att = e.GetAttribute ( "name", true );
61 assert(att);
62 subpath = path + CSEP + att->value;
63 }
64 for ( size_t i = 0; i < e.subElements.size (); i++ )
65 ProcessXML ( *e.subElements[i], subpath );
66 }
67
68 ModuleType
69 Module::GetModuleType ( const XMLAttribute& attribute )
70 {
71 if ( attribute.value == "buildtool" )
72 return BuildTool;
73 if ( attribute.value == "staticlibrary" )
74 return StaticLibrary;
75 if ( attribute.value == "kernelmodedll" )
76 return KernelModeDLL;
77 throw InvalidAttributeValueException ( attribute.name,
78 attribute.value );
79 }
80
81 string
82 Module::GetPath ()
83 {
84 return FixSeparator (path) + CSEP + name + EXEPOSTFIX;
85 }
86
87
88 File::File ( const string& _name )
89 : name(_name)
90 {
91 }
92
93
94 Library::Library ( const string& _name )
95 : name(_name)
96 {
97 }