aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 1576b0c53ac3abfed13e767cac6ff698f25e0f6a (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "buildparser.h"
//#include "viewerplain.h"
//#include "viewerpercent.h"
//#include "viewermake.h"
#include "paramproc.h"
#include "staticstring.h"
#include "build.h"

class Param : public ParamProc
{
public:
	Param() :
		sFile("build.conf"),
		sCache(".build.cache"),
		bDebug( false ),
		bPostDebug( false ),
		sView("plain")
	{
		addHelpBanner("Build r?\n\n");
		addParam("file", 'f', &sFile, 
				"Set the input script, default: build.conf");
		addParam('p', mkproc(Param::procViewPercent),
				"Switch to percent view.");
		addParam('m', mkproc(Param::procViewMake),
				"Switch to 'make' style view.");
		addParam("cache", &sCache,
				"Set an alternative cache file." );
		addParam('d', &bDebug,
				"Display debug info instead of building", NULL, "true" );
		addParam('D', &bPostDebug,
				"Display debug info after building", NULL, "true" );
		addParam("help", mkproc(ParamProc::help),
				"This help");
		//pViewer = new ViewerPlain;
	}

	virtual ~Param()
	{
		//delete pViewer;
	}

	virtual int cmdParam( int argc, char *argv[] )
	{
		if( sAction > 0 )
		{
			printf("You can only specify one action per command line.\n\n");
			exit( 1 );
		}
		sAction = argv[0];
		return 1;
	}

	int procViewPercent( int argc, char *argv[] )
	{
		sView = "percent";
	}

	int procViewMake( int argc, char *argv[] )
	{
		sView = "make";
	}

	std::string sCache;
	std::string sFile;
	std::string sView;
	StaticString sAction;
	//Viewer *pViewer;
	bool bDebug;
	bool bPostDebug;

private:
};

int main( int argc, char *argv[] )
{
	Param prm;
	prm.process( argc, argv );

	BuildParser bld;
	Build *pBuild;

	try
	{
		pBuild = bld.load( prm.sFile.c_str() );
		pBuild->setCache( prm.sCache );
		pBuild->setView( prm.sView );
		if( prm.bDebug )
		{
			printf("\n\n----------\nDebug dump\n----------\n");
			pBuild->debugDump();
		}
		else
		{
			if( prm.sAction > 0 )
				pBuild->execAction( prm.sAction.getString() );
			else
				pBuild->execAction("");
		}
		if( prm.bPostDebug )
		{
			printf("\n\n----------\nDebug dump\n----------\n");
			pBuild->debugDump();
		}
	}
	catch( BuildException &e )
	{
		fputs( e.what(), stderr );
		fputs( "\n", stderr );
		if( prm.bPostDebug )
		{
			printf("\n\n----------\nDebug dump\n----------\n");
			pBuild->debugDump();
		}
		return 1;
	}

	delete pBuild;
}