From 3f23635a339d58f5dcf078859229cbcd547735db Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 30 Apr 2008 12:02:37 +0200 Subject: [PATCH] [uicb] Use bool instead of int for returning status Signed-off-by: Julien Danjou --- uicb.c | 39 +++++++++++++++++++-------------------- uicb.h | 4 +++- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/uicb.c b/uicb.c index 827b0d49d..5e7fdfb04 100644 --- a/uicb.c +++ b/uicb.c @@ -138,9 +138,9 @@ uicb_spawn(int screen, char *arg) /** Run the uicb. * \param cmd The uicb command to parse. - * \return 0 on succes, -1 on failure. + * \return true on succes, false on failure. */ -static int +static bool __uicb_run(char *cmd) { char *p, *argcpy; @@ -154,27 +154,27 @@ __uicb_run(char *cmd) if (!p) { warn("ignoring malformed command\n"); - return -1; + return false; } screen = atoi(cmd); if(screen >= globalconf.screens_info->nscreen || screen < 0) { warn("invalid screen specified: %i\n", screen); - return -1; + return false; } p = strtok(NULL, " "); if (!p) { warn("ignoring malformed command.\n"); - return -1; + return false; } uicb = name_func_lookup(p, UicbList); if (!uicb) { warn("unknown uicb function: %s.\n", p); - return -1; + return false; } if (p + a_strlen(p) < cmd + len) @@ -190,29 +190,28 @@ __uicb_run(char *cmd) else uicb(screen, NULL); - return 0; + return true; } /** Parse a command. - * \param cmd the buffer - * \return 0 on succes, -1 on failure + * \param cmd The buffer to parse. + * \return true on succes, false on failure. */ -int +bool __uicb_parsecmd(char *cmd) { char *p, *curcmd = cmd; + bool ret = false; - if(!a_strlen(cmd)) - return -1; + if(a_strlen(cmd)) + while((p = strchr(curcmd, '\n'))) + { + *p = '\0'; + ret = __uicb_run(curcmd); + curcmd = p + 1; + } - while((p = strchr(curcmd, '\n'))) - { - *p = '\0'; - __uicb_run(curcmd); - curcmd = p + 1; - } - - return 0; + return ret; } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/uicb.h b/uicb.h index 766f28b41..8f535d46e 100644 --- a/uicb.h +++ b/uicb.h @@ -22,9 +22,11 @@ #ifndef AWESOME_UICB_H #define AWESOME_UICB_H +#include + typedef void (uicb_t)(int, char *); -int __uicb_parsecmd(char *); +bool __uicb_parsecmd(char *); uicb_t uicb_restart; uicb_t uicb_exec;