~ubuntu-branches/ubuntu/saucy/tlf/saucy

« back to all changes in this revision

Viewing changes to src/getctydata.c

  • Committer: Package Import Robot
  • Author(s): John T. Nogatch
  • Date: 2013-02-09 14:56:34 UTC
  • mfrom: (1.2.5) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130209145634-de47b40lyf5ntgsu
Tags: 1.1.5-1
* Update from upstream git
* LP: #854080, #514303

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
18
 */
19
19
 
20
 
        /* ------------------------------------------------------------
21
 
        *              Parse various  call  formats
22
 
        *              Convert country data
23
 
        *--------------------------------------------------------------*/
 
20
        /* ------------------------------------------------------------
 
21
         *              Parse various  call  formats
 
22
         *              Convert country data
 
23
         *--------------------------------------------------------------*/
24
24
 
25
25
#include "globalvars.h"
 
26
#include <glib.h>
26
27
#include "getctydata.h"
 
28
#include "dxcc.h"
 
29
 
 
30
int getpfxindex(char *checkcallptr)
 
31
{
 
32
    char checkbuffer[17] = "";
 
33
    char checkncall[17] = "";
 
34
    char checkcall[17] = "";
 
35
    char findcall[17] = "";
 
36
 
 
37
    prefix_data *pfx;
 
38
    int pfxmax = prefix_count();
 
39
 
 
40
    int i = 0, w = 0, abnormal_call = 0;
 
41
    char portable = '\0';
 
42
    int pp = 0;
 
43
    size_t loc;
 
44
 
 
45
    g_strlcpy(checkcall, checkcallptr, 17);
 
46
 
 
47
    portable = '\0';
 
48
 
 
49
    if (strstr(checkcall, "/QRP") != NULL)      /* drop QRP suffix */
 
50
        checkcall[strlen(checkcall) - 4] = '\0';
 
51
 
 
52
    if (strstr(checkcall, "/AM") != NULL)       // airborne mobile, no country (0), no zone (0)
 
53
        checkcall[0] = '\0';
 
54
 
 
55
    if (strstr(checkcall, "/MM") != NULL)       // maritime mobile, no country, no zone
 
56
        checkcall[0] = '\0';
 
57
 
 
58
    strncpy(findcall, checkcall, 16);
 
59
 
 
60
    loc = strcspn(checkcall, "/");
 
61
 
 
62
    if (loc != strlen(checkcall)) {
 
63
        char call1[17];
 
64
        char call2[17];
 
65
 
 
66
 
 
67
        strncpy(call1, checkcall, loc);         /* 1st part before '/' */
 
68
        call1[loc] = '\0';
 
69
        strcpy(call2, checkcall + loc + 1);     /* 2nd part after '/' */
 
70
 
 
71
        if (strlen(call2) < strlen(call1)
 
72
            && strlen(call2) > 1) {
 
73
            sprintf(checkcall, "%s/%s", call2, call1);
 
74
            abnormal_call = 1;
 
75
            loc = strcspn(checkcall, "/");
 
76
        }
 
77
 
 
78
        if (loc > 3) {
 
79
 
 
80
            strncpy(checkbuffer, (checkcall + loc + 1),
 
81
                    (strlen(checkcall) + 1) - loc);
 
82
 
 
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, "/");
 
94
        }
 
95
 
 
96
        if (loc != strlen(checkcall)) {
 
97
 
 
98
            if (loc < 5)
 
99
                checkcall[loc] = '\0';  /*  "PA/DJ0LN/P   */
 
100
            else {              /*  DJ0LN/P       */
 
101
                strncpy(checkcall, checkcall, loc + 1);
 
102
            }
 
103
        }
 
104
 
 
105
        /* ------------------------------------------------------------ */
 
106
 
 
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];
 
111
                    break;
 
112
                }
 
113
            }
 
114
        } else if (strlen(checkbuffer) > 1)
 
115
            strcpy(checkcall, checkbuffer);
 
116
 
 
117
    }
 
118
 
 
119
    /* -------------check full call exceptions first...--------------------- */
 
120
 
 
121
    w = -1;
 
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);
 
128
 
 
129
        for (i = 0; i < pfxmax; i++) {
 
130
            pfx = prefix_by_index(i);
 
131
            if (strcmp(checkncall, pfx->pfx) == 0) {
 
132
                w = i;
 
133
                break;
 
134
            }
 
135
        }
 
