[uicb] Use bool instead of int for returning status

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-30 12:02:37 +02:00
parent 6f409e39d0
commit 3f23635a33
2 changed files with 22 additions and 21 deletions

39
uicb.c
View File

@ -138,9 +138,9 @@ uicb_spawn(int screen, char *arg)
/** Run the uicb. /** Run the uicb.
* \param cmd The uicb command to parse. * \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) __uicb_run(char *cmd)
{ {
char *p, *argcpy; char *p, *argcpy;
@ -154,27 +154,27 @@ __uicb_run(char *cmd)
if (!p) if (!p)
{ {
warn("ignoring malformed command\n"); warn("ignoring malformed command\n");
return -1; return false;
} }
screen = atoi(cmd); screen = atoi(cmd);
if(screen >= globalconf.screens_info->nscreen || screen < 0) if(screen >= globalconf.screens_info->nscreen || screen < 0)
{ {
warn("invalid screen specified: %i\n", screen); warn("invalid screen specified: %i\n", screen);
return -1; return false;
} }
p = strtok(NULL, " "); p = strtok(NULL, " ");
if (!p) if (!p)
{ {
warn("ignoring malformed command.\n"); warn("ignoring malformed command.\n");
return -1; return false;
} }
uicb = name_func_lookup(p, UicbList); uicb = name_func_lookup(p, UicbList);
if (!uicb) if (!uicb)
{ {
warn("unknown uicb function: %s.\n", p); warn("unknown uicb function: %s.\n", p);
return -1; return false;
} }
if (p + a_strlen(p) < cmd + len) if (p + a_strlen(p) < cmd + len)
@ -190,29 +190,28 @@ __uicb_run(char *cmd)
else else
uicb(screen, NULL); uicb(screen, NULL);
return 0; return true;
} }
/** Parse a command. /** Parse a command.
* \param cmd the buffer * \param cmd The buffer to parse.
* \return 0 on succes, -1 on failure * \return true on succes, false on failure.
*/ */
int bool
__uicb_parsecmd(char *cmd) __uicb_parsecmd(char *cmd)
{ {
char *p, *curcmd = cmd; char *p, *curcmd = cmd;
bool ret = false;
if(!a_strlen(cmd)) if(a_strlen(cmd))
return -1; while((p = strchr(curcmd, '\n')))
{
*p = '\0';
ret = __uicb_run(curcmd);
curcmd = p + 1;
}
while((p = strchr(curcmd, '\n'))) return ret;
{
*p = '\0';
__uicb_run(curcmd);
curcmd = p + 1;
}
return 0;
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

4
uicb.h
View File

@ -22,9 +22,11 @@
#ifndef AWESOME_UICB_H #ifndef AWESOME_UICB_H
#define AWESOME_UICB_H #define AWESOME_UICB_H
#include <stdbool.h>
typedef void (uicb_t)(int, char *); typedef void (uicb_t)(int, char *);
int __uicb_parsecmd(char *); bool __uicb_parsecmd(char *);
uicb_t uicb_restart; uicb_t uicb_restart;
uicb_t uicb_exec; uicb_t uicb_exec;