From 425c8ea635172b061f5ddd1365a8bf05012d0812 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 23 Jun 2008 18:06:00 +0200 Subject: [PATCH] util: tokenize a_strtobool() --- common/tokenize.gperf | 4 ++++ common/util.h | 20 +++++++++++++------- widgets/graph.c | 4 ++-- widgets/iconbox.c | 2 +- widgets/progressbar.c | 4 ++-- widgets/taglist.c | 2 +- widgets/tasklist.c | 2 +- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/common/tokenize.gperf b/common/tokenize.gperf index b5119bc1e..884e8784b 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -1,3 +1,4 @@ +1 align all auto @@ -26,6 +27,7 @@ left line max_value min_value +on resize reverse right @@ -45,6 +47,8 @@ ticks_gap top topleft topright +true vertical vertical_gradient width +yes diff --git a/common/util.h b/common/util.h index f0caaa08b..be5009632 100644 --- a/common/util.h +++ b/common/util.h @@ -30,6 +30,8 @@ #include #include +#include "tokenize.h" + /** A list of possible position, not sex related */ 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. */ static inline bool -a_strtobool(const char *s) +a_strtobool(const char *s, ssize_t len) { - if(!strcasecmp(s, "true") - || !strcasecmp(s, "on") - || !strcasecmp(s, "yes") - || !strcasecmp(s, "1")) - return true; - return false; + switch(a_tokenize(s, len)) + { + case A_TK_TRUE: + case A_TK_YES: + case A_TK_ON: + case A_TK_1: + return true; + default: + return false; + } } #define fatal(string, ...) _fatal(__LINE__, \ diff --git a/widgets/graph.c b/widgets/graph.c index ab384dad7..1d6c69938 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -414,10 +414,10 @@ graph_tell(widget_t *widget, const char *property, const char *new_value) graph_pcolor_set(&graph->pcolor_end, setting); break; case A_TK_VERTICAL_GRADIENT: - graph->vertical_gradient = a_strtobool(setting); + graph->vertical_gradient = a_strtobool(setting, -1); break; case A_TK_SCALE: - graph->scale = a_strtobool(setting); + graph->scale = a_strtobool(setting, -1); break; case A_TK_MAX_VALUE: graph->max_value = atof(setting); diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 301cb78e3..8db93e038 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -81,7 +81,7 @@ iconbox_tell(widget_t *widget, const char *property, const char *new_value) d->image = draw_image_new(new_value); break; case A_TK_RESIZE: - d->resize = a_strtobool(new_value); + d->resize = a_strtobool(new_value, -1); break; default: return WIDGET_ERROR; diff --git a/widgets/progressbar.c b/widgets/progressbar.c index cdbcfe6b3..7b1b114b9 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -436,7 +436,7 @@ progressbar_tell(widget_t *widget, const char *property, const char *new_value) d->height = atof(new_value); return WIDGET_NOERROR; case A_TK_VERTICAL: - d->vertical = a_strtobool(new_value); + d->vertical = a_strtobool(new_value, -1); return WIDGET_NOERROR; /* 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; break; case A_TK_REVERSE: - bar->reverse = a_strtobool(setting); + bar->reverse = a_strtobool(setting, -1); break; default: return WIDGET_ERROR; diff --git a/widgets/taglist.c b/widgets/taglist.c index 14425f47f..f7c5ef242 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -274,7 +274,7 @@ taglist_tell(widget_t *widget, const char *property, const char *new_value) d->text_urgent = a_strdup(new_value); break; case A_TK_SHOW_EMPTY: - d->show_empty = a_strtobool(new_value); + d->show_empty = a_strtobool(new_value, -1); break; default: return WIDGET_ERROR; diff --git a/widgets/tasklist.c b/widgets/tasklist.c index fc8997383..abc93f412 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -277,7 +277,7 @@ tasklist_tell(widget_t *widget, const char *property, const char *new_value) d->text_urgent = a_strdup(new_value); break; case A_TK_SHOW_ICONS: - d->show_icons = a_strtobool(new_value); + d->show_icons = a_strtobool(new_value, -1); break; case A_TK_SHOW: switch(a_tokenize(new_value, -1))