Logo Search packages:      
Sourcecode: tucnak2 version File versions  Download package

dwdb.c

/*
    Tucnak - VHF contest log
    Copyright (C) 2002-2006  Ladislav Vaiz <ok1zia@nagano.cz>

    This program is free software; you can redistribute it and/or                                                        
    modify it under the terms of the GNU General Public License                                                          
    version 2 as published by the Free Software Foundation.

*/

#include "header.h"


struct dw *dw;
static gchar *dw_next;  /* wwl1 */
static gchar *wd_next;  /* dxc1 */

struct dw *init_dw(void){
    struct dw *dw;

    dw = g_new0(struct dw,1 );

    dw->pd = g_hash_table_new(g_str_hash, g_str_equal);
    dw->dw = g_hash_table_new(g_str_hash, g_str_equal);
    dw->wd = g_hash_table_new(g_str_hash, g_str_equal);

    dw_next = NULL;
    wd_next = NULL;

    return dw;
}



gboolean free_gpointer_item(gpointer key, gpointer value, gpointer user_data){
    if (key) g_free(key);
    if (value) g_free(value);
    return TRUE;
}

gboolean free_dw_item(gpointer key, gpointer value, gpointer user_data){
    struct dw_item *dwi;
    
    g_free(key);
    dwi = (struct dw_item *)value;
    if (dwi->wwl0) g_free(dwi->wwl0);
    if (dwi->wwl1) g_free(dwi->wwl1);

    g_hash_table_foreach_remove(dwi->wwls, free_gpointer_item, NULL);
    g_hash_table_destroy(dwi->wwls);
    
    g_free(value);
    return FALSE;
}

gboolean free_wd_item(gpointer key, gpointer value, gpointer user_data){
    struct wd_item *wdi;
    
    g_free(key);
    wdi = (struct wd_item *)value;
    if (wdi->dxc0) g_free(wdi->dxc0);
    if (wdi->dxc1) g_free(wdi->dxc1);
    g_free(value);
    return FALSE;
}


void free_dw(struct dw *dw){
    g_hash_table_foreach_remove(dw->pd, free_gpointer_item, NULL);
    g_hash_table_destroy(dw->pd);
    g_hash_table_foreach_remove(dw->dw, free_dw_item, NULL);
    g_hash_table_destroy(dw->dw);
    g_hash_table_foreach_remove(dw->wd, free_wd_item, NULL);
    g_hash_table_destroy(dw->wd);
    g_free(dw);
}

gint get_pd_size(struct dw *dw){
    return g_hash_table_size(dw->pd);
}

gint get_dw_size(struct dw *dw){
    return g_hash_table_size(dw->dw);
}

gint get_wd_size(struct dw *dw){
    return g_hash_table_size(dw->wd);
}


#define DW_DELIM " \t\r\n"

gchar *safe_fgets(GString *gs, FILE *f, int stripcomment){
    char s[102], *c;
    int len;
    
    
    g_string_truncate(gs, 0);

    while (1){
        c = fgets(s, 100, f);
        if (!c) return NULL;
        
        len = strlen(s);
        if (len>0 && s[len-1]=='\n'){ /* MAC ?*/
            s[len-1]='\0';
            if (len>1 && s[len-2]=='\r') s[len-2]='\0';
            g_string_append(gs, s);
            break;
        }
        g_string_append(gs, s);
    }
    
    if (stripcomment){
        char *c;

        c = index(gs->str, '#');
        if (c) g_string_truncate(gs, c - gs->str);
    }
        
     /*dbg("%3d '%s'\n",gs->len, gs->str);*/
    return gs->str;    
}


