/[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.29 by pa4tu, Sat Oct 30 08:07:39 2004 UTC revision 1.30 by pa4tu, Mon Nov 1 20:06:23 2004 UTC
# Line 33  Line 33 
33  extern GtkWidget *mainwindow;  extern GtkWidget *mainwindow;
34  extern preferencestype preferences;  extern preferencestype preferences;
35  extern statetype state;  extern statetype state;
36  dxcc_data *dxcc;  GPtrArray *dxcc;
37  GHashTable *prefixes;  GHashTable *prefixes;
38  gchar *searchpx = NULL;  gchar *searchpx = NULL;
39  gint excwaz, excitu;  gint excwaz, excitu;
40    
41    void
42    cleanup_dxcc (void)
43    {
44            gint i;
45    
46            /* free the dxcc array */
47            for (i = 0; i < dxcc->len; i++)
48            {
49                    dxcc_data *d = g_ptr_array_index (dxcc, i);
50                    g_free (d->countryname);
51                    g_free (d->continent);
52                    g_free (d->px);
53                    g_free (d->exceptions);
54                    g_free (d);
55            }
56            g_ptr_array_free (dxcc, TRUE);
57            if (prefixes) g_hash_table_destroy (prefixes);
58    }
59    
60  static gchar *  static gchar *
61  findpfx (gchar * pfx)  findpfx (gchar * pfx)
62  {  {
# Line 167  lookup_dxcc (gchar * callsign) Line 186  lookup_dxcc (gchar * callsign)
186          return (country);          return (country);
187  }  }
188    
189    static void
190    dxcc_add (gchar *c, gint w, gint i, gchar *cont, gint lat, gint lon,
191            gint tz, gchar *p, gchar *e)
192    {
193            dxcc_data *new_dxcc = g_new (dxcc_data, 1);
194    
195            new_dxcc -> countryname = g_strdup (c);
196            new_dxcc -> waz = w;
197            new_dxcc -> itu = i;
198            new_dxcc -> continent = g_strdup (cont);
199            new_dxcc -> latitude = lat;
200            new_dxcc -> longitude = lon;
201            new_dxcc -> timezone = tz;
202            new_dxcc -> px = g_strdup (p);
203            new_dxcc -> exceptions = g_strdup (e);
204            g_ptr_array_add (dxcc, new_dxcc);
205    }
206    
207  gint  gint
208  readctydata (void)  readctydata (void)
# Line 185  readctydata (void) Line 221  readctydata (void)
221                          return (1);                          return (1);
222                  }                  }
223    
224          dxcc = g_new0 (dxcc_data, 400);          dxcc = g_ptr_array_new ();
225          prefixes = g_hash_table_new_full (g_str_hash, g_str_equal,          prefixes = g_hash_table_new_full (g_str_hash, g_str_equal,
226                  (GDestroyNotify)g_free, NULL);                  (GDestroyNotify)g_free, NULL);
227    
228          /* first field in case hash_table_lookup returns NULL */          /* first field in case hash_table_lookup returns NULL */
229          dxcc[0].countryname = g_strdup ("");          dxcc_add ("", -1, -1, "", 0, 0, 0, "", "");
         dxcc[0].waz = -1;  
         dxcc[0].itu = -1;  
         dxcc[0].continent = g_strdup ("");  
         dxcc[0].latitude = 0;  
         dxcc[0].longitude = 0;  
         dxcc[0].timezone = 0;  
         dxcc[0].px = g_strdup ("");  
         dxcc[0].exceptions = g_strdup ("");  
   
