diff options
Diffstat (limited to '')
-rw-r--r-- | src/main.cpp | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 1d3dc10..0000000 --- a/src/main.cpp +++ /dev/null | |||
@@ -1,172 +0,0 @@ | |||
1 | #include "buildparser.h" | ||
2 | //#include "viewerplain.h" | ||
3 | //#include "viewerpercent.h" | ||
4 | //#include "viewermake.h" | ||
5 | #include "bu/paramproc.h" | ||
6 | #include "bu/fstring.h" | ||
7 | #include "build.h" | ||
8 | #include "action.h" | ||
9 | |||
10 | #include <stdlib.h> | ||
11 | |||
12 | class Param : public Bu::ParamProc | ||
13 | { | ||
14 | public: | ||
15 | Param() : | ||
16 | sFile("build.conf"), | ||
17 | sCache(".build.cache"), | ||
18 | bDebug( false ), | ||
19 | bPostDebug( false ), | ||
20 | sView("colorpct"), | ||
21 | bInfo( false ), | ||
22 | bCleanMode( false ), | ||
23 | sDir("") | ||
24 | { | ||
25 | addHelpBanner("Build r?\n\n"); | ||
26 | addParam("file", 'f', &sFile, | ||
27 | "Set the input script, default: build.conf"); | ||
28 | addParam("info", 'i', &bInfo, | ||
29 | "Display useful info about the loaded config file.", NULL, "true" ); | ||
30 | addParam("chdir", 'C', &sDir, | ||
31 | "Change to the specified dir before doing anything else." ); | ||
32 | addParam("clean", 'c', &bCleanMode, | ||
33 | "Clean instead of checking the given action.", NULL, "true" ); | ||
34 | addParam('p', mkproc(Param::procViewPercent), | ||
35 | "Switch to percent view."); | ||
36 | addParam('P', mkproc(Param::procViewPlain), | ||
37 | "Switch to plain view."); | ||
38 | addParam("color", mkproc(Param::procColorPercent), | ||
39 | "Switch to colored percent view."); | ||
40 | addParam('m', mkproc(Param::procViewMake), | ||
41 | "Switch to 'make' style view."); | ||
42 | addParam("cache", &sCache, | ||
43 | "Set an alternative cache file, default: .build.cache" ); | ||
44 | addParam('d', &bDebug, | ||
45 | "Display debug info instead of building", NULL, "true" ); | ||
46 | addParam('D', &bPostDebug, | ||
47 | "Display debug info after building", NULL, "true" ); | ||
48 | addParam("help", mkproc(ParamProc::help), | ||
49 | "This help"); | ||
50 | //pViewer = new ViewerPlain; | ||
51 | } | ||
52 | |||
53 | virtual ~Param() | ||
54 | { | ||
55 | //delete pViewer; | ||
56 | } | ||
57 | |||
58 | virtual int cmdParam( int argc, char *argv[] ) | ||
59 | { | ||
60 | if( sAction.isSet() ) | ||
61 | { | ||
62 | printf("You can only specify one action per command line.\n\n"); | ||
63 | exit( 1 ); | ||
64 | } | ||
65 | sAction = argv[0]; | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | int procViewPercent( int argc, char *argv[] ) | ||
70 | { | ||
71 | sView = "percent"; | ||
72 | } | ||
73 | |||
74 | int procViewPlain( int argc, char *argv[] ) | ||
75 | { | ||
76 | sView = "plain"; | ||
77 | } | ||
78 | |||
79 | int procViewMake( int argc, char *argv[] ) | ||
80 | { | ||
81 | sView = "make"; | ||
82 | } | ||
83 | |||
84 | int procColorPercent( int argc, char *argv[] ) | ||
85 | { | ||
86 | sView = "colorpct"; | ||
87 | } | ||
88 | |||
89 | Bu::FString sCache; | ||
90 | Bu::FString sFile; | ||
91 | Bu::FString sView; | ||
92 | Bu::FString sDir; | ||
93 | Bu::FString sAction; | ||
94 | //Viewer *pViewer; | ||
95 | bool bDebug; | ||
96 | bool bPostDebug; | ||
97 | bool bInfo; | ||
98 | bool bCleanMode; | ||
99 | |||
100 | private: | ||
101 | }; | ||
102 | |||
103 | int main( int argc, char *argv[] ) | ||
104 | { | ||
105 | Param prm; | ||
106 | prm.process( argc, argv ); | ||
107 | |||
108 | BuildParser bld; | ||
109 | Build *pBuild = NULL; | ||
110 | |||
111 | char *olddir = NULL; | ||
112 | |||
113 | try | ||
114 | { | ||
115 | if( prm.sDir != "" ) | ||
116 | { | ||
117 | olddir = new char[4096]; | ||
118 | getcwd( olddir, 4096 ); | ||
119 | chdir( prm.sDir.getStr() ); | ||
120 | } | ||
121 | |||
122 | pBuild = bld.load( prm.sFile.getStr() ); | ||
123 | pBuild->setCache( prm.sCache.getStr() ); | ||
124 | pBuild->setView( prm.sView.getStr() ); | ||
125 | if( prm.bCleanMode ) | ||
126 | pBuild->setMode( Action::actClean ); | ||
127 | |||
128 | if( prm.bInfo ) | ||
129 | { | ||
130 | pBuild->printInfo(); | ||
131 | delete pBuild; | ||
132 | if( olddir ) { chdir( olddir ); delete[] olddir; } | ||
133 | return 0; | ||
134 | } | ||
135 | if( prm.bDebug ) | ||
136 | { | ||
137 | printf("\n\n----------\nDebug dump\n----------\n"); | ||
138 | pBuild->debugDump(); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | if( prm.sAction.isSet() ) | ||
143 | pBuild->execAction( prm.sAction.getStr() ); | ||
144 | else | ||
145 | pBuild->execAction(""); | ||
146 | } | ||
147 | if( prm.bPostDebug ) | ||
148 | { | ||
149 | printf("\n\n----------\nDebug dump\n----------\n"); | ||
150 | pBuild->debugDump(); | ||
151 | } | ||
152 | } | ||
153 | catch( BuildException &e ) | ||
154 | { | ||
155 | fputs( e.what(), stderr ); | ||
156 | fputs( "\n", stderr ); | ||
157 | if( prm.bPostDebug ) | ||
158 | { | ||
159 | printf("\n\n----------\nDebug dump\n----------\n"); | ||
160 | pBuild->debugDump(); | ||
161 | } | ||
162 | delete pBuild; | ||
163 | if( olddir ) { chdir( olddir ); delete[] olddir; } | ||
164 | return 1; | ||
165 | } | ||
166 | |||
167 | delete pBuild; | ||
168 | if( olddir ) { chdir( olddir ); delete[] olddir; } | ||
169 | |||
170 | return 0; | ||
171 | } | ||
172 | |||