gchar *safe_mgets(GString *gs, const char *file, long int *pos, const long int len, int stripcomment){
      const char *c;

    /*dbg("sage_mgets(%d,%d,%d)\n", *pos, len, stripcomment);*/
      g_string_truncate(gs, 0);

      for (c=file+(*pos); c!=file+len; c++,(*pos)++){
            switch(*c){
                  case '\r':
                        continue;
                  case '\n':
                        c++;(*pos)++;
                        goto brk;
            }
            g_string_append_c(gs, *c);
      }
brk:;  
/*    dbg("brk at %d\n", *pos);*/
    if (stripcomment){
        char *c;

        c = index(gs->str, '#');
        if (c) g_string_truncate(gs, c - gs->str);
    }
/*    dbg("%3d '%s'\n",gs->len, gs->str);*/
    if (*pos>=len) return NULL;
    return gs->str;    
}

void add_pd(struct dw *dw, gchar *prefix, gchar *dxc){
    gpointer orig_prefix, orig_dxc;

/*    dbg("add_pd(prefix='%s', dxc='%s'\n", prefix, dxc );*/
    
    if (g_hash_table_lookup_extended(dw->pd, (gpointer) prefix,
               &orig_prefix, &orig_dxc)){
        
        g_hash_table_remove(dw->pd, orig_prefix);
        g_free(orig_prefix);
        g_free(orig_dxc);
    } 
    g_hash_table_insert(dw->pd, g_strdup(prefix), g_strdup(dxc) );
}


struct dw_item *add_dxc(struct dw *dw, gchar *dxc, gchar *wwl0, gchar *wwl1){
    struct dw_item *dxci;

    /*dbg("add_dxc(dxc='%s', wwl='%s' '%s')\n",dxc, wwl0, wwl1);*/
    

    dxci = g_hash_table_lookup(dw->dw, dxc);
    if (!dxci) {
       dxci = g_new0(struct dw_item, 1); 
       
       dxci->wwls = g_hash_table_new(g_str_hash, g_str_equal);
       g_hash_table_insert(dw->dw, g_strdup(dxc), dxci);
    }
    
    if (dxci->wwl0 && wwl0) { g_free(dxci->wwl0); dxci->wwl0 = NULL; }
    if (dxci->wwl1 && wwl1) { g_free(dxci->wwl1); dxci->wwl1 = NULL; }

    dxci->wwl0 = g_strdup(wwl0);
    dxci->wwl1 = g_strdup(wwl1);
    
    return dxci;
}

void add_dw(struct dw_item *dxci, gchar *dxc, gchar *wwl){
    gpointer orig_wwl, orig_dxc;
    char wwl1[6];

    if (!wwl) return;
    
    
    
    if (g_hash_table_lookup_extended(dxci->wwls, (gpointer) wwl,
               &orig_wwl, &orig_dxc)){
        
        g_hash_table_remove(dxci->wwls, orig_wwl);
        g_free(orig_wwl);
        g_free(orig_dxc);
    } 
    safe_strncpy(wwl1, wwl, 5);
    /*dbg("add_dw(dxc='%s', wwl='%s')\n", dxc, wwl1);*/
    g_hash_table_insert(dxci->wwls, g_strdup(wwl1), g_strdup(dxc) );
    
}


void add_wd(struct dw *dw, gchar *wwl, gchar *dxc){
    struct wd_item *wdi;
    
    if (!wwl || !dxc) return;
   /*dbg("add_wd(wwl='%s', dxc='%s')  size=%d \n",wwl, dxc, g_hash_table_size(dw->wd));*/
    
    wdi = g_hash_table_lookup(dw->wd, wwl);
    if (!wdi){
        wdi = g_new0(struct wd_item, 1);

        g_hash_table_insert(dw->wd, g_strdup(wwl), wdi);
      /*  dbg("   adding wwl '%s' \n", wwl);*/
    }
    
    if (!wdi->dxc0) {
        wdi->dxc0 = g_strdup(dxc);
        /*dbg("      adding dxc0 '%s' \n", wdi->dxc0);*/
        return;
    }
    
    if (!wdi->dxc1) {
        wdi->dxc1 = g_strdup(dxc);       
       /* dbg("      adding dxc1 '%s' \n", wdi->dxc1);*/
        return;
    }
    
    return;
}



