improved CLookup::Utility

pull/1/head
Tom Early 3 years ago
parent ee0664dab7
commit 99dd9543a3

@ -115,12 +115,12 @@ bool CLookup::LoadContentFile(std::stringstream &ss)
return rval;
}
bool CLookup::Utility(Eaction action)
bool CLookup::Utility(Eaction action, Esource source)
{
std::stringstream ss;
LoadParameters();
auto rval = LoadContentHttp(ss);
auto rval = (Esource::http == source) ? LoadContentHttp(ss) : LoadContentFile(ss);
if (rval)
std::cout << ss.str() << std::endl;
UpdateContent(ss, action);
return rval;
}

@ -25,6 +25,7 @@
#include "Configure.h"
enum class Eaction { normal, parse, error_only };
enum class Esource { http, file };
// compare function for std::map::find
@ -60,7 +61,7 @@ public:
// locks
void Lock(void) { m_Mutex.lock(); }
void Unlock(void) { m_Mutex.unlock(); }
bool Utility(Eaction action);
bool Utility(Eaction action, Esource source);
protected:
std::time_t GetLastModTime();

@ -95,7 +95,7 @@ void CLookupDmr::UpdateContent(std::stringstream &ss, Eaction action)
}
if (Eaction::error_only == action && failed)
{
std::cout << "Bad syntax at line '" << line << "'\n";
std::cout << line << '\n';
}
}
if (Eaction::normal == action)

@ -95,7 +95,7 @@ void CLookupNxdn::UpdateContent(std::stringstream &ss, Eaction action)
}
if (Eaction::error_only == action && failed)
{
std::cout << "Bad syntax at line '" << line << "'\n";
std::cout << line << '\n';
}
}
if (Eaction::normal == action)

@ -66,9 +66,10 @@ void CLookupYsf::UpdateContent(std::stringstream &ss, Eaction action)
}
else if (Eaction::error_only == action)
{
std::cout << "YSF value '" << line << ";' is malformed" << std::endl;
std::cout << line << '\n';
}
}
if (Eaction::normal == action)
std::cout << "DMR Id database size now is " << m_map.size() << std::endl;
}