136
 
 
137
    } else {
 
138
        int bestlen = 0;
 
139
        for (i = 0; i < pfxmax; i++) {
 
140
            int l;
 
141
            pfx = prefix_by_index(i);
 
142
            if (*pfx->pfx != findcall[0])
 
143
                continue;
 
144
 
 
145
            l = strlen(pfx->pfx);
 
146
            if (l <= bestlen)
 
147
                continue;
 
148
 
 
149
            if (strncmp(pfx->pfx, findcall, l) == 0) {
 
150
                bestlen = l;
 
151
                w = i;
 
152
            }
 
153
        }
 
154
    }
 
155
 
 
156
    if (w < 0 && 0 != strcmp(findcall, checkcall)) {
 
157
        // only if not found in prefix full call exception list
 
158
        int bestlen = 0;
 
159
        for (i = 0; i < pfxmax; i++) {
 
160
            int l;
 
161
            pfx = prefix_by_index(i);
 
162
            if (*pfx->pfx != checkcall[0])
 
163
                continue;
 
164
            l = strlen(pfx->pfx);
 
165
            if (l <= bestlen)
 
166
                continue;
 
167
            if (strncmp(pfx->pfx, checkcall, l) == 0) {
 
168
                bestlen = l;
 
169
                w = i;
 
170
            }
 
171
        }
 
172
    }
 
173
 
 
174
    return w;
 
175
}
 
176
 
 
177
int getctynr(char *checkcall) 
 
178
{
 
179
    int w;
 
180
    
 
181
    w = getpfxindex(checkcall);
 
182
 
 
183
    if (w >= 0)
 
184
        return prefix_by_index(w)->dxcc_index;
 
185
    else
 
186
        return 0;       /* no country found */
 
187
}
 
188
 
27
189
 
28
190
int getctydata(char *checkcallptr)
29
191
{
30
 
 
31
 
        char checkbuffer[17] = "";
32
 
        char checkncall[17] = "";
33
 
        char checkcall[17] = "";
34
 
        char findcall[17] = "";
35
 
 
36
 
        int i = 0, w =  0, x = 0 , ii = 0, abnormal_call = 0;
37
 
        char portable = '\0';
38
 
        int pp = 0;
39
 
        size_t loc;
40
 
 
41
 
        strncpy (checkcall, checkcallptr, 16);
42
 
        checkcall[16]=0;
43
 
 
44
 
 
45
 
        portable = '\0';
46
 
 
47
 
        if (strstr(checkcall, "/QRP") != NULL)
48
 
                checkcall[strlen(checkcall)-4] ='\0';
49
 
 
50
 
        if (strstr(checkcall, "/AM") != NULL)           // airborne mobile, no country (0), no zone (0)
51
 
                checkcall[0]='\0';
52
 
 
53
 
        if (strstr(checkcall, "/MM") != NULL)           // maritime mobile, no country, no zone
54
 
                checkcall[0]='\0';
55
 
 
56
 
        strncpy (findcall, checkcall, 16);
57
 
 
58
 
        loc = strcspn(checkcall, "/");
59
 
 
60
 
        if (loc != strlen(checkcall))
61
 
        {
62
 
                char call1[17];
63
 
                char call2[17];
64
 
 
65
 
                strncpy(call1, checkcall, loc);
66
 
                call1[loc]='\0';
67
 
                strcpy(call2, checkcall+loc+1);
68
 
 
69
 
                if (strlen(call2) < strlen(call1)
70
 
                        && strlen(call2) > 1)
71
 
                {
72
 
                        sprintf(checkcall, "%s/%s", call2, call1);
73
 
                        abnormal_call = 1;
74
 
                        loc = strcspn(checkcall, "/");
75
 
                }
76
 
 
77
 
                if (loc > 3){
78
 
 
79
 
                        strncpy(checkbuffer, (checkcall  +  loc + 1), (strlen(checkcall) + 1) - loc);
80
 
 
81
 
 
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, "/");
93
 
                }
94
 
 
95
 
                if (loc != strlen(checkcall))
96
 
                {
97
 
 
98
 
                        if (loc  <  5)
99
 
                                        checkcall[loc] =  '\0'; /*  "PA/DJ0LN/P   */
100
 
                        else
101
 
                        {                                       /*  DJ0LN/P       */
102
 
                                strncpy(checkcall, checkcall, loc + 1);
103
 
                        }
104
 
                }
105
 
 
106
 
 
107
 
 
108
 
                /* ------------------------------------------------------------*/
109
 
 
110
 
 
111
 
                if ((strlen(checkbuffer) == 1) && isdigit(checkbuffer[0]))
112
 
                {                                     /*  /3 */
113
 
                        for ( pp = strlen(checkcall)-1; pp > 0 ; pp--)
114
 
                        {
115
 
                                if (isdigit(checkcall[pp]))
116
 
                                {
117
 
                                        checkcall[pp] = checkbuffer[0];
118
 
                                        break;
119
 
                                }
120
 
                        }
121
 
                }
122
 
                else if (strlen(checkbuffer) > 1)
123
 
                        strcpy (checkcall, checkbuffer);
124
 
 
125
 
        }
