From a41c25c0f5adad121e7baa8ff296b95e8f91045b Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 7 Jan 2008 15:48:42 +0100 Subject: [PATCH] modify the tell function to respect spaces --- widgets/textbox.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/widgets/textbox.c b/widgets/textbox.c index 83f9b3d5..e18c315b 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -66,8 +66,8 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, static void textbox_tell(Widget *widget, char *command) { - char *tok; - int i, color; + char *tok, *ntok, buf[8]; + int i = 0, color = 0; ssize_t command_len = a_strlen(command) + 1; char* text = p_new(char, command_len); @@ -75,29 +75,40 @@ textbox_tell(Widget *widget, char *command) if (d->text) p_delete(&d->text); - for(tok = strtok(command, " "), i = color = 0; tok; tok = strtok(NULL, " "), i++) + for(tok = command ; tok; tok = ntok, i++) { + /* get next token */ + ntok = strchr(tok + 1, ' '); + + /* if not first time in the loop, drop the space and put it in the + * string */ + if(i) + { + tok++; + a_strcat(text, command_len, " "); + } + if(*tok == '#' && i < 2) { + if(ntok) + a_strncpy(buf, ssizeof(buf), tok, ntok - tok); switch(i) { case 0: d->fg = initxcolor(get_phys_screen(widget->statusbar->screen), - tok); + buf); break; case 1: d->bg = initxcolor(get_phys_screen(widget->statusbar->screen), - tok); + buf); break; }; color++; } + else if(ntok) + a_strncat(text, command_len, tok, ntok - tok); else - { - if(i > color) - a_strcat(text, command_len, " "); a_strcat(text, command_len, tok); - } } d->text = a_strdup(text);