230          state.countries = 1;          state.countries = 1;
231    
232          while (!feof (fp))          while (!feof (fp))
# Line 223  readctydata (void) Line 250  readctydata (void)
250                  /* split up the second line */                  /* split up the second line */
251                  pfxsplit = g_strsplit (split[8], ",", 0);                  pfxsplit = g_strsplit (split[8], ",", 0);
252    
253                  dxcc[state.countries].countryname = g_strdup (split[0]);                  dxcc_add (split[0], atoi(split[1]), atoi(split[2]), split[3],
254                  dxcc[state.countries].waz = atoi (split[1]);                          (gint)atof(split[4]) * 100, (gint)atof(split[5]) * 100,
255                  dxcc[state.countries].itu = atoi (split[2]);                          (gint)atof(split[6]) * 10, split[7], split[8]);
                 dxcc[state.countries].continent = g_strdup (split[3]);  
                 dxcc[state.countries].latitude = (gint)(atof(split[4]) * 100);  
                 dxcc[state.countries].longitude = (gint)(atof(split[5]) * 100);  
                 dxcc[state.countries].timezone = (gint)(atof(split[6]) * 10);  
                 dxcc[state.countries].px = g_strdup (split[7]);  
                 dxcc[state.countries].exceptions = g_strdup (split[8]);  
256    
257                  /* official prefix */                  /* official prefix */
258                  g_ascii_strup(split[7], -1); /* some chars are lowercase */                  g_ascii_strup(split[7], -1); /* some chars are lowercase */
# Line 351  updatedxccframe (gchar * callsign) Line 372  updatedxccframe (gchar * callsign)
372    
373          if (country > 0)          if (country > 0)
374          {          {
375                  labeltext1 = g_strdup (dxcc[country].countryname);                  dxcc_data *d = g_ptr_array_index (dxcc, country);
376                    labeltext1 = g_strdup (d->countryname);
377                  /* look for exceptions */                  /* look for exceptions */
378                  if (strchr(dxcc[country].exceptions, '(') || strchr(dxcc[country].exceptions, '['))                  if (strchr(d->exceptions, '(') || strchr(d->exceptions, '['))
379                  {                  {
380                          excsplit = g_strsplit(dxcc[country].exceptions, ",", 0);                          excsplit = g_strsplit(d->exceptions, ",", 0);
381                          for (iexc = 0;; iexc++)                          for (iexc = 0;; iexc++)
382                          {                          {
383                                  if (!excsplit[iexc]) break;                                  if (!excsplit[iexc]) break;
384                                  exc = findexc(excsplit[iexc]);                                  exc = findexc(excsplit[iexc]);
385                                  if (g_ascii_strcasecmp(searchpx, exc) == 0)                                  if (g_ascii_strcasecmp(searchpx, exc) == 0)
386                                  {                                  {
387                                          labeltext2 = g_strdup_printf ("%s - ITU %d - CQ %d", dxcc[country].continent, excitu, excwaz);                                          labeltext2 = g_strdup_printf ("%s - ITU %d - CQ %d", d->continent, excitu, excwaz);
388                                          exception = TRUE;                                          exception = TRUE;
389                                  }                                  }
390                          }                          }
# Line 370  updatedxccframe (gchar * callsign) Line 392  updatedxccframe (gchar * callsign)
392                  }                  }
393    
394                  if (! exception)                  if (! exception)
395                          labeltext2 = g_strdup_printf ("%s - ITU %d - CQ %d", dxcc[country].continent, dxcc[country].itu, dxcc[country].waz);                          labeltext2 = g_strdup_printf ("%s - ITU %d - CQ %d", d->continent, d->itu, d->waz);
396                  labeltext3 = g_strdup_printf (_("Timezone: %+1.1f"), (gdouble)dxcc[country].timezone/10);                  labeltext3 = g_strdup_printf (_("Timezone: %+1.1f"), (gdouble)d->timezone/10);
397                  labeltext4 = g_strdup_printf (_("Location: %+1.2f %+1.2f"),     (gdouble)dxcc[country].latitude/100, (gdouble)dxcc[country].longitude/100);                  labeltext4 = g_strdup_printf (_("Location: %+1.2f %+1.2f"),     (gdouble)d->latitude/100, (gdouble)d->longitude/100);
398                  gcresult = g_strdup (gc(preferences.units, state.mylocation, (gdouble)dxcc[country].latitude/100, (gdouble)dxcc[country].longitude/100));                  gcresult = g_strdup (gc(preferences.units, state.mylocation, (gdouble)d->latitude/100, (gdouble)d->longitude/100));
399          }          }
400          else          else
401          {          {

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

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