apply terminal detection hack to all supported tools, add missing terminfo header

develop
Petr Mrázek 2011-05-15 06:10:47 +02:00
parent fe6eb4b70a
commit ca65aa99e6
22 changed files with 204 additions and 183 deletions

@ -7,9 +7,11 @@
#include <ctime> #include <ctime>
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include "termutil.h"
int main (void) int main (void)
{ {
bool temporary_terminal = TemporaryTerminal();
time_t start, end; time_t start, end;
double time_diff; double time_diff;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
@ -23,9 +25,8 @@ int main (void)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
/* /*
@ -79,10 +80,11 @@ int main (void)
DF->Detach(); DF->Detach();
time_diff = difftime(end, start); time_diff = difftime(end, start);
cout << "suspend tests done in " << time_diff << " seconds." << endl; cout << "suspend tests done in " << time_diff << " seconds." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
{
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif }
return 0; return 0;
} }

@ -11,6 +11,7 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/DFVector.h> #include <dfhack/DFVector.h>
#include <dfhack/extra/MapExtras.h> // map cache for the win. #include <dfhack/extra/MapExtras.h> // map cache for the win.
#include "termutil.h"
using namespace DFHack; using namespace DFHack;
using MapExtras::Block; using MapExtras::Block;
using MapExtras::MapCache; using MapExtras::MapCache;
@ -19,6 +20,7 @@ typedef std::map <DFCoord, uint32_t> coordmap;
int main (int argc, char * argv[]) int main (int argc, char * argv[])
{ {
bool temporary_terminal = TemporaryTerminal();
// Command line options // Command line options
bool destroy = false; bool destroy = false;
if(argc > 1 && strcmp(argv[1],"-d") == 0) if(argc > 1 && strcmp(argv[1],"-d") == 0)
@ -53,9 +55,8 @@ int main (int argc, char * argv[])
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -67,9 +68,8 @@ int main (int argc, char * argv[])
if(!Maps->Start()) if(!Maps->Start())
{ {
cerr << "Can't initialize map." << endl; cerr << "Can't initialize map." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
MapCache MC (Maps); MapCache MC (Maps);
@ -84,9 +84,8 @@ int main (int argc, char * argv[])
if (!Gui->getCursorCoords(cx,cy,cz)) if (!Gui->getCursorCoords(cx,cy,cz))
{ {
cerr << "Cursor position not found. Please enabled the cursor." << endl; cerr << "Cursor position not found. Please enabled the cursor." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
pos_cursor = DFCoord(cx,cy,cz); pos_cursor = DFCoord(cx,cy,cz);
@ -95,18 +94,16 @@ int main (int argc, char * argv[])
if(!b) if(!b)
{ {
cerr << "Cursor is in an invalid area. Place it over something save first." << endl; cerr << "Cursor is in an invalid area. Place it over something save first." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
uint16_t ttype = MC.tiletypeAt(pos_cursor); uint16_t ttype = MC.tiletypeAt(pos_cursor);
if(!DFHack::isFloorTerrain(ttype)) if(!DFHack::isFloorTerrain(ttype))
{ {
cerr << "Cursor should be placed over a floor." << endl; cerr << "Cursor should be placed over a floor." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
} }
@ -209,9 +206,10 @@ int main (int argc, char * argv[])
{ {
cout << "Done. " << dumped_total << " items marked for destruction." << endl; cout << "Done. " << dumped_total << " items marked for destruction." << endl;
} }
#ifndef LINUX_BUILD if(temporary_terminal)
cout << "Press any key to continue" << endl; {
cin.ignore(); cout << "Press any key to continue" << endl;
#endif cin.ignore();
}
return 0; return 0;
} }

@ -7,10 +7,11 @@
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include "termutil.h"
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
bool temporary_terminal = TemporaryTerminal();
bool quiet = false; bool quiet = false;
for(int i = 1; i < argc; i++) for(int i = 1; i < argc; i++)
{ {
@ -33,9 +34,8 @@ int main (int argc, char** argv)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
DFHack::Maps *Mapz = DF->getMaps(); DFHack::Maps *Mapz = DF->getMaps();
@ -44,9 +44,8 @@ int main (int argc, char** argv)
if(!Mapz->Start()) if(!Mapz->Start())
{ {
cerr << "Can't init map." << endl; cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -91,12 +90,10 @@ int main (int argc, char** argv)
} }
} }
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if (!quiet && temporary_terminal)
if (!quiet) {
{ cout << "Done. Press any key to continue" << endl;
cout << "Done. Press any key to continue" << endl; cin.ignore();
cin.ignore(); }
}
#endif
return 0; return 0;
} }

@ -13,9 +13,11 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/DFVector.h> #include <dfhack/DFVector.h>
#include <dfhack/DFTypes.h> #include <dfhack/DFTypes.h>
#include "termutil.h"
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
bool temporary_terminal = TemporaryTerminal();
bool dump_scattered = false; bool dump_scattered = false;
bool confiscate_all = false; bool confiscate_all = false;
bool dry_run = false; bool dry_run = false;
@ -60,9 +62,8 @@ int main (int argc, char *argv[])
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -175,10 +176,10 @@ int main (int argc, char *argv[])
*/ */
} }
} }
if(temporary_terminal)
#ifndef LINUX_BUILD {
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif }
return 0; return 0;
} }

