-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastructure.cpp
129 lines (112 loc) · 3.53 KB
/
datastructure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Gpredict: Interface module for Gpredict by Alexandru Csete, OZ9AEC
Gcontrols: Add-on module by Lisa Nelson AK7WS to control Radio
and custom ASCII rotor.
Copyright (C) 2018-2025 Lisa Nelson AK7WS.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, visit http://www.fsf.org/
*/
#include "datastructure.h"
#include "mainwindow.h"
#include <QString>
#include <QDebug>
DataStructure::DataStructure()
{
ComTermChars = "";
Resp = NULL;
}
//-----------------------------------------------------------------------
void DataStructure::Clear()
{
ComTermChars = "";
Resp = NULL;
}
//-----------------------------------------------------------------------
void DataStructure::AddStructComTerms(QString str)
{
ComTermChars = str;
}
//-----------------------------------------------------------------------
void DataStructure::AddStructResps(QString str1,QString str2)
{
if (Resp == NULL)
{
Resp = new RespStruct;
Resp->instr = str1;
Resp->outstr = str2;
Resp->next = NULL;
}
else
{
RespStruct *ptr = Resp; // Start at the beginning.
while (ptr->next != NULL)
{
ptr = ptr->next;
}
ptr->next = new RespStruct;
ptr = ptr->next; // Now on the new resp box
ptr->instr = str1;
ptr->outstr = str2;
ptr->next = NULL;
}
}
//-----------------------------------------------------------------------
void DataStructure::PrintResps()
{
RespStruct *ptr = Resp; // Start at the beginning.
while (ptr != NULL)
{
qDebug() << "--->" << ptr->instr << " --->" << ptr->outstr;
ptr = ptr->next;
}
}
//-----------------------------------------------------------------------
bool DataStructure::GetResponseCode(QString resp, QString *code)
{
QString s;
RespStruct *ptr = Resp; // Start at the beginning.
//qDebug() << "getresponse has this:" << resp;
while ((ptr != NULL) && (resp != ptr->instr))
if (resp.indexOf(ptr->instr))
ptr = ptr->next;
if (ptr != NULL && resp == ptr->instr)
{
*code = ptr->outstr;
return true;
}
return false;
}
//-----------------------------------------------------------------------
RespStruct *DataStructure::GetNextRespCode(RespStruct *p,QString *resp, QString *code)
{
RespStruct *ptr = p; // Start at the passed pointer.
if (ptr == NULL)
{
*code = "NULL";
return NULL; // Don't deal with NULL pointer!
}
else
{
while ((ptr != NULL) && (*resp != ptr->instr))
ptr = ptr->next; // Search through list.
if (ptr == NULL)
{
*code = "NULL";
return NULL; // Didn't find any more...
}
if (ptr->instr == *resp)
{ // Got a match!
*code = ptr->outstr;
return ptr->next; // Let calling function know where we left off.
}
}
return NULL; // Make compiler happy with a return.
}