-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_rules.cc
More file actions
89 lines (79 loc) · 2.43 KB
/
make_rules.cc
File metadata and controls
89 lines (79 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stddef.h>
#include <sstream>
#include <list>
#include <utility>
#include "make_rules.h"
#include "make_match.h"
#include "match.h"
using namespace std;
bool MakeRule::match(const string &target, Match **match)
{
// wildcard offsets in the target and dependencies
MakeMatch *makeMatch;
list<string>::iterator b, e, te;
if( targets == NULL ) return false;
makeMatch = new MakeMatch;
b = targets->begin();
e = targets->end();
for( te = b; te != e; te ++ ) {
if( makeMatch->initialize(target, *te) ) {
*match = makeMatch;
return true;
}
}
delete makeMatch;
return false;
}
string MakeRule::expand_command( const string &command, const string &target, Match *m )
{
string ret = command;
size_t position = 0;
while( true ) {
position = ret.find('$', position);
if( position == std::string::npos ) break;
// If it's the last character, do nothing special
if( position == ret.length() - 1 ) return ret;
// See what follows
switch( ret[ position + 1 ] ) {
case '@':
// Substitute targets
ret = ret.replace(position, 2, target);
position += target.length();
break;
case '<':
// Substitute first dependency
{
string s;
s = m->substitute( declaredDeps->begin()->first );
ret = ret.replace(position, 2, s);
position += s.length();
}
break;
case '^':
// Substitute all dependencies
{
string s;
ret = ret.erase(position, 2);
for( list<pair<string,bool> >::iterator i = declaredDeps->begin(); i != declaredDeps->end(); i ++ ) {
s = m->substitute( i->first ) + " ";
ret = ret.insert(position, s);
position += s.length();
}
}
break;
#if 0
case '(':
// Substitute variable
#endif
case '$':
// Substitute $
ret = ret.erase(position+1, position+2);
position++;
break;
default:
// Don't expand
position ++;
}
}
return ret;
}