From 5c70a67ac41640d103ba30b68ccbf32c4adcf6d3 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sun, 30 Dec 2018 11:27:37 -0700 Subject: [PATCH] improved assigned_module treatment --- QnetDVAP.cpp | 68 +++++++++++++++++++++++++++++++++++------------ QnetDVRPTR.cpp | 60 ++++++++++++++++++++++++++++++------------ QnetITAP.cpp | 66 ++++++++++++++++++++++++++++++++-------------- QnetRelay.cpp | 71 +++++++++++++++++++++++++++++++++++--------------- 4 files changed, 192 insertions(+), 73 deletions(-) diff --git a/QnetDVAP.cpp b/QnetDVAP.cpp index d62e5a0..09ddb9d 100644 --- a/QnetDVAP.cpp +++ b/QnetDVAP.cpp @@ -167,16 +167,39 @@ static bool read_config(const char *cfgFile) const std::string estr; // an empty string std::string type; std::string dvap_path("module_"); - dvap_path.append(1, 'a' + assigned_module); - if (cfg.KeyExists(dvap_path)) { - cfg.GetValue(dvap_path, estr, type, 1, 16); - if (type.compare("dvap")) { - fprintf(stderr, "assigned module '%c' type is not 'dvap'\n", 'a' + assigned_module); + if (0 > assigned_module) { + // we need to find the lone dvap module + for (int i=0; i<3; i++) { + std::string test(dvap_path); + test.append(1, 'a'+i); + if (cfg.KeyExists(test)) { + cfg.GetValue(test, estr, type, 1, 16); + if (type.compare("dvap")) { + fprintf(stderr, "%s = '%s', expecting 'dvap'!\n", test.c_str(), type.c_str()); + return true; + } + dvap_path.assign(test); + assigned_module = i; + break; + } + } + if (0 > assigned_module) { + fprintf(stderr, "Error: no 'dvap' module found\n!"); return true; } } else { - fprintf(stderr, "%s is not defined!\n", dvap_path.c_str()); - return true; + // make sure dvap module is defined + dvap_path.append(1, 'a' + assigned_module); + if (cfg.KeyExists(dvap_path)) { + cfg.GetValue(dvap_path, estr, type, 1, 16); + if (type.compare("dvap")) { + fprintf(stderr, "%s = %s is not 'dvap' type!\n", dvap_path.c_str(), type.c_str()); + return true; + } + } else { + fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module); + return true; + } } RPTR_MOD = 'A' + assigned_module; cfg.GetValue(dvap_path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX); @@ -502,33 +525,44 @@ int main(int argc, const char **argv) setvbuf(stdout, NULL, _IOLBF, 0); printf("dvap_rptr VERSION %s\n", VERSION); - if (argc != 3) { - fprintf(stderr, "Usage: %s assigned_module dvap_rptr.cfg\n", argv[0]); + if (argc != 2) { + fprintf(stderr, "Usage: %s dvap_rptr.cfg\n", argv[0]); return 1; } + if ('-' == argv[1][0]) { + printf("\nQnetDVAP Version #%s Copyright (C) 2018-2019 by Thomas A. Early N7TAE\n", DVAP_VERSION); + printf("QnetDVAP comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); + printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); + return 0; + } + + const char *qn = strstr(argv[0], "qndvap"); + if (NULL == qn) { + fprintf(stderr, "Error finding 'qndvap' in %s!\n", argv[0]); + return 1; + } + qn += 6; + switch (argv[1][0]) { - case '0': + case NULL: + assigned_module = -1; + break; case 'a': - case 'A': assigned_module = 0; break; - case '1': case 'b': - case 'B': assigned_module = 1; break; - case '2': case 'c': - case 'C': assigned_module = 2; break; default: - fprintf(stderr, "ERROR: '%s' is not a valid module\nassigned module must be 0, a, A, 1, b, B, 2, c or C\n", argv[1]); + fprintf(stderr, "ERROR: '%s' is not a valid module\nassigned module must be a, b or c\n", argv[1]); return 1; } - if (read_config(argv[2])) { + if (read_config(argv[1])) { printf("Failed to process config file %s\n", argv[2]); return 1; } diff --git a/QnetDVRPTR.cpp b/QnetDVRPTR.cpp index c9b939e..44520f1 100644 --- a/QnetDVRPTR.cpp +++ b/QnetDVRPTR.cpp @@ -1820,15 +1820,39 @@ static bool read_config(const char *cfgFile) const std::string estr; // an empty string std::string type; std::string path("module_"); - path += ('a' + assigned_module); - if (cfg.KeyExists(path)) { - if (cfg.GetValue(path, estr, type, 1, 16) || type.compare("dvrptr")) { - fprintf(stderr, "%s = %s is not 'dvrptr'!\n", path.c_str(), type.c_str()); + if (0 > assigned_module) { + // we need to find the lone dvrptr module + for (int i=0; i<3; i++) { + std::string test(path); + test.append(1, 'a'+i); + if (cfg.KeyExists(test)) { + cfg.GetValue(test, estr, type, 1, 16); + if (type.compare("dvrptr")) { + fprintf(stderr, "%s = '%s', expecting 'dvrptr'!\n", test.c_str(), type.c_str()); + return true; + } + path.assign(test); + assigned_module = i; + break; + } + } + if (0 > assigned_module) { + fprintf(stderr, "Error: no 'dvrptr' module found\n!"); return true; } } else { - fprintf(stderr, "module %c is not defined\n", 'a' + assigned_module); - return 1; + // make sure dvrptr module is defined + path.append(1, 'a' + assigned_module); + if (cfg.KeyExists(path)) { + cfg.GetValue(path, estr, type, 1, 16); + if (type.compare("dvrptr")) { + fprintf(stderr, "%s = %s is not 'dvrptr' type!\n", path.c_str(), type.c_str()); + return true; + } + } else { + fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module); + return true; + } } DVRPTR_MOD = 'A' + assigned_module; cfg.GetValue(path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX); @@ -2473,33 +2497,37 @@ int main(int argc, const char **argv) setvbuf(stdout, NULL, _IOLBF, 0); printf("dvrptr VERSION %s\n", VERSION); - if (argc != 3) { - fprintf(stderr, "Usage: %s assigned_module dvrptr.cfg\n", argv[0]); + if (argc != 2) { + fprintf(stderr, "Usage: %s dvrptr.cfg\n", argv[0]); return 1; } + if ('-' == argv[1][0]) { + printf("\nQnetDVRPTR Version #%s Copyright (C) 2018-2019 by Thomas A. Early N7TAE\n", DVRPTR_VERSION); + printf("QnetDVRPTR comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); + printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); + return 0; + } + switch (argv[1][0]) { - case '0': + case NULL: + assigned_module = -1; + break; case 'a': - case 'A': assigned_module = 0; break; - case '1': case 'b': - case 'B': assigned_module = 1; break; - case '2': case 'c': - case 'C': assigned_module = 2; break; default: - fprintf(stderr, "ERROR: '%s' is not a valid module\nassigned module must be 0, a, A, 1, b, B, 2, c or C\n", argv[1]); + fprintf(stderr, "ERROR: '%s' is not a valid module\nassigned module must be a, b or c\n", argv[1]); return 1; } - if (read_config(argv[2])) { + if (read_config(argv[1])) { fprintf(stderr, "Failed to process config file %s\n", argv[2]); return 1; } diff --git a/QnetITAP.cpp b/QnetITAP.cpp index f2b1965..c3deeb3 100644 --- a/QnetITAP.cpp +++ b/QnetITAP.cpp @@ -464,16 +464,39 @@ bool CQnetITAP::ReadConfig(const char *cfgFile) const std::string estr; // an empty string std::string type; std::string itap_path("module_"); - itap_path.append(1, 'a' + assigned_module); - if (cfg.KeyExists(itap_path)) { - cfg.GetValue(itap_path, estr, type, 1, 16); - if (type.compare("itap")) { - fprintf(stderr, "assigned module %c is not 'itap'\n", 'a' + assigned_module); + if (0 > assigned_module) { + // we need to find the lone itap module + for (int i=0; i<3; i++) { + std::string test(itap_path); + test.append(1, 'a'+i); + if (cfg.KeyExists(test)) { + cfg.GetValue(test, estr, type, 1, 16); + if (type.compare("itap")) { + fprintf(stderr, "%s = '%s', expecting 'itap'!\n", test.c_str(), type.c_str()); + return true; + } + itap_path.assign(test); + assigned_module = i; + break; + } + } + if (0 > assigned_module) { + fprintf(stderr, "Error: no 'itap' module found\n!"); return true; } } else { - fprintf(stderr, "assigned module %c not defined\n", 'a' + assigned_module); - return true; + // make sure itap module is defined + itap_path.append(1, 'a' + assigned_module); + if (cfg.KeyExists(itap_path)) { + cfg.GetValue(itap_path, estr, type, 1, 16); + if (type.compare("itap")) { + fprintf(stderr, "%s = %s is not 'itap' type!\n", itap_path.c_str(), type.c_str()); + return true; + } + } else { + fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module); + return true; + } } RPTR_MOD = 'A' + assigned_module; @@ -556,41 +579,46 @@ void CQnetITAP::calcPFCS(const unsigned char *packet, unsigned char *pfcs) int main(int argc, const char **argv) { setbuf(stdout, NULL); - if (3 != argc) { - fprintf(stderr, "usage: %s assigned_module path_to_config_file\n", argv[0]); + if (2 != argc) { + fprintf(stderr, "usage: %s path_to_config_file\n", argv[0]); return 1; - } else { - printf("\nQnetITAP Version #%s Copyright (C) 2018 by Thomas A. Early N7TAE\n", ITAP_VERSION); + } + + if ('-' == argv[1][0]) { + printf("\nQnetITAP Version #%s Copyright (C) 2018-2019 by Thomas A. Early N7TAE\n", ITAP_VERSION); printf("QnetITAP comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); return 0; } + const char *qn = strstr(argv[0], "qnitap"); + if (NULL == qn) { + fprintf(stderr, "Error finding 'qnitap' in %s!\n", argv[0]); + return 1; + } + qn += 6; int assigned_module; switch (argv[1][0]) { - case '0': + case NULL: + assigned_module = -1; + break; case 'a': - case 'A': assigned_module = 0; break; - case '1': case 'b': - case 'B': assigned_module = 1; break; - case '2': case 'c': - case 'C': assigned_module = 2; break; default: - fprintf(stderr, "assigned module must be 0, a, A, 1, b, B, 2, c or C\n"); + fprintf(stderr, "assigned module must be a, b or c\n"); return 1; } CQnetITAP qnitap(assigned_module); - qnitap.Run(argv[2]); + qnitap.Run(argv[1]); printf("%s is closing.\n", argv[0]); diff --git a/QnetRelay.cpp b/QnetRelay.cpp index b09f435..cb57f53 100644 --- a/QnetRelay.cpp +++ b/QnetRelay.cpp @@ -355,18 +355,42 @@ bool CQnetRelay::ReadConfig(const char *cfgFile) return true; const std::string estr; // an empty GetDefaultString - std::string type; + std::string mmdvm_path("module_"); - mmdvm_path.append(1, 'a' + assigned_module); - if (cfg.KeyExists(mmdvm_path)) { - cfg.GetValue(mmdvm_path, estr, type, 1, 16); - if (type.compare("mmdvm")) { - fprintf(stderr, "%s = %s is not 'mmdvm' type!\n", mmdvm_path.c_str(), type.c_str()); + std::string type; + if (0 > assigned_module) { + // we need to find the lone mmdvm module + for (int i=0; i<3; i++) { + std::string test(mmdvm_path); + test.append(1, 'a'+i); + if (cfg.KeyExists(test)) { + cfg.GetValue(test, estr, type, 1, 16); + if (type.compare("mmdvm")) { + fprintf(stderr, "%s = '%s', expecting 'mmdvm'!\n", test.c_str(), type.c_str()); + return true; + } + mmdvm_path.assign(test); + assigned_module = i; + break; + } + } + if (0 > assigned_module) { + fprintf(stderr, "Error: no 'mmdvm' module found\n!"); return true; } } else { - fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module); - return true; + // make sure mmdvm module is defined + mmdvm_path.append(1, 'a' + assigned_module); + if (cfg.KeyExists(mmdvm_path)) { + cfg.GetValue(mmdvm_path, estr, type, 1, 16); + if (type.compare("mmdvm")) { + fprintf(stderr, "%s = %s is not 'mmdvm' type!\n", mmdvm_path.c_str(), type.c_str()); + return true; + } + } else { + fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module); + return true; + } } RPTR_MOD = 'A' + assigned_module; @@ -394,41 +418,46 @@ void CQnetRelay::SignalCatch(const int signum) int main(int argc, const char **argv) { setbuf(stdout, NULL); - if (3 != argc) { - fprintf(stderr, "usage: %s assigned_module path_to_config_file\n", argv[0]); + if (2 != argc) { + fprintf(stderr, "usage: %s path_to_config_file\n", argv[0]); return 1; - } else { - printf("\nQnetRelay Version #%s Copyright (C) 2018 by Thomas A. Early N7TAE\n", RELAY_VERSION); + } + + if ('-' == argv[1][0]) { + printf("\nQnetRelay Version #%s Copyright (C) 2018-2019 by Thomas A. Early N7TAE\n", RELAY_VERSION); printf("QnetRelay comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); return 0; } + const char *qn = strstr(argv[0], "qnrelay"); + if (NULL == qn) { + fprintf(stderr, "Error finding 'qnrelay' in %s!\n", argv[0]); + return 1; + } + qn += 7; int module; - switch (argv[1][0]) { - case '0': + switch (*qn) { + case NULL: + module = -1; + break; case 'a': - case 'A': module = 0; break; - case '1': case 'b': - case 'B': module = 1; break; - case '2': case 'c': - case 'C': module = 2; break; default: - fprintf(stderr, "assigned module must be 0, a, A, 1, b, B, 2, c or C\n"); + fprintf(stderr, "assigned module must be a, b or c\n"); return 1; } CQnetRelay qnmmdvm(module); - bool trouble = qnmmdvm.Run(argv[2]); + bool trouble = qnmmdvm.Run(argv[1]); printf("%s is closing.\n", argv[0]);