Use strtok in run_uicb, in preparation for improving error reporting.
Yes strtok is not nice, but it's nicer than rolling your own. ;)
This commit is contained in:
parent
417c7a5116
commit
f5372a7252
46
uicb.c
46
uicb.c
|
@ -95,46 +95,38 @@ parse_control(char *cmd, awesome_config *awesomeconf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
run_uicb(char *cmd, awesome_config *awesomeconf)
|
run_uicb(char *cmd, awesome_config *awesomeconf)
|
||||||
{
|
{
|
||||||
char *p, *uicb_name;
|
char *p;
|
||||||
const char *arg;
|
const char *arg;
|
||||||
int screen;
|
int screen, len;
|
||||||
void (*uicb) (awesome_config *, int, const char *);
|
void (*uicb) (awesome_config *, int, const char *);
|
||||||
|
|
||||||
if(!a_strlen(cmd))
|
len = strlen(cmd);
|
||||||
|
p = strtok(cmd, " ");
|
||||||
|
if (!p)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(!(p = strchr(cmd, ' ')))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
*p++ = '\0';
|
|
||||||
|
|
||||||
screen = atoi(cmd);
|
screen = atoi(cmd);
|
||||||
if(screen >= get_screen_count(awesomeconf->display) || screen < 0)
|
if(screen >= get_screen_count(awesomeconf->display) || screen < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uicb_name = p;
|
p = strtok(NULL, " ");
|
||||||
|
if (!p)
|
||||||
if(!(p = strchr(p, ' ')))
|
return -1;
|
||||||
arg = "";
|
uicb = name_func_lookup(p, UicbList);
|
||||||
else
|
if (!uicb)
|
||||||
{
|
|
||||||
*p++ = '\0';
|
|
||||||
arg = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((p = strchr(arg, '\n')))
|
|
||||||
*p = '\0';
|
|
||||||
|
|
||||||
uicb = name_func_lookup(uicb_name, UicbList);
|
|
||||||
|
|
||||||
if(uicb)
|
|
||||||
uicb(awesomeconf, screen, arg);
|
|
||||||
else
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (p+strlen(p) < cmd+len)
|
||||||
|
arg = p + strlen(p) + 1;
|
||||||
|
else
|
||||||
|
arg = NULL;
|
||||||
|
|
||||||
|
uicb(awesomeconf, screen, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|
||||||
|
|
Loading…
Reference in New Issue