@ -79,8 +79,6 @@ int main(int argc, char *argv[])
#else // UTILITY is defined
#include <unistd.h>
////////////////////////////////////////////////////////////////////////////////////////
// global objects
@ -92,130 +90,115 @@ CLookupYsf g_LYtr;
static void usage(std::ostream &os, const char *name)
{
os << "Usage: " << name << " [-d | -n | -y] [-p | -q] inifile\n";
os << "Where:\n"
" -d - read the DMR Id http source (default)\n"
" -n - read the NXDN Id http source\n"
" -y - read the YSF Tx/Tx http source\n"
" -p - parse the input, removing bad lines\n"
" -q - parse the input, but only output problem lines in the http source\n"
" infile - an error-free urfd ini file (check it first with inicheck)\n"
"Without -p or -q, no parsing is done and the raw http source is output\n"
<< std::endl;
os << "\nUsage: " << name << " DATABASE SOURCE ACTION INIFILE\n";
os << "DATABASE (choose one)\n"
" dmr : The DmrId <==> Callsign databases.\n"
" nxdn : The NxdnId <==> Callsign databases.\n"
" ysf : The Callsign => Tx/Rx frequency database.\n"
"SOURCE (choose one)\n"
" file : The file specified by the FilePath ini parameter.\n"
" http : The URL specified by the URL ini paramater.\n"
"ACTION (choose one)\n"
" print : Print all lines from the SOURCE that are syntactically correct.\n"
" error : Print only the lines with failed syntax.\n"
"INIFILE : an error-free urfd ini file (check it first with inicheck).\n\n"
"Only the first character of DATABASE, SOURCE and ACTION is read.\n"
"Example: " << name << " y f e urfd.ini # Check your YSF Tx/Rx database file specifed in urfd.ini for syntax errors.\n\n";
}
enum class Edb { none, dmr, nxdn, ysf };
int main(int argc, char *argv[])
{
Edb db = Edb::none;
Eaction action = Eaction::normal;
while (1)
{
auto c = getopt(argc, argv, "dnypq");
if (c < 0)
{
if (1 == argc)
Edb db;
Eaction action;
Esource source;
if (5 != argc)
{
usage(std::cout, argv[0]);
return EXIT_SUCCESS;
}
break;
usage(std::cerr, argv[0]);
return EXIT_FAILURE;
}
else
{
switch (c)
switch (argv[1][0])
{
// define the input souce
case 'd':
if (Edb::none == db)
case 'D':
db = Edb::dmr;
else
{
std::cerr << "You can only select one database!\n";
usage(std::cerr, argv[0]);
return EXIT_FAILURE;
}
break;
case 'n':
if (Edb::none == db)
case 'N':
db = Edb::nxdn;
else
{
std::cerr << "You can only select one database!\n";
usage(std::cerr, argv[0]);
return EXIT_FAILURE;
}
break;
case 'y':
if (Edb::none == db)
case 'Y':
db = Edb::ysf;
else
{
std::cerr << "You can only select one database!\n";
usage(std::cerr, argv[0]);
return EXIT_FAILURE;
}
break;
// define the action
case 'p':
if (Eaction::error_only == action)
default:
std::cout << "Unrecognized DATABASE: " << argv[1];
db = Edb::none;
break;
}
switch (argv[2][0])
{
std::cerr << "You can't specify both -p and -q!\n";
usage(std::cerr, argv[0]);
return EXIT_FAILURE;
case 'h':
case 'H':
source = Esource::http;
break;
case 'f':
case 'F':
source = Esource::file;
break;
default:
std::cerr << "Unrecognized SOURCE: " << argv[2] << std::endl;
db = Edb::none;
break;
}
else
switch (argv[3][0])
{
case 'p':
case 'P':
action = Eaction::parse;
break;
case 'q':
if (Eaction::parse == action)
{
std::cerr << "You can't specify both -p and -q!\n";
usage(std::cerr, argv[0]);
return EXIT_FAILURE;
}
else
case 'e':
case 'E':
action = Eaction::error_only;
break;
// finally
default:
usage(std::cerr, argv[0]);
return EXIT_FAILURE;
std::cerr << "Unrecognized ACTION: " << argv[3] << std::endl;
db = Edb::none;
break;
}
}
}
if (optind + 1 != argc)
if (db == Edb::none)
{
std::cerr << argv[0] << ": " << ((optind==argc) ? "No ini file specified!" : "Too many arguments!") << std::endl;
usage(std::cerr, argv[0]);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
if (g_Conf.ReadData(argv[optind]))
if (g_Conf.ReadData(argv[4]))
return EXIT_FAILURE;
if (Edb::none == db)
db = Edb::dmr;
switch (db)
{
case Edb::dmr:
g_LDid.Utility(action);
g_LDid.Utility(action, source);
break;
case Edb::nxdn:
g_LNid.Utility(action);
g_LNid.Utility(action, source);
break;
case Edb::ysf:
g_LYtr.Utility(action);
g_LYtr.Utility(action, source);
break;
}

@ -37,17 +37,18 @@ LDFLAGS=-pthread -lcurl
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
DEPS = $(SRCS:.cpp=.d)
DBUTILOBJS = Configure.o CurlGet.o Lookup.o LookupDmr.o LookupNxdn.o LookupYsf.o YSFNode.o Callsign.o
all : $(EXE) $(INICHECK) $(DBUTIL)
$(EXE) : $(OBJS)
$(CXX) $^ -o $@ $(LDFLAGS)
$(INICHECK) : Configure.cpp CurlGet.cpp
$(CXX) -DINICHECK $(CFLAGS) Configure.cpp CurlGet.cpp -o $(INICHECK) -lcurl
$(INICHECK) : Configure.cpp CurlGet.o
$(CXX) -DINICHECK $(CFLAGS) $< CurlGet.o -o $@ -lcurl
$(DBUTIL) : Main.cpp Configure.cpp CurlGet.cpp Lookup.cpp LookupDmr.cpp LookupNxdn.cpp LookupYsf.cpp YSFNode.cpp Callsign.cpp
$(CXX) -DUTILITY $(CFLAGS) -o dbutil Main.cpp Configure.cpp CurlGet.cpp Lookup.cpp LookupDmr.cpp LookupNxdn.cpp LookupYsf.cpp YSFNode.cpp Callsign.cpp -lcurl
$(DBUTIL) : Main.cpp $(DBUTILOBJS)
$(CXX) -DUTILITY $(CFLAGS) $< $(DBUTILOBJS) -o $@ -lcurl
%.o : %.cpp
$(CXX) $(CFLAGS) -c $< -o $@

Loading…
Cancel
Save

Powered by TurnKey Linux.