static void decode_de(yystype *params[], struct text_buffer *txtbuf) { const char *p = TOKEN_GET(params[0], cstring); const long a = TOKEN_GET(params[1], ival); /*const char *c = params[2];*/ char *k = TOKEN_GET(params[3], string); /*const char *r = params[5];*/ unsigned val=0; unsigned nsplit = 0; const char* o; const char **tokens; memset(txtbuf, 0, sizeof(*txtbuf)); if(!p || !k ) return; for(o = k; *o; o++) if(*o == '|') nsplit++; nsplit++; tokens = malloc(sizeof(char*)*nsplit); if(!tokens) { return; } cli_strtokenize(k,'|',nsplit, tokens); do { while(*p && !isalnum(*p)) { if(*p=='\\' && (p[1] == '\'' || p[1] == '\"')) p++; else textbuffer_putc(txtbuf, *p++); } if(!*p) break; val = 0; o = p; while(*p && isalnum(*p)) { unsigned x; unsigned char v = *p++; /* TODO: use a table here */ if(v >= 'a') x = 10+v-'a'; else if(v >= 'A') x = 36+v-'A'; else x = v-'0'; val = val*a+x; } if(val >= nsplit || !tokens[val] || !tokens[val][0]) while(o!=p) textbuffer_putc(txtbuf, *o++); else textbuffer_append(txtbuf, tokens[val]); } while (*p); free(tokens); textbuffer_append(txtbuf, "\0"); }
END_TEST START_TEST (test_append) { fail_unless(textbuffer_append(&buf, "test") != -1, "tbuf append"); fail_unless(textbuffer_putc(&buf, '\0') != -1, "tbuf putc"); fail_unless(buf.data && !strcmp(buf.data,"test"), "textbuffer_append"); }