126
 
 
127
 
        if (wpx == 1 || pfxmult == 1) getpx(checkcall);
128
 
        // needed for wpx and other pfx contests...
129
 
 
130
 
        /* -------------check full call exceptions first...----------------------------*/
131
 
 
132
 
        w=-1;
133
 
        if (abnormal_call == 1)
134
 
        {
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] = "";
 
196
 
 
197
    prefix_data *pfx;
 
198
    int pfxmax = prefix_count();
 
199
 
 
200
    int i = 0, w = 0, x = 0, abnormal_call = 0;
 
201
    char portable = '\0';
 
202
    int pp = 0;
 
203
    size_t loc;
 
204
 
 
205
    g_strlcpy(checkcall, checkcallptr, 17);
 
206
 
 
207
    portable = '\0';
 
208
 
 
209
    if (strstr(checkcall, "/QRP") != NULL)      /* drop QRP suffix */
 
210
        checkcall[strlen(checkcall) - 4] = '\0';
 
211
 
 
212
    if (strstr(checkcall, "/AM") != NULL)       // airborne mobile, no country (0), no zone (0)
 
213
        checkcall[0] = '\0';
 
214
 
 
215
    if (strstr(checkcall, "/MM") != NULL)       // maritime mobile, no country, no zone
 
216
        checkcall[0] = '\0';
 
217
 
 
218
    strncpy(findcall, checkcall, 16);
 
219
 
 
220
    loc = strcspn(checkcall, "/");
 
221
 
 
222
    if (loc != strlen(checkcall)) {
 
223
        char call1[17];
 
224
        char call2[17];
 
225
 
 
226
        strncpy(call1, checkcall, loc);         /* 1st part before '/' */
 
227
        call1[loc] = '\0';
 
228
        strcpy(call2, checkcall + loc + 1);     /* 2nd part after '/' */
 
229
 
 
230
        if (strlen(call2) < strlen(call1)
 
231
            && strlen(call2) > 1) {
 
232
            sprintf(checkcall, "%s/%s", call2, call1);
 
233
            abnormal_call = 1;
 
234
            loc = strcspn(checkcall, "/");
 
235
        }
 
236
 
 
237
        if (loc > 3) {
 
238
 
 
239
            strncpy(checkbuffer, (checkcall + loc + 1),
 
240
                    (strlen(checkcall) + 1) - loc);
 
241
 
 
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, "/");
 
253
        }
 
254
 
 
255
        if (loc != strlen(checkcall)) {
 
256
 
 
257
            if (loc < 5)
 
258
                checkcall[loc] = '\0';  /*  "PA/DJ0LN/P   */
 
259
            else {              /*  DJ0LN/P       */
 
260
                strncpy(checkcall, checkcall, loc + 1);
 
261
            }
 
262
        }
 
263
 
 
264
        /* ------------------------------------------------------------ */
 
265
 
 
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];
 
270
                    break;
 
271
                }
 
272
            }
 
273
        } else if (strlen(checkbuffer) > 1)
 
274
            strcpy(checkcall, checkbuffer);
 
275
 
 
276
    }
 
277
 
 
278
    if (wpx == 1 || pfxmult == 1)
 
279
        /* needed for wpx and other pfx contests */
 
280
        getpx(checkcall);
 
281
 
 
282
    /* -------------check full call exceptions first...--------------------- */
 
283
 
 
284
    w = -1;
 
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);
139
 
 
140
 
                for  (i=0  ;  i  < MAX_DBLINES  ;  i++)
141
 
                {
142
 
                        if (strcmp(checkncall, prefixlines[i]) == 0)
143
 
                        {
144
 
                                w = i;
145
 
                                x = dataindex[i];
146
 
                                break;
147
 
                        }
148
 
                }