@ -11,9 +11,11 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/DFVector.h> #include <dfhack/DFVector.h>
#include <dfhack/DFTypes.h> #include <dfhack/DFTypes.h>
#include "termutil.h"
int main () int main ()
{ {
bool temporary_terminal = TemporaryTerminal();
DFHack::Process * p; DFHack::Process * p;
unsigned int i; unsigned int i;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
@ -27,9 +29,8 @@ int main ()
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -44,9 +45,8 @@ int main ()
catch(DFHack::Error::All & e) catch(DFHack::Error::All & e)
{ {
cerr << "Fatal error, exiting :(" << endl << e.what() << endl; cerr << "Fatal error, exiting :(" << endl << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -68,9 +68,10 @@ int main ()
} }
cout << "Found and untasked " << numtasked << " items." << endl; cout << "Found and untasked " << numtasked << " items." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cout << "Done. Press any key to continue" << endl; {
cin.ignore(); cout << "Done. Press any key to continue" << endl;
#endif cin.ignore();
}
return 0; return 0;
} }

@ -10,10 +10,11 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/DFTileTypes.h> #include <dfhack/DFTileTypes.h>
#include "termutil.h"
int main (void) int main (void)
{ {
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0; uint32_t num_blocks = 0;
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
@ -42,9 +43,8 @@ int main (void)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
DFHack::Maps *Mapz = DF->getMaps(); DFHack::Maps *Mapz = DF->getMaps();
@ -53,9 +53,8 @@ int main (void)
if (!Mapz->Start()) if (!Mapz->Start())
{ {
cerr << "Can't init map." << endl; cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -138,9 +137,10 @@ int main (void)
DF->Detach(); DF->Detach();
cout << "Found and changed " << count << " tiles." << endl; cout << "Found and changed " << count << " tiles." << endl;
cout << "Fixed " << countbad << " bad down ramps." << endl; cout << "Fixed " << countbad << " bad down ramps." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cout << "Done. Press any key to continue" << endl; {
cin.ignore(); cout << "Done. Press any key to continue" << endl;
#endif cin.ignore();
}
return 0; return 0;
} }

@ -10,10 +10,11 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/DFTileTypes.h> #include <dfhack/DFTileTypes.h>
#include "termutil.h"
int main (void) int main (void)
{ {
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::designations40d designations; DFHack::designations40d designations;
DFHack::tiletypes40d tiles; DFHack::tiletypes40d tiles;
@ -35,9 +36,8 @@ int main (void)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
DFHack::Maps *Mapz = DF->getMaps(); DFHack::Maps *Mapz = DF->getMaps();
@ -46,9 +46,8 @@ int main (void)
if (!Mapz->Start()) if (!Mapz->Start())
{ {
cerr << "Can't init map." << endl; cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -56,9 +55,8 @@ int main (void)
if(!Mapz->StartFeatures()) if(!Mapz->StartFeatures())
{ {
cerr << "Can't get features." << endl; cerr << "Can't get features." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -114,9 +112,10 @@ int main (void)
} }
DF->Detach(); DF->Detach();
cout << "Found and changed " << count << " tiles." << endl; cout << "Found and changed " << count << " tiles." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cout << "Done. Press any key to continue" << endl; {
cin.ignore(); cout << "Done. Press any key to continue" << endl;
#endif cin.ignore();
}
return 0; return 0;
} }

@ -10,9 +10,11 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/VersionInfoFactory.h> #include <dfhack/VersionInfoFactory.h>
using namespace DFHack; using namespace DFHack;
#include "termutil.h"
int main (int numargs, const char ** args) int main (int numargs, const char ** args)
{ {
bool temporary_terminal = TemporaryTerminal();
/* /*
DFHack::VersionInfoFactory * VIF = new DFHack::VersionInfoFactory("Memory.xml"); DFHack::VersionInfoFactory * VIF = new DFHack::VersionInfoFactory("Memory.xml");
for(int i = 0; i < VIF->versions.size(); i++) for(int i = 0; i < VIF->versions.size(); i++)
@ -29,16 +31,16 @@ int main (int numargs, const char ** args)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
cout << DF->getMemoryInfo()->PrintOffsets(); cout << DF->getMemoryInfo()->PrintOffsets();
#ifndef LINUX_BUILD if(temporary_terminal)
{
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif }
//delete VIF; //delete VIF;
return 0; return 0;
} }

@ -9,7 +9,7 @@
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include "termutil.h"
void print_progress (int current, int total) void print_progress (int current, int total)
{ {
if(total < 100) if(total < 100)
@ -29,10 +29,10 @@ void print_progress (int current, int total)
int main (int numargs, char** args) int main (int numargs, char** args)
{ {
bool temporary_terminal = TemporaryTerminal();
time_t start, end; time_t start, end;
double time_diff; double time_diff;
unsigned int iterations = 0; unsigned int iterations = 0;
if (numargs == 2) if (numargs == 2)
{ {
@ -41,7 +41,7 @@ int main (int numargs, char** args)
} }
if(iterations == 0) if(iterations == 0)
iterations = 1000; iterations = 1000;
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0; uint32_t num_blocks = 0;
uint64_t bytes_read = 0; uint64_t bytes_read = 0;
@ -58,19 +58,17 @@ int main (int numargs, char** args)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
time(&start); time(&start);
cout << "doing " << iterations << " iterations" << endl; cout << "doing " << iterations << " iterations" << endl;
for(uint32_t i = 0; i< iterations;i++) for(uint32_t i = 0; i< iterations;i++)
{ {
print_progress (i, iterations); print_progress (i, iterations);
if(!Maps->Start()) if(!Maps->Start())
break; break;
Maps->getSize(x_max,y_max,z_max); Maps->getSize(x_max,y_max,z_max);
@ -97,9 +95,10 @@ int main (int numargs, char** args)
cout << num_blocks << " blocks read" << endl; cout << num_blocks << " blocks read" << endl;
cout << bytes_read / (1024 * 1024) << " MB" << endl; cout << bytes_read / (1024 * 1024) << " MB" << endl;
cout << "map export tests done in " << time_diff << " seconds." << endl; cout << "map export tests done in " << time_diff << " seconds." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
{
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif }
return 0; return 0;
} }

@ -5,12 +5,13 @@
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include "termutil.h"
int main (void) int main (void)
{ {
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::designations40d designations; DFHack::designations40d designations;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF; DFHack::Context * DF;
DFHack::Maps *Maps; DFHack::Maps *Maps;
@ -23,18 +24,16 @@ int main (void)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
// init the map // init the map
if(!Maps->Start()) if(!Maps->Start())
{ {
cerr << "Can't init map." << endl; cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
DFHack::t_blockflags bflags; DFHack::t_blockflags bflags;
@ -76,8 +75,7 @@ int main (void)
cout << "Magma tiles: " << magma << endl; cout << "Magma tiles: " << magma << endl;
cout << endl << "Done." << endl; cout << endl << "Done." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 0; return 0;
} }

@ -7,9 +7,11 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/modules/Gui.h> #include <dfhack/modules/Gui.h>
#include "termutil.h"
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
bool temporary_terminal = TemporaryTerminal();
bool quiet = false; bool quiet = false;
for(int i = 1; i < argc; i++) for(int i = 1; i < argc; i++)
{ {
@ -30,9 +32,8 @@ int main (int argc, char** argv)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(!quiet && temporary_terminal)
if(!quiet) cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -41,9 +42,8 @@ int main (int argc, char** argv)
World->SetPauseState(true); World->SetPauseState(true);
DF->Resume(); 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;
cout << "Done. The current game frame will have to finish first. This can take some time on bugged maps." << endl; if(!quiet && temporary_terminal)
if (!quiet) cin.ignore(); cin.ignore();
#endif
return 0; return 0;
} }

@ -5,14 +5,13 @@
#include <map> #include <map>
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
//#include <dfhack/modules/Gui.h> #include "termutil.h"
//#include <dfhack/DFTileTypes.h>
int main (void) int main (void)
{ {
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::occupancies40d occupancies; DFHack::occupancies40d occupancies;
//DFHack::tiletypes40d tiles;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF; DFHack::Context *DF;
@ -24,9 +23,8 @@ int main (void)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -36,9 +34,8 @@ int main (void)
if(!Maps->Start()) if(!Maps->Start())
{ {
cerr << "Can't init map." << endl; cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -68,9 +65,10 @@ int main (void)
} }
} }
} }
#ifndef LINUX_BUILD if(temporary_terminal)
cout << "The map has been marked as a creature lair. Items shouldn't scatter." << endl; {
cin.ignore(); cout << "The map has been marked as a creature lair. Items shouldn't scatter." << endl;
#endif cin.ignore();
}
return 0; return 0;
} }

@ -9,6 +9,8 @@ using namespace std;
#include <set> #include <set>
using namespace MapExtras; using namespace MapExtras;
#include "termutil.h"
typedef vector <DFHack::DFCoord> coord_vec; typedef vector <DFHack::DFCoord> coord_vec;
class Brush class Brush
@ -130,6 +132,7 @@ public:
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
bool temporary_terminal = TemporaryTerminal();
bool quiet = false; bool quiet = false;
for(int i = 1; i < argc; i++) for(int i = 1; i < argc; i++)
{ {
@ -140,11 +143,7 @@ int main (int argc, char** argv)
} }
} }
int32_t x,y,z; int32_t x,y,z;
/*
DFHack::designations40d designations;
DFHack::tiletypes40d tiles;
DFHack::t_temperatures temp1,temp2;
*/
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
@ -165,9 +164,8 @@ int main (int argc, char** argv)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
bool end = false; bool end = false;
@ -496,12 +494,10 @@ int main (int argc, char** argv)
} }
} }
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if(temporary_terminal && !quiet)
if(!quiet)
{ {
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
} }
#endif
return 0; return 0;
} }

