/[xlog]/xlog/src/dxcc.c
ViewVC logotype

Diff of /xlog/src/dxcc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by pa4tu, Thu Nov 21 20:24:06 2002 UTC revision 1.7 by pa4tu, Sat Nov 23 14:29:54 2002 UTC
# Line 83  readctydata (void) Line 83  readctydata (void)
83    
84    dxcc = g_new0 (dxcc_data, 400);    dxcc = g_new0 (dxcc_data, 400);
85    prefixes = g_hash_table_new (g_str_hash, g_str_equal);    prefixes = g_hash_table_new (g_str_hash, g_str_equal);
86    
87      /* first field in case hash_table_lookup returns NULL */
88      dxcc[0].countryname = g_strdup ("Unknown Country");
89      dxcc[0].waz = -1;
90      dxcc[0].itu = -1;
91      dxcc[0].exceptions = NULL;
92    
93      state.countries = 1;
94    
95    while (!feof (fp))    while (!feof (fp))
96      {      {
97        while (ch != 59)        while (ch != 59)
# Line 128  readctydata (void) Line 137  readctydata (void)
137    return (0);    return (0);
138  }  }
139    
140    static gchar *
141  static gint  getpx (gchar *checkcall)
 lookup_dxcc (gchar * callsign)  
142  {  {
   gint result, country = -1;  
   gchar *prefix;  
143    
144    prefix = g_strndup (callsign, 4);    gchar *pxstr, **split;
   country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, prefix));  
   g_free (prefix);  
145    
146    if (country == 0)    /* characters after '/' might contain a country */
147      if (strchr(checkcall, '/'))
148      {
149      split = g_strsplit(checkcall, "/", 2);
150      if ((strlen(split[1]) > 1) &&
151        (strlen(split[1]) < strlen(split[0])))
152      {      {
153        prefix = g_strndup (callsign, 3);        if ((g_strcasecmp(split[1], "AM") == 0) ||
154        country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, prefix));          (g_strcasecmp(split[1], "MM") == 0))
155        g_free (prefix);            pxstr = NULL;
156            else if (g_strcasecmp(split[1], "QRP") == 0)
157              pxstr = g_strdup(split[0]);
158            else pxstr = g_strdup(split[1]);
159      }      }
160        else pxstr = g_strdup(split[0]);
161        g_strfreev(split);
162      }
163      else pxstr = g_strdup(checkcall);
164      return(pxstr);
165    }
166    
   if (country == 0)  
     {  
       prefix = g_strndup (callsign, 2);  
       country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, prefix));  
       g_free (prefix);  
     }  
167    
168    if (country == 0)  static gint
169      {  lookup_dxcc (gchar * callsign)
170        prefix = g_strndup (callsign, 1);  {
171        country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, prefix));    gint ipx, country = -1;
172        g_free (prefix);    gchar *px, *searchpx = NULL;
173      }  
174      px = getpx(callsign);
175    
176      for (ipx = strlen(px); ipx > 0; ipx--)
177      {
178        searchpx = g_strndup (px, ipx);
179        country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, searchpx));
180        if (country >= 0) break;
181      }
182    
183      g_free (px);
184      if (strlen(searchpx) > 0) g_free(searchpx);
185    
186    /* country starts at 0 */    return (country);
   if (country == 0)  
     result = -1;  
   else  
     result = country;  
   return (result);  
187  }  }
188    
189    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26