Skip to content

Commit

Permalink
Boolean configs can be both set or unset (#358)
Browse files Browse the repository at this point in the history
* in addition migrate NO_LEADING_ZEROS_SERIAL to LEADING_ZEROS_SERIAL
  • Loading branch information
zcsahok authored Nov 11, 2022
1 parent 8fa8dd9 commit fc4b0f0
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 121 deletions.
2 changes: 1 addition & 1 deletion src/globalvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ extern bool mult_side;
extern bool countrylist_only;
extern bool mixedmode;
extern bool qso_once;
extern bool noleadingzeros;
extern bool leading_zeros_serial;
extern bool ignoredupe;
extern bool continentlist_only;
extern bool debugflag;
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool serial_section_mult = false;
bool serial_or_section = false; /* exchange is serial OR section, like HA-DX */
bool serial_grid4_mult = false;
bool qso_once = false;
bool noleadingzeros;
bool leading_zeros_serial;
bool ctcomp;
bool nob4 = false; // allow auto b4
bool ignoredupe = false;
Expand Down Expand Up @@ -626,7 +626,7 @@ static void init_variables() {
unique_call_multi = MULT_NONE;
generic_mult = MULT_NONE;

noleadingzeros = false;
leading_zeros_serial = true;
ctcomp = false;
resend_call = RESEND_NOT_SET;

Expand Down
151 changes: 92 additions & 59 deletions src/parse_logcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ int getidxbybandstr(char *confband) {
return -1;
}

static void str_toupper(char *str) {
for (char *p = str; *p; ++p) {
*p = g_ascii_toupper(*p);
}
}

////////////////////
// global variables for matcher functions:
GMatchInfo *match_info;
Expand Down Expand Up @@ -177,14 +183,43 @@ static int parse_int(const char *string, gint64 min, gint64 max, int *result) {
return PARSE_OK;
}

int cfg_bool_const(const cfg_arg_t arg) {
*arg.bool_p = arg.bool_value;
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;
}

g_free(str);

*result = value;
return PARSE_OK;
}

int cfg_contest_bool_const(const cfg_arg_t arg) {
*(bool *)((char *)contest + arg.offset) = arg.bool_value;
return PARSE_OK;
int cfg_bool(const cfg_arg_t arg) {
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));
}

int cfg_int_const(const cfg_arg_t arg) {
Expand Down Expand Up @@ -298,9 +333,7 @@ static int cfg_call(const cfg_arg_t arg) {
return PARSE_WRONG_PARAMETER;
}

for (char *p = my.call; *p; ++p) {
*p = g_ascii_toupper(*p);
}
str_toupper(my.call);

return PARSE_OK;
}
Expand Down Expand Up @@ -1094,58 +1127,58 @@ static int cfg_resend_call(const cfg_arg_t arg) {
}

