From 0df38244e4a7576cac4c0c1f3f2ea4c5bf3ce0f2 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Thu, 11 Nov 2010 02:09:43 +0100 Subject: [PATCH] added -q (quiet) command line parameter to a couple of tools, to allow usage in scripts. --- tools/supported/cleanmap.cpp | 22 ++++++++++++++++++---- tools/supported/forcepause.cpp | 16 +++++++++++++--- tools/supported/liquids.cpp | 20 ++++++++++++++++---- tools/supported/position.cpp | 15 ++++++++++++++- tools/supported/prospector.cpp | 2 +- tools/supported/weather.cpp | 29 +++++++++++++++++++++++++---- 6 files changed, 87 insertions(+), 17 deletions(-) diff --git a/tools/supported/cleanmap.cpp b/tools/supported/cleanmap.cpp index 900aa3f72..7ff2e7255 100644 --- a/tools/supported/cleanmap.cpp +++ b/tools/supported/cleanmap.cpp @@ -8,9 +8,20 @@ using namespace std; #include -int main (void) +int main (int argc, char** argv) { - uint32_t x_max,y_max,z_max; + + bool quiet = false; + for(int i = 1; i < argc; i++) + { + string test = argv[i]; + if(test == "-q") + { + quiet = true; + } + } + + uint32_t x_max,y_max,z_max; uint32_t num_blocks = 0; uint32_t bytes_read = 0; vector splatter; @@ -72,8 +83,11 @@ int main (void) } DF->Detach(); #ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); + if (!quiet) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } #endif return 0; } diff --git a/tools/supported/forcepause.cpp b/tools/supported/forcepause.cpp index 521859078..c6115aa5a 100644 --- a/tools/supported/forcepause.cpp +++ b/tools/supported/forcepause.cpp @@ -8,8 +8,18 @@ using namespace std; #include #include -int main (void) +int main (int argc, char** argv) { + bool quiet = false; + for(int i = 1; i < argc; i++) + { + string test = argv[i]; + if(test == "-q") + { + quiet = true; + } + } + DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context *DF; try @@ -21,7 +31,7 @@ int main (void) { cerr << e.what() << endl; #ifndef LINUX_BUILD - cin.ignore(); + if(!quiet) cin.ignore(); #endif return 1; } @@ -33,7 +43,7 @@ int main (void) DF->Resume(); #ifndef LINUX_BUILD cout << "Done. The current game frame will have to finish first. This can take some time on bugged maps." << endl; - cin.ignore(); + if (!quiet) cin.ignore(); #endif return 0; } diff --git a/tools/supported/liquids.cpp b/tools/supported/liquids.cpp index 702630162..702610931 100644 --- a/tools/supported/liquids.cpp +++ b/tools/supported/liquids.cpp @@ -9,9 +9,18 @@ using namespace std; #include #include -int main (void) +int main (int argc, char** argv) { - int32_t x,y,z; + bool quiet = false; + for(int i = 1; i < argc; i++) + { + string test = argv[i]; + if(test == "-q") + { + quiet = true; + } + } + int32_t x,y,z; DFHack::designations40d designations; DFHack::tiletypes40d tiles; DFHack::t_temperatures temp1,temp2; @@ -460,8 +469,11 @@ int main (void) } DF->Detach(); #ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); + if(!quiet) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } #endif return 0; } diff --git a/tools/supported/position.cpp b/tools/supported/position.cpp index 5f666ec4e..e660c2a91 100644 --- a/tools/supported/position.cpp +++ b/tools/supported/position.cpp @@ -8,8 +8,18 @@ using namespace std; #include -int main (void) +int main (int argc, char** argv) { + bool quiet = false; + for(int i = 1; i < argc; i++) + { + string test = argv[i]; + if(test == "-q") + { + quiet = true; + } + } + DFHack::Position * Position = 0; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF; @@ -50,8 +60,11 @@ int main (void) } #ifndef LINUX_BUILD + if(!quiet) + { cout << "Done. Press any key to continue" << endl; cin.ignore(); + } #endif return 0; } diff --git a/tools/supported/prospector.cpp b/tools/supported/prospector.cpp index 77ba6afcb..096b1269a 100644 --- a/tools/supported/prospector.cpp +++ b/tools/supported/prospector.cpp @@ -44,7 +44,7 @@ int main (int argc, const char* argv[]) bool showhidden = false; bool showbaselayers = false; - for(int i = 0; i < argc; i++) + for(int i = 1; i < argc; i++) { string test = argv[i]; if(test == "-a") diff --git a/tools/supported/weather.cpp b/tools/supported/weather.cpp index 6d441b00b..4ca738842 100644 --- a/tools/supported/weather.cpp +++ b/tools/supported/weather.cpp @@ -43,9 +43,26 @@ void printWeather(DFHack::WeatherType current) } using namespace DFHack; -int main (int numargs, const char ** args) +int main (int argc, char** argv) { - DFHack::ContextManager DFMgr("Memory.xml"); + string command = ""; + bool quiet = false; + bool cmdarg = false; + for(int i = 1; i < argc; i++) + { + string test = argv[i]; + if(test == "-q") + { + quiet = true; + } + else + { + command = test; + cmdarg = true; + } + } + + DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context *DF = DFMgr.getSingleContext(); try @@ -68,9 +85,8 @@ int main (int numargs, const char ** args) { WeatherType current = (WeatherType) W->ReadCurrentWeather(); DF->Resume(); - string command = ""; printWeather(current); - getline(cin, command); + if (command == "") getline(cin, command); // only read from stdin if command hasn't been passed on the console DF->Suspend(); if(command == "c") { @@ -88,10 +104,15 @@ int main (int numargs, const char ** args) { end = true; } + command = ""; + if(cmdarg) end = true; // exit the loop when a cmd line arg has been passed. } #ifndef LINUX_BUILD + if (!quiet) + { std::cout << "Done. Press any key to continue" << std::endl; cin.ignore(); + } #endif DF->Detach(); return 0;