~hmatuschek/+junk/qdmr-package

« back to all changes in this revision

Viewing changes to lib/csvreader.cc

  • Committer: Hannes Matuschek
  • Date: 2020-07-07 14:49:41 UTC
  • mfrom: (1.1.4)
  • Revision ID: hmatuschek@gmail.com-20200707144941-niwxz5phhmi0kt1w
* Finalized implementation of MD5R.
* Fixed RD-5R upload.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include "logger.hh"
5
5
 
6
6
#include <QRegExp>
 
7
#include <QDebug>
7
8
 
8
9
QVector< QPair<QRegExp, CSVLexer::Token::TokenType> > CSVLexer::_pattern = {
9
10
  { QRegExp("^([a-zA-Z_][a-zA-Z0-9_]*)"),      CSVLexer::Token::T_KEYWORD },
152
153
}
153
154
 
154
155
bool
 
156
CSVHandler::handleUserDB(bool userdb, qint64 line, qint64 column, QString &errorMessage) {
 
157
  Q_UNUSED(userdb);
 
158
  Q_UNUSED(line);
 
159
  Q_UNUSED(column);
 
160
  Q_UNUSED(errorMessage);
 
161
  return true;
 
162
}
 
163
 
 
164
bool
155
165
CSVHandler::handleDTMFContact(qint64 idx, const QString &name, const QString &num, bool rxTone,
156
166
                              qint64 line, qint64 column, QString &errorMessage)
157
167
{
331
341
    } else if ((CSVLexer::Token::T_KEYWORD == token.type) && ("speech" == token.value.toLower())) {
332
342
      if (! _parse_speech(lexer))
333
343
        return false;
 
344
    } else if ((CSVLexer::Token::T_KEYWORD == token.type) && ("userdb" == token.value.toLower())) {
 
345
      if (! _parse_userdb(lexer))
 
346
        return false;
334
347
    } else if ((CSVLexer::Token::T_KEYWORD == token.type) && ("contact" == token.value.toLower())) {
335
348
      if (! _parse_contacts(lexer))
336
349
        return false;
534
547
}
535
548
 
536
549
bool
 
550
CSVParser::_parse_userdb(CSVLexer &lexer) {
 
551
  CSVLexer::Token token = lexer.next();
 
552
  if (CSVLexer::Token::T_COLON != token.type) {
 
553
    _errorMessage = QString("Parse error @ %1,%2: Unexpected token %3 '%4' expected ':'.")
 
554
        .arg(token.line).arg(token.column).arg(token.type).arg(token.value);
 
555
    return false;
 
556
  }
 
557
 
 
558
  token = lexer.next();
 
559
  if ((CSVLexer::Token::T_KEYWORD != token.type) ||
 
560
      (("on" != token.value.toLower()) && ("off" != token.value.toLower())))
 
561
  {
 
562
    _errorMessage = QString("Parse error @ %1,%2: Unexpected token %3 '%4' expected 'On' or 'Off'.")
 
563
        .arg(token.line).arg(token.column).arg(token.type).arg(token.value);
 
564
    return false;
 
565
  }
 
566
  qint64 line=token.line, column=token.column;
 
567
  bool userdb = ("on" == token.value.toLower());
 
568
 
 
569
  token = lexer.next();
 
570
  if ((CSVLexer::Token::T_NEWLINE != token.type) && (CSVLexer::Token::T_END_OF_STREAM != token.type)){
 
571
    _errorMessage = QString("Parse error @ %1,%2: Unexpected token %3 '%4' expected newline/EOS.")
 
572
        .arg(token.line).arg(token.column).arg(token.type).arg(token.value);
 
573
    return false;
 
574
  }
 
575
 
 
576
  return _handler->handleUserDB(userdb, line, column, _errorMessage);
 
577
}
 
