-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbard_utils.cpp
More file actions
232 lines (200 loc) · 4.14 KB
/
bard_utils.cpp
File metadata and controls
232 lines (200 loc) · 4.14 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include <iostream>
#include <fstream>
#include <sstream>
#include <cctype>
#include <ctime>
#include <cstring>
#include <ncurses.h>
#include "bard_utils.h"
using namespace std;
// prototypes
void spaceitup(string &s);
void printperson(Person *p);
void printpersonnc(Person *p);
// constructors and things
Person::Person(const Person &obj) {
call = obj.call;
name = obj.name;
location = obj.location;
}
Person::Person() { }
Contact::Contact() {
location = -1;
sigs = 59;
sigr = 59;
}
Time::Time() {
hour = -1;
}
// functions
int Bard::init(string f) {
int tmp, i;
string line, tmps;
ifstream in;
istringstream inss;
Person *p;
Contact *c;
// setup
in.open(f);
MODE = ESC;
// read in user info
userInfo = new User;
getline(in, line);
inss.str(line);
inss >> userInfo->call >> userInfo->name;
inss >> tmp;
for (i = 0; i < tmp; i++) {
inss >> tmps;
spaceitup(tmps);
userInfo->location.push_back(tmps);
}
inss >> tmp;
for (i = 0; i < tmp; i++) {
inss >> tmps;
spaceitup(tmps);
userInfo->radio.push_back(tmps);
}
inss.clear();
getline(in, line);
inss.str(line);
for (i = 0; i < 4; i++) inss >> userInfo->def[i];
memcpy(userInfo->cur, userInfo->def, sizeof(userInfo->def));
inss.clear(); // cleanse
// read in people
while (getline(in, line)) {
p = new Person;
inss.str(line);
// calls
inss >> tmp;
for (i = 0; i < tmp; i++) {
inss >> tmps;
p->call.push_back(tmps);
}
// name
inss >> p->name;
spaceitup(p->name);
// locations
inss >> tmp;
for (i = 0; i < tmp; i++) {
inss >> tmps;
spaceitup(tmps);
p->location.push_back(tmps);
}
// contacts
inss >> tmp;
for (i = 0; i < tmp; i++) {
getline(in, line);
inss.clear();
inss.str(line);
c = new Contact;
//inss >> c->day >> c->month >> c->year >> c->location;
p->contact.push_back(c);
}
// clean up
//printperson(p);
for (i = 0; i < p->call.size(); i++) {
people.insert(make_pair(p->call[i], p));
}
inss.clear();
}
return 0;
}
void spaceitup(string &s) {
for (int i = 0; i < s.size(); i++) {
if (s[i] == '_') s[i] = ' ';
}
}
/*
void printperson(Person *p) {
for (int i = 0; i < p->call.size(); i++) {
if (i == 0) cout << "call: ";
else cout << " previous: ";
cout << p->call[i] << endl;
}
cout << "name: " << p->name << endl;
cout << "locations:\n";
for (int i = 0; i < p->location.size(); i++) {
cout << " " << i+1 << ": " << p->location[i] << endl;
}
cout << "contacts:\n";
for (int i = 0; i < p->contact.size(); i++) {
cout << " date: " << p->contact[i]->day << "."
<< p->contact[i]->month << "."
<< p->contact[i]->year << "\n";
cout << " location: " << p->location[p->contact[i]->location] << endl << endl;
}
cout << endl;
}
*/
void Bard::print() {
map<string, Person*>::iterator pit;
/*
for (int i = 0; i < people.size(); i++) {
printpersonnc(people[i]);
}
*/
for (pit = people.begin(); pit != people.end(); pit++) {
cout << pit->first;
}
}
void Bard::setMode(Mode m) {
MODE = m;
}
Mode Bard::getCurrMode() {
return MODE;
}
Mode Bard::getMode() {
return MODE;
}
void Bard::cap(string &s) {
for (int i = 0; s[i] != '\0'; i++) {
s[i] = toupper(s[i]);
}
}
Person* Bard::search(string name) {
map<string, Person*>::iterator pit;
pit = people.find(name);
if (pit == people.end()) return NULL;
else return pit->second;
}
void Bard::log(Person *p) {
Person *pl = search(p->name);
// create person
if (pl == NULL) {
for (int i = 0; i < p->call.size(); i++) {
people.insert(make_pair(p->call[i], p));
}
}
// add contact if exists
else {
pl->contact.insert(pl->contact.end(),
p->contact.begin(),
p->contact.end());
}
}
Time* Bard::getTime() {
time_t t;
struct tm *ptm;
Time *ts;
ts = new Time;
// get the time
time(&t);
ptm = gmtime(&t);
// set the time
ts->hour = ptm->tm_hour;
ts->minute = ptm->tm_min;
ts->day = ptm->tm_mday;
ts->month = ptm->tm_mon + 1;
ts->year = ptm->tm_year + 1900;
return ts;
}
string Bard::getRadioMode(int i) {
switch (i) {
case 0: return "SSB";
case 1: return "CW";
case 2: return "FM";
case 3: return "AM";
case 4: return "SAT";
default: return "BAD_NUM";
}
}