static config_t logcfg_configs[] = {
{"CONTEST_MODE", CFG_BOOL_TRUE(iscontest)},
{"MIXED", CFG_BOOL_TRUE(mixedmode)},
{"IGNOREDUPE", CFG_BOOL_TRUE(ignoredupe)},
{"USE_CONTINENTLIST_ONLY", CFG_BOOL_TRUE(continentlist_only)},
{"RADIO_CONTROL", CFG_BOOL_TRUE(trx_control)},
{"PORTABLE_MULT_2", CFG_BOOL_TRUE(portable_x2)},

{"USEPARTIALS", CFG_BOOL_TRUE(use_part)},
{"PARTIALS", CFG_BOOL_TRUE(partials)},
{"RECALL_MULTS", CFG_CONTEST_BOOL_TRUE(recall_mult)},
{"WYSIWYG_MULTIBAND", CFG_BOOL_TRUE(wysiwyg_multi)},
{"WYSIWYG_ONCE", CFG_BOOL_TRUE(wysiwyg_once)},
{"RIT_CLEAR", CFG_BOOL_TRUE(rit)},
{"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)},
{"NO_LEADING_ZEROS_SERIAL", CFG_BOOL_TRUE(noleadingzeros)},
{"SCOREWINDOW", CFG_BOOL_TRUE(showscore_flag)},
{"CHECKWINDOW", CFG_BOOL_TRUE(searchflg)},
{"SEND_DE", CFG_BOOL_TRUE(demode)},
{"SERIAL_EXCHANGE", CFG_CONTEST_BOOL_TRUE(exchange_serial)},
{"COUNTRY_MULT", CFG_BOOL_TRUE(country_mult)},
{"CQWW_M2", CFG_BOOL_TRUE(cqwwm2)},
{"LAN_DEBUG", CFG_BOOL_TRUE(landebug)},
{"CALLUPDATE", CFG_BOOL_TRUE(call_update)},
{"TIME_MASTER", CFG_BOOL_TRUE(time_master)},
{"CTCOMPATIBLE", CFG_BOOL_TRUE(ctcomp)},
{"SERIAL\\+SECTION", CFG_BOOL_TRUE(serial_section_mult)},
{"SECTION_MULT", CFG_BOOL_TRUE(sectn_mult)},
{"NOB4", CFG_BOOL_TRUE(nob4)},
{"SHOW_TIME", CFG_BOOL_TRUE(show_time)},
{"RXVT", CFG_BOOL_TRUE(use_rxvt)},
{"WAZMULT", CFG_BOOL_TRUE(wazmult)},
{"ITUMULT", CFG_BOOL_TRUE(itumult)},
{"CONTINENT_EXCHANGE", CFG_BOOL_TRUE(exc_cont)},
{"NOAUTOCQ", CFG_BOOL_TRUE(noautocq)},
{"NO_BANDSWITCH_ARROWKEYS", CFG_BOOL_TRUE(no_arrows)},
{"SOUNDCARD", CFG_BOOL_TRUE(sc_sidetone)},
{"LOWBAND_DOUBLE", CFG_BOOL_TRUE(lowband_point_mult)},
{"CLUSTER_LOG", CFG_BOOL_TRUE(clusterlog)},
{"SERIAL\\+GRID4", CFG_BOOL_TRUE(serial_grid4_mult)},
{"LOGFREQUENCY", CFG_BOOL_TRUE(logfrequency)},
{"NO_RST", CFG_BOOL_TRUE(no_rst)},
{"SERIAL_OR_SECTION", CFG_BOOL_TRUE(serial_or_section)},
{"PFX_MULT", CFG_BOOL_TRUE(pfxmult)},
{"PFX_MULT_MULTIBAND", CFG_BOOL_TRUE(pfxmultab)},
{"QTCREC_RECORD", CFG_BOOL_TRUE(qtcrec_record)},
{"QTC_AUTO_FILLTIME", CFG_BOOL_TRUE(qtc_auto_filltime)},
{"QTC_RECV_LAZY", CFG_BOOL_TRUE(qtc_recv_lazy)},
{"BMAUTOGRAB", CFG_BOOL_TRUE(bmautograb)},
{"BMAUTOADD", CFG_BOOL_TRUE(bmautoadd)},
{"SPRINTMODE", CFG_BOOL_TRUE(sprint_mode)},
{"KEYER_BACKSPACE", CFG_BOOL_TRUE(keyer_backspace)},
{"SECTION_MULT_ONCE", CFG_BOOL_TRUE(sectn_mult_once)},
{"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)},

{"F([1-9]|1[0-2])", CFG_MESSAGE(message, -1)}, // index is 1-based
{"S&P_TU_MSG", CFG_MESSAGE(message, SP_TU_MSG)},
Expand Down
10 changes: 4 additions & 6 deletions src/parse_logcfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ typedef struct {
};
union { // extra info
int int_value;
bool bool_value;
struct {
int string_type;
int base, size;
Expand All @@ -86,12 +85,11 @@ typedef struct {
cfg_arg_t arg;
} config_t;

#define CFG_BOOL_TRUE(var) NO_PARAM, cfg_bool_const, \
(cfg_arg_t){.bool_p=&var, .bool_value=true}
#define CFG_BOOL(var) OPTIONAL_PARAM, cfg_bool, \
(cfg_arg_t){.bool_p=&var}

#define CFG_CONTEST_BOOL_TRUE(var) NO_PARAM, cfg_contest_bool_const, \
(cfg_arg_t){.offset=offsetof(contest_config_t, var), \
.bool_value=true}
#define CFG_CONTEST_BOOL(var) OPTIONAL_PARAM, cfg_contest_bool, \
(cfg_arg_t){.offset=offsetof(contest_config_t, var)}

#define CFG_INT_CONST(var,n) NO_PARAM, cfg_int_const, \
(cfg_arg_t){.int_p=&var, .int_value=n}
Expand Down
2 changes: 1 addition & 1 deletion src/sendbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void ExpandMacro(void) {
}
qsonroutput[4] = '\0';

if (!noleadingzeros && leading_zeros > 1) {
if (leading_zeros_serial && leading_zeros > 1) {
leading_zeros = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/setcontest.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void setcontest(char *name) {
qso_once = true;
multlist = 1;
// sectn_mult = true;
noleadingzeros = true;
leading_zeros_serial = false;
}

if (CONTEST_IS(PACC_PA)) {
Expand Down
2 changes: 1 addition & 1 deletion test/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool serial_section_mult = false;
bool serial_or_section = false; /* exchange is serial OR section, like HA-DX */
bool serial_grid4_mult = false;
bool qso_once = false;
bool noleadingzeros;
bool leading_zeros_serial;
bool ctcomp = false;
int isdupe = 0; // 0 if nodupe -- for auto qso b4 (LZ3NY)
bool nob4 = false; // allow auto b4
Expand Down
23 changes: 19 additions & 4 deletions test/test_parse_logcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,26 @@ void test_usepartials(void **state) {
assert_int_equal(use_part, 1);
}

void test_usepartials_with_arg(void **state) {
int rc = call_parse_logcfg("USEPARTIALS=no\n");
void test_usepartials_no(void **state) {
use_part = true;
int rc = call_parse_logcfg("USEPARTIALS = no\n"); // space around =
assert_int_equal(rc, PARSE_OK);
assert_int_equal(use_part, false);
}

void test_usepartials_yes(void **state) {
use_part = false;
int rc = call_parse_logcfg("USEPARTIALS=yes\n");
assert_int_equal(rc, PARSE_OK);
assert_int_equal(use_part, true);
}

void test_usepartials_wrong_arg(void **state) {
int rc = call_parse_logcfg("USEPARTIALS=abc\n");
assert_int_equal(rc, PARSE_ERROR);
assert_string_equal(showmsg_spy,
"Keyword 'USEPARTIALS' can't have a parameter. See man page.\n");
"Wrong parameter format for keyword 'USEPARTIALS'. See man page.\n");

}

typedef struct {
Expand Down Expand Up @@ -434,7 +449,7 @@ static bool_true_t bool_trues[] = {
{"QTCREC_RECORD", &qtcrec_record},
{"QTC_AUTO_FILLTIME", &qtc_auto_filltime},
{"QTC_RECV_LAZY", &qtc_recv_lazy},
{"NO_LEADING_ZEROS_SERIAL", &noleadingzeros},
{"LEADING_ZEROS_SERIAL", &leading_zeros_serial},
};

void test_bool_trues(void **state) {
Expand Down
4 changes: 2 additions & 2 deletions test/test_sendbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void test_expandQsoNrshort(void **state) {
}

void test_expandQsoNr_leadingzeros(void **state) {
noleadingzeros = false;
leading_zeros_serial = true;
strcpy(qsonrstr, "0007");
check_ExpandMacro("nr #", "nr 007");
strcpy(qsonrstr, "0073");
Expand All @@ -200,7 +200,7 @@ void test_expandQsoNr_leadingzeros(void **state) {
}

void test_expandQsoNr_noleadingzeros(void **state) {
noleadingzeros = true;
leading_zeros_serial = false;
strcpy(qsonrstr, "0007");
check_ExpandMacro("nr #", "nr 7");
strcpy(qsonrstr, "0073");
Expand Down
Loading

0 comments on commit fc4b0f0

Please sign in to comment.