@ -7,7 +7,7 @@
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include "termutil.h"
std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies) std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies)
{ {
const char * gm[]= const char * gm[]=
@ -37,6 +37,7 @@ std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies)
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
bool temporary_terminal = TemporaryTerminal();
bool quiet = false; bool quiet = false;
for(int i = 1; i < argc; i++) for(int i = 1; i < argc; i++)
{ {
@ -65,9 +66,8 @@ int main (int argc, char** argv)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
DFHack::t_gamemodes gmm; DFHack::t_gamemodes gmm;
@ -117,12 +117,10 @@ int main (int argc, char** argv)
cerr << "Can't detach from DF" << endl; cerr << "Can't detach from DF" << endl;
} }
#ifndef LINUX_BUILD if(!quiet && temporary_terminal)
if(!quiet) {
{ cout << "Done. Press any key to continue" << endl;
cout << "Done. Press any key to continue" << endl; cin.ignore();
cin.ignore(); }
}
#endif
return 0; return 0;
} }

@ -13,16 +13,16 @@ using namespace std;
#define DFHACK_WANT_TILETYPES 1 #define DFHACK_WANT_TILETYPES 1
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/extra/MapExtras.h> #include <dfhack/extra/MapExtras.h>
#include "termutil.h"
using namespace DFHack; using namespace DFHack;
int main (int numargs, const char ** args) int main (int numargs, const char ** args)
{ {
bool temporary_terminal = TemporaryTerminal();
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext(); DFHack::Context *DF = DFMgr.getSingleContext();
#ifndef LINUX_BUILD BEGIN_PROBE:
BEGIN_PROBE:
#endif
try try
{ {
DF->Attach(); DF->Attach();
@ -30,9 +30,8 @@ int main (int numargs, const char ** args)
catch (std::exception& e) catch (std::exception& e)
{ {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -206,10 +205,11 @@ int main (int numargs, const char ** args)
} }
} }
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
{
std::cout << "Press any key to refresh..." << std::endl; std::cout << "Press any key to refresh..." << std::endl;
cin.ignore(); cin.ignore();
goto BEGIN_PROBE; goto BEGIN_PROBE;
#endif }
return 0; return 0;
} }

@ -21,6 +21,7 @@ void waitmsec (int delay)
Sleep(delay); Sleep(delay);
} }
#endif #endif
#include "termutil.h"
struct hideblock struct hideblock
{ {
@ -32,9 +33,9 @@ struct hideblock
int main (void) int main (void)
{ {
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::designations40d designations; DFHack::designations40d designations;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF; DFHack::Context *DF;
try try
@ -45,12 +46,10 @@ int main (void)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
DFHack::Maps *Maps =DF->getMaps(); DFHack::Maps *Maps =DF->getMaps();
DFHack::World *World =DF->getWorld(); DFHack::World *World =DF->getWorld();
// walk the map, save the hide bits, reveal. // walk the map, save the hide bits, reveal.
@ -69,9 +68,8 @@ int main (void)
if(!Maps->Start()) if(!Maps->Start())
{ {
cerr << "Can't init map." << endl; cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -129,9 +127,10 @@ int main (void)
} }
Maps->WriteDesignations(hb.x,hb.y,hb.z, &designations); Maps->WriteDesignations(hb.x,hb.y,hb.z, &designations);
} }
#ifndef LINUX_BUILD if(temporary_terminal)
cout << "Done. Press any key to continue" << endl; {
cin.ignore(); cout << "Done. Press any key to continue" << endl;
#endif cin.ignore();
}
return 0; return 0;
} }

