ready to make the debug dump
This commit is contained in:
parent
81a3465fc4
commit
48802b5f73
@ -974,7 +974,6 @@ void str8gen_init(Str8Gen* gen, SliceByte backing);
|
|||||||
Str8Gen str8gen_make( SliceByte backing);
|
Str8Gen str8gen_make( SliceByte backing);
|
||||||
|
|
||||||
void str8gen_append_str8(Str8Gen* gen, Str8 str);
|
void str8gen_append_str8(Str8Gen* gen, Str8 str);
|
||||||
// void str8gen_append_fmt (Str8Gen* gen, Str8 fmt, ...);
|
|
||||||
|
|
||||||
void str8gen_init(Str8Gen* gen, SliceByte backing) {
|
void str8gen_init(Str8Gen* gen, SliceByte backing) {
|
||||||
assert(gen != nullptr);
|
assert(gen != nullptr);
|
||||||
@ -998,6 +997,7 @@ In order to support appending formatted content via str8gen_apppend_fmt, we'll b
|
|||||||
Where a format template string is provided with a 'id' wrapped in delimiters which will be the angle brackets: <id>
|
Where a format template string is provided with a 'id' wrapped in delimiters which will be the angle brackets: <id>
|
||||||
Example: This formatted string will have <id> subsituted into it.
|
Example: This formatted string will have <id> subsituted into it.
|
||||||
*/
|
*/
|
||||||
|
#pragma region fmt_vtoken
|
||||||
|
|
||||||
typedef struct FmtTokEntry FmtTokEntry;
|
typedef struct FmtTokEntry FmtTokEntry;
|
||||||
struct FmtTokEntry {
|
struct FmtTokEntry {
|
||||||
@ -1102,11 +1102,13 @@ struct SliceStr8 {
|
|||||||
SSIZE len;
|
SSIZE len;
|
||||||
};
|
};
|
||||||
|
|
||||||
Str8 fmt__vtoken(SliceByte backing, Str8 fmt_template, SliceStr8* tokens)
|
#define local_persist static
|
||||||
{
|
|
||||||
FArena a_backing = farena_init(backing);
|
|
||||||
SliceFmtTokEntry table = {a_backing.start, 0};
|
|
||||||
|
|
||||||
|
Str8 fmt__vtoken(SliceByte backing_tbl, SliceByte backing_buf, Str8 fmt_template, SliceStr8* tokens)
|
||||||
|
{
|
||||||
|
assert(tokens != nullptr);
|
||||||
|
FArena a_backing = farena_init(backing_tbl);
|
||||||
|
SliceFmtTokEntry table = {a_backing.start, 0};
|
||||||
S32 left = tokens->len;
|
S32 left = tokens->len;
|
||||||
for (slice_iter(*tokens, token)) {
|
for (slice_iter(*tokens, token)) {
|
||||||
FmtTokEntry* entry = farena_push(a_backing, FmtTokEntry);
|
FmtTokEntry* entry = farena_push(a_backing, FmtTokEntry);
|
||||||
@ -1116,14 +1118,36 @@ Str8 fmt__vtoken(SliceByte backing, Str8 fmt_template, SliceStr8* tokens)
|
|||||||
entry->value = * token;
|
entry->value = * token;
|
||||||
++ table.len;
|
++ table.len;
|
||||||
}
|
}
|
||||||
SliceByte buffer = { .ptr = cast(U8*, a_backing.start) + a_backing.used, .len = a_backing.capacity - a_backing.used };
|
Str8 result = fmt_vtoken_slice(backing_buf, table, fmt_template);
|
||||||
Str8 result = fmt_vtoken_slice(buffer, table, fmt_template);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expected to take a Str8 array of entries formatted as a 2D array of key-value pairs (Str8[length][2])
|
// Expected to take a Str8 array of entries formatted as a 2D array of key-value pairs (Str8[length][2])
|
||||||
// The array will be tracked using a SliceStr8 structure.
|
// The array will be tracked using a SliceStr8 structure.
|
||||||
#define fmt_vtoken(backing, fmt_template, tokens) fmt__vtoken(backing, fmt_template, &(SliceStr8){.ptr = cast(Str8*, tokens), .len = size_of(tokens) / size_of(Str8) })
|
#define fmt_vtoken(backing_tbl, backing_buf, fmt_template, tokens) \
|
||||||
|
fmt__vtoken(backing_tbl, backing_buf, lit(fmt_template), \
|
||||||
|
&(SliceStr8){ \
|
||||||
|
.ptr = cast(Str8*, ((Str8[])tokens)), \
|
||||||
|
.len = size_of( ((Str8[])tokens)) / size_of(Str8) \
|
||||||
|
} \
|
||||||
|
)
|
||||||
|
#pragma endregion fmt_vtoken
|
||||||
|
|
||||||
|
inline
|
||||||
|
void str8gen__append_fmt(Str8Gen* gen, Str8 fmt_template, SliceStr8* tokens)
|
||||||
|
{
|
||||||
|
local_persist FMem_64KB tbl_backing = {0};
|
||||||
|
SliceByte fmt_backing = {gen->ptr + gen->len, gen->backing.len - gen->len};
|
||||||
|
fmt__vtoken(fmem_slice(tbl_backing), fmt_backing, fmt_template, tokens);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#define str8gen_append_fmt(gen, fmt_template, tokens) \
|
||||||
|
str8gen__append_fmt(& gen, lit(fmt_template), \
|
||||||
|
&(SliceStr8){ \
|
||||||
|
.ptr = cast(Str8*, ((Str8[])tokens)), \
|
||||||
|
.len = size_of( ((Str8[])tokens)) / size_of(Str8) \
|
||||||
|
} \
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Define a mapping array:
|
Define a mapping array:
|
||||||
@ -1132,18 +1156,34 @@ Str8 mappings [][2] = {
|
|||||||
^^ Add entries as above ^^
|
^^ Add entries as above ^^
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
#define fmt_vtoken_entry(key, value) { lit(key), lit(value) }
|
#define fmt_entry(key, value) lit(key), lit(value)
|
||||||
|
|
||||||
#ifdef DEMO__WATL_DUMP_V1
|
#ifdef DEMO__WATL_DUMP_V1
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
set_utf8_codepage();
|
set_utf8_codepage();
|
||||||
|
|
||||||
SliceByte scratch = slicemem_alloc(MEGABYTES(64));
|
local_persist FMem_64KB tbl_scratch;
|
||||||
Str8 subst_table [][2] = {
|
SliceByte fmt_scratch = slicemem_alloc(MEGABYTES(8));
|
||||||
fmt_vtoken_entry("maybe_sub", "IT SUBST!!!"),
|
Str8 test_str = fmt_vtoken(fmem_slice(tbl_scratch), fmt_scratch, "Will this work? <maybe_sub>", {
|
||||||
};
|
fmt_entry("maybe_sub", "IT SUBST!!!")
|
||||||
Str8 test_str = fmt_vtoken(scratch, lit("Will this work? <maybe_sub>"), subst_table);
|
});
|
||||||
|
|
||||||
|
SliceByte scratchgen = slicemem_alloc(MEGABYTES(16));
|
||||||
|
Str8Gen gen = str8gen_make(scratchgen);
|
||||||
|
str8gen_append_fmt(gen, "Testing now with Str8Gen!! <maybe_sub>!", {
|
||||||
|
fmt_entry("maybe_sub", "lets fucking go!!!")
|
||||||
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
We now have what we need to create the debug dump and the structural listing for WATL's data structures.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Str8 watl_debug_dmp(SliceByte buffer, WATL_SliceLine lines)
|
||||||
|
{
|
||||||
|
Str8Gen result = str8gen_make(buffer);
|
||||||
|
return (Str8){ result.ptr, result.len };
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user