modify the tell function to respect spaces

This commit is contained in:
Julien Danjou 2008-01-07 15:48:42 +01:00
parent fb07026639
commit a41c25c0f5
1 changed files with 20 additions and 9 deletions

View File

@ -66,8 +66,8 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
static void static void
textbox_tell(Widget *widget, char *command) textbox_tell(Widget *widget, char *command)
{ {
char *tok; char *tok, *ntok, buf[8];
int i, color; int i = 0, color = 0;
ssize_t command_len = a_strlen(command) + 1; ssize_t command_len = a_strlen(command) + 1;
char* text = p_new(char, command_len); char* text = p_new(char, command_len);
@ -75,30 +75,41 @@ textbox_tell(Widget *widget, char *command)
if (d->text) if (d->text)
p_delete(&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(*tok == '#' && i < 2)
{ {
if(ntok)
a_strncpy(buf, ssizeof(buf), tok, ntok - tok);
switch(i) switch(i)
{ {
case 0: case 0:
d->fg = initxcolor(get_phys_screen(widget->statusbar->screen), d->fg = initxcolor(get_phys_screen(widget->statusbar->screen),
tok); buf);
break; break;
case 1: case 1:
d->bg = initxcolor(get_phys_screen(widget->statusbar->screen), d->bg = initxcolor(get_phys_screen(widget->statusbar->screen),
tok); buf);
break; break;
}; };
color++; color++;
} }
else if(ntok)
a_strncat(text, command_len, tok, ntok - tok);
else else
{
if(i > color)
a_strcat(text, command_len, " ");
a_strcat(text, command_len, tok); a_strcat(text, command_len, tok);
} }
}
d->text = a_strdup(text); d->text = a_strdup(text);
p_delete(&text); p_delete(&text);