From fbca004944f9e30bcf3b82ad95a48a1f668a9751 Mon Sep 17 00:00:00 2001 From: David Freese Date: Thu, 8 Jan 2009 05:41:52 -0600 Subject: [PATCH] Changes to spotting regex parsing Windows does not recognize '\2' reference tag in regular expression defined in pskrep.cxx. Changed to combination of regexec and string find processing for required result. Added modem frequency to spotting call when logging or forcing a spot report. --- src/dialogs/Viewer.cxx | 2 ++ src/dialogs/fl_digi.cxx | 15 +++++++----- src/logger/logger.cxx | 3 ++- src/spot/pskrep.cxx | 12 +++++++-- src/spot/spot.cxx | 54 ++++++++++++++++++++++++++++++++--------- 5 files changed, 66 insertions(+), 20 deletions(-) diff --git a/src/dialogs/Viewer.cxx b/src/dialogs/Viewer.cxx index afe7d0a2..5a19575a 100644 --- a/src/dialogs/Viewer.cxx +++ b/src/dialogs/Viewer.cxx @@ -14,6 +14,8 @@ #include "flinput2.h" #include "spot.h" +#include "debug.h" + #include #include #include diff --git a/src/dialogs/fl_digi.cxx b/src/dialogs/fl_digi.cxx index 42026ea6..43d84457 100644 --- a/src/dialogs/fl_digi.cxx +++ b/src/dialogs/fl_digi.cxx @@ -1433,7 +1433,8 @@ void cb_QRZ(Fl_Widget *b, void *) break; case FL_RIGHT_MOUSE: if (quick_choice(string("Spot \"").append(inpCall->value()).append("\"?").c_str(), false)) - spot_manual(inpCall->value(), inpLoc->value()); +// spot_manual(inpCall->value(), inpLoc->value()); + spot_manual(inpCall->value(), inpLoc->value(), active_modem->get_freq()); break; default: break; @@ -2879,15 +2880,16 @@ void put_rx_char(unsigned int data) WriteARQ(data); + bool viewer = (mode >= MODE_PSK_FIRST && mode <= MODE_PSK_LAST && dlgViewer && dlgViewer->visible()); + if (progStatus.spot_recv && !viewer) + spot_recv(data); + string s; if (iscntrl(data)) s = ascii2[data & 0x7F]; - else { + else s += data; - bool viewer = (mode >= MODE_PSK_FIRST && mode <= MODE_PSK_LAST && dlgViewer && dlgViewer->visible()); - if (progStatus.spot_recv && !viewer) - spot_recv(data); - } + if (Maillogfile) Maillogfile->log_to_file(cLogfile::LOG_RX, s); @@ -3099,6 +3101,7 @@ void put_echo_char(unsigned int data) if (progStatus.LOGenabled) logfile->log_to_file(cLogfile::LOG_TX, s); + } void resetRTTY() { diff --git a/src/logger/logger.cxx b/src/logger/logger.cxx index d59b33a9..9f21605d 100644 --- a/src/logger/logger.cxx +++ b/src/logger/logger.cxx @@ -195,7 +195,8 @@ static void send_IPC_log(void) void submit_log(void) { if (progStatus.spot_log) - spot_log(inpCall->value(), inpLoc->value()); +// spot_log(inpCall->value(), inpLoc->value()); + spot_log(inpCall->value(), inpLoc->value(), active_modem->get_freq()); struct tm *tm; time_t t; diff --git a/src/spot/pskrep.cxx b/src/spot/pskrep.cxx index 436e064d..2f5cf8ee 100644 --- a/src/spot/pskrep.cxx +++ b/src/spot/pskrep.cxx @@ -63,8 +63,16 @@ LOG_SET_SOURCE(debug::LOG_SPOTTER); // The regular expression that matches the spotter's buffer when it calls us. // It must define at least two capturing groups, the second of which is the // spotted callsign. -#define CALLSIGN_RE "[[:alnum:]]?[[:alpha:]/]+[[:digit:]]+[[:alnum:]/]+" -#define PSKREP_RE "(de|cq|qrz)[^[:alnum:]/\n]+" "(" CALLSIGN_RE ")" " +(.* +)?\\2[^[:alnum:]]+$" +//#define CALLSIGN_RE "[[:alnum:]]?[[:alpha:]/]+[[:digit:]]+[[:alnum:]/]+" +//#define PSKREP_RE "(de|cq|qrz)[^[:alnum:]/\n]+" "(" CALLSIGN_RE ")" " +(.* +)?\\2[^[:alnum:]]+$" + +#define CALLSIGN_RE "("\ +"[[:alnum:]]+/[[:alnum:]]?[[:alpha:]]+[[:digit:]]+[[:alnum:]/]+"\ +")|("\ +"[[:alnum:]]?[[:alpha:]]+[[:digit:]]+[[:alnum:]/]+"\ +")" + +#define PSKREP_RE "(de|cq|qrz)[^[:alnum:]]+" "(" CALLSIGN_RE ")" " +(.* +)?\\2[^[:alnum:]]+$" // Try to flush the report queue every SEND_INTERVAL seconds. #define SEND_INTERVAL 300 diff --git a/src/spot/spot.cxx b/src/spot/spot.cxx index 0834a1a4..a450fa7d 100644 --- a/src/spot/spot.cxx +++ b/src/spot/spot.cxx @@ -32,8 +32,12 @@ #include "debug.h" #include "spot.h" +#include +using namespace std; + #define SEARCHLEN 32 -#define DECBUFSIZE 8 * SEARCHLEN +//#define DECBUFSIZE 8 * SEARCHLEN +#define DECBUFSIZE 4 * SEARCHLEN using namespace std; @@ -55,10 +59,22 @@ typedef vector cblist_t; static cblist_t cblist; +#define CALLSIGN_RE "("\ +"[[:alnum:]]+/[[:alnum:]]?[[:alpha:]]+[[:digit:]]+[[:alnum:]/]+"\ +")|("\ +"[[:alnum:]]?[[:alpha:]]+[[:digit:]]+[[:alnum:]/]+"\ +")" +#define CALLSIGN_REP CALLSIGN_RE "[^[:alnum:]]+$" + +static fre_t re_call(CALLSIGN_REP, REG_EXTENDED); + void spot_recv(char c, int decoder, int afreq) { static trx_mode last_mode = NUM_MODES + 1; + if (c == '\n' ) c = ' '; + if (c < ' ') return; + switch (decoder) { case -1: // mode without multiple decoders decoder = active_modem->get_mode(); @@ -84,19 +100,35 @@ void spot_recv(char c, int decoder, int afreq) string& buf = buffers[decoder]; buf.reserve(DECBUFSIZE); - buf += c; - string::size_type n = buf.length(); + size_t n = buf.length(); if (n == DECBUFSIZE) buf.erase(0, DECBUFSIZE - SEARCHLEN); - const char* search = buf.c_str() + (n > SEARCHLEN ? n - SEARCHLEN : 0); - for (cblist_t::iterator i = cblist.begin(); i != cblist.end(); ++i) { - if (i->rcb && unlikely(i->re->match(search))) { - const vector& m = i->re->suboff(); - if (m.empty()) - i->rcb(afreq, search, NULL, 0, i->data); - else - i->rcb(afreq, search, &m[0], m.size(), i->data); + buf += toupper(c); + n = buf.length(); + +//#ifdef __CYGWIN__ +// This code segment resolves regexec problems on Windows +// Windows regex compile does not recognize the \2 tag in the reg expression +// (see pskrep.cxx) + + string search = buf.substr(n> SEARCHLEN ? n - SEARCHLEN: 0); + + for (cblist_t::iterator cbl = cblist.begin(); cbl != cblist.end(); ++cbl) { + if (cbl->rcb) { + if (re_call.match(search.c_str())) { + const vector& offset = re_call.suboff(); + if (!offset.empty()) { + size_t pos = offset[0].rm_so; + string call = search.substr(pos); + size_t firstcall = search.find(call); + if (firstcall != pos) + if ( ( (pos = search.find("DE ")) != string::npos && pos < firstcall) || + ( (pos = search.find("CQ ")) != string::npos && pos < firstcall) || + ( (pos = search.find("QRZ ")) != string::npos && pos < firstcall) ) + cbl->rcb(afreq, search.c_str(), &offset[0], offset.size(), cbl->data); + } + } } } }