17
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
/* ------------------------------------------------------------
21
* Parse various call formats
22
* Convert country data
23
*--------------------------------------------------------------*/
20
/* ------------------------------------------------------------
21
* Parse various call formats
22
* Convert country data
23
*--------------------------------------------------------------*/
25
25
#include "globalvars.h"
26
27
#include "getctydata.h"
30
int getpfxindex(char *checkcallptr)
32
char checkbuffer[17] = "";
33
char checkncall[17] = "";
34
char checkcall[17] = "";
35
char findcall[17] = "";
38
int pfxmax = prefix_count();
40
int i = 0, w = 0, abnormal_call = 0;
45
g_strlcpy(checkcall, checkcallptr, 17);
49
if (strstr(checkcall, "/QRP") != NULL) /* drop QRP suffix */
50
checkcall[strlen(checkcall) - 4] = '\0';
52
if (strstr(checkcall, "/AM") != NULL) // airborne mobile, no country (0), no zone (0)
55
if (strstr(checkcall, "/MM") != NULL) // maritime mobile, no country, no zone
58
strncpy(findcall, checkcall, 16);
60
loc = strcspn(checkcall, "/");
62
if (loc != strlen(checkcall)) {
67
strncpy(call1, checkcall, loc); /* 1st part before '/' */
69
strcpy(call2, checkcall + loc + 1); /* 2nd part after '/' */
71
if (strlen(call2) < strlen(call1)
72
&& strlen(call2) > 1) {
73
sprintf(checkcall, "%s/%s", call2, call1);
75
loc = strcspn(checkcall, "/");
80
strncpy(checkbuffer, (checkcall + loc + 1),
81
(strlen(checkcall) + 1) - loc);
83
if (strlen(checkbuffer) == 1)
84
checkcall[loc] = '\0';
85
if (checkbuffer[0] == 'M' && strlen(checkbuffer) <= 3)
86
checkcall[loc] = '\0';
87
if (checkbuffer[0] == 'Q' && strlen(checkbuffer) == 3) /* /QRP */
88
checkcall[loc] = '\0';
89
if (checkbuffer[0] == 'A' && strlen(checkbuffer) <= 3) /* /A, /AM etc */
90
checkcall[loc] = '\0';
91
if ((strlen(checkbuffer) <= 3) && (checkbuffer[0] <= '9') && (checkbuffer[0] >= '0')) /* /3, etc */
92
portable = checkbuffer[0];
93
loc = strcspn(checkcall, "/");
96
if (loc != strlen(checkcall)) {
99
checkcall[loc] = '\0'; /* "PA/DJ0LN/P */
101
strncpy(checkcall, checkcall, loc + 1);
105
/* ------------------------------------------------------------ */
107
if ((strlen(checkbuffer) == 1) && isdigit(checkbuffer[0])) { /* /3 */
108
for (pp = strlen(checkcall) - 1; pp > 0; pp--) {
109
if (isdigit(checkcall[pp])) {
110
checkcall[pp] = checkbuffer[0];
114
} else if (strlen(checkbuffer) > 1)
115
strcpy(checkcall, checkbuffer);
119
/* -------------check full call exceptions first...--------------------- */
122
if (abnormal_call == 1) {
123
// pa3fwm 20040111: is pp guaranteed to be properly initialized
124
// if/when we get here??
125
// pa0r 20040117: It is not. Code changed...
126
// strncpy(checkncall , findcall, pp);
127
strncpy(checkncall, findcall, sizeof(checkncall) - 1);
129
for (i = 0; i < pfxmax; i++) {
130
pfx = prefix_by_index(i);
131
if (strcmp(checkncall, pfx->pfx) == 0) {
139
for (i = 0; i < pfxmax; i++) {
141
pfx = prefix_by_index(i);
142
if (*pfx->pfx != findcall[0])
145
l = strlen(pfx->pfx);
149
if (strncmp(pfx->pfx, findcall, l) == 0) {
156
if (w < 0 && 0 != strcmp(findcall, checkcall)) {
157
// only if not found in prefix full call exception list
159
for (i = 0; i < pfxmax; i++) {
161
pfx = prefix_by_index(i);
162
if (*pfx->pfx != checkcall[0])
164
l = strlen(pfx->pfx);
167
if (strncmp(pfx->pfx, checkcall, l) == 0) {
177
int getctynr(char *checkcall)
181
w = getpfxindex(checkcall);
184
return prefix_by_index(w)->dxcc_index;
186
return 0; /* no country found */
28
190
int getctydata(char *checkcallptr)
31
char checkbuffer[17] = "";
32
char checkncall[17] = "";
33
char checkcall[17] = "";
34
char findcall[17] = "";
36
int i = 0, w = 0, x = 0 , ii = 0, abnormal_call = 0;
41
strncpy (checkcall, checkcallptr, 16);
47
if (strstr(checkcall, "/QRP") != NULL)
48
checkcall[strlen(checkcall)-4] ='\0';
50
if (strstr(checkcall, "/AM") != NULL) // airborne mobile, no country (0), no zone (0)
53
if (strstr(checkcall, "/MM") != NULL) // maritime mobile, no country, no zone
56
strncpy (findcall, checkcall, 16);
58
loc = strcspn(checkcall, "/");
60
if (loc != strlen(checkcall))
65
strncpy(call1, checkcall, loc);
67
strcpy(call2, checkcall+loc+1);
69
if (strlen(call2) < strlen(call1)
72
sprintf(checkcall, "%s/%s", call2, call1);
74
loc = strcspn(checkcall, "/");
79
strncpy(checkbuffer, (checkcall + loc + 1), (strlen(checkcall) + 1) - loc);
82
if (strlen(checkbuffer) == 1)
83
checkcall[loc] = '\0';
84
if (checkbuffer[0] == 'M' && strlen(checkbuffer) <= 3)
85
checkcall[loc] = '\0';
86
if (checkbuffer[0] == 'Q' && strlen(checkbuffer) == 3) /* /QRP */
87
checkcall[loc] = '\0';
88
if (checkbuffer[0] == 'A' && strlen(checkbuffer) <= 3) /* /A, /AM etc */
89
checkcall[loc] = '\0';
90
if ((strlen(checkbuffer) <= 3) && (checkbuffer[0] <= '9') && (checkbuffer[0] >= '0')) /* /3, etc */
91
portable = checkbuffer[0];
92
loc = strcspn(checkcall, "/");
95
if (loc != strlen(checkcall))
99
checkcall[loc] = '\0'; /* "PA/DJ0LN/P */
102
strncpy(checkcall, checkcall, loc + 1);
108
/* ------------------------------------------------------------*/
111
if ((strlen(checkbuffer) == 1) && isdigit(checkbuffer[0]))
113
for ( pp = strlen(checkcall)-1; pp > 0 ; pp--)
115
if (isdigit(checkcall[pp]))
117
checkcall[pp] = checkbuffer[0];
122
else if (strlen(checkbuffer) > 1)
123
strcpy (checkcall, checkbuffer);
127
if (wpx == 1 || pfxmult == 1) getpx(checkcall);
128
// needed for wpx and other pfx contests...
130
/* -------------check full call exceptions first...----------------------------*/
133
if (abnormal_call == 1)
135
// pa3fwm 20040111: is pp guaranteed to be properly initialized if/when we get here??
192
char checkbuffer[17] = "";
193
char checkncall[17] = "";
194
char checkcall[17] = "";
195
char findcall[17] = "";
198
int pfxmax = prefix_count();
200
int i = 0, w = 0, x = 0, abnormal_call = 0;
201
char portable = '\0';
205
g_strlcpy(checkcall, checkcallptr, 17);
209
if (strstr(checkcall, "/QRP") != NULL) /* drop QRP suffix */
210
checkcall[strlen(checkcall) - 4] = '\0';
212
if (strstr(checkcall, "/AM") != NULL) // airborne mobile, no country (0), no zone (0)
215
if (strstr(checkcall, "/MM") != NULL) // maritime mobile, no country, no zone
218
strncpy(findcall, checkcall, 16);
220
loc = strcspn(checkcall, "/");
222
if (loc != strlen(checkcall)) {
226
strncpy(call1, checkcall, loc); /* 1st part before '/' */
228
strcpy(call2, checkcall + loc + 1); /* 2nd part after '/' */
230
if (strlen(call2) < strlen(call1)
231
&& strlen(call2) > 1) {
232
sprintf(checkcall, "%s/%s", call2, call1);
234
loc = strcspn(checkcall, "/");
239
strncpy(checkbuffer, (checkcall + loc + 1),
240
(strlen(checkcall) + 1) - loc);
242
if (strlen(checkbuffer) == 1)
243
checkcall[loc] = '\0';
244
if (checkbuffer[0] == 'M' && strlen(checkbuffer) <= 3)
245
checkcall[loc] = '\0';
246
if (checkbuffer[0] == 'Q' && strlen(checkbuffer) == 3) /* /QRP */
247
checkcall[loc] = '\0';
248
if (checkbuffer[0] == 'A' && strlen(checkbuffer) <= 3) /* /A, /AM etc */
249
checkcall[loc] = '\0';
250
if ((strlen(checkbuffer) <= 3) && (checkbuffer[0] <= '9') && (checkbuffer[0] >= '0')) /* /3, etc */
251
portable = checkbuffer[0];
252
loc = strcspn(checkcall, "/");
255
if (loc != strlen(checkcall)) {
258
checkcall[loc] = '\0'; /* "PA/DJ0LN/P */
260
strncpy(checkcall, checkcall, loc + 1);
264
/* ------------------------------------------------------------ */
266
if ((strlen(checkbuffer) == 1) && isdigit(checkbuffer[0])) { /* /3 */
267
for (pp = strlen(checkcall) - 1; pp > 0; pp--) {
268
if (isdigit(checkcall[pp])) {
269
checkcall[pp] = checkbuffer[0];
273
} else if (strlen(checkbuffer) > 1)
274
strcpy(checkcall, checkbuffer);
278
if (wpx == 1 || pfxmult == 1)
279
/* needed for wpx and other pfx contests */
282
/* -------------check full call exceptions first...--------------------- */
285
if (abnormal_call == 1) {
286
// pa3fwm 20040111: is pp guaranteed to be properly initialized
287
// if/when we get here??
136
288
// pa0r 20040117: It is not. Code changed...
137
// strncpy(checkncall , findcall, pp);
138
strncpy(checkncall , findcall, sizeof(checkncall) - 1);
140
for (i=0 ; i < MAX_DBLINES ; i++)
142
if (strcmp(checkncall, prefixlines[i]) == 0)
154
for (i=0 ; i < MAX_DBLINES ; i++) {
156
if (prefixlines[i][0]!=findcall[0]) continue;
157
l=strlen(prefixlines[i]);
158
if (l<=bestlen) continue;
159
if (strncmp(prefixlines[i],findcall,l)==0) {
164
if (w>=0) x=dataindex[w];
167
// if (w >= 0 && 0!=strcmp(findcall,checkcall)) // only if not found in prefix full call exception list
168
if (w < 0 && 0!=strcmp(findcall,checkcall)) // only if not found in prefix full call exception list
169
// pa3fwm 20040111: is this really right? shouldn't it be w<0 ?
170
// pa0r 20040117: It should indeed be w < 0.
173
for (i=0 ; i < MAX_DBLINES ; i++) {
175
if (prefixlines[i][0]!=checkcall[0]) continue;
176
l=strlen(prefixlines[i]);
177
if (l<=bestlen) continue;
178
if (strncmp(prefixlines[i],checkcall,l)==0) {
183
if (w>=0) x=dataindex[w];
185
// pa3fwm, 20040113: it seems there is no guarantee that w>=0 when we get here; or is that guarantee implicit by completeness of the prefix list?
186
// pa0r, 20040117: it will be -1 if there is a non-existing prefix in the cty.dat file.
187
// so let's use the 'normal' pfx in that case (x defaults to 0).
188
// if (strlen(zonearray[w]) > 0) {
189
if (w > 0 && strlen(zonearray[w]) > 0) {
190
strncpy (cqzone, zonearray[w], 2);
191
strncpy (ituzone, ituarray[w], 2);
194
strncpy(cqzone, datalines[x] + 26, 2);
195
strncpy(ituzone, datalines[x] + 31, 2);
198
for (ii=0; ii < strlen(checkcall); ii++) {
199
if (checkcall[ii] == '7' || checkcall[ii] == '6') {
200
strncpy (cqzone, "03",2);
202
} else if (checkcall[ii] == '5' || checkcall[ii] == '8' || checkcall[ii] == '9' || checkcall[ii] == '0') {
203
strncpy (cqzone, "04",2);
205
} else if (checkcall[ii] == '1' || checkcall[ii] == '2' || checkcall[ii] == '3' || checkcall[ii] == '4') {
206
strncpy (cqzone, "05",2);
214
for (ii=0; ii < strlen(checkcall); ii++) {
215
if (checkcall[ii] == '7' ) {
216
strncpy (cqzone, "03",2);
218
} else if (checkcall[ii] == '3' || checkcall[ii] == '4' || checkcall[ii] == '5' || checkcall[ii] == '6') {
219
strncpy (cqzone, "04",2);
221
} else strncpy (cqzone, "05",2);
228
strcpy(zone_export, cqzone);
230
strcpy(zone_export, ituzone);
232
strncpy (ituzone, ituarray[w], 2);
236
strncpy (continent, datalines[countrynr]+ 36 ,3);
289
// strncpy(checkncall , findcall, pp);
290
strncpy(checkncall, findcall, sizeof(checkncall) - 1);
292
for (i = 0; i < pfxmax; i++) {
293
pfx = prefix_by_index(i);
294
if (strcmp(checkncall, pfx->pfx) == 0) {
303
for (i = 0; i < pfxmax; i++) {
305
pfx = prefix_by_index(i);
306
if (*pfx->pfx != findcall[0])
309
l = strlen(pfx->pfx);
313
if (strncmp(pfx->pfx, findcall, l) == 0) {
319
x = prefix_by_index(w)->dxcc_index;
322
if (w < 0 && 0 != strcmp(findcall, checkcall)) {
323
// only if not found in prefix full call exception list
325
for (i = 0; i < pfxmax; i++) {
327
pfx = prefix_by_index(i);
328
if (*pfx->pfx != checkcall[0])
330
l = strlen(pfx->pfx);
333
if (strncmp(pfx->pfx, checkcall, l) == 0) {
339
x = prefix_by_index(w)->dxcc_index;
343
sprintf(cqzone, "%02d", prefix_by_index(w) -> cq);
344
sprintf(ituzone, "%02d", prefix_by_index(w) -> itu);
348
strcpy(zone_export, cqzone);
350
strcpy(zone_export, ituzone);
352
// w must be >0 tb 17feb2011
353
// strncpy(ituzone, ituarray[w], 2);
356
strncpy(continent, dxcc_by_index(countrynr) -> continent , 3);
242
362
/* --------------------for background ---------------------------*/
244
364
// pa3fwm, 20040113: I didn't "clean" this part yet
245
int getctydata2(char *checkcall)
247
extern char prefixlines[MAX_DBLINES][17];
248
extern char cqzone[];
249
extern char zonearray[MAX_DBLINES][3];
250
extern int dataindex[MAX_DBLINES];
251
extern int countrynr;
252
extern char datalines[MAX_DATALINES][81];
254
char checkbuffer[17] = "";
255
char membuffer[17] = "";
258
int i = 0, w = 0, x = 0;
260
char portable = '\0';
264
strncpy (membuffer, checkcall, 16);
267
if (strstr(checkcall, "/QRP") != NULL) //strip the qrp
268
checkcall[strlen(checkcall)-4] ='\0';
270
loc = strcspn(checkcall, "/");
274
strncpy(checkbuffer, (checkcall + loc + 1), (strlen(checkcall) + 1) - loc);
277
if (strlen(checkbuffer) == 1)
278
checkcall[loc] = '\0';
279
if (checkbuffer[0] == 'M' && strlen(checkbuffer) <= 3)
280
checkcall[loc] = '\0';
281
if (checkbuffer[0] == 'Q' && strlen(checkbuffer) == 3) /* /QRP */
282
checkcall[loc] = '\0';
283
if (checkbuffer[0] == 'A' && strlen(checkbuffer) <= 3) /* /A, /AM etc */
284
checkcall[loc] = '\0';
285
if ((strlen(checkbuffer) <= 3) && (checkbuffer[0] <= 57) && (checkbuffer[0] >= 48)) /* /3, etc */
286
portable = checkbuffer[0];
289
loc = strcspn(checkcall, "/");
292
if (loc != strlen(checkcall)){
295
checkcall[loc] = '\0'; /* "PA/DJ0LN/P */
299
strncpy(checkcall, checkcall, loc + 1);
304
/* ------------------------------------------------------------*/
307
if (strlen(checkbuffer) == 1) { /* /3 */
308
for ( pp = strlen(checkcall)-1; pp > 0 ; pp--) {
310
if ((checkcall[pp] <= '9') && (checkcall[pp] >= '0'))
311
if ((checkbuffer[0] <= '9')&&(checkbuffer[0] >= '0')){
312
checkcall[pp] = checkbuffer[0];
316
} else if (strlen(checkbuffer) > 1)
317
strcpy (checkcall, checkbuffer);
323
/* ------------------------------------------------------------*/
327
for (pp = 1; pp <= strlen(checkcall); pp++) {
329
strncpy(checkncall , checkcall, pp);
333
for (i=0 ; i <= MAX_DBLINES ; i++){
336
if ((strncmp(checkncall, prefixlines[i] , strlen(prefixlines[i])) == 0)) {
338
if (strlen(checkncall) == strlen(prefixlines[i])){
350
if (strlen(zonearray[w]) > 0) {
352
strncpy (cqzone, zonearray[w], 2);
354
else strncpy(cqzone, datalines[x] + 26, 2);
358
strcpy(checkcall, membuffer);
365
int getctydata2(char *checkcall)
367
extern char cqzone[];
368
extern int countrynr;
370
char checkbuffer[17] = "";
371
char membuffer[17] = "";
375
int pfxmax = prefix_count();
376
int i = 0, w = 0, x = 0;
377
char portable = '\0';
381
strncpy(membuffer, checkcall, 16);
384
if (strstr(checkcall, "/QRP") != NULL) //strip the qrp
385
checkcall[strlen(checkcall) - 4] = '\0';
387
loc = strcspn(checkcall, "/");
391
strncpy(checkbuffer, (checkcall + loc + 1),
392
(strlen(checkcall) + 1) - loc);
394
if (strlen(checkbuffer) == 1)
395
checkcall[loc] = '\0';
396
if (checkbuffer[0] == 'M' && strlen(checkbuffer) <= 3)
397
checkcall[loc] = '\0';
398
if (checkbuffer[0] == 'Q' && strlen(checkbuffer) == 3) /* /QRP */
399
checkcall[loc] = '\0';
400
if (checkbuffer[0] == 'A' && strlen(checkbuffer) <= 3) /* /A, /AM etc */
401
checkcall[loc] = '\0';
402
if ((strlen(checkbuffer) <= 3) && (checkbuffer[0] <= 57) && (checkbuffer[0] >= 48)) /* /3, etc */
403
portable = checkbuffer[0];
406
loc = strcspn(checkcall, "/");
408
if (loc != strlen(checkcall)) {
411
checkcall[loc] = '\0'; /* "PA/DJ0LN/P */
414
strncpy(checkcall, checkcall, loc + 1);
419
/* ------------------------------------------------------------ */
421
if (strlen(checkbuffer) == 1) { /* /3 */
422
for (pp = strlen(checkcall) - 1; pp > 0; pp--) {
424
if ((checkcall[pp] <= '9') && (checkcall[pp] >= '0'))
425
if ((checkbuffer[0] <= '9') && (checkbuffer[0] >= '0')) {
426
checkcall[pp] = checkbuffer[0];
430
} else if (strlen(checkbuffer) > 1)
431
strcpy(checkcall, checkbuffer);
435
/* ------------------------------------------------------------ */
439
for (pp = 1; pp <= strlen(checkcall); pp++) {
441
strncpy(checkncall, checkcall, pp);
442
checkncall[pp] = '\0';
444
for (i = 0; i < pfxmax; i++) {
446
pfx = prefix_by_index(i);
449
(checkncall, pfx->pfx, strlen(pfx->pfx)) == 0)) {
451
if (strlen(checkncall) == strlen(pfx->pfx)) {
461
sprintf(cqzone, "%02d", prefix_by_index(w) -> cq);
465
strcpy(checkcall, membuffer);