@ -8,8 +8,11 @@
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include "termutil.h"
int main (void) int main (void)
{ {
bool temporary_terminal = TemporaryTerminal();
string blah; string blah;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF; DFHack::Context * DF;
@ -21,9 +24,8 @@ int main (void)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
cout << "Attached, DF should be suspended now" << endl; cout << "Attached, DF should be suspended now" << endl;
@ -48,10 +50,12 @@ int main (void)
if(!DF->Detach()) if(!DF->Detach())
{ {
cerr << "Can't detach from DF" << endl; cerr << "Can't detach from DF" << endl;
if(temporary_terminal)
cin.ignore();
return 1; return 1;
} }
cout << "Detached, DF should be running again" << endl; cout << "Detached, DF should be running again" << endl;
getline(cin, blah); if(temporary_terminal)
getline(cin, blah);
return 0; return 0;
} }

@ -0,0 +1,29 @@
#ifndef TERMUTIL_H
#define TERMUTIL_H
#ifdef LINUX_BUILD
// FIXME: is this ever false?
bool TemporaryTerminal ()
{
return false;
}
#else
#include <windows.h>
#include <stdio.h>
#include <conio.h>
bool TemporaryTerminal ()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hStdOutput;
hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
if (!GetConsoleScreenBufferInfo(hStdOutput, &csbi))
{
printf("GetConsoleScreenBufferInfo failed: %d\n", GetLastError());
return false;
}
return ((!csbi.dwCursorPosition.X) && (!csbi.dwCursorPosition.Y));
};
#endif // LINUX_BUILD
#endif

