From 845ea9dcc3708114d96666257b567d2cb42ecfdb Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 6 Jan 2008 22:42:06 +0100 Subject: [PATCH] rework uicb, cosmetic, use a_str functions --- uicb.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/uicb.c b/uicb.c index 8ec06d4c..d67aac2c 100644 --- a/uicb.c +++ b/uicb.c @@ -85,48 +85,55 @@ const NameFuncLink UicbList[] = }; static int -run_uicb(char *cmd, AwesomeConf *awesomeconf __attribute ((unused))) +run_uicb(char *cmd) { - char *p; + char *p, *argcpy; const char *arg; - char *argcpy; - int screen, len; - void (*uicb) (int, const char *); + int screen; + ssize_t len; + Uicb *uicb; - len = strlen(cmd); + len = a_strlen(cmd); p = strtok(cmd, " "); - if (!p){ + if (!p) + { warn("Ignoring malformed command\n"); return -1; } screen = atoi(cmd); - if(screen >= get_screen_count() || screen < 0){ + if(screen >= get_screen_count() || screen < 0) + { warn("Invalid screen specified: %i\n", screen); return -1; } p = strtok(NULL, " "); - if (!p){ + if (!p) + { warn("Ignoring malformed command.\n"); return -1; } + uicb = name_func_lookup(p, UicbList); - if (!uicb){ + if (!uicb) + { warn("Unknown UICB function: %s.\n", p); return -1; } - if (p+strlen(p) < cmd+len) + if (p + a_strlen(p) < cmd + len) { - arg = p + strlen(p) + 1; + arg = p + a_strlen(p) + 1; + len = a_strlen(arg); /* Allow our callees to modify this string. */ - argcpy = p_new(char, strlen(arg)+1); - strncpy(argcpy, arg, strlen(arg)); + argcpy = p_new(char, len + 1); + a_strncpy(argcpy, len + 1, arg, len); uicb(screen, argcpy); p_delete(&argcpy); } else uicb(screen, NULL); + return 0; } @@ -141,9 +148,10 @@ parse_control(char *cmd) while((p = strchr(curcmd, '\n'))) { *p = '\0'; - run_uicb(curcmd, &globalconf); + run_uicb(curcmd); curcmd = p + 1; } + return 0; } -- 2.11.4.GIT