578
 
 
579
bool
537
580
CSVParser::_parse_contacts(CSVLexer &lexer) {
538
581
  // skip rest of header
539
582
  CSVLexer::Token token = lexer.next();
725
768
 
726
769
bool
727
770
CSVParser::_parse_digital_channel(qint64 idx, CSVLexer &lexer) {
 
771
  bool ok=false;
728
772
  CSVLexer::Token token = lexer.next();
729
773
  qint64 line=token.line, column=token.column;
730
774
  if (CSVLexer::Token::T_STRING != token.type) {
740
784
        .arg(token.line).arg(token.column).arg(token.type).arg(token.value);
741
785
    return false;
742
786
  }
743
 
  double rx = token.value.toDouble();
 
787
  double rx = token.value.toDouble(&ok);
 
788
  if (! ok) {
 
789
    _errorMessage = QString("Parse error @ %1,%2: Cannot convert '%3' to double.")
 
790
        .arg(token.line).arg(token.column).arg(token.value);
 
791
    return false;
 
792
  }
744
793
 
745
794
  token = lexer.next();
746
795
  if (CSVLexer::Token::T_NUMBER != token.type) {
748
797
        .arg(token.line).arg(token.column).arg(token.type).arg(token.value);
749
798
    return false;
750
799
  }
751
 
  double tx = token.value.toDouble();
 
800
  double tx = token.value.toDouble(&ok);
 
801
  if (! ok) {
 
802
    _errorMessage = QString("Parse error @ %1,%2: Cannot convert '%3' to double.")
 
803
        .arg(token.line).arg(token.column).arg(token.value);
 
804
    return false;
 
805
  }
752
806
  if (token.value.startsWith('+') || token.value.startsWith('-'))
753
807
    tx = rx + tx;
754
808
 
787
841
        .arg(token.line).arg(token.column).arg(token.type).arg(token.value);
788
842
    return false;
789
843
  }
790
 
  qint64 tot =  (CSVLexer::Token::T_NOT_SET != token.type) ? 0 : token.value.toInt();
 
844
  qint64 tot =  (CSVLexer::Token::T_NOT_SET == token.type) ? 0 : token.value.toInt();
791
845
 
792
846
  bool rxOnly;
793
847
  token = lexer.next();
872
926
  }
873
927
 
874
928
  token = lexer.next();
875
 
  qint64 gps; bool ok;
 
929
  qint64 gps;
876
930
  if (CSVLexer::Token::T_NOT_SET == token.type) {
877
931
    gps = 0;
878
932
  } else if (CSVLexer::Token::T_NUMBER == token.type) {
986
1040
        .arg(token.line).arg(token.column).arg(token.type).arg(token.value);
987
1041
    return false;
988
1042
  }
989
 
  qint64 tot =  (CSVLexer::Token::T_NOT_SET != token.type) ? 0 : token.value.toInt();
 
1043
  qint64 tot =  (CSVLexer::Token::T_NOT_SET == token.type) ? 0 : token.value.toInt();
990
1044
 
991
1045
  bool rxOnly;
992
1046
  token = lexer.next();
1007
1061
  } else if (CSVLexer::Token::T_KEYWORD == token.type) {
1008
1062
    if ("free" == token.value.toLower())
1009
1063
      admit = AnalogChannel::AdmitFree;
1010
 
    else if ("color" == token.value.toLower())
 
1064
    else if ("tone" == token.value.toLower())
1011
1065
      admit = AnalogChannel::AdmitTone;
1012
1066
    else {
1013
1067
      _errorMessage = QString("Parse error @ %1,%2: Unexpected token %3 '%4' expected 'Free', 'Tone'.")
1436
1490
 
1437
1491
 
1438
1492
bool
 
1493
CSVReader::handleUserDB(bool userdb, qint64 line, qint64 column, QString &errorMessage) {
 
1494
  Q_UNUSED(line);
 
1495
  Q_UNUSED(column);
 
1496
  Q_UNUSED(errorMessage);
 
1497
 
 
1498
  if (_link) {
 
1499
    _config->setUploadUserDB(userdb);
 
1500
  }
 
1501
  return true;
 
1502
}
 
1503
 
 
1504
 
 
1505
bool
1439
1506
CSVReader::handleDTMFContact(qint64 idx, const QString &name, const QString &num, bool rxTone,
1440
1507
                             qint64 line, qint64 column, QString &errorMessage)
1441
1508
{