int load_dw_from_file(struct dw *dw, gchar *filename){
    FILE *f;
      long int len;
      gchar *file;
      int ret;
      size_t r;
    
    f = fopen(filename, "rt");
    if (!f) {
/*        dbg("Can't open '%s'\n",filename);*/
        return -1;
    }
      if (fseek(f, SEEK_END, 0L)<0){
            fclose(f);
            return -1;
      }
      len=ftell(f);
      if (len<0 || len>0x10000000) {    /* g_new can allocate only gsize=unisgned int */
            fclose(f);
            return -1;
      }
      
      if (fseek(f, SEEK_SET, 0L)<0){
            fclose(f);
            return -1;
      }
      
      file=g_new(gchar, len);
      r=fread(file, 1, len, f);
    fclose(f);
      if (r!=len) return -1;
      ret=load_dw_from_mem(dw, file, len);
      g_free(file);
      return ret;
}

int load_dw_from_mem(struct dw *dw, const char *file, const long int len){
    GString *pref, *wwls, *centers; 
    gchar *dxc, *prefix, *wwl, *c0, *c1;
    struct dw_item *dxci;
    char *token_ptr;
      long int pos;

    pref    = g_string_sized_new(100);
    wwls    = g_string_sized_new(100);
    centers = g_string_sized_new(100);
    

      pos=0;
    while(1){
        do {
           if (!safe_mgets(pref,  file, &pos, len, 1)) goto abort;
        }while (pref->len==0);
        
        dxc = strtok_r(pref->str, DW_DELIM, &token_ptr);
        if (!dxc) continue;
        add_pd(dw, dxc, dxc);
        
        while ((prefix=strtok_r(NULL, DW_DELIM, &token_ptr))!=NULL){
            add_pd(dw, prefix, dxc);
        } 
        
        if (!safe_mgets(wwls,    file, &pos, len, 1)) break;
        if (!wwls->len) continue;

        if (!safe_mgets(centers, file, &pos, len, 1)) break;

        if (centers->len)  c0 = strtok_r(centers->str, DW_DELIM, &token_ptr);
        else               c0 = strtok_r(wwls->str,    DW_DELIM, &token_ptr);
        
        c1 = strtok_r(NULL, DW_DELIM, &token_ptr);
            

        dxci = add_dxc(dw, dxc, c0, c1); 
        
        add_dw(dxci, dxc, c0);
        add_dw(dxci, dxc, c1);
        add_wd(dw, c0, dxc);
        add_wd(dw, c1, dxc);

        if (centers->len){  
            c0 = strtok_r(wwls->str, DW_DELIM, &token_ptr);
            add_dw(dxci, dxc, c0);
            add_wd(dw, c0, dxc);
        }
        
        while((wwl = strtok_r(NULL, DW_DELIM, &token_ptr))!=NULL){
            add_dw(dxci, dxc, wwl);
            add_wd(dw, wwl, dxc);
        }  
        
    }
abort:;
    g_string_free(pref, 1);
    g_string_free(wwls, 1);
    g_string_free(centers, 1);
    return 0;
}

#define CTY_DELIM ":"
#define PREF_DELIM ","

int load_cty_from_file(struct dw *dw, gchar *filename){
    FILE *f;
      long int len;
      gchar *file;
      int ret;
      size_t r;
    
    f = fopen(filename, "rt");
    if (!f) {
/*        dbg("Can't open '%s'\n",filename);*/
        return -1;
    }
      if (fseek(f, SEEK_END, 0L)<0){
            fclose(f);
            return -1;
      }
      len=ftell(f);
      if (len<0 || len>0x10000000) {    /* g_new can allocate only gsize=unisgned int */
            fclose(f);
            return -1;
      }
      
      if (fseek(f, SEEK_SET, 0L)<0){
            fclose(f);
            return -1;
      }
      
      file=g_new(gchar, len);
      r=fread(file, 1, len, f);
    fclose(f);
      if (r!=len) return -1;
      ret=load_cty_from_mem(dw, file, len);
      g_free(file);
      return ret;
}


