diff --git a/src/addmult.c b/src/addmult.c index dba6f04a..8a8301c9 100644 --- a/src/addmult.c +++ b/src/addmult.c @@ -42,226 +42,226 @@ GPtrArray *mults_possible; * -1 if not a (new) mult */ static int addmult_internal(struct qso_t *qso, bool check_only) { - int mult_index = -1; - int idx; - char *stripped_comment; + int mult_index = -1; + int idx; + char *stripped_comment; - stripped_comment = strdup(qso->comment); - g_strchomp(stripped_comment); + stripped_comment = strdup(qso->comment); + g_strchomp(stripped_comment); + + // --------------------------- arrlss ------------------------------------ + if (CONTEST_IS(ARRL_SS)) { + + idx = get_exact_mult_index(qso->mult1_value); + if (idx >= 0) { + remember_multi(get_mult(idx), qso->bandindex, MULT_ALL, check_only); + // NOTE: return value not used, new mult is not marked in log + } + } + + // ---------------------------serial + section --------------------------- + else if (serial_section_mult || sectn_mult) { + + /* is it a mult? */ + idx = get_exact_mult_index(qso->mult1_value); + if (idx >= 0) { + mult_index = + remember_multi(get_mult(idx), qso->bandindex, MULT_BAND, check_only); + } + } - // --------------------------- arrlss ------------------------------------ - if (CONTEST_IS(ARRL_SS)) { + // --------------------------- section_mult_once-------------------------- + else if (sectn_mult_once) { - idx = get_exact_mult_index(qso->mult1_value); - if (idx >= 0) { - remember_multi(get_mult(idx), qso->bandindex, MULT_ALL, check_only); - // NOTE: return value not used, new mult is not marked in log + /* is it a mult? */ + idx = get_exact_mult_index(qso->mult1_value); + if (idx >= 0) { + mult_index = + remember_multi(get_mult(idx), qso->bandindex, MULT_ALL, check_only); + } } - } - // ---------------------------serial + section --------------------------- - else if (serial_section_mult || sectn_mult) { + // ------------------------------- section ---------------------------- + else if (dx_arrlsections && (countrynr == w_cty || countrynr == ve_cty)) { + + idx = get_exact_mult_index(qso->mult1_value); + if (idx >= 0) { + mult_index = + remember_multi(get_mult(idx), qso->bandindex, MULT_BAND, check_only); + } + } - /* is it a mult? */ - idx = get_exact_mult_index(qso->mult1_value); - if (idx >= 0) { - mult_index = - remember_multi(get_mult(idx), qso->bandindex, MULT_BAND, check_only); + // --------------------wysiwyg---------------- + else if (wysiwyg_once) { + mult_index = remember_multi(stripped_comment, qso->bandindex, MULT_ALL, + check_only); } - } - // --------------------------- section_mult_once-------------------------- - else if (sectn_mult_once) { + else if (wysiwyg_multi) { + mult_index = remember_multi(stripped_comment, qso->bandindex, MULT_BAND, + check_only); + } - /* is it a mult? */ - idx = get_exact_mult_index(qso->mult1_value); - if (idx >= 0) { - mult_index = - remember_multi(get_mult(idx), qso->bandindex, MULT_ALL, check_only); + /* -------------- unique call multi -------------- */ + else if (unique_call_multi != MULT_NONE) { + mult_index = remember_multi(qso->call, qso->bandindex, unique_call_multi, + check_only); } - } - // ------------------------------- section ---------------------------- - else if (dx_arrlsections && (countrynr == w_cty || countrynr == ve_cty)) { + /* ------------ grid mult (per band) ------------- */ + else if (serial_grid4_mult) { + mult_index = remember_multi(qso->mult1_value, qso->bandindex, MULT_BAND, + check_only); + } - idx = get_exact_mult_index(qso->mult1_value); - if (idx >= 0) { - mult_index = - remember_multi(get_mult(idx), qso->bandindex, MULT_BAND, check_only); + // ----------- generic: use mult1 ----------- + else if (generic_mult != MULT_NONE) { + mult_index = remember_multi(qso->mult1_value, qso->bandindex, generic_mult, + check_only); } - } - - // --------------------wysiwyg---------------- - else if (wysiwyg_once) { - mult_index = remember_multi(stripped_comment, qso->bandindex, MULT_ALL, - check_only); - } - - else if (wysiwyg_multi) { - mult_index = remember_multi(stripped_comment, qso->bandindex, MULT_BAND, - check_only); - } - - /* -------------- unique call multi -------------- */ - else if (unique_call_multi != MULT_NONE) { - mult_index = remember_multi(qso->call, qso->bandindex, unique_call_multi, - check_only); - } - - /* ------------ grid mult (per band) ------------- */ - else if (serial_grid4_mult) { - mult_index = remember_multi(qso->mult1_value, qso->bandindex, MULT_BAND, - check_only); - } - - // ----------- generic: use mult1 ----------- - else if (generic_mult != MULT_NONE) { - mult_index = remember_multi(qso->mult1_value, qso->bandindex, generic_mult, - check_only); - } - - free(stripped_comment); - return mult_index; + + free(stripped_comment); + return mult_index; } int addmult(struct qso_t *qso) { - return addmult_internal(qso, false); + return addmult_internal(qso, false); } int check_mult(struct qso_t *qso) { - return addmult_internal(qso, true); // check_only mode + return addmult_internal(qso, true); // check_only mode } /* -------------------------------------------------------------------*/ void addmult_lan(void) { - int i; - int matching_len = 0, idx = -1; - char ssexchange[21]; - char stripped_comment[21]; - char multi_call[20]; - bool check_only = false;//FIXME param - - new_mult = -1; - - // --------------------------- arrlss ------------------------------------ - if (CONTEST_IS(ARRL_SS)) { - g_strlcpy(ssexchange, lan_logline + 54, 21); - - /* check all possible mults for match and remember the longest one */ - for (i = 0; i < get_mult_count(); i++) { - int len = get_matching_length(ssexchange, i); - if (len > matching_len) { - matching_len = len; - idx = i; - } + int i; + int matching_len = 0, idx = -1; + char ssexchange[21]; + char stripped_comment[21]; + char multi_call[20]; + bool check_only = false;//FIXME param + + new_mult = -1; + + // --------------------------- arrlss ------------------------------------ + if (CONTEST_IS(ARRL_SS)) { + g_strlcpy(ssexchange, lan_logline + 54, 21); + + /* check all possible mults for match and remember the longest one */ + for (i = 0; i < get_mult_count(); i++) { + int len = get_matching_length(ssexchange, i); + if (len > matching_len) { + matching_len = len; + idx = i; + } + } + + if (idx >= 0) { + remember_multi(get_mult(idx), bandinx, MULT_ALL, check_only); + } } - if (idx >= 0) { - remember_multi(get_mult(idx), bandinx, MULT_ALL, check_only); - } - } - - // --------------------wysiwyg---------------- - if (wysiwyg_once) { - g_strlcpy(stripped_comment, lan_logline + 54, 15); - g_strchomp(stripped_comment); + // --------------------wysiwyg---------------- + if (wysiwyg_once) { + g_strlcpy(stripped_comment, lan_logline + 54, 15); + g_strchomp(stripped_comment); - new_mult = remember_multi(stripped_comment, bandinx, MULT_ALL, check_only); - } + new_mult = remember_multi(stripped_comment, bandinx, MULT_ALL, check_only); + } - if (wysiwyg_multi) { - g_strlcpy(stripped_comment, lan_logline + 54, 15); - g_strchomp(stripped_comment); + if (wysiwyg_multi) { + g_strlcpy(stripped_comment, lan_logline + 54, 15); + g_strchomp(stripped_comment); - new_mult = remember_multi(stripped_comment, bandinx, MULT_BAND, check_only); - } + new_mult = remember_multi(stripped_comment, bandinx, MULT_BAND, check_only); + } - /* -------------- unique call multi -------------- */ - g_strlcpy(multi_call, lan_logline + 68, 10); - g_strchomp(multi_call); + /* -------------- unique call multi -------------- */ + g_strlcpy(multi_call, lan_logline + 68, 10); + g_strchomp(multi_call); - if (unique_call_multi == MULT_ALL) { - new_mult = remember_multi(multi_call, bandinx, MULT_ALL, check_only); - } + if (unique_call_multi == MULT_ALL) { + new_mult = remember_multi(multi_call, bandinx, MULT_ALL, check_only); + } - if (unique_call_multi == MULT_BAND) { - new_mult = remember_multi(multi_call, bandinx, MULT_BAND, check_only); - } + if (unique_call_multi == MULT_BAND) { + new_mult = remember_multi(multi_call, bandinx, MULT_BAND, check_only); + } } /* lookup n-th position in list of possible mults and * return pointer to data structure */ possible_mult_t *get_mult_base(int n) { - return (possible_mult_t *)g_ptr_array_index(mults_possible, n); + return (possible_mult_t *)g_ptr_array_index(mults_possible, n); } /* look up n-th position in list of possible mults and * return pointer to multname */ char *get_mult(int n) { - return get_mult_base(n)->name; + return get_mult_base(n)->name; } /* return alias list on n-th position of possible mults */ GSList *get_aliases(int n) { - return get_mult_base(n)->aliases; + return get_mult_base(n)->aliases; } /* return number of possible mults */ int get_mult_count(void) { - return mults_possible != NULL ? mults_possible->len : 0; + return mults_possible != NULL ? mults_possible->len : 0; } /* get best matching length of name or aliaslist of mult 'n' in 'str' */ unsigned int get_matching_length(char *str, unsigned int n) { - unsigned len = 0; + unsigned len = 0; - if (strstr(str, get_mult(n)) != NULL) { - len = strlen(get_mult(n)); - } + if (strstr(str, get_mult(n)) != NULL) { + len = strlen(get_mult(n)); + } - for (int i = 0; i < g_slist_length(get_aliases(n)); i++) { - char *tmp = g_slist_nth_data(get_aliases(n), i); - if (strstr(str, tmp) != NULL) { - if (strlen(tmp) >= len) - len = strlen(tmp); + for (int i = 0; i < g_slist_length(get_aliases(n)); i++) { + char *tmp = g_slist_nth_data(get_aliases(n), i); + if (strstr(str, tmp) != NULL) { + if (strlen(tmp) >= len) + len = strlen(tmp); + } } - } - return len; + return len; } /* get mult index for exact match */ int get_exact_mult_index(char *str) { - if (str == NULL) { - return -1; - } - int len = strlen(str); - if (len == 0) { - return -1; - } - for (int i = 0; i < get_mult_count(); i++) { - if (get_matching_length(str, i) == len) { - return i; + if (str == NULL) { + return -1; + } + int len = strlen(str); + if (len == 0) { + return -1; } - } - return -1; + for (int i = 0; i < get_mult_count(); i++) { + if (get_matching_length(str, i) == len) { + return i; + } + } + return -1; } /* function to free mults_possible entries */ void free_possible_mult(gpointer data) { - possible_mult_t *tmp = (possible_mult_t *)data; - g_free(tmp -> name); /* free the name of the multi */ - g_slist_free_full(tmp -> aliases, g_free); - g_free(tmp); + possible_mult_t *tmp = (possible_mult_t *)data; + g_free(tmp -> name); /* free the name of the multi */ + g_slist_free_full(tmp -> aliases, g_free); + g_free(tmp); } /* compare functions to sort multi by aphabetic order */ gint cmp_size(char **a, char **b) { - possible_mult_t *t1 = (possible_mult_t *)*a; - possible_mult_t *t2 = (possible_mult_t *)*b; - return g_strcmp0(t1->name, t2->name); + possible_mult_t *t1 = (possible_mult_t *)*a; + possible_mult_t *t2 = (possible_mult_t *)*b; + return g_strcmp0(t1->name, t2->name); } /* parse a mult line and add data to database @@ -274,44 +274,44 @@ gint cmp_size(char **a, char **b) { * There may be more than one alias line for a multi, so add all aliases to * that multi */ void add_mult_line(char *line) { - possible_mult_t *multi; - gchar **list; - char *mult = NULL; - int index = -1; - - list = g_strsplit(line, ":", 2); - mult = g_strstrip(list[0]); - - /* find mult in already defined ones */ - for (int i = 0; i < get_mult_count(); i++) { - if (strcmp(get_mult(i), mult) == 0) { - index = i; - break; + possible_mult_t *multi; + gchar **list; + char *mult = NULL; + int index = -1; + + list = g_strsplit(line, ":", 2); + mult = g_strstrip(list[0]); + + /* find mult in already defined ones */ + for (int i = 0; i < get_mult_count(); i++) { + if (strcmp(get_mult(i), mult) == 0) { + index = i; + break; + } } - } - - if (index == -1) { - /* not found -> prepare new one */ - multi = g_new0(possible_mult_t, 1); - multi->name = g_strdup(mult); - multi->aliases = NULL; - g_ptr_array_add(mults_possible, multi); - } else - /* else use existing one */ - multi = get_mult_base(index); - - if (list[1] != NULL) { /* parse aliases if present */ - gchar **aliaslist; - aliaslist = g_strsplit(list[1], ",", 0); - for (int i = 0; aliaslist[i] != NULL; i++) { - multi->aliases = - g_slist_append(multi->aliases, - g_strdup(g_strstrip(aliaslist[i]))); + + if (index == -1) { + /* not found -> prepare new one */ + multi = g_new0(possible_mult_t, 1); + multi->name = g_strdup(mult); + multi->aliases = NULL; + g_ptr_array_add(mults_possible, multi); + } else + /* else use existing one */ + multi = get_mult_base(index); + + if (list[1] != NULL) { /* parse aliases if present */ + gchar **aliaslist; + aliaslist = g_strsplit(list[1], ",", 0); + for (int i = 0; aliaslist[i] != NULL; i++) { + multi->aliases = + g_slist_append(multi->aliases, + g_strdup(g_strstrip(aliaslist[i]))); + } + g_strfreev(aliaslist); } - g_strfreev(aliaslist); - } - g_strfreev(list); + g_strfreev(list); } /** loads possible multipliers from external file @@ -329,62 +329,62 @@ void add_mult_line(char *line) { * */ int init_and_load_multipliers(void) { - FILE *cfp; - char *s_inputbuffer = NULL; - size_t s_inputbuffer_len = 0; - char *mults_location; - ssize_t read; - - if (mults_possible) { - /* free old array if exists */ - g_ptr_array_free(mults_possible, TRUE); - } - mults_possible = g_ptr_array_new_with_free_func(free_possible_mult); - - if (strlen(multsfile) == 0) { - return 0; - } - - mults_location = find_available(multsfile); - - if ((cfp = fopen(mults_location, "r")) == NULL) { - mvprintw(9, 0, "Error opening multiplier file %s.\n", multsfile); - refreshp(); - sleep(5); - } - - g_free(mults_location); - - if (cfp == NULL) { - return 0; // couldn't open file - } - - while ((read = getline(&s_inputbuffer, &s_inputbuffer_len, cfp)) != -1) { - if (s_inputbuffer_len > 0) { - /* strip leading and trailing whitespace */ - g_strstrip(s_inputbuffer); - - /* drop comments starting with '#' and empty lines */ - if (*s_inputbuffer == '#' || *s_inputbuffer == '\0') { - continue; - } - - add_mult_line(s_inputbuffer); - } - else { - fprintf(stderr, "RuntimeError: %s:%d", __FILE__, __LINE__); - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } - - fclose(cfp); - if (s_inputbuffer > 0) - free(s_inputbuffer); - /* do not rely on the order in the mult file but sort it here */ - g_ptr_array_sort(mults_possible, (GCompareFunc)cmp_size); - - return get_mult_count(); + FILE *cfp; + char *s_inputbuffer = NULL; + size_t s_inputbuffer_len = 0; + char *mults_location; + ssize_t read; + + if (mults_possible) { + /* free old array if exists */ + g_ptr_array_free(mults_possible, TRUE); + } + mults_possible = g_ptr_array_new_with_free_func(free_possible_mult); + + if (strlen(multsfile) == 0) { + return 0; + } + + mults_location = find_available(multsfile); + + if ((cfp = fopen(mults_location, "r")) == NULL) { + mvprintw(9, 0, "Error opening multiplier file %s.\n", multsfile); + refreshp(); + sleep(5); + } + + g_free(mults_location); + + if (cfp == NULL) { + return 0; // couldn't open file + } + + while ((read = getline(&s_inputbuffer, &s_inputbuffer_len, cfp)) != -1) { + if (s_inputbuffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + /* strip leading and trailing whitespace */ + g_strstrip(s_inputbuffer); + + /* drop comments starting with '#' and empty lines */ + if (*s_inputbuffer == '#' || *s_inputbuffer == '\0') { + continue; + } + + add_mult_line(s_inputbuffer); + } + } + + fclose(cfp); + if (s_inputbuffer > 0) + free(s_inputbuffer); + /* do not rely on the order in the mult file but sort it here */ + g_ptr_array_sort(mults_possible, (GCompareFunc)cmp_size); + + return get_mult_count(); } /** initialize mults scoring @@ -392,17 +392,17 @@ int init_and_load_multipliers(void) { * empties multis[] array, set the number of multis and multscore per band to 0. */ void init_mults() { - int n; + int n; - for (n = 0; n < MAX_MULTS; n++) { - multis[n].name[0] = '\0'; - multis[n].band = 0; - } + for (n = 0; n < MAX_MULTS; n++) { + multis[n].name[0] = '\0'; + multis[n].band = 0; + } - nr_multis = 0; + nr_multis = 0; - for (n = 0; n < NBANDS; n++) - multscore[n] = 0; + for (n = 0; n < NBANDS; n++) + multscore[n] = 0; } static pthread_mutex_t mult_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -422,54 +422,54 @@ static pthread_mutex_t mult_mutex = PTHREAD_MUTEX_INITIALIZER; * (-1 if multiplier is an empty string or not new) */ int remember_multi(char *multiplier, int band, int mult_mode, bool check_only) { - /* search multbuffer in mults array */ - bool found = false; - int index = -1; - if (multiplier == NULL || *multiplier == '\0' || mult_mode == MULT_NONE) - return -1; /* ignore if empty string or disabled */ - - pthread_mutex_lock(&mult_mutex); - - for (int i = 0; i < nr_multis; i++) { - /* already in list? */ - if (strcmp(multis[i].name, multiplier) == 0) { - found = 1; - - /* new band? check if mult is per band */ - if ((multis[i].band & inxes[band]) == 0) { - - if (!check_only) { - // update band even if not strictly needed - multis[i].band |= inxes[band]; - } - - if (mult_mode == MULT_BAND) { - index = i; // new band - } - } - - break; - } - } - - // found && index < 0: not new mult - // found && index >= 0: existing mult on a new band - // !found: new mult - - if (!found) { - index = nr_multis; /* not found, add new multi */ - } - - if (index >= 0 && !check_only) { - if (!found) { // new mult - strcpy(multis[index].name, multiplier); - nr_multis++; + /* search multbuffer in mults array */ + bool found = false; + int index = -1; + if (multiplier == NULL || *multiplier == '\0' || mult_mode == MULT_NONE) + return -1; /* ignore if empty string or disabled */ + + pthread_mutex_lock(&mult_mutex); + + for (int i = 0; i < nr_multis; i++) { + /* already in list? */ + if (strcmp(multis[i].name, multiplier) == 0) { + found = 1; + + /* new band? check if mult is per band */ + if ((multis[i].band & inxes[band]) == 0) { + + if (!check_only) { + // update band even if not strictly needed + multis[i].band |= inxes[band]; + } + + if (mult_mode == MULT_BAND) { + index = i; // new band + } + } + + break; + } + } + + // found && index < 0: not new mult + // found && index >= 0: existing mult on a new band + // !found: new mult + + if (!found) { + index = nr_multis; /* not found, add new multi */ + } + + if (index >= 0 && !check_only) { + if (!found) { // new mult + strcpy(multis[index].name, multiplier); + nr_multis++; + } + multis[index].band |= inxes[band]; + multscore[band]++; } - multis[index].band |= inxes[band]; - multscore[band]++; - } - pthread_mutex_unlock(&mult_mutex); + pthread_mutex_unlock(&mult_mutex); - return index; + return index; } diff --git a/src/bandmap.c b/src/bandmap.c index b39da1da..02cd8864 100644 --- a/src/bandmap.c +++ b/src/bandmap.c @@ -68,13 +68,13 @@ GList *allspots = NULL; GPtrArray *spots; bm_config_t bm_config = { - .allband = true, /* show all bands */ - .allmode = true, /* show all mode */ - .showdupes = true, /* show dupes */ - .skipdupes = true, /* skip dupes during grab */ - .lifetime = 900, /* default lifetime */ - .onlymults = false, /* DO NOT show ONLY multipliers */ - .show_out_of_band = false, /* do not show out-of-band spots */ + .allband = true, /* show all bands */ + .allmode = true, /* show all mode */ + .showdupes = true, /* show dupes */ + .skipdupes = true, /* skip dupes during grab */ + .lifetime = 900, /* default lifetime */ + .onlymults = false, /* DO NOT show ONLY multipliers */ + .show_out_of_band = false, /* do not show out-of-band spots */ }; static bool bm_initialized = false; @@ -89,122 +89,123 @@ spot *copy_spot(spot *data); */ void bmdata_write_file() { - FILE *fp; - spot *sp; - GList *found; - struct timeval tv; + FILE *fp; + spot *sp; + GList *found; + struct timeval tv; - if ((fp = fopen(".bmdata.dat", "w")) == NULL) { - attron(modify_attr(COLOR_PAIR(CB_DUPE) | A_BOLD)); - mvaddstr(13, 29, "can't open bandmap data file!"); - refreshp(); - return; - } + if ((fp = fopen(".bmdata.dat", "w")) == NULL) { + attron(modify_attr(COLOR_PAIR(CB_DUPE) | A_BOLD)); + mvaddstr(13, 29, "can't open bandmap data file!"); + refreshp(); + return; + } - gettimeofday(&tv, NULL); + gettimeofday(&tv, NULL); - pthread_mutex_lock(&bm_mutex); + pthread_mutex_lock(&bm_mutex); - found = allspots; - fprintf(fp, "%d\n", (int)tv.tv_sec); - while (found != NULL) { - sp = found->data; - fprintf(fp, "%s;%d;%d;%d;%c;%u;%d;%d;%d;%s;%d\n", - sp->call, sp->freq, sp->mode, sp->bandindex, - sp->node, sp->timeout, sp->dupe, sp->cqzone, - sp->ctynr, g_strchomp(sp->pfx), sp->mult); - found = found->next; - } + found = allspots; + fprintf(fp, "%d\n", (int)tv.tv_sec); + while (found != NULL) { + sp = found->data; + fprintf(fp, "%s;%d;%d;%d;%c;%u;%d;%d;%d;%s;%d\n", + sp->call, sp->freq, sp->mode, sp->bandindex, + sp->node, sp->timeout, sp->dupe, sp->cqzone, + sp->ctynr, g_strchomp(sp->pfx), sp->mult); + found = found->next; + } - pthread_mutex_unlock(&bm_mutex); + pthread_mutex_unlock(&bm_mutex); - fclose(fp); + fclose(fp); } /* * read bandmap spots from file, put them to allspots list */ void bmdata_read_file() { - FILE *fp; - struct timeval tv; - int timediff, last_bm_save_time, fc, read; - char *line = NULL; - char *token; - size_t line_len = 0; - static bool bmdata_parsed = false; - - if (bmdata_parsed) - return; - - if ((fp = fopen(".bmdata.dat", "r")) != NULL) { - bmdata_parsed = true; - if ((read = getline(&line, &line_len, fp)) != -1) { - sscanf(line, "%d", &last_bm_save_time); - gettimeofday(&tv, NULL); - timediff = (int)tv.tv_sec - last_bm_save_time; - if (timediff < 0) - timediff = 0; - - while ((read = getline(&line, &line_len, fp)) != -1) { - if (line_len > 0) { - spot *entry = g_new0(spot, 1); - fc = 0; - token = strtok(line, ";"); - while (token != NULL) { - switch (fc) { - case 0: entry -> call = g_strdup(token); - break; - case 1: sscanf(token, "%d", &entry->freq); - break; - case 2: sscanf(token, "%hhd", &entry->mode); - break; - case 3: // re-evaluate band index - entry->bandindex = freq2bandindex(entry->freq); - break; - case 4: sscanf(token, "%c", &entry->node); - break; - case 5: sscanf(token, "%u", &entry->timeout); - break; - case 6: // dupe is transient, not read back - entry->dupe = false; - break; - case 7: sscanf(token, "%d", &entry->cqzone); - break; - case 8: sscanf(token, "%d", &entry->ctynr); - break; - case 9: entry->pfx = g_strdup(token); - break; - case 10: // mult is transient, not read back - entry->mult = false; - break; - } - fc++; - token = strtok(NULL, ";"); - } - - if (entry->timeout > timediff) { - entry->timeout -= timediff; /* remaining time */ - allspots = g_list_insert_sorted(allspots, entry, (GCompareFunc)cmp_freq); - } else { - free_spot(entry); - } - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - - if (line != NULL) - free(line); - - fclose(fp); - } + FILE *fp; + struct timeval tv; + int timediff, last_bm_save_time, fc, read; + char *line = NULL; + char *token; + size_t line_len = 0; + static bool bmdata_parsed = false; + + if (bmdata_parsed) + return; + + if ((fp = fopen(".bmdata.dat", "r")) != NULL) { + bmdata_parsed = true; + if ((read = getline(&line, &line_len, fp)) != -1) { + sscanf(line, "%d", &last_bm_save_time); + gettimeofday(&tv, NULL); + timediff = (int)tv.tv_sec - last_bm_save_time; + if (timediff < 0) + timediff = 0; + + while ((read = getline(&line, &line_len, fp)) != -1) { + if (line_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + + spot *entry = g_new0(spot, 1); + fc = 0; + token = strtok(line, ";"); + while (token != NULL) { + switch (fc) { + case 0: entry -> call = g_strdup(token); + break; + case 1: sscanf(token, "%d", &entry->freq); + break; + case 2: sscanf(token, "%hhd", &entry->mode); + break; + case 3: // re-evaluate band index + entry->bandindex = freq2bandindex(entry->freq); + break; + case 4: sscanf(token, "%c", &entry->node); + break; + case 5: sscanf(token, "%u", &entry->timeout); + break; + case 6: // dupe is transient, not read back + entry->dupe = false; + break; + case 7: sscanf(token, "%d", &entry->cqzone); + break; + case 8: sscanf(token, "%d", &entry->ctynr); + break; + case 9: entry->pfx = g_strdup(token); + break; + case 10: // mult is transient, not read back + entry->mult = false; + break; + } + fc++; + token = strtok(NULL, ";"); + } + + if (entry->timeout > timediff) { + entry->timeout -= timediff; /* remaining time */ + allspots = g_list_insert_sorted(allspots, entry, (GCompareFunc)cmp_freq); + } else { + free_spot(entry); + } + } + } + } else { + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + + if (line != NULL) + free(line); + + fclose(fp); + } } /** \brief initialize bandmap @@ -213,23 +214,23 @@ void bmdata_read_file() { */ void bm_init() { - if (bm_initialized) - return; + if (bm_initialized) + return; - pthread_mutex_lock(&bm_mutex); + pthread_mutex_lock(&bm_mutex); - init_pair(CB_NEW, COLOR_CYAN, COLOR_WHITE); - init_pair(CB_NORMAL, COLOR_BLUE, COLOR_WHITE); - init_pair(CB_DUPE, COLOR_BLACK, COLOR_WHITE); - init_pair(CB_OLD, COLOR_YELLOW, COLOR_WHITE); + init_pair(CB_NEW, COLOR_CYAN, COLOR_WHITE); + init_pair(CB_NORMAL, COLOR_BLUE, COLOR_WHITE); + init_pair(CB_DUPE, COLOR_BLACK, COLOR_WHITE); + init_pair(CB_OLD, COLOR_YELLOW, COLOR_WHITE); - spots = g_ptr_array_new_full(128, (GDestroyNotify)free_spot); + spots = g_ptr_array_new_full(128, (GDestroyNotify)free_spot); - bmdata_read_file(); + bmdata_read_file(); - pthread_mutex_unlock(&bm_mutex); + pthread_mutex_unlock(&bm_mutex); - bm_initialized = true; + bm_initialized = true; } /** \brief guess mode based on frequency @@ -237,12 +238,12 @@ void bm_init() { * \return CWMODE, DIGIMODE or SSBMODE */ int freq2mode(freq_t freq, int band) { - if (freq <= cwcorner[band]) - return CWMODE; - else if (freq < ssbcorner[band]) - return DIGIMODE; - else - return SSBMODE; + if (freq <= cwcorner[band]) + return CWMODE; + else if (freq < ssbcorner[band]) + return DIGIMODE; + else + return SSBMODE; } /** \brief add DX spot message to bandmap @@ -250,48 +251,48 @@ int freq2mode(freq_t freq, int band) { * check if cluster message is a dx spot, * if so split it into pieces and insert in spot list */ void bm_add(char *s) { - char *line; - char *call; - char node = ' '; - - line = g_strdup(s); - if (strncmp(line, "DX de ", 6) != 0) { - g_free(line); - return; - } + char *line; + char *call; + char node = ' '; + + line = g_strdup(s); + if (strncmp(line, "DX de ", 6) != 0) { + g_free(line); + return; + } - if ((call = strtok(line + 26, " \t")) == NULL) { - g_free(line); - return; - } + if ((call = strtok(line + 26, " \t")) == NULL) { + g_free(line); + return; + } - if (strncmp(line + 6, "TLF-", 4) == 0) - node = line[10]; /* get sending node id */ + if (strncmp(line + 6, "TLF-", 4) == 0) + node = line[10]; /* get sending node id */ - bandmap_addspot(call, atof(line + 16) * 1000, node); - g_free(line); + bandmap_addspot(call, atof(line + 16) * 1000, node); + g_free(line); } /* compare functions to search in list */ gint cmp_call(spot *ldata, char *call) { - return g_strcmp0(ldata->call, call); + return g_strcmp0(ldata->call, call); } gint cmp_freq(spot *a, spot *b) { - unsigned int af = a->freq; - unsigned int bf = b->freq; + unsigned int af = a->freq; + unsigned int bf = b->freq; - if (af < bf) return -1; - if (af > bf) return 1; - return 0; + if (af < bf) return -1; + if (af > bf) return 1; + return 0; } /* free an allocated spot */ void free_spot(spot *data) { - g_free(data->call); - g_free(data->pfx); - g_free(data); + g_free(data->call); + g_free(data->pfx); + g_free(data); } /** add a new spot to bandmap data @@ -300,159 +301,159 @@ void free_spot(spot *data) { * \param node reporting node */ void bandmap_addspot(char *call, freq_t freq, char node) { - /* - if a spot on that band and mode is already in list replace old entry - * with new one and set timeout to SPOT_NEW, - * otherwise add it to the list as new - * - if other call on same frequency (with some TOLERANCE) replace it and set - * timeout to SPOT_NEW - * - all frequencies from cluster are rounded to 100 Hz, - * remember all other frequencies exactly - * but display only rounded to 100 Hz - sort exact - */ - GList *found; - int bandindex; - char mode; - dxcc_data *dxccdata; - int dxccindex; - int wi; - char *lastexch; - struct ie_list *current_ie; - - /* add only HF spots */ - if (freq > 30000000) - return; - - bandindex = freq2bandindex(freq); - mode = freq2mode(freq, bandindex); - - /* acquire bandmap mutex */ - pthread_mutex_lock(&bm_mutex); - - /* look if call is already on list in that mode and band */ - /* each call is allowed in every combination of band and mode - * but only once */ - found = g_list_find_custom(allspots, call, (GCompareFunc)cmp_call); - - while (found != NULL) { - - /* if same band and mode -> found spot already in list */ - if (((spot *)found->data)->bandindex == bandindex && - ((spot *)found->data)->mode == mode) - break; - - found = g_list_find_custom(found->next, call, (GCompareFunc)cmp_call); - } - - /* if already in list on that band and mode - * -> set timeout to SPOT_NEW, and set new freq and reporting node - * if freq has changed enough sort list anew by freq - */ - if (found) { - ((spot *)found->data)->timeout = SPOT_NEW; - ((spot *)found->data)->node = node; - if (DISTANCE(((spot *)found->data)->freq, freq) > TOLERANCE) { - ((spot *)found->data)->freq = freq; - allspots = g_list_sort(allspots, (GCompareFunc)cmp_freq); - } - } else { - /* if not in list already -> prepare new entry and - * insert in list at correct freq */ - spot *entry = g_new(spot, 1); - entry -> call = g_strdup(call); - entry -> freq = freq; - entry -> mode = mode; - entry -> bandindex = bandindex; - entry -> node = node; - entry -> timeout = SPOT_NEW; - entry -> dupe = 0; /* Dupe will be determined later. */ - entry -> mult = false; /* Mult will be determined later. */ - - lastexch = NULL; - dxccindex = getctynr(entry->call); - if (CONTEST_IS(CQWW)) { - // check if the callsign exists in worked list - wi = lookup_worked(call); - if (wi >= 0) { - lastexch = g_strdup(worked[wi].exchange); - } - - if (lastexch == NULL && main_ie_list != NULL) { - current_ie = main_ie_list; - - while (current_ie) { - if (strcmp(call, current_ie->call) == 0) { - lastexch = g_strdup(current_ie->exchange); + /* - if a spot on that band and mode is already in list replace old entry + * with new one and set timeout to SPOT_NEW, + * otherwise add it to the list as new + * - if other call on same frequency (with some TOLERANCE) replace it and set + * timeout to SPOT_NEW + * - all frequencies from cluster are rounded to 100 Hz, + * remember all other frequencies exactly + * but display only rounded to 100 Hz - sort exact + */ + GList *found; + int bandindex; + char mode; + dxcc_data *dxccdata; + int dxccindex; + int wi; + char *lastexch; + struct ie_list *current_ie; + + /* add only HF spots */ + if (freq > 30000000) + return; + + bandindex = freq2bandindex(freq); + mode = freq2mode(freq, bandindex); + + /* acquire bandmap mutex */ + pthread_mutex_lock(&bm_mutex); + + /* look if call is already on list in that mode and band */ + /* each call is allowed in every combination of band and mode + * but only once */ + found = g_list_find_custom(allspots, call, (GCompareFunc)cmp_call); + + while (found != NULL) { + + /* if same band and mode -> found spot already in list */ + if (((spot *)found->data)->bandindex == bandindex && + ((spot *)found->data)->mode == mode) break; - } - current_ie = current_ie->next; - } - } + + found = g_list_find_custom(found->next, call, (GCompareFunc)cmp_call); } - if (dxccindex > 0) { - dxccdata = dxcc_by_index(dxccindex); - entry -> cqzone = dxccdata->cq; - if (lastexch != NULL) { - entry -> cqzone = atoi(lastexch); - g_free(lastexch); - } - entry -> ctynr = dxccindex; - entry -> pfx = g_strdup(dxccdata->pfx); + + /* if already in list on that band and mode + * -> set timeout to SPOT_NEW, and set new freq and reporting node + * if freq has changed enough sort list anew by freq + */ + if (found) { + ((spot *)found->data)->timeout = SPOT_NEW; + ((spot *)found->data)->node = node; + if (DISTANCE(((spot *)found->data)->freq, freq) > TOLERANCE) { + ((spot *)found->data)->freq = freq; + allspots = g_list_sort(allspots, (GCompareFunc)cmp_freq); + } } else { - entry -> cqzone = 0; - entry -> ctynr = 0; - entry -> pfx = g_strdup(""); + /* if not in list already -> prepare new entry and + * insert in list at correct freq */ + spot *entry = g_new(spot, 1); + entry -> call = g_strdup(call); + entry -> freq = freq; + entry -> mode = mode; + entry -> bandindex = bandindex; + entry -> node = node; + entry -> timeout = SPOT_NEW; + entry -> dupe = 0; /* Dupe will be determined later. */ + entry -> mult = false; /* Mult will be determined later. */ + + lastexch = NULL; + dxccindex = getctynr(entry->call); + if (CONTEST_IS(CQWW)) { + // check if the callsign exists in worked list + wi = lookup_worked(call); + if (wi >= 0) { + lastexch = g_strdup(worked[wi].exchange); + } + + if (lastexch == NULL && main_ie_list != NULL) { + current_ie = main_ie_list; + + while (current_ie) { + if (strcmp(call, current_ie->call) == 0) { + lastexch = g_strdup(current_ie->exchange); + break; + } + current_ie = current_ie->next; + } + } + } + if (dxccindex > 0) { + dxccdata = dxcc_by_index(dxccindex); + entry -> cqzone = dxccdata->cq; + if (lastexch != NULL) { + entry -> cqzone = atoi(lastexch); + g_free(lastexch); + } + entry -> ctynr = dxccindex; + entry -> pfx = g_strdup(dxccdata->pfx); + } else { + entry -> cqzone = 0; + entry -> ctynr = 0; + entry -> pfx = g_strdup(""); + } + allspots = g_list_insert_sorted(allspots, entry, (GCompareFunc)cmp_freq); + /* lookup where it is */ + found = g_list_find(allspots, entry); + } + + /* check that spot is unique on freq +/- TOLERANCE Hz, + * drop other entries if needed */ + if (found->prev && + (DISTANCE(((spot *)(found->prev)->data)->freq, freq) < TOLERANCE)) { + spot *olddata; + olddata = found->prev->data; + allspots = g_list_remove_link(allspots, found->prev); + free_spot(olddata); } - allspots = g_list_insert_sorted(allspots, entry, (GCompareFunc)cmp_freq); - /* lookup where it is */ - found = g_list_find(allspots, entry); - } - - /* check that spot is unique on freq +/- TOLERANCE Hz, - * drop other entries if needed */ - if (found->prev && - (DISTANCE(((spot *)(found->prev)->data)->freq, freq) < TOLERANCE)) { - spot *olddata; - olddata = found->prev->data; - allspots = g_list_remove_link(allspots, found->prev); - free_spot(olddata); - } - if (found->next && - (DISTANCE(((spot *)(found->next)->data)->freq, freq) < TOLERANCE)) { - spot *olddata; - olddata = found->next->data; - allspots = g_list_remove_link(allspots, found->next); - free_spot(olddata); - } - - pthread_mutex_unlock(&bm_mutex); + if (found->next && + (DISTANCE(((spot *)(found->next)->data)->freq, freq) < TOLERANCE)) { + spot *olddata; + olddata = found->next->data; + allspots = g_list_remove_link(allspots, found->next); + free_spot(olddata); + } + + pthread_mutex_unlock(&bm_mutex); } void bandmap_age() { - /* - * go through all entries - * + decrement timeout - * + set state to new, normal, aged or dead - * + if dead -> drop it from collection - */ - - pthread_mutex_lock(&bm_mutex); - - GList *list = allspots; - - while (list) { - spot *data = list->data; - GList *temp = list; - list = list->next; - if (data->timeout) { - data->timeout--; - } - if (data->timeout == 0) { - allspots = g_list_remove_link(allspots, temp); - free_spot(data); + /* + * go through all entries + * + decrement timeout + * + set state to new, normal, aged or dead + * + if dead -> drop it from collection + */ + + pthread_mutex_lock(&bm_mutex); + + GList *list = allspots; + + while (list) { + spot *data = list->data; + GList *temp = list; + list = list->next; + if (data->timeout) { + data->timeout--; + } + if (data->timeout == 0) { + allspots = g_list_remove_link(allspots, temp); + free_spot(data); + } } - } - pthread_mutex_unlock(&bm_mutex); + pthread_mutex_unlock(&bm_mutex); } /** check if call is new multi @@ -461,15 +462,15 @@ void bandmap_age() { */ bool bm_ismulti(spot *data) { - if (data == NULL || data->cqzone <= 0 || data->ctynr <= 0) { - return false; // no data - } + if (data == NULL || data->cqzone <= 0 || data->ctynr <= 0) { + return false; // no data + } - if (contest->is_multi) { - return contest->is_multi(data); - } + if (contest->is_multi) { + return contest->is_multi(data); + } - return general_ismulti(data); + return general_ismulti(data); } /** check if call is a dupe @@ -480,74 +481,74 @@ bool bm_ismulti(spot *data) { bool bm_isdupe(char *call, int band) { - /* spots for warc bands are never dupes */ - if (IsWarcIndex(band)) - return false; + /* spots for warc bands are never dupes */ + if (IsWarcIndex(band)) + return false; - int found = lookup_worked(call); + int found = lookup_worked(call); - if (found == -1) /* new call */ - return false; + if (found == -1) /* new call */ + return false; - if (qtcdirection > 0) { - struct t_qtc_store_obj *qtc_obj = qtc_get(call); - if (qtc_obj->total > 0 && qtc_obj->total < 10) { - return false; - } - if (qtc_obj->total == 0 && qtc_obj->capable > 0) { - return false; + if (qtcdirection > 0) { + struct t_qtc_store_obj *qtc_obj = qtc_get(call); + if (qtc_obj->total > 0 && qtc_obj->total < 10) { + return false; + } + if (qtc_obj->total == 0 && qtc_obj->capable > 0) { + return false; + } } - } - if (worked[found].band & inxes[band]) { - return worked_in_current_minitest_period(found); - } + if (worked[found].band & inxes[band]) { + return worked_in_current_minitest_period(found); + } - return false; + return false; } void bm_show_info() { - int curx, cury; + int curx, cury; - getyx(stdscr, cury, curx); /* remember cursor */ + getyx(stdscr, cury, curx); /* remember cursor */ - /* show info field on the right */ - attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); - move(TOPLINE, 66); - vline(ACS_VLINE, LINES - TOPLINE - 1); + /* show info field on the right */ + attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); + move(TOPLINE, 66); + vline(ACS_VLINE, LINES - TOPLINE - 1); - int middle = (LINES - 1 + TOPLINE) / 2; - int arrow = (grab_up ? ACS_DARROW : ACS_UARROW); - mvaddch(middle - 1, 66, arrow); - mvaddch(middle, 66, arrow); - mvaddch(middle + 1, 66, arrow); + int middle = (LINES - 1 + TOPLINE) / 2; + int arrow = (grab_up ? ACS_DARROW : ACS_UARROW); + mvaddch(middle - 1, 66, arrow); + mvaddch(middle, 66, arrow); + mvaddch(middle + 1, 66, arrow); - mvprintw(LASTLINE - 5, 67, " bands: %s", bm_config.allband ? "all" : "own"); - mvprintw(LASTLINE - 4, 67, " modes: %s", bm_config.allmode ? "all" : "own"); - mvprintw(LASTLINE - 3, 67, " dupes: %s", bm_config.showdupes ? "yes" : "no"); - mvprintw(LASTLINE - 2, 67, " onl.ml: %s", bm_config.onlymults ? "yes" : "no"); + mvprintw(LASTLINE - 5, 67, " bands: %s", bm_config.allband ? "all" : "own"); + mvprintw(LASTLINE - 4, 67, " modes: %s", bm_config.allmode ? "all" : "own"); + mvprintw(LASTLINE - 3, 67, " dupes: %s", bm_config.showdupes ? "yes" : "no"); + mvprintw(LASTLINE - 2, 67, " onl.ml: %s", bm_config.onlymults ? "yes" : "no"); - attrset(COLOR_PAIR(CB_NEW) | A_BOLD); - mvaddstr(LASTLINE - 1, 67, " NEW"); + attrset(COLOR_PAIR(CB_NEW) | A_BOLD); + mvaddstr(LASTLINE - 1, 67, " NEW"); - attrset(COLOR_PAIR(CB_NORMAL)); - printw(" SPOT"); + attrset(COLOR_PAIR(CB_NORMAL)); + printw(" SPOT"); - attrset(COLOR_PAIR(CB_OLD)); - printw(" OLD"); + attrset(COLOR_PAIR(CB_OLD)); + printw(" OLD"); - attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); - mvaddstr(LASTLINE, 67, " dupe"); + attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); + mvaddstr(LASTLINE, 67, " dupe"); - attrset(COLOR_PAIR(CB_NORMAL)); - printw(" M"); - attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); - printw("-ulti"); + attrset(COLOR_PAIR(CB_NORMAL)); + printw(" M"); + attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); + printw("-ulti"); - attroff(A_BOLD | A_STANDOUT); + attroff(A_BOLD | A_STANDOUT); - move(cury, curx); /* reset cursor */ + move(cury, curx); /* reset cursor */ } /* helper function for bandmap display @@ -558,19 +559,19 @@ void bm_show_info() { * - worked small caps */ void colorize_spot(spot *data) { - if (data -> timeout > SPOT_NORMAL) - attrset(COLOR_PAIR(CB_NEW) | A_BOLD); + if (data -> timeout > SPOT_NORMAL) + attrset(COLOR_PAIR(CB_NEW) | A_BOLD); - else if (data -> timeout > SPOT_OLD) - attrset(COLOR_PAIR(CB_NORMAL)); + else if (data -> timeout > SPOT_OLD) + attrset(COLOR_PAIR(CB_NORMAL)); - else - attrset(COLOR_PAIR(CB_OLD)); + else + attrset(COLOR_PAIR(CB_OLD)); - if (data->dupe && bm_config.showdupes) { - attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); - attroff(A_STANDOUT); - } + if (data->dupe && bm_config.showdupes) { + attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); + attroff(A_STANDOUT); + } } /* helper function for bandmap display @@ -578,31 +579,31 @@ void colorize_spot(spot *data) { * add QTC flags for WAE contest */ char *format_spot(spot *data) { - char *temp; - char *temp2; - - if (qtcdirection > 0) { - temp = qtc_format(data->call); - } else - temp = g_strdup(data->call); - - if (data->dupe && bm_config.showdupes) { - temp2 = temp; - temp = g_ascii_strdown(temp2, -1); - g_free(temp2); - } - return temp; + char *temp; + char *temp2; + + if (qtcdirection > 0) { + temp = qtc_format(data->call); + } else + temp = g_strdup(data->call); + + if (data->dupe && bm_config.showdupes) { + temp2 = temp; + temp = g_ascii_strdown(temp2, -1); + g_free(temp2); + } + return temp; } static char get_spot_marker(spot *data) { - if (data->bandindex == BANDINDEX_OOB) { - return 'X'; - } - if (data->mult) { - return 'M'; - } - - return ' '; + if (data->bandindex == BANDINDEX_OOB) { + return 'X'; + } + if (data->mult) { + return 'M'; + } + + return ' '; } @@ -610,23 +611,23 @@ static char get_spot_marker(spot *data) { * shows formatted spot on actual cursor position */ void show_spot(spot *data) { - attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); - printw("%7.1f%c", (data->freq / 1000.), - (data->node == thisnode ? '*' : data->node)); - - char marker = get_spot_marker(data); - if (marker != ' ') { - attrset(COLOR_PAIR(CB_NORMAL)); - } - addch(marker); - if (marker != ' ') { attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); - } + printw("%7.1f%c", (data->freq / 1000.), + (data->node == thisnode ? '*' : data->node)); - char *temp = format_spot(data); - colorize_spot(data); - printw(" %-12s", temp); - g_free(temp); + char marker = get_spot_marker(data); + if (marker != ' ') { + attrset(COLOR_PAIR(CB_NORMAL)); + } + addch(marker); + if (marker != ' ') { + attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); + } + + char *temp = format_spot(data); + colorize_spot(data); + printw(" %-12s", temp); + g_free(temp); } /* helper function for bandmap display @@ -634,24 +635,24 @@ void show_spot(spot *data) { */ void show_spot_on_qrg(spot *data) { - printw("%7.1f%c%c ", (data->freq / 1000.), - (data->node == thisnode ? '*' : data->node), - get_spot_marker(data)); + printw("%7.1f%c%c ", (data->freq / 1000.), + (data->node == thisnode ? '*' : data->node), + get_spot_marker(data)); - char *temp = format_spot(data); - printw("%-12s", temp); - g_free(temp); + char *temp = format_spot(data); + printw("%-12s", temp); + g_free(temp); } /* helper function for bandmap display * advance to next spot position */ void next_spot_position(int *y, int *x) { - *y += 1; - if (*y == LASTLINE + 1) { - *y = TOPLINE; - *x += SPOT_COLUMN_WIDTH; - } + *y += 1; + if (*y == LASTLINE + 1) { + *y = TOPLINE; + *x += SPOT_COLUMN_WIDTH; + } } /* helper function for bandmap display @@ -662,29 +663,29 @@ void next_spot_position(int *y, int *x) { * as middle value of the band/mode corners. */ freq_t bm_get_center(int band, int mode) { - freq_t centerfrequency; - - if (trx_control) - return freq; /* return freq from rig */ - - /* calculate center frequency for current band and mode */ - if (CWMODE == mode) { - centerfrequency = (bandcorner[band][0] + cwcorner[band]) / 2.; - } else if (SSBMODE == mode) { - centerfrequency = (ssbcorner[band] + bandcorner[band][1]) / 2.; - } else { - centerfrequency = (cwcorner[band] + ssbcorner[band]) / 2.; - } - return centerfrequency; + freq_t centerfrequency; + + if (trx_control) + return freq; /* return freq from rig */ + + /* calculate center frequency for current band and mode */ + if (CWMODE == mode) { + centerfrequency = (bandcorner[band][0] + cwcorner[band]) / 2.; + } else if (SSBMODE == mode) { + centerfrequency = (ssbcorner[band] + bandcorner[band][1]) / 2.; + } else { + centerfrequency = (cwcorner[band] + ssbcorner[band]) / 2.; + } + return centerfrequency; } /* small helpers for filter_spots() */ static bool band_matches(spot *data) { - return (data->bandindex == bandinx); + return (data->bandindex == bandinx); } static bool mode_matches(spot *data) { - return (data->mode == trxmode); + return (data->mode == trxmode); } /* @@ -692,279 +693,279 @@ static bool mode_matches(spot *data) { * selected spots */ void filter_spots() { - GList *list; - spot *data; - /* acquire mutex - * do not add new spots to allspots during - * - aging and - * - filtering - * furthermore do not allow call lookup as long as - * filtered spot array is build anew */ - - pthread_mutex_lock(&bm_mutex); - - if (spots) - g_ptr_array_free(spots, TRUE); /* free spot array */ - /* allocate new one */ - spots = g_ptr_array_new_full(128, (GDestroyNotify)free_spot); - - for (list = allspots; list; list = list->next) { - data = list->data; - - /* check and mark spot as dupe */ - data->dupe = bm_isdupe(data->call, data->bandindex); - - /* ignore spots on WARC bands if in contest mode */ - if (iscontest && IsWarcIndex(data->bandindex)) - continue; - - /* ignore dupes if not forced */ - if (data->dupe && !bm_config.showdupes) - continue; - - /* Ignore non-multis if we want to show only multis */ - data->mult = bm_ismulti(data); - if (!data->mult && bm_config.onlymults) - continue; - - /* ignore out-of-band spots if configured so */ - if (data->bandindex == BANDINDEX_OOB && !bm_config.show_out_of_band) { - continue; - } + GList *list; + spot *data; + /* acquire mutex + * do not add new spots to allspots during + * - aging and + * - filtering + * furthermore do not allow call lookup as long as + * filtered spot array is build anew */ - /* if spot is allband or allmode is set or band or mode matches - * than add to the filtered 'spot' array - */ - if ((bm_config.allband || band_matches(data)) && - (bm_config.allmode || mode_matches(data))) { + pthread_mutex_lock(&bm_mutex); + + if (spots) + g_ptr_array_free(spots, TRUE); /* free spot array */ + /* allocate new one */ + spots = g_ptr_array_new_full(128, (GDestroyNotify)free_spot); + + for (list = allspots; list; list = list->next) { + data = list->data; + + /* check and mark spot as dupe */ + data->dupe = bm_isdupe(data->call, data->bandindex); + + /* ignore spots on WARC bands if in contest mode */ + if (iscontest && IsWarcIndex(data->bandindex)) + continue; + + /* ignore dupes if not forced */ + if (data->dupe && !bm_config.showdupes) + continue; + + /* Ignore non-multis if we want to show only multis */ + data->mult = bm_ismulti(data); + if (!data->mult && bm_config.onlymults) + continue; + + /* ignore out-of-band spots if configured so */ + if (data->bandindex == BANDINDEX_OOB && !bm_config.show_out_of_band) { + continue; + } + + /* if spot is allband or allmode is set or band or mode matches + * than add to the filtered 'spot' array + */ + if ((bm_config.allband || band_matches(data)) && + (bm_config.allmode || mode_matches(data))) { - spot *copy = copy_spot(data); - g_ptr_array_add(spots, copy); + spot *copy = copy_spot(data); + g_ptr_array_add(spots, copy); + } } - } - pthread_mutex_unlock(&bm_mutex); + pthread_mutex_unlock(&bm_mutex); } void bandmap_show() { - /* - * display depending on filter state - * - all bands on/off - * - all mode on/off - * - dupes on/off - * - * If more entries to show than room in window, show around - * current frequency - * - * mark entries according to age, source and worked state. Mark new multis - * - new bright blue - * - normal blue - * - aged brown - * - worked small caps - * - new multi mark with blue M between QRG and call - * - self announced stations - * small preceding letter for reporting station - * - * show own frequency as dashline in green color - * - highlight actual spot if near own frequency - * - * Allow selection of one of the spots (switches to S&P) - * - Ctrl-G as known - * - '.' and cursor plus 'Enter' \Todo - * - Test mouseclick.. \Todo - * - * '.' goes into map, shows help line above and supports - * - cursormovement - * - 'ESC' leaves mode - * - 'Enter' selects spot - * - 'B', 'D', 'M', 'O' switches filtering for band, dupes, mode - * and multiPlier on or off. - */ - - spot *data; - int curx, cury; - int bm_x, bm_y; - int i, j; - - bm_init(); - filter_spots(); - - /* afterwards display filtered list around own QRG +/- some offset - * (offset gets reset if we change frequency */ - - getyx(stdscr, cury, curx); /* remember cursor */ - - /* start in TOPLINE, column 0 */ - bm_y = TOPLINE; - bm_x = 0; - - /* clear space for bandmap */ - attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); - - move(bm_y, 0); /* do not overwrite # frequency */ - for (j = 0; j < 67; j++) - addch(' '); - - for (i = bm_y + 1; i < LASTLINE + 1; i++) { - move(i, 0); - for (j = 0; j < 80; j++) - addch(' '); - } - - /* show info text */ - bm_show_info(); - - /* split bandmap into two parts below and above current QRG. - * Give both both parts equal size. - * If there are less spots then reserved in the half - * give the remaining room to the other half. - * - * These results in maximized usage of the bandmap display while - * trying to keep the actual frequency in the center. - */ - unsigned int below_qrg = 0; - unsigned int on_qrg = 0; - unsigned int startindex, stopindex; - - const freq_t centerfrequency = bm_get_center(bandinx, trxmode); - - /* calc number of spots below your current QRG */ - for (i = 0; i < spots->len; i++) { - data = g_ptr_array_index(spots, i); - - if (data->freq <= centerfrequency - TOLERANCE) - below_qrg++; - else - break; - } + /* + * display depending on filter state + * - all bands on/off + * - all mode on/off + * - dupes on/off + * + * If more entries to show than room in window, show around + * current frequency + * + * mark entries according to age, source and worked state. Mark new multis + * - new bright blue + * - normal blue + * - aged brown + * - worked small caps + * - new multi mark with blue M between QRG and call + * - self announced stations + * small preceding letter for reporting station + * + * show own frequency as dashline in green color + * - highlight actual spot if near own frequency + * + * Allow selection of one of the spots (switches to S&P) + * - Ctrl-G as known + * - '.' and cursor plus 'Enter' \Todo + * - Test mouseclick.. \Todo + * + * '.' goes into map, shows help line above and supports + * - cursormovement + * - 'ESC' leaves mode + * - 'Enter' selects spot + * - 'B', 'D', 'M', 'O' switches filtering for band, dupes, mode + * and multiPlier on or off. + */ - /* check if current QRG is on a spot */ - if (below_qrg < spots->len) { - data = g_ptr_array_index(spots, below_qrg); + spot *data; + int curx, cury; + int bm_x, bm_y; + int i, j; - if (!(data->freq > centerfrequency + TOLERANCE)) - on_qrg = 1; - } + bm_init(); + filter_spots(); - /* calc the index into the spot array of the first spot to show */ - { - unsigned int max_below; - unsigned int above_qrg = spots->len - below_qrg - on_qrg; + /* afterwards display filtered list around own QRG +/- some offset + * (offset gets reset if we change frequency */ - if (above_qrg < ((NR_SPOTS - 1) / 2)) { - max_below = NR_SPOTS - above_qrg - 1; - } else - max_below = NR_SPOTS / 2; + getyx(stdscr, cury, curx); /* remember cursor */ - startindex = (below_qrg < max_below) ? 0 : (below_qrg - max_below); - } + /* start in TOPLINE, column 0 */ + bm_y = TOPLINE; + bm_x = 0; - /* calculate the index+1 of the last spot to show */ - stopindex = (spots->len < startindex + NR_SPOTS - (1 - on_qrg)) - ? spots->len - : (startindex + NR_SPOTS - (1 - on_qrg)); + /* clear space for bandmap */ + attrset(COLOR_PAIR(CB_DUPE) | A_BOLD); - /* correct calculations if we have no rig frequency to show */ - if (!trx_control) { - if (on_qrg) { - on_qrg = 0; - } else { - stopindex += 1; + move(bm_y, 0); /* do not overwrite # frequency */ + for (j = 0; j < 67; j++) + addch(' '); + + for (i = bm_y + 1; i < LASTLINE + 1; i++) { + move(i, 0); + for (j = 0; j < 80; j++) + addch(' '); } - if (spots->len < stopindex) - stopindex = spots->len; - } - - /* show spots below QRG */ - for (i = startindex; i < below_qrg; i++) { - move(bm_y, bm_x); - show_spot(g_ptr_array_index(spots, i)); - next_spot_position(&bm_y, &bm_x); - } - - /* show highlighted frequency marker or spot on QRG if rig control - * is active */ - if (trx_control) { - move(bm_y, bm_x); - attrset(COLOR_PAIR(C_HEADER) | A_STANDOUT); - if (!on_qrg) { - printw("%7.1f %s", centerfrequency / 1000.0, "============"); - } else { - show_spot_on_qrg(g_ptr_array_index(spots, below_qrg)); + + /* show info text */ + bm_show_info(); + + /* split bandmap into two parts below and above current QRG. + * Give both both parts equal size. + * If there are less spots then reserved in the half + * give the remaining room to the other half. + * + * These results in maximized usage of the bandmap display while + * trying to keep the actual frequency in the center. + */ + unsigned int below_qrg = 0; + unsigned int on_qrg = 0; + unsigned int startindex, stopindex; + + const freq_t centerfrequency = bm_get_center(bandinx, trxmode); + + /* calc number of spots below your current QRG */ + for (i = 0; i < spots->len; i++) { + data = g_ptr_array_index(spots, i); + + if (data->freq <= centerfrequency - TOLERANCE) + below_qrg++; + else + break; } - next_spot_position(&bm_y, &bm_x); - } - /* show spots above QRG */ - for (i = below_qrg + on_qrg; i < stopindex; i++) { - move(bm_y, bm_x); - show_spot(g_ptr_array_index(spots, i)); - next_spot_position(&bm_y, &bm_x); - } + /* check if current QRG is on a spot */ + if (below_qrg < spots->len) { + data = g_ptr_array_index(spots, below_qrg); + + if (!(data->freq > centerfrequency + TOLERANCE)) + on_qrg = 1; + } - attroff(A_BOLD); - move(cury, curx); /* reset cursor */ + /* calc the index into the spot array of the first spot to show */ + { + unsigned int max_below; + unsigned int above_qrg = spots->len - below_qrg - on_qrg; - refreshp(); + if (above_qrg < ((NR_SPOTS - 1) / 2)) { + max_below = NR_SPOTS - above_qrg - 1; + } else + max_below = NR_SPOTS / 2; + + startindex = (below_qrg < max_below) ? 0 : (below_qrg - max_below); + } + + /* calculate the index+1 of the last spot to show */ + stopindex = (spots->len < startindex + NR_SPOTS - (1 - on_qrg)) + ? spots->len + : (startindex + NR_SPOTS - (1 - on_qrg)); + + /* correct calculations if we have no rig frequency to show */ + if (!trx_control) { + if (on_qrg) { + on_qrg = 0; + } else { + stopindex += 1; + } + if (spots->len < stopindex) + stopindex = spots->len; + } + + /* show spots below QRG */ + for (i = startindex; i < below_qrg; i++) { + move(bm_y, bm_x); + show_spot(g_ptr_array_index(spots, i)); + next_spot_position(&bm_y, &bm_x); + } + + /* show highlighted frequency marker or spot on QRG if rig control + * is active */ + if (trx_control) { + move(bm_y, bm_x); + attrset(COLOR_PAIR(C_HEADER) | A_STANDOUT); + if (!on_qrg) { + printw("%7.1f %s", centerfrequency / 1000.0, "============"); + } else { + show_spot_on_qrg(g_ptr_array_index(spots, below_qrg)); + } + next_spot_position(&bm_y, &bm_x); + } + + /* show spots above QRG */ + for (i = below_qrg + on_qrg; i < stopindex; i++) { + move(bm_y, bm_x); + show_spot(g_ptr_array_index(spots, i)); + next_spot_position(&bm_y, &bm_x); + } + + attroff(A_BOLD); + move(cury, curx); /* reset cursor */ + + refreshp(); } /** allow control of bandmap features */ void bm_menu() { - int curx, cury; - char c = -1; - int j; - - getyx(stdscr, cury, curx); /* remember cursor */ - - attrset(COLOR_PAIR(C_LOG) | A_STANDOUT); - mvaddstr(13, 0, " Toggle and, ode, upes or nly multi filter"); - printw(" | any other - leave "); - - c = toupper(key_get()); - switch (c) { - case 'B': - bm_config.allband = !bm_config.allband; - break; - - case 'M': - bm_config.allmode = !bm_config.allmode; - break; - - case 'D': - bm_config.showdupes = !bm_config.showdupes; - break; - - case 'O': - bm_config.onlymults = !bm_config.onlymults; - break; - } - bandmap_show(); /* refresh display */ - - move(13, 0); - for (j = 0; j < 80; j++) - addch(' '); - - move(cury, curx); - refreshp(); + int curx, cury; + char c = -1; + int j; + + getyx(stdscr, cury, curx); /* remember cursor */ + + attrset(COLOR_PAIR(C_LOG) | A_STANDOUT); + mvaddstr(13, 0, " Toggle and, ode, upes or nly multi filter"); + printw(" | any other - leave "); + + c = toupper(key_get()); + switch (c) { + case 'B': + bm_config.allband = !bm_config.allband; + break; + + case 'M': + bm_config.allmode = !bm_config.allmode; + break; + + case 'D': + bm_config.showdupes = !bm_config.showdupes; + break; + + case 'O': + bm_config.onlymults = !bm_config.onlymults; + break; + } + bandmap_show(); /* refresh display */ + + move(13, 0); + for (j = 0; j < 80; j++) + addch(' '); + + move(cury, curx); + refreshp(); } spot *copy_spot(spot *data) { - spot *result = NULL; - - result = g_new0(spot, 1); - result -> call = g_strdup(data -> call); - result -> freq = data -> freq; - result -> mode = data -> mode; - result -> bandindex = data -> bandindex; - result -> node = data -> node; - result -> timeout = data -> timeout; - result -> dupe = data -> dupe; - result -> mult = data -> mult; - result -> cqzone = data -> cqzone; - result -> ctynr = data -> ctynr; - result -> pfx = g_strdup(data -> pfx); - - return result; + spot *result = NULL; + + result = g_new0(spot, 1); + result -> call = g_strdup(data -> call); + result -> freq = data -> freq; + result -> mode = data -> mode; + result -> bandindex = data -> bandindex; + result -> node = data -> node; + result -> timeout = data -> timeout; + result -> dupe = data -> dupe; + result -> mult = data -> mult; + result -> cqzone = data -> cqzone; + result -> ctynr = data -> ctynr; + result -> pfx = g_strdup(data -> pfx); + + return result; } /** Search partialcall in filtered bandmap @@ -978,30 +979,30 @@ spot *copy_spot(spot *data) { * after use). */ spot *bandmap_lookup(char *partialcall) { - spot *result = NULL; + spot *result = NULL; - if ((*partialcall != '\0') && (spots->len > 0)) { - int i; + if ((*partialcall != '\0') && (spots->len > 0)) { + int i; - pthread_mutex_lock(&bm_mutex); + pthread_mutex_lock(&bm_mutex); - for (i = 0; i < spots->len; i++) { - spot *data; - data = g_ptr_array_index(spots, i); + for (i = 0; i < spots->len; i++) { + spot *data; + data = g_ptr_array_index(spots, i); - if (strstr(data->call, partialcall) != NULL) { + if (strstr(data->call, partialcall) != NULL) { - /* copy data into a new Spot structure */ - result = copy_spot(data); + /* copy data into a new Spot structure */ + result = copy_spot(data); - break; - } - } + break; + } + } - pthread_mutex_unlock(&bm_mutex); + pthread_mutex_unlock(&bm_mutex); - } - return result; + } + return result; } /** Lookup next call in filtered spotlist @@ -1022,32 +1023,32 @@ spot *bandmap_lookup(char *partialcall) { spot *bandmap_next(bool upwards, freq_t freq) { - if (spots->len == 0) { - return NULL; - } + if (spots->len == 0) { + return NULL; + } - spot *result = NULL; + spot *result = NULL; - pthread_mutex_lock(&bm_mutex); + pthread_mutex_lock(&bm_mutex); - freq_t f0 = freq + (upwards ? 1 : -1) * (TOLERANCE / 2); + freq_t f0 = freq + (upwards ? 1 : -1) * (TOLERANCE / 2); - for (int i = 0; i < spots->len; i++) { - int index = (upwards ? i : spots->len - 1 - i); - spot *data = g_ptr_array_index(spots, index); - // spot must be above/below f0 depending on direction - bool freq_ok = (upwards ? data->freq > f0 : data->freq < f0); + for (int i = 0; i < spots->len; i++) { + int index = (upwards ? i : spots->len - 1 - i); + spot *data = g_ptr_array_index(spots, index); + // spot must be above/below f0 depending on direction + bool freq_ok = (upwards ? data->freq > f0 : data->freq < f0); - if (freq_ok && (!bm_config.skipdupes || !data->dupe)) { - /* copy data into a new Spot structure */ - result = copy_spot(data); - break; + if (freq_ok && (!bm_config.skipdupes || !data->dupe)) { + /* copy data into a new Spot structure */ + result = copy_spot(data); + break; + } } - } - pthread_mutex_unlock(&bm_mutex); + pthread_mutex_unlock(&bm_mutex); - return result; + return result; } /* @@ -1056,12 +1057,12 @@ spot *bandmap_next(bool upwards, freq_t freq) { * The buffer has to be at least n+1 chars long. */ void str_truncate(char *buffer, char *string, int n) { - if (strlen(string) > n) { - g_strlcpy(buffer, string, n - 1); /* truncate to n-2 chars */ - strcat(buffer, ".."); - } else { - g_strlcpy(buffer, string, n + 1); /* copy up to n chars */ - } + if (strlen(string) > n) { + g_strlcpy(buffer, string, n - 1); /* truncate to n-2 chars */ + strcat(buffer, ".."); + } else { + g_strlcpy(buffer, string, n + 1); /* copy up to n chars */ + } } /* @@ -1070,20 +1071,20 @@ void str_truncate(char *buffer, char *string, int n) { * (if any) */ char *qtc_format(char *call) { - char tcall[15]; - char qtcflag; - struct t_qtc_store_obj *qtc_temp_ptr; - - qtc_temp_ptr = qtc_get(call); - qtcflag = qtc_get_value(qtc_temp_ptr); - - if (qtc_temp_ptr->total <= 0 && qtcflag == '\0') { - str_truncate(tcall, call, SPOT_CALL_WIDTH); - } else { - str_truncate(tcall, call, SPOT_CALL_WIDTH - 2); - sprintf(tcall + strlen(tcall), " %c", qtcflag); - } - return g_strdup(tcall); + char tcall[15]; + char qtcflag; + struct t_qtc_store_obj *qtc_temp_ptr; + + qtc_temp_ptr = qtc_get(call); + qtcflag = qtc_get_value(qtc_temp_ptr); + + if (qtc_temp_ptr->total <= 0 && qtcflag == '\0') { + str_truncate(tcall, call, SPOT_CALL_WIDTH); + } else { + str_truncate(tcall, call, SPOT_CALL_WIDTH - 2); + sprintf(tcall + strlen(tcall), " %c", qtcflag); + } + return g_strdup(tcall); } /** Search filtered bandmap for a spot near the given frequency @@ -1095,25 +1096,25 @@ char *qtc_format(char *call) { */ void get_spot_on_qrg(char *dest, freq_t freq) { - *dest = '\0'; + *dest = '\0'; - if (spots->len > 0) { - int i; + if (spots->len > 0) { + int i; - pthread_mutex_lock(&bm_mutex); + pthread_mutex_lock(&bm_mutex); - for (i = 0; i < spots->len; i++) { - spot *data; - data = g_ptr_array_index(spots, i); - - if ((fabs(data->freq - freq) < TOLERANCE) && - (!bm_config.skipdupes || !data->dupe)) { - strcpy(dest, data->call); - break; - } - } + for (i = 0; i < spots->len; i++) { + spot *data; + data = g_ptr_array_index(spots, i); - pthread_mutex_unlock(&bm_mutex); + if ((fabs(data->freq - freq) < TOLERANCE) && + (!bm_config.skipdupes || !data->dupe)) { + strcpy(dest, data->call); + break; + } + } - } + pthread_mutex_unlock(&bm_mutex); + + } } diff --git a/src/cabrillo_utils.c b/src/cabrillo_utils.c index d6f26c8a..21cd34a1 100644 --- a/src/cabrillo_utils.c +++ b/src/cabrillo_utils.c @@ -40,70 +40,70 @@ /* conversion table between tag name in format file and internal tag */ static const struct tag_conv tag_tbl[] = { - { "FREQ", FREQ }, - { "MODE", MODE }, - { "DATE", DATE }, - { "TIME", TIME }, - { "MYCALL", MYCALL }, - { "HISCALL", HISCALL }, - { "RST_S", RST_S }, - { "RST_R", RST_R }, - { "EXC_S", EXC_S }, - { "EXCH", EXCH }, - { "EXC1", EXC1 }, - { "EXC2", EXC2 }, - { "EXC3", EXC3 }, - { "EXC4", EXC4 }, - { "TX", TX }, - { "QTCRCALL", QTCRCALL }, - { "QTCHEAD", QTCHEAD }, - { "QTCSCALL", QTCSCALL }, - { "QTC", QTC } + { "FREQ", FREQ }, + { "MODE", MODE }, + { "DATE", DATE }, + { "TIME", TIME }, + { "MYCALL", MYCALL }, + { "HISCALL", HISCALL }, + { "RST_S", RST_S }, + { "RST_R", RST_R }, + { "EXC_S", EXC_S }, + { "EXCH", EXCH }, + { "EXC1", EXC1 }, + { "EXC2", EXC2 }, + { "EXC3", EXC3 }, + { "EXC4", EXC4 }, + { "TX", TX }, + { "QTCRCALL", QTCRCALL }, + { "QTCHEAD", QTCHEAD }, + { "QTCSCALL", QTCSCALL }, + { "QTC", QTC } }; /* translate item name into a tag */ enum tag_t translate_item_name(char *name) { - int i; - - /* lookup name in tag list */ - for (i = 0; i < G_N_ELEMENTS(tag_tbl); i++) { - if (strcmp(tag_tbl[i].item_name, name) == 0) { - /* and return corresponding tab */ - return tag_tbl[i].tag; + int i; + + /* lookup name in tag list */ + for (i = 0; i < G_N_ELEMENTS(tag_tbl); i++) { + if (strcmp(tag_tbl[i].item_name, name) == 0) { + /* and return corresponding tab */ + return tag_tbl[i].tag; + } } - } - /* if not found return NO_ITEM tag */ - return NO_ITEM; + /* if not found return NO_ITEM tag */ + return NO_ITEM; } /** free cabrillo format description */ void free_cabfmt(struct cabrillo_desc *desc) { - int i; + int i; + + if (desc == NULL) + return; - if (desc == NULL) - return; + if (desc->item_array) { + for (i = 0; i < desc->item_array->len; i++) { + g_free(g_ptr_array_index(desc->item_array, i)); + } - if (desc->item_array) { - for (i = 0; i < desc->item_array->len; i++) { - g_free(g_ptr_array_index(desc->item_array, i)); + g_ptr_array_free(desc->item_array, TRUE); } - g_ptr_array_free(desc->item_array, TRUE); - } + if (desc->qtc_item_array) { + for (i = 0; i < desc->qtc_item_array->len; i++) { + g_free(g_ptr_array_index(desc->qtc_item_array, i)); + } - if (desc->qtc_item_array) { - for (i = 0; i < desc->qtc_item_array->len; i++) { - g_free(g_ptr_array_index(desc->qtc_item_array, i)); + g_ptr_array_free(desc->qtc_item_array, TRUE); } - g_ptr_array_free(desc->qtc_item_array, TRUE); - } - - FREE_DYNAMIC_STRING(desc->name); - FREE_DYNAMIC_STRING(desc->exchange_separator); - g_free(desc); + FREE_DYNAMIC_STRING(desc->name); + FREE_DYNAMIC_STRING(desc->exchange_separator); + g_free(desc); } @@ -114,26 +114,26 @@ void free_cabfmt(struct cabrillo_desc *desc) { * - max length */ struct line_item *parse_line_entry(char *line_entry) { - struct line_item *item; - gchar **parts; - enum tag_t tag; + struct line_item *item; + gchar **parts; + enum tag_t tag; - item = g_malloc(sizeof(struct line_item)); - parts = g_strsplit(line_entry, ",", 2); + item = g_malloc(sizeof(struct line_item)); + parts = g_strsplit(line_entry, ",", 2); - if (g_strv_length(parts) == 2) { - tag = translate_item_name(parts[0]); + if (g_strv_length(parts) == 2) { + tag = translate_item_name(parts[0]); - item->tag = tag; - item->len = atoi(parts[1]); - } else { - /* type is NO_ITEM */ - item->tag = NO_ITEM; - } + item->tag = tag; + item->len = atoi(parts[1]); + } else { + /* type is NO_ITEM */ + item->tag = NO_ITEM; + } - g_strfreev(parts); + g_strfreev(parts); - return item; + return item; } /** read cabrillo format description @@ -147,488 +147,489 @@ struct line_item *parse_line_entry(char *line_entry) { * (NULL if file or format not found or not readable) */ struct cabrillo_desc *read_cabrillo_format(char *filename, char *format) { - GKeyFile *keyfile; - GError *error = NULL; - gchar **list; - gsize nrstrings; - struct cabrillo_desc *cabdesc; - int i; - - keyfile = g_key_file_new(); + GKeyFile *keyfile; + GError *error = NULL; + gchar **list; + gsize nrstrings; + struct cabrillo_desc *cabdesc; + int i; + + keyfile = g_key_file_new(); + + if (!g_key_file_load_from_file(keyfile, filename, + G_KEY_FILE_NONE, &error)) { + g_error_free(error); + + /* file does not exist or is wrongly formatted */ + g_key_file_free(keyfile); + return NULL; + } - if (!g_key_file_load_from_file(keyfile, filename, - G_KEY_FILE_NONE, &error)) { - g_error_free(error); + /* check if 'format' defined in file */ + if (g_key_file_has_group(keyfile, format) == FALSE) { - /* file does not exist or is wrongly formatted */ - g_key_file_free(keyfile); - return NULL; - } + /* group not found */ + g_key_file_free(keyfile); + return NULL; + } - /* check if 'format' defined in file */ - if (g_key_file_has_group(keyfile, format) == FALSE) { + /* read needed keys */ + list = g_key_file_get_string_list(keyfile, format, + "QSO", &nrstrings, &error); - /* group not found */ - g_key_file_free(keyfile); - return NULL; - } + if (error && error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND) { - /* read needed keys */ - list = g_key_file_get_string_list(keyfile, format, - "QSO", &nrstrings, &error); - - if (error && error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND) { + /* if not found -> stop processing as that key is mandatory */ + g_error_free(error); + g_key_file_free(keyfile); + return NULL; + } - /* if not found -> stop processing as that key is mandatory */ - g_error_free(error); - g_key_file_free(keyfile); - return NULL; - } + /* construct new format descriptor and fill it in */ + cabdesc = g_new0(struct cabrillo_desc, 1); + cabdesc->name = g_strdup(format); + cabdesc->item_array = g_ptr_array_new(); + cabdesc->item_count = nrstrings; + cabdesc->qtc_item_array = NULL; + cabdesc->qtc_item_count = 0; - /* construct new format descriptor and fill it in */ - cabdesc = g_new0(struct cabrillo_desc, 1); - cabdesc->name = g_strdup(format); - cabdesc->item_array = g_ptr_array_new(); - cabdesc->item_count = nrstrings; - cabdesc->qtc_item_array = NULL; - cabdesc->qtc_item_count = 0; + for (i = 0; i < nrstrings; i++) { + struct line_item *item; - for (i = 0; i < nrstrings; i++) { - struct line_item *item; + item = parse_line_entry(list[i]); + if (item) { + /* add only well formatted entries */ + g_ptr_array_add(cabdesc->item_array, item); + } + } - item = parse_line_entry(list[i]); - if (item) { - /* add only well formatted entries */ - g_ptr_array_add(cabdesc->item_array, item); + if (cabdesc->item_array->len != nrstrings) { + /* not all entries are ok -> stop processing */ + free_cabfmt(cabdesc); + g_strfreev(list); + g_key_file_free(keyfile); + return NULL; } - } - if (cabdesc->item_array->len != nrstrings) { - /* not all entries are ok -> stop processing */ - free_cabfmt(cabdesc); g_strfreev(list); - g_key_file_free(keyfile); - return NULL; - } - g_strfreev(list); + /* read needed QTC keys */ + list = g_key_file_get_string_list(keyfile, format, + "QTC", &nrstrings, &error); - /* read needed QTC keys */ - list = g_key_file_get_string_list(keyfile, format, - "QTC", &nrstrings, &error); + if (error && error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND) { - if (error && error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND) { + /* if not found -> stop processing as that key is optional */ + g_error_free(error); + error = NULL; - /* if not found -> stop processing as that key is optional */ - g_error_free(error); - error = NULL; + } else { - } else { + /* construct new format descriptor and fill it in */ + cabdesc->qtc_item_array = g_ptr_array_new(); + cabdesc->qtc_item_count = nrstrings; - /* construct new format descriptor and fill it in */ - cabdesc->qtc_item_array = g_ptr_array_new(); - cabdesc->qtc_item_count = nrstrings; - - for (i = 0; i < nrstrings; i++) { - struct line_item *item; + for (i = 0; i < nrstrings; i++) { + struct line_item *item; - item = parse_line_entry(list[i]); - if (item) { - /* add only well formatted entries */ - g_ptr_array_add(cabdesc->qtc_item_array, item); - } - } + item = parse_line_entry(list[i]); + if (item) { + /* add only well formatted entries */ + g_ptr_array_add(cabdesc->qtc_item_array, item); + } + } - if (cabdesc->qtc_item_array->len != nrstrings) { - /* not all entries are ok -> stop processing */ - free_cabfmt(cabdesc); - g_strfreev(list); - g_key_file_free(keyfile); - return NULL; + if (cabdesc->qtc_item_array->len != nrstrings) { + /* not all entries are ok -> stop processing */ + free_cabfmt(cabdesc); + g_strfreev(list); + g_key_file_free(keyfile); + return NULL; + } } - } - g_strfreev(list); + g_strfreev(list); - cabdesc->exchange_separator = g_key_file_get_string(keyfile, format, - "EXCHANGE-SEPARATOR", &error); - if (error) { - g_error_free(error); // clear error - error = NULL; - } + cabdesc->exchange_separator = g_key_file_get_string(keyfile, format, + "EXCHANGE-SEPARATOR", &error); + if (error) { + g_error_free(error); // clear error + error = NULL; + } - /* possible further entries in format specification may contain information - * about allowed items for different categories: - * CONTEST, CATEGORY-OPERATOR, CATEGORY_TRANSMITTER, CATEGORY-POWER, - * CATEGORY-ASSISTED, CATEGORY-BAND, CATEGORY-MODE, C-STATION, C-TIME. - * C-OVERLAY - */ + /* possible further entries in format specification may contain information + * about allowed items for different categories: + * CONTEST, CATEGORY-OPERATOR, CATEGORY_TRANSMITTER, CATEGORY-POWER, + * CATEGORY-ASSISTED, CATEGORY-BAND, CATEGORY-MODE, C-STATION, C-TIME. + * C-OVERLAY + */ - g_key_file_free(keyfile); + g_key_file_free(keyfile); - /* return parsed cabrillo format description */ - return cabdesc; + /* return parsed cabrillo format description */ + return cabdesc; } cbr_field_t cabrillo_fields[] = { - // internals - { - .name = CBR_EXCHANGE, .text = "Your exchange", - .hint = "(e.g. State, province, age etc... (# if serial number))", - .internal = true - }, - { - .name = CBR_QSO_FORMAT, - .internal = true - }, - { - .name = CBR_TEMPLATE, - .internal = true - }, - // - { - .name = "CONTEST", .text = "Contest", - .hint = "(CQ-WW-CW/SSB, CQ-WPX-CW/SSB, ARRL-DX-CW/SSB)", - }, - { - .name = CBR_CALLSIGN, // filled internally - }, - { - .name = "CATEGORY-ASSISTED", .text = "Category-Assisted", - .hint = "(ASSISTED, NON-ASSISTED)", - }, - { - .name = "CATEGORY-BAND", .text = "Bands", - .hint = "(ALL,160M,80M,40M,20M,15M,10M)", - }, - { - .name = "CATEGORY-MODE", .text = "Mode", - .hint = "(CW,SSB,RTTY,MIXED)", - }, - { - .name = "CATEGORY-OPERATOR", .text = "Category-Operator", - .hint = "(SINGLE-OP, MULTI-OP, CHECKLOG)", - }, - { - .name = "CATEGORY-POWER", .text = "Power", - .hint = "(HIGH,LOW,QRP)", - }, - { - .name = "CATEGORY-STATION", .text = "Category-Station", - .hint = "(FIXED, MOBILE, PORTABLE, ROVER, EXPEDITION, HQ, SCHOOL)", - .skip_empty = true - }, - { - .name = "CATEGORY-TIME", .text = "Category-Time", - .hint = "(6-HOURS, 12-HOURS, 24-HOURS)", - .skip_empty = true - }, - { - .name = "CATEGORY-TRANSMITTER", .text = "Transmitter", - .hint = "(ONE, TWO, LIMITED, UNLIMITED, SWL)", - .skip_empty = true - }, - { - .name = "CATEGORY-OVERLAY", .text = "Category-Overlay", - .hint = "(ROOKIE, TB-WIRES, NOVICE-TECH, OVER-50)", - .skip_empty = true - }, - { - .name = "CERTIFICATE", .text = "Certificate", - .hint = "(YES [default], NO)", - .disabled = true - }, - { - .name = CBR_SCORE, // filled internally - }, - { - .name = "CLUB", .text = "Club", - .skip_empty = true - }, - { - .name = "LOCATION", .text = "Location", - .hint = "(section, IOTA name, RDA, State/Province, ...)", - .skip_empty = true - }, - { - .name = "GRID-LOCATOR", .text = "Locator:", - .disabled = true - }, - { - .name = "NAME", .text = "Operator name", - }, - { - .name = "EMAIL", .text = "E-mail", - .disabled = true - }, - { - .name = "ADDRESS", .text = "Address", - }, - { - .name = "ADDRESS(2)", .text = "Address(2)", - .disabled = true - }, - { - .name = "ADDRESS(3)", .text = "Address(3)", - .disabled = true - }, - { - .name = "ADDRESS-CITY", .text = "Address-City", - .disabled = true - }, - { - .name = "ADDRESS-STATE-PROVINCE", .text = "Address-State/Province", - .disabled = true - }, - { - .name = "ADDRESS-POSTALCODE", .text = "Address-PostalCode", - .disabled = true - }, - { - .name = "ADDRESS-COUNTRY", .text = "Address-Country", - .disabled = true - }, - { - .name = "OPERATORS", .text = "List of Operators", - .hint = "(space delimited)", - }, - { - .name = "OFFTIME", .text = "Offtime", - .hint = "(yyyy-mm-dd hhmm yyyy-mm-dd hhmm)", - .skip_empty = true - }, - { - .name = "SOAPBOX", .text = "Soapbox", - .hint = "(use any text editor to include more lines)", - .skip_empty = true - }, - { - .name = "SOAPBOX(2)", .text = "Soapbox(2)", - .disabled = true - }, - { - .name = "SOAPBOX(3)", .text = "Soapbox(3)", - .disabled = true - }, + // internals + { + .name = CBR_EXCHANGE, .text = "Your exchange", + .hint = "(e.g. State, province, age etc... (# if serial number))", + .internal = true + }, + { + .name = CBR_QSO_FORMAT, + .internal = true + }, + { + .name = CBR_TEMPLATE, + .internal = true + }, + // + { + .name = "CONTEST", .text = "Contest", + .hint = "(CQ-WW-CW/SSB, CQ-WPX-CW/SSB, ARRL-DX-CW/SSB)", + }, + { + .name = CBR_CALLSIGN, // filled internally + }, + { + .name = "CATEGORY-ASSISTED", .text = "Category-Assisted", + .hint = "(ASSISTED, NON-ASSISTED)", + }, + { + .name = "CATEGORY-BAND", .text = "Bands", + .hint = "(ALL,160M,80M,40M,20M,15M,10M)", + }, + { + .name = "CATEGORY-MODE", .text = "Mode", + .hint = "(CW,SSB,RTTY,MIXED)", + }, + { + .name = "CATEGORY-OPERATOR", .text = "Category-Operator", + .hint = "(SINGLE-OP, MULTI-OP, CHECKLOG)", + }, + { + .name = "CATEGORY-POWER", .text = "Power", + .hint = "(HIGH,LOW,QRP)", + }, + { + .name = "CATEGORY-STATION", .text = "Category-Station", + .hint = "(FIXED, MOBILE, PORTABLE, ROVER, EXPEDITION, HQ, SCHOOL)", + .skip_empty = true + }, + { + .name = "CATEGORY-TIME", .text = "Category-Time", + .hint = "(6-HOURS, 12-HOURS, 24-HOURS)", + .skip_empty = true + }, + { + .name = "CATEGORY-TRANSMITTER", .text = "Transmitter", + .hint = "(ONE, TWO, LIMITED, UNLIMITED, SWL)", + .skip_empty = true + }, + { + .name = "CATEGORY-OVERLAY", .text = "Category-Overlay", + .hint = "(ROOKIE, TB-WIRES, NOVICE-TECH, OVER-50)", + .skip_empty = true + }, + { + .name = "CERTIFICATE", .text = "Certificate", + .hint = "(YES [default], NO)", + .disabled = true + }, + { + .name = CBR_SCORE, // filled internally + }, + { + .name = "CLUB", .text = "Club", + .skip_empty = true + }, + { + .name = "LOCATION", .text = "Location", + .hint = "(section, IOTA name, RDA, State/Province, ...)", + .skip_empty = true + }, + { + .name = "GRID-LOCATOR", .text = "Locator:", + .disabled = true + }, + { + .name = "NAME", .text = "Operator name", + }, + { + .name = "EMAIL", .text = "E-mail", + .disabled = true + }, + { + .name = "ADDRESS", .text = "Address", + }, + { + .name = "ADDRESS(2)", .text = "Address(2)", + .disabled = true + }, + { + .name = "ADDRESS(3)", .text = "Address(3)", + .disabled = true + }, + { + .name = "ADDRESS-CITY", .text = "Address-City", + .disabled = true + }, + { + .name = "ADDRESS-STATE-PROVINCE", .text = "Address-State/Province", + .disabled = true + }, + { + .name = "ADDRESS-POSTALCODE", .text = "Address-PostalCode", + .disabled = true + }, + { + .name = "ADDRESS-COUNTRY", .text = "Address-Country", + .disabled = true + }, + { + .name = "OPERATORS", .text = "List of Operators", + .hint = "(space delimited)", + }, + { + .name = "OFFTIME", .text = "Offtime", + .hint = "(yyyy-mm-dd hhmm yyyy-mm-dd hhmm)", + .skip_empty = true + }, + { + .name = "SOAPBOX", .text = "Soapbox", + .hint = "(use any text editor to include more lines)", + .skip_empty = true + }, + { + .name = "SOAPBOX(2)", .text = "Soapbox(2)", + .disabled = true + }, + { + .name = "SOAPBOX(3)", .text = "Soapbox(3)", + .disabled = true + }, }; cbr_field_t *find_cabrillo_field(const char *name) { - for (int i = 0; i < G_N_ELEMENTS(cabrillo_fields); ++i) { - if (strcmp(cabrillo_fields[i].name, name) == 0) { - return &cabrillo_fields[i]; + for (int i = 0; i < G_N_ELEMENTS(cabrillo_fields); ++i) { + if (strcmp(cabrillo_fields[i].name, name) == 0) { + return &cabrillo_fields[i]; + } } - } - return NULL; + return NULL; } int get_cabrillo_field_value(const cbr_field_t *field, char *buffer, int size) { - if (field == NULL || field->disabled) { - return -1; // no such field or disabled - } - if (field->value != NULL && !field->value_is_hint) { - g_strlcpy(buffer, field->value, size); // use specified value + if (field == NULL || field->disabled) { + return -1; // no such field or disabled + } + if (field->value != NULL && !field->value_is_hint) { + g_strlcpy(buffer, field->value, size); // use specified value + return 0; + } + + if (field->text == NULL) { + return -1; // missing value, no text, don't ask + } + + // ask if no value was provided + const char *hint; + if (field->value != NULL) { + hint = field->value; + } else if (field->hint != NULL) { + hint = field->hint; + } else { + hint = ""; + } + + char *prompt = g_strdup_printf("%s: %s", field->text, hint); + if (strlen(prompt) > 76) { + prompt[76] = 0; + prompt[75] = '.'; + prompt[74] = '.'; + prompt[73] = '.'; + } + + char input[80]; + ask(input, prompt); + g_free(prompt); + + g_strstrip(input); + g_strlcpy(buffer, input, size); + + if (strlen(buffer) == 0 && field->skip_empty) { + return -1; // skip empty value + } + return 0; - } - - if (field->text == NULL) { - return -1; // missing value, no text, don't ask - } - - // ask if no value was provided - const char *hint; - if (field->value != NULL) { - hint = field->value; - } else if (field->hint != NULL) { - hint = field->hint; - } else { - hint = ""; - } - - char *prompt = g_strdup_printf("%s: %s", field->text, hint); - if (strlen(prompt) > 76) { - prompt[76] = 0; - prompt[75] = '.'; - prompt[74] = '.'; - prompt[73] = '.'; - } - - char input[80]; - ask(input, prompt); - g_free(prompt); - - g_strstrip(input); - g_strlcpy(buffer, input, size); - - if (strlen(buffer) == 0 && field->skip_empty) { - return -1; // skip empty value - } - - return 0; } void write_cabrillo_header(FILE *fp) { - char buffer[80]; - - // set CALLSIGN - cbr_field_t *call = find_cabrillo_field(CBR_CALLSIGN); - FREE_DYNAMIC_STRING(call->value); - call->value = g_strdup(my.call); - call->disabled = false; // always enabled - - // set CLAIMED-SCORE unless disabled - cbr_field_t *score = find_cabrillo_field(CBR_SCORE); - if (!score->disabled) { - FREE_DYNAMIC_STRING(score->value); - score->value = g_strdup_printf("%d", get_total_score()); - } - - // set GRID-LOCATOR if enabled and my.qra is not empty - cbr_field_t *locator = find_cabrillo_field(CBR_LOCATOR); - if (!locator->disabled && locator->value == NULL && my.qra[0] != 0) { - locator->value = g_strdup(my.qra); - } - - fprintf(fp, "START-OF-LOG: 3.0\n"); - fprintf(fp, "CREATED-BY: %s\n", argp_program_version); - format_time(buffer, sizeof(buffer), CREATED_DATE_TIME_FORMAT); - fprintf(fp, "X-CREATED-ON: %s\n", buffer); - - for (int i = 0; i < G_N_ELEMENTS(cabrillo_fields); ++i) { - if (cabrillo_fields[i].internal) { - continue; // internal use only + char buffer[80]; + + // set CALLSIGN + cbr_field_t *call = find_cabrillo_field(CBR_CALLSIGN); + FREE_DYNAMIC_STRING(call->value); + call->value = g_strdup(my.call); + call->disabled = false; // always enabled + + // set CLAIMED-SCORE unless disabled + cbr_field_t *score = find_cabrillo_field(CBR_SCORE); + if (!score->disabled) { + FREE_DYNAMIC_STRING(score->value); + score->value = g_strdup_printf("%d", get_total_score()); } - if (get_cabrillo_field_value(&cabrillo_fields[i], buffer, 80) != 0) { - continue; // has no value + // set GRID-LOCATOR if enabled and my.qra is not empty + cbr_field_t *locator = find_cabrillo_field(CBR_LOCATOR); + if (!locator->disabled && locator->value == NULL && my.qra[0] != 0) { + locator->value = g_strdup(my.qra); } - // cut index from name, e.g. ADDRESS(2) - char tag[40]; - strcpy(tag, cabrillo_fields[i].name); - char *p = strchr(tag, '('); - if (p != NULL) { - *p = 0; + fprintf(fp, "START-OF-LOG: 3.0\n"); + fprintf(fp, "CREATED-BY: %s\n", argp_program_version); + format_time(buffer, sizeof(buffer), CREATED_DATE_TIME_FORMAT); + fprintf(fp, "X-CREATED-ON: %s\n", buffer); + + for (int i = 0; i < G_N_ELEMENTS(cabrillo_fields); ++i) { + if (cabrillo_fields[i].internal) { + continue; // internal use only + } + + if (get_cabrillo_field_value(&cabrillo_fields[i], buffer, 80) != 0) { + continue; // has no value + } + + // cut index from name, e.g. ADDRESS(2) + char tag[40]; + strcpy(tag, cabrillo_fields[i].name); + char *p = strchr(tag, '('); + if (p != NULL) { + *p = 0; + } + fprintf(fp, "%s: %s\n", tag, buffer); } - fprintf(fp, "%s: %s\n", tag, buffer); - } } static int process_cabrillo_template_file(const char *file_name); // called from parse_logcfg.c and process_cabrillo_template_file() int add_cabrillo_field(const char *name, const char *value) { - cbr_field_t *field = find_cabrillo_field(name); - if (field == NULL) { - return PARSE_NO_MATCH; - } - - // special cases: - // 1) QSO-FORMAT: set cabrillo variable - if (strcmp(name, CBR_QSO_FORMAT) == 0) { - FREE_DYNAMIC_STRING(cabrillo); - cabrillo = g_strdup(value); + cbr_field_t *field = find_cabrillo_field(name); + if (field == NULL) { + return PARSE_NO_MATCH; + } + + // special cases: + // 1) QSO-FORMAT: set cabrillo variable + if (strcmp(name, CBR_QSO_FORMAT) == 0) { + FREE_DYNAMIC_STRING(cabrillo); + cabrillo = g_strdup(value); + return PARSE_OK; + } + // 2) TEMPLATE: read fields from Cabrillo file + if (strcmp(name, CBR_TEMPLATE) == 0) { + return process_cabrillo_template_file(value); + } + + field->disabled = false; + FREE_DYNAMIC_STRING(field->value); + + if (value == NULL) { + return PARSE_OK; // missing value just enables field + } + + int len = strlen(value); + field->value_is_hint = (len > 1 && value[0] == '(' && value[len - 1] == ')'); + field->disabled = (len == 1 && value[0] == '-'); + if (!field->disabled) { + field->value = g_strdup(value); + } + return PARSE_OK; - } - // 2) TEMPLATE: read fields from Cabrillo file - if (strcmp(name, CBR_TEMPLATE) == 0) { - return process_cabrillo_template_file(value); - } - - field->disabled = false; - FREE_DYNAMIC_STRING(field->value); - - if (value == NULL) { - return PARSE_OK; // missing value just enables field - } - - int len = strlen(value); - field->value_is_hint = (len > 1 && value[0] == '(' && value[len - 1] == ')'); - field->disabled = (len == 1 && value[0] == '-'); - if (!field->disabled) { - field->value = g_strdup(value); - } - - return PARSE_OK; } static bool skip_template_line(const char *line) { - static const char *skips[] = { - "^$", "^#", "^X-", // empty line or comment - "^(START|END)-OF-LOG:", - "^CREATED-BY:", - "^CALLSIGN:", - "^QSO:", - "^" CBR_TEMPLATE ":" // no recursion - }; - - for (int i = 0; i < G_N_ELEMENTS(skips); ++i) { - if (g_regex_match_simple(skips[i], line, 0, 0)) { - return true; + static const char *skips[] = { + "^$", "^#", "^X-", // empty line or comment + "^(START|END)-OF-LOG:", + "^CREATED-BY:", + "^CALLSIGN:", + "^QSO:", + "^" CBR_TEMPLATE ":" // no recursion + }; + + for (int i = 0; i < G_N_ELEMENTS(skips); ++i) { + if (g_regex_match_simple(skips[i], line, 0, 0)) { + return true; + } } - } - return false; + return false; } static int process_cabrillo_template_file(const char *file_name) { - FILE *fp = fopen(file_name, "r"); - if (fp == NULL) { - error_details = g_strdup_printf("can't open '%s'", file_name); - return PARSE_WRONG_PARAMETER; - } - - char* logline = NULL; - size_t read_len = 0; - int read; - - int result = PARSE_OK; - - while ((read = getline(&logline, &read_len, fp)) != 1) { - if (read_len > 0) { - g_strstrip(logline); - if (skip_template_line(logline)) { - continue; // skip it - } - char **fields = g_strsplit(logline, ":", 2); - g_strstrip(fields[0]); - if (g_strv_length(fields) == 2) { - g_strstrip(fields[1]); - } - - int rc = add_cabrillo_field(fields[0], fields[1]); - - if (rc != PARSE_OK) { - error_details = g_strdup_printf("unknown tag '%s'", fields[0]); - result = PARSE_ERROR; - } - - g_strfreev(fields); - - if (result != PARSE_OK) { - break; - } - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } - - if (logline != NULL) - free(logline); - fclose(fp); - - return result; + FILE *fp = fopen(file_name, "r"); + if (fp == NULL) { + error_details = g_strdup_printf("can't open '%s'", file_name); + return PARSE_WRONG_PARAMETER; + } + + char *logline = NULL; + size_t read_len = 0; + int read; + + int result = PARSE_OK; + + while ((read = getline(&logline, &read_len, fp)) != 1) { + if (read_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + g_strstrip(logline); + if (skip_template_line(logline)) { + continue; // skip it + } + char **fields = g_strsplit(logline, ":", 2); + g_strstrip(fields[0]); + if (g_strv_length(fields) == 2) { + g_strstrip(fields[1]); + } + + int rc = add_cabrillo_field(fields[0], fields[1]); + + if (rc != PARSE_OK) { + error_details = g_strdup_printf("unknown tag '%s'", fields[0]); + result = PARSE_ERROR; + } + + g_strfreev(fields); + + if (result != PARSE_OK) { + break; + } + } + } + + if (logline != NULL) + free(logline); + fclose(fp); + + return result; } void get_cabrillo_file_name(char *buffer) { - strcpy(buffer, my.call); - for (char *p = buffer; *p; p++) { - if (*p == '/') { // convert '/' to '_' - *p = '_'; + strcpy(buffer, my.call); + for (char *p = buffer; *p; p++) { + if (*p == '/') { // convert '/' to '_' + *p = '_'; + } } - } - strcat(buffer, ".cbr"); + strcat(buffer, ".cbr"); } diff --git a/src/checklogfile.c b/src/checklogfile.c index 6203f84c..59485c62 100644 --- a/src/checklogfile.c +++ b/src/checklogfile.c @@ -52,44 +52,49 @@ * \return 0 on success */ int repair_log(char *filename) { - gchar *backupfile; - gchar *cmd; - char* buffer = NULL; + gchar *backupfile; + gchar *cmd; + char *buffer = NULL; size_t buffer_len = 200; - gchar *fill; - int rc; + gchar *fill; + int rc; int read; - FILE *infp; - FILE *outfp; + FILE *infp; + FILE *outfp; - /* make a backup of the original file */ - backupfile = g_strconcat(filename, ".bak", NULL); - showstring("Backing up original file as: ", backupfile); + /* make a backup of the original file */ + backupfile = g_strconcat(filename, ".bak", NULL); + showstring("Backing up original file as: ", backupfile); - cmd = g_strconcat("cp ", filename, " ", backupfile, NULL); - rc = system(cmd); - g_free(cmd); + cmd = g_strconcat("cp ", filename, " ", backupfile, NULL); + rc = system(cmd); + g_free(cmd); - if (rc != 0) { + if (rc != 0) { showmsg("Could not backup logfile. Giving up!"); return 1; - } + } - showmsg("Converting file to new format"); - if ((infp = fopen(backupfile, "r")) == NULL) { + showmsg("Converting file to new format"); + if ((infp = fopen(backupfile, "r")) == NULL) { showmsg("Could not convert logfile. Sorry!"); return 1; - } + } - if ((outfp = fopen(filename, "w")) == NULL) { + if ((outfp = fopen(filename, "w")) == NULL) { fclose(infp); showmsg("Could not convert logfile. Sorry!"); return 1; - } + } - while((read = getline(&buffer, &buffer_len, infp)) != 1) { + while ((read = getline(&buffer, &buffer_len, infp)) != 1) { if (buffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } /* strip trailing whitespace (and newline) */ g_strchomp(buffer); @@ -101,34 +106,30 @@ int repair_log(char *filename) { fputs(buffer, outfp); fputs("\n", outfp); } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } + } if (buffer != NULL) free(buffer); - fclose(outfp); - fclose(infp); - g_free(backupfile); + fclose(outfp); + fclose(infp); + g_free(backupfile); - showmsg("Done"); - sleep(2); + showmsg("Done"); + sleep(2); - return 0; + return 0; } int checklogfile_new(char *filename) { - int lineno; - int tooshort; + int lineno; + int tooshort; int read; - char* buffer = NULL; + char *buffer = NULL; size_t buffer_len = 160; - FILE *fp; + FILE *fp; - /* check if logfile exist and can be opened for read */ - if ((fp = fopen(filename, "r")) == NULL) { + /* check if logfile exist and can be opened for read */ + if ((fp = fopen(filename, "r")) == NULL) { if (errno == EACCES) { showstring("Can not access log file: ", filename); @@ -151,15 +152,20 @@ int checklogfile_new(char *filename) { showstring("Can not check log file: ", filename); return 1; - } + } - /* check each line of the logfile of correct format */ - lineno = 0; - tooshort = 0; + /* check each line of the logfile of correct format */ + lineno = 0; + tooshort = 0; - while((read = getline(&buffer, &buffer_len, fp)) != -1) { + while ((read = getline(&buffer, &buffer_len, fp)) != -1) { if (buffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } int band, linelen; int bandok = 0; @@ -169,15 +175,15 @@ int checklogfile_new(char *filename) { band = atoi(buffer); if ((band == 160) || - (band == 80) || - (band == 60) || - (band == 40) || - (band == 30) || - (band == 20) || - (band == 17) || - (band == 15) || - (band == 12) || - (band == 10)) + (band == 80) || + (band == 60) || + (band == 40) || + (band == 30) || + (band == 20) || + (band == 17) || + (band == 15) || + (band == 12) || + (band == 10)) bandok = 1; if (!((buffer[0] == ';') || bandok)) { @@ -202,17 +208,13 @@ int checklogfile_new(char *filename) { tooshort = 1; } } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } + } if (buffer != NULL) free(buffer); - fclose(fp); + fclose(fp); - if (tooshort) { + if (tooshort) { char c; /* some lines in logfile are too short, maybe old logfile format */ @@ -228,28 +230,28 @@ int checklogfile_new(char *filename) { /* trying to repair */ return repair_log(filename); - } + } - return 0; + return 0; } void checklogfile(void) { - extern char logfile[]; + extern char logfile[]; - int qsobytes; + int qsobytes; int read; - struct stat statbuf; - char* inputbuffer = NULL; + struct stat statbuf; + char *inputbuffer = NULL; size_t read_len = 160; - FILE *infile; - FILE *outfile; - FILE *fp; + FILE *infile; + FILE *outfile; + FILE *fp; - if ((fp = fopen(logfile, "a")) == NULL) { + if ((fp = fopen(logfile, "a")) == NULL) { TLF_LOG_WARN("I can not find the logfile ..."); - } else { + } else { fstat(fileno(fp), &statbuf); fclose(fp); @@ -258,43 +260,44 @@ void checklogfile(void) { if ((qsobytes % LOGLINELEN) != 0) { if ((infile = fopen(logfile, "r")) == NULL) { - TLF_LOG_WARN("Unable to open logfile..."); - - } else { - if ((outfile = fopen("./cpyfile", "w")) == NULL) { - fclose(infile); - TLF_LOG_WARN("Unable to open cpyfile..."); + TLF_LOG_WARN("Unable to open logfile..."); } else { - while ((read = getline(&inputbuffer, &read_len, infile)) != -1) { - if (read_len > 0) { - if (strlen(inputbuffer) != LOGLINELEN) { - /* append spaces */ - for (int i = strlen(inputbuffer); - i < LOGLINELEN; i++) { - - strcat(inputbuffer, " "); + if ((outfile = fopen("./cpyfile", "w")) == NULL) { + fclose(infile); + TLF_LOG_WARN("Unable to open cpyfile..."); + + } else { + while ((read = getline(&inputbuffer, &read_len, infile)) != -1) { + if (read_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); } + if (strlen(inputbuffer) != LOGLINELEN) { + /* append spaces */ + for (int i = strlen(inputbuffer); + i < LOGLINELEN; i++) { - inputbuffer[LOGLINELEN - 1] = '\n'; - inputbuffer[LOGLINELEN] = '\0'; + strcat(inputbuffer, " "); + } + + inputbuffer[LOGLINELEN - 1] = '\n'; + inputbuffer[LOGLINELEN] = '\0'; + } + fputs(inputbuffer, outfile); } - fputs(inputbuffer, outfile); - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); } - } - if (inputbuffer != NULL) - free(inputbuffer); - fclose(infile); - fclose(outfile); - } - rename("./cpyfile", logfile); - remove("./cpyfile"); + if (inputbuffer != NULL) + free(inputbuffer); + fclose(infile); + fclose(outfile); + } + rename("./cpyfile", logfile); + remove("./cpyfile"); } } - } + } } diff --git a/src/dxcc.c b/src/dxcc.c index f23b89be..c6e13185 100644 --- a/src/dxcc.c +++ b/src/dxcc.c @@ -37,78 +37,78 @@ bool have_exact_matches; char cty_dat_version[12]; // VERyyyymmdd enum { - TCPI_NONE = -1, - TCPI_AMB = -2, + TCPI_NONE = -1, + TCPI_AMB = -2, }; prefix_data dummy_pfx = { - "No Prefix", - 0, - 0, - 0, - INFINITY, - INFINITY, - "", - INFINITY, - false + "No Prefix", + 0, + 0, + 0, + INFINITY, + INFINITY, + "", + INFINITY, + false }; static void prefix_free(gpointer data) { - prefix_data *pfx_data = data; + prefix_data *pfx_data = data; - g_free(pfx_data -> pfx); - g_free(pfx_data -> continent); - g_free(pfx_data); + g_free(pfx_data -> pfx); + g_free(pfx_data -> continent); + g_free(pfx_data); } void prefix_init(void) { - if (hashed_prefix) { - g_hash_table_destroy(hashed_prefix); - } - hashed_prefix = g_hash_table_new(g_str_hash, g_str_equal); - - if (prefix) { - g_ptr_array_free(prefix, TRUE); - } - prefix = g_ptr_array_new_with_free_func(prefix_free); - have_exact_matches = false; - for (int i = 0; i < 36 * 36; i++) { - two_char_prefix_index[i] = TCPI_NONE; - } + if (hashed_prefix) { + g_hash_table_destroy(hashed_prefix); + } + hashed_prefix = g_hash_table_new(g_str_hash, g_str_equal); + + if (prefix) { + g_ptr_array_free(prefix, TRUE); + } + prefix = g_ptr_array_new_with_free_func(prefix_free); + have_exact_matches = false; + for (int i = 0; i < 36 * 36; i++) { + two_char_prefix_index[i] = TCPI_NONE; + } } /* convert char to base36 */ static int to_base36(char c) { - if (isdigit(c)) { - return c - '0'; - } - if (isupper(c)) { - return 10 + c - 'A'; - } - return 0; // rest is mapped to zero + if (isdigit(c)) { + return c - '0'; + } + if (isupper(c)) { + return 10 + c - 'A'; + } + return 0; // rest is mapped to zero } /* get hash key for a call/prefix */ static int prefix_hash_key(const char *call) { - if (call[0] == 0) { // normally call is never empty - return 0; - } - return to_base36(call[0]) + 36 * to_base36(call[1]); + if (call[0] == 0) { // normally call is never empty + return 0; + } + return to_base36(call[0]) + 36 * to_base36(call[1]); } /* return number of entries in prefix array */ unsigned int prefix_count(void) { - return prefix->len; + return prefix->len; } /* give pointer to prefix struct at 'index' */ prefix_data *prefix_by_index(unsigned int index) { - if (index < 0 || index >= prefix_count()) - return &dummy_pfx; + if (index < 0 || index >= prefix_count()) + return &dummy_pfx; - return (prefix_data *)g_ptr_array_index(prefix, index); + return (prefix_data *)g_ptr_array_index(prefix, index); } /** lookup key in table of hashed prefixes @@ -117,260 +117,261 @@ prefix_data *prefix_by_index(unsigned int index) { * \param value - the corresponding prefix index */ static gboolean lookup_hashed_prefix(const char *key, void *value) { - return g_hash_table_lookup_extended(hashed_prefix, key, NULL, value); + return g_hash_table_lookup_extended(hashed_prefix, key, NULL, value); } /* search for a full match of 'call' in the pfx table */ int find_full_match(const char *call) { - void *value; - int w = -1; + void *value; + int w = -1; - if (lookup_hashed_prefix(call, &value)) { - w = GPOINTER_TO_INT(value); - } + if (lookup_hashed_prefix(call, &value)) { + w = GPOINTER_TO_INT(value); + } - return w; + return w; } /* search for the best mach of 'call' in pfx table */ int find_best_match(const char *call) { - void *value; - int w = -1; - - if (call == NULL) - return w; + void *value; + int w = -1; + + if (call == NULL) + return w; + + /* first check if it has a unique 2-char prefix */ + if (strlen(call) >= 2) { + int key = prefix_hash_key(call); + if (two_char_prefix_index[key] >= 0) { + return two_char_prefix_index[key]; + } + } - /* first check if it has a unique 2-char prefix */ - if (strlen(call) >= 2) { - int key = prefix_hash_key(call); - if (two_char_prefix_index[key] >= 0) { - return two_char_prefix_index[key]; + /* first try full match */ + if (lookup_hashed_prefix(call, &value)) { + w = GPOINTER_TO_INT(value); + return w; } - } - /* first try full match */ - if (lookup_hashed_prefix(call, &value)) { - w = GPOINTER_TO_INT(value); - return w; - } - - /* stepwise shorten the call and pick up first one -> maximum length - * Be careful to not use entries which require an exact match - */ - char *temp = g_strdup(call); - for (int len = strlen(call) - 1; len >= 1; len--) { - temp[len] = 0; // truncate to len - if (lookup_hashed_prefix(temp, &value)) { - int idx = GPOINTER_TO_INT(value); - if (!prefix_by_index(idx)->exact) { - w = idx; - break; - } + /* stepwise shorten the call and pick up first one -> maximum length + * Be careful to not use entries which require an exact match + */ + char *temp = g_strdup(call); + for (int len = strlen(call) - 1; len >= 1; len--) { + temp[len] = 0; // truncate to len + if (lookup_hashed_prefix(temp, &value)) { + int idx = GPOINTER_TO_INT(value); + if (!prefix_by_index(idx)->exact) { + w = idx; + break; + } + } } - } - g_free(temp); + g_free(temp); - return w; + return w; } /* add a new DXCC prefix description */ void prefix_add(char *pfxstr) { - char *ver = (*pfxstr == '=' ? pfxstr + 1 : pfxstr); - if (strlen(ver) == 11 && strncmp(ver, "VER", 3) == 0) { - strcpy(cty_dat_version, ver); // save it - } - - gchar *loc; - gint last_index = dxcc_count() - 1; - dxcc_data *last_dx = dxcc_by_index(last_index); - prefix_data *new_prefix = g_new(prefix_data, 1); - - if (*pfxstr == '=') { - new_prefix -> exact = true; - have_exact_matches = true; - pfxstr++; - } else - new_prefix -> exact = false; - - loc = strchr(pfxstr, '~'); - if (loc != NULL) { - new_prefix -> timezone = atof(loc + 1); - *loc = '\0'; - } else - new_prefix -> timezone = last_dx->timezone; - - loc = strchr(pfxstr, '{'); - if (loc != NULL) { - new_prefix -> continent = g_strdup(loc + 1); - *loc = '\0'; - loc = strchr(new_prefix -> continent, '}'); - if (loc != NULL) - *loc = '\0'; - } else - new_prefix -> continent = g_strdup(last_dx->continent); - - loc = strchr(pfxstr, '<'); - if (loc != NULL) { - new_prefix -> lat = atof(loc + 1); - *loc = '\0'; - if ((loc = strchr(loc, '/')) != NULL) - new_prefix -> lon = atof(loc + 1); - else - new_prefix -> lon = INFINITY; - } else { - new_prefix -> lat = last_dx->lat; - new_prefix -> lon = last_dx->lon; - } - - loc = strchr(pfxstr, '['); - if (loc != NULL) { - new_prefix -> itu = atoi(loc + 1); - *loc = '\0'; - } else - new_prefix -> itu = last_dx -> itu; - - loc = strchr(pfxstr, '('); - if (loc != NULL) { - new_prefix -> cq = atoi(loc + 1); - *loc = '\0'; - } else - new_prefix -> cq = last_dx -> cq; - - new_prefix -> pfx = g_strdup(pfxstr); - new_prefix -> dxcc_ctynr = last_index; - - g_ptr_array_add(prefix, new_prefix); - int index = prefix_count() - 1; - g_hash_table_insert(hashed_prefix, - new_prefix->pfx, - GINT_TO_POINTER(index)); - - /* build 2-char prefix hash */ - if (strlen(pfxstr) >= 2) { - int key = prefix_hash_key(pfxstr); - if (two_char_prefix_index[key] == TCPI_NONE) { - two_char_prefix_index[key] = index; // first one + char *ver = (*pfxstr == '=' ? pfxstr + 1 : pfxstr); + if (strlen(ver) == 11 && strncmp(ver, "VER", 3) == 0) { + strcpy(cty_dat_version, ver); // save it + } + + gchar *loc; + gint last_index = dxcc_count() - 1; + dxcc_data *last_dx = dxcc_by_index(last_index); + prefix_data *new_prefix = g_new(prefix_data, 1); + + if (*pfxstr == '=') { + new_prefix -> exact = true; + have_exact_matches = true; + pfxstr++; + } else + new_prefix -> exact = false; + + loc = strchr(pfxstr, '~'); + if (loc != NULL) { + new_prefix -> timezone = atof(loc + 1); + *loc = '\0'; + } else + new_prefix -> timezone = last_dx->timezone; + + loc = strchr(pfxstr, '{'); + if (loc != NULL) { + new_prefix -> continent = g_strdup(loc + 1); + *loc = '\0'; + loc = strchr(new_prefix -> continent, '}'); + if (loc != NULL) + *loc = '\0'; + } else + new_prefix -> continent = g_strdup(last_dx->continent); + + loc = strchr(pfxstr, '<'); + if (loc != NULL) { + new_prefix -> lat = atof(loc + 1); + *loc = '\0'; + if ((loc = strchr(loc, '/')) != NULL) + new_prefix -> lon = atof(loc + 1); + else + new_prefix -> lon = INFINITY; } else { - two_char_prefix_index[key] = TCPI_AMB; // ambiguous + new_prefix -> lat = last_dx->lat; + new_prefix -> lon = last_dx->lon; + } + + loc = strchr(pfxstr, '['); + if (loc != NULL) { + new_prefix -> itu = atoi(loc + 1); + *loc = '\0'; + } else + new_prefix -> itu = last_dx -> itu; + + loc = strchr(pfxstr, '('); + if (loc != NULL) { + new_prefix -> cq = atoi(loc + 1); + *loc = '\0'; + } else + new_prefix -> cq = last_dx -> cq; + + new_prefix -> pfx = g_strdup(pfxstr); + new_prefix -> dxcc_ctynr = last_index; + + g_ptr_array_add(prefix, new_prefix); + int index = prefix_count() - 1; + g_hash_table_insert(hashed_prefix, + new_prefix->pfx, + GINT_TO_POINTER(index)); + + /* build 2-char prefix hash */ + if (strlen(pfxstr) >= 2) { + int key = prefix_hash_key(pfxstr); + if (two_char_prefix_index[key] == TCPI_NONE) { + two_char_prefix_index[key] = index; // first one + } else { + two_char_prefix_index[key] = TCPI_AMB; // ambiguous + } } - } } static void dxcc_free(gpointer data) { - dxcc_data *dxcc = data; + dxcc_data *dxcc = data; - g_free(dxcc -> countryname); - g_free(dxcc -> continent); - g_free(dxcc -> pfx); - g_free(dxcc); + g_free(dxcc -> countryname); + g_free(dxcc -> continent); + g_free(dxcc -> pfx); + g_free(dxcc); } void dxcc_init(void) { - cty_dat_version[0] = 0; - if (dxcc) { - g_ptr_array_free(dxcc, TRUE); - } - dxcc = g_ptr_array_new_with_free_func(dxcc_free); + cty_dat_version[0] = 0; + if (dxcc) { + g_ptr_array_free(dxcc, TRUE); + } + dxcc = g_ptr_array_new_with_free_func(dxcc_free); } /* return number of entries in dxcc array */ unsigned int dxcc_count(void) { - return dxcc->len; + return dxcc->len; } /* give pointer to dxcc_data struct at 'index' */ dxcc_data *dxcc_by_index(unsigned int index) { - if (index >= dxcc_count()) - index = 0; + if (index >= dxcc_count()) + index = 0; - return (dxcc_data *)g_ptr_array_index(dxcc, index); + return (dxcc_data *)g_ptr_array_index(dxcc, index); } void dxcc_add(char *dxcc_line) { - gchar **split; - gint item; - dxcc_data *new_dxcc = g_new(dxcc_data, 1); + gchar **split; + gint item; + dxcc_data *new_dxcc = g_new(dxcc_data, 1); + + /* split up the line */ + split = g_strsplit(dxcc_line, ":", 9); - /* split up the line */ - split = g_strsplit(dxcc_line, ":", 9); + if (g_strv_length(split) < 8) { /* wrong syntax, ignore line */ + g_strfreev(split); + g_free(new_dxcc); + return; + } + + for (item = 0; item < 8; item++) + g_strstrip(split[item]); + + new_dxcc -> countryname = g_strdup(split[0]); + new_dxcc -> cq = atoi(split[1]); + new_dxcc -> itu = atoi(split[2]); + new_dxcc -> continent = g_strdup(split[3]); + new_dxcc -> lat = atof(split[4]); + new_dxcc -> lon = atof(split[5]); + new_dxcc -> timezone = atof(split[6]); + if (*split[7] == '*') { + new_dxcc -> pfx = g_strdup(split[7] + 1); + new_dxcc -> starred = true; + } else { + new_dxcc -> pfx = g_strdup(split[7]); + new_dxcc -> starred = false; + } - if (g_strv_length(split) < 8) { /* wrong syntax, ignore line */ g_strfreev(split); - g_free(new_dxcc); - return; - } - - for (item = 0; item < 8; item++) - g_strstrip(split[item]); - - new_dxcc -> countryname = g_strdup(split[0]); - new_dxcc -> cq = atoi(split[1]); - new_dxcc -> itu = atoi(split[2]); - new_dxcc -> continent = g_strdup(split[3]); - new_dxcc -> lat = atof(split[4]); - new_dxcc -> lon = atof(split[5]); - new_dxcc -> timezone = atof(split[6]); - if (*split[7] == '*') { - new_dxcc -> pfx = g_strdup(split[7] + 1); - new_dxcc -> starred = true; - } else { - new_dxcc -> pfx = g_strdup(split[7]); - new_dxcc -> starred = false; - } - - g_strfreev(split); - - g_ptr_array_add(dxcc, new_dxcc); + + g_ptr_array_add(dxcc, new_dxcc); } /** load cty database from filename */ int load_ctydata(char *filename) { - FILE *fd; - char* buf = NULL; - size_t buf_len = 181; - char *loc; - int read; - - if ((fd = fopen(filename, "r")) == NULL) - return -1; - - dxcc_init(); - prefix_init(); - - // set default for empty country == country nr 0 - dxcc_add("Not Specified : --: --: --: -00.00: 00.00: 0.0: :"); - - while ((read = getline(&buf, &buf_len, fd)) != -1) { - if (buf_len > 0) { - g_strchomp(buf); /* drop CR and/or NL and */ - if (*buf == '\0') /* ignore empty lines */ - continue; - - if (buf[0] != ' ') { // data line - dxcc_add(buf); - } else { // prefix line - loc = strtok(buf, " ,;"); - while (loc != NULL) { - prefix_add(loc); - loc = strtok(NULL, " ,;"); - } - } - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } - - if (buf != NULL) - free(buf); - - fclose(fd); - return 0; + FILE *fd; + char *buf = NULL; + size_t buf_len = 181; + char *loc; + int read; + + if ((fd = fopen(filename, "r")) == NULL) + return -1; + + dxcc_init(); + prefix_init(); + + // set default for empty country == country nr 0 + dxcc_add("Not Specified : --: --: --: -00.00: 00.00: 0.0: :"); + + while ((read = getline(&buf, &buf_len, fd)) != -1) { + if (buf_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + g_strchomp(buf); /* drop CR and/or NL and */ + if (*buf == '\0') /* ignore empty lines */ + continue; + + if (buf[0] != ' ') { // data line + dxcc_add(buf); + } else { // prefix line + loc = strtok(buf, " ,;"); + while (loc != NULL) { + prefix_add(loc); + loc = strtok(NULL, " ,;"); + } + } + } + } + + if (buf != NULL) + free(buf); + + fclose(fd); + return 0; } diff --git a/src/initial_exchange.c b/src/initial_exchange.c index 3c444122..655eb923 100644 --- a/src/initial_exchange.c +++ b/src/initial_exchange.c @@ -39,36 +39,42 @@ */ void free_ie_list(struct ie_list *head) { - struct ie_list *next; + struct ie_list *next; - while (head) { - next = head->next; - free(head); - head = next; - } + while (head) { + next = head->next; + free(head); + head = next; + } } struct ie_list *make_ie_list(char *file) { - FILE *fp; - char *inputbuffer = NULL; - size_t inputbuffer_len = 91; - char *loc; - - struct ie_list *ie_listhead = NULL; - struct ie_list *new; - char *token; - int read, linectr = 0; - - if ((fp = fopen(file, "r")) == NULL) { - showmsg("Cannot find initial exchange file"); - return NULL; - } - - showstring("Using initial exchange file", file); + FILE *fp; + char *inputbuffer = NULL; + size_t inputbuffer_len = 91; + char *loc; + + struct ie_list *ie_listhead = NULL; + struct ie_list *new; + char *token; + int read, linectr = 0; + + if ((fp = fopen(file, "r")) == NULL) { + showmsg("Cannot find initial exchange file"); + return NULL; + } + + showstring("Using initial exchange file", file); + + while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { + if (inputbuffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } - while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { - if (inputbuffer_len > 0) { linectr++; g_strstrip(inputbuffer); // strip leading/trailing whitespace @@ -127,7 +133,7 @@ struct ie_list *make_ie_list(char *file) { free_ie_list(ie_listhead); fclose(fp); sprintf(msg, "Line %d: 0 or more than one token before comma", - linectr); + linectr); showmsg(msg); return NULL; } @@ -149,15 +155,11 @@ struct ie_list *make_ie_list(char *file) { new->next = ie_listhead; ie_listhead = new; } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } + } if (inputbuffer != NULL) free(inputbuffer); - fclose(fp); + fclose(fp); - return ie_listhead; + return ie_listhead; } diff --git a/src/parse_logcfg.c b/src/parse_logcfg.c index da702e57..058d4eae 100644 --- a/src/parse_logcfg.c +++ b/src/parse_logcfg.c @@ -67,95 +67,97 @@ char *error_details = NULL; int read_logcfg(void) { - static char defltconf[] = PACKAGE_DATA_DIR "/" LOGCFG_DAT_FILE; - FILE *fp; - - if (config_file != NULL) { - fp = fopen(config_file, "r"); - if (fp == NULL) { - showstring("Error opening config file: ", config_file); - return PARSE_ERROR; - } - } else { - config_file = g_strdup(LOGCFG_DAT_FILE); + static char defltconf[] = PACKAGE_DATA_DIR "/" LOGCFG_DAT_FILE; + FILE *fp; + + if (config_file != NULL) { + fp = fopen(config_file, "r"); + if (fp == NULL) { + showstring("Error opening config file: ", config_file); + return PARSE_ERROR; + } + } else { + config_file = g_strdup(LOGCFG_DAT_FILE); + + if (access(config_file, R_OK) == -1) { + showmsg("No logcfg.dat found. Copying default config file."); + showmsg("Please adapt the settings to your needs."); + char *cmd = g_strdup_printf("cp %s %s", defltconf, + LOGCFG_DAT_FILE); + IGNORE(system(cmd)); + g_free(cmd); + sleep(2); + } + if ((fp = fopen(config_file, "r")) == NULL) { + showmsg("Error opening logcfg.dat file."); + return PARSE_ERROR; + } - if (access(config_file, R_OK) == -1) { - showmsg("No logcfg.dat found. Copying default config file."); - showmsg("Please adapt the settings to your needs."); - char *cmd = g_strdup_printf("cp %s %s", defltconf, - LOGCFG_DAT_FILE); - IGNORE(system(cmd)); - g_free(cmd); - sleep(2); - } - if ((fp = fopen(config_file, "r")) == NULL) { - showmsg("Error opening logcfg.dat file."); - return PARSE_ERROR; } + showstring("Reading config file:", config_file); - } - showstring("Reading config file:", config_file); - - sound_setup_default(); - int status = parse_configfile(fp); - fclose(fp); + sound_setup_default(); + int status = parse_configfile(fp); + fclose(fp); - return status; + return status; } static bool isCommentLine(char *buffer) { - return buffer[0] == 0 || buffer[0] == '#' || buffer[0] == ';'; + return buffer[0] == 0 || buffer[0] == '#' || buffer[0] == ';'; } int parse_configfile(FILE *fp) { - int status = PARSE_OK; - char *buffer = NULL; - size_t buffer_len = 0; - ssize_t read; - - while ((read = getline(&buffer, &buffer_len, fp)) != -1) { - if (buffer_len > 0 && errno != ENOMEM) { - g_strchug(buffer); // remove leading space - if (isCommentLine(buffer)) { // skip comments and empty lines - continue; - } - - status = parse_logcfg(buffer); - if (status != PARSE_OK) { - break; - } - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } - - if (buffer != NULL) - free(buffer); - return status; + int status = PARSE_OK; + char *buffer = NULL; + size_t buffer_len = 0; + ssize_t read; + + while ((read = getline(&buffer, &buffer_len, fp)) != -1) { + if (buffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + + g_strchug(buffer); // remove leading space + if (isCommentLine(buffer)) { // skip comments and empty lines + continue; + } + + status = parse_logcfg(buffer); + if (status != PARSE_OK) { + break; + } + } + } + + if (buffer != NULL) + free(buffer); + return status; } /** convert band string into index number (0..NBANDS-2) */ // note: NBANDS-1 is the OOB int getidxbybandstr(char *confband) { - char buf[8]; + char buf[8]; - g_strchomp(confband); + g_strchomp(confband); - for (int i = 0; i < NBANDS - 1; i++) { - strcpy(buf, band[i]); - if (strcmp(confband, g_strchug(buf)) == 0) { - return i; + for (int i = 0; i < NBANDS - 1; i++) { + strcpy(buf, band[i]); + if (strcmp(confband, g_strchug(buf)) == 0) { + return i; + } } - } - return -1; + return -1; } static void str_toupper(char *str) { - for (char *p = str; *p; ++p) { - *p = g_ascii_toupper(*p); - } + for (char *p = str; *p; ++p) { + *p = g_ascii_toupper(*p); + } } //////////////////// @@ -165,81 +167,81 @@ const char *parameter; static int parse_int(const char *string, gint64 min, gint64 max, int *result) { - gchar *str = g_strdup(string); - g_strstrip(str); + gchar *str = g_strdup(string); + g_strstrip(str); - if (str[0] == 0) { // empty input - g_free(str); - return PARSE_INVALID_INTEGER; - } + if (str[0] == 0) { // empty input + g_free(str); + return PARSE_INVALID_INTEGER; + } - gchar *end_ptr = NULL; - errno = 0; - gint64 value = g_ascii_strtoll(str, &end_ptr, 10); + gchar *end_ptr = NULL; + errno = 0; + gint64 value = g_ascii_strtoll(str, &end_ptr, 10); - if ((errno != 0 && errno != ERANGE) - || end_ptr == NULL || *end_ptr != 0) { + if ((errno != 0 && errno != ERANGE) + || end_ptr == NULL || *end_ptr != 0) { - g_free(str); - return PARSE_INVALID_INTEGER; - } + g_free(str); + return PARSE_INVALID_INTEGER; + } - g_free(str); + g_free(str); - if (errno == ERANGE || value < min || value > max) { - return PARSE_INTEGER_OUT_OF_RANGE; - } + if (errno == ERANGE || value < min || value > max) { + return PARSE_INTEGER_OUT_OF_RANGE; + } - *result = (int)value; - return PARSE_OK; + *result = (int)value; + return PARSE_OK; } static int parse_bool(const char *string, bool *result) { - gchar *str = NULL; - if (string != NULL) { - str = g_strdup(string); - g_strstrip(str); - str_toupper(str); // normalize to upper case - } - - bool value; - - if (str == NULL || str[0] == 0 // no or empty input is true - || strcmp(str, "TRUE") == 0 - || strcmp(str, "YES") == 0 - || strcmp(str, "ON") == 0) { - value = true; - } else if (strcmp(str, "FALSE") == 0 - || strcmp(str, "NO") == 0 - || strcmp(str, "OFF") == 0) { - value = false; - } else { - g_free(str); - return PARSE_WRONG_PARAMETER; - } + gchar *str = NULL; + if (string != NULL) { + str = g_strdup(string); + g_strstrip(str); + str_toupper(str); // normalize to upper case + } + + bool value; + + if (str == NULL || str[0] == 0 // no or empty input is true + || strcmp(str, "TRUE") == 0 + || strcmp(str, "YES") == 0 + || strcmp(str, "ON") == 0) { + value = true; + } else if (strcmp(str, "FALSE") == 0 + || strcmp(str, "NO") == 0 + || strcmp(str, "OFF") == 0) { + value = false; + } else { + g_free(str); + return PARSE_WRONG_PARAMETER; + } - g_free(str); + g_free(str); - *result = value; - return PARSE_OK; + *result = value; + return PARSE_OK; } int cfg_bool(const cfg_arg_t arg) { - return parse_bool(parameter, arg.bool_p); + return parse_bool(parameter, arg.bool_p); } int cfg_contest_bool(const cfg_arg_t arg) { - return parse_bool(parameter, (bool *)((char *)contest + arg.offset)); + return parse_bool(parameter, (bool *)((char *)contest + arg.offset)); } int cfg_int_const(const cfg_arg_t arg) { - *arg.int_p = arg.int_value; - return PARSE_OK; + *arg.int_p = arg.int_value; + return PARSE_OK; } int cfg_integer(const cfg_arg_t arg) { - return parse_int(parameter, (gint64)arg.min, (gint64)arg.max, arg.int_p); + return parse_int(parameter, (gint64)arg.min, (gint64)arg.max, arg.int_p); } // @@ -248,1287 +250,1289 @@ int cfg_integer(const cfg_arg_t arg) { // message: msg, size > 0, base used // int cfg_string(const cfg_arg_t arg) { - gchar *index = g_match_info_fetch(match_info, 1); - int n = 0; - if (NULL != index) { - n = atoi(index); // use provided index - g_free(index); - } - - char *str = g_strdup(parameter); - // chomp/strip - if (arg.chomp) { - g_strchomp(str); - } - if (arg.strip) { - g_strstrip(str); - } - // check length - if (arg.size > 0 && strlen(str) >= arg.size) { - g_free(str); - return PARSE_STRING_TOO_LONG; - } - // replace trailing newline with a space - if (arg.nl_to_space) { - char *nl = strrchr(str, '\n'); - if (nl) { - *nl = ' '; - } - } - - // store value - switch (arg.string_type) { - case STATIC: - g_strlcpy(arg.char_p, str, arg.size); - g_free(str); - break; - case MESSAGE: - g_strlcpy(arg.msg[arg.base + n], str, arg.size); - g_free(str); - break; - case DYNAMIC: - if (arg.char_pp[arg.base + n] != NULL) { - g_free(arg.char_pp[arg.base + n]); - } - arg.char_pp[arg.base + n] = str; - } - return PARSE_OK; + gchar *index = g_match_info_fetch(match_info, 1); + int n = 0; + if (NULL != index) { + n = atoi(index); // use provided index + g_free(index); + } + + char *str = g_strdup(parameter); + // chomp/strip + if (arg.chomp) { + g_strchomp(str); + } + if (arg.strip) { + g_strstrip(str); + } + // check length + if (arg.size > 0 && strlen(str) >= arg.size) { + g_free(str); + return PARSE_STRING_TOO_LONG; + } + // replace trailing newline with a space + if (arg.nl_to_space) { + char *nl = strrchr(str, '\n'); + if (nl) { + *nl = ' '; + } + } + + // store value + switch (arg.string_type) { + case STATIC: + g_strlcpy(arg.char_p, str, arg.size); + g_free(str); + break; + case MESSAGE: + g_strlcpy(arg.msg[arg.base + n], str, arg.size); + g_free(str); + break; + case DYNAMIC: + if (arg.char_pp[arg.base + n] != NULL) { + g_free(arg.char_pp[arg.base + n]); + } + arg.char_pp[arg.base + n] = str; + } + return PARSE_OK; } static int cfg_telnetport(const cfg_arg_t arg) { - int rc = cfg_integer((cfg_arg_t) {.int_p = &portnum, .min = 1, .max = INT32_MAX}); - if (rc != PARSE_OK) { - return rc; - } - packetinterface = TELNET_INTERFACE; - return PARSE_OK; + int rc = cfg_integer((cfg_arg_t) {.int_p = &portnum, .min = 1, .max = INT32_MAX}); + if (rc != PARSE_OK) { + return rc; + } + packetinterface = TELNET_INTERFACE; + return PARSE_OK; } // define colors: GREEN (header), CYAN (windows), WHITE (log win), // MAGENTA (marker / dupes), BLUE (input field) and YELLOW (window frames) static int cfg_tlfcolor(const cfg_arg_t arg) { - gchar *index = g_match_info_fetch(match_info, 1); - int n = atoi(index); // get index (1..6) - g_free(index); + gchar *index = g_match_info_fetch(match_info, 1); + int n = atoi(index); // get index (1..6) + g_free(index); - int rc = PARSE_OK; - char *str = g_strdup(parameter); - g_strstrip(str); + int rc = PARSE_OK; + char *str = g_strdup(parameter); + g_strstrip(str); - if (strlen(str) == 2 && isdigit(str[0]) && isdigit(str[1])) { - if (n >= 2) { - ++n; // skip RED + if (strlen(str) == 2 && isdigit(str[0]) && isdigit(str[1])) { + if (n >= 2) { + ++n; // skip RED + } + tlfcolors[n][0] = str[0] - '0'; + tlfcolors[n][1] = str[1] - '0'; + } else { + error_details = g_strdup("must be a 2 digit octal number"); + rc = PARSE_WRONG_PARAMETER; } - tlfcolors[n][0] = str[0] - '0'; - tlfcolors[n][1] = str[1] - '0'; - } else { - error_details = g_strdup("must be a 2 digit octal number"); - rc = PARSE_WRONG_PARAMETER; - } - g_free(str); + g_free(str); - return rc; + return rc; } // returns 0 on error static unsigned int parse_frequency(char *input) { - char *value = g_strdup(input); - str_toupper(value); // normalize to upper case - /* must be digits and an optional K suffix */ - if (!g_regex_match_simple("^\\s*[0-9]+K?\\s*$", - value, (GRegexCompileFlags)0, (GRegexMatchFlags)0)) { - g_free(value); - return 0; - } + char *value = g_strdup(input); + str_toupper(value); // normalize to upper case + /* must be digits and an optional K suffix */ + if (!g_regex_match_simple("^\\s*[0-9]+K?\\s*$", + value, (GRegexCompileFlags)0, (GRegexMatchFlags)0)) { + g_free(value); + return 0; + } - int freq = atoi(value); - if (strchr(value, 'K') != NULL) { - freq *= 1000; - } + int freq = atoi(value); + if (strchr(value, 'K') != NULL) { + freq *= 1000; + } - g_free(value); - return freq; + g_free(value); + return freq; } static int cfg_band(const cfg_arg_t arg) { - gchar *index = g_match_info_fetch(match_info, 1); - int band = atoi(index); - int bi = bandnr2index(band); // get band index - g_free(index); - - if (bi == BANDINDEX_OOB) { - error_details = g_strdup("invalid band"); - return PARSE_ERROR; - } + gchar *index = g_match_info_fetch(match_info, 1); + int band = atoi(index); + int bi = bandnr2index(band); // get band index + g_free(index); - int rc = PARSE_OK; - char **fields = g_strsplit(parameter, ",", 4); - unsigned int values[4]; - for (int i = 0; i < 4 && rc == PARSE_OK; ++i) { - if (fields[i] == NULL) { - error_details = g_strdup("too few arguments"); - rc = PARSE_WRONG_PARAMETER; - break; + if (bi == BANDINDEX_OOB) { + error_details = g_strdup("invalid band"); + return PARSE_ERROR; } - values[i] = parse_frequency(fields[i]); - if (values[i] == 0) { - error_details = g_strdup_printf("invalid frequency %s", fields[i]); - rc = PARSE_WRONG_PARAMETER; - } - // values may not be decreasing - else if (i > 0 && values[i] < values[i - 1]) { - error_details = g_strdup_printf("wrong frequency %s", fields[i]); - rc = PARSE_WRONG_PARAMETER; + + int rc = PARSE_OK; + char **fields = g_strsplit(parameter, ",", 4); + unsigned int values[4]; + for (int i = 0; i < 4 && rc == PARSE_OK; ++i) { + if (fields[i] == NULL) { + error_details = g_strdup("too few arguments"); + rc = PARSE_WRONG_PARAMETER; + break; + } + values[i] = parse_frequency(fields[i]); + if (values[i] == 0) { + error_details = g_strdup_printf("invalid frequency %s", fields[i]); + rc = PARSE_WRONG_PARAMETER; + } + // values may not be decreasing + else if (i > 0 && values[i] < values[i - 1]) { + error_details = g_strdup_printf("wrong frequency %s", fields[i]); + rc = PARSE_WRONG_PARAMETER; + } } - } - if (rc == PARSE_OK) { - bandcorner[bi][0] = values[0]; - cwcorner[bi] = values[1]; - ssbcorner[bi] = values[2]; - bandcorner[bi][1] = values[3]; - } + if (rc == PARSE_OK) { + bandcorner[bi][0] = values[0]; + cwcorner[bi] = values[1]; + ssbcorner[bi] = values[2]; + bandcorner[bi][1] = values[3]; + } - g_strfreev(fields); + g_strfreev(fields); - return rc; + return rc; } static int cfg_call(const cfg_arg_t arg) { - int rc = cfg_string((cfg_arg_t) { - .char_p = my.call, .size = sizeof(my.call), - .strip = true, .string_type = STATIC - }); - if (rc != PARSE_OK) { - return rc; - } - if (strlen(my.call) <= 2) { - error_details = g_strdup("too short"); - return PARSE_WRONG_PARAMETER; - } + int rc = cfg_string((cfg_arg_t) { + .char_p = my.call, .size = sizeof(my.call), + .strip = true, .string_type = STATIC + }); + if (rc != PARSE_OK) { + return rc; + } + if (strlen(my.call) <= 2) { + error_details = g_strdup("too short"); + return PARSE_WRONG_PARAMETER; + } - str_toupper(my.call); + str_toupper(my.call); - return PARSE_OK; + return PARSE_OK; } static int cfg_contest(const cfg_arg_t arg) { - char contest[41]; - int rc = cfg_string((cfg_arg_t) { - .char_p = contest, .size = 40, .strip = true, .string_type = STATIC - }); - if (rc != PARSE_OK) { - return rc; - } - setcontest(contest); - return PARSE_OK; + char contest[41]; + int rc = cfg_string((cfg_arg_t) { + .char_p = contest, .size = 40, .strip = true, .string_type = STATIC + }); + if (rc != PARSE_OK) { + return rc; + } + setcontest(contest); + return PARSE_OK; } static int cfg_operating_mode(const cfg_arg_t arg) { - char *str = g_ascii_strup(parameter, -1); - g_strstrip(str); + char *str = g_ascii_strup(parameter, -1); + g_strstrip(str); - if (strcmp(str, "CQ") == 0) { - cqmode = CQ; - } else if (strcmp(str, "S&P") == 0) { - cqmode = S_P; - } else { - g_free(str); - error_details = g_strdup("must be CQ or S&P"); - return PARSE_WRONG_PARAMETER; - } + if (strcmp(str, "CQ") == 0) { + cqmode = CQ; + } else if (strcmp(str, "S&P") == 0) { + cqmode = S_P; + } else { + g_free(str); + error_details = g_strdup("must be CQ or S&P"); + return PARSE_WRONG_PARAMETER; + } - g_free(str); - return PARSE_OK; + g_free(str); + return PARSE_OK; } static int cfg_bandoutput(const cfg_arg_t arg) { - char *str = g_strdup(parameter); - g_strstrip(str); + char *str = g_strdup(parameter); + g_strstrip(str); - int rc = PARSE_OK; + int rc = PARSE_OK; - if (g_regex_match_simple("^\\d{10}$", str, G_REGEX_CASELESS, - (GRegexMatchFlags)0)) { - use_bandoutput = 1; - for (int i = 0; i <= 9; i++) { // 10x - bandindexarray[i] = str[i] - '0'; + if (g_regex_match_simple("^\\d{10}$", str, G_REGEX_CASELESS, + (GRegexMatchFlags)0)) { + use_bandoutput = 1; + for (int i = 0; i <= 9; i++) { // 10x + bandindexarray[i] = str[i] - '0'; + } + } else { + error_details = g_strdup_printf("must be %d digits", NBANDS); + rc = PARSE_WRONG_PARAMETER; } - } else { - error_details = g_strdup_printf("must be %d digits", NBANDS); - rc = PARSE_WRONG_PARAMETER; - } - g_free(str); + g_free(str); - return rc; + return rc; } static int cfg_n_points(const cfg_arg_t arg) { - gchar *keyword = g_match_info_fetch(match_info, 0); - - if (g_str_has_prefix(keyword, "ONE")) { - contest->points.type = FIXED; - contest->points.point = 1; - } else if (g_str_has_prefix(keyword, "TWO")) { - contest->points.type = FIXED; - contest->points.point = 2; - } else if (g_str_has_prefix(keyword, "THREE")) { - contest->points.type = FIXED; - contest->points.point = 3; - } + gchar *keyword = g_match_info_fetch(match_info, 0); + + if (g_str_has_prefix(keyword, "ONE")) { + contest->points.type = FIXED; + contest->points.point = 1; + } else if (g_str_has_prefix(keyword, "TWO")) { + contest->points.type = FIXED; + contest->points.point = 2; + } else if (g_str_has_prefix(keyword, "THREE")) { + contest->points.type = FIXED; + contest->points.point = 3; + } - g_free(keyword); + g_free(keyword); - return PARSE_OK; + return PARSE_OK; } static int cfg_bandmap(const cfg_arg_t arg) { - cluster = MAP; - - /* init bandmap filtering */ - bm_config.allband = true; - bm_config.allmode = true; - bm_config.showdupes = true; - bm_config.skipdupes = false; - bm_config.lifetime = 900; - bm_config.onlymults = false; - bm_config.show_out_of_band = false; - - /* Allow configuration of bandmap display if keyword - * is followed by a '=' - * Parameter format is BANDMAP=, - * - string parsed for the letters B, M, D and S - * - spot lifetime in seconds (>=30) - */ - if (parameter != NULL) { - char **bm_fields = g_strsplit(parameter, ",", 2); - if (bm_fields[0] != NULL) { - char *ptr = bm_fields[0]; - while (*ptr != '\0') { - switch (*ptr++) { - case 'B': bm_config.allband = false; - break; - case 'M': bm_config.allmode = false; - break; - case 'D': bm_config.showdupes = false; - break; - case 'S': bm_config.skipdupes = true; - break; - case 'O': bm_config.onlymults = true; - break; - case 'X': bm_config.show_out_of_band = true; - break; - default: - break; + cluster = MAP; + + /* init bandmap filtering */ + bm_config.allband = true; + bm_config.allmode = true; + bm_config.showdupes = true; + bm_config.skipdupes = false; + bm_config.lifetime = 900; + bm_config.onlymults = false; + bm_config.show_out_of_band = false; + + /* Allow configuration of bandmap display if keyword + * is followed by a '=' + * Parameter format is BANDMAP=, + * - string parsed for the letters B, M, D and S + * - spot lifetime in seconds (>=30) + */ + if (parameter != NULL) { + char **bm_fields = g_strsplit(parameter, ",", 2); + if (bm_fields[0] != NULL) { + char *ptr = bm_fields[0]; + while (*ptr != '\0') { + switch (*ptr++) { + case 'B': bm_config.allband = false; + break; + case 'M': bm_config.allmode = false; + break; + case 'D': bm_config.showdupes = false; + break; + case 'S': bm_config.skipdupes = true; + break; + case 'O': bm_config.onlymults = true; + break; + case 'X': bm_config.show_out_of_band = true; + break; + default: + break; + } + } } - } - } - if (bm_fields[1] != NULL) { - int lifetime; - g_strstrip(bm_fields[1]); - lifetime = atoi(bm_fields[1]); - if (lifetime >= 30) - /* aging called each second */ - bm_config.lifetime = lifetime; - } + if (bm_fields[1] != NULL) { + int lifetime; + g_strstrip(bm_fields[1]); + lifetime = atoi(bm_fields[1]); + if (lifetime >= 30) + /* aging called each second */ + bm_config.lifetime = lifetime; + } - g_strfreev(bm_fields); - } + g_strfreev(bm_fields); + } - return PARSE_OK; + return PARSE_OK; } static int cfg_cwspeed(const cfg_arg_t arg) { - int value = 0; /* avoid warning about uninitialized variables */ - int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 6, .max = 60}); - if (rc != PARSE_OK) { - return rc; - } - SetCWSpeed(value); - return PARSE_OK; + int value = 0; /* avoid warning about uninitialized variables */ + int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 6, .max = 60}); + if (rc != PARSE_OK) { + return rc; + } + SetCWSpeed(value); + return PARSE_OK; } static int cfg_cwtone(const cfg_arg_t arg) { - int value = 0; /* avoid warning about uninitialized variables */ - int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 0, .max = 999}); - if (rc != PARSE_OK) { - return rc; - } - sprintf(tonestr, "%d", value); - return PARSE_OK; + int value = 0; /* avoid warning about uninitialized variables */ + int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 0, .max = 999}); + if (rc != PARSE_OK) { + return rc; + } + sprintf(tonestr, "%d", value); + return PARSE_OK; } static int cfg_sunspots(const cfg_arg_t arg) { - int value = 0; /* avoid warning about uninitialized variables */ - int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 0, .max = 1000}); - if (rc != PARSE_OK) { - return rc; - } - wwv_set_r(value); - return PARSE_OK; + int value = 0; /* avoid warning about uninitialized variables */ + int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 0, .max = 1000}); + if (rc != PARSE_OK) { + return rc; + } + wwv_set_r(value); + return PARSE_OK; } static int cfg_sfi(const cfg_arg_t arg) { - int value = 0; /* avoid warning about uninitialized variables */ - int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 0, .max = 1000}); - if (rc != PARSE_OK) { - return rc; - } - wwv_set_sfi(value); - return PARSE_OK; + int value = 0; /* avoid warning about uninitialized variables */ + int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 0, .max = 1000}); + if (rc != PARSE_OK) { + return rc; + } + wwv_set_sfi(value); + return PARSE_OK; } static int cfg_tncport(const cfg_arg_t arg) { - strncpy(tncportname, parameter, 39); + strncpy(tncportname, parameter, 39); - packetinterface = TNC_INTERFACE; - return PARSE_OK; + packetinterface = TNC_INTERFACE; + return PARSE_OK; } static int cfg_addnode(const cfg_arg_t arg) { - if (nodes >= MAXNODES) { - error_details = g_strdup_printf("max %d nodes allowed", MAXNODES); - return PARSE_WRONG_PARAMETER; - } - /* split host name and port number, separated by colon */ - char **an_fields; - an_fields = g_strsplit(parameter, ":", 2); - /* copy host name */ - g_strlcpy(bc_hostaddress[nodes], g_strchomp(an_fields[0]), - sizeof(bc_hostaddress[0])); - if (an_fields[1] != NULL) { - /* copy host port, if found */ - g_strlcpy(bc_hostservice[nodes], g_strchomp(an_fields[1]), - sizeof(bc_hostservice[0])); - } - g_strfreev(an_fields); - - nodes++; - lan_active = true; - - return PARSE_OK; + if (nodes >= MAXNODES) { + error_details = g_strdup_printf("max %d nodes allowed", MAXNODES); + return PARSE_WRONG_PARAMETER; + } + /* split host name and port number, separated by colon */ + char **an_fields; + an_fields = g_strsplit(parameter, ":", 2); + /* copy host name */ + g_strlcpy(bc_hostaddress[nodes], g_strchomp(an_fields[0]), + sizeof(bc_hostaddress[0])); + if (an_fields[1] != NULL) { + /* copy host port, if found */ + g_strlcpy(bc_hostservice[nodes], g_strchomp(an_fields[1]), + sizeof(bc_hostservice[0])); + } + g_strfreev(an_fields); + + nodes++; + lan_active = true; + + return PARSE_OK; } static int cfg_thisnode(const cfg_arg_t arg) { - char *str = g_ascii_strup(parameter, -1); - g_strstrip(str); + char *str = g_ascii_strup(parameter, -1); + g_strstrip(str); - if (strlen(str) != 1 || str[0] < 'A' || str[0] > 'A' + MAXNODES) { - g_free(str); - error_details = g_strdup_printf("name is A..%c", 'A' + MAXNODES - 1); - return PARSE_WRONG_PARAMETER; - } + if (strlen(str) != 1 || str[0] < 'A' || str[0] > 'A' + MAXNODES) { + g_free(str); + error_details = g_strdup_printf("name is A..%c", 'A' + MAXNODES - 1); + return PARSE_WRONG_PARAMETER; + } - thisnode = str[0]; + thisnode = str[0]; - g_free(str); - return PARSE_OK; + g_free(str); + return PARSE_OK; } static int cfg_mult_list(const cfg_arg_t arg) { - int rc = cfg_string((cfg_arg_t) { - .char_p = multsfile, .size = 80, .strip = true, .string_type = STATIC - }); - if (rc != PARSE_OK) { - return rc; - } - multlist = 1; - return PARSE_OK; + int rc = cfg_string((cfg_arg_t) { + .char_p = multsfile, .size = 80, .strip = true, .string_type = STATIC + }); + if (rc != PARSE_OK) { + return rc; + } + multlist = 1; + return PARSE_OK; } static int cfg_markers(const cfg_arg_t arg) { - int rc = cfg_string((cfg_arg_t) { - .char_p = markerfile, .size = 120, .strip = true, .string_type = STATIC - }); - if (rc != PARSE_OK) { - return rc; - } + int rc = cfg_string((cfg_arg_t) { + .char_p = markerfile, .size = 120, .strip = true, .string_type = STATIC + }); + if (rc != PARSE_OK) { + return rc; + } - gchar *type = g_match_info_fetch(match_info, 1); - if (strcmp(type, "") == 0) { - xplanet = MARKER_ALL; - } else if (strcmp(type, "DOT") == 0) { - xplanet = MARKER_DOTS; - } else if (strcmp(type, "CALL") == 0) { - xplanet = MARKER_CALLS; - } - g_free(type); - return PARSE_OK; + gchar *type = g_match_info_fetch(match_info, 1); + if (strcmp(type, "") == 0) { + xplanet = MARKER_ALL; + } else if (strcmp(type, "DOT") == 0) { + xplanet = MARKER_DOTS; + } else if (strcmp(type, "CALL") == 0) { + xplanet = MARKER_CALLS; + } + g_free(type); + return PARSE_OK; } static int cfg_dx_n_sections(const cfg_arg_t arg) { - dx_arrlsections = true; - setcontest(whichcontest); - return PARSE_OK; + dx_arrlsections = true; + setcontest(whichcontest); + return PARSE_OK; } static int cfg_countrylist(const cfg_arg_t arg) { - char *buffer = NULL; - size_t buffer_len = 2000; - ssize_t read; - char *country_list_raw = NULL; // will point somewhere into buffer - FILE *fp; - - /* First of all we are checking if the parameter in - COUNTRYLIST= is a file name. If it is we start - parsing the file. If we find a line starting with our - case insensitive contest name, we copy the countries from - that line into country_list_raw. - If the input was not a file name we directly copy it into - country_list_raw (must not have a preceding contest name). */ - - buffer = (char *)calloc(buffer_len, sizeof(char)); - g_strlcpy(buffer, parameter, buffer_len); - g_strchomp(buffer); /* drop trailing whitespace */ - - - if ((fp = fopen(buffer, "r")) != NULL) { - char *prefix = g_strdup_printf("%s:", whichcontest); - - while ((read = getline(&buffer, &buffer_len, fp)) != -1) { - if (buffer_len > 0) { - g_strstrip(buffer); /* no leading/trailing whitespace*/ - - /* accept only a line starting with the contest name - * (CONTEST=) followed by ':' */ - if (strncasecmp(buffer, prefix, strlen(prefix)) == 0) { - country_list_raw = buffer + strlen(prefix); // skip prefix - break; - } - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } - - g_free(prefix); - fclose(fp); - - } else { /* not a file */ - if (buffer != NULL) { - char *colon = strchr(buffer, ':'); - if (colon != NULL) { - country_list_raw = colon + 1; // skip optional contest name - } else { - country_list_raw = buffer; - } - } - } - - if (country_list_raw == NULL) { - return PARSE_WRONG_PARAMETER; // e.g. in case of no match in file - } - - /* parse the country_list_raw string into an array - * (countrylist) for future use. */ - - char *tk_ptr = strtok(country_list_raw, ","); - int counter = 0; - - memset(countrylist, 0, sizeof(countrylist)); - - while (tk_ptr) { - char *prefix = g_strdup(tk_ptr); - g_strstrip(prefix); - if (strlen(prefix) >= sizeof(countrylist[0])) { - error_details = g_strdup_printf("prefix too long (%s)", prefix); - g_free(prefix); - return PARSE_WRONG_PARAMETER; - } - - strcpy(countrylist[counter], prefix); - g_free(prefix); - - tk_ptr = strtok(NULL, ","); - counter++; - - if (counter == G_N_ELEMENTS(countrylist)) { - error_details = g_strdup("too many prefixes"); - return PARSE_WRONG_PARAMETER; - } - } - - /* on which multiplier side of the rules we are */ - getpx(my.call); - mult_side = exist_in_country_list(); - setcontest(whichcontest); - free(buffer); - - return PARSE_OK; + char *buffer = NULL; + size_t buffer_len = 2000; + ssize_t read; + char *country_list_raw = NULL; // will point somewhere into buffer + FILE *fp; + + /* First of all we are checking if the parameter in + COUNTRYLIST= is a file name. If it is we start + parsing the file. If we find a line starting with our + case insensitive contest name, we copy the countries from + that line into country_list_raw. + If the input was not a file name we directly copy it into + country_list_raw (must not have a preceding contest name). */ + + buffer = (char *)calloc(buffer_len, sizeof(char)); + g_strlcpy(buffer, parameter, buffer_len); + g_strchomp(buffer); /* drop trailing whitespace */ + + printf("%s\n", buffer); + if ((fp = fopen(buffer, "r")) != NULL) { + char *prefix = g_strdup_printf("%s:", whichcontest); + + while ((read = getline(&buffer, &buffer_len, fp)) != -1) { + if (buffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d\n", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + g_strstrip(buffer); /* no leading/trailing whitespace*/ + + /* accept only a line starting with the contest name + * (CONTEST=) followed by ':' */ + if (strncasecmp(buffer, prefix, strlen(prefix)) == 0) { + country_list_raw = buffer + strlen(prefix); // skip prefix + break; + } + } + } + + g_free(prefix); + fclose(fp); + + } else { /* not a file */ + if (buffer != NULL) { + char *colon = strchr(buffer, ':'); + if (colon != NULL) { + country_list_raw = colon + 1; // skip optional contest name + } else { + country_list_raw = buffer; + } + } + } + + if (country_list_raw == NULL) { + return PARSE_WRONG_PARAMETER; // e.g. in case of no match in file + } + + /* parse the country_list_raw string into an array + * (countrylist) for future use. */ + + char *tk_ptr = strtok(country_list_raw, ","); + int counter = 0; + + memset(countrylist, 0, sizeof(countrylist)); + + while (tk_ptr) { + char *prefix = g_strdup(tk_ptr); + g_strstrip(prefix); + if (strlen(prefix) >= sizeof(countrylist[0])) { + error_details = g_strdup_printf("prefix too long (%s)", prefix); + g_free(prefix); + return PARSE_WRONG_PARAMETER; + } + + strcpy(countrylist[counter], prefix); + g_free(prefix); + + tk_ptr = strtok(NULL, ","); + counter++; + + if (counter == G_N_ELEMENTS(countrylist)) { + error_details = g_strdup("too many prefixes"); + return PARSE_WRONG_PARAMETER; + } + } + + /* on which multiplier side of the rules we are */ + getpx(my.call); + mult_side = exist_in_country_list(); + setcontest(whichcontest); + free(buffer); + + return PARSE_OK; } static int cfg_continentlist(const cfg_arg_t arg) { - char* buffer; - size_t buffer_len = 2000; - int read; - char *cont_multiplier_list = NULL; // will point somewhere into buffer - FILE *fp; - - /* - CONTINENTLIST (in file or listed in logcfg.dat) - First of all we are checking if inserted data in - CONTINENTLIST= is a file name. If it is we start - parsing the file. If we got our case insensitive contest name, - we copy the multipliers from it into multipliers_list. - If the input was not a file name we directly copy it into - cont_multiplier_list (must not have a preceding contest name). - The last step is to parse the multipliers_list into an array - (continent_multiplier_list) for future use. - */ - buffer = (char *)calloc(buffer_len, sizeof(char)); - g_strlcpy(buffer, parameter, buffer_len); - g_strchomp(buffer); /* drop trailing whitespace */ - - if ((fp = fopen(buffer, "r")) != NULL) { - char *prefix = g_strdup_printf("%s:", whichcontest); - while((read = getline(&buffer, &buffer_len, fp)) != -1) { - if (buffer_len > 0) { - g_strstrip(buffer); /* no leading/trailing whitespace*/ - /* accept only a line starting with the contest name - * (CONTEST=) followed by ':' */ - if (strncasecmp(buffer, prefix, strlen(prefix)) == 0) { - cont_multiplier_list = buffer + strlen(prefix); // skip prefix - break; - } - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } - - g_free(prefix); - fclose(fp); - } else { /* not a file */ - char *colon = index(buffer, ':'); - if (colon != NULL) { - cont_multiplier_list = colon + 1; // skip optional contest name - } else { - cont_multiplier_list = buffer; - } - } - - if (cont_multiplier_list == NULL) { - return PARSE_WRONG_PARAMETER; // e.g. in case of no match in file - } - - /* parse the cont_multiplier_list string into an array - * (continent_multiplier_list) for future use. */ - - char *tk_ptr = strtok(cont_multiplier_list, ","); - int counter = 0; - - memset(continent_multiplier_list, 0, sizeof(continent_multiplier_list)); - - while (tk_ptr) { - char *entry = g_strdup(tk_ptr); - g_strstrip(entry); - if (strlen(entry) >= sizeof(continent_multiplier_list[0])) { - error_details = g_strdup_printf("entry too long (%s)", entry); - g_free(entry); - return PARSE_WRONG_PARAMETER; - } - - strcpy(continent_multiplier_list[counter], entry); - g_free(entry); - - tk_ptr = strtok(NULL, ","); - counter++; - - if (counter == G_N_ELEMENTS(continent_multiplier_list)) { - error_details = g_strdup("too many continents"); - return PARSE_WRONG_PARAMETER; - } - } - - setcontest(whichcontest); - free(buffer); - return PARSE_OK; + char *buffer; + size_t buffer_len = 2000; + int read; + char *cont_multiplier_list = NULL; // will point somewhere into buffer + FILE *fp; + + /* + CONTINENTLIST (in file or listed in logcfg.dat) + First of all we are checking if inserted data in + CONTINENTLIST= is a file name. If it is we start + parsing the file. If we got our case insensitive contest name, + we copy the multipliers from it into multipliers_list. + If the input was not a file name we directly copy it into + cont_multiplier_list (must not have a preceding contest name). + The last step is to parse the multipliers_list into an array + (continent_multiplier_list) for future use. + */ + buffer = (char *)calloc(buffer_len, sizeof(char)); + g_strlcpy(buffer, parameter, buffer_len); + g_strchomp(buffer); /* drop trailing whitespace */ + + if ((fp = fopen(buffer, "r")) != NULL) { + char *prefix = g_strdup_printf("%s:", whichcontest); + while ((read = getline(&buffer, &buffer_len, fp)) != -1) { + if (buffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + g_strstrip(buffer); /* no leading/trailing whitespace*/ + /* accept only a line starting with the contest name + * (CONTEST=) followed by ':' */ + if (strncasecmp(buffer, prefix, strlen(prefix)) == 0) { + cont_multiplier_list = buffer + strlen(prefix); // skip prefix + break; + } + } + } + + g_free(prefix); + fclose(fp); + } else { /* not a file */ + char *colon = index(buffer, ':'); + if (colon != NULL) { + cont_multiplier_list = colon + 1; // skip optional contest name + } else { + cont_multiplier_list = buffer; + } + } + + if (cont_multiplier_list == NULL) { + return PARSE_WRONG_PARAMETER; // e.g. in case of no match in file + } + + /* parse the cont_multiplier_list string into an array + * (continent_multiplier_list) for future use. */ + + char *tk_ptr = strtok(cont_multiplier_list, ","); + int counter = 0; + + memset(continent_multiplier_list, 0, sizeof(continent_multiplier_list)); + + while (tk_ptr) { + char *entry = g_strdup(tk_ptr); + g_strstrip(entry); + if (strlen(entry) >= sizeof(continent_multiplier_list[0])) { + error_details = g_strdup_printf("entry too long (%s)", entry); + g_free(entry); + return PARSE_WRONG_PARAMETER; + } + + strcpy(continent_multiplier_list[counter], entry); + g_free(entry); + + tk_ptr = strtok(NULL, ","); + counter++; + + if (counter == G_N_ELEMENTS(continent_multiplier_list)) { + error_details = g_strdup("too many continents"); + return PARSE_WRONG_PARAMETER; + } + } + + setcontest(whichcontest); + free(buffer); + return PARSE_OK; } static int cfg_country_list_only(const cfg_arg_t arg) { - countrylist_only = true; - if (mult_side) { - countrylist_only = false; - } - return PARSE_OK; + countrylist_only = true; + if (mult_side) { + countrylist_only = false; + } + return PARSE_OK; } static int cfg_bandweight_points(const cfg_arg_t arg) { - static char bwp_params_list[50] = ""; - int bandindex = -1; + static char bwp_params_list[50] = ""; + int bandindex = -1; - if (strlen(bwp_params_list) == 0) { - g_strlcpy(bwp_params_list, parameter, sizeof(bwp_params_list)); - g_strchomp(bwp_params_list); - } + if (strlen(bwp_params_list) == 0) { + g_strlcpy(bwp_params_list, parameter, sizeof(bwp_params_list)); + g_strchomp(bwp_params_list); + } - char *tk_ptr = strtok(bwp_params_list, ";:,"); - if (tk_ptr != NULL) { - while (tk_ptr) { + char *tk_ptr = strtok(bwp_params_list, ";:,"); + if (tk_ptr != NULL) { + while (tk_ptr) { - bandindex = getidxbybandstr(g_strchomp(tk_ptr)); - tk_ptr = strtok(NULL, ";:,"); - if (tk_ptr != NULL && bandindex >= 0) { - bandweight_points[bandindex] = atoi(tk_ptr); - } - tk_ptr = strtok(NULL, ";:,"); + bandindex = getidxbybandstr(g_strchomp(tk_ptr)); + tk_ptr = strtok(NULL, ";:,"); + if (tk_ptr != NULL && bandindex >= 0) { + bandweight_points[bandindex] = atoi(tk_ptr); + } + tk_ptr = strtok(NULL, ";:,"); + } } - } - return PARSE_OK; + return PARSE_OK; } static int cfg_bandweight_multis(const cfg_arg_t arg) { - static char bwm_params_list[50] = ""; - int bandindex = -1; + static char bwm_params_list[50] = ""; + int bandindex = -1; - if (strlen(bwm_params_list) == 0) { - g_strlcpy(bwm_params_list, parameter, sizeof(bwm_params_list)); - g_strchomp(bwm_params_list); - } + if (strlen(bwm_params_list) == 0) { + g_strlcpy(bwm_params_list, parameter, sizeof(bwm_params_list)); + g_strchomp(bwm_params_list); + } - char *tk_ptr = strtok(bwm_params_list, ";:,"); - if (tk_ptr != NULL) { - while (tk_ptr) { + char *tk_ptr = strtok(bwm_params_list, ";:,"); + if (tk_ptr != NULL) { + while (tk_ptr) { - bandindex = getidxbybandstr(g_strchomp(tk_ptr)); - tk_ptr = strtok(NULL, ";:,"); - if (tk_ptr != NULL && bandindex >= 0) { - bandweight_multis[bandindex] = atoi(tk_ptr); - } - tk_ptr = strtok(NULL, ";:,"); + bandindex = getidxbybandstr(g_strchomp(tk_ptr)); + tk_ptr = strtok(NULL, ";:,"); + if (tk_ptr != NULL && bandindex >= 0) { + bandweight_multis[bandindex] = atoi(tk_ptr); + } + tk_ptr = strtok(NULL, ";:,"); + } } - } - return PARSE_OK; + return PARSE_OK; } static int cfg_pfx_num_multis(const cfg_arg_t arg) { - /* based on LZ3NY code, by HA2OS - PFX_NUM_MULTIS (in file or listed in logcfg.dat), - We directly copy it into pfxnummulti_str, then parse the prefixlist - and fill the pfxnummulti array. - */ - - int counter = 0; - int pfxnum; - static char pfxnummulti_str[50] = ""; - char parsepfx[15] = ""; - - g_strlcpy(pfxnummulti_str, parameter, sizeof(pfxnummulti_str)); - g_strchomp(pfxnummulti_str); - - /* creating the array */ - char *tk_ptr = strtok(pfxnummulti_str, ","); - counter = 0; - - if (tk_ptr != NULL) { - while (tk_ptr) { - parsepfx[0] = '\0'; - if (isdigit(tk_ptr[strlen(tk_ptr) - 1])) { - sprintf(parsepfx, "%sAA", tk_ptr); - } else { - sprintf(parsepfx, "%s0AA", tk_ptr); - } - pfxnummulti[counter].countrynr = getctydata(parsepfx); - for (pfxnum = 0; pfxnum < 10; pfxnum++) { - pfxnummulti[counter].qsos[pfxnum] = 0; - } - tk_ptr = strtok(NULL, ","); - counter++; - } - } - pfxnummultinr = counter; - setcontest(whichcontest); - return PARSE_OK; + /* based on LZ3NY code, by HA2OS + PFX_NUM_MULTIS (in file or listed in logcfg.dat), + We directly copy it into pfxnummulti_str, then parse the prefixlist + and fill the pfxnummulti array. + */ + + int counter = 0; + int pfxnum; + static char pfxnummulti_str[50] = ""; + char parsepfx[15] = ""; + + g_strlcpy(pfxnummulti_str, parameter, sizeof(pfxnummulti_str)); + g_strchomp(pfxnummulti_str); + + /* creating the array */ + char *tk_ptr = strtok(pfxnummulti_str, ","); + counter = 0; + + if (tk_ptr != NULL) { + while (tk_ptr) { + parsepfx[0] = '\0'; + if (isdigit(tk_ptr[strlen(tk_ptr) - 1])) { + sprintf(parsepfx, "%sAA", tk_ptr); + } else { + sprintf(parsepfx, "%s0AA", tk_ptr); + } + pfxnummulti[counter].countrynr = getctydata(parsepfx); + for (pfxnum = 0; pfxnum < 10; pfxnum++) { + pfxnummulti[counter].qsos[pfxnum] = 0; + } + tk_ptr = strtok(NULL, ","); + counter++; + } + } + pfxnummultinr = counter; + setcontest(whichcontest); + return PARSE_OK; } static int cfg_sc_volume(const cfg_arg_t arg) { - int value = 0; - int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 0, .max = 100}); - if (rc != PARSE_OK) { - return rc; - } - sprintf(sc_volume, "%d", value); - return PARSE_OK; + int value = 0; + int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 0, .max = 100}); + if (rc != PARSE_OK) { + return rc; + } + sprintf(sc_volume, "%d", value); + return PARSE_OK; } static int cfg_mfj1278_keyer(const cfg_arg_t arg) { - int rc = cfg_string((cfg_arg_t) { - .char_p = controllerport, .size = 80, .strip = true, .string_type = STATIC - }); - if (rc != PARSE_OK) { - return rc; - } - cwkeyer = MFJ1278_KEYER; - digikeyer = MFJ1278_KEYER; - return PARSE_OK; + int rc = cfg_string((cfg_arg_t) { + .char_p = controllerport, .size = 80, .strip = true, .string_type = STATIC + }); + if (rc != PARSE_OK) { + return rc; + } + cwkeyer = MFJ1278_KEYER; + digikeyer = MFJ1278_KEYER; + return PARSE_OK; } static int cfg_gmfsk(const cfg_arg_t arg) { - int rc = cfg_string((cfg_arg_t) { - .char_p = controllerport, .size = 80, .strip = true, .string_type = STATIC - }); - if (rc != PARSE_OK) { - return rc; - } - digikeyer = GMFSK; - return PARSE_OK; + int rc = cfg_string((cfg_arg_t) { + .char_p = controllerport, .size = 80, .strip = true, .string_type = STATIC + }); + if (rc != PARSE_OK) { + return rc; + } + digikeyer = GMFSK; + return PARSE_OK; } static int cfg_change_rst(const cfg_arg_t arg) { - change_rst = true; - if (parameter == NULL) { - rst_init(NULL); - return PARSE_OK; - } - char *str = g_strdup(parameter); - g_strstrip(str); - /* comma separated list of RS(T) values 33..39, 43..39, 53..59 allowed. */ - if (!g_regex_match_simple("^([3-5][3-9]\\d?\\s*,\\s*)*[3-5][3-9]\\d?$", - str, G_REGEX_CASELESS, (GRegexMatchFlags)0)) { - g_free(str); - error_details = g_strdup("must be a comma separated list of RS(T) values"); - return PARSE_WRONG_PARAMETER; - } + change_rst = true; + if (parameter == NULL) { + rst_init(NULL); + return PARSE_OK; + } + char *str = g_strdup(parameter); + g_strstrip(str); + /* comma separated list of RS(T) values 33..39, 43..39, 53..59 allowed. */ + if (!g_regex_match_simple("^([3-5][3-9]\\d?\\s*,\\s*)*[3-5][3-9]\\d?$", + str, G_REGEX_CASELESS, (GRegexMatchFlags)0)) { + g_free(str); + error_details = g_strdup("must be a comma separated list of RS(T) values"); + return PARSE_WRONG_PARAMETER; + } - rst_init(str); + rst_init(str); - g_free(str); - return PARSE_OK; + g_free(str); + return PARSE_OK; } static int cfg_rttymode(const cfg_arg_t arg) { - trxmode = DIGIMODE; - strcpy(modem_mode, "RTTY"); - return PARSE_OK; + trxmode = DIGIMODE; + strcpy(modem_mode, "RTTY"); + return PARSE_OK; } static int cfg_myqra(const cfg_arg_t arg) { - strcpy(my.qra, parameter); + strcpy(my.qra, parameter); - if (check_qra(my.qra) == 0) { - return PARSE_WRONG_PARAMETER; - } + if (check_qra(my.qra) == 0) { + return PARSE_WRONG_PARAMETER; + } - return PARSE_OK; + return PARSE_OK; } static int cfg_powermult(const cfg_arg_t arg) { - if (fixedmult == 0.0 && atof(parameter) > 0.0) { - fixedmult = atof(parameter); - } + if (fixedmult == 0.0 && atof(parameter) > 0.0) { + fixedmult = atof(parameter); + } - return PARSE_OK; + return PARSE_OK; } static int cfg_qtc(const cfg_arg_t arg) { - char *str = g_ascii_strup(parameter, -1); - g_strstrip(str); + char *str = g_ascii_strup(parameter, -1); + g_strstrip(str); - int rc = PARSE_OK; + int rc = PARSE_OK; - if (strcmp(str, "RECV") == 0) { - qtcdirection = RECV; - } else if (strcmp(str, "SEND") == 0) { - qtcdirection = SEND; - } else if (strcmp(str, "BOTH") == 0) { - qtcdirection = RECV | SEND; - } else { - error_details = g_strdup("must be RECV, SEND, or BOTH"); - rc = PARSE_WRONG_PARAMETER; - } + if (strcmp(str, "RECV") == 0) { + qtcdirection = RECV; + } else if (strcmp(str, "SEND") == 0) { + qtcdirection = SEND; + } else if (strcmp(str, "BOTH") == 0) { + qtcdirection = RECV | SEND; + } else { + error_details = g_strdup("must be RECV, SEND, or BOTH"); + rc = PARSE_WRONG_PARAMETER; + } - g_free(str); - return rc; + g_free(str); + return rc; } static int cfg_qtcrec_record_command(const cfg_arg_t arg) { - int p, q = 0, i = 0, s = 0; - for (p = 0; p < strlen(parameter); p++) { - if (p > 0 && parameter[p] == ' ') { - s = 1; - qtcrec_record_command_shutdown[p] = '\0'; - } - if (s == 0) { - qtcrec_record_command_shutdown[p] = parameter[p]; - } - if (parameter[p] == '$') { - qtcrec_record_command[i][q] = '\0'; - i = 1; - p++; - q = 0; - } - if (parameter[p] != '\n') { - qtcrec_record_command[i][q] = parameter[p]; + int p, q = 0, i = 0, s = 0; + for (p = 0; p < strlen(parameter); p++) { + if (p > 0 && parameter[p] == ' ') { + s = 1; + qtcrec_record_command_shutdown[p] = '\0'; + } + if (s == 0) { + qtcrec_record_command_shutdown[p] = parameter[p]; + } + if (parameter[p] == '$') { + qtcrec_record_command[i][q] = '\0'; + i = 1; + p++; + q = 0; + } + if (parameter[p] != '\n') { + qtcrec_record_command[i][q] = parameter[p]; + } + q++; + qtcrec_record_command[i][q] = ' '; } - q++; - qtcrec_record_command[i][q] = ' '; - } - if (qtcrec_record_command[i][q - 1] != '&') { - qtcrec_record_command[i][q++] = ' '; - qtcrec_record_command[i][q++] = '&'; - } - qtcrec_record_command[i][q] = '\0'; + if (qtcrec_record_command[i][q - 1] != '&') { + qtcrec_record_command[i][q++] = ' '; + qtcrec_record_command[i][q++] = '&'; + } + qtcrec_record_command[i][q] = '\0'; - return PARSE_OK; + return PARSE_OK; } static int cfg_exclude_multilist(const cfg_arg_t arg) { - char *str = g_ascii_strup(parameter, -1); - g_strstrip(str); + char *str = g_ascii_strup(parameter, -1); + g_strstrip(str); - if (strcmp(str, "CONTINENTLIST") == 0) { - g_free(str); - if (strlen(continent_multiplier_list[0]) == 0) { - error_details = g_strdup("need to set the CONTINENTLIST first"); - return PARSE_WRONG_PARAMETER; - } - exclude_multilist_type = EXCLUDE_CONTINENT; - } else if (strcmp(str, "COUNTRYLIST") == 0) { - g_free(str); - if (strlen(countrylist[0]) == 0) { - error_details = g_strdup("need to set the COUNTRYLIST first"); - return PARSE_WRONG_PARAMETER; + if (strcmp(str, "CONTINENTLIST") == 0) { + g_free(str); + if (strlen(continent_multiplier_list[0]) == 0) { + error_details = g_strdup("need to set the CONTINENTLIST first"); + return PARSE_WRONG_PARAMETER; + } + exclude_multilist_type = EXCLUDE_CONTINENT; + } else if (strcmp(str, "COUNTRYLIST") == 0) { + g_free(str); + if (strlen(countrylist[0]) == 0) { + error_details = g_strdup("need to set the COUNTRYLIST first"); + return PARSE_WRONG_PARAMETER; + } + exclude_multilist_type = EXCLUDE_COUNTRY; + } else { + g_free(str); + error_details = g_strdup("must be CONTINENTLIST or COUNTRYLIST"); + return PARSE_WRONG_PARAMETER; } - exclude_multilist_type = EXCLUDE_COUNTRY; - } else { - g_free(str); - error_details = g_strdup("must be CONTINENTLIST or COUNTRYLIST"); - return PARSE_WRONG_PARAMETER; - } - return PARSE_OK; + return PARSE_OK; } static int cfg_fldigi(const cfg_arg_t arg) { #ifndef HAVE_LIBXMLRPC - showmsg("WARNING: XMLRPC not compiled - skipping setup."); - sleep(2); - digikeyer = NO_KEYER; + showmsg("WARNING: XMLRPC not compiled - skipping setup."); + sleep(2); + digikeyer = NO_KEYER; #else - if (parameter != NULL) { - int rc = cfg_string((cfg_arg_t) { - .char_p = fldigi_url, .size = sizeof(fldigi_url), .strip = true, - .string_type = STATIC - }); - if (rc != PARSE_OK) { - return rc; + if (parameter != NULL) { + int rc = cfg_string((cfg_arg_t) { + .char_p = fldigi_url, .size = sizeof(fldigi_url), .strip = true, + .string_type = STATIC + }); + if (rc != PARSE_OK) { + return rc; + } } - } - digikeyer = FLDIGI; - if (!fldigi_isenabled()) { - fldigi_toggle(); - } + digikeyer = FLDIGI; + if (!fldigi_isenabled()) { + fldigi_toggle(); + } #endif - return PARSE_OK; + return PARSE_OK; } static int cfg_minitest(const cfg_arg_t arg) { - if (parameter == NULL) { - minitest = MINITEST_DEFAULT_PERIOD; - return PARSE_OK; - } + if (parameter == NULL) { + minitest = MINITEST_DEFAULT_PERIOD; + return PARSE_OK; + } - int value = 1; /* avoid warning about divide by zero */ - int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 60, .max = 1800}); - if (rc != PARSE_OK) { - return rc; - } + int value = 1; /* avoid warning about divide by zero */ + int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 60, .max = 1800}); + if (rc != PARSE_OK) { + return rc; + } - if ((3600 % value) != 0) { - error_details = g_strdup("must be an integral divider of 3600 seconds"); - return PARSE_WRONG_PARAMETER; - } + if ((3600 % value) != 0) { + error_details = g_strdup("must be an integral divider of 3600 seconds"); + return PARSE_WRONG_PARAMETER; + } - minitest = value; + minitest = value; - return PARSE_OK; + return PARSE_OK; } static int set_multi_mode(const cfg_arg_t arg, int *config) { - char *str = g_ascii_strup(parameter, -1); - g_strstrip(str); - - if (strcmp(str, "ALL") == 0) { - *config = MULT_ALL; - } else if (strcmp(str, "BAND") == 0) { - *config = MULT_BAND; - } else if (strcmp(str, "NONE") == 0) { - *config = MULT_NONE; - } else { - g_free(str); - error_details = g_strdup("must be ALL, BAND or NONE"); - return PARSE_WRONG_PARAMETER; - } + char *str = g_ascii_strup(parameter, -1); + g_strstrip(str); - g_free(str); - return PARSE_OK; + if (strcmp(str, "ALL") == 0) { + *config = MULT_ALL; + } else if (strcmp(str, "BAND") == 0) { + *config = MULT_BAND; + } else if (strcmp(str, "NONE") == 0) { + *config = MULT_NONE; + } else { + g_free(str); + error_details = g_strdup("must be ALL, BAND or NONE"); + return PARSE_WRONG_PARAMETER; + } + + g_free(str); + return PARSE_OK; } static int cfg_unique_call_multi(const cfg_arg_t arg) { - return set_multi_mode(arg, &unique_call_multi); + return set_multi_mode(arg, &unique_call_multi); } static int cfg_generic_mult(const cfg_arg_t arg) { - return set_multi_mode(arg, &generic_mult); + return set_multi_mode(arg, &generic_mult); } static int cfg_digi_rig_mode(const cfg_arg_t arg) { - char *str = g_ascii_strup(parameter, -1); - g_strstrip(str); - - if (strcmp(str, "USB") == 0) { - digi_mode = RIG_MODE_USB; - } else if (strcmp(str, "LSB") == 0) { - digi_mode = RIG_MODE_LSB; - } else if (strcmp(str, "RTTY") == 0) { - digi_mode = RIG_MODE_RTTY; - } else if (strcmp(str, "RTTYR") == 0) { - digi_mode = RIG_MODE_RTTYR; - } else { - g_free(str); - error_details = g_strdup("must be USB, LSB, RTTY, or RTTYR"); - return PARSE_WRONG_PARAMETER; - } + char *str = g_ascii_strup(parameter, -1); + g_strstrip(str); - g_free(str); - return PARSE_OK; + if (strcmp(str, "USB") == 0) { + digi_mode = RIG_MODE_USB; + } else if (strcmp(str, "LSB") == 0) { + digi_mode = RIG_MODE_LSB; + } else if (strcmp(str, "RTTY") == 0) { + digi_mode = RIG_MODE_RTTY; + } else if (strcmp(str, "RTTYR") == 0) { + digi_mode = RIG_MODE_RTTYR; + } else { + g_free(str); + error_details = g_strdup("must be USB, LSB, RTTY, or RTTYR"); + return PARSE_WRONG_PARAMETER; + } + + g_free(str); + return PARSE_OK; } static int cfg_cabrillo_field(const cfg_arg_t arg) { - char *str = NULL; - if (parameter != NULL) { - str = g_strdup(parameter); - g_strstrip(str); - } - gchar *name = g_match_info_fetch(match_info, 1); + char *str = NULL; + if (parameter != NULL) { + str = g_strdup(parameter); + g_strstrip(str); + } + gchar *name = g_match_info_fetch(match_info, 1); - int rc = add_cabrillo_field(name, str); + int rc = add_cabrillo_field(name, str); - FREE_DYNAMIC_STRING(name); - FREE_DYNAMIC_STRING(str); - return rc; + FREE_DYNAMIC_STRING(name); + FREE_DYNAMIC_STRING(str); + return rc; } static int cfg_resend_call(const cfg_arg_t arg) { - char *str = g_ascii_strup(parameter, -1); - g_strstrip(str); - - if (strcmp(str, "PARTIAL") == 0) { - resend_call = RESEND_PARTIAL; - } else if (strcmp(str, "FULL") == 0) { - resend_call = RESEND_FULL; - } else { - g_free(str); - error_details = g_strdup("must be FULL or PARTIAL"); - return PARSE_WRONG_PARAMETER; - } + char *str = g_ascii_strup(parameter, -1); + g_strstrip(str); + + if (strcmp(str, "PARTIAL") == 0) { + resend_call = RESEND_PARTIAL; + } else if (strcmp(str, "FULL") == 0) { + resend_call = RESEND_FULL; + } else { + g_free(str); + error_details = g_strdup("must be FULL or PARTIAL"); + return PARSE_WRONG_PARAMETER; + } - g_free(str); - return PARSE_OK; + g_free(str); + return PARSE_OK; } static config_t logcfg_configs[] = { - {"CONTEST_MODE", CFG_BOOL(iscontest)}, - {"MIXED", CFG_BOOL(mixedmode)}, - {"IGNOREDUPE", CFG_BOOL(ignoredupe)}, - {"USE_CONTINENTLIST_ONLY", CFG_BOOL(continentlist_only)}, - {"RADIO_CONTROL", CFG_BOOL(trx_control)}, - {"PORTABLE_MULT_2", CFG_BOOL(portable_x2)}, - - {"USEPARTIALS", CFG_BOOL(use_part)}, - {"PARTIALS", CFG_BOOL(partials)}, - {"RECALL_MULTS", CFG_CONTEST_BOOL(recall_mult)}, - {"WYSIWYG_MULTIBAND", CFG_BOOL(wysiwyg_multi)}, - {"WYSIWYG_ONCE", CFG_BOOL(wysiwyg_once)}, - {"RIT_CLEAR", CFG_BOOL(rit)}, - {"SHORT_SERIAL", CFG_INT_ONE(shortqsonr)}, - {"LEADING_ZEROS_SERIAL", CFG_BOOL(leading_zeros_serial)}, - {"SCOREWINDOW", CFG_BOOL(showscore_flag)}, - {"CHECKWINDOW", CFG_BOOL(searchflg)}, - {"SEND_DE", CFG_BOOL(demode)}, - {"SERIAL_EXCHANGE", CFG_CONTEST_BOOL(exchange_serial)}, - {"COUNTRY_MULT", CFG_BOOL(country_mult)}, - {"CQWW_M2", CFG_BOOL(cqwwm2)}, - {"LAN_DEBUG", CFG_BOOL(landebug)}, - {"CALLUPDATE", CFG_BOOL(call_update)}, - {"TIME_MASTER", CFG_BOOL(time_master)}, - {"CTCOMPATIBLE", CFG_BOOL(ctcomp)}, - {"SERIAL\\+SECTION", CFG_BOOL(serial_section_mult)}, - {"SECTION_MULT", CFG_BOOL(sectn_mult)}, - {"NOB4", CFG_BOOL(nob4)}, - {"SHOW_TIME", CFG_BOOL(show_time)}, - {"RXVT", CFG_BOOL(use_rxvt)}, - {"WAZMULT", CFG_BOOL(wazmult)}, - {"ITUMULT", CFG_BOOL(itumult)}, - {"CONTINENT_EXCHANGE", CFG_BOOL(exc_cont)}, - {"NOAUTOCQ", CFG_BOOL(noautocq)}, - {"NO_BANDSWITCH_ARROWKEYS", CFG_BOOL(no_arrows)}, - {"SOUNDCARD", CFG_BOOL(sc_sidetone)}, - {"LOWBAND_DOUBLE", CFG_BOOL(lowband_point_mult)}, - {"CLUSTER_LOG", CFG_BOOL(clusterlog)}, - {"SERIAL\\+GRID4", CFG_BOOL(serial_grid4_mult)}, - {"LOGFREQUENCY", CFG_BOOL(logfrequency)}, - {"NO_RST", CFG_BOOL(no_rst)}, - {"SERIAL_OR_SECTION", CFG_BOOL(serial_or_section)}, - {"PFX_MULT", CFG_BOOL(pfxmult)}, - {"PFX_MULT_MULTIBAND", CFG_BOOL(pfxmultab)}, - {"QTCREC_RECORD", CFG_BOOL(qtcrec_record)}, - {"QTC_AUTO_FILLTIME", CFG_BOOL(qtc_auto_filltime)}, - {"QTC_RECV_LAZY", CFG_BOOL(qtc_recv_lazy)}, - {"BMAUTOGRAB", CFG_BOOL(bmautograb)}, - {"BMAUTOADD", CFG_BOOL(bmautoadd)}, - {"SPRINTMODE", CFG_BOOL(sprint_mode)}, - {"KEYER_BACKSPACE", CFG_BOOL(keyer_backspace)}, - {"SECTION_MULT_ONCE", CFG_BOOL(sectn_mult_once)}, - {"ESC_STOPS_TX_ONLY", CFG_BOOL(stop_tx_only)}, - - {"F([1-9]|1[0-2])", CFG_MESSAGE(message, -1)}, // index is 1-based - {"S&P_TU_MSG", CFG_MESSAGE(message, SP_TU_MSG)}, - {"CQ_TU_MSG", CFG_MESSAGE(message, CQ_TU_MSG)}, - {"ALT_([0-9])", CFG_MESSAGE(message, CQ_TU_MSG + 1)}, - {"S&P_CALL_MSG", CFG_MESSAGE(message, SP_CALL_MSG)}, - - {"VKM([1-9]|1[0-2])", CFG_MESSAGE(ph_message, -1)}, - {"VKCQM", CFG_MESSAGE(ph_message, CQ_TU_MSG)}, - {"VKSPM", CFG_MESSAGE(ph_message, SP_TU_MSG)}, - - {"DKF([1-9]|1[0-2])", CFG_MESSAGE_DYNAMIC(digi_message, -1)}, - {"DKCQM", CFG_MESSAGE_DYNAMIC(digi_message, CQ_TU_MSG)}, - {"DKSPM", CFG_MESSAGE_DYNAMIC(digi_message, SP_TU_MSG)}, - {"DKSPC", CFG_MESSAGE_DYNAMIC(digi_message, SP_CALL_MSG)}, - {"ALT_DK([1-9]|10)", CFG_MESSAGE_DYNAMIC(digi_message, CQ_TU_MSG)}, - - {"QR_F([1-9]|1[0-2])", CFG_MESSAGE(qtc_recv_msgs, -1) }, - {"QR_VKM([1-9]|1[0-2])", CFG_MESSAGE(qtc_phrecv_message, -1) }, - {"QR_VKCQM", CFG_MESSAGE(qtc_phrecv_message, CQ_TU_MSG) }, - {"QR_VKSPM", CFG_MESSAGE(qtc_phrecv_message, SP_TU_MSG) }, - - {"QS_F([1-9]|1[0-2])", CFG_MESSAGE(qtc_send_msgs, -1) }, - {"QS_VKM([1-9]|1[0-2])", CFG_MESSAGE(qtc_phsend_message, -1) }, - {"QS_VKCQM", CFG_MESSAGE(qtc_phsend_message, CQ_TU_MSG) }, - {"QS_VKSPM", CFG_MESSAGE(qtc_phsend_message, SP_TU_MSG) }, - - {"TLFCOLOR([1-6])", NEED_PARAM, cfg_tlfcolor}, - {"BAND_([0-9]+)", NEED_PARAM, cfg_band}, - - {"LAN_PORT", CFG_INT(lan_port, 1000, INT32_MAX)}, - {"TIME_OFFSET", CFG_INT(timeoffset, -23, 23)}, - {"NETKEYERPORT", CFG_INT(netkeyer_port, 1, INT32_MAX)}, - {"TNCSPEED", CFG_INT(tnc_serial_rate, 0, INT32_MAX)}, - {"RIGSPEED", CFG_INT(serial_rate, 0, INT32_MAX)}, - {"CQDELAY", CFG_INT(cqdelay, 3, 60)}, - {"SSBPOINTS", CFG_INT(ssbpoints, 0, INT32_MAX)}, - {"CWPOINTS", CFG_INT(cwpoints, 0, INT32_MAX)}, - {"WEIGHT", CFG_INT(weight, -50, 50)}, - {"TXDELAY", CFG_INT(txdelay, 0, 50)}, - {"TUNE_SECONDS", CFG_INT(tune_seconds, 1, 100)}, - {"RIGMODEL", CFG_INT(myrig_model, 0, 99999)}, - {"COUNTRY_LIST_POINTS", CFG_INT(countrylist_points, 0, INT32_MAX)}, - {"MY_COUNTRY_POINTS", CFG_INT(my_country_points, 0, INT32_MAX)}, - {"MY_CONTINENT_POINTS", CFG_INT(my_cont_points, 0, INT32_MAX)}, - {"DX_POINTS", CFG_INT(dx_cont_points, 0, INT32_MAX)}, - {"CWBANDWIDTH", CFG_INT(cw_bandwidth, 0, INT32_MAX)}, - {"CONTINENT_LIST_POINTS", CFG_INT(continentlist_points, 0, INT32_MAX)}, - - {"NETKEYER", CFG_INT_CONST(cwkeyer, NET_KEYER)}, - {"HAMLIB_KEYER", CFG_INT_CONST(cwkeyer, HAMLIB_KEYER)}, - {"FIFO_INTERFACE", CFG_INT_CONST(packetinterface, FIFO_INTERFACE)}, - {"LONG_SERIAL", CFG_INT_CONST(shortqsonr, 0)}, - {"CLUSTER", CFG_INT_CONST(cluster, CLUSTER)}, - {"SSBMODE", CFG_INT_CONST(trxmode, SSBMODE)}, - {"RIGPTT", CFG_INT_CONST(rigptt, CAT_PTT_WANTED)}, - - {"RIGCONF", CFG_STRING_STATIC(rigconf, 80)}, - {"LOGFILE", CFG_STRING_STATIC(logfile, 120)}, - {"KEYER_DEVICE", CFG_STRING_STATIC(keyer_device, 10)}, - {"NETKEYERHOST", CFG_STRING_STATIC(netkeyer_hostaddress, 16)}, - {"TELNETHOST", CFG_STRING_STATIC(pr_hostaddress, 48)}, - {"QTC_CAP_CALLS", CFG_STRING_STATIC(qtc_cap_calls, 40)}, - {"SYNCFILE", CFG_STRING_STATIC(synclogfile, 120)}, - {"INITIAL_EXCHANGE", CFG_STRING_STATIC(exchange_list, 40)}, - {"DIGIMODEM", CFG_STRING_STATIC(rttyoutput, 120)}, - {"FKEY-HEADER", CFG_STRING_STATIC(fkey_header, sizeof(fkey_header))}, - - {"CABRILLO", CFG_STRING(cabrillo)}, - {"CALLMASTER", CFG_STRING(callmaster_filename)}, - {"EDITOR", CFG_STRING(editor_cmd)}, - {"VK_PLAY_COMMAND", CFG_STRING(vk_play_cmd)}, - {"VK_RECORD_COMMAND", CFG_STRING(vk_record_cmd)}, - {"SOUNDLOG_PLAY_COMMAND", CFG_STRING(soundlog_play_cmd)}, - {"SOUNDLOG_RECORD_COMMAND", CFG_STRING(soundlog_record_cmd)}, - {"SOUNDLOG_DIRECTORY", CFG_STRING(soundlog_dir)}, + {"CONTEST_MODE", CFG_BOOL(iscontest)}, + {"MIXED", CFG_BOOL(mixedmode)}, + {"IGNOREDUPE", CFG_BOOL(ignoredupe)}, + {"USE_CONTINENTLIST_ONLY", CFG_BOOL(continentlist_only)}, + {"RADIO_CONTROL", CFG_BOOL(trx_control)}, + {"PORTABLE_MULT_2", CFG_BOOL(portable_x2)}, + + {"USEPARTIALS", CFG_BOOL(use_part)}, + {"PARTIALS", CFG_BOOL(partials)}, + {"RECALL_MULTS", CFG_CONTEST_BOOL(recall_mult)}, + {"WYSIWYG_MULTIBAND", CFG_BOOL(wysiwyg_multi)}, + {"WYSIWYG_ONCE", CFG_BOOL(wysiwyg_once)}, + {"RIT_CLEAR", CFG_BOOL(rit)}, + {"SHORT_SERIAL", CFG_INT_ONE(shortqsonr)}, + {"LEADING_ZEROS_SERIAL", CFG_BOOL(leading_zeros_serial)}, + {"SCOREWINDOW", CFG_BOOL(showscore_flag)}, + {"CHECKWINDOW", CFG_BOOL(searchflg)}, + {"SEND_DE", CFG_BOOL(demode)}, + {"SERIAL_EXCHANGE", CFG_CONTEST_BOOL(exchange_serial)}, + {"COUNTRY_MULT", CFG_BOOL(country_mult)}, + {"CQWW_M2", CFG_BOOL(cqwwm2)}, + {"LAN_DEBUG", CFG_BOOL(landebug)}, + {"CALLUPDATE", CFG_BOOL(call_update)}, + {"TIME_MASTER", CFG_BOOL(time_master)}, + {"CTCOMPATIBLE", CFG_BOOL(ctcomp)}, + {"SERIAL\\+SECTION", CFG_BOOL(serial_section_mult)}, + {"SECTION_MULT", CFG_BOOL(sectn_mult)}, + {"NOB4", CFG_BOOL(nob4)}, + {"SHOW_TIME", CFG_BOOL(show_time)}, + {"RXVT", CFG_BOOL(use_rxvt)}, + {"WAZMULT", CFG_BOOL(wazmult)}, + {"ITUMULT", CFG_BOOL(itumult)}, + {"CONTINENT_EXCHANGE", CFG_BOOL(exc_cont)}, + {"NOAUTOCQ", CFG_BOOL(noautocq)}, + {"NO_BANDSWITCH_ARROWKEYS", CFG_BOOL(no_arrows)}, + {"SOUNDCARD", CFG_BOOL(sc_sidetone)}, + {"LOWBAND_DOUBLE", CFG_BOOL(lowband_point_mult)}, + {"CLUSTER_LOG", CFG_BOOL(clusterlog)}, + {"SERIAL\\+GRID4", CFG_BOOL(serial_grid4_mult)}, + {"LOGFREQUENCY", CFG_BOOL(logfrequency)}, + {"NO_RST", CFG_BOOL(no_rst)}, + {"SERIAL_OR_SECTION", CFG_BOOL(serial_or_section)}, + {"PFX_MULT", CFG_BOOL(pfxmult)}, + {"PFX_MULT_MULTIBAND", CFG_BOOL(pfxmultab)}, + {"QTCREC_RECORD", CFG_BOOL(qtcrec_record)}, + {"QTC_AUTO_FILLTIME", CFG_BOOL(qtc_auto_filltime)}, + {"QTC_RECV_LAZY", CFG_BOOL(qtc_recv_lazy)}, + {"BMAUTOGRAB", CFG_BOOL(bmautograb)}, + {"BMAUTOADD", CFG_BOOL(bmautoadd)}, + {"SPRINTMODE", CFG_BOOL(sprint_mode)}, + {"KEYER_BACKSPACE", CFG_BOOL(keyer_backspace)}, + {"SECTION_MULT_ONCE", CFG_BOOL(sectn_mult_once)}, + {"ESC_STOPS_TX_ONLY", CFG_BOOL(stop_tx_only)}, + + {"F([1-9]|1[0-2])", CFG_MESSAGE(message, -1)}, // index is 1-based + {"S&P_TU_MSG", CFG_MESSAGE(message, SP_TU_MSG)}, + {"CQ_TU_MSG", CFG_MESSAGE(message, CQ_TU_MSG)}, + {"ALT_([0-9])", CFG_MESSAGE(message, CQ_TU_MSG + 1)}, + {"S&P_CALL_MSG", CFG_MESSAGE(message, SP_CALL_MSG)}, + + {"VKM([1-9]|1[0-2])", CFG_MESSAGE(ph_message, -1)}, + {"VKCQM", CFG_MESSAGE(ph_message, CQ_TU_MSG)}, + {"VKSPM", CFG_MESSAGE(ph_message, SP_TU_MSG)}, + + {"DKF([1-9]|1[0-2])", CFG_MESSAGE_DYNAMIC(digi_message, -1)}, + {"DKCQM", CFG_MESSAGE_DYNAMIC(digi_message, CQ_TU_MSG)}, + {"DKSPM", CFG_MESSAGE_DYNAMIC(digi_message, SP_TU_MSG)}, + {"DKSPC", CFG_MESSAGE_DYNAMIC(digi_message, SP_CALL_MSG)}, + {"ALT_DK([1-9]|10)", CFG_MESSAGE_DYNAMIC(digi_message, CQ_TU_MSG)}, + + {"QR_F([1-9]|1[0-2])", CFG_MESSAGE(qtc_recv_msgs, -1) }, + {"QR_VKM([1-9]|1[0-2])", CFG_MESSAGE(qtc_phrecv_message, -1) }, + {"QR_VKCQM", CFG_MESSAGE(qtc_phrecv_message, CQ_TU_MSG) }, + {"QR_VKSPM", CFG_MESSAGE(qtc_phrecv_message, SP_TU_MSG) }, + + {"QS_F([1-9]|1[0-2])", CFG_MESSAGE(qtc_send_msgs, -1) }, + {"QS_VKM([1-9]|1[0-2])", CFG_MESSAGE(qtc_phsend_message, -1) }, + {"QS_VKCQM", CFG_MESSAGE(qtc_phsend_message, CQ_TU_MSG) }, + {"QS_VKSPM", CFG_MESSAGE(qtc_phsend_message, SP_TU_MSG) }, + + {"TLFCOLOR([1-6])", NEED_PARAM, cfg_tlfcolor}, + {"BAND_([0-9]+)", NEED_PARAM, cfg_band}, + + {"LAN_PORT", CFG_INT(lan_port, 1000, INT32_MAX)}, + {"TIME_OFFSET", CFG_INT(timeoffset, -23, 23)}, + {"NETKEYERPORT", CFG_INT(netkeyer_port, 1, INT32_MAX)}, + {"TNCSPEED", CFG_INT(tnc_serial_rate, 0, INT32_MAX)}, + {"RIGSPEED", CFG_INT(serial_rate, 0, INT32_MAX)}, + {"CQDELAY", CFG_INT(cqdelay, 3, 60)}, + {"SSBPOINTS", CFG_INT(ssbpoints, 0, INT32_MAX)}, + {"CWPOINTS", CFG_INT(cwpoints, 0, INT32_MAX)}, + {"WEIGHT", CFG_INT(weight, -50, 50)}, + {"TXDELAY", CFG_INT(txdelay, 0, 50)}, + {"TUNE_SECONDS", CFG_INT(tune_seconds, 1, 100)}, + {"RIGMODEL", CFG_INT(myrig_model, 0, 99999)}, + {"COUNTRY_LIST_POINTS", CFG_INT(countrylist_points, 0, INT32_MAX)}, + {"MY_COUNTRY_POINTS", CFG_INT(my_country_points, 0, INT32_MAX)}, + {"MY_CONTINENT_POINTS", CFG_INT(my_cont_points, 0, INT32_MAX)}, + {"DX_POINTS", CFG_INT(dx_cont_points, 0, INT32_MAX)}, + {"CWBANDWIDTH", CFG_INT(cw_bandwidth, 0, INT32_MAX)}, + {"CONTINENT_LIST_POINTS", CFG_INT(continentlist_points, 0, INT32_MAX)}, + + {"NETKEYER", CFG_INT_CONST(cwkeyer, NET_KEYER)}, + {"HAMLIB_KEYER", CFG_INT_CONST(cwkeyer, HAMLIB_KEYER)}, + {"FIFO_INTERFACE", CFG_INT_CONST(packetinterface, FIFO_INTERFACE)}, + {"LONG_SERIAL", CFG_INT_CONST(shortqsonr, 0)}, + {"CLUSTER", CFG_INT_CONST(cluster, CLUSTER)}, + {"SSBMODE", CFG_INT_CONST(trxmode, SSBMODE)}, + {"RIGPTT", CFG_INT_CONST(rigptt, CAT_PTT_WANTED)}, + + {"RIGCONF", CFG_STRING_STATIC(rigconf, 80)}, + {"LOGFILE", CFG_STRING_STATIC(logfile, 120)}, + {"KEYER_DEVICE", CFG_STRING_STATIC(keyer_device, 10)}, + {"NETKEYERHOST", CFG_STRING_STATIC(netkeyer_hostaddress, 16)}, + {"TELNETHOST", CFG_STRING_STATIC(pr_hostaddress, 48)}, + {"QTC_CAP_CALLS", CFG_STRING_STATIC(qtc_cap_calls, 40)}, + {"SYNCFILE", CFG_STRING_STATIC(synclogfile, 120)}, + {"INITIAL_EXCHANGE", CFG_STRING_STATIC(exchange_list, 40)}, + {"DIGIMODEM", CFG_STRING_STATIC(rttyoutput, 120)}, + {"FKEY-HEADER", CFG_STRING_STATIC(fkey_header, sizeof(fkey_header))}, + + {"CABRILLO", CFG_STRING(cabrillo)}, + {"CALLMASTER", CFG_STRING(callmaster_filename)}, + {"EDITOR", CFG_STRING(editor_cmd)}, + {"VK_PLAY_COMMAND", CFG_STRING(vk_play_cmd)}, + {"VK_RECORD_COMMAND", CFG_STRING(vk_record_cmd)}, + {"SOUNDLOG_PLAY_COMMAND", CFG_STRING(soundlog_play_cmd)}, + {"SOUNDLOG_RECORD_COMMAND", CFG_STRING(soundlog_record_cmd)}, + {"SOUNDLOG_DIRECTORY", CFG_STRING(soundlog_dir)}, #ifdef HAVE_PYTHON - {"PLUGIN_CONFIG", CFG_STRING(plugin_config)}, + {"PLUGIN_CONFIG", CFG_STRING(plugin_config)}, #endif - {"RIGPORT", CFG_STRING_NOCHOMP(rigportname)}, - {"CLUSTERLOGIN", CFG_STRING_STATIC_NOCHOMP(clusterlogin, 80)}, - - {"CALL", NEED_PARAM, cfg_call}, - {"(CONTEST|RULES)", NEED_PARAM, cfg_contest}, - {"TELNETPORT", NEED_PARAM, cfg_telnetport}, - {"BANDOUTPUT", NEED_PARAM, cfg_bandoutput}, - {"(ONE_POINT|(TWO|THREE)_POINTS)", NO_PARAM, cfg_n_points}, - {"BANDMAP", OPTIONAL_PARAM, cfg_bandmap}, - {"CWSPEED", NEED_PARAM, cfg_cwspeed}, - {"CWTONE", NEED_PARAM, cfg_cwtone}, - {"SUNSPOTS", NEED_PARAM, cfg_sunspots}, - {"SFI", NEED_PARAM, cfg_sfi}, - {"TNCPORT", NEED_PARAM, cfg_tncport}, - {"ADDNODE", NEED_PARAM, cfg_addnode}, - {"THISNODE", NEED_PARAM, cfg_thisnode}, - {"MULT_LIST", NEED_PARAM, cfg_mult_list}, - {"MARKER(|DOT|CALL)S", NEED_PARAM, cfg_markers}, - {"DX_&_SECTIONS", NO_PARAM, cfg_dx_n_sections}, - {"COUNTRYLIST", NEED_PARAM, cfg_countrylist}, - {"CONTINENTLIST", NEED_PARAM, cfg_continentlist}, - {"USE_COUNTRYLIST_ONLY", NO_PARAM, cfg_country_list_only}, - {"SIDETONE_VOLUME", NEED_PARAM, cfg_sc_volume}, - {"MFJ1278_KEYER", NEED_PARAM, cfg_mfj1278_keyer}, - {"CHANGE_RST", OPTIONAL_PARAM, cfg_change_rst}, - {"GMFSK", NEED_PARAM, cfg_gmfsk}, - {"RTTYMODE", NO_PARAM, cfg_rttymode}, - {"MYQRA", NEED_PARAM, cfg_myqra}, - {"POWERMULT", NEED_PARAM, cfg_powermult}, - {"QTC", NEED_PARAM, cfg_qtc}, - {"BANDWEIGHT_POINTS", NEED_PARAM, cfg_bandweight_points}, - {"BANDWEIGHT_MULTIS", NEED_PARAM, cfg_bandweight_multis}, - {"PFX_NUM_MULTIS", NEED_PARAM, cfg_pfx_num_multis}, - {"QTCREC_RECORD_COMMAND", NEED_PARAM, cfg_qtcrec_record_command}, - {"EXCLUDE_MULTILIST", NEED_PARAM, cfg_exclude_multilist}, - {"FLDIGI", OPTIONAL_PARAM, cfg_fldigi}, - {"MINITEST", OPTIONAL_PARAM, cfg_minitest}, - {"UNIQUE_CALL_MULTI", NEED_PARAM, cfg_unique_call_multi}, - {"DIGI_RIG_MODE", NEED_PARAM, cfg_digi_rig_mode}, - {"CABRILLO-(.+)", OPTIONAL_PARAM, cfg_cabrillo_field}, - {"RESEND_CALL", NEED_PARAM, cfg_resend_call}, - {"GENERIC_MULT", NEED_PARAM, cfg_generic_mult}, - {"OPERATING_MODE", NEED_PARAM, cfg_operating_mode}, - - {NULL} // end marker + {"RIGPORT", CFG_STRING_NOCHOMP(rigportname)}, + {"CLUSTERLOGIN", CFG_STRING_STATIC_NOCHOMP(clusterlogin, 80)}, + + {"CALL", NEED_PARAM, cfg_call}, + {"(CONTEST|RULES)", NEED_PARAM, cfg_contest}, + {"TELNETPORT", NEED_PARAM, cfg_telnetport}, + {"BANDOUTPUT", NEED_PARAM, cfg_bandoutput}, + {"(ONE_POINT|(TWO|THREE)_POINTS)", NO_PARAM, cfg_n_points}, + {"BANDMAP", OPTIONAL_PARAM, cfg_bandmap}, + {"CWSPEED", NEED_PARAM, cfg_cwspeed}, + {"CWTONE", NEED_PARAM, cfg_cwtone}, + {"SUNSPOTS", NEED_PARAM, cfg_sunspots}, + {"SFI", NEED_PARAM, cfg_sfi}, + {"TNCPORT", NEED_PARAM, cfg_tncport}, + {"ADDNODE", NEED_PARAM, cfg_addnode}, + {"THISNODE", NEED_PARAM, cfg_thisnode}, + {"MULT_LIST", NEED_PARAM, cfg_mult_list}, + {"MARKER(|DOT|CALL)S", NEED_PARAM, cfg_markers}, + {"DX_&_SECTIONS", NO_PARAM, cfg_dx_n_sections}, + {"COUNTRYLIST", NEED_PARAM, cfg_countrylist}, + {"CONTINENTLIST", NEED_PARAM, cfg_continentlist}, + {"USE_COUNTRYLIST_ONLY", NO_PARAM, cfg_country_list_only}, + {"SIDETONE_VOLUME", NEED_PARAM, cfg_sc_volume}, + {"MFJ1278_KEYER", NEED_PARAM, cfg_mfj1278_keyer}, + {"CHANGE_RST", OPTIONAL_PARAM, cfg_change_rst}, + {"GMFSK", NEED_PARAM, cfg_gmfsk}, + {"RTTYMODE", NO_PARAM, cfg_rttymode}, + {"MYQRA", NEED_PARAM, cfg_myqra}, + {"POWERMULT", NEED_PARAM, cfg_powermult}, + {"QTC", NEED_PARAM, cfg_qtc}, + {"BANDWEIGHT_POINTS", NEED_PARAM, cfg_bandweight_points}, + {"BANDWEIGHT_MULTIS", NEED_PARAM, cfg_bandweight_multis}, + {"PFX_NUM_MULTIS", NEED_PARAM, cfg_pfx_num_multis}, + {"QTCREC_RECORD_COMMAND", NEED_PARAM, cfg_qtcrec_record_command}, + {"EXCLUDE_MULTILIST", NEED_PARAM, cfg_exclude_multilist}, + {"FLDIGI", OPTIONAL_PARAM, cfg_fldigi}, + {"MINITEST", OPTIONAL_PARAM, cfg_minitest}, + {"UNIQUE_CALL_MULTI", NEED_PARAM, cfg_unique_call_multi}, + {"DIGI_RIG_MODE", NEED_PARAM, cfg_digi_rig_mode}, + {"CABRILLO-(.+)", OPTIONAL_PARAM, cfg_cabrillo_field}, + {"RESEND_CALL", NEED_PARAM, cfg_resend_call}, + {"GENERIC_MULT", NEED_PARAM, cfg_generic_mult}, + {"OPERATING_MODE", NEED_PARAM, cfg_operating_mode}, + + {NULL} // end marker }; static int check_match(const config_t *cfg, const char *keyword) { - gchar *pattern = g_strdup_printf("^%s$", cfg->regex); - GRegex *regex = g_regex_new(pattern, 0, 0, NULL); - g_free(pattern); + gchar *pattern = g_strdup_printf("^%s$", cfg->regex); + GRegex *regex = g_regex_new(pattern, 0, 0, NULL); + g_free(pattern); - int result = PARSE_NO_MATCH; // default: not found + int result = PARSE_NO_MATCH; // default: not found - g_regex_match(regex, keyword, 0, &match_info); - if (g_match_info_matches(match_info)) { + g_regex_match(regex, keyword, 0, &match_info); + if (g_match_info_matches(match_info)) { - if (cfg->param_kind == NEED_PARAM && parameter == NULL) { - result = PARSE_MISSING_PARAMETER; - } else if (cfg->param_kind == NO_PARAM && parameter != NULL) { - result = PARSE_EXTRA_PARAMETER; - } else { - result = cfg->func(cfg->arg); + if (cfg->param_kind == NEED_PARAM && parameter == NULL) { + result = PARSE_MISSING_PARAMETER; + } else if (cfg->param_kind == NO_PARAM && parameter != NULL) { + result = PARSE_EXTRA_PARAMETER; + } else { + result = cfg->func(cfg->arg); + } } - } - g_match_info_free(match_info); - g_regex_unref(regex); + g_match_info_free(match_info); + g_regex_unref(regex); - return result; + return result; } static int apply_config(const char *keyword, const char *param, - const config_t *configs) { + const config_t *configs) { - parameter = param; // save for matcher functions + parameter = param; // save for matcher functions - int result = PARSE_NO_MATCH; + int result = PARSE_NO_MATCH; - for (const config_t *cfg = configs; cfg->regex ; ++cfg) { - result = check_match(cfg, keyword); - if (result != PARSE_NO_MATCH) { - break; + for (const config_t *cfg = configs; cfg->regex ; ++cfg) { + result = check_match(cfg, keyword); + if (result != PARSE_NO_MATCH) { + break; + } } - } - switch (result) { - case PARSE_OK: - return PARSE_OK; + switch (result) { + case PARSE_OK: + return PARSE_OK; - case PARSE_NO_MATCH: - KeywordNotSupported(keyword); - break; + case PARSE_NO_MATCH: + KeywordNotSupported(keyword); + break; - case PARSE_MISSING_PARAMETER: - ParameterNeeded(keyword); - break; + case PARSE_MISSING_PARAMETER: + ParameterNeeded(keyword); + break; - case PARSE_EXTRA_PARAMETER: - ParameterUnexpected(keyword); - break; + case PARSE_EXTRA_PARAMETER: + ParameterUnexpected(keyword); + break; - case PARSE_INVALID_INTEGER: - WrongFormat_details(keyword, "invalid number"); - break; + case PARSE_INVALID_INTEGER: + WrongFormat_details(keyword, "invalid number"); + break; - case PARSE_INTEGER_OUT_OF_RANGE: - WrongFormat_details(keyword, "value out of range"); - break; + case PARSE_INTEGER_OUT_OF_RANGE: + WrongFormat_details(keyword, "value out of range"); + break; - case PARSE_STRING_TOO_LONG: - WrongFormat_details(keyword, "value too long"); - break; + case PARSE_STRING_TOO_LONG: + WrongFormat_details(keyword, "value too long"); + break; - default: - if (error_details != NULL) { - WrongFormat_details(keyword, error_details); - g_free(error_details); - } else { - WrongFormat(keyword); - } - } + default: + if (error_details != NULL) { + WrongFormat_details(keyword, error_details); + g_free(error_details); + } else { + WrongFormat(keyword); + } + } - return PARSE_ERROR; + return PARSE_ERROR; } //////////////////// int parse_logcfg(char *inputbuffer) { - /* split the inputline at '=' to max 2 elements - * - * leave the components in fields[0] (keyword) and - * fields[1] for the parameters - * - * if only 1 component (no '='), it is only a keyword - * g_strstrip it and test for keywordlist - * - * if 2 components (there is a '=' in the line) - * g_strstrip first component and test for keywordlist - * g_strchug second component -> strip leading space from parameters - * - * That allows plain keywords and also keywords with parameters (which - * follows a '=' sign - */ - - char **fields = g_strsplit(inputbuffer, "=", 2); - g_strstrip(fields[0]); - - if (*fields[0] == '\0') { /* only whitespace found? */ - g_strfreev(fields); - return (PARSE_OK); - } - - if (g_strv_length(fields) == 2) { /* strip leading whitespace */ - g_strchug(fields[1]); /* from parameters */ - } - - int result = apply_config(fields[0], fields[1], logcfg_configs); - - g_strfreev(fields); - return result; + /* split the inputline at '=' to max 2 elements + * + * leave the components in fields[0] (keyword) and + * fields[1] for the parameters + * + * if only 1 component (no '='), it is only a keyword + * g_strstrip it and test for keywordlist + * + * if 2 components (there is a '=' in the line) + * g_strstrip first component and test for keywordlist + * g_strchug second component -> strip leading space from parameters + * + * That allows plain keywords and also keywords with parameters (which + * follows a '=' sign + */ + + char **fields = g_strsplit(inputbuffer, "=", 2); + g_strstrip(fields[0]); + + if (*fields[0] == '\0') { /* only whitespace found? */ + g_strfreev(fields); + return (PARSE_OK); + } + + if (g_strv_length(fields) == 2) { /* strip leading whitespace */ + g_strchug(fields[1]); /* from parameters */ + } + + int result = apply_config(fields[0], fields[1], logcfg_configs); + + g_strfreev(fields); + return result; } /** Complain about problems in configuration @@ -1539,49 +1543,49 @@ int parse_logcfg(char *inputbuffer) { * \param msg The reason for the problem to be shown */ void Complain(char *msg) { - attron(A_STANDOUT); - showmsg(msg); - attroff(A_STANDOUT); - beep(); + attron(A_STANDOUT); + showmsg(msg); + attroff(A_STANDOUT); + beep(); } /** Complain about not supported keyword */ void KeywordNotSupported(const char *keyword) { - char msgbuffer[192]; - sprintf(msgbuffer, "Keyword '%s' not supported. See man page.\n", keyword); - Complain(msgbuffer); + char msgbuffer[192]; + sprintf(msgbuffer, "Keyword '%s' not supported. See man page.\n", keyword); + Complain(msgbuffer); } /** Complain about missing parameter */ void ParameterNeeded(const char *keyword) { - char msgbuffer[192]; - sprintf(msgbuffer, - "Keyword '%s' must be followed by a parameter ('=....'). See man page.\n", - keyword); - Complain(msgbuffer); + char msgbuffer[192]; + sprintf(msgbuffer, + "Keyword '%s' must be followed by a parameter ('=....'). See man page.\n", + keyword); + Complain(msgbuffer); } void ParameterUnexpected(const char *keyword) { - char msgbuffer[192]; - sprintf(msgbuffer, - "Keyword '%s' can't have a parameter. See man page.\n", - keyword); - Complain(msgbuffer); + char msgbuffer[192]; + sprintf(msgbuffer, + "Keyword '%s' can't have a parameter. See man page.\n", + keyword); + Complain(msgbuffer); } /** Complain about wrong parameter format */ void WrongFormat(const char *keyword) { - char msgbuffer[192]; - sprintf(msgbuffer, - "Wrong parameter format for keyword '%s'. See man page.\n", - keyword); - Complain(msgbuffer); + char msgbuffer[192]; + sprintf(msgbuffer, + "Wrong parameter format for keyword '%s'. See man page.\n", + keyword); + Complain(msgbuffer); } void WrongFormat_details(const char *keyword, const char *details) { - char msgbuffer[192]; - sprintf(msgbuffer, - "Wrong parameter for keyword '%s': %s.\n", - keyword, details); - Complain(msgbuffer); + char msgbuffer[192]; + sprintf(msgbuffer, + "Wrong parameter for keyword '%s': %s.\n", + keyword, details); + Complain(msgbuffer); } diff --git a/src/readcabrillo.c b/src/readcabrillo.c index 597c01db..f781411b 100644 --- a/src/readcabrillo.c +++ b/src/readcabrillo.c @@ -46,10 +46,10 @@ #include "utils.h" enum { - LOGPREF_NONE, - LOGPREF_QSO, - LOGPREF_XQSO, - LOGPREF_QTC + LOGPREF_NONE, + LOGPREF_QSO, + LOGPREF_XQSO, + LOGPREF_QTC }; static int cablinecnt = 0; @@ -58,114 +58,114 @@ char qtcrecv_logfile_import[] = "IMPORT_QTC_recv.log"; void concat_comment(char *dest, char *exchstr) { - if (strlen(dest) > 0) { - g_strlcat(dest, " ", COMMENT_SIZE); - } - g_strlcat(dest, exchstr, COMMENT_SIZE); + if (strlen(dest) > 0) { + g_strlcat(dest, " ", COMMENT_SIZE); + } + g_strlcat(dest, exchstr, COMMENT_SIZE); } int qtcs_allowed(struct cabrillo_desc *cabdesc) { - return ((qtcdirection > 0) && (cabdesc->qtc_item_count > 0)); + return ((qtcdirection > 0) && (cabdesc->qtc_item_count > 0)); } /* check if line starts with 'start' */ int starts_with(char *line, char *start) { - return (strncmp(line, start, strlen(start)) == 0); + return (strncmp(line, start, strlen(start)) == 0); } /* write a new line to the qso log */ void write_log_fm_cabr(struct qso_t *qso) { - qso->qso_nr = cablinecnt; - - checkexchange(qso, false); - dupe = is_dupe(qso->call, qso->bandindex, qso->mode); - addcall(qso); /* add call to worked list and check it for dupe */ - score_qso(qso); - char *logline = makelogline(qso); /* format logline */ - qso->logline = logline; - store_qso(logfile, logline); - g_ptr_array_add(qso_array, qso); - - cleanup_qso(); - qsoflags_for_qtc[NR_QSOS - 1] = 0; + qso->qso_nr = cablinecnt; + + checkexchange(qso, false); + dupe = is_dupe(qso->call, qso->bandindex, qso->mode); + addcall(qso); /* add call to worked list and check it for dupe */ + score_qso(qso); + char *logline = makelogline(qso); /* format logline */ + qso->logline = logline; + store_qso(logfile, logline); + g_ptr_array_add(qso_array, qso); + + cleanup_qso(); + qsoflags_for_qtc[NR_QSOS - 1] = 0; } /* write a new line to the qtc log */ void write_qtclog_fm_cabr(char *qtcrcall, struct read_qtc_t qtc_line) { - static int qtc_curr_call_nr = 0; - static int qtc_last_call_nr = 0; - static int qtc_last_qtc_serial = 0; - static int qtc_last_qtc_count = 0; - static char qtc_last_qtc_rcall[15] = ""; - - char thiscall[15] = "", ttime[5] = ""; - int found_call = 0, found_empty = 0; - - if (strcmp(qtcrcall, my.call) == 0) { // RECV - qtc_line.direction = RECV; - qtc_line.qsonr = cablinecnt; - make_qtc_logline(qtc_line, qtcrecv_logfile_import); - } else { // SENT - - qtc_line.direction = SEND; - // search the sent callsign in list of QSOs - - found_call = 0; // indicates that the callsign found - found_empty = 0;// indicates that there is the "hole" in the list - // some reason, eg. own call - // if new qtc block comes, go back to last empty - if (qtc_last_qtc_count != qtc_line.qtchead_count && - qtc_last_qtc_serial != qtc_line.qtchead_serial && - strcmp(qtc_last_qtc_rcall, qtcrcall) != 0) { - // current nr last stored nr - empty (see above) or after last - qtc_curr_call_nr = qtc_last_call_nr; - strcpy(qtc_last_qtc_rcall, qtcrcall); - qtc_last_qtc_serial = qtc_line.qtchead_serial; - qtc_last_qtc_count = qtc_line.qtchead_count; - } - - // look until not found and we're in list - while (found_call == 0 && qtc_curr_call_nr < NR_QSOS) { - strncpy(thiscall, QSOS(qtc_curr_call_nr) + 29, 14); - g_strchomp(thiscall); - strncpy(ttime, QSOS(qtc_curr_call_nr) + 17, 2); - strncpy(ttime + 2, QSOS(qtc_curr_call_nr) + 20, 2); - ttime[4] = '\0'; - // check the call wasn't sent, and call and time are equals - if (qsoflags_for_qtc[qtc_curr_call_nr] == 0 && - (strcmp(thiscall, qtc_line.qtc_call) == 0) && - (strcmp(ttime, qtc_line.qtc_time)) == 0) { - found_call = qtc_curr_call_nr + 1; - qsoflags_for_qtc[qtc_curr_call_nr] = 1; - } else { - if (found_empty == 0) { - found_empty = 1; - qtc_last_call_nr = qtc_curr_call_nr; + static int qtc_curr_call_nr = 0; + static int qtc_last_call_nr = 0; + static int qtc_last_qtc_serial = 0; + static int qtc_last_qtc_count = 0; + static char qtc_last_qtc_rcall[15] = ""; + + char thiscall[15] = "", ttime[5] = ""; + int found_call = 0, found_empty = 0; + + if (strcmp(qtcrcall, my.call) == 0) { // RECV + qtc_line.direction = RECV; + qtc_line.qsonr = cablinecnt; + make_qtc_logline(qtc_line, qtcrecv_logfile_import); + } else { // SENT + + qtc_line.direction = SEND; + // search the sent callsign in list of QSOs + + found_call = 0; // indicates that the callsign found + found_empty = 0;// indicates that there is the "hole" in the list + // some reason, eg. own call + // if new qtc block comes, go back to last empty + if (qtc_last_qtc_count != qtc_line.qtchead_count && + qtc_last_qtc_serial != qtc_line.qtchead_serial && + strcmp(qtc_last_qtc_rcall, qtcrcall) != 0) { + // current nr last stored nr - empty (see above) or after last + qtc_curr_call_nr = qtc_last_call_nr; + strcpy(qtc_last_qtc_rcall, qtcrcall); + qtc_last_qtc_serial = qtc_line.qtchead_serial; + qtc_last_qtc_count = qtc_line.qtchead_count; } - } - // increment list pos. - qtc_curr_call_nr++; + // look until not found and we're in list + while (found_call == 0 && qtc_curr_call_nr < NR_QSOS) { + strncpy(thiscall, QSOS(qtc_curr_call_nr) + 29, 14); + g_strchomp(thiscall); + strncpy(ttime, QSOS(qtc_curr_call_nr) + 17, 2); + strncpy(ttime + 2, QSOS(qtc_curr_call_nr) + 20, 2); + ttime[4] = '\0'; + // check the call wasn't sent, and call and time are equals + if (qsoflags_for_qtc[qtc_curr_call_nr] == 0 && + (strcmp(thiscall, qtc_line.qtc_call) == 0) && + (strcmp(ttime, qtc_line.qtc_time)) == 0) { + found_call = qtc_curr_call_nr + 1; + qsoflags_for_qtc[qtc_curr_call_nr] = 1; + } else { + if (found_empty == 0) { + found_empty = 1; + qtc_last_call_nr = qtc_curr_call_nr; + } + } + + // increment list pos. + qtc_curr_call_nr++; + } + // end search + if (found_empty == 0 && found_call > 0) { + qtc_last_call_nr = qtc_curr_call_nr; + } else { + // TODO + // handling this issue + //if (found_call == 0) { + //syslog(LOG_DEBUG, "Found invalid QTC time / QTC call: '%s' '%s' - '%s' '%s' at QTC with %s [%d] (%d - %d)", qtc_line.qtc_time, qtc_line.qtc_call, ttime, thiscall, qtcrcall, qtc_curr_call_nr, found_empty, found_call); + //} + qtc_curr_call_nr = qtc_last_call_nr; + } + strcpy(qtc_line.call, qtcrcall); + qtc_line.callpos = found_call; + qtc_line.qsonr = cablinecnt; + make_qtc_logline(qtc_line, qtcsend_logfile_import); } - // end search - if (found_empty == 0 && found_call > 0) { - qtc_last_call_nr = qtc_curr_call_nr; - } else { - // TODO - // handling this issue - //if (found_call == 0) { - //syslog(LOG_DEBUG, "Found invalid QTC time / QTC call: '%s' '%s' - '%s' '%s' at QTC with %s [%d] (%d - %d)", qtc_line.qtc_time, qtc_line.qtc_call, ttime, thiscall, qtcrcall, qtc_curr_call_nr, found_empty, found_call); - //} - qtc_curr_call_nr = qtc_last_call_nr; - } - strcpy(qtc_line.call, qtcrcall); - qtc_line.callpos = found_call; - qtc_line.qsonr = cablinecnt; - make_qtc_logline(qtc_line, qtcsend_logfile_import); - } } /* Cabrillo QSO to Tlf format @@ -180,207 +180,207 @@ struct read_qtc_t qtc_line; /* make global for testability */ void cab_qso_to_tlf(char *line, struct cabrillo_desc *cabdesc) { - int item_count; - GPtrArray *item_array; - struct line_item *item; - - int i; - int pos = 0; - char tempstr[80], *tempstrp, timestr[3]; - int linetype = LOGPREF_NONE; - char qtcrcall[15], qtcscall[15]; - - // [UNIVERSAL] - // QSO=FREQ,5;MODE,2;DATE,10;TIME,4;MYCALL,13;RST_S,3;EXC_S,6;HISCALL,13;RST_R,3;EXCH,6 - - // [WAEDC] - // QSO=FREQ,5;MODE,2;DATE,10;TIME,4;MYCALL,13;RST_S,3;EXC_S,6;HISCALL,13;RST_R,3;EXCH,6 - // QTC=FREQ,5;MODE,2;DATE,10;TIME,4;QTCRCALL,13;QTCHEAD,10;QTCSCALL,13;QTC,23 - // QSO: 14043 CW 2016-08-13 0022 HA2OS 599 0004 KL7SB/VY2 599 025 - // QSO: 7002 CW 2016-08-13 0033 HA2OS 599 0008 K6ND 599 044 - // - // Tlf log: - // 20CW 13-Aug-16 00:22 0004 KL7SB/VY2 599 599 025 KL7 1 14043.5 - // 40CW 13-Aug-16 00:33 0008 K6ND 599 599 044 K6 1 7002.8 - - // QSO: 14084 RY 2016-11-12 1210 HA2OS 599 0013 K4GM 599 156 - // QTC: 14084 RY 2016-11-12 1214 HA2OS 13/10 K4GM 0230 DL6UHD 074 - // - // 20DIG 0013 12-Nov-16 12:14 K4GM 0013 0010 0230 DL6UHD 074 14084.0 - // BANDM QSO DATE TIME CALL SERIAL/NR TIME QTCCALL QTCSER FREQ - // - // QSO: 3593 RY 2016-11-12 2020 HA2OS 599 0110 RG9A 599 959 - // QTC: 3593 RY 2016-11-12 2021 RG9A 2/10 HA2OS 1208 2M0WEV 018 - // - // 80DIG 0110 0011 12-Nov-16 20:21 RG9A 0002 0010 1208 2M0WEV 018 3593.8 - // BANDM QSO POS DATE TIME CALL SERIAL/NR TIME QTCCALL QTCSER FREQ - - - struct tm time_ptr_cabrillo; - memset(&time_ptr_cabrillo, 0, sizeof(struct tm)); - memset(&qtc_line, 0, sizeof(struct read_qtc_t)); - - if (starts_with(line, "QSO")) { - pos = 5; - cablinecnt++; - linetype = LOGPREF_QSO; - item_count = cabdesc->item_count; - item_array = cabdesc->item_array; - } else if (starts_with(line, "X-QSO")) { - pos = 7; - cablinecnt++; - linetype = LOGPREF_XQSO; - item_count = cabdesc->item_count; - item_array = cabdesc->item_array; - } else if (qtcs_allowed(cabdesc) && (starts_with(line, "QTC"))) { - pos = 5; - linetype = LOGPREF_QTC; - item_count = cabdesc->qtc_item_count; - item_array = cabdesc->qtc_item_array; - } else { - return; - } - - struct qso_t *qso = g_malloc0(sizeof(struct qso_t)); - qso->comment = g_malloc0(COMMENT_SIZE); // pre-allocate buffer for comment - - qtcrcall[0] = '\0'; - qtcscall[0] = '\0'; - - for (i = 0; i < item_count; i++) { - item = g_ptr_array_index(item_array, i); - g_strlcpy(tempstr, line + pos, item->len + 1); - g_strchomp(tempstr); - pos += item->len; - pos++; // space between fields - switch (item->tag) { - case FREQ: - qso->freq = atof(tempstr) * 1000.0; - qso->bandindex = freq2bandindex(qso->freq); //FIXME check OOB, see log_utils - strcpy(qtc_line.band, band[qso->bandindex]); - qtc_line.freq = qso->freq; - break; - case MODE: - if (strcmp(tempstr, "CW") == 0) { - qso->mode = CWMODE; - strcpy(qtc_line.mode, "CW "); - } else if (strcmp(tempstr, "PH") == 0) { - qso->mode = SSBMODE; - strcpy(qtc_line.mode, "PH "); - } else { - qso->mode = DIGIMODE; - strcpy(qtc_line.mode, "DIG"); - } - break; - case DATE: - strptime(tempstr, "%Y-%m-%d", &time_ptr_cabrillo); - strftime(qtc_line.date, sizeof(qtc_line.date), DATE_FORMAT, &time_ptr_cabrillo); - break; - case TIME: - timestr[0] = tempstr[0]; - timestr[1] = tempstr[1]; - timestr[2] = '\0'; - time_ptr_cabrillo.tm_hour = atoi(timestr); - timestr[0] = tempstr[2]; - timestr[1] = tempstr[3]; - timestr[2] = '\0'; - time_ptr_cabrillo.tm_min = atoi(timestr); - sprintf(qtc_line.time, "%02d:%02d", time_ptr_cabrillo.tm_hour, - time_ptr_cabrillo.tm_min); - break; - case MYCALL: - break; - case HISCALL: - qso->call = g_strdup(tempstr); - break; - case RST_S: - qso->rst_s = atoi(tempstr); - break; - case RST_R: - qso->rst_r = atoi(tempstr); - break; - case EXCH: - strcpy(qso->comment, tempstr); - break; - case EXC1: - strcpy(qso->comment, tempstr); - break; - case EXC2: - concat_comment(qso->comment, tempstr); - break; - case EXC3: - concat_comment(qso->comment, tempstr); - break; - case EXC4: - concat_comment(qso->comment, tempstr); - break; - case EXC_S: - case TX: - case QTCRCALL: - strcpy(qtcrcall, tempstr); - strcpy(qtc_line.call, tempstr); - break; - case QTCHEAD: - strcpy(qtc_line.qtchead, tempstr); - qtc_line.qtchead_serial = 0; - if ((tempstrp = strtok(qtc_line.qtchead, "/")) != NULL) - qtc_line.qtchead_serial = atoi(tempstrp); - - qtc_line.qtchead_count = 0; - if ((tempstrp = strtok(NULL, " ")) != NULL) - qtc_line.qtchead_count = atoi(tempstrp); - - break; - case QTCSCALL: - strcpy(qtcscall, tempstr); - strcpy(qtc_line.call, tempstr); - break; - case QTC: - strcpy(qtc_line.qtcstr, tempstr); - if ((tempstrp = strtok(qtc_line.qtcstr, " ")) != NULL) - strcpy(qtc_line.qtc_time, tempstrp); - - if ((tempstrp = strtok(NULL, " ")) != NULL) { - g_strchomp(tempstrp); - strcpy(qtc_line.qtc_call, tempstrp); - } + int item_count; + GPtrArray *item_array; + struct line_item *item; + + int i; + int pos = 0; + char tempstr[80], *tempstrp, timestr[3]; + int linetype = LOGPREF_NONE; + char qtcrcall[15], qtcscall[15]; + + // [UNIVERSAL] + // QSO=FREQ,5;MODE,2;DATE,10;TIME,4;MYCALL,13;RST_S,3;EXC_S,6;HISCALL,13;RST_R,3;EXCH,6 + + // [WAEDC] + // QSO=FREQ,5;MODE,2;DATE,10;TIME,4;MYCALL,13;RST_S,3;EXC_S,6;HISCALL,13;RST_R,3;EXCH,6 + // QTC=FREQ,5;MODE,2;DATE,10;TIME,4;QTCRCALL,13;QTCHEAD,10;QTCSCALL,13;QTC,23 + // QSO: 14043 CW 2016-08-13 0022 HA2OS 599 0004 KL7SB/VY2 599 025 + // QSO: 7002 CW 2016-08-13 0033 HA2OS 599 0008 K6ND 599 044 + // + // Tlf log: + // 20CW 13-Aug-16 00:22 0004 KL7SB/VY2 599 599 025 KL7 1 14043.5 + // 40CW 13-Aug-16 00:33 0008 K6ND 599 599 044 K6 1 7002.8 + + // QSO: 14084 RY 2016-11-12 1210 HA2OS 599 0013 K4GM 599 156 + // QTC: 14084 RY 2016-11-12 1214 HA2OS 13/10 K4GM 0230 DL6UHD 074 + // + // 20DIG 0013 12-Nov-16 12:14 K4GM 0013 0010 0230 DL6UHD 074 14084.0 + // BANDM QSO DATE TIME CALL SERIAL/NR TIME QTCCALL QTCSER FREQ + // + // QSO: 3593 RY 2016-11-12 2020 HA2OS 599 0110 RG9A 599 959 + // QTC: 3593 RY 2016-11-12 2021 RG9A 2/10 HA2OS 1208 2M0WEV 018 + // + // 80DIG 0110 0011 12-Nov-16 20:21 RG9A 0002 0010 1208 2M0WEV 018 3593.8 + // BANDM QSO POS DATE TIME CALL SERIAL/NR TIME QTCCALL QTCSER FREQ + + + struct tm time_ptr_cabrillo; + memset(&time_ptr_cabrillo, 0, sizeof(struct tm)); + memset(&qtc_line, 0, sizeof(struct read_qtc_t)); + + if (starts_with(line, "QSO")) { + pos = 5; + cablinecnt++; + linetype = LOGPREF_QSO; + item_count = cabdesc->item_count; + item_array = cabdesc->item_array; + } else if (starts_with(line, "X-QSO")) { + pos = 7; + cablinecnt++; + linetype = LOGPREF_XQSO; + item_count = cabdesc->item_count; + item_array = cabdesc->item_array; + } else if (qtcs_allowed(cabdesc) && (starts_with(line, "QTC"))) { + pos = 5; + linetype = LOGPREF_QTC; + item_count = cabdesc->qtc_item_count; + item_array = cabdesc->qtc_item_array; + } else { + return; + } - qtc_line.qtc_serial = 0; - if ((tempstrp = strtok(NULL, " ")) != NULL) { - g_strchomp(tempstrp); - qtc_line.qtc_serial = atoi(tempstrp); + struct qso_t *qso = g_malloc0(sizeof(struct qso_t)); + qso->comment = g_malloc0(COMMENT_SIZE); // pre-allocate buffer for comment + + qtcrcall[0] = '\0'; + qtcscall[0] = '\0'; + + for (i = 0; i < item_count; i++) { + item = g_ptr_array_index(item_array, i); + g_strlcpy(tempstr, line + pos, item->len + 1); + g_strchomp(tempstr); + pos += item->len; + pos++; // space between fields + switch (item->tag) { + case FREQ: + qso->freq = atof(tempstr) * 1000.0; + qso->bandindex = freq2bandindex(qso->freq); //FIXME check OOB, see log_utils + strcpy(qtc_line.band, band[qso->bandindex]); + qtc_line.freq = qso->freq; + break; + case MODE: + if (strcmp(tempstr, "CW") == 0) { + qso->mode = CWMODE; + strcpy(qtc_line.mode, "CW "); + } else if (strcmp(tempstr, "PH") == 0) { + qso->mode = SSBMODE; + strcpy(qtc_line.mode, "PH "); + } else { + qso->mode = DIGIMODE; + strcpy(qtc_line.mode, "DIG"); + } + break; + case DATE: + strptime(tempstr, "%Y-%m-%d", &time_ptr_cabrillo); + strftime(qtc_line.date, sizeof(qtc_line.date), DATE_FORMAT, &time_ptr_cabrillo); + break; + case TIME: + timestr[0] = tempstr[0]; + timestr[1] = tempstr[1]; + timestr[2] = '\0'; + time_ptr_cabrillo.tm_hour = atoi(timestr); + timestr[0] = tempstr[2]; + timestr[1] = tempstr[3]; + timestr[2] = '\0'; + time_ptr_cabrillo.tm_min = atoi(timestr); + sprintf(qtc_line.time, "%02d:%02d", time_ptr_cabrillo.tm_hour, + time_ptr_cabrillo.tm_min); + break; + case MYCALL: + break; + case HISCALL: + qso->call = g_strdup(tempstr); + break; + case RST_S: + qso->rst_s = atoi(tempstr); + break; + case RST_R: + qso->rst_r = atoi(tempstr); + break; + case EXCH: + strcpy(qso->comment, tempstr); + break; + case EXC1: + strcpy(qso->comment, tempstr); + break; + case EXC2: + concat_comment(qso->comment, tempstr); + break; + case EXC3: + concat_comment(qso->comment, tempstr); + break; + case EXC4: + concat_comment(qso->comment, tempstr); + break; + case EXC_S: + case TX: + case QTCRCALL: + strcpy(qtcrcall, tempstr); + strcpy(qtc_line.call, tempstr); + break; + case QTCHEAD: + strcpy(qtc_line.qtchead, tempstr); + qtc_line.qtchead_serial = 0; + if ((tempstrp = strtok(qtc_line.qtchead, "/")) != NULL) + qtc_line.qtchead_serial = atoi(tempstrp); + + qtc_line.qtchead_count = 0; + if ((tempstrp = strtok(NULL, " ")) != NULL) + qtc_line.qtchead_count = atoi(tempstrp); + + break; + case QTCSCALL: + strcpy(qtcscall, tempstr); + strcpy(qtc_line.call, tempstr); + break; + case QTC: + strcpy(qtc_line.qtcstr, tempstr); + if ((tempstrp = strtok(qtc_line.qtcstr, " ")) != NULL) + strcpy(qtc_line.qtc_time, tempstrp); + + if ((tempstrp = strtok(NULL, " ")) != NULL) { + g_strchomp(tempstrp); + strcpy(qtc_line.qtc_call, tempstrp); + } + + qtc_line.qtc_serial = 0; + if ((tempstrp = strtok(NULL, " ")) != NULL) { + g_strchomp(tempstrp); + qtc_line.qtc_serial = atoi(tempstrp); + } + case NO_ITEM: + default: + break; } - case NO_ITEM: - default: - break; - } - } + } - // strip trailing exchange separators and change them to the specified value - // note: it assumes that exchanges do not contain spaces - g_strchomp(qso->comment); - if (cabdesc->exchange_separator != NULL) { - // use the first separator char - g_strdelimit(qso->comment, " ", cabdesc->exchange_separator[0]); - } + // strip trailing exchange separators and change them to the specified value + // note: it assumes that exchanges do not contain spaces + g_strchomp(qso->comment); + if (cabdesc->exchange_separator != NULL) { + // use the first separator char + g_strdelimit(qso->comment, " ", cabdesc->exchange_separator[0]); + } - qso->timestamp = timegm(&time_ptr_cabrillo); + qso->timestamp = timegm(&time_ptr_cabrillo); - if ((linetype == LOGPREF_QSO) || (linetype == LOGPREF_XQSO)) { - write_log_fm_cabr(qso); - } else if (linetype == LOGPREF_QTC) { - write_qtclog_fm_cabr(qtcrcall, qtc_line); - free_qso(qso); - } + if ((linetype == LOGPREF_QSO) || (linetype == LOGPREF_XQSO)) { + write_log_fm_cabr(qso); + } else if (linetype == LOGPREF_QTC) { + write_qtclog_fm_cabr(qtcrcall, qtc_line); + free_qso(qso); + } } void show_readcab_msg(int mode, char *msg) { - if (mode == READCAB_MODE_CLI) { - showmsg(msg); - refreshp(); - } + if (mode == READCAB_MODE_CLI) { + showmsg(msg); + refreshp(); + } } /** readcabrillo @@ -391,74 +391,74 @@ void show_readcab_msg(int mode, char *msg) { */ int readcabrillo(int mode) { - struct cabrillo_desc *cabdesc; - char input_logfile[24]; - char output_logfile[80], temp_logfile[80]; - char* logline = NULL; - char *tempstrp; + struct cabrillo_desc *cabdesc; + char input_logfile[24]; + char output_logfile[80], temp_logfile[80]; + char *logline = NULL; + char *tempstrp; size_t read_len = 0; - char t_qsonrstr[5]; - int t_qsonum; - int t_bandinx; + char t_qsonrstr[5]; + int t_qsonum; + int t_bandinx; int read; - FILE *fp1, *fp2, *fpqtc; + FILE *fp1, *fp2, *fpqtc; - if (cabrillo == NULL) { + if (cabrillo == NULL) { show_readcab_msg(mode, "Missing CABRILLO= keyword (see man page)"); sleep(2); return 1; - } + } - char *cab_file = find_available("cabrillo.fmt"); - cabdesc = read_cabrillo_format(cab_file, cabrillo); - g_free(cab_file); + char *cab_file = find_available("cabrillo.fmt"); + cabdesc = read_cabrillo_format(cab_file, cabrillo); + g_free(cab_file); - if (!cabdesc) { + if (!cabdesc) { show_readcab_msg(mode, "Cabrillo format specification not found!"); sleep(2); return 2; - } + } - tempstrp = g_strdup_printf("CABRILLO format: %s", cabrillo); - show_readcab_msg(mode, tempstrp); - g_free(tempstrp); - sleep(1); + tempstrp = g_strdup_printf("CABRILLO format: %s", cabrillo); + show_readcab_msg(mode, tempstrp); + g_free(tempstrp); + sleep(1); - strcpy(temp_logfile, logfile); + strcpy(temp_logfile, logfile); - get_cabrillo_file_name(input_logfile); - tempstrp = g_strdup_printf("Reading from %s", input_logfile); - show_readcab_msg(mode, tempstrp); - g_free(tempstrp); + get_cabrillo_file_name(input_logfile); + tempstrp = g_strdup_printf("Reading from %s", input_logfile); + show_readcab_msg(mode, tempstrp); + g_free(tempstrp); - strcpy(output_logfile, "IMPORT_"); - strcat(output_logfile, logfile); - strcpy(logfile, output_logfile); + strcpy(output_logfile, "IMPORT_"); + strcat(output_logfile, logfile); + strcpy(logfile, output_logfile); - if ((fp2 = fopen(output_logfile, "w")) == NULL) { + if ((fp2 = fopen(output_logfile, "w")) == NULL) { tempstrp = g_strdup_printf("Can't open output logfile: %s.", - output_logfile); + output_logfile); show_readcab_msg(mode, tempstrp); g_free(tempstrp); sleep(2); free_cabfmt(cabdesc); return 1; - } - fclose(fp2); + } + fclose(fp2); - if ((fp1 = fopen(input_logfile, "r")) == NULL) { + if ((fp1 = fopen(input_logfile, "r")) == NULL) { tempstrp = g_strdup_printf("Can't open input logfile: %s.", - input_logfile); + input_logfile); show_readcab_msg(mode, tempstrp); g_free(tempstrp); sleep(2); free_cabfmt(cabdesc); return 1; - } + } - if (cabdesc->qtc_item_count > 0) { + if (cabdesc->qtc_item_count > 0) { if (qtcdirection & SEND) { fpqtc = fopen(qtcsend_logfile_import, "w"); if (fpqtc) fclose(fpqtc); @@ -468,31 +468,33 @@ int readcabrillo(int mode) { fpqtc = fopen(qtcrecv_logfile_import, "w"); if (fpqtc) fclose(fpqtc); } - } + } - strcpy(t_qsonrstr, qsonrstr); - t_qsonum = qsonum; - t_bandinx = bandinx; + strcpy(t_qsonrstr, qsonrstr); + t_qsonum = qsonum; + t_bandinx = bandinx; - init_qso_array(); + init_qso_array(); - while((read = getline(&logline, &read_len, fp1)) != 1) { - if (read_len > 0) + while ((read = getline(&logline, &read_len, fp1)) != 1) { + if (read_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } cab_qso_to_tlf(logline, cabdesc); - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); } - } + } - strcpy(qsonrstr, t_qsonrstr); - qsonum = t_qsonum; - bandinx = t_bandinx; + strcpy(qsonrstr, t_qsonrstr); + qsonum = t_qsonum; + bandinx = t_bandinx; if (logline != NULL) free(logline); - fclose(fp1); - free_cabfmt(cabdesc); - strcpy(logfile, temp_logfile); + fclose(fp1); + free_cabfmt(cabdesc); + strcpy(logfile, temp_logfile); - return 0; + return 0; } diff --git a/src/readcalls.c b/src/readcalls.c index dc0dd557..1c643af1 100644 --- a/src/readcalls.c +++ b/src/readcalls.c @@ -55,99 +55,104 @@ /* Backup original logfile and write a new one from internal database */ void do_backup(const char *logfile, bool interactive) { - // save a backup - char prefix[40]; - format_time(prefix, sizeof(prefix), "%Y%m%d_%H%M%S"); - char *backup = g_strdup_printf("%s_%s", prefix, logfile); - rename(logfile, backup); - // rewrite log - for (int i = 0 ; i < NR_QSOS; i++) { + // save a backup + char prefix[40]; + format_time(prefix, sizeof(prefix), "%Y%m%d_%H%M%S"); + char *backup = g_strdup_printf("%s_%s", prefix, logfile); + rename(logfile, backup); + // rewrite log + for (int i = 0 ; i < NR_QSOS; i++) { store_qso(logfile, QSOS(i)); - } - if (interactive) { + } + if (interactive) { showstring("Log has been backed up as", backup); sleep(1); - } - g_free(backup); + } + g_free(backup); } void init_scoring(void) { - /* reset counter and score anew */ - total = 0; + /* reset counter and score anew */ + total = 0; - init_qso_array(); - init_worked(); + init_qso_array(); + init_worked(); - for (int i = 1; i <= MAX_DATALINES - 1; i++) - countries[i] = 0; + for (int i = 1; i <= MAX_DATALINES - 1; i++) + countries[i] = 0; - for (int i = 0; i < NBANDS; i++) - qsos_per_band[i] = 0; + for (int i = 0; i < NBANDS; i++) + qsos_per_band[i] = 0; - for (int i = 0; i < NBANDS; i++) - countryscore[i] = 0; + for (int i = 0; i < NBANDS; i++) + countryscore[i] = 0; - for (int n = 1; n < MAX_ZONES; n++) - zones[n] = 0; + for (int n = 1; n < MAX_ZONES; n++) + zones[n] = 0; - for (int n = 0; n < NBANDS; n++) - zonescore[n] = 0; + for (int n = 0; n < NBANDS; n++) + zonescore[n] = 0; - init_mults(); + init_mults(); - InitPfx(); + InitPfx(); - for (int i = 0; i < pfxnummultinr; i++) { - for (int n = 0; n < PFXNUMBERS; n++) { - pfxnummulti[i].qsos[n] = 0; + for (int i = 0; i < pfxnummultinr; i++) { + for (int n = 0; n < PFXNUMBERS; n++) { + pfxnummulti[i].qsos[n] = 0; + } } - } - if (plugin_has_setup()) { - plugin_setup(); - } + if (plugin_has_setup()) { + plugin_setup(); + } } static void show_progress(int linenr) { - if (linenr == 1) { - printw(" "); // leading separator after log file name - refreshp(); - } - if (((linenr + 1) % 100) == 0) { - printw("*"); - refreshp(); - } + if (linenr == 1) { + printw(" "); // leading separator after log file name + refreshp(); + } + if (((linenr + 1) % 100) == 0) { + printw("*"); + refreshp(); + } } int readcalls(const char *logfile, bool interactive) { - char* inputbuffer = NULL; + char *inputbuffer = NULL; size_t inputbuffer_len = 0; - struct qso_t *qso; - int linenr = 0; + struct qso_t *qso; + int linenr = 0; ssize_t read; - FILE *fp; + FILE *fp; - if (interactive) { + if (interactive) { showstring("Reading logfile:", (char *)logfile); - } + } - init_scoring(); + init_scoring(); - if ((fp = fopen(logfile, "r")) == NULL) { + if ((fp = fopen(logfile, "r")) == NULL) { showmsg("Error opening logfile "); sleep(2); exit(1); - } + } - bool log_changed = false; + bool log_changed = false; - while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { + while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { if (inputbuffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } // drop trailing newline inputbuffer[inputbuffer_len - 1] = '\0'; linenr++; - + if (interactive) { show_progress(linenr); } @@ -171,7 +176,7 @@ int readcalls(const char *logfile, bool interactive) { score_qso(qso); char *logline = makelogline(qso); -// Ignore new line character at end of line in qso->logline + // Ignore new line character at end of line in qso->logline if (strcmp(logline, strtok(qso->logline, "\n")) != 0) { g_free(qso->logline); qso->logline = g_strdup(logline); @@ -180,7 +185,7 @@ int readcalls(const char *logfile, bool interactive) { g_free(logline); - if(inputbuffer != NULL) + if (inputbuffer != NULL) free(inputbuffer); // drop transient fields @@ -190,15 +195,11 @@ int readcalls(const char *logfile, bool interactive) { g_ptr_array_add(qso_array, qso); } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } } - fclose(fp); + fclose(fp); - if (log_changed) { + if (log_changed) { bool ok = false; if (interactive) { showmsg("Log changed due to rescoring. Do you want to save it? Y/(N)"); @@ -210,72 +211,72 @@ int readcalls(const char *logfile, bool interactive) { if (ok) { do_backup(logfile, interactive); } - } + } - return linenr; // nr of lines in log + return linenr; // nr of lines in log } int log_read_n_score() { - int nr_qsolines = readcalls(logfile, false); + int nr_qsolines = readcalls(logfile, false); - if (qtcdirection > 0) { - readqtccalls(); - } - return nr_qsolines; + if (qtcdirection > 0) { + readqtccalls(); + } + return nr_qsolines; } //------------------------------------------------------------------------ int synclog(char *synclogfile) { - char wgetcmd[120] = "wget ftp://"; //user:password@hst/dir/file - char date_buf[60]; - - format_time(date_buf, sizeof(date_buf), "%d%H%M"); - - if (strlen(synclogfile) < 80) - strcat(wgetcmd, synclogfile); - else { - showmsg("Warning: Name of syncfile too long\n"); - sleep(5); - exit(1); - } - strcat(wgetcmd, " -O log1 -o wgetlogfile"); - - if (system(wgetcmd) == 0) - showmsg("Syncfile o.k.\n"); - else { - showmsg("Warning: Did not get syncfile !!\nExiting...\n"); - sleep(5); - exit(1); - } - - wgetcmd[0] = '\0'; - sprintf(wgetcmd, "cp %s log2", logfile); - if (system(wgetcmd) != 0) - showstring("\nCopying logfile %s failed\n", logfile); - - showmsg("Backing up logfile.\n"); - sleep(1); - sprintf(wgetcmd, "cp %s %s%s", logfile, date_buf, logfile); - if (system(wgetcmd) != 0) - showstring("\nCopying logfile %s to backup failed\n", logfile); - - showmsg("Merging logfiles...\n"); - sleep(1); - sprintf(wgetcmd, "cat log1 log2 | sort -g -k4,4 | uniq > %s", - logfile); - if (system(wgetcmd) == 0) - showmsg("Merging logs successful\n"); - else { - showmsg("Problem merging logs.\nExiting...\n"); - sleep(5); - exit(1); - } - sleep(1); - IGNORE(system("rm log1"));; - IGNORE(system("rm log2"));; - - return (0); + char wgetcmd[120] = "wget ftp://"; //user:password@hst/dir/file + char date_buf[60]; + + format_time(date_buf, sizeof(date_buf), "%d%H%M"); + + if (strlen(synclogfile) < 80) + strcat(wgetcmd, synclogfile); + else { + showmsg("Warning: Name of syncfile too long\n"); + sleep(5); + exit(1); + } + strcat(wgetcmd, " -O log1 -o wgetlogfile"); + + if (system(wgetcmd) == 0) + showmsg("Syncfile o.k.\n"); + else { + showmsg("Warning: Did not get syncfile !!\nExiting...\n"); + sleep(5); + exit(1); + } + + wgetcmd[0] = '\0'; + sprintf(wgetcmd, "cp %s log2", logfile); + if (system(wgetcmd) != 0) + showstring("\nCopying logfile %s failed\n", logfile); + + showmsg("Backing up logfile.\n"); + sleep(1); + sprintf(wgetcmd, "cp %s %s%s", logfile, date_buf, logfile); + if (system(wgetcmd) != 0) + showstring("\nCopying logfile %s to backup failed\n", logfile); + + showmsg("Merging logfiles...\n"); + sleep(1); + sprintf(wgetcmd, "cat log1 log2 | sort -g -k4,4 | uniq > %s", + logfile); + if (system(wgetcmd) == 0) + showmsg("Merging logs successful\n"); + else { + showmsg("Problem merging logs.\nExiting...\n"); + sleep(5); + exit(1); + } + sleep(1); + IGNORE(system("rm log1"));; + IGNORE(system("rm log2"));; + + return (0); } diff --git a/src/readqtccalls.c b/src/readqtccalls.c index 5d4b9a7b..9db1404d 100644 --- a/src/readqtccalls.c +++ b/src/readqtccalls.c @@ -37,18 +37,18 @@ int qsoflags_for_qtc[MAX_QSOS]; int nr_qtcsent = 0; int readqtccalls() { - int s = 0; - char *inputbuffer = NULL; - size_t inputbuffer_len = 160; - FILE *fp; - char temps[30], callsign[15]; - int tempi; - int last_qtc = 0; - int i, read; - - qtc_init(); - - if (qtcdirection & SEND) { + int s = 0; + char *inputbuffer = NULL; + size_t inputbuffer_len = 160; + FILE *fp; + char temps[30], callsign[15]; + int tempi; + int last_qtc = 0; + int i, read; + + qtc_init(); + + if (qtcdirection & SEND) { showmsg("Reading QTC sent logfile..."); /* mark all qso lines as not used for QTC */ @@ -64,13 +64,19 @@ int readqtccalls() { while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { if (inputbuffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + s++; /* find maximum sent QTC block serial */ g_strlcpy(temps, inputbuffer + 50, 5); // get serial of QTC block tempi = atoi(temps); if (tempi > nr_qtcsent) { - nr_qtcsent = tempi; + nr_qtcsent = tempi; } /* mark corresponding qso line as used for QTC */ @@ -86,14 +92,10 @@ int readqtccalls() { /* find first unused QSO number for QTCs */ if (tempi > last_qtc) { - last_qtc = tempi; + last_qtc = tempi; } } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } + } if (inputbuffer != NULL) free(inputbuffer); @@ -103,16 +105,16 @@ int readqtccalls() { /* find first QSO which was not used for QTC yet */ for (i = 0; i < last_qtc; i++) { if (qsoflags_for_qtc[i] == 0) { - next_qtc_qso = i; - break; + next_qtc_qso = i; + break; } } fclose(fp); - - } - if (qtcdirection & RECV) { + } + + if (qtcdirection & RECV) { showmsg("Reading QTC recv logfile..."); if ((fp = fopen(QTC_RECV_LOG, "r")) == NULL) { @@ -123,66 +125,73 @@ int readqtccalls() { while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { if (inputbuffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } /* remember callsign, build number of received QTCs */ parse_qtcline(inputbuffer, callsign, RECV); qtc_inc(callsign, RECV); total++; /* add one point per QTC */ } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } } if (inputbuffer != NULL) free(inputbuffer); fclose(fp); - } + } - if (strlen(qtc_cap_calls) > 0) { - showmsg("Reading QTC callsigns file..."); + if (strlen(qtc_cap_calls) > 0) { + showmsg("Reading QTC callsigns file..."); - if ((fp = fopen(qtc_cap_calls, "r")) == NULL) { - showmsg("Error opening QTC callsigns file."); - sleep(2); - return -1; - } + if ((fp = fopen(qtc_cap_calls, "r")) == NULL) { + showmsg("Error opening QTC callsigns file."); + sleep(2); + return -1; + } + + while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { + /* remember callsign, mark it as QTC capable, based on eg. last years */ + if (inputbuffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } - while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { - /* remember callsign, mark it as QTC capable, based on eg. last years */ - if (inputbuffer_len > 0) - qtc_inc(g_strstrip(inputbuffer), QTC_CAP); - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); + qtc_inc(g_strstrip(inputbuffer), QTC_CAP); + } } + + if (inputbuffer != NULL) + free(inputbuffer); + fclose(fp); } - if (inputbuffer != NULL) - free(inputbuffer); - fclose(fp); - } - - showmsg("Reading QTC meta logfile..."); - - if ((fp = fopen(QTC_META_LOG, "r")) == NULL) { - showmsg("QTC meta logfile missing, skipping this step."); - } else { - while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { - /* remember callsign, set marked QTC states */ - if (inputbuffer_len > 0) - parse_qtc_flagline(inputbuffer); - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); + showmsg("Reading QTC meta logfile..."); + + if ((fp = fopen(QTC_META_LOG, "r")) == NULL) { + showmsg("QTC meta logfile missing, skipping this step."); + } else { + while ((read = getline(&inputbuffer, &inputbuffer_len, fp)) != -1) { + /* remember callsign, set marked QTC states */ + if (inputbuffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + + parse_qtc_flagline(inputbuffer); + } } - } - if (inputbuffer != NULL) - free(inputbuffer); - fclose(fp); - } + if (inputbuffer != NULL) + free(inputbuffer); + fclose(fp); + } - return s; + return s; } diff --git a/src/searchlog.c b/src/searchlog.c index dc88941f..b23da2e7 100644 --- a/src/searchlog.c +++ b/src/searchlog.c @@ -1,23 +1,23 @@ - /* - * Tlf - contest logging program for amateur radio operators - * Copyright (C) 2001-2002-2003 Rein Couperus - * 2013 Ervin Hegedüs - HA2OS - * 2018 Thomas Beierlein - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +/* +* Tlf - contest logging program for amateur radio operators +* Copyright (C) 2001-2002-2003 Rein Couperus +* 2013 Ervin Hegedüs - HA2OS +* 2018 Thomas Beierlein - +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ /* ------------------------------------------------------------ * Search log for calls / bands / countries * @@ -83,85 +83,85 @@ static bool is_current_mode(const char *line); * \return - true if also WARC bands */ int IsAllBand() { - return (CONTEST_IS(DXPED) || !iscontest); + return (CONTEST_IS(DXPED) || !iscontest); } void InitSearchPanel() { - if (IsAllBand()) - nr_bands = 9; - else - nr_bands = 6; - - search_win = newwin(nr_bands + 2, 39, 1, 41); - search_panel = new_panel(search_win); - hide_panel(search_panel); + if (IsAllBand()) + nr_bands = 9; + else + nr_bands = 6; + + search_win = newwin(nr_bands + 2, 39, 1, 41); + search_panel = new_panel(search_win); + hide_panel(search_panel); } void ShowSearchPanel(void) { - if (!initialized) { - InitSearchPanel(); - initialized = 1; - } - show_panel(search_panel); - top_panel(search_panel); + if (!initialized) { + InitSearchPanel(); + initialized = 1; + } + show_panel(search_panel); + top_panel(search_panel); } void HideSearchPanel(void) { - hide_panel(search_panel); + hide_panel(search_panel); } void drawSearchWin(void) { - int i; - - wbkgd(search_win, (chtype)(' ' | COLOR_PAIR(C_LOG))); - werase(search_win); - - wnicebox(search_win, 0, 0, nr_bands, 37, "Worked"); - if (qtcdirection > 0) { - mvwaddstr(search_win, 0, 35, "Q"); - } - - wattrset(search_win, COLOR_PAIR(C_LOG) | A_STANDOUT); - for (i = 0; i < nr_bands; i++) - mvwaddstr(search_win, i + 1, 1, spaces(37)); - - mvwaddstr(search_win, 1, 1, " 10"); - mvwaddstr(search_win, 2, 1, " 15"); - mvwaddstr(search_win, 3, 1, " 20"); - mvwaddstr(search_win, 4, 1, " 40"); - mvwaddstr(search_win, 5, 1, " 80"); - mvwaddstr(search_win, 6, 1, "160"); - if (IsAllBand()) { - mvwaddstr(search_win, 7, 1, " 12"); - mvwaddstr(search_win, 8, 1, " 17"); - mvwaddstr(search_win, 9, 1, " 30"); - } + int i; + + wbkgd(search_win, (chtype)(' ' | COLOR_PAIR(C_LOG))); + werase(search_win); + + wnicebox(search_win, 0, 0, nr_bands, 37, "Worked"); + if (qtcdirection > 0) { + mvwaddstr(search_win, 0, 35, "Q"); + } + + wattrset(search_win, COLOR_PAIR(C_LOG) | A_STANDOUT); + for (i = 0; i < nr_bands; i++) + mvwaddstr(search_win, i + 1, 1, spaces(37)); + + mvwaddstr(search_win, 1, 1, " 10"); + mvwaddstr(search_win, 2, 1, " 15"); + mvwaddstr(search_win, 3, 1, " 20"); + mvwaddstr(search_win, 4, 1, " 40"); + mvwaddstr(search_win, 5, 1, " 80"); + mvwaddstr(search_win, 6, 1, "160"); + if (IsAllBand()) { + mvwaddstr(search_win, 7, 1, " 12"); + mvwaddstr(search_win, 8, 1, " 17"); + mvwaddstr(search_win, 9, 1, " 30"); + } } void displayCallInfo(dxcc_data *dx, char *pxstr) { - wattroff(search_win, A_STANDOUT); - wattron(search_win, COLOR_PAIR(C_BORDER)); + wattroff(search_win, A_STANDOUT); + wattron(search_win, COLOR_PAIR(C_BORDER)); - mvwaddstr(search_win, nr_bands + 1, 2, dx->countryname); + mvwaddstr(search_win, nr_bands + 1, 2, dx->countryname); - if (CONTEST_IS(CQWW) || wazmult || itumult) { - char *zone_info = NULL; - if (current_qso.normalized_comment[0] != 0) { - zone_info = current_qso.normalized_comment; - } else if (proposed_exchange[0] != 0) { - zone_info = proposed_exchange; - } - if (zone_info != NULL) { - mvwprintw(search_win, nr_bands + 1, 32, "%2s", zone_info); + if (CONTEST_IS(CQWW) || wazmult || itumult) { + char *zone_info = NULL; + if (current_qso.normalized_comment[0] != 0) { + zone_info = current_qso.normalized_comment; + } else if (proposed_exchange[0] != 0) { + zone_info = proposed_exchange; + } + if (zone_info != NULL) { + mvwprintw(search_win, nr_bands + 1, 32, "%2s", zone_info); + } } - } - if (CONTEST_IS(WPX) || pfxmult) { - int i = strlen(dx->countryname); - mvwaddstr(search_win, nr_bands + 1, 2 + i + 3, pxstr); - } + if (CONTEST_IS(WPX) || pfxmult) { + int i = strlen(dx->countryname); + mvwaddstr(search_win, nr_bands + 1, 2 + i + 3, pxstr); + } } @@ -174,202 +174,202 @@ void displayCallInfo(dxcc_data *dx, char *pxstr) { // return: true if display is full // static bool show_partial(int *row, int *col, char *call, - GHashTable *callset, - int *nr_suggested, char *suggested_call) { - - const int len = strlen(call); - bool space = (*col > 1); // whether to put leading space - int new_col = *col + (space ? 1 : 0) + len; - if (new_col >= PARTIALS_COLS) { // doesn't fit on this line - *row += 1; // start next one - *col = 1; - space = false; - new_col = *col + len; - } - if (*row >= PARTIALS_ROWS) { - return true; // display full - } - - if (!g_hash_table_add(callset, call)) { - return false; // already shown - } - - mvprintw(PARTIALS_Y0 + *row, PARTIALS_X0 + *col, "%s%s", - (space ? " " : ""), call); - - *col = new_col; - - if (*nr_suggested == 0) { // remember first partial call - strcpy(suggested_call, call); - } - *nr_suggested += 1; - - return false; // assume it's not full yet + GHashTable *callset, + int *nr_suggested, char *suggested_call) { + + const int len = strlen(call); + bool space = (*col > 1); // whether to put leading space + int new_col = *col + (space ? 1 : 0) + len; + if (new_col >= PARTIALS_COLS) { // doesn't fit on this line + *row += 1; // start next one + *col = 1; + space = false; + new_col = *col + len; + } + if (*row >= PARTIALS_ROWS) { + return true; // display full + } + + if (!g_hash_table_add(callset, call)) { + return false; // already shown + } + + mvprintw(PARTIALS_Y0 + *row, PARTIALS_X0 + *col, "%s%s", + (space ? " " : ""), call); + + *col = new_col; + + if (*nr_suggested == 0) { // remember first partial call + strcpy(suggested_call, call); + } + *nr_suggested += 1; + + return false; // assume it's not full yet } int displayPartials(char *suggested_call) { - int row, col, k; - char *loc; - char printres[14] = ""; - int suggested = 0; - - const int hislen = strlen(current_qso.call); - - if (hislen < 2) { - return 0; // input too short - } - - row = 0; - col = 1; // 1 column left margin - - attron(modify_attr(COLOR_PAIR(C_LOG) | A_STANDOUT)); - - for (k = 0; k < PARTIALS_ROWS; k++) { - mvprintw(PARTIALS_Y0 + k, 0, "%*s", PARTIALS_COLS, ""); - } - - attrset(COLOR_PAIR(C_DUPE)); - mvaddstr(1, 1, "??"); - attron(COLOR_PAIR(C_LOG) | A_STANDOUT); - - /* check what we have worked first */ - /** \todo the method below parses through the array of already - * looked up search results from the search window. That is quick - * but has the drawback, that we have no band information and - * therefore print some entries more than once. - * Better would be to lookup the partial call in the array of - * worked stations 'callarray' - it is there only once and we can - * also see from 'call_band' if it is a dupe here. - * be aware of the problem of marking it dupe only for a complete - * match. - */ - if (dupe == ISDUPE) { - attrset(COLOR_PAIR(C_DUPE)); - } else { - attron(modify_attr(COLOR_PAIR(C_BORDER) | A_STANDOUT)); - } + int row, col, k; + char *loc; + char printres[14] = ""; + int suggested = 0; - GHashTable *callset = g_hash_table_new(g_str_hash, g_str_equal); - int full = 0; + const int hislen = strlen(current_qso.call); - for (k = 0; k < srch_index && !full; k++) { - if (strlen(searchresult[k]) <= 2) { - continue; // too short (unlikely) + if (hislen < 2) { + return 0; // input too short } - if (strstr(searchresult[k], current_qso.call) == NULL) { - continue; // not matching + + row = 0; + col = 1; // 1 column left margin + + attron(modify_attr(COLOR_PAIR(C_LOG) | A_STANDOUT)); + + for (k = 0; k < PARTIALS_ROWS; k++) { + mvprintw(PARTIALS_Y0 + k, 0, "%*s", PARTIALS_COLS, ""); } - printres[0] = '\0'; - strncat(printres, searchresult[k] + 29, 12); + attrset(COLOR_PAIR(C_DUPE)); + mvaddstr(1, 1, "??"); + attron(COLOR_PAIR(C_LOG) | A_STANDOUT); + + /* check what we have worked first */ + /** \todo the method below parses through the array of already + * looked up search results from the search window. That is quick + * but has the drawback, that we have no band information and + * therefore print some entries more than once. + * Better would be to lookup the partial call in the array of + * worked stations 'callarray' - it is there only once and we can + * also see from 'call_band' if it is a dupe here. + * be aware of the problem of marking it dupe only for a complete + * match. + */ + if (dupe == ISDUPE) { + attrset(COLOR_PAIR(C_DUPE)); + } else { + attron(modify_attr(COLOR_PAIR(C_BORDER) | A_STANDOUT)); + } - /* cut string just at first space after call */ - loc = strchr(printres, ' '); - if (loc) - *loc = '\0'; + GHashTable *callset = g_hash_table_new(g_str_hash, g_str_equal); + int full = 0; - full = show_partial(&row, &col, printres, callset, - &suggested, suggested_call); + for (k = 0; k < srch_index && !full; k++) { + if (strlen(searchresult[k]) <= 2) { + continue; // too short (unlikely) + } + if (strstr(searchresult[k], current_qso.call) == NULL) { + continue; // not matching + } - } + printres[0] = '\0'; + strncat(printres, searchresult[k] + 29, 12); - attron(COLOR_PAIR(C_LOG) | A_STANDOUT); - attroff(A_BOLD); + /* cut string just at first space after call */ + loc = strchr(printres, ' '); + if (loc) + *loc = '\0'; - /* and now check callmaster database */ + full = show_partial(&row, &col, printres, callset, + &suggested, suggested_call); - attron(modify_attr(COLOR_PAIR(C_LOG) | A_STANDOUT)); + } - // make 2 runs: fist look for calls starting with - // then the ones containing 'current_qso.call' - for (int run = 1; run <= 2; run++) { - for (k = 0; k < callmaster->len && !full; k++) { + attron(COLOR_PAIR(C_LOG) | A_STANDOUT); + attroff(A_BOLD); - char *mastercall = CALLMASTERARRAY(k); + /* and now check callmaster database */ - int match; - if (run == 1) { // starts with - match = (strncmp(mastercall, current_qso.call, hislen) == 0); - } else { // contains - match = (strstr(mastercall, current_qso.call) != NULL); - } + attron(modify_attr(COLOR_PAIR(C_LOG) | A_STANDOUT)); - if (!match) { - continue; // not matching - } + // make 2 runs: fist look for calls starting with + // then the ones containing 'current_qso.call' + for (int run = 1; run <= 2; run++) { + for (k = 0; k < callmaster->len && !full; k++) { - full = show_partial(&row, &col, mastercall, callset, - &suggested, suggested_call); + char *mastercall = CALLMASTERARRAY(k); + + int match; + if (run == 1) { // starts with + match = (strncmp(mastercall, current_qso.call, hislen) == 0); + } else { // contains + match = (strstr(mastercall, current_qso.call) != NULL); + } + + if (!match) { + continue; // not matching + } + full = show_partial(&row, &col, mastercall, callset, + &suggested, suggested_call); + + } } - } - g_hash_table_destroy(callset); + g_hash_table_destroy(callset); - return suggested; + return suggested; } /* Display list of partials and handle USEPARTIALS auto-completion */ void handlePartials(void) { - char suggested_call[LOGLINELEN + 1] = ""; - int nr_suggested; + char suggested_call[LOGLINELEN + 1] = ""; + int nr_suggested; - /* print list of partials in upper left region */ - nr_suggested = displayPartials(suggested_call); + /* print list of partials in upper left region */ + nr_suggested = displayPartials(suggested_call); - /* If only one partial call found and USEPARTIALS set, - * use that call for auto-completion. Can be blocked by - * pressing tab in calledit() function - */ - if ((nr_suggested == 1) && use_part && !block_part - && strlen(suggested_call) > strlen(current_qso.call)) { + /* If only one partial call found and USEPARTIALS set, + * use that call for auto-completion. Can be blocked by + * pressing tab in calledit() function + */ + if ((nr_suggested == 1) && use_part && !block_part + && strlen(suggested_call) > strlen(current_qso.call)) { - strcpy(current_qso.call, suggested_call); - beep(); - } + strcpy(current_qso.call, suggested_call); + beep(); + } } /* Parses searchresult and prepare string for searchwindow display from it */ void extractData(int index) { - g_strlcpy(result[index], searchresult[index], 7); /* band + mode */ + g_strlcpy(result[index], searchresult[index], 7); /* band + mode */ - if (show_time) // show qso time - strncat(result[index], searchresult[index] + 17, 5); - else // show qso number - strncat(result[index], searchresult[index] + 22, 5); + if (show_time) // show qso time + strncat(result[index], searchresult[index] + 17, 5); + else // show qso number + strncat(result[index], searchresult[index] + 22, 5); - strncat(result[index], searchresult[index] + 28, 12); /* call */ - strncat(result[index], searchresult[index] + 52, 16); /* exch */ + strncat(result[index], searchresult[index] + 28, 12); /* call */ + strncat(result[index], searchresult[index] + 52, 16); /* exch */ } /* find band from bandstring and choose line 'j' for display */ int bandstr2line(char *buffer) { - int j = 0; - - if (buffer[1] == '1' && buffer[2] == '0') - j = 1; - if (buffer[1] == '1' && buffer[2] == '5') - j = 2; - if (buffer[1] == '2') - j = 3; - if (buffer[1] == '4') - j = 4; - if (buffer[1] == '8') - j = 5; - if (buffer[1] == '6') - j = 6; - if (buffer[1] == '1' && buffer[2] == '2') - j = 7; - if (buffer[1] == '1' && buffer[2] == '7') - j = 8; - if (buffer[1] == '3' && buffer[2] == '0') - j = 9; - return j; + int j = 0; + + if (buffer[1] == '1' && buffer[2] == '0') + j = 1; + if (buffer[1] == '1' && buffer[2] == '5') + j = 2; + if (buffer[1] == '2') + j = 3; + if (buffer[1] == '4') + j = 4; + if (buffer[1] == '8') + j = 5; + if (buffer[1] == '6') + j = 6; + if (buffer[1] == '1' && buffer[2] == '2') + j = 7; + if (buffer[1] == '1' && buffer[2] == '7') + j = 8; + if (buffer[1] == '3' && buffer[2] == '0') + j = 9; + return j; } // @@ -377,11 +377,11 @@ int bandstr2line(char *buffer) { // static bool qso_has_current_mode(const struct qso_t *qso) { - if (!mixedmode) { - return true; // always true if not in mixed mode - } + if (!mixedmode) { + return true; // always true if not in mixed mode + } - return qso->mode == trxmode; + return qso->mode == trxmode; } @@ -390,46 +390,46 @@ static bool qso_has_current_mode(const struct qso_t *qso) { */ void filterLog(const char *call) { - srch_index = 0; + srch_index = 0; - for (int qso_index = 0; qso_index < NR_QSOS; qso_index++) { + for (int qso_index = 0; qso_index < NR_QSOS; qso_index++) { - struct qso_t *qso = g_ptr_array_index(qso_array, qso_index); - if (qso->is_comment) { - continue; - } + struct qso_t *qso = g_ptr_array_index(qso_array, qso_index); + if (qso->is_comment) { + continue; + } - if (!qso_has_current_mode(qso)) { - continue; // different mode - } + if (!qso_has_current_mode(qso)) { + continue; // different mode + } - if (strstr(qso->call, call) == 0) { - continue; // no match - } + if (strstr(qso->call, call) == 0) { + continue; // no match + } - g_strlcpy(searchresult[srch_index], QSOS(qso_index), 81); - extractData(srch_index); + g_strlcpy(searchresult[srch_index], QSOS(qso_index), 81); + extractData(srch_index); - if (srch_index++ > MAX_CALLS - 1) { - break; + if (srch_index++ > MAX_CALLS - 1) { + break; + } } - } } /* helper functions to check filtered lines for match with * current_qso.call or actual band */ static bool call_matches(const char *line) { - char buffer[20]; + char buffer[20]; - g_strlcpy(buffer, line + 12, 20); - *strchrnul(buffer, ' ') = '\0'; + g_strlcpy(buffer, line + 12, 20); + *strchrnul(buffer, ' ') = '\0'; - return (strcmp(buffer, current_qso.call) == 0); + return (strcmp(buffer, current_qso.call) == 0); } static bool band_matches(const char *line) { - return log_get_band(line) == bandinx; + return log_get_band(line) == bandinx; } // @@ -437,307 +437,307 @@ static bool band_matches(const char *line) { // static bool is_current_mode(const char *line) { - if (!mixedmode) { - return true; // always true if not in mixed mode - } + if (!mixedmode) { + return true; // always true if not in mixed mode + } - return log_get_mode(line) == trxmode; + return log_get_mode(line) == trxmode; } static bool line_matches_actual_qso(const char *line) { - if (call_matches(line) - && (band_matches(line) || qso_once) - && is_current_mode(line)) { + if (call_matches(line) + && (band_matches(line) || qso_once) + && is_current_mode(line)) { - int found = lookup_worked(current_qso.call); - if (worked_in_current_minitest_period(found)) { - return true; + int found = lookup_worked(current_qso.call); + if (worked_in_current_minitest_period(found)) { + return true; + } } - } - return false; + return false; } void displaySearchResults(void) { - int r_index; - char buffer[LOGLINELEN + 1] = ""; - char qtccall[15]; // temp str for qtc search - int z, l, j; - struct t_qtc_store_obj *qtc_temp_ptr; + int r_index; + char buffer[LOGLINELEN + 1] = ""; + char qtccall[15]; // temp str for qtc search + int z, l, j; + struct t_qtc_store_obj *qtc_temp_ptr; - dupe = NODUPE; + dupe = NODUPE; - /* print resulting call in line according to band in check window */ - for (r_index = 0; r_index < srch_index; r_index++) { - g_strlcpy(buffer, result[r_index], 38); + /* print resulting call in line according to band in check window */ + for (r_index = 0; r_index < srch_index; r_index++) { + g_strlcpy(buffer, result[r_index], 38); - wattrset(search_win, COLOR_PAIR(C_WINDOW) | A_STANDOUT); - if (!ignoredupe && line_matches_actual_qso(buffer)) { - wattrset(search_win, COLOR_PAIR(C_DUPE)); - dupe = ISDUPE; - beep(); - } + wattrset(search_win, COLOR_PAIR(C_WINDOW) | A_STANDOUT); + if (!ignoredupe && line_matches_actual_qso(buffer)) { + wattrset(search_win, COLOR_PAIR(C_DUPE)); + dupe = ISDUPE; + beep(); + } - /* display line in search window */ - j = bandstr2line(buffer); + /* display line in search window */ + j = bandstr2line(buffer); - if ((j < 7) || IsAllBand()) { - mvwaddstr(search_win, j, 1, buffer); - } + if ((j < 7) || IsAllBand()) { + mvwaddstr(search_win, j, 1, buffer); + } - if ((j > 0) && (j < 7)) { /* no WARC band */ - if (qtcdirection > 0) { - qtccall[0] = '\0'; - z = 12; // first pos of callsign - l = 0; - do { - qtccall[l] = buffer[z]; - z++; l++; - } while (buffer[z] != ' '); - qtccall[l] = '\0'; - - qtc_temp_ptr = qtc_get(qtccall); - qtcflags[j - 1] = qtc_get_value(qtc_temp_ptr); - } - } + if ((j > 0) && (j < 7)) { /* no WARC band */ + if (qtcdirection > 0) { + qtccall[0] = '\0'; + z = 12; // first pos of callsign + l = 0; + do { + qtccall[l] = buffer[z]; + z++; l++; + } while (buffer[z] != ' '); + qtccall[l] = '\0'; + + qtc_temp_ptr = qtc_get(qtccall); + qtcflags[j - 1] = qtc_get_value(qtc_temp_ptr); + } + } - buffer[0] = '\0'; - } + buffer[0] = '\0'; + } } void displayWorkedZonesCountries(int z) { - extern int pacc_qsos[10][10]; - extern int ja_cty; - extern int zl_cty; - extern int vk_cty; - extern int ua9_cty; - extern int lu_cty; - extern int py_cty; - extern int ce_cty; - extern int zs_cty; - - static int pxnr; - int pfxnumcntidx; - - /* print worked zones and countrys for each band in checkwindow */ - wattron(search_win, COLOR_PAIR(C_HEADER) | A_STANDOUT); - - if (qtcdirection > 0) { - for (int l = 0; l < 6; l++) { - if (qtcflags[l] != ' ') { - mvwprintw(search_win, l + 1, 35, "%c", qtcflags[l]); - } + extern int pacc_qsos[10][10]; + extern int ja_cty; + extern int zl_cty; + extern int vk_cty; + extern int ua9_cty; + extern int lu_cty; + extern int py_cty; + extern int ce_cty; + extern int zs_cty; + + static int pxnr; + int pfxnumcntidx; + + /* print worked zones and countrys for each band in checkwindow */ + wattron(search_win, COLOR_PAIR(C_HEADER) | A_STANDOUT); + + if (qtcdirection > 0) { + for (int l = 0; l < 6; l++) { + if (qtcflags[l] != ' ') { + mvwprintw(search_win, l + 1, 35, "%c", qtcflags[l]); + } + } } - } - if (CONTEST_IS(CQWW) || !iscontest || CONTEST_IS(PACC_PA)) { + if (CONTEST_IS(CQWW) || !iscontest || CONTEST_IS(PACC_PA)) { - if ((countries[countrynr] & BAND10) != 0) { - mvwaddstr(search_win, 1, 36, "C"); - mvwaddstr(search_win, 1, 1, " 10"); - } - if ((countries[countrynr] & BAND15) != 0) { - mvwaddstr(search_win, 2, 36, "C"); - mvwaddstr(search_win, 2, 1, " 15"); - } - if ((countries[countrynr] & BAND20) != 0) { - mvwaddstr(search_win, 3, 36, "C"); - mvwaddstr(search_win, 3, 1, " 20"); - } - if ((countries[countrynr] & BAND40) != 0) { - mvwaddstr(search_win, 4, 36, "C"); - mvwaddstr(search_win, 4, 1, " 40"); - } - if ((countries[countrynr] & BAND80) != 0) { - mvwaddstr(search_win, 5, 36, "C"); - mvwaddstr(search_win, 5, 1, " 80"); - } - if ((countries[countrynr] & BAND160) != 0) { - mvwaddstr(search_win, 6, 1, "160"); - mvwaddstr(search_win, 6, 36, "C"); - } - if (IsAllBand()) { - if ((countries[countrynr] & BAND12) != 0) { - mvwaddstr(search_win, 7, 1, " 12"); - mvwaddstr(search_win, 7, 36, "C"); - } - if ((countries[countrynr] & BAND17) != 0) { - mvwaddstr(search_win, 8, 1, " 17"); - mvwaddstr(search_win, 8, 36, "C"); - } - if ((countries[countrynr] & BAND30) != 0) { - mvwaddstr(search_win, 9, 1, " 30"); - mvwaddstr(search_win, 9, 36, "C"); - } - } - } - if (CONTEST_IS(CQWW) || wazmult || itumult) { - if ((zones[z] & BAND10) != 0) { - mvwaddstr(search_win, 1, 37, "Z"); - } - if ((zones[z] & BAND15) != 0) { - mvwaddstr(search_win, 2, 37, "Z"); - } - if ((zones[z] & BAND20) != 0) { - mvwaddstr(search_win, 3, 37, "Z"); - } - if ((zones[z] & BAND40) != 0) { - mvwaddstr(search_win, 4, 37, "Z"); - } - if ((zones[z] & BAND80) != 0) { - mvwaddstr(search_win, 5, 37, "Z"); + if ((countries[countrynr] & BAND10) != 0) { + mvwaddstr(search_win, 1, 36, "C"); + mvwaddstr(search_win, 1, 1, " 10"); + } + if ((countries[countrynr] & BAND15) != 0) { + mvwaddstr(search_win, 2, 36, "C"); + mvwaddstr(search_win, 2, 1, " 15"); + } + if ((countries[countrynr] & BAND20) != 0) { + mvwaddstr(search_win, 3, 36, "C"); + mvwaddstr(search_win, 3, 1, " 20"); + } + if ((countries[countrynr] & BAND40) != 0) { + mvwaddstr(search_win, 4, 36, "C"); + mvwaddstr(search_win, 4, 1, " 40"); + } + if ((countries[countrynr] & BAND80) != 0) { + mvwaddstr(search_win, 5, 36, "C"); + mvwaddstr(search_win, 5, 1, " 80"); + } + if ((countries[countrynr] & BAND160) != 0) { + mvwaddstr(search_win, 6, 1, "160"); + mvwaddstr(search_win, 6, 36, "C"); + } + if (IsAllBand()) { + if ((countries[countrynr] & BAND12) != 0) { + mvwaddstr(search_win, 7, 1, " 12"); + mvwaddstr(search_win, 7, 36, "C"); + } + if ((countries[countrynr] & BAND17) != 0) { + mvwaddstr(search_win, 8, 1, " 17"); + mvwaddstr(search_win, 8, 36, "C"); + } + if ((countries[countrynr] & BAND30) != 0) { + mvwaddstr(search_win, 9, 1, " 30"); + mvwaddstr(search_win, 9, 36, "C"); + } + } } - if ((zones[z] & BAND160) != 0) { - mvwaddstr(search_win, 6, 37, "Z"); + if (CONTEST_IS(CQWW) || wazmult || itumult) { + if ((zones[z] & BAND10) != 0) { + mvwaddstr(search_win, 1, 37, "Z"); + } + if ((zones[z] & BAND15) != 0) { + mvwaddstr(search_win, 2, 37, "Z"); + } + if ((zones[z] & BAND20) != 0) { + mvwaddstr(search_win, 3, 37, "Z"); + } + if ((zones[z] & BAND40) != 0) { + mvwaddstr(search_win, 4, 37, "Z"); + } + if ((zones[z] & BAND80) != 0) { + mvwaddstr(search_win, 5, 37, "Z"); + } + if ((zones[z] & BAND160) != 0) { + mvwaddstr(search_win, 6, 37, "Z"); + } } - } - if (CONTEST_IS(PACC_PA)) { + if (CONTEST_IS(PACC_PA)) { - getpx(current_qso.call); - pxnr = districtnumber(wpx_prefix); + getpx(current_qso.call); + pxnr = districtnumber(wpx_prefix); - if ((countrynr == w_cty) || - (countrynr == ve_cty) || - (countrynr == ja_cty) || - (countrynr == py_cty) || - (countrynr == lu_cty) || - (countrynr == ua9_cty) || - (countrynr == zl_cty) || - (countrynr == ce_cty) || - (countrynr == zs_cty) || - (countrynr == vk_cty)) { - if ((pacc_qsos[0][pxnr] & BAND160) == BAND160) - mvwaddstr(search_win, 6, 37, "M"); + if ((countrynr == w_cty) || + (countrynr == ve_cty) || + (countrynr == ja_cty) || + (countrynr == py_cty) || + (countrynr == lu_cty) || + (countrynr == ua9_cty) || + (countrynr == zl_cty) || + (countrynr == ce_cty) || + (countrynr == zs_cty) || + (countrynr == vk_cty)) { + if ((pacc_qsos[0][pxnr] & BAND160) == BAND160) + mvwaddstr(search_win, 6, 37, "M"); - if ((pacc_qsos[0][pxnr] & BAND80) == BAND80) - mvwaddstr(search_win, 5, 37, "M"); + if ((pacc_qsos[0][pxnr] & BAND80) == BAND80) + mvwaddstr(search_win, 5, 37, "M"); - if ((pacc_qsos[0][pxnr] & BAND40) == BAND40) - mvwaddstr(search_win, 4, 37, "M"); + if ((pacc_qsos[0][pxnr] & BAND40) == BAND40) + mvwaddstr(search_win, 4, 37, "M"); - if ((pacc_qsos[0][pxnr] & BAND20) == BAND20) - mvwaddstr(search_win, 3, 37, "M"); + if ((pacc_qsos[0][pxnr] & BAND20) == BAND20) + mvwaddstr(search_win, 3, 37, "M"); - if ((pacc_qsos[0][pxnr] & BAND15) == BAND15) - mvwaddstr(search_win, 2, 37, "M"); + if ((pacc_qsos[0][pxnr] & BAND15) == BAND15) + mvwaddstr(search_win, 2, 37, "M"); - if ((pacc_qsos[0][pxnr] & BAND10) == BAND10) - mvwaddstr(search_win, 1, 37, "M"); + if ((pacc_qsos[0][pxnr] & BAND10) == BAND10) + mvwaddstr(search_win, 1, 37, "M"); + } } - } - if ((pfxnummultinr >= 0 || country_mult) && iscontest) { - getpx(current_qso.call); - pxnr = districtnumber(wpx_prefix); + if ((pfxnummultinr >= 0 || country_mult) && iscontest) { + getpx(current_qso.call); + pxnr = districtnumber(wpx_prefix); - getctydata(current_qso.call); - pfxnumcntidx = -1; - int tbandidx = -1; + getctydata(current_qso.call); + pfxnumcntidx = -1; + int tbandidx = -1; - if (pfxnummultinr >= 0) { - int pfxi = 0; - while (pfxi < pfxnummultinr) { - if (pfxnummulti[pfxi].countrynr == countrynr) { - pfxnumcntidx = pfxi; - break; + if (pfxnummultinr >= 0) { + int pfxi = 0; + while (pfxi < pfxnummultinr) { + if (pfxnummulti[pfxi].countrynr == countrynr) { + pfxnumcntidx = pfxi; + break; + } + pfxi++; + } + } + if (pfxnumcntidx >= 0) { + tbandidx = pfxnummulti[pfxnumcntidx].qsos[pxnr]; + } else { + tbandidx = countries[countrynr]; } - pfxi++; - } - } - if (pfxnumcntidx >= 0) { - tbandidx = pfxnummulti[pfxnumcntidx].qsos[pxnr]; - } else { - tbandidx = countries[countrynr]; - } - if ((tbandidx & BAND160) == BAND160) { - mvwaddstr(search_win, 6, 37, "M"); - } - if ((tbandidx & BAND80) == BAND80) { - mvwaddstr(search_win, 5, 37, "M"); - } - if ((tbandidx & BAND40) == BAND40) { - mvwaddstr(search_win, 4, 37, "M"); - } - if ((tbandidx & BAND20) == BAND20) { - mvwaddstr(search_win, 3, 37, "M"); - } - if ((tbandidx & BAND15) == BAND15) { - mvwaddstr(search_win, 2, 37, "M"); - } - if ((tbandidx & BAND10) == BAND10) { - mvwaddstr(search_win, 1, 37, "M"); + if ((tbandidx & BAND160) == BAND160) { + mvwaddstr(search_win, 6, 37, "M"); + } + if ((tbandidx & BAND80) == BAND80) { + mvwaddstr(search_win, 5, 37, "M"); + } + if ((tbandidx & BAND40) == BAND40) { + mvwaddstr(search_win, 4, 37, "M"); + } + if ((tbandidx & BAND20) == BAND20) { + mvwaddstr(search_win, 3, 37, "M"); + } + if ((tbandidx & BAND15) == BAND15) { + mvwaddstr(search_win, 2, 37, "M"); + } + if ((tbandidx & BAND10) == BAND10) { + mvwaddstr(search_win, 1, 37, "M"); + } } - } } void searchlog() { - dxcc_data *dx; - int zone; + dxcc_data *dx; + int zone; - if (!initialized) { - InitSearchPanel(); - initialized = 1; - } + if (!initialized) { + InitSearchPanel(); + initialized = 1; + } - /* show checkwindow and partials */ - if (strlen(current_qso.call) > 1 && searchflg) { + /* show checkwindow and partials */ + if (strlen(current_qso.call) > 1 && searchflg) { - ShowSearchPanel(); - drawSearchWin(); + ShowSearchPanel(); + drawSearchWin(); - filterLog(current_qso.call); - displaySearchResults(); + filterLog(current_qso.call); + displaySearchResults(); - /* prepare and print lower line of checkwindow */ - dx = dxcc_by_index(countrynr); - get_proposed_exchange(); - displayCallInfo(dx, wpx_prefix); - zone = zone_nr(proposed_exchange); //TODO is this correct? - displayWorkedZonesCountries(zone); + /* prepare and print lower line of checkwindow */ + dx = dxcc_by_index(countrynr); + get_proposed_exchange(); + displayCallInfo(dx, wpx_prefix); + zone = zone_nr(proposed_exchange); //TODO is this correct? + displayWorkedZonesCountries(zone); - refreshp(); + refreshp(); - if (partials) { - handlePartials(); - } + if (partials) { + handlePartials(); + } - /* show needed sections for ARRL_Sweep Stake*/ - if (dupe == NODUPE && CONTEST_IS(ARRL_SS)) - show_needed_sections(); + /* show needed sections for ARRL_Sweep Stake*/ + if (dupe == NODUPE && CONTEST_IS(ARRL_SS)) + show_needed_sections(); - if (dupe == ISDUPE) { - attrset(COLOR_PAIR(C_DUPE)); - mvaddstr(12, 29, current_qso.call); - refreshp(); - usleep(500000); - } + if (dupe == ISDUPE) { + attrset(COLOR_PAIR(C_DUPE)); + mvaddstr(12, 29, current_qso.call); + refreshp(); + usleep(500000); + } - printcall(); + printcall(); - } else { - HideSearchPanel(); - } + } else { + HideSearchPanel(); + } } /* loading callmaster database */ static void init_callmaster(void) { - callmaster_version[0] = 0; - if (callmaster) { - g_ptr_array_free(callmaster, TRUE); - } - callmaster = g_ptr_array_new_full(CALLMASTER_SIZE, g_free); + callmaster_version[0] = 0; + if (callmaster) { + g_ptr_array_free(callmaster, TRUE); + } + callmaster = g_ptr_array_new_full(CALLMASTER_SIZE, g_free); } /** loads callmaster database from file @@ -745,30 +745,35 @@ static void init_callmaster(void) { */ int load_callmaster(void) { - FILE *cfp; - char *callmaster_location; - char* s_inputbuffer = NULL; + FILE *cfp; + char *callmaster_location; + char *s_inputbuffer = NULL; size_t s_inputbuffer_len = 186; int read; - init_callmaster(); + init_callmaster(); - if (callmaster_filename == NULL) + if (callmaster_filename == NULL) callmaster_filename = g_strdup(CALLMASTER_DEFAULT); - callmaster_location = find_available(callmaster_filename); + callmaster_location = find_available(callmaster_filename); - if ((cfp = fopen(callmaster_location, "r")) == NULL) { + if ((cfp = fopen(callmaster_location, "r")) == NULL) { g_free(callmaster_location); TLF_LOG_WARN("Error opening callmaster file."); return 0; - } - g_free(callmaster_location); + } + g_free(callmaster_location); - GHashTable *callset = g_hash_table_new(g_str_hash, g_str_equal); + GHashTable *callset = g_hash_table_new(g_str_hash, g_str_equal); - while((read = getline(&s_inputbuffer, &s_inputbuffer_len, cfp)) != -1) { + while ((read = getline(&s_inputbuffer, &s_inputbuffer_len, cfp)) != -1) { if (s_inputbuffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } g_strstrip(s_inputbuffer); /* skip comment lines and calls shorter than 3 chars */ @@ -799,10 +804,6 @@ int load_callmaster(void) { g_hash_table_add(callset, call); g_ptr_array_add(callmaster, call); } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } } g_hash_table_destroy(callset); @@ -818,61 +819,61 @@ int load_callmaster(void) { /* -------------------------------------------------------------- */ void show_needed_sections(void) { - int j, vert, hor, cnt, found; - char mprint[50]; + int j, vert, hor, cnt, found; + char mprint[50]; - if (CONTEST_IS(ARRL_SS)) { - cnt = 0; + if (CONTEST_IS(ARRL_SS)) { + cnt = 0; - wattron(search_win, modify_attr(COLOR_PAIR(C_WINDOW) | A_STANDOUT)); + wattron(search_win, modify_attr(COLOR_PAIR(C_WINDOW) | A_STANDOUT)); - for (j = 1; j < 7; j++) - mvwaddstr(search_win, j, 1, spaces(37)); + for (j = 1; j < 7; j++) + mvwaddstr(search_win, j, 1, spaces(37)); - for (vert = 1; vert < 7; vert++) { - if (cnt >= get_mult_count()) - break; + for (vert = 1; vert < 7; vert++) { + if (cnt >= get_mult_count()) + break; - for (hor = 0; hor < 9; hor++) { - if (cnt >= get_mult_count()) - break; + for (hor = 0; hor < 9; hor++) { + if (cnt >= get_mult_count()) + break; - strcpy(mprint, get_mult(cnt)); + strcpy(mprint, get_mult(cnt)); - found = 0; - for (j = 0; j < nr_multis; j++) { - if (strncmp(multis[j].name, mprint, strlen(mprint)) == 0) { - found = 1; - break; - } - } + found = 0; + for (j = 0; j < nr_multis; j++) { + if (strncmp(multis[j].name, mprint, strlen(mprint)) == 0) { + found = 1; + break; + } + } - if (found != 1) { - mprint[3] = '\0'; + if (found != 1) { + mprint[3] = '\0'; - wattron(search_win, - modify_attr(COLOR_PAIR(C_WINDOW) | A_STANDOUT)); + wattron(search_win, + modify_attr(COLOR_PAIR(C_WINDOW) | A_STANDOUT)); - if (strlen(mprint) > 1) - mvwprintw(search_win, vert, (hor * 4) + 2, "%s ", mprint); + if (strlen(mprint) > 1) + mvwprintw(search_win, vert, (hor * 4) + 2, "%s ", mprint); - } else - hor--; + } else + hor--; - cnt++; + cnt++; - } + } + } } - } - wnicebox(search_win, 0, 0, 6, 37, "Needed Sections"); - refreshp(); + wnicebox(search_win, 0, 0, 6, 37, "Needed Sections"); + refreshp(); } void OnLowerSearchPanel(int x, char *str) { - int y = 1 + (IsAllBand() ? 10 : 6); + int y = 1 + (IsAllBand() ? 10 : 6); - wattrset(search_win, modify_attr(COLOR_PAIR(C_BORDER))); - mvwaddstr(search_win, y, x, str); + wattrset(search_win, modify_attr(COLOR_PAIR(C_BORDER))); + mvwaddstr(search_win, y, x, str); } diff --git a/src/writecabrillo.c b/src/writecabrillo.c index 9e9aaa28..e0efdea9 100644 --- a/src/writecabrillo.c +++ b/src/writecabrillo.c @@ -51,38 +51,38 @@ void free_linedata(struct linedata_t *ptr); struct linedata_t *parse_logline(char *buffer) { - struct linedata_t *ptr; + struct linedata_t *ptr; - ptr = g_malloc0(sizeof(struct linedata_t)); + ptr = g_malloc0(sizeof(struct linedata_t)); - /* remember whole line */ - ptr->logline = g_strdup(buffer); - ptr->qtcdirection = 0; - ptr->qsots = 0; + /* remember whole line */ + ptr->logline = g_strdup(buffer); + ptr->qtcdirection = 0; + ptr->qsots = 0; - struct qso_t *qso = parse_qso(buffer); + struct qso_t *qso = parse_qso(buffer); - ptr-> band = qso->band; - ptr-> mode = qso->mode; - ptr-> day = qso->day; - ptr-> month = qso->month; - ptr-> year = qso->year; - ptr-> hour = qso->hour; - ptr-> min = qso->min; - ptr-> qso_nr = qso->qso_nr; - ptr-> call = qso->call; - ptr-> rst_s = qso->rst_s; - ptr-> rst_r = qso->rst_r; - ptr-> comment = qso->comment; - ptr-> freq = qso->freq; - ptr-> tx = qso->tx; + ptr-> band = qso->band; + ptr-> mode = qso->mode; + ptr-> day = qso->day; + ptr-> month = qso->month; + ptr-> year = qso->year; + ptr-> hour = qso->hour; + ptr-> min = qso->min; + ptr-> qso_nr = qso->qso_nr; + ptr-> call = qso->call; + ptr-> rst_s = qso->rst_s; + ptr-> rst_r = qso->rst_r; + ptr-> comment = qso->comment; + ptr-> freq = qso->freq; + ptr-> tx = qso->tx; - g_strchomp(ptr->comment); // remove trailing spaces + g_strchomp(ptr->comment); // remove trailing spaces - g_free(qso); /* free qso_t struct but not the + g_free(qso); /* free qso_t struct but not the allocated string copies */ - return ptr; + return ptr; } /** get next qso record from log @@ -94,26 +94,27 @@ struct linedata_t *parse_logline(char *buffer) { * \return ptr to new qso record (or NULL if eof) */ struct linedata_t *get_next_record(FILE *fp) { - char* buffer = NULL; - size_t buffer_len = 160; - struct linedata_t *ptr; - int read; - - while ((read = getline(&buffer, &buffer_len, fp)) != -1) { - if (buffer_len > 0) { - if (!log_is_comment(buffer)) { - ptr = parse_logline(buffer); - return ptr; - } - } - else { - perror("RuntimeError: "); - exit(EXIT_FAILURE); - } - } - if (buffer != NULL) - free(buffer); - return NULL; + char *buffer = NULL; + size_t buffer_len = 160; + struct linedata_t *ptr; + int read; + + while ((read = getline(&buffer, &buffer_len, fp)) != -1) { + if (buffer_len > 0) { + if (errno == ENOMEM) { + fprintf(stderr, "Error in: %s:%d", __FILE__, __LINE__); + perror("RuntimeError: "); + exit(EXIT_FAILURE); + } + if (!log_is_comment(buffer)) { + ptr = parse_logline(buffer); + return ptr; + } + } + } + if (buffer != NULL) + free(buffer); + return NULL; } /** get next qtc record from log @@ -125,349 +126,349 @@ struct linedata_t *get_next_record(FILE *fp) { * \return ptr to new qtc record (or NULL if eof) */ struct linedata_t *get_next_qtc_record(FILE *fp, int qtcdirection) { - char* buffer = NULL; - size_t buffer_len = 100; - char *tmp; - char *sp; - struct linedata_t *ptr; - int pos, shift, read; - struct tm date_n_time; - - if (fp == NULL) { - return NULL; - } - - if ((read = getline(&buffer, &buffer_len, fp)) == -1) { - return NULL; - } - - ptr = g_malloc0(sizeof(struct linedata_t)); - - /* remember whole line */ - ptr->logline = g_strdup(buffer); - ptr->qtcdirection = qtcdirection; - - /* tx */ - if (qtcdirection == RECV) { - pos = 28; - shift = 0; - } else { - pos = 33; - shift = 5; - } - ptr->tx = (buffer[pos] == ' ') ? 0 : 1; - - /* split buffer into parts for linedata_t record and parse - * them accordingly */ - tmp = strtok_r(buffer, " \t", &sp); - - /* band */ - ptr->band = atoi(tmp); - - /* mode */ - if (strcasestr(tmp, "CW")) - ptr->mode = CWMODE; - else if (strcasestr(tmp, "SSB")) - ptr->mode = SSBMODE; - else - ptr->mode = DIGIMODE; - - /* qso number */ - ptr->qso_nr = atoi(strtok_r(NULL, " \t", &sp)); - - /* in case of SEND direction, the 3rd field is the original number of sent QSO, - but it doesn't need for QTC line */ - if (qtcdirection & SEND) { - tmp = strtok_r(NULL, " \t", &sp); - } - /* date & time */ - memset(&date_n_time, 0, sizeof(struct tm)); - - strptime(strtok_r(NULL, " \t", &sp), DATE_FORMAT, &date_n_time); - strptime(strtok_r(NULL, " \t", &sp), TIME_FORMAT, &date_n_time); - - ptr->qsots = timegm(&date_n_time); - ptr->year = date_n_time.tm_year + 1900; /* convert to + char *buffer = NULL; + size_t buffer_len = 100; + char *tmp; + char *sp; + struct linedata_t *ptr; + int pos, shift, read; + struct tm date_n_time; + + if (fp == NULL) { + return NULL; + } + + if ((read = getline(&buffer, &buffer_len, fp)) == -1) { + return NULL; + } + + ptr = g_malloc0(sizeof(struct linedata_t)); + + /* remember whole line */ + ptr->logline = g_strdup(buffer); + ptr->qtcdirection = qtcdirection; + + /* tx */ + if (qtcdirection == RECV) { + pos = 28; + shift = 0; + } else { + pos = 33; + shift = 5; + } + ptr->tx = (buffer[pos] == ' ') ? 0 : 1; + + /* split buffer into parts for linedata_t record and parse + * them accordingly */ + tmp = strtok_r(buffer, " \t", &sp); + + /* band */ + ptr->band = atoi(tmp); + + /* mode */ + if (strcasestr(tmp, "CW")) + ptr->mode = CWMODE; + else if (strcasestr(tmp, "SSB")) + ptr->mode = SSBMODE; + else + ptr->mode = DIGIMODE; + + /* qso number */ + ptr->qso_nr = atoi(strtok_r(NULL, " \t", &sp)); + + /* in case of SEND direction, the 3rd field is the original number of sent QSO, + but it doesn't need for QTC line */ + if (qtcdirection & SEND) { + tmp = strtok_r(NULL, " \t", &sp); + } + /* date & time */ + memset(&date_n_time, 0, sizeof(struct tm)); + + strptime(strtok_r(NULL, " \t", &sp), DATE_FORMAT, &date_n_time); + strptime(strtok_r(NULL, " \t", &sp), TIME_FORMAT, &date_n_time); + + ptr->qsots = timegm(&date_n_time); + ptr->year = date_n_time.tm_year + 1900; /* convert to 1968..2067 */ - ptr->month = date_n_time.tm_mon + 1; /* tm_mon = 0..11 */ - ptr->day = date_n_time.tm_mday; - - ptr->hour = date_n_time.tm_hour; - ptr->min = date_n_time.tm_min; - - if (ptr->tx == 1) { - /* ignore TX if set */ - strtok_r(NULL, " \t", &sp); - } - /* his call */ - ptr->call = g_strdup(strtok_r(NULL, " \t", &sp)); - - /* QTC serial and number */ - ptr->qtc_serial = atoi(strtok_r(NULL, " \t", &sp)); - ptr->qtc_number = atoi(strtok_r(NULL, " \t", &sp)); - - ptr->qtc_qtime = g_strdup(strtok_r(NULL, " \t", &sp)); - ptr->qtc_qcall = g_strdup(strtok_r(NULL, " \t", &sp)); - ptr->qtc_qserial = g_strdup(strtok_r(NULL, " \t", &sp)); - - /* frequency */ - ptr->freq = atof(buffer + 80 + shift) * 1000.0; - if (freq2bandindex(ptr->freq) == BANDINDEX_OOB) { - ptr->freq = 0.; - } - - free(buffer); - return ptr; + ptr->month = date_n_time.tm_mon + 1; /* tm_mon = 0..11 */ + ptr->day = date_n_time.tm_mday; + + ptr->hour = date_n_time.tm_hour; + ptr->min = date_n_time.tm_min; + + if (ptr->tx == 1) { + /* ignore TX if set */ + strtok_r(NULL, " \t", &sp); + } + /* his call */ + ptr->call = g_strdup(strtok_r(NULL, " \t", &sp)); + + /* QTC serial and number */ + ptr->qtc_serial = atoi(strtok_r(NULL, " \t", &sp)); + ptr->qtc_number = atoi(strtok_r(NULL, " \t", &sp)); + + ptr->qtc_qtime = g_strdup(strtok_r(NULL, " \t", &sp)); + ptr->qtc_qcall = g_strdup(strtok_r(NULL, " \t", &sp)); + ptr->qtc_qserial = g_strdup(strtok_r(NULL, " \t", &sp)); + + /* frequency */ + ptr->freq = atof(buffer + 80 + shift) * 1000.0; + if (freq2bandindex(ptr->freq) == BANDINDEX_OOB) { + ptr->freq = 0.; + } + + free(buffer); + return ptr; } /** free linedata record pointed to by ptr */ void free_linedata(struct linedata_t *ptr) { - if (ptr != NULL) { - g_free(ptr->comment); - g_free(ptr->logline); - g_free(ptr->call); - if (ptr->qtc_qtime != NULL) { - g_free(ptr->qtc_qtime); - g_free(ptr->qtc_qcall); - g_free(ptr->qtc_qserial); - } - g_free(ptr); - } + if (ptr != NULL) { + g_free(ptr->comment); + g_free(ptr->logline); + g_free(ptr->call); + if (ptr->qtc_qtime != NULL) { + g_free(ptr->qtc_qtime); + g_free(ptr->qtc_qcall); + g_free(ptr->qtc_qserial); + } + g_free(ptr); + } } /** write out information */ void info(char *s) { - attron(modify_attr(COLOR_PAIR(C_INPUT) | A_STANDOUT)); - mvaddstr(13, 29, s); - refreshp(); + attron(modify_attr(COLOR_PAIR(C_INPUT) | A_STANDOUT)); + mvaddstr(13, 29, s); + refreshp(); } const char *to_mode[] = { - "CW", - "PH", - "RY" + "CW", + "PH", + "RY" }; /* add 'src' to 'dst' with max. 'len' chars left padded */ void add_lpadded(char *dst, char *src, int len) { - int l = strlen(src); - if (l > len) { - sprintf(dst, "!ERROR: field too wide (%s)", src); // overwrites buffer - return; - } + int l = strlen(src); + if (l > len) { + sprintf(dst, "!ERROR: field too wide (%s)", src); // overwrites buffer + return; + } - strcat(dst, " "); // add delimiter + strcat(dst, " "); // add delimiter - char *field = g_malloc(len + 1); - memset(field, ' ', len); - memcpy(field + len - l, src, l); - field[len] = '\0'; - strcat(dst, field); - g_free(field); + char *field = g_malloc(len + 1); + memset(field, ' ', len); + memcpy(field + len - l, src, l); + field[len] = '\0'; + strcat(dst, field); + g_free(field); } /* add 'src' to 'dst' with max. 'len' char right padded */ void add_rpadded(char *dst, char *src, int len) { - int l = strlen(src); - if (l > len) { - sprintf(dst, "!ERROR: field too wide (%s)", src); // overwrites buffer - return; - } + int l = strlen(src); + if (l > len) { + sprintf(dst, "!ERROR: field too wide (%s)", src); // overwrites buffer + return; + } - strcat(dst, " "); // add delimiter + strcat(dst, " "); // add delimiter - char *field = g_malloc(len + 1); - memset(field, ' ', len); - memcpy(field, src, l); - field[len] = '\0'; - strcat(dst, field); // add field - g_free(field); + char *field = g_malloc(len + 1); + memset(field, ' ', len); + memcpy(field, src, l); + field[len] = '\0'; + strcat(dst, field); // add field + g_free(field); } /* get the n-th token of a string, return empty string if no n-th token */ /* default separator is whitespace (space or tab) */ gchar *get_nth_token(gchar *str, int n, const char *separator) { - gchar *string = g_strdup(str); - const char *delim = (separator != NULL ? separator : " \t"); - gchar *ptr; - char *sp; - - ptr = strtok_r(string, delim, &sp); - - while (n > 0 && ptr != NULL) { - ptr = strtok_r(NULL, delim, &sp); - n--; - } - - /* if no n-th element in string, return empty string */ - if (ptr == NULL) - ptr = strdup(""); - else - ptr = strdup(ptr); - - g_free(string); - return ptr; + gchar *string = g_strdup(str); + const char *delim = (separator != NULL ? separator : " \t"); + gchar *ptr; + char *sp; + + ptr = strtok_r(string, delim, &sp); + + while (n > 0 && ptr != NULL) { + ptr = strtok_r(NULL, delim, &sp); + n--; + } + + /* if no n-th element in string, return empty string */ + if (ptr == NULL) + ptr = strdup(""); + else + ptr = strdup(ptr); + + g_free(string); + return ptr; } static gchar *get_sent_exchage(int qso_nr) { - char number[6]; - sprintf(number, "%04d", qso_nr); - gchar *result = g_strndup(exchange, 80); - replace_n(result, 80, "#", number, 99); - return result; + char number[6]; + sprintf(number, "%04d", qso_nr); + gchar *result = g_strndup(exchange, 80); + replace_n(result, 80, "#", number, 99); + return result; } /* format QSO: or QTC: line according to Cabrillo format description * and put it into buffer */ void prepare_line(struct linedata_t *qso, struct cabrillo_desc *desc, - char *buf) { - - freq_t freq; - int i; - char tmp[80]; - struct line_item *item; - gchar *token; - int item_count; - GPtrArray *item_array; - - if (qso == NULL) { - strcpy(buf, ""); - return; - } - - freq = qso->freq; - if (freq == 0) - freq = (freq_t) band2freq(qso->band); - - if (qso->qtcdirection == 0) { - strcpy(buf, "QSO:"); /* start the line */ - item_count = desc->item_count; - item_array = desc->item_array; - } else { - if (desc->qtc_item_array == NULL) { - strcpy(buf, ""); /* no QTC format description */ - return; - } - strcpy(buf, "QTC:"); /* start the line */ - item_count = desc->qtc_item_count; - item_array = desc->qtc_item_array; - } - - for (i = 0; i < item_count; i++) { - item = g_ptr_array_index(item_array, i); - switch (item->tag) { - case FREQ: - sprintf(tmp, "%d", (int)(freq / 1000.0)); - add_lpadded(buf, tmp, item->len); - break; - case MODE: - sprintf(tmp, "%s", to_mode[qso->mode]); - add_lpadded(buf, tmp, item->len); - break; - case DATE: - sprintf(tmp, "%4d-%02d-%02d", - qso->year, qso->month, qso->day); - add_lpadded(buf, tmp, item->len); - break; - case TIME: - sprintf(tmp, "%02d%02d", qso->hour, qso->min); - add_lpadded(buf, tmp, item->len); - break; - case MYCALL: - add_rpadded(buf, my.call, item->len); - break; - case HISCALL: - add_rpadded(buf, qso->call, item->len); - break; - case RST_S: - sprintf(tmp, "%d", qso->rst_s); - add_rpadded(buf, tmp, item->len); - break; - case RST_R: - sprintf(tmp, "%d", qso->rst_r); - add_rpadded(buf, tmp, item->len); - break; - case EXCH: - add_rpadded(buf, qso->comment, item->len); - break; - case EXC1: - token = get_nth_token(qso->comment, 0, desc->exchange_separator); - add_rpadded(buf, token, item->len); - g_free(token); - break; - case EXC2: - token = get_nth_token(qso->comment, 1, desc->exchange_separator); - add_rpadded(buf, token, item->len); - g_free(token); - break; - case EXC3: - token = get_nth_token(qso->comment, 2, desc->exchange_separator); - add_rpadded(buf, token, item->len); - g_free(token); - break; - case EXC4: - token = get_nth_token(qso->comment, 3, desc->exchange_separator); - add_rpadded(buf, token, item->len); - g_free(token); - break; - case EXC_S: - token = get_sent_exchage(qso->qso_nr); - add_rpadded(buf, token, item->len); - g_free(token); - break; - case TX: - sprintf(tmp, "%1d", qso->tx); - add_rpadded(buf, tmp, item->len); - break; - case QTCRCALL: - if (qso->qtcdirection == 1) { // RECV - strcpy(tmp, my.call); - } - if (qso->qtcdirection == 2) { // SEND - strcpy(tmp, qso->call); + char *buf) { + + freq_t freq; + int i; + char tmp[80]; + struct line_item *item; + gchar *token; + int item_count; + GPtrArray *item_array; + + if (qso == NULL) { + strcpy(buf, ""); + return; + } + + freq = qso->freq; + if (freq == 0) + freq = (freq_t) band2freq(qso->band); + + if (qso->qtcdirection == 0) { + strcpy(buf, "QSO:"); /* start the line */ + item_count = desc->item_count; + item_array = desc->item_array; + } else { + if (desc->qtc_item_array == NULL) { + strcpy(buf, ""); /* no QTC format description */ + return; } - add_rpadded(buf, g_strchomp(tmp), item->len); - break; - case QTCHEAD: - tmp[0] = '\0'; - sprintf(tmp, "%*d/%d", 3, qso->qtc_serial, qso->qtc_number); - add_rpadded(buf, g_strchomp(tmp), item->len); - break; - case QTCSCALL: - if (qso->qtcdirection == 1) { // RECV - strcpy(tmp, qso->call); + strcpy(buf, "QTC:"); /* start the line */ + item_count = desc->qtc_item_count; + item_array = desc->qtc_item_array; + } + + for (i = 0; i < item_count; i++) { + item = g_ptr_array_index(item_array, i); + switch (item->tag) { + case FREQ: + sprintf(tmp, "%d", (int)(freq / 1000.0)); + add_lpadded(buf, tmp, item->len); + break; + case MODE: + sprintf(tmp, "%s", to_mode[qso->mode]); + add_lpadded(buf, tmp, item->len); + break; + case DATE: + sprintf(tmp, "%4d-%02d-%02d", + qso->year, qso->month, qso->day); + add_lpadded(buf, tmp, item->len); + break; + case TIME: + sprintf(tmp, "%02d%02d", qso->hour, qso->min); + add_lpadded(buf, tmp, item->len); + break; + case MYCALL: + add_rpadded(buf, my.call, item->len); + break; + case HISCALL: + add_rpadded(buf, qso->call, item->len); + break; + case RST_S: + sprintf(tmp, "%d", qso->rst_s); + add_rpadded(buf, tmp, item->len); + break; + case RST_R: + sprintf(tmp, "%d", qso->rst_r); + add_rpadded(buf, tmp, item->len); + break; + case EXCH: + add_rpadded(buf, qso->comment, item->len); + break; + case EXC1: + token = get_nth_token(qso->comment, 0, desc->exchange_separator); + add_rpadded(buf, token, item->len); + g_free(token); + break; + case EXC2: + token = get_nth_token(qso->comment, 1, desc->exchange_separator); + add_rpadded(buf, token, item->len); + g_free(token); + break; + case EXC3: + token = get_nth_token(qso->comment, 2, desc->exchange_separator); + add_rpadded(buf, token, item->len); + g_free(token); + break; + case EXC4: + token = get_nth_token(qso->comment, 3, desc->exchange_separator); + add_rpadded(buf, token, item->len); + g_free(token); + break; + case EXC_S: + token = get_sent_exchage(qso->qso_nr); + add_rpadded(buf, token, item->len); + g_free(token); + break; + case TX: + sprintf(tmp, "%1d", qso->tx); + add_rpadded(buf, tmp, item->len); + break; + case QTCRCALL: + if (qso->qtcdirection == 1) { // RECV + strcpy(tmp, my.call); + } + if (qso->qtcdirection == 2) { // SEND + strcpy(tmp, qso->call); + } + add_rpadded(buf, g_strchomp(tmp), item->len); + break; + case QTCHEAD: + tmp[0] = '\0'; + sprintf(tmp, "%*d/%d", 3, qso->qtc_serial, qso->qtc_number); + add_rpadded(buf, g_strchomp(tmp), item->len); + break; + case QTCSCALL: + if (qso->qtcdirection == 1) { // RECV + strcpy(tmp, qso->call); + } + if (qso->qtcdirection == 2) { // SEND + strcpy(tmp, my.call); + } + add_rpadded(buf, g_strchomp(tmp), item->len); + break; + case QTC: + sprintf(tmp, "%s %-13s %4s", qso->qtc_qtime, qso->qtc_qcall, qso->qtc_qserial); + add_rpadded(buf, g_strchomp(tmp), item->len); + break; + case NO_ITEM: + default: + ; // no action } - if (qso->qtcdirection == 2) { // SEND - strcpy(tmp, my.call); + if (buf[0] == '!') { + break; // there was an error } - add_rpadded(buf, g_strchomp(tmp), item->len); - break; - case QTC: - sprintf(tmp, "%s %-13s %4s", qso->qtc_qtime, qso->qtc_qcall, qso->qtc_qserial); - add_rpadded(buf, g_strchomp(tmp), item->len); - break; - case NO_ITEM: - default: - ; // no action - } - if (buf[0] == '!') { - break; // there was an error - } - } - strcat(buf, "\n"); /* closing nl */ + } + strcat(buf, "\n"); /* closing nl */ } static void set_exchange_format() { - if (contest->exchange_serial) { - strcpy(exchange, "#"); // contest is using serial number - return; - } - get_cabrillo_field_value(find_cabrillo_field(CBR_EXCHANGE), exchange, - sizeof(exchange)); + if (contest->exchange_serial) { + strcpy(exchange, "#"); // contest is using serial number + return; + } + get_cabrillo_field_value(find_cabrillo_field(CBR_EXCHANGE), exchange, + sizeof(exchange)); } // @@ -479,173 +480,173 @@ static void set_exchange_format() { // the error text starting with an exclamation mark // static bool process_record(struct linedata_t *qso, - struct cabrillo_desc *cabdesc, - char *buffer, FILE *fp2) { + struct cabrillo_desc *cabdesc, + char *buffer, FILE *fp2) { - prepare_line(qso, cabdesc, buffer); - free_linedata(qso); + prepare_line(qso, cabdesc, buffer); + free_linedata(qso); - if (strlen(buffer) > 5) { - fputs(buffer, fp2); - } + if (strlen(buffer) > 5) { + fputs(buffer, fp2); + } - bool ok = true; - if (buffer[0] == '!') { - g_strchomp(buffer); - info(buffer + 1); // show error message - sleep(2); - ok = false; - } + bool ok = true; + if (buffer[0] == '!') { + g_strchomp(buffer); + info(buffer + 1); // show error message + sleep(2); + ok = false; + } - return ok; + return ok; } int write_cabrillo(void) { - struct cabrillo_desc *cabdesc; - char cabrillo_file_name[80]; - char buffer[4000] = ""; + struct cabrillo_desc *cabdesc; + char cabrillo_file_name[80]; + char buffer[4000] = ""; - FILE *fp1, *fp2, *fpqtcrec = NULL, *fpqtcsent = NULL; - struct linedata_t *qso, *qtcrec = NULL, *qtcsent = NULL; - int qsonr, qtcrecnr, qtcsentnr; + FILE *fp1, *fp2, *fpqtcrec = NULL, *fpqtcsent = NULL; + struct linedata_t *qso, *qtcrec = NULL, *qtcsent = NULL; + int qsonr, qtcrecnr, qtcsentnr; - if (cabrillo == NULL) { - info("Missing CABRILLO= keyword (see man page)"); - sleep(2); - return 1; - } + if (cabrillo == NULL) { + info("Missing CABRILLO= keyword (see man page)"); + sleep(2); + return 1; + } - char *cab_file = find_available("cabrillo.fmt"); + char *cab_file = find_available("cabrillo.fmt"); - cabdesc = read_cabrillo_format(cab_file, cabrillo); + cabdesc = read_cabrillo_format(cab_file, cabrillo); - g_free(cab_file); + g_free(cab_file); - if (!cabdesc) { - info("Cabrillo format specification not found!"); - sleep(2); - return 2; - } + if (!cabdesc) { + info("Cabrillo format specification not found!"); + sleep(2); + return 2; + } - /* open logfile and create a Cabrillo file */ - if ((fp1 = fopen(logfile, "r")) == NULL) { - info("Can't open logfile."); - sleep(2); - free_cabfmt(cabdesc); - return 1; - } - if (cabdesc->qtc_item_array != NULL) { - if (qtcdirection & 1) { - fpqtcrec = fopen(QTC_RECV_LOG, "r"); - if (fpqtcrec == NULL) { - info("Can't open received QTC logfile."); + /* open logfile and create a Cabrillo file */ + if ((fp1 = fopen(logfile, "r")) == NULL) { + info("Can't open logfile."); sleep(2); free_cabfmt(cabdesc); - fclose(fp1); return 1; - } } - if (qtcdirection & 2) { - fpqtcsent = fopen(QTC_SENT_LOG, "r"); - if (fpqtcsent == NULL) { - info("Can't open sent QTC logfile."); + if (cabdesc->qtc_item_array != NULL) { + if (qtcdirection & 1) { + fpqtcrec = fopen(QTC_RECV_LOG, "r"); + if (fpqtcrec == NULL) { + info("Can't open received QTC logfile."); + sleep(2); + free_cabfmt(cabdesc); + fclose(fp1); + return 1; + } + } + if (qtcdirection & 2) { + fpqtcsent = fopen(QTC_SENT_LOG, "r"); + if (fpqtcsent == NULL) { + info("Can't open sent QTC logfile."); + sleep(2); + free_cabfmt(cabdesc); + fclose(fp1); + if (fpqtcrec != NULL) fclose(fpqtcrec); + return 1; + } + } + } + + get_cabrillo_file_name(cabrillo_file_name); + if ((fp2 = fopen(cabrillo_file_name, "w")) == NULL) { + info("Can't create Cabrillo file."); sleep(2); free_cabfmt(cabdesc); fclose(fp1); + if (fpqtcsent != NULL) fclose(fpqtcsent); if (fpqtcrec != NULL) fclose(fpqtcrec); - return 1; - } + return 2; } - } - - get_cabrillo_file_name(cabrillo_file_name); - if ((fp2 = fopen(cabrillo_file_name, "w")) == NULL) { - info("Can't create Cabrillo file."); - sleep(2); - free_cabfmt(cabdesc); - fclose(fp1); - if (fpqtcsent != NULL) fclose(fpqtcsent); - if (fpqtcrec != NULL) fclose(fpqtcrec); - return 2; - } - - /* exchange and header information */ - set_exchange_format(); - write_cabrillo_header(fp2); + /* exchange and header information */ + set_exchange_format(); - time_t start_time = get_time(); - info("Writing Cabrillo file"); + write_cabrillo_header(fp2); - qsonr = 0; - qtcrecnr = 0; - qtcsentnr = 0; - bool ok = true; - while (ok && (qso = get_next_record(fp1))) { + time_t start_time = get_time(); + info("Writing Cabrillo file"); - qsonr++; - ok = process_record(qso, cabdesc, buffer, fp2); - if (!ok) { - break; // stop processing immediately - } + qsonr = 0; + qtcrecnr = 0; + qtcsentnr = 0; + bool ok = true; + while (ok && (qso = get_next_record(fp1))) { - if (fpqtcrec != NULL && qtcrec == NULL) { - qtcrec = get_next_qtc_record(fpqtcrec, RECV); - if (qtcrec != NULL) { - qtcrecnr = qtcrec->qso_nr; - } - } - if (fpqtcsent != NULL && qtcsent == NULL) { - qtcsent = get_next_qtc_record(fpqtcsent, SEND); - if (qtcsent != NULL) { - qtcsentnr = qtcsent->qso_nr; - } - } - while (qtcrecnr == qsonr || qtcsentnr == qsonr) { - if (qtcsent == NULL || (qtcrec != NULL && qtcrec->qsots < qtcsent->qsots)) { - ok = process_record(qtcrec, cabdesc, buffer, fp2); + qsonr++; + ok = process_record(qso, cabdesc, buffer, fp2); + if (!ok) { + break; // stop processing immediately + } - qtcrec = get_next_qtc_record(fpqtcrec, RECV); - if (qtcrec != NULL) { - qtcrecnr = qtcrec->qso_nr; - } else { - qtcrecnr = 0; + if (fpqtcrec != NULL && qtcrec == NULL) { + qtcrec = get_next_qtc_record(fpqtcrec, RECV); + if (qtcrec != NULL) { + qtcrecnr = qtcrec->qso_nr; + } } - } else { - ok = process_record(qtcsent, cabdesc, buffer, fp2); - - qtcsent = get_next_qtc_record(fpqtcsent, SEND); - if (qtcsent != NULL) { - qtcsentnr = qtcsent->qso_nr; - } else { - qtcsentnr = 0; + if (fpqtcsent != NULL && qtcsent == NULL) { + qtcsent = get_next_qtc_record(fpqtcsent, SEND); + if (qtcsent != NULL) { + qtcsentnr = qtcsent->qso_nr; + } + } + while (qtcrecnr == qsonr || qtcsentnr == qsonr) { + if (qtcsent == NULL || (qtcrec != NULL && qtcrec->qsots < qtcsent->qsots)) { + ok = process_record(qtcrec, cabdesc, buffer, fp2); + + qtcrec = get_next_qtc_record(fpqtcrec, RECV); + if (qtcrec != NULL) { + qtcrecnr = qtcrec->qso_nr; + } else { + qtcrecnr = 0; + } + } else { + ok = process_record(qtcsent, cabdesc, buffer, fp2); + + qtcsent = get_next_qtc_record(fpqtcsent, SEND); + if (qtcsent != NULL) { + qtcsentnr = qtcsent->qso_nr; + } else { + qtcsentnr = 0; + } + } + + if (!ok) { + break; // stop QTC processing, will exit main loop later + } } - } - if (!ok) { - break; // stop QTC processing, will exit main loop later - } } - } - - fclose(fp1); + fclose(fp1); - fputs("END-OF-LOG:\n", fp2); - fclose(fp2); - if (fpqtcrec != NULL) { - fclose(fpqtcrec); - } + fputs("END-OF-LOG:\n", fp2); + fclose(fp2); + if (fpqtcrec != NULL) { + fclose(fpqtcrec); + } - free_cabfmt(cabdesc); + free_cabfmt(cabdesc); - if (get_time() == start_time) { - sleep(1); - } + if (get_time() == start_time) { + sleep(1); + } - return 0; + return 0; } @@ -653,125 +654,125 @@ int write_cabrillo(void) { void add_adif_field(char *adif_line, char *field, char *value) { - char *tmp; - - if (strlen(field) == 0) - return; - - if (value == NULL) { - tmp = g_strdup_printf("<%s>", field); - } else { - tmp = g_strdup_printf("<%s:%zd>%s", - field, strlen(value), value); - } - strcat(adif_line, tmp); - g_free(tmp); + char *tmp; + + if (strlen(field) == 0) + return; + + if (value == NULL) { + tmp = g_strdup_printf("<%s>", field); + } else { + tmp = g_strdup_printf("<%s:%zd>%s", + field, strlen(value), value); + } + strcat(adif_line, tmp); + g_free(tmp); } void add_adif_field_formated(char *buffer, char *field, char *fmt, ...) { - va_list args; - char *value; + va_list args; + char *value; - va_start(args, fmt); - value = g_strdup_vprintf(fmt, args); - va_end(args); + va_start(args, fmt); + value = g_strdup_vprintf(fmt, args); + va_end(args); - add_adif_field(buffer, field, value); - g_free(value); + add_adif_field(buffer, field, value); + g_free(value); } /* write ADIF header to open file */ void write_adif_header(FILE *fp) { - char timebuf[100]; - - fputs - ("################################################################################\n", - fp); - fputs("# ADIF v3.10 data file exported by TLF\n", fp); - fputs("# according to specifications on http://www.adif.org\n", - fp); - fputs - ("################################################################################\n", - fp); - - format_time(timebuf, sizeof(timebuf), CREATED_DATE_TIME_FORMAT); - fprintf(fp, "Created %s for %s\n\n", timebuf, my.call); - - /* Write contest name */ - fprintf(fp, "Contest Name: %s\n", whichcontest); - fputs("3.10\n", fp); - fputs("TLF\n", fp); - fprintf(fp, "%s\n", strlen(VERSION), VERSION); - fputs("\n", fp); + char timebuf[100]; + + fputs + ("################################################################################\n", + fp); + fputs("# ADIF v3.10 data file exported by TLF\n", fp); + fputs("# according to specifications on http://www.adif.org\n", + fp); + fputs + ("################################################################################\n", + fp); + + format_time(timebuf, sizeof(timebuf), CREATED_DATE_TIME_FORMAT); + fprintf(fp, "Created %s for %s\n\n", timebuf, my.call); + + /* Write contest name */ + fprintf(fp, "Contest Name: %s\n", whichcontest); + fputs("3.10\n", fp); + fputs("TLF\n", fp); + fprintf(fp, "%s\n", strlen(VERSION), VERSION); + fputs("\n", fp); } /* format QSO line from buf according to ADIF format description * and put it into buffer */ void prepare_adif_line(char *buffer, struct linedata_t *qso) { - char *tmp; - - strcpy(buffer, ""); - - /* CALLSIGN */ - add_adif_field(buffer, "CALL", qso->call); - - /* BAND */ - add_adif_field_formated(buffer, "BAND", "%dM", qso->band); - - /* FREQ if available */ - if (qso->freq > 0) { - // write MHz - add_adif_field_formated(buffer, "FREQ", "%.4f", - qso->freq / 1000000.0); - } - - /* QSO MODE */ - if (qso->mode == CWMODE) - tmp = "CW"; - else if (qso->mode == SSBMODE) - tmp = "SSB"; - else if (strcmp(modem_mode, "RTTY") == 0) - tmp = "RTTY"; - else - /* \todo DIGI is no allowed mode */ - tmp = "DIGI"; - add_adif_field(buffer, "MODE", tmp); - - /* QSO_DATE */ - add_adif_field_formated(buffer, "QSO_DATE", "%4d%02d%02d", - qso->year, qso->month, qso->day); - - /* TIME_ON */ - add_adif_field_formated(buffer, "TIME_ON", "%02d%02d", - qso->hour, qso->min); - - /* RST_SENT */ - if (!no_rst) { - add_adif_field_formated(buffer, "RST_SENT", "%d", qso->rst_s); - } - - /* Sent contest serial number or exchange */ - bool serial_only = (strcmp(exchange, "#") == 0); - tmp = get_sent_exchage(qso->qso_nr); - g_strstrip(tmp); - add_adif_field(buffer, (serial_only ? "STX" : "STX_STRING"), tmp); - g_free(tmp); - - /* RST_RCVD */ - if (!no_rst) { - add_adif_field_formated(buffer, "RST_RCVD", "%d", qso->rst_r); - } - - /* Received contest serial number or exchange */ - tmp = g_strdup(qso->comment); - g_strstrip(tmp); - add_adif_field(buffer, (serial_only ? "SRX" : "SRX_STRING"), tmp); - g_free(tmp); - - /* - end of ADIF row */ - strcat(buffer, "\n"); + char *tmp; + + strcpy(buffer, ""); + + /* CALLSIGN */ + add_adif_field(buffer, "CALL", qso->call); + + /* BAND */ + add_adif_field_formated(buffer, "BAND", "%dM", qso->band); + + /* FREQ if available */ + if (qso->freq > 0) { + // write MHz + add_adif_field_formated(buffer, "FREQ", "%.4f", + qso->freq / 1000000.0); + } + + /* QSO MODE */ + if (qso->mode == CWMODE) + tmp = "CW"; + else if (qso->mode == SSBMODE) + tmp = "SSB"; + else if (strcmp(modem_mode, "RTTY") == 0) + tmp = "RTTY"; + else + /* \todo DIGI is no allowed mode */ + tmp = "DIGI"; + add_adif_field(buffer, "MODE", tmp); + + /* QSO_DATE */ + add_adif_field_formated(buffer, "QSO_DATE", "%4d%02d%02d", + qso->year, qso->month, qso->day); + + /* TIME_ON */ + add_adif_field_formated(buffer, "TIME_ON", "%02d%02d", + qso->hour, qso->min); + + /* RST_SENT */ + if (!no_rst) { + add_adif_field_formated(buffer, "RST_SENT", "%d", qso->rst_s); + } + + /* Sent contest serial number or exchange */ + bool serial_only = (strcmp(exchange, "#") == 0); + tmp = get_sent_exchage(qso->qso_nr); + g_strstrip(tmp); + add_adif_field(buffer, (serial_only ? "STX" : "STX_STRING"), tmp); + g_free(tmp); + + /* RST_RCVD */ + if (!no_rst) { + add_adif_field_formated(buffer, "RST_RCVD", "%d", qso->rst_r); + } + + /* Received contest serial number or exchange */ + tmp = g_strdup(qso->comment); + g_strstrip(tmp); + add_adif_field(buffer, (serial_only ? "SRX" : "SRX_STRING"), tmp); + g_free(tmp); + + /* - end of ADIF row */ + strcat(buffer, "\n"); } /* @@ -780,51 +781,51 @@ void prepare_adif_line(char *buffer, struct linedata_t *qso) { */ int write_adif(void) { - struct linedata_t *qso; - char buffer[181] = ""; - char adif_tmp_name[40] = ""; + struct linedata_t *qso; + char buffer[181] = ""; + char adif_tmp_name[40] = ""; - FILE *fp1, *fp2; + FILE *fp1, *fp2; - if ((fp1 = fopen(logfile, "r")) == NULL) { - info("Opening logfile not possible."); - sleep(2); - return 1; - } - strcpy(adif_tmp_name, whichcontest); - strcat(adif_tmp_name, ".adi"); + if ((fp1 = fopen(logfile, "r")) == NULL) { + info("Opening logfile not possible."); + sleep(2); + return 1; + } + strcpy(adif_tmp_name, whichcontest); + strcat(adif_tmp_name, ".adi"); - if ((fp2 = fopen(adif_tmp_name, "w")) == NULL) { - info("Opening ADIF file not possible."); - sleep(2); - fclose(fp1); //added by F8CFE - return 2; - } + if ((fp2 = fopen(adif_tmp_name, "w")) == NULL) { + info("Opening ADIF file not possible."); + sleep(2); + fclose(fp1); //added by F8CFE + return 2; + } - /* in case using write_adif() without write_cabrillo() before - * just get the needed information */ - set_exchange_format(); + /* in case using write_adif() without write_cabrillo() before + * just get the needed information */ + set_exchange_format(); - time_t start_time = get_time(); - info("Writing ADIF file"); + time_t start_time = get_time(); + info("Writing ADIF file"); - write_adif_header(fp2); + write_adif_header(fp2); - while ((qso = get_next_record(fp1))) { + while ((qso = get_next_record(fp1))) { - prepare_adif_line(buffer, qso); - fputs(buffer, fp2); + prepare_adif_line(buffer, qso); + fputs(buffer, fp2); - free_linedata(qso); - } + free_linedata(qso); + } - fclose(fp1); - fclose(fp2); + fclose(fp1); + fclose(fp2); - if (get_time() == start_time) { - sleep(1); - } + if (get_time() == start_time) { + sleep(1); + } - return 0; + return 0; } // end write_adif diff --git a/tools/astylerc b/tools/astylerc index 780e9a4f..73c11287 100644 --- a/tools/astylerc +++ b/tools/astylerc @@ -3,8 +3,8 @@ # K&R style formatting/indenting with some tweaks. style=attach -# Indent with a width of 4 spaces. Use 8 space tabs if possible -# indent=force-tab-x=8 +# Indent with a width of 4 spaces. Use 4 space tabs if possible +indent=force-tab-x=4 indent=force-tab=4 # Pad empty lines around header blocks (e.g. 'if', 'for', 'while'...).