/[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.2 by pa4tu, Thu Nov 21 19:36:43 2002 UTC revision 1.3 by pa4tu, Thu Nov 21 19:57:46 2002 UTC
# Line 41  dxcc_data *dxcc; Line 41  dxcc_data *dxcc;
41  GHashTable *prefixes;  GHashTable *prefixes;
42    
43  /* if there is an underscore in the prefix this means we have to substitute 0-9 */  /* if there is an underscore in the prefix this means we have to substitute 0-9 */
44  static gboolean find_underscore(gchar *string, gchar *primaryprefix, guint i)  static gboolean
45    find_underscore (gchar * string, gchar * primaryprefix, guint i)
46  {  {
47          gchar **underscore = NULL, *end, *j;    gchar **underscore = NULL, *end, *j;
48          guint k;    guint k;
49    
50          underscore = g_strsplit(string, "_", 0);    underscore = g_strsplit (string, "_", 0);
51          if (underscore[1] != NULL) {    if (underscore[1] != NULL)
52                  end = string + strlen(string);      {
53                  for (j = string; j < end; ++j)        end = string + strlen (string);
54          for (j = string; j < end; ++j)
55            {
56              switch (*j)
57                {
58                case '_':
59                  for (k = 0; k <= 9; k++)
60                  {                  {
61                          switch (*j)                    *j = 48 + k;
62                          {                    g_hash_table_insert (prefixes, g_strdup (string),
63                                  case '_':                                         GINT_TO_POINTER (i + 1));
64                                          for (k = 0; k <= 9; k++)                    state.prefixes++;
                                         {  
                                                 *j = 48 + k;  
                                                 g_hash_table_insert(prefixes, g_strdup(string), GINT_TO_POINTER(i + 1));  
                                                 state.prefixes++;  
                                         }  
                                 break;  
                         }  
65                  }                  }
66                  g_strfreev(underscore);                break;
67                  return(TRUE);              }
         }  
         else {  
                 g_strfreev(underscore);  
                 return(FALSE);  
68          }          }
69          g_strfreev (underscore);
70          return (TRUE);
71        }
72      else
73        {
74          g_strfreev (underscore);
75          return (FALSE);
76        }
77  }  }
78    
79  /* see if we can find a string like 4J-4K and substitute the prefixes in between */  /* see if we can find a string like 4J-4K and substitute the prefixes in between */
80  static gboolean find_dash(gchar *string, gchar *primaryprefix, guint i)  static gboolean
81    find_dash (gchar * string, gchar * primaryprefix, guint i)
82  {  {
83          gchar **dash = NULL, *begin, *end, *common, *newprefix;    gchar **dash = NULL, *begin, *end, *common, *newprefix;
84          gchar first, j;    gchar first, j;
85    
86          dash = g_strsplit(string, "-", 0);    dash = g_strsplit (string, "-", 0);
87          if (dash[1] != NULL)    if (dash[1] != NULL)
88          {                                                                       /*4J-4K*/      {                           /*4J-4K */
89                  begin = dash[0] + 1;                            /* J */        begin = dash[0] + 1;      /* J */
90                  first = *begin;        first = *begin;
91                  end = dash[1] + 1;                              /* K */        end = dash[1] + 1;        /* K */
92                  common = g_strndup(dash[0], 1); /* 4 */        common = g_strndup (dash[0], 1);  /* 4 */
93                  for (j = *begin; j <= *end; j++) {        for (j = *begin; j <= *end; j++)
94                          newprefix = g_strdup_printf("%s%c", common, j);          {
95                          if (g_strcasecmp(newprefix, primaryprefix) != 0) { /* only add new prefixes */            newprefix = g_strdup_printf ("%s%c", common, j);
96                                  g_hash_table_insert(prefixes, g_strdup(newprefix), GINT_TO_POINTER(i + 1));            if (g_strcasecmp (newprefix, primaryprefix) != 0)
97                                  state.prefixes++;              {                   /* only add new prefixes */
98                          }                g_hash_table_insert (prefixes, g_strdup (newprefix),
99                  }                                     GINT_TO_POINTER (i + 1));
100                  if (j - first == 26) /* we have A-Z, so first character also needs to be added */                state.prefixes++;
101                          if (g_strcasecmp(common, primaryprefix) != 0)              }
102                          {          }
103                                  g_hash_table_insert(prefixes, g_strdup(common), GINT_TO_POINTER(i + 1));        if (j - first == 26)      /* we have A-Z, so first character also needs to be added */
104                                  state.prefixes++;          if (g_strcasecmp (common, primaryprefix) != 0)
105                          }            {
106                  g_free(common);              g_hash_table_insert (prefixes, g_strdup (common),
107                  g_strfreev(dash);                                   GINT_TO_POINTER (i + 1));
108                  return(TRUE);              state.prefixes++;
109          }            }
110          else {        g_free (common);
111                  g_strfreev(dash);        g_strfreev (dash);
112                  return(FALSE);        return (TRUE);
113          }      }
114      else
115        {
116          g_strfreev (dash);
117          return (FALSE);
118        }
119  }  }
120    
121  /*  /*
# Line 178  static void convert_to_hashtable(void) Line 188  static void convert_to_hashtable(void)
188  }  }
189  */  */
190    
191  static gchar *findpfx(gchar *pfx)  static gchar *
192    findpfx (gchar * pfx)
193  {  {
194    gchar *end, *j;    gchar *end, *j;
195    
196    g_strstrip(pfx);    g_strstrip (pfx);
197    end = pfx + strlen(pfx);    end = pfx + strlen (pfx);
198    for (j = pfx; j < end; ++j)    for (j = pfx; j < end; ++j)
   {  
     switch (*j)  
199      {      {
200        case '(':        switch (*j)
201        case '[':          {
202        case ';':          case '(':
203          *j = '\0';          case '[':
204        break;          case ';':
205              *j = '\0';
206              break;
207            }
208      }      }
   }  
209    return pfx;    return pfx;
210  }  }
211    
# Line 208  readctydata (void) Line 219  readctydata (void)
219    gchar **split, **pfxsplit;    gchar **split, **pfxsplit;
220    
221    
222    cty_location = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S, "dxcc",    cty_location = g_strconcat (PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S, "dxcc",
223      G_DIR_SEPARATOR_S, "cty.dat", NULL);                                G_DIR_SEPARATOR_S, "cty.dat", NULL);
224    
225    if ((fp = fopen (cty_location, "r")) == NULL)    if ((fp = fopen (cty_location, "r")) == NULL)
226    {      {
227      g_free(cty_location);        g_free (cty_location);
228      return (1);        return (1);
229    }      }
230    
231    dxcc = g_new0(dxcc_data, 400);    dxcc = g_new0 (dxcc_data, 400);
232    prefixes = g_hash_table_new(g_str_hash, g_str_equal);    prefixes = g_hash_table_new (g_str_hash, g_str_equal);
233    while (!feof (fp))    while (!feof (fp))
234      {      {
235        while (ch != 59)        while (ch != 59)
236        {          {
237          ch = fgetc (fp);            ch = fgetc (fp);
238          if (ch == EOF) break;            if (ch == EOF)
239          buf[ichar++] = ch;              break;
240        }            buf[ichar++] = ch;
241        if (ch == EOF) break;          }
242        buf[ichar]= '\0';        if (ch == EOF)
243            break;
244          buf[ichar] = '\0';
245        ichar = 0;        ichar = 0;
246        ch = 0;        ch = 0;
247          
248        /* split up the first line */        /* split up the first line */
249        split = g_strsplit(buf, ":", 9);        split = g_strsplit (buf, ":", 9);
250        for (dxccitem = 0; dxccitem < 9; dxccitem++)        for (dxccitem = 0; dxccitem < 9; dxccitem++)
251          g_strstrip(split[dxccitem]);          g_strstrip (split[dxccitem]);
252        /* split up the second line */        /* split up the second line */
253        pfxsplit = g_strsplit(split[8], ",", 0);        pfxsplit = g_strsplit (split[8], ",", 0);
254    
255        dxcc[state.countries].countryname = g_strdup(split[0]);        dxcc[state.countries].countryname = g_strdup (split[0]);
256        dxcc[state.countries].waz = atoi(split[1]);        dxcc[state.countries].waz = atoi (split[1]);
257        dxcc[state.countries].itu = atoi(split[2]);        dxcc[state.countries].itu = atoi (split[2]);
258        dxcc[state.countries].exceptions = g_strdup(split[8]);        dxcc[state.countries].exceptions = g_strdup (split[8]);
259    
260        for (ipfx = 0;; ipfx++)        for (ipfx = 0;; ipfx++)
261        {          {
262          if (!pfxsplit[ipfx]) break;            if (!pfxsplit[ipfx])
263          pfx = findpfx(pfxsplit[ipfx]);              break;
264          g_hash_table_insert(prefixes, g_strdup(pfx),            pfx = findpfx (pfxsplit[ipfx]);
265            GINT_TO_POINTER(state.countries));            g_hash_table_insert (prefixes, g_strdup (pfx),
266        }                                 GINT_TO_POINTER (state.countries));
267            }
268    
269        g_strfreev(pfxsplit);        g_strfreev (pfxsplit);
270        g_strfreev(split);        g_strfreev (split);
271        state.countries++;        state.countries++;
272      }      }
273    fclose (fp);    fclose (fp);
274    g_free(cty_location);    g_free (cty_location);
275    return (0);    return (0);
276  }  }
277    
# Line 299  void loaddxcc(void) Line 313  void loaddxcc(void)
313          g_free(dxccfile);          g_free(dxccfile);
314  }*/  }*/
315    
316  static gint lookup_dxcc(gchar *callsign)  static gint
317    lookup_dxcc (gchar * callsign)
318  {  {
319          gint result, country;    gint result, country;
320          gchar *prefix;    gchar *prefix;
321    
322          prefix = g_strndup(callsign, 4);    prefix = g_strndup (callsign, 4);
323          country = GPOINTER_TO_INT(g_hash_table_lookup(prefixes, prefix));    country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, prefix));
324          g_free(prefix);    g_free (prefix);
   
         if (country == 0) {  
                 prefix = g_strndup(callsign, 3);  
                 country = GPOINTER_TO_INT(g_hash_table_lookup(prefixes, prefix));  
                 g_free(prefix);  
         }  