149
 
 
150
 
        }
151
 
        else
152
 
        {
153
 
                int bestlen=0;
154
 
                for  (i=0  ;  i  < MAX_DBLINES  ;  i++) {
155
 
                        int l;
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) {
160
 
                                bestlen=l;
161
 
                                w=i;
162
 
                        }
163
 
                }
164
 
                if (w>=0) x=dataindex[w];
165
 
        }
166
 
 
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.
171
 
        {
172
 
                int bestlen=0;
173
 
                for  (i=0  ;  i  < MAX_DBLINES  ;  i++) {
174
 
                        int l;
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) {
179
 
                                bestlen=l;
180
 
                                w=i;
181
 
                        }
182
 
                }
183
 
                if (w>=0) x=dataindex[w];
184
 
        }
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);
192
 
        }
193
 
        else {
194
 
                strncpy(cqzone, datalines[x] + 26, 2);
195
 
                strncpy(ituzone, datalines[x] + 31, 2);
196
 
 
197
 
                if(x == w_cty) {
198
 
                        for (ii=0; ii < strlen(checkcall); ii++) {
199
 
                                if (checkcall[ii] == '7' || checkcall[ii] == '6') {
200
 
                                        strncpy (cqzone, "03",2);
201
 
                                        break;
202
 
                                } else if (checkcall[ii] == '5' || checkcall[ii] == '8' || checkcall[ii] == '9' || checkcall[ii] == '0') {
203
 
                                        strncpy (cqzone, "04",2);
204
 
                                        break;
205
 
                                }  else if (checkcall[ii] == '1' || checkcall[ii] == '2' || checkcall[ii] == '3' || checkcall[ii] == '4') {
206
 
                                        strncpy (cqzone, "05",2);
207
 
                                        break;
208
 
                                }
209
 
                        }
210
 
 
211
 
                }
212
 
 
213
 
                if(x == ve_cty) {
214
 
                        for (ii=0; ii < strlen(checkcall); ii++) {
215
 
                                if (checkcall[ii] == '7' ) {
216
 
                                        strncpy (cqzone, "03",2);
217
 
                                        break;
218
 
                                } else if (checkcall[ii] == '3' || checkcall[ii] == '4' || checkcall[ii] == '5' || checkcall[ii] == '6') {
219
 
                                        strncpy (cqzone, "04",2);
220
 
                                        break;
221
 
                                }  else  strncpy (cqzone, "05",2);
222
 
 
223
 
                        }
224
 
                }
225
 
        }          // end exception
226
 
 
227
 
        if (itumult!=1)
228
 
                strcpy(zone_export, cqzone);
229
 
        else
230
 
                strcpy(zone_export, ituzone);
231
 
 
232
 
        strncpy (ituzone, ituarray[w], 2);
233
 
 
234
 
 
235
 
        countrynr  = x;
236
 
        strncpy (continent,  datalines[countrynr]+  36 ,3);
237
 
        continent[2]  = '\0';
238
 
 
239
 
        return (x);
 
289
        //      strncpy(checkncall , findcall, pp);
 
290
        strncpy(checkncall, findcall, sizeof(checkncall) - 1);
 
291
 
 
292
        for (i = 0; i < pfxmax; i++) {
 
293
            pfx = prefix_by_index(i);
 
294
            if (strcmp(checkncall, pfx->pfx) == 0) {
 
295
                w = i;
 
296
                x = pfx->dxcc_index;
 
297
                break;
 
298
            }
 
299
        }
 
300
 
 
301
    } else {
 
302
        int bestlen = 0;
 
303
        for (i = 0; i < pfxmax; i++) {
 
304
            int l;
 
305
            pfx = prefix_by_index(i);
 
306
            if (*pfx->pfx != findcall[0])
 
307
                continue;
 
308
 
 
309
            l = strlen(pfx->pfx);
 
310
            if (l <= bestlen)
 
311
                continue;
 
312
 
 
313
            if (strncmp(pfx->pfx, findcall, l) == 0) {
 
314
                bestlen = l;
 
315
                w = i;
 
316
            }
 
317
        }
 
318
        if (w >= 0)
 
319
            x = prefix_by_index(w)->dxcc_index;
 
320
    }
 
