2014-08-27 18:31:31 +05:30
|
|
|
#include "base/application.h"
|
|
|
|
|
2015-01-16 16:18:19 +05:30
|
|
|
#include <libgen.h>
|
2014-08-27 18:31:31 +05:30
|
|
|
#include <linux/limits.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
using namespace base;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
int
|
|
|
|
application::run(int argc, char **argv)
|
|
|
|
{
|
2015-01-16 16:18:19 +05:30
|
|
|
string cmd = get_basename(argv[0]);
|
2014-08-27 18:31:31 +05:30
|
|
|
|
2014-08-28 16:13:02 +05:30
|
|
|
if (cmd == string("pdata_tools")) {
|
2014-08-27 18:31:31 +05:30
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
|
|
|
if (!argc) {
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = argv[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<command const *>::const_iterator it;
|
|
|
|
for (it = cmds_.begin(); it != cmds_.end(); ++it) {
|
|
|
|
if (cmd == (*it)->get_name())
|
|
|
|
return (*it)->run(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "Unknown command '" << cmd << "'\n";
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
application::usage()
|
|
|
|
{
|
|
|
|
std::cerr << "Usage: <command> <args>\n"
|
|
|
|
<< "commands:\n";
|
|
|
|
|
|
|
|
std::list<command const *>::const_iterator it;
|
|
|
|
for (it = cmds_.begin(); it != cmds_.end(); ++it) {
|
|
|
|
std::cerr << " " << (*it)->get_name() << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2015-01-16 16:18:19 +05:30
|
|
|
application::get_basename(std::string const &path) const
|
2014-08-27 18:31:31 +05:30
|
|
|
{
|
|
|
|
char buffer[PATH_MAX + 1];
|
|
|
|
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
strncpy(buffer, path.c_str(), PATH_MAX);
|
|
|
|
|
|
|
|
return ::basename(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|