@ -9,6 +9,7 @@
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/extra/MapExtras.h> #include <dfhack/extra/MapExtras.h>
#include "termutil.h"
void tolower(std::string &str) void tolower(std::string &str)
{ {
@ -389,6 +390,7 @@ public:
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max = 0, y_max = 0, z_max = 0; uint32_t x_max = 0, y_max = 0, z_max = 0;
int32_t x = 0, y = 0, z = 0; int32_t x = 0, y = 0, z = 0;
DFHack::ContextManager manager("Memory.xml"); DFHack::ContextManager manager("Memory.xml");
@ -397,9 +399,8 @@ int main(int argc, char *argv[])
if (!context->Attach()) if (!context->Attach())
{ {
std::cerr << "Unable to attach to DF!" << std::endl; std::cerr << "Unable to attach to DF!" << std::endl;
#ifndef LINUX_BUILD if(temporary_terminal)
std::cin.ignore(); std::cin.ignore();
#endif
return 1; return 1;
} }
@ -513,9 +514,8 @@ int main(int argc, char *argv[])
{ {
std::cerr << "Cannot get map info!" << std::endl; std::cerr << "Cannot get map info!" << std::endl;
context->Detach(); context->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
std::cin.ignore(); std::cin.ignore();
#endif
return 1; return 1;
} }
maps->getSize(x_max, y_max, z_max); maps->getSize(x_max, y_max, z_max);
@ -587,10 +587,11 @@ int main(int argc, char *argv[])
} }
context->Detach(); context->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
std::cout << "Press any key to finish."; {
std::cin.ignore(); std::cout << "Press any key to finish.";
#endif std::cin.ignore();
}
std::cout << std::endl; std::cout << std::endl;
return 0; return 0;
} }