321
 
 
322
    if (w < 0 && 0 != strcmp(findcall, checkcall)) {
 
323
        // only if not found in prefix full call exception list
 
324
        int bestlen = 0;
 
325
        for (i = 0; i < pfxmax; i++) {
 
326
            int l;
 
327
            pfx = prefix_by_index(i);
 
328
            if (*pfx->pfx != checkcall[0])
 
329
                continue;
 
330
            l = strlen(pfx->pfx);
 
331
            if (l <= bestlen)
 
332
                continue;
 
333
            if (strncmp(pfx->pfx, checkcall, l) == 0) {
 
334
                bestlen = l;
 
335
                w = i;
 
336
            }
 
337
        }
 
338
        if (w >= 0)
 
339
            x = prefix_by_index(w)->dxcc_index;
 
340
    }
 
341
 
 
342
    if (w > 0 ) {
 
343
        sprintf(cqzone, "%02d", prefix_by_index(w) -> cq);
 
344
        sprintf(ituzone, "%02d", prefix_by_index(w) -> itu);
 
345
    } 
 
346
 
 
347
    if (itumult != 1)
 
348
        strcpy(zone_export, cqzone);
 
349
    else
 
350
        strcpy(zone_export, ituzone);
 
351
 
 
352
// w must be >0  tb 17feb2011
 
353
//    strncpy(ituzone, ituarray[w], 2);
 
354
 
 
355
    countrynr = x;
 
356
    strncpy(continent, dxcc_by_index(countrynr) -> continent , 3);
 
357
    continent[2] = '\0';
 
358
 
 
359
    return (x);
240
360
}
241
361
 
242
362
/* --------------------for background ---------------------------*/
243
363
 
244
364
// pa3fwm, 20040113: I didn't "clean" this part yet
245
 
        int getctydata2(char *checkcall)
246
 
        {
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];
253
 
 
254
 
        char checkbuffer[17] = "";
255
 
        char membuffer[17] = "";
256
 
        char checkncall[20];
257
 
 
258
 
        int i = 0,  w =  0, x = 0;
259
 
        int exception;
260
 
        char portable = '\0';
261
 
        int pp = 0;
262
 
        size_t loc;
263
 
 
264
 
        strncpy (membuffer, checkcall, 16);
265
 
        portable = '\0';
266
 
 
267
 
        if (strstr(checkcall, "/QRP") != NULL) //strip the qrp
268
 
                checkcall[strlen(checkcall)-4] ='\0';
269
 
 
270
 
        loc = strcspn(checkcall, "/");
271
 
 
272
 
        if (loc > 4){
273
 
 
274
 
                strncpy(checkbuffer, (checkcall  +  loc + 1), (strlen(checkcall) + 1) - loc);
275
 
 
276
 
 
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];
287
 
 
288
 
        }
289
 
        loc = strcspn(checkcall, "/");
290
 
 
291
 
 
292
 
        if (loc != strlen(checkcall)){
293
 
 
294
 
                if (loc  <  5)
295
 
                                checkcall[loc] =  '\0'; /*  "PA/DJ0LN/P   */
296
 
                else
297
 
                {                                       /*  DJ0LN/P       */
298
 
 
299
 
                strncpy(checkcall, checkcall, loc + 1);
300
 
 
301
 
        }
302
 
        }
303
 
 
304
 
        /* ------------------------------------------------------------*/
305
 
 
306
 
 
307
 
        if (strlen(checkbuffer) == 1) {                                     /*  /3 */
308
 
                for ( pp = strlen(checkcall)-1; pp > 0 ; pp--) {
309
 
 
310
 
                                if ((checkcall[pp] <= '9') && (checkcall[pp] >= '0'))
311
 
                                        if ((checkbuffer[0] <= '9')&&(checkbuffer[0] >= '0')){
312
 
                                                checkcall[pp] = checkbuffer[0];
313
 
                                                break;
314
 
                                        }
315
 
                        }
316
 
                }  else if (strlen(checkbuffer) > 1)
317
 
                        strcpy (checkcall, checkbuffer);
318
 
 
319
 
        getpx(checkcall);
320
 
 
321
 
 
322
 
 
323
 
        /* ------------------------------------------------------------*/
324
 
 
325
 
        w=0;
326
 
 
327
 
                for (pp = 1; pp <= strlen(checkcall); pp++) {
328
 
 
329
 
                        strncpy(checkncall , checkcall, pp);
330
 
                        checkncall[pp]='\0';
331
 
 
332
 
 
333
 
                        for  (i=0  ;  i  <= MAX_DBLINES  ;  i++){
334
 
 
335
 
 
336
 
                                if ((strncmp(checkncall, prefixlines[i] , strlen(prefixlines[i])) == 0)) {
337
 
 
338
 
                                        if (strlen(checkncall) == strlen(prefixlines[i])){
339
 
                                                w = i;
340
 
                                                x = dataindex[i];
341
 
                                                break;
342
 
                                        }
343
 
 
344
 
                                }
345
 
                        }
346
 
                }
