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; return rval;
} }
bool CLookup::Utility(Eaction action) bool CLookup::Utility(Eaction action, Esource source)
{ {
std::stringstream ss; std::stringstream ss;
LoadParameters(); LoadParameters();
auto rval = LoadContentHttp(ss); auto rval = (Esource::http == source) ? LoadContentHttp(ss) : LoadContentFile(ss);
if (rval) if (rval)
std::cout << ss.str() << std::endl; UpdateContent(ss, action);
return rval; return rval;
} }

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

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

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

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

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

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

Loading…
Cancel
Save

Powered by TurnKey Linux.