Refactor conf_parse_bool()
* Increase size argument for strncmp() comparisons by one to include the terminating null-character (otherwise "yesfoo" would be parsed as "yes", "nobar" as "no"). * Pass destination address as an additional argument and return success/failure status to allow for better error handling. * Temporarily remove error handling (will be fixed later). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
c875ab4195
commit
7e4f995692
@ -462,7 +462,7 @@ struct pad {
|
|||||||
|
|
||||||
/* Notification bar definition. */
|
/* Notification bar definition. */
|
||||||
struct nbar {
|
struct nbar {
|
||||||
int show; /* display or hide the notify-bar */
|
unsigned show; /* display or hide the notify-bar */
|
||||||
int cntdwn; /* warn when time left before next app
|
int cntdwn; /* warn when time left before next app
|
||||||
becomes lesser than cntdwn */
|
becomes lesser than cntdwn */
|
||||||
char datefmt[BUFSIZ]; /* format for displaying date */
|
char datefmt[BUFSIZ]; /* format for displaying date */
|
||||||
|
38
src/custom.c
38
src/custom.c
@ -71,18 +71,17 @@ struct attribute {
|
|||||||
|
|
||||||
static struct attribute attr;
|
static struct attribute attr;
|
||||||
|
|
||||||
static unsigned
|
static int
|
||||||
conf_parse_bool (char *string)
|
conf_parse_bool (unsigned *dest, char *val)
|
||||||
{
|
{
|
||||||
if (strncmp (string, "yes", 3) == 0)
|
if (strncmp (val, "yes", 4) == 0)
|
||||||
return 1;
|
*dest = 1;
|
||||||
else if (strncmp (string, "no", 2) == 0)
|
else if (strncmp (val, "no", 3) == 0)
|
||||||
return 0;
|
*dest = 0;
|
||||||
else
|
else
|
||||||
{
|
|
||||||
EXIT (_("wrong configuration variable format."));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -235,10 +234,12 @@ custom_remove_attr (WINDOW *win, int attr_num)
|
|||||||
static void
|
static void
|
||||||
custom_set_conf (struct conf *conf, int background, enum conf_var var, char *val)
|
custom_set_conf (struct conf *conf, int background, enum conf_var var, char *val)
|
||||||
{
|
{
|
||||||
|
unsigned tmp;
|
||||||
|
|
||||||
switch (var)
|
switch (var)
|
||||||
{
|
{
|
||||||
case CUSTOM_CONF_AUTOSAVE:
|
case CUSTOM_CONF_AUTOSAVE:
|
||||||
conf->auto_save = conf_parse_bool (val);
|
conf_parse_bool (&conf->auto_save, val);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_PERIODICSAVE:
|
case CUSTOM_CONF_PERIODICSAVE:
|
||||||
if (atoi (val) < 0)
|
if (atoi (val) < 0)
|
||||||
@ -247,22 +248,23 @@ custom_set_conf (struct conf *conf, int background, enum conf_var var, char *val
|
|||||||
conf->periodic_save = atoi (val);
|
conf->periodic_save = atoi (val);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_CONFIRMQUIT:
|
case CUSTOM_CONF_CONFIRMQUIT:
|
||||||
conf->confirm_quit = conf_parse_bool (val);
|
conf_parse_bool (&conf->confirm_quit, val);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_CONFIRMDELETE:
|
case CUSTOM_CONF_CONFIRMDELETE:
|
||||||
conf->confirm_delete = conf_parse_bool (val);
|
conf_parse_bool (&conf->confirm_delete, val);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_SKIPSYSTEMDIALOGS:
|
case CUSTOM_CONF_SKIPSYSTEMDIALOGS:
|
||||||
conf->skip_system_dialogs = conf_parse_bool (val);
|
conf_parse_bool (&conf->skip_system_dialogs, val);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_SKIPPROGRESSBAR:
|
case CUSTOM_CONF_SKIPPROGRESSBAR:
|
||||||
conf->skip_progress_bar = conf_parse_bool (val);
|
conf_parse_bool (&conf->skip_progress_bar, val);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_CALENDAR_DEFAULTVIEW:
|
case CUSTOM_CONF_CALENDAR_DEFAULTVIEW:
|
||||||
calendar_set_view (atoi (val));
|
calendar_set_view (atoi (val));
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_WEEKBEGINSONMONDAY:
|
case CUSTOM_CONF_WEEKBEGINSONMONDAY:
|
||||||
if (conf_parse_bool (val))
|
conf_parse_bool (&tmp, val);
|
||||||
|
if (tmp)
|
||||||
calendar_set_first_day_of_week (MONDAY);
|
calendar_set_first_day_of_week (MONDAY);
|
||||||
else
|
else
|
||||||
calendar_set_first_day_of_week (SUNDAY);
|
calendar_set_first_day_of_week (SUNDAY);
|
||||||
@ -277,7 +279,7 @@ custom_set_conf (struct conf *conf, int background, enum conf_var var, char *val
|
|||||||
wins_set_sbar_width (atoi (val));
|
wins_set_sbar_width (atoi (val));
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_NOTIFYBARSHOW:
|
case CUSTOM_CONF_NOTIFYBARSHOW:
|
||||||
nbar.show = conf_parse_bool (val);
|
conf_parse_bool (&nbar.show, val);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_NOTIFYBARDATE:
|
case CUSTOM_CONF_NOTIFYBARDATE:
|
||||||
(void)strncpy (nbar.datefmt, val, strlen (val) + 1);
|
(void)strncpy (nbar.datefmt, val, strlen (val) + 1);
|
||||||
@ -301,10 +303,10 @@ custom_set_conf (struct conf *conf, int background, enum conf_var var, char *val
|
|||||||
conf->input_datefmt = 1;
|
conf->input_datefmt = 1;
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_DMON_ENABLE:
|
case CUSTOM_CONF_DMON_ENABLE:
|
||||||
dmon.enable = conf_parse_bool (val);
|
conf_parse_bool (&dmon.enable, val);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_CONF_DMON_LOG:
|
case CUSTOM_CONF_DMON_LOG:
|
||||||
dmon.log = conf_parse_bool (val);
|
conf_parse_bool (&dmon.log, val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user