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
|
#include "miwm_framework.h"
#include <stdlib.h> // getenv()
#include <sys/stat.h> // mkdir()
#include <sys/types.h> // mkdir()
#include "EPathFinder.h"
namespace miwm {
std::string homePath( const std::string & append )
{
const char * hp = ::getenv( "HOME" );
static string abspath = string(hp) + EPathFinder::getDirectorySeparator() + ".miwm";
if( ! EPathFinder::isAccessible( abspath ) )
{
if( 0 != ::mkdir( abspath.c_str(), 0700 ) )
{
CERR << __FILE__<<":"<<__LINE__<<" error: could not create miwm home directory ["<<abspath<<"]." << std::endl;
hp = ::getenv( "TEMP" );
abspath = hp ? std::string(hp) : "/";
}
}
return abspath + append;
}
EPropertyList & config()
{
static EPropertyList meyers;
static bool donethat = false;
if( ! donethat && (donethat=true) )
{
string fname = miwm::homePath() + "/miwm.config";
meyers.load( fname );
meyers.saveAtDestruction(true);
CERR << "config file = ["<<fname<<"]"<<std::endl;
}
return meyers;
}
ESimpleCLParser & args()
{
static ESimpleCLParser meyers;
return meyers;
}
void show_help()
{
std::ostream & os = std::cout;
os << "Command-line arguments:\n" << miwm::args().dumpHelp();
os << endl;
return;
}
int init( int argc, char ** argv )
{
ESimpleCLParser & a = miwm::args();
a.setHelp( "memcheck", "Integer in the range (1..3), enables memory leak checks." );
int argcount = a.setArgs( argc, argv );
return argcount;
}
}; // namespace miwm
|