int load_cty_from_mem(struct dw *dw, const char *file, const long int len){
    GString *gs, *gs_next; 
    gchar **line, **prefs;
    int i;
    gchar *dxc;
    char wwl4[6];
      long int pos;
    struct dw_item *dxci;
    
    
    gs      = g_string_sized_new(100);
    gs_next = g_string_sized_new(100);
    
    pos=0;
    while(1){
        if (gs_next->len>0){
            g_string_assign(gs, gs_next->str);
        }else{
            if (!safe_mgets(gs,  file, &pos, len, 0)) break;
        }
        
        while(1){
            if (!safe_mgets(gs_next,  file, &pos, len, 0)){
                g_string_truncate(gs_next,0); /* next safe_mgets breaks loop */
                break;
            }
            
            if (gs_next->str[0]==' '){ 
                g_string_append(gs, gs_next->str);
            }else{
                break;
            }
        }

        
        line = g_strsplit(gs->str, CTY_DELIM, 9);
        for (i=0;i<9;i++) if (line[i] ==NULL) break;
        if (i!=9) continue;
        
        g_strstrip(line[4]);
        g_strstrip(line[5]);
        g_strstrip(line[7]);
        g_strstrip(line[8]);
        
        
        dxc=line[7];
        if (index(dxc, '/')) {
            g_strfreev(line);
            continue;
        }
        
        if (!dxc) continue;
        add_pd(dw, dxc, dxc);
        
/*        dbg("h=%s, w=%s, d=%s, p=%s\n", line[5], line[6], line[7], line[8]);*/
        
        prefs = g_strsplit(line[8], PREF_DELIM, 0);
        for (i=0; prefs[i]!=NULL; i++){
            char *c;

            g_strstrip(prefs[i]);
            if (index(prefs[i],'/')) continue;
            if ((c=index(prefs[i],'('))!=NULL) *c='\0';
            if ((c=index(prefs[i],'['))!=NULL) *c='\0';
            if ((c=index(prefs[i],';'))!=NULL) *c='\0';
            
            if (strlen(prefs[i])>2 && !isdigit(prefs[i][ strlen(prefs[i])-1])) continue;
            
            /*dbg("\t'%s'", prefs[i]);  */
            add_pd(dw, prefs[i], dxc);
            
        }
        g_strfreev(prefs);
        /*dbg("\n");*/
        compute_wwl4(wwl4, -atof(line[5]), atof(line[4]));

        /*dbg("h=%s, w=%s, d=%s, wwl4=%s \n", line[4], line[5], line[7], wwl4);*/
        dxci = add_dxc(dw, dxc, wwl4, NULL); 
        
        g_strfreev(line);
        
    }
    g_string_free(gs, 1);
    g_string_free(gs_next, 1);
    return 0;
}


void read_dw_files(struct dw *dw){
    gchar *s;
      int ret;
    
    s = g_strconcat(getenv("HOME"), "/tucnak/cty.dat", NULL);
    ret=load_cty_from_file(dw, s);
    g_free(s);
      if (ret<0){
      load_cty_from_mem(dw, txt_cty, sizeof(txt_cty));
      }
    
    s = g_strconcat(getenv("HOME"), "/tucnak/tucnakdw", NULL);
    ret=load_dw_from_file(dw, s);
    g_free(s);
      if (ret<0){
      load_dw_from_mem(dw, txt_tucnakdw, sizeof(txt_tucnakdw));
      }
}




