util: tokenize a_strtobool()

This commit is contained in:
Julien Danjou 2008-06-23 18:06:00 +02:00
parent 9caa9fc96f
commit 425c8ea635
7 changed files with 24 additions and 14 deletions

View File

@ -1,3 +1,4 @@
1
align align
all all
auto auto
@ -26,6 +27,7 @@ left
line line
max_value max_value
min_value min_value
on
resize resize
reverse reverse
right right
@ -45,6 +47,8 @@ ticks_gap
top top
topleft topleft
topright topright
true
vertical vertical
vertical_gradient vertical_gradient
width width
yes

View File

@ -30,6 +30,8 @@
#include <assert.h> #include <assert.h>
#include <alloca.h> #include <alloca.h>
#include "tokenize.h"
/** A list of possible position, not sex related */ /** A list of possible position, not sex related */
typedef enum typedef enum
{ {
@ -295,14 +297,18 @@ a_strncat(char *dst, ssize_t n, const char *src, ssize_t l)
* \return true if the string is recognized as possibly true, false otherwise. * \return true if the string is recognized as possibly true, false otherwise.
*/ */
static inline bool static inline bool
a_strtobool(const char *s) a_strtobool(const char *s, ssize_t len)
{ {
if(!strcasecmp(s, "true") switch(a_tokenize(s, len))
|| !strcasecmp(s, "on") {
|| !strcasecmp(s, "yes") case A_TK_TRUE:
|| !strcasecmp(s, "1")) case A_TK_YES:
case A_TK_ON:
case A_TK_1:
return true; return true;
default:
return false; return false;
}
} }
#define fatal(string, ...) _fatal(__LINE__, \ #define fatal(string, ...) _fatal(__LINE__, \

View File

@ -414,10 +414,10 @@ graph_tell(widget_t *widget, const char *property, const char *new_value)
graph_pcolor_set(&graph->pcolor_end, setting); graph_pcolor_set(&graph->pcolor_end, setting);
break; break;
case A_TK_VERTICAL_GRADIENT: case A_TK_VERTICAL_GRADIENT:
graph->vertical_gradient = a_strtobool(setting); graph->vertical_gradient = a_strtobool(setting, -1);
break; break;
case A_TK_SCALE: case A_TK_SCALE:
graph->scale = a_strtobool(setting); graph->scale = a_strtobool(setting, -1);
break; break;
case A_TK_MAX_VALUE: case A_TK_MAX_VALUE:
graph->max_value = atof(setting); graph->max_value = atof(setting);

View File

@ -81,7 +81,7 @@ iconbox_tell(widget_t *widget, const char *property, const char *new_value)
d->image = draw_image_new(new_value); d->image = draw_image_new(new_value);
break; break;
case A_TK_RESIZE: case A_TK_RESIZE:
d->resize = a_strtobool(new_value); d->resize = a_strtobool(new_value, -1);
break; break;
default: default:
return WIDGET_ERROR; return WIDGET_ERROR;

View File

@ -436,7 +436,7 @@ progressbar_tell(widget_t *widget, const char *property, const char *new_value)
d->height = atof(new_value); d->height = atof(new_value);
return WIDGET_NOERROR; return WIDGET_NOERROR;
case A_TK_VERTICAL: case A_TK_VERTICAL:
d->vertical = a_strtobool(new_value); d->vertical = a_strtobool(new_value, -1);
return WIDGET_NOERROR; return WIDGET_NOERROR;
/* following properties need a datasection */ /* following properties need a datasection */
@ -514,7 +514,7 @@ progressbar_tell(widget_t *widget, const char *property, const char *new_value)
bar->value = bar->max_value; bar->value = bar->max_value;
break; break;
case A_TK_REVERSE: case A_TK_REVERSE:
bar->reverse = a_strtobool(setting); bar->reverse = a_strtobool(setting, -1);
break; break;
default: default:
return WIDGET_ERROR; return WIDGET_ERROR;

View File

@ -274,7 +274,7 @@ taglist_tell(widget_t *widget, const char *property, const char *new_value)
d->text_urgent = a_strdup(new_value); d->text_urgent = a_strdup(new_value);
break; break;
case A_TK_SHOW_EMPTY: case A_TK_SHOW_EMPTY:
d->show_empty = a_strtobool(new_value); d->show_empty = a_strtobool(new_value, -1);
break; break;
default: default:
return WIDGET_ERROR; return WIDGET_ERROR;

View File

@ -277,7 +277,7 @@ tasklist_tell(widget_t *widget, const char *property, const char *new_value)
d->text_urgent = a_strdup(new_value); d->text_urgent = a_strdup(new_value);
break; break;
case A_TK_SHOW_ICONS: case A_TK_SHOW_ICONS:
d->show_icons = a_strtobool(new_value); d->show_icons = a_strtobool(new_value, -1);
break; break;
case A_TK_SHOW: case A_TK_SHOW:
switch(a_tokenize(new_value, -1)) switch(a_tokenize(new_value, -1))