93 const fs::path program(conf.
GetName());
96 const string prgpath = program.parent_path().string();
98 #if BOOST_VERSION < 104600 99 const string prgname = program.filename();
101 const string prgname = program.filename().string();
104 fs::path path = conf.
Has(
"logpath") ? conf.
Get<
string>(
"logpath") :
"";
109 path = prgpath.empty() ?
"." : prgpath;
112 if (access(prgpath.c_str(), W_OK))
116 if (conf.
Has(
"home"))
118 path = conf.
Get<
string>(
"home");
125 fs::create_directories(path);
129 static T shell((path/prgname).
string().c_str(),
130 conf.
Has(
"console") ? conf.
Get<
int>(
"console")!=1 : conf.
Get<
bool>(
"null"));
141 if (conf.
Has(
"console") || !conf.
Get<
bool>(
"null"))
148 if (conf.
Has(
"log") && !conf.
Get<
bool>(
"no-log"))
150 #if BOOST_VERSION < 104600 151 const fs::path file = fs::path(conf.
Get<
string>(
"log")).filename();
153 const fs::path file = fs::path(conf.
Get<
string>(
"log")).filename();
155 if (!wout.
OpenLogFile((path/file).string(), conf.
Get<
bool>(
"append-log")))
156 win <<
kYellow <<
"WARNING - Couldn't open log-file " << (path/file).string() <<
": " << strerror(errno) << endl;
162 io_service.Write(now,
"/----------------------- Program ------------------------");
163 io_service.Write(now,
"| Program: " PACKAGE_STRING " ("+prgname+
":"+to_string(getpid())+
")");
164 io_service.Write(now,
"| CallPath: "+prgpath);
165 io_service.Write(now,
"| Compiled: " __DATE__
" " __TIME__ );
166 io_service.Write(now,
"| Revision: " REVISION);
170 io_service.Write(now,
"| Start: "+now.
GetAsStr(
"%c"));
171 io_service.Write(now,
"\\----------------------- Options ------------------------");
172 const multimap<string,string> mmap = conf.
GetOptions();
173 for (
auto it=mmap.begin(); it!=mmap.end(); it++)
174 io_service.Write(now,
": "+it->first+(it->second.empty()?
"":
" = ")+it->second);
176 const map<string,string> &args = conf.
GetOptions<
string>(
"arg:");
179 io_service.Write(now,
"------------------------ Arguments ----------------------",
MessageImp::kMessage);
181 for (
auto it=args.begin(); it!=args.end(); it++)
184 str.setf(ios_base::left);
185 str <<
": " << it->first <<
" = " << it->second;
190 io_service.Write(now,
"\\------------------- Evaluating options -----------------");
191 const int rc = io_service.EvalOptions(conf);
195 str <<
"Exit triggered by EvalOptions with rc=" << rc;
203 io_service.Write(now,
"------------- Unrecognized wildcard options -------------",
MessageImp::kWarn);
206 for (
auto it=wco.begin(); it!=wco.end(); it++)
207 if (it->second.length()>max)
208 max = it->second.length();
210 for (
auto it=wco.begin(); it!=wco.end(); it++)
213 str.setf(ios_base::left);
214 str << setw(max+1) << it->second <<
" : " << it->first;
217 io_service.Write(now,
"Unrecognized options found, will exit with rc=127",
MessageImp::kError);
221 io_service.Message(
"==================== Starting main loop =================");
223 if (conf.
Has(
"console") || !conf.
Get<
bool>(
"null"))
229 shell.SetReceiver(io_service);
241 !io_service.MessageQueueEmpty()) && !shell.IsStopped())
245 const vector<string> v1 = conf.
Vec<
string>(
"cmd");
246 for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
247 shell.ProcessLine(*it);
249 const vector<string> v2 = conf.
Vec<
string>(
"exec");
250 for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)
251 shell.Execute(*it, args);
254 if (!conf.
Get<
bool>(
"quit"))
#define PACKAGE_BUGREPORT
Mainloop running, state machine in operation.
A warning, things that somehow might result in unexpected or unwanted bahaviour.
void SetNullOutput(bool n=true)
Switch on or off any physical output to the screen (cout or fWindow)
Adds some functionality to boost::posix_time::ptime for our needs.
A C++ ostream to an ncurses window supporting attributes and colors.
T Get(const std::string &var)
const std::map< std::string, T > GetOptions(const std::string &opt)
std::vector< T > Vec(const std::string &var)
void Setup(const std::string &dns="", const std::string &host="")
An info telling something which can be interesting to know.
Just a message, usually obsolete.
bool Has(const std::string &var)
void Thread(MainImp *io_service, bool dummy, int &rc)
Error, something unexpected happened, but can still be handled by the program.
void Display(bool empty=false)
Display backlog.
#define DIM_VERSION_NUMBER
bool GetNullOutput() const
const std::map< std::string, std::string > & GetWildcardOptions() const
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
bool OpenLogFile(const std::string &filename, bool append=false)
Open a log-file.
const std::string & GetName() const
void SetBacklog(bool n=true)
Switch on or off any storage in the backlog.