325    
326          if (country == 0) {    if (country == 0)
327                  prefix = g_strndup(callsign, 2);      {
328                  country = GPOINTER_TO_INT(g_hash_table_lookup(prefixes, prefix));        prefix = g_strndup (callsign, 3);
329                  g_free(prefix);        country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, prefix));
330          }        g_free (prefix);
331        }
         if (country == 0) {  
                 prefix = g_strndup(callsign, 1);  
                 country = GPOINTER_TO_INT(g_hash_table_lookup(prefixes, prefix));  
                 g_free(prefix);  
         }  
332    
333          /* country starts at 1 */    if (country == 0)
334          if (country == 0) result = -1; else result = country - 1;      {
335          return(result);        prefix = g_strndup (callsign, 2);
336  }        country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, prefix));
337          g_free (prefix);
338        }
339    
340      if (country == 0)
341        {
342          prefix = g_strndup (callsign, 1);
343          country = GPOINTER_TO_INT (g_hash_table_lookup (prefixes, prefix));
344          g_free (prefix);
345        }
346    
347  void updatedxccframe(gchar *callsign)    /* country starts at 1 */
348  {/*    if (country == 0)
349          GtkWidget *dxcclabel1, *dxcclabel2, *dxcclabel3, *dxcclabel4,      result = -1;
350                  *dxcclabel5, *dxccframe;    else
351          gchar **dxccsplit = NULL;      result = country - 1;
352          gchar *labeltext1, *labeltext2, *labeltext3, *labeltext4;    return (result);
353          gint country = 0;  }
         gchar *gcresult;  
   
         dxcclabel1 = lookup_widget(mainwindow, "dxcclabel1");  
         dxcclabel2 = lookup_widget(mainwindow, "dxcclabel2");  
         dxcclabel3 = lookup_widget(mainwindow, "dxcclabel3");  
         dxcclabel4 = lookup_widget(mainwindow, "dxcclabel4");  
         dxcclabel5 = lookup_widget(mainwindow, "dxcclabel5");  
         dxccframe = lookup_widget(mainwindow, "dxccframe");  
         labeltext1 = g_strdup("");  
         labeltext2 = g_strdup("");  
         labeltext3 = g_strdup("");  
         labeltext4 = g_strdup("");  
         gcresult = g_strdup("");  
         gtk_frame_set_label(GTK_FRAME(dxccframe), "DXCC");  
354    
         if (g_strcasecmp(callsign, "") != 0)  
         {  
                 country = lookup_dxcc(callsign);  
                 gtk_frame_set_label(GTK_FRAME(dxccframe), callsign);  
         }  
355    
356          if (country > 0)  void
357          {  updatedxccframe (gchar * callsign)
358                  dxccsplit = g_strsplit(dxcc[country], ":", 0);  {                               /*
359                  labeltext1 = g_strdup(dxccsplit[1]);                                     GtkWidget *dxcclabel1, *dxcclabel2, *dxcclabel3, *dxcclabel4,
360                  labeltext2 = g_strdup_printf("%s - ITU %s - CQ %s", dxccsplit[2], dxccsplit[3], dxccsplit[4]);                                     *dxcclabel5, *dxccframe;
361                  labeltext3 = g_strdup_printf(_("Timezone: %s"), dxccsplit[5]);                                     gchar **dxccsplit = NULL;
362                  labeltext4 = g_strdup_printf(_("Location: %s, %s"), dxccsplit[6], dxccsplit[7]);                                     gchar *labeltext1, *labeltext2, *labeltext3, *labeltext4;
363                  gcresult = g_strdup(gc(preferences.units, state.mylocation, g_strconcat(dxccsplit[6], dxccsplit[7], NULL)));                                     gint country = 0;
364          }                                     gchar *gcresult;
365          else if (country == -1)  
366          {                                     dxcclabel1 = lookup_widget(mainwindow, "dxcclabel1");
367                  labeltext1 = g_strdup(_("Unknown Country"));                                     dxcclabel2 = lookup_widget(mainwindow, "dxcclabel2");
368          }                                     dxcclabel3 = lookup_widget(mainwindow, "dxcclabel3");
369          gtk_label_set_text(GTK_LABEL(dxcclabel1), labeltext1);                                     dxcclabel4 = lookup_widget(mainwindow, "dxcclabel4");
370          gtk_label_set_text(GTK_LABEL(dxcclabel2), labeltext2);                                     dxcclabel5 = lookup_widget(mainwindow, "dxcclabel5");
371          gtk_label_set_text(GTK_LABEL(dxcclabel3), labeltext3);                                     dxccframe = lookup_widget(mainwindow, "dxccframe");
372          gtk_label_set_text(GTK_LABEL(dxcclabel4), labeltext4);                                     labeltext1 = g_strdup("");
373          gtk_label_set_text(GTK_LABEL(dxcclabel5), gcresult);                                     labeltext2 = g_strdup("");
374          g_free(labeltext1);                                     labeltext3 = g_strdup("");
375          g_free(labeltext2);                                     labeltext4 = g_strdup("");
376          g_free(labeltext3);                                     gcresult = g_strdup("");
377          g_free(labeltext4);                                     gtk_frame_set_label(GTK_FRAME(dxccframe), "DXCC");
378          g_free(gcresult);  
379          g_strfreev(dxccsplit); */                                     if (g_strcasecmp(callsign, "") != 0)
380                                       {
381                                       country = lookup_dxcc(callsign);
382                                       gtk_frame_set_label(GTK_FRAME(dxccframe), callsign);
383                                       }
384    
385                                       if (country > 0)
386                                       {
387                                       dxccsplit = g_strsplit(dxcc[country], ":", 0);
388                                       labeltext1 = g_strdup(dxccsplit[1]);
389                                       labeltext2 = g_strdup_printf("%s - ITU %s - CQ %s", dxccsplit[2], dxccsplit[3], dxccsplit[4]);
390                                       labeltext3 = g_strdup_printf(_("Timezone: %s"), dxccsplit[5]);
391                                       labeltext4 = g_strdup_printf(_("Location: %s, %s"), dxccsplit[6], dxccsplit[7]);
392                                       gcresult = g_strdup(gc(preferences.units, state.mylocation, g_strconcat(dxccsplit[6], dxccsplit[7], NULL)));
393                                       }
394                                       else if (country == -1)
395                                       {
396                                       labeltext1 = g_strdup(_("Unknown Country"));
397                                       }
398                                       gtk_label_set_text(GTK_LABEL(dxcclabel1), labeltext1);
399                                       gtk_label_set_text(GTK_LABEL(dxcclabel2), labeltext2);
400                                       gtk_label_set_text(GTK_LABEL(dxcclabel3), labeltext3);
401                                       gtk_label_set_text(GTK_LABEL(dxcclabel4), labeltext4);
402                                       gtk_label_set_text(GTK_LABEL(dxcclabel5), gcresult);
403                                       g_free(labeltext1);
404                                       g_free(labeltext2);
405                                       g_free(labeltext3);
406                                       g_free(labeltext4);
407                                       g_free(gcresult);
408                                       g_strfreev(dxccsplit); */
409  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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