diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-09-29 20:46:24 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-09-29 20:46:24 +0000 |
commit | 04ccf5b458c95530c0371ca80cc76dcf17feda62 (patch) | |
tree | 31d048e23c1d378cc04f5a75457827b9296bd5d9 /src | |
parent | 98c0214d267c596eaa40d8904f15db24833e8b1f (diff) | |
download | build-04ccf5b458c95530c0371ca80cc76dcf17feda62.tar.gz build-04ccf5b458c95530c0371ca80cc76dcf17feda62.tar.bz2 build-04ccf5b458c95530c0371ca80cc76dcf17feda62.tar.xz build-04ccf5b458c95530c0371ca80cc76dcf17feda62.zip |
Added support for -C or --chdir, very helpful
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0cbc9c9..06a1ff6 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -17,13 +17,16 @@ public: | |||
17 | bPostDebug( false ), | 17 | bPostDebug( false ), |
18 | sView("plain"), | 18 | sView("plain"), |
19 | bInfo( false ), | 19 | bInfo( false ), |
20 | bCleanMode( false ) | 20 | bCleanMode( false ), |
21 | sDir("") | ||
21 | { | 22 | { |
22 | addHelpBanner("Build r?\n\n"); | 23 | addHelpBanner("Build r?\n\n"); |
23 | addParam("file", 'f', &sFile, | 24 | addParam("file", 'f', &sFile, |
24 | "Set the input script, default: build.conf"); | 25 | "Set the input script, default: build.conf"); |
25 | addParam("info", 'i', &bInfo, | 26 | addParam("info", 'i', &bInfo, |
26 | "Display useful info about the loaded config file.", NULL, "true" ); | 27 | "Display useful info about the loaded config file.", NULL, "true" ); |
28 | addParam("chdir", 'C', &sDir, | ||
29 | "Change to the specified dir before doing anything else." ); | ||
27 | addParam("clean", 'c', &bCleanMode, | 30 | addParam("clean", 'c', &bCleanMode, |
28 | "Clean instead of checking the given action.", NULL, "true" ); | 31 | "Clean instead of checking the given action.", NULL, "true" ); |
29 | addParam('p', mkproc(Param::procViewPercent), | 32 | addParam('p', mkproc(Param::procViewPercent), |
@@ -70,6 +73,7 @@ public: | |||
70 | std::string sCache; | 73 | std::string sCache; |
71 | std::string sFile; | 74 | std::string sFile; |
72 | std::string sView; | 75 | std::string sView; |
76 | std::string sDir; | ||
73 | StaticString sAction; | 77 | StaticString sAction; |
74 | //Viewer *pViewer; | 78 | //Viewer *pViewer; |
75 | bool bDebug; | 79 | bool bDebug; |
@@ -88,8 +92,17 @@ int main( int argc, char *argv[] ) | |||
88 | BuildParser bld; | 92 | BuildParser bld; |
89 | Build *pBuild = NULL; | 93 | Build *pBuild = NULL; |
90 | 94 | ||
95 | char *olddir = NULL; | ||
96 | |||
91 | try | 97 | try |
92 | { | 98 | { |
99 | if( prm.sDir != "" ) | ||
100 | { | ||
101 | olddir = new char[4096]; | ||
102 | getcwd( olddir, 4096 ); | ||
103 | chdir( prm.sDir.c_str() ); | ||
104 | } | ||
105 | |||
93 | pBuild = bld.load( prm.sFile.c_str() ); | 106 | pBuild = bld.load( prm.sFile.c_str() ); |
94 | pBuild->setCache( prm.sCache ); | 107 | pBuild->setCache( prm.sCache ); |
95 | pBuild->setView( prm.sView ); | 108 | pBuild->setView( prm.sView ); |
@@ -100,6 +113,7 @@ int main( int argc, char *argv[] ) | |||
100 | { | 113 | { |
101 | pBuild->printInfo(); | 114 | pBuild->printInfo(); |
102 | delete pBuild; | 115 | delete pBuild; |
116 | if( olddir ) { chdir( olddir ); delete[] olddir; } | ||
103 | return 0; | 117 | return 0; |
104 | } | 118 | } |
105 | if( prm.bDebug ) | 119 | if( prm.bDebug ) |
@@ -130,10 +144,12 @@ int main( int argc, char *argv[] ) | |||
130 | pBuild->debugDump(); | 144 | pBuild->debugDump(); |
131 | } | 145 | } |
132 | delete pBuild; | 146 | delete pBuild; |
147 | if( olddir ) { chdir( olddir ); delete[] olddir; } | ||
133 | return 1; | 148 | return 1; |
134 | } | 149 | } |
135 | 150 | ||
136 | delete pBuild; | 151 | delete pBuild; |
152 | if( olddir ) { chdir( olddir ); delete[] olddir; } | ||
137 | 153 | ||
138 | return 0; | 154 | return 0; |
139 | } | 155 | } |