@ -12,9 +12,11 @@ using namespace std;
#include <dfhack/extra/MapExtras.h> #include <dfhack/extra/MapExtras.h>
using namespace MapExtras; using namespace MapExtras;
using namespace DFHack; using namespace DFHack;
#include "termutil.h"
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
bool temporary_terminal = TemporaryTerminal();
ContextManager DFMgr("Memory.xml"); ContextManager DFMgr("Memory.xml");
Context * DF; Context * DF;
try try
@ -25,9 +27,8 @@ int main (int argc, char* argv[])
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -40,9 +41,8 @@ int main (int argc, char* argv[])
{ {
cerr << "Can't init map. Make sure you have a map loaded in DF." << endl; cerr << "Can't init map. Make sure you have a map loaded in DF." << endl;
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -55,9 +55,8 @@ int main (int argc, char* argv[])
if(cx == -30000) if(cx == -30000)
{ {
cerr << "Cursor is not active. Point the cursor at some empty space you want to be unhidden." << endl; cerr << "Cursor is not active. Point the cursor at some empty space you want to be unhidden." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
@ -66,9 +65,8 @@ int main (int argc, char* argv[])
if(isWallTerrain(tt)) if(isWallTerrain(tt))
{ {
cerr << "Point the cursor at some empty space you want to be unhidden." << endl; cerr << "Point the cursor at some empty space you want to be unhidden." << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
// hide all tiles, flush cache // hide all tiles, flush cache
@ -194,10 +192,11 @@ int main (int argc, char* argv[])
MCache->WriteAll(); MCache->WriteAll();
delete MCache; delete MCache;
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
{
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif }
return 0; return 0;
} }

@ -8,8 +8,10 @@
using namespace std; using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include "termutil.h"
int main (void) int main (void)
{ {
bool temporary_terminal = TemporaryTerminal();
string blah; string blah;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF; DFHack::Context *DF;
@ -21,9 +23,8 @@ int main (void)
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }

@ -10,10 +10,12 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
#include <dfhack/extra/MapExtras.h> #include <dfhack/extra/MapExtras.h>
#include "termutil.h"
using namespace MapExtras; using namespace MapExtras;
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
bool temporary_terminal = TemporaryTerminal();
// Command line options // Command line options
bool updown = false; bool updown = false;
if(argc > 1 && strcmp(argv[1],"-x") == 0) if(argc > 1 && strcmp(argv[1],"-x") == 0)
@ -29,9 +31,8 @@ int main (int argc, char* argv[])
catch (exception& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -44,9 +45,8 @@ int main (int argc, char* argv[])
{ {
cerr << "Can't init map. Make sure you have a map loaded in DF." << endl; cerr << "Can't init map. Make sure you have a map loaded in DF." << endl;
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
@ -69,9 +69,8 @@ int main (int argc, char* argv[])
{ {
cerr << "I won't dig the borders. That would be cheating!" << endl; cerr << "I won't dig the borders. That would be cheating!" << endl;
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
MapCache * MCache = new MapCache(Maps); MapCache * MCache = new MapCache(Maps);
@ -85,9 +84,8 @@ int main (int argc, char* argv[])
cerr << "This tile is non-vein. Bye :)" << endl; cerr << "This tile is non-vein. Bye :)" << endl;
delete MCache; delete MCache;
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
cin.ignore(); cin.ignore();
#endif
return 1; return 1;
} }
printf("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole); printf("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole);
@ -200,10 +198,11 @@ int main (int argc, char* argv[])
MCache->WriteAll(); MCache->WriteAll();
delete MCache; delete MCache;
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD if(temporary_terminal)
{
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif }
return 0; return 0;
} }