aboutsummaryrefslogtreecommitdiff
path: root/src/functiongetmakedeps.cpp
blob: 69003ba68ca66a59d9daf5ceb8e21e4011b7fc56 (plain)
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
/*
 * Copyright (C) 2007-2014 Xagasoft, All rights reserved.
 *
 * This file is part of the Xagasoft Build and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "functiongetmakedeps.h"
#include "context.h"
#include "view.h"

#include <bu/process.h>
#include <bu/sio.h>
using namespace Bu;

#include <bu/plugger.h>
PluginInterface3( pluginFunctionGetMakeDeps, getMakeDeps, FunctionGetMakeDeps,
        Function, "Mike Buland", 0, 1 );

FunctionGetMakeDeps::FunctionGetMakeDeps()
{
}

FunctionGetMakeDeps::~FunctionGetMakeDeps()
{
}

Bu::String FunctionGetMakeDeps::getName() const
{
    return "getMakeDeps";
}

Variable FunctionGetMakeDeps::call( Variable &/*input*/, VarList lParams )
{
    pContext->getView()->cmdStarted( lParams.first().getString().getStr() );
    Process p( Process::StdOut, "/bin/sh", "/bin/sh", "-c",
        lParams.first().getString().getStr(), NULL );

    // Gather all data from the command.
    Bu::String sBuf;
    do
    {
        char buf[4096];
        int iRead = p.read( buf, 4096 );
        sBuf.append( buf, iRead );
    }
    while( !p.isEos() );
    
    pContext->getView()->cmdFinished( "", "", p.childExitStatus() );
    
    Variable vRet( Variable::typeList );

    Bu::String::iterator i, j;
    i = sBuf.find(':')+2;
    while( i )
    {
        // Find whitespace at the end of the word, this one is easy, there's
        // always a space after a word
        for( j = i; j && *j != ' ' && *j != '\n' && *j != '\r'; j++ ) { }
        
        Bu::String sTmp( i, j );
        vRet.append( sTmp );
    
        // Find the begining of the next word, trickier, we don't want to go
        // off the end, and we need to skip \ chars at the ends of lines, right
        // now this is too stupid to do that, so it may not work on windows.
        // TODO: perhaps make this only skip \ chars at the ends of lines,
        // we'll see if it matters.
        for( i = j+1;
             i && (*i == ' ' || *i == '\\' || *i == '\n' || *i == '\r'); i++ )
        { }
    }

    return vRet;
}