int wwl_is_ok_by_call(struct dw *dw, gchar *wwl, gchar *call){
    char dxcc[25];
    struct dw_item *dxci;
    char swwl[5];
    
    if (!wwl || !call) return 1;
    
    get_dxcc(dw, dxcc, call);
    /*dbg("dxcc=%s\n", dxcc);*/
            
    dxci = g_hash_table_lookup(dw->dw, dxcc);
    if (!dxci) {
/*        dbg("can't find dxcc (%s) for call %s \n", dxcc, call);*/
        return 0;
    }

    safe_strncpy(swwl, wwl, 5);
    if (g_hash_table_lookup(dxci->wwls, swwl)){
/*       dbg("is OK\n"); */
       return 1; 
    }
/*    dbg("loc not found\n");*/
    return 0;
}


/* 0=OK
   1=WARN, known call from unknown locator
   2=ERR,  prefix and big wwl dont match
   256=WARN, suspicious call
   257=ERR, suspicious call
   
*/ 
int get_susp(struct cw *cw, struct dw *dw, gchar *call, gchar *wwl, int ambig){
    int susp=0;
    gchar *wwl0, *wwl1;
    
    /*dbg("get_susp('%s', '%s')\n", call, wwl);*/
    if (!call || !wwl || !*call || !*wwl) return 0;
    
    if (!wwl_is_ok_by_call(dw, wwl, call)) {
        susp=2; /* bad country */
        goto skip; 
    }

    wwl0=find_wwl_by_call(cw, call);
    wwl1=find_wwl_by_call(cw, NULL); 

    if (wwl0!=NULL){ /* we don't know this call, cannot be suspicious */
        susp = 1;
        if (wwl0 && strcasecmp(wwl0, wwl)==0) susp = 0; 
        if (wwl1 && strcasecmp(wwl1, wwl)==0) susp = 0; 
    }

skip:;    
    if (ambig) if (get_susp_ambiguous_call(cw, call, wwl, NULL, 1)) susp|=0x100;
    /* dbg("   ret=%d\n", susp);*/
    return susp;
}


int get_susp_call(struct cw *cw, struct dw *dw, gchar *call, gchar *wwl){
    int susp;
    char s[40]; 

   /* dbg("get_susp_call('%s', '%s')\n", call, wwl);*/
    if (!call || !*call){  /* pokud je vsechno NULL nebo "", tak get_susp skonci s nulou a test s /P pokracuje */
        return 0;
    }

    susp=get_susp(cw, dw, call, wwl, 1);
    if (susp) return 1; /* get_susp muze vratit 0x100 a co bysme s tim delali */

    get_raw_call(s, call);
    if (strcmp(s, call)==0){ /* without /p */
      /*  dbg("without ");*/
        strcat(s, "/P");
        if (find_wwl_by_call(cw, s)) {
            susp=1;   /* call is without /p and in C_W exists call with /p */
        }
    }else{        /* call is with /p */
        /*dbg("with ");*/
        if (find_wwl_by_call(cw, s)) {
            susp=1;   /* call is with /p and in C_W exists call without /p */
        }
    }

    if (wwl && *wwl) susp=get_susp_ambiguous_call(cw, call, wwl, NULL, 1);
    
   /* dbg("   ret=%d\n", susp);*/
    return susp;
}

int get_susp_loc(struct cw *cw, struct dw *dw, gchar *call, gchar *wwl){
    return get_susp(cw, dw, call, wwl, 0);
}

#define ADDQSO if (!err) { \
    if (qso->time_str){ \
        g_string_sprintfa(gs, "%s %s %c%c.%c%c\n", qso->callsign?qso->callsign:"?", qso->locator?qso->locator:"?", qso->time_str[0], qso->time_str[1], qso->time_str[2], qso->time_str[3]); \
    }else{ \
        g_string_sprintfa(gs, "%s %s\n", qso->callsign?qso->callsign:"?", qso->locator?qso->locator:"?"); \
    }err=1;}

