|
|
@ -9,7 +9,12 @@
|
|
|
|
class ArgParser
|
|
|
|
class ArgParser
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ArgParser() : m_use_console(false), m_logFile() {}
|
|
|
|
ArgParser()
|
|
|
|
|
|
|
|
: m_print_to_console(false)
|
|
|
|
|
|
|
|
, m_print_timestamp(false)
|
|
|
|
|
|
|
|
, m_logFile()
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void printUsage(bool cout = true)
|
|
|
|
void printUsage(bool cout = true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
|
|
|
std::ostringstream oss;
|
|
|
@ -18,6 +23,7 @@ public:
|
|
|
|
<< "Logs the input (till EOF) to the console or to a file.\n"
|
|
|
|
<< "Logs the input (till EOF) to the console or to a file.\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "Options:\n"
|
|
|
|
<< "Options:\n"
|
|
|
|
|
|
|
|
<< " -t, prefix lines with timestamp\n"
|
|
|
|
<< " -c, log to console\n"
|
|
|
|
<< " -c, log to console\n"
|
|
|
|
<< " -f FILE log to FILE\n"
|
|
|
|
<< " -f FILE log to FILE\n"
|
|
|
|
<< " -h print this help\n"
|
|
|
|
<< " -h print this help\n"
|
|
|
@ -31,13 +37,17 @@ public:
|
|
|
|
else
|
|
|
|
else
|
|
|
|
std::cerr << oss.str();
|
|
|
|
std::cerr << oss.str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int parse(int argc, char* argv[])
|
|
|
|
int parse(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int c;
|
|
|
|
while ((c = getopt (argc, argv, "cf:h")) != -1) {
|
|
|
|
while ((c = getopt (argc, argv, "ctf:h")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
case 'c':
|
|
|
|
m_use_console = true;
|
|
|
|
m_print_to_console = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
|
|
|
|
m_print_timestamp = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
case 'f':
|
|
|
|
m_logFile = std::string(optarg);
|
|
|
|
m_logFile = std::string(optarg);
|
|
|
@ -50,22 +60,24 @@ public:
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((m_use_console && !m_logFile.empty()) ||
|
|
|
|
if ((m_print_to_console && !m_logFile.empty()) ||
|
|
|
|
(!m_use_console && m_logFile.empty())) {
|
|
|
|
(!m_print_to_console && m_logFile.empty())) {
|
|
|
|
printUsage(false);
|
|
|
|
printUsage(false);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool useConsole() const { return m_use_console; }
|
|
|
|
bool printToConsole() const { return m_print_to_console; }
|
|
|
|
|
|
|
|
bool printTimestamp() const { return m_print_timestamp; }
|
|
|
|
std::string logFile() const { return m_logFile; }
|
|
|
|
std::string logFile() const { return m_logFile; }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
int m_argc;
|
|
|
|
int m_argc;
|
|
|
|
char** m_argv;
|
|
|
|
char** m_argv;
|
|
|
|
|
|
|
|
|
|
|
|
bool m_use_console;
|
|
|
|
bool m_print_to_console;
|
|
|
|
|
|
|
|
bool m_print_timestamp;
|
|
|
|
std::string m_logFile;
|
|
|
|
std::string m_logFile;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|