#define array_count_pair(type, ...) (const type []){__VA_ARGS__}, sizeof((const type []){__VA_ARGS__})/sizeof(type)
static void test_read_cstring(void) {
- #define next() do {array_free(str); array_init(str, NULL); csp++;} while(0)
+ #define next() do {darray_free(str); darray_init(str); csp++;} while(0)
#define cs (*csp)
#define verify_quotechar(correct, correct_continuation_offset, quotechar) do { \
const size_t s = sizeof(correct)-1; \
};
const char * const *csp = cstrings;
const char *p;
- array_char str = array_new(NULL);
+ darray_char str = darray_new();
tok_message_queue mq;
queue_init(mq, NULL);
//Check a series of hex escapes
verify("\x50\x35\x12\xEF\xFE\x12\x45", 32);
- array_free(str);
+ darray_free(str);
//tok_message_queue_dump(&mq);
queue_skip(mq);
}
if (i<e)
- printf("Item %u is incorrect\n", i);
+ printf("Item %zu is incorrect\n", i);
ok(i==e, "Is message queue correct?");
ok(!queue_count(mq), "Message queue should be empty now.");
}
return;
}
if (sn.dots_found != dots_found) {
- fail("%s : sn.dots_found is %d; should be %d", str_pipes,
+ fail("%s : sn.dots_found is %zu; should be %zu", str_pipes,
sn.dots_found, dots_found);
return;
}
};
#define T(txt, ...) {txt, sizeof(txt)-1, array_count_pair(struct token, __VA_ARGS__)}
-#define string(txt) {.string={.item = (txt), .size = sizeof(txt)-1}}
+#define string(txt) {.string=(darray_char[1]){{.item = (char *)(txt), .size = sizeof(txt)-1}}}
#define opkw(v) {.opkw = (v)}
#define txt(t) .txt = (t), .txt_size = sizeof(t)-1
#define integer(...) {.integer={__VA_ARGS__}}
#define floating(...) {.floating={__VA_ARGS__}}
#define space {.type = TOK_WHITE, .txt = " ", .txt_size = 1}
#define startline {.type = TOK_STARTLINE}
-#define include(str) {.include = (str)}
+#define include(str) {.include = (char *)(str)}
struct tokenizer_msg_test {
struct tokenizer_test test;
#define M(...) array_count_pair(const char *, __VA_ARGS__)
struct tokenizer_test tokenizer_tests[] = {
- T(""),
+ { "", 0, 0 },
T("\n",
{.type = TOK_WHITE, txt("\n")}
),
goto done; \
} while(0)
- tl = tokenize(txt, txt_size, mq);
+ tl = tokenize(txt, txt, txt_size, mq);
if (tl->orig != txt || tl->orig_size != txt_size)
failed("tokenize() did not replicate orig/orig_size from arguments");
case TOK_CHAR:
case TOK_STRING:
//anything using string
- if (tok_gen->string.size != tok_correct->string.size ||
- memcmp(tok_gen->string.item, tok_correct->string.item,
- tok_gen->string.size) ||
- tok_gen->string.item[tok_gen->string.size] != 0 )
+ if (tok_gen->string->size != tok_correct->string->size ||
+ memcmp(tok_gen->string->item, tok_correct->string->item,
+ tok_gen->string->size) ||
+ tok_gen->string->item[tok_gen->string->size] != 0 )
failed("Token \"%s\": String value incorrect", tok_correct->txt);
break;
case TOK_STRING_IQUOTE:
static void test_tokenizer_file(const char *file_name, tok_message_queue *mq) {
FILE *f = fopen(file_name, "rb");
- array_char text = array_new(NULL);
+ darray_char *text = talloc_darray(NULL);
const size_t inc = 1024;
struct token_list *tl;
for (;;) {
size_t read_len;
- array_realloc(text, text.size+inc+1);
- read_len = fread(text.item+text.size, 1, inc, f);
- text.size += read_len;
- text.item[text.size] = 0;
+ darray_realloc(*text, text->size+inc+1);
+ read_len = fread(text->item+text->size, 1, inc, f);
+ text->size += read_len;
+ text->item[text->size] = 0;
if (read_len < inc)
break;
goto end;
}
- tl = tokenize(text.item, text.size, mq);
+ tl = tokenize(text, text->item, text->size, mq);
tl->filename = file_name;
//printf("File '%s' has %zu tokens\n", file_name, token_list_count(tl));
}*/
end:
- array_free(text);
+ talloc_free(text);
if (f)
fclose(f);
}