int qso_info(struct qso *qso, GString *gs, GString *gs2){
    char s[40],s1[40], raw[40];
    int err,ret, susp, k;
    char *wwl0, *wwl1;
    struct band *b;
    struct qso *q;
    int i,j;


    ret=0;
    if (!qso) return -1;
    if (qso->error) return -1;
    if (qso->dupe) return -1;

    err=0;
    if (!find_name_by_call(namedb, qso->callsign) &&
        !find_wwl_by_call(cw, qso->callsign)){
        ADDQSO;
        g_string_sprintfa(gs, "Callsign unknown in namedb and C_W\n");
        ret=1;
    }

    if (qso->locator && *qso->locator){
        if (!wwl_is_ok_by_call(dw, qso->locator, qso->callsign)){
            ADDQSO;
            g_string_sprintfa(gs, "Prefix and big wwl dont match\n");
            ret=2;
        }
    }

    wwl0=find_wwl_by_call(cw, qso->callsign);
    wwl1=find_wwl_by_call(cw, NULL); 

    susp=0;
    if (wwl0!=NULL){ /* we don't know this call, cannot be suspicious */
        susp = 1;
        if (wwl0 && strcasecmp(wwl0, qso->locator)==0) susp = 0; 
        if (wwl1 && strcasecmp(wwl1, qso->locator)==0) susp = 0; 
    }

    if (qso->locator && *qso->locator){
        if (susp){
            ADDQSO;
            g_string_sprintfa(gs, "Known call from unknown locator\n");
            if (ret<1) ret=1;
        }
    }
    
    get_raw_call(raw, qso->callsign);
    strcpy(s, raw);
    if (strcmp(s, qso->callsign)==0){ /* without /p */
        strcpy(s1, s);
        strcat(s, "/P");
        if (find_wwl_by_call_newer(cw, raw, cw->minstamp)) {
            ADDQSO;
            g_string_sprintfa(gs, "Call is without /P and in C_W exists call with /P\n");
            if (ret<1) ret=1;
        }
        strcat(s1, "/");
        for (k=0;k<=9;k++){
            strcpy(s, s1);
            s[strlen(s)+1]='\0';
            s[strlen(s)]='0'+k;
            if (find_wwl_by_call_newer(cw, s, cw->minstamp)) {
                ADDQSO;
                g_string_sprintfa(gs, "Call is without /%d and in C_W exists call with /%d\n", k, k);
                if (ret<1) ret=1;
            }
        }

    }else{        /* call is with /p */
        if (find_wwl_by_call_newer(cw, s, cw->minstamp)) {
            ADDQSO;
            g_string_sprintfa(gs, "Call is with /P and in C_W exists call without /P\n");
            if (ret<1) ret=1;
        }
    }

    g_string_truncate(gs2, 0);
    get_susp_ambiguous_call(cw, qso->callsign, qso->locator, gs2, 1);
    if (gs2->len>0){
        ADDQSO;
        g_string_sprintfa(gs, "Other similar call known from this locator. Maybe %s?\n", gs2->str);
        if (ret<1) ret=1;
    }

    for (i=0; i<ctest->bands->len; i++){
        b = (struct band*)g_ptr_array_index(ctest->bands, i);
        if (b == qso->band) continue;
        for (j=0; j<b->qsos->len; j++){
            q = (struct qso *)g_ptr_array_index(b->qsos, j);
            if (q->error || q->dupe) continue;

            get_raw_call(s, q->callsign);

            /*if (q->callsign[0]=='D' && q->callsign[1]=='M' && q->callsign[2]=='7'){
                 dbg("call %s %s %s %d\n", q->callsign, s, raw, strcmp(s, raw));
            } */
            if (strcmp(s, raw) != 0) continue; /* not same station */
             /*dbg("RAW match %s %s\n", s, raw);*/
            if (strcmp(q->callsign, qso->callsign) != 0){ 
                ADDQSO;
                g_string_sprintfa(gs, "Callsign on band %c is %s\n", toupper(b->bandchar), q->callsign);
                if (ret<1) ret=1;
            }
            
            if (strcmp(q->locator, qso->locator) != 0){
                ADDQSO;
                g_string_sprintfa(gs, "Locator on band %c is %s\n", toupper(b->bandchar), q->locator);
                if (ret<1) ret=1;
            }

        }
    }
    

    return ret;
}

