-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstation_loc.cpp
More file actions
105 lines (99 loc) · 2.83 KB
/
station_loc.cpp
File metadata and controls
105 lines (99 loc) · 2.83 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
/***************************************************************************
station_loc.cpp - description
-------------------
begin : Sat Dec 14 2002
copyright : (C) 2002 by ARRL
author : Jon Bloom
email : jbloom@arrl.org
revision : $Id$
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "sysconfig.h"
#endif
#include <string.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include "tqsllib.h"
#include "tqslexc.h"
using std::string;
using std::ios;
using std::cerr;
using std::cout;
using std::endl;
int
usage() {
cerr << "Usage: station_loc callsign [dxcc]" << endl;
exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[]) {
try {
string call, dxcc;
if (argc < 2)
usage();
call = argv[1];
if (argc > 2)
dxcc = argv[2];
if (tqsl_init())
throw tqslexc();
tQSL_Location loc;
if (tqsl_initStationLocationCapture(&loc))
throw tqslexc();
if (tqsl_setStationLocationCapturePage(loc, 1))
throw tqslexc();
// We know that the first field of page 1 is always call and the 2nd is DXCC
int nfield;
tqsl_getNumLocationFieldListItems(loc, 0, &nfield);
int i;
for (i = 0; i < nfield; i++) {
char buf[256];
if (tqsl_getLocationFieldListItem(loc, 0, i, buf, sizeof buf))
throw tqslexc();
if (!strcasecmp(buf, call.c_str()))
break;
}
if (i == nfield)
throw myexc(string("Can't init station location for call = ") + call);
if (tqsl_setLocationFieldIndex(loc, 0, i))
throw tqslexc();
if (tqsl_updateStationLocationCapture(loc))
throw tqslexc();
if (dxcc != "") {
int nfield;
tqsl_getNumLocationFieldListItems(loc, 1, &nfield);
//cerr << nfield << endl;
for (i = 0; i < nfield; i++) {
char buf[256];
if (tqsl_setLocationFieldIndex(loc, 1, i))
throw tqslexc();
if (tqsl_getLocationFieldCharData(loc, 1, buf, sizeof buf))
throw tqslexc();
//cerr << buf << endl;
if (!strcasecmp(buf, dxcc.c_str()))
break;
}
if (i == nfield)
throw myexc(string("Can't init location for DXCC = ") + dxcc);
if (tqsl_setLocationFieldIndex(loc, 1, i))
throw tqslexc();
}
int dxcc_idx;
if (tqsl_getLocationFieldIndex(loc, 1, &dxcc_idx))
throw tqslexc();
char buf[256];
if (tqsl_getLocationFieldListItem(loc, 1, dxcc_idx, buf, sizeof buf))
throw tqslexc();
string lname = call + "_auto";
if (tqsl_setStationLocationCaptureName(loc, lname.c_str()))
throw tqslexc();
if (tqsl_saveStationLocationCapture(loc, 1))
throw tqslexc();
tqsl_endStationLocationCapture(&loc);
cout << "Wrote station location for " << call << " - " << buf << endl;
} catch(exception& x) {
cerr << "Aborted: " << x.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}