347
 
 
348
 
        exception = 0;
349
 
 
350
 
        if (strlen(zonearray[w]) > 0) {
351
 
                exception = 1;
352
 
                strncpy (cqzone,  zonearray[w], 2);
353
 
        }
354
 
        else strncpy(cqzone, datalines[x] + 26, 2);
355
 
 
356
 
        countrynr  = x;
357
 
 
358
 
        strcpy(checkcall, membuffer);
359
 
 
360
 
        return (x);
361
 
 
362
 
        }
 
365
int getctydata2(char *checkcall)
 
366
{
 
367
    extern char cqzone[];
 
368
    extern int countrynr;
 
369
 
 
370
    char checkbuffer[17] = "";
 
371
    char membuffer[17] = "";
 
372
    char checkncall[20];
 
373
 
 
374
    prefix_data *pfx;
 
375
    int pfxmax = prefix_count();
 
376
    int i = 0, w = 0, x = 0;
 
377
    char portable = '\0';
 
378
    int pp = 0;
 
379
    size_t loc;
 
380
 
 
381
    strncpy(membuffer, checkcall, 16);
 
382
    portable = '\0';
 
383
 
 
384
    if (strstr(checkcall, "/QRP") != NULL)      //strip the qrp
 
385
        checkcall[strlen(checkcall) - 4] = '\0';
 
386
 
 
387
    loc = strcspn(checkcall, "/");
 
388
 
 
389
    if (loc > 4) {
 
390
 
 
391
        strncpy(checkbuffer, (checkcall + loc + 1),
 
392
                (strlen(checkcall) + 1) - loc);
 
393
 
 
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];
 
404
 
 
405
    }
 
406
    loc = strcspn(checkcall, "/");
 
407
 
 
408
    if (loc != strlen(checkcall)) {
 
409
 
 
410
        if (loc < 5)
 
411
            checkcall[loc] = '\0';      /*  "PA/DJ0LN/P   */
 
412
        else {                  /*  DJ0LN/P       */
 
413
 
 
414
            strncpy(checkcall, checkcall, loc + 1);
 
415
 
 
416
        }
 
417
    }
 
418
 
 
419
    /* ------------------------------------------------------------ */
 
420
 
 
421
    if (strlen(checkbuffer) == 1) {     /*  /3 */
 
422
        for (pp = strlen(checkcall) - 1; pp > 0; pp--) {
 
423
 
 
424
            if ((checkcall[pp] <= '9') && (checkcall[pp] >= '0'))
 
425
                if ((checkbuffer[0] <= '9') && (checkbuffer[0] >= '0')) {
 
426
                    checkcall[pp] = checkbuffer[0];
 
427
                    break;
 
428
                }
 
429
        }
 
430
    } else if (strlen(checkbuffer) > 1)
 
431
        strcpy(checkcall, checkbuffer);
 
432
 
 
433
    getpx(checkcall);
 
434
 
 
435
    /* ------------------------------------------------------------ */
 
436
 
 
437
    w = 0;
 
438
 
 
439
    for (pp = 1; pp <= strlen(checkcall); pp++) {
 
440
 
 
441
        strncpy(checkncall, checkcall, pp);
 
442
        checkncall[pp] = '\0';
 
443
 
 
444
        for (i = 0; i < pfxmax; i++) {
 
445
                
 
446
            pfx = prefix_by_index(i);
 
447
 
 
448
            if ((strncmp
 
449
                 (checkncall, pfx->pfx, strlen(pfx->pfx)) == 0)) {
 
450
 
 
451
                if (strlen(checkncall) == strlen(pfx->pfx)) {
 
452
                    w = i;
 
453
                    x = pfx->dxcc_index;
 
454
                    break;
 
455
                }
 
456
 
 
457
            }
 
458
        }
 
459
    }
 
460
 
 
461
    sprintf(cqzone, "%02d", prefix_by_index(w) -> cq);
 
462
 
 
463
    countrynr = x;
 
464
 
 
465
    strcpy(checkcall, membuffer);
 
466
 
 
467
    return (x);
 
468
 
 
469
}