void menu_qso_check(union cba_t cba){
    GString *gs, *gs2;
    struct band *band;
    struct qso *qso;
    int i,j,ret;
    FILE *f;
    char *filename;

    if (!ctest) return;

    gs=g_string_sized_new(10000);
    gs2=g_string_sized_new(1000);
    g_string_sprintf(gs,  "   Tucnak QSO check list\n");
    g_string_sprintfa(gs, " *************************\n");
    g_string_sprintfa(gs, "\n\n");
    g_string_sprintfa(gs, "   Call: %s\n", ctest->pcall);
    g_string_sprintfa(gs, "Contest: %s\n", ctest->tname);
    g_string_sprintfa(gs, "   Date: %s\n", ctest->tdate);
    g_string_sprintfa(gs, "\n\n");

    for (i=0;i<ctest->bands->len;i++){
        band = (struct band *)g_ptr_array_index(ctest->bands, i);
        g_string_sprintfa(gs, "   Band %c %s\n", toupper(band->bandchar), band->pband);
        g_string_sprintfa(gs, " ********************\n");
        for (j=0;j<band->qsos->len;j++){
            qso = (struct qso *)g_ptr_array_index(band->qsos, j);
            ret=qso_info(qso, gs, gs2);
            if (ret) g_string_sprintfa(gs, "\n");
            if (ret>=0) qso->suspcall=ret;
        }
    }

    g_string_sprintfa(gs, "\n\nEOF\n");

    filename = g_strdup_printf("%s/qsocheck.txt", ctest->directory);
    f=fopen(filename,"wt");
    if (!f) {
        log_addf(VTEXT(T_CANT_WRITE_S), filename);
        errbox(VTEXT(T_CANT_WRITE), errno);
        g_free(filename);
        g_string_free(gs, TRUE);
        g_string_free(gs2, TRUE);
        return;
    }
    ret=fwrite(gs->str, 1, gs->len, f);
    fclose(f);
    if (ret!=gs->len){
        log_addf(VTEXT(T_CANT_WRITE_S), filename);
        errbox(VTEXT(T_CANT_WRITE), 0);
        g_free(filename);
        g_string_free(gs, TRUE);
        g_string_free(gs2, TRUE);
        return;
    }
    log_addf(VTEXT(T_SAVED_S), filename);
    g_free(filename);
    g_string_free(gs, TRUE);
    g_string_free(gs2, TRUE);
    return;
}

void call_info(union cba_t cba){
    struct qso *qso=NULL;
    GString *gs, *gs2;
    static char ss[1024];
    int err,freeqso,i;
    char *title, *c;
    char raw[30];

    gs=g_string_sized_new(500);
    gs2=g_string_sized_new(500);

      err=0;
      freeqso=0;
/*    dbg("TMPQ.callsign=%s %p\n", TMPQ.callsign, aband);*/

    if (cba.qso){
            qso=cba.qso;
        qso_info(qso, gs, gs2);
    }else if (aband && (!TMPQ.callsign || !strlen(TMPQ.callsign))){
        if (aband->qsos->len<=0) goto x;
        qso=(struct qso *)g_ptr_array_index(aband->qsos, aband->qsos->len-1);
        qso_info(qso, gs, gs2);
    }else if (aband){
        /* tmpqso is valid */
        qso=g_new0(struct qso, 1);
        qso->callsign = TMPQ.callsign;    /* foreign keys */
        qso->locator = TMPQ.locator;
        qso->rsts = TMPQ.rsts;
        qso->qsonrs = TMPQ.qsonrs;
        qso->rstr = TMPQ.rstr;
        qso->qsonrr = TMPQ.qsonrr;
        qso_info(qso, gs, gs2);
            freeqso=1;
    }else{
        qso=g_new0(struct qso, 1);
        qso->callsign = gses->il->cdata;    /* foreign key */
        qso->locator = "";
        qso->rsts = "";
        qso->qsonrs = "";
        qso->rstr = "";
        qso->qsonrr = "";
        qso_info(qso, gs, gs2);
            freeqso=1;
    }

    if (gs->len>0){
        title=VTEXT(T_CALL_INFO);
    }else{
            ADDQSO;
        g_string_sprintfa(gs, "Seems to be O.K.\n");
        safe_strncpy(ss, gs->str, sizeof(ss));
        title=VTEXT(T_OK);
    }

    /* next callsign info */
    g_string_append(gs, "\n");

    /* C_W */
    get_raw_call(raw, qso->callsign);
    g_string_truncate(gs2, 0);
    cwdb_call_info(gs2, qso->callsign, "");
    cwdb_call_info(gs2, qso->callsign, "/P");
    for (i=0;i<=9;i++){
        char stroke[10];
        sprintf(stroke, "/%d", i);
        cwdb_call_info(gs2, qso->callsign, stroke);
    }
    if (gs2->len>0){
        g_string_append(gs, gs2->str);
    }else{
        g_string_sprintfa(gs, "C_W: %s not found\n", qso->callsign);
    }

    /* namedb */
    c=find_name_by_call(namedb, qso->callsign);
    if (c){
        g_string_sprintfa(gs, "Name: %s's name is %s\n", qso->callsign, c);
    }else{
        g_string_sprintfa(gs, "Name: %s's name is unknown\n", qso->callsign);
    }

    safe_strncpy(ss, gs->str, sizeof(ss));
    msg_box(NULL, title, AL_LEFT, ss, NULL, 1, VTEXT(T_OK), NULL, B_ENTER | B_ESC);
x:;    
    g_string_free(gs, TRUE);
    g_string_free(gs2, TRUE);
    if (freeqso) g_free(qso);
}


gchar *find_wwl_by_dxc(struct dw *dw,  gchar *dxc){
    struct dw_item *dxci;

    if (!dxc) return dw_next;
    dw_next = NULL;
    
    dxci = g_hash_table_lookup(dw->dw, dxc);
    if (!dxci) return NULL;

    dw_next = dxci->wwl1;

    return dxci->wwl0;
    
}

gchar *find_dxc_by_wwl(struct dw *dw, gchar *wwl){
    struct wd_item *wdi;
    char s[10];

    if (!wwl) return wd_next;
    wd_next = NULL;

    safe_strncpy(s, wwl, 10);
    if (strlen(s)>4) s[4]='\0';

    wdi = g_hash_table_lookup(dw->wd, s);
    if (!wdi) return NULL;
    
    wd_next = wdi->dxc1;
    return wdi->dxc0;
    
}


char *get_dxcc(struct dw *dw, char *buf, char *call){ 
    char *c0, *c1, *dxc;
    
    c0=c1=NULL;
    safe_strncpy0(buf, call, 20);
    if (regmatch(call, "^(.*[0-9])[A-Z]*", &c0, &c1, NULL)==0){
        
        safe_strncpy0(buf, c1, 20);
        while (*c1!='\0'){
           dxc = g_hash_table_lookup(dw->pd, c1);
           if (dxc) {
      /*        dbg("get_dxcc(%s)='%s'\n", call, c1); */
              safe_strncpy0(buf, dxc, 20);
              break;
           }
           c1[strlen(c1)-1]='\0'; 
        }
    }
    if (c0) mem_free(c0);
    if (c1) mem_free(c1);
/*    dbg("get_dxcc='%s'\n", dxc);*/
    return buf;  
}


Generated by